﻿/*
What it does:  This file contains commonly used functions from possibly many wizards.
               This file will help us keep minimum functions within  the wizard.asp page.

Referred by : wizarda.asp
*/


function changePrintColors(colorno, iColor, iColorName, yindex, pantoneNo, pcolorgrp, yfilloroutline) {
	var tLastColor = document.preview["hcolorno" + colorno].value
	if (!yfilloroutline) {
		if (GetElement(["printcolor"+colorno])){
			GetElement(["printcolor"+colorno]).bgColor = iColor
			if (GetElement(["printcolorname"+colorno])){
				GetElement(["printcolorname"+colorno]).innerHTML = iColorName
			}
		}
		if (GetElement(["logocolor_"+colorno])){
			GetElement(["logocolor_"+colorno]).bgColor = iColor
		}
		if (GetElement(["elementcolor"+colorno])){
			GetElement(["elementcolor"+colorno]).bgColor = iColor
		}
		if (GetElement(["felementcolor_"+colorno])){
			GetElement(["felementcolor_"+colorno]).bgColor = iColor
		}

		for (k=1; k<=maxnotexts; k++){
			if (GetElement(["elementcolor"+k+colorno])){
				GetElement(["elementcolor"+k+colorno]).bgColor = iColor
			}
		}
	 	currobj["hcolorno"+colorno].value = iColor
		currobj["hcolorname"+colorno].value = iColorName

	 	currobj["hpantone"+colorno].value = pantoneNo

		for(var i=1; i<num_divs; i++) {
			if (div_color[i] == colorno) {
				div_color_hex[i] = "#"+iColor
			}
			if (div_bgcolor[i] == colorno) {
				div_bgcolor_hex[i] = "#"+iColor
			}
			if (div_fields[i]) {
				if (GetElement(["elementcolor_" + i + "_" + colorno])){
					GetElement(["elementcolor_" + i + "_" + colorno]).bgColor = iColor
				}
			}
		}
		
		if (flag_Graphic_Palette){
			tindex=getobjectno(flag_GraphicField)
			if (div_imagecolor[tindex]) {
				if (tLastColor == div_imagecolor[tindex].split('#').join('')) {
					if (div_imagecolor[tindex].split('#').join('') != iColor) {
						AssignLogoColor(colorno)		
					}
				}
			}
		}
		
		if (GetElement(["felementcolor_"+colorno])){
			SelectThisObject()		
		}	
		
		if (yindex > 0) {
			changeColor(colorno, yindex)
		}
	}
	else {
		if (yfilloroutline == 'fill') {
			currobj["hcolorno"+fill_color].value = iColor
			currobj["hcolorname"+fill_color].value = iColorName
			
			fill_color_RGB = iColor
		}
		else if (yfilloroutline == 'outline') {
			currobj["hcolorno"+outline_color].value = iColor
			currobj["hcolorname"+outline_color].value = iColorName
			
			outline_color_RGB = iColor
		}
	}

    Flash_UpdateFlashObjects()
    	
	SetUserDefinedColors(colorno, iColor, pantoneNo)
	
	if (xwin != null){
		xwin.close()
	}
}

function changeMultiColor(colorno, iColor, iColorName, yindex, pantoneNo, pcolorgrp) {
	if (yindex > 1) {
		div_color_hex[yindex] = "#"+iColor
		if (div_contents[yindex]) {
			if (GetElement(["elementcolor_" + yindex + "_" + colorno])){
				GetElement(["elementcolor_" + yindex + "_" + colorno]).bgColor = iColor
			}
		}
	}
	
	Flash_UpdateFlashObjects()
	
	if (xwin != null){
		xwin.close()
	}
}

//change color of individual line
function changeColor(colorno, yindex){
	if (document.preview.selection) {
		var xobj = document.preview.selection
		yindex = xobj.options[xobj.selectedIndex].value
	}
	
	if (!ValidateLabel(yindex)) {
		return;
	}
	
	if (div_fields[yindex].toUpperCase().indexOf('BARCODE') >= 0 || div_fields[yindex].toUpperCase().indexOf('TRACK') >= 0) {
		return;
	}
	
	if (xnumcolor <= "4") {
		//To facilitate removal of separate color selection section 
		//from the wizard specially for xpressmats.
		if (flag_PopupPalletteAlways) {
			showColors(colorno, yindex)
		}
		else {
			if (currobj["hcolorno"+colorno].value.length > 0) {
				div_color[yindex] = colorno
				div_color_hex[yindex] = "#"+currobj["hcolorno"+colorno].value
				CalcColorsUsed()
			}
		}	
	}
	else {
		showAdvanceColors(colorno, yindex)
	}
	
	Flash_UpdateFlashObjects();
}

function htmlencode_(ystr){
	ystr = ystr.split("&quot;").join("\"")
	return ystr
}

function htmlencode(ystr){
	ystr = ystr.split("&quot;").join("\"")
	ystr = ystr.split("&apos;").join("'")
	ystr = ystr.split("&lt;").join("<")
	ystr = ystr.split("&gt;").join(">")
	ystr = ystr.split("&nbsp;").join(" ")
	ystr = ystr.split("&amp;").join("&")	
	return ystr
}

function show_margin(yflag) {
	if (GetElement("divmargin")) {
		if (yflag) {
			divmargin.style.visibility = "visible"
		}
		else {
			divmargin.style.visibility = "hidden"
		}
	}
}

function isRectangle(yindex){
	if (div_contents[yindex] == "prectangle" || div_contents[yindex] == "rectangle") {
		return true
	}
	return false
}

var xsep = "^*"
var a_names, a_values;

pipe_w =0;
pipe_h=0;

function ChangePhotoBorderColor(tColor) {
	for (var k=1; k<num_divs; k++) {
		if (div_contents[k]) {
			if (div_contents[k].indexOf('rectangle') >= 0) {
				if (div_prompt[k].toUpperCase().indexOf('PHOTOBORDER') >= 0 || div_prompt[k].toUpperCase().indexOf('TITLERECT') >= 0) {
					currobj['hcolorno' + div_color[k]].value = tColor.split('#').join('')
					div_bgcolor_hex[k] = "#" + tColor.split('#').join('')
					if (div_bgcolor_hex[k] == "" || div_bgcolor_hex[k] == "#") {
                        //
					}
					
				}
			}
		}
	}
	
	Flash_UpdateFlashObjects();
}


function ShowHidePhotoBorder(yobj) {
//	for (var k=1; k<num_divs; k++) {
//		if (div_contents[k]) {
//			if (div_contents[k].indexOf('rectangle') >= 0) {
//				if (div_prompt[k].toUpperCase().indexOf('PHOTOBORDER') >= 0) {
//					var xobj = getRS(zz_bgnestref, zz_document, zz_all, joinParam(zz_div, k), zz_style)
//					if (yobj.checked) {
//						xobj.visibility = "visible"
//						div_hidden[k] = false;
//					}
//					else {
//						xobj.visibility = "hidden"
//						div_hidden[k] = true;
//					}
//				}
//			}
//		}
//	}
}

function ReplaceVerse(ypms, yhex) {
	var xSpacing=0;
	var xVHt = 0;
	var yactualpms = ypms
	ypms = ypms.split(" ").join("")
	xverseimage = trim_(xverseimage)
	var tverseimage = xverseimage.split('z.jpg').join('_'+ypms+'.gif')
	for (k=1; k<num_divs; k++) {
		if (div_fields[k]) {
			if (div_fields[k] == "VERSEIMAGE") {
				if (xverseimage.length > 0) {
					div_h[k] = (xverseheight / xversewidth) * div_w[k]
					xVHt = 2 * div_h[k]
					xSpacing = (back_height -  (2 * div_h[k]) * 0.85  - 12)/3
					div_y[k] = xSpacing

					if (document.images["div" + k + "img"]) {
						if (tverseimage.substring(0,4).toLowerCase() == '/xp2' || tverseimage.substring(0,4).toLowerCase() == '\\xp2'){
							document.images["div" + k + "img"].src = tverseimage	
							div_text[k] = tverseimage
						}else{
							document.images["div" + k + "img"].src = "/xp2/clipart/" + tverseimage	
							div_text[k] = "/xp2/clipart/" + tverseimage
						}
					}
				}
				else  {
					div_text[k] = 'null.gif'
					div_h[k] = 1
					div_w[k] = 1
					xSpacing = 1
					div_y[k] = xSpacing
					xVHt = 0 
					if (document.images["div" + k + "img"]) {
						document.images["div" + k + "img"].src = "/xp2/clipart/null.gif" 
					}
				}
			}
			else if (div_fields[k] == "LOGOIMAGE") {
				if (div_text[k].indexOf('null.gif') < 0) {
					grayscale=true	//When placing logo for the firsttime then set it to true
					convert_logo_color(k, div_text[k], '', grayscale)				
				}
			}
			if (div_fields[k].toUpperCase().indexOf("TEXTLINE") >= 0) {
				document.preview["hcolorno" + div_color[k]].value = yhex.split('#').join('')
				div_color_hex[k] = yhex
                var colid = div_color[k]
                Flash_ChangeLabelColor_FromTB(colid)
			}
			if (div_fields[k].toUpperCase().indexOf("GROUP") >= 0) {
				if (xsubcatgid.toLowerCase().indexOf('holidaycards') >= 0 && xverseimage.length > 0) {  
					if (xverseimage.length > 0) {
						div_y[k] = xVHt + (2 * xSpacing) - 12
					}
					else {
						div_y[k] = (back_height - (2 * div_h[k])) / 2
					}
				}
				//Vj - Changes according to New Js
				Flash_ResetObjectsPosition()
			}
		}
	}
	if (xsubcatgid.toLowerCase() == "holidaycards") {
		document.preview.ColorCode.value = GetColorCode(yactualpms)	
		document.preview.PrintColors.value = yactualpms
	}
	
    Flash_Update_RectAndTextObjColors();
	
}

function SetHCTextColor(ypms, yhex) {
	var xSpacing=0;
	var xVHt = 0;
	var yactualpms = ypms
	ypms = ypms.split(" ").join("")
	for (k=1; k<num_divs; k++) {
		if (div_fields[k]) {
			if (div_fields[k].toUpperCase().indexOf("TEXTLINE") >= 0) {
				document.preview["hcolorno" + div_color[k]].value = yhex.split('#').join('')
				div_color_hex[k] = yhex
			}
		}
	}
	if (xsubcatgid.toLowerCase() == "holidaycards") {
		document.preview.ColorCode.value = GetColorCode(yactualpms)	
		document.preview.PrintColors.value = yactualpms
	}
	
	Flash_Update_RectAndTextObjColors();
}

var LastLogoPos;
LastLogoPos = 0
function MoveLogoNow() {
	var xindex = getobjectno(flag_GraphicField)
	if (xindex > 0) {
		MoveLogo(xindex, aLogoPositions[++LastLogoPos], xLogoAssociation)
		if (LastLogoPos >= aLogoPositions.length) {
			LastLogoPos = 0
		}
	}
}

function ChangeLogoPosition(yPos) {
	xpermited = false
	for (var k=0; k<aLogoPositions.length; k++) {
		if (aLogoPositions[k] == yPos) {
			xpermited = true
		}
	}
	if (!xpermited) {
		alert("The position that you selected for you logo or other graphic is not possible\non this design. Please choose another position.")
		return;
	}
	var xindex = getobjectno(flag_GraphicField)
	if (xindex > 0) {
		SetIndicativePos(yPos)
		if (div_text[xindex].toLowerCase().indexOf('addimage.gif') >= 0) {
			alert("You have not uploaded a logo or selected a graphic from our clip art\nlibrary. To use this feature, you need to first upload a logo or have\nselected an image from the clip art library.")
			return;
		}
		MoveLogo(xindex, yPos, xLogoAssociation)

	}
}

function SetIndicativePos(yPos) {
	if (!flag_Graphic) {   //This means the section to display indicative logo positions is not visible
		return;
	}
	for (var k=0; k < aPosCode.length; k++) {
		if (xLogoPositions.indexOf(aPosCode[k]) >= 0) {
			eval("Cell" + aPosCode[k]).bgColor = "#CCCCCC"
		}
		else {
			eval("Cell" + aPosCode[k]).bgColor = "#FFFFFF"
		}
	}
	eval("Cell" + yPos).bgColor = "#FF0000"
	for (var k=0; k<document.preview.logo_pos.length; k++) {
		if (document.preview.logo_pos.options[k].value == yPos) {
			document.preview.logo_pos.options[k].selected = true;
			break;
		}
	}
}

function MoveLogo(yindex, yPos, yAsso) {
	var asso_x = 0;
	var asso_y = 0;
	var asso_w = 0;
	var asso_h = 0;
	xgindex = 0	
	if (yAsso.length <= 0) {   //Align with template as reference
		if (yPos == "TL" || yPos == "ML" || yPos == "BL") {
			div_x[yindex] = xLogoxoffset * 96
		}
		else if (yPos == "TR" || yPos == "MR" || yPos == "BR") {
			div_x[yindex] = back_width - ((2 * div_w[yindex]) + (xLogoxoffset * 96))
		}
		else if (yPos == "TC" || yPos == "MC" || yPos == "BC") {
			div_x[yindex] = (back_width - (2 * div_w[yindex])) / 2
		}

		if (yPos == "TL" || yPos == "TC" || yPos == "TR") {
			div_y[yindex] = xLogoyoffset * 96
		}
		else if (yPos == "BL" || yPos == "BC" || yPos == "BR") {
			div_y[yindex] = back_height - ((2 * div_h[yindex]) + (xLogoyoffset * 96))
		}
		else if (yPos == "ML" || yPos == "MC" || yPos == "MR") {
			div_y[yindex] = (back_height - ((2 * div_h[yindex]) + (xLogoyoffset * 96))) / 2
		}
	}
	else {
		xgindex = getobjectno(yAsso)
		if (xgindex > 0) {
			if (yPos == "TL" || yPos == "ML" || yPos == "BL") {
				div_x[yindex] = (olddiv_x[xgindex] + 0)    
			}
			else if (yPos == "TR" || yPos == "MR" || yPos == "BR") {
				div_x[yindex] = (2 * olddiv_w[xgindex] - (2 * div_w[yindex]) ) + (back_width - (2 * olddiv_w[xgindex])) / 2
			}
			else if (yPos == "TC" || yPos == "MC" || yPos == "BC") {
				div_x[yindex] = (2 * olddiv_w[xgindex] - (2 * div_w[yindex]) + back_width - (2 * olddiv_w[xgindex])) / 2  
			}

			if (yPos == "TL" || yPos == "TC" || yPos == "TR") {
				div_y[yindex] = (olddiv_y[xgindex] + 0) 
			}
			else if (yPos == "BL" || yPos == "BC" || yPos == "BR") {
				div_y[yindex] = (olddiv_y[xgindex]) + (2 * olddiv_h[xgindex]) - (2 * div_h[yindex])
			}
			else if (yPos == "ML" || yPos == "MC" || yPos == "MR") {
				div_y[yindex] = (olddiv_y[xgindex]) + ((2 * olddiv_h[xgindex] - (2 * div_h[yindex])) / 2)
			}
		}
	}

    //11232010
    //Flash_SetImageAlignment()
    ResetObject(yindex);
    FlashResizeImage(0, 0)
	if (div_text[yindex].toLowerCase() != 'null.gif') {
		AdjustLabelPositions(yindex, yPos, yAsso, xgindex)
	}

}

function AdjustLabelPositions(yindex, yPos, yAsso, ygindex) {
	var xgrpprefix = ""
	if (yAsso.length > 0) {
		if (yAsso.toUpperCase().indexOf("GROUP") >= 0) {
			xgrpprefix = yAsso.toUpperCase().split('GROUP').join('')
			if (xgrpprefix.length > 0) {
				xgrpprefix = xgrpprefix + "-0"
			}
		}
		if (xgrpprefix.length > 0) {
			j = ygindex
			var xfisrtsection;
			if (parseFloat(olddiv_w[ygindex]) >= parseFloat(olddiv_h[ygindex])) {
				xfisrtsection = false
				//logo will be suppressing the text group object from top to bottom or vice versa
				if (xLogoPlacement.length <= 0 || xLogoPlacement != 'TB') {  
					xfisrtsection = true
				}
			}
			else {
				xfisrtsection = true
				//logo will be suppressing the text group object from left to right or vice versa
				if (xLogoPlacement.length <= 0 || xLogoPlacement != 'LR') { 
					xfisrtsection = false
				}
			}
			
			if (xfisrtsection) {
				div_x[j] = olddiv_x[j]
				div_y[j] = olddiv_y[j]
				div_h[j] = olddiv_h[j]
				div_w[j] = olddiv_w[j]
							
				if (yPos == "TL" || yPos == "ML" || yPos == "BL") {
					div_x[j] = olddiv_x[j] + (2 * div_w[yindex])
					div_w[j] = olddiv_w[j] - div_w[yindex]
				}
				else if (yPos == "TR" || yPos == "MR" || yPos == "BR") {
					div_w[j] = olddiv_w[j] - div_w[yindex]   
				}
				else if (yPos == "TC") {
					div_y[j] = olddiv_y[j] + (2 * div_h[yindex])
					div_h[j] = olddiv_h[j] - div_h[yindex]
				}
				else if (yPos == "BC") {
					div_h[j] = olddiv_h[j] - div_h[yindex]   
				}
			}
			else {
				div_x[j] = olddiv_x[j]
				div_y[j] = olddiv_y[j]
				div_h[j] = olddiv_h[j]
				div_w[j] = olddiv_w[j]						
				if (yPos == "TL" || yPos == "TC" || yPos == "TR") {
					div_y[j] = olddiv_y[j] + (2 * div_h[yindex])
					div_h[j] = olddiv_h[j] - div_h[yindex]
				}
				else if (yPos == "BL" || yPos == "BC" || yPos == "BR") {
					div_h[j] = olddiv_h[j] - div_h[yindex]   
				}
				else if (yPos == "ML") {
					div_x[j] = olddiv_x[j] + (2 * div_w[yindex])
					div_w[j] = olddiv_w[j] - div_w[yindex]
				}
				else if (yPos == "MR") {
					div_w[j] = olddiv_w[j] - div_w[yindex] 
				}
			}
			if 	(j > 0) {
			    //11232010
				//changeDivSize(j)
				//changeDivLocation(j)
				ResetObject(j);
			}						
		}
	}
	else {
		xLogoHeight = 2 * div_h[yindex]
		xTotalHeight = 0
		for(var j=1; j<num_divs; j++) {	
			if (div_contents[j]) {
				if (div_contents[j].indexOf("plabel") >= 0) {
					if (div_group[j]) {
						if (div_group[j].indexOf("-0") || div_group[j] == "") {
							xTotalHeight = xTotalHeight + (2 * div_h[j])
						}
					}
				}
			}
		}
		xextraht = 0
		if (xTotalHeight > 0) {
			for(var j=1; j<num_divs; j++) {	
				if (div_contents[j]) {
					if (div_contents[j].indexOf("plabel") >= 0) {
						if (div_group[j]) {
							if (div_group[j].indexOf("-0") >= 0 || div_group[j] == "") {
								div_x[j] = olddiv_x[j]
								div_y[j] = olddiv_y[j]
								div_h[j] = olddiv_h[j]
								div_w[j] = olddiv_w[j]	
								if (parseFloat(back_width) >= parseFloat(back_height)) {
									if (yPos == "TL" || yPos == "ML" || yPos == "BL") {
										div_x[j] = olddiv_x[j] + (2 * div_w[yindex])
										div_w[j] = olddiv_w[j] - div_w[yindex]
									}
									else if (yPos == "TR" || yPos == "MR" || yPos == "BR") {
										div_w[j] = olddiv_w[j] - div_w[yindex]   
									}
									else if (yPos == "TC") {
										div_y[j] = olddiv_y[j] + (2 * div_h[yindex]) - (2 * xextraht)
										div_h[j] = olddiv_h[j] - (((2 * div_h[yindex] * 2 * olddiv_h[j]) / xTotalHeight) / 2)
										xextraht = xextraht + (((2 * div_h[yindex] * 2 * olddiv_h[j]) / xTotalHeight) / 2)
									}
									else if (yPos == "BC") {
										div_y[j] = olddiv_y[j] - (2 * xextraht)
										div_h[j] = olddiv_h[j] - (((2 * div_h[yindex] * 2 * olddiv_h[j]) / xTotalHeight) / 2)
										xextraht = xextraht + (((2 * div_h[yindex] * 2 * olddiv_h[j]) / xTotalHeight) / 2)
									}
								}
								else {
									if (yPos == "TL" || yPos == "TC" || yPos == "TR") {
										div_y[j] = olddiv_y[j] + (2 * div_h[yindex]) - (xextraht)
										div_h[j] = olddiv_h[j] - (((2 * div_h[yindex] * 2 * olddiv_h[j]) / xTotalHeight) / 2)
										xextraht = xextraht + ((2 * div_h[yindex] * 2 * olddiv_h[j]) / xTotalHeight) 										
									}
									else if (yPos == "BL" || yPos == "BC" || yPos == "BR") {
										div_y[j] = olddiv_y[j] - (xextraht)
										div_h[j] = olddiv_h[j] - (((2 * div_h[yindex] * 2 * olddiv_h[j]) / xTotalHeight) / 2)
										xextraht = xextraht + ((2 * div_h[yindex] * 2 * olddiv_h[j]) / xTotalHeight)
									}
									else if (yPos == "ML") {
										div_x[j] = olddiv_x[j] + (2 * div_w[yindex])
										div_w[j] = olddiv_w[j] - div_w[yindex]
									}
									else if (yPos == "MR") {
										div_w[j] = olddiv_w[j] - div_w[yindex] 
									}
								}
								if 	(j > 0) {
								    //11232010
									//changeDivSize(j)
									//changeDivLocation(j)
									ResetObject(j);
								}						
							}
						}
					}
				}
			}
		}
	}
}

function signstart(){

	if (currobj.signtype.value!='ANSI'){
		yindex=getobjectno("symbol")
		if (yindex!=-1){
			div_hidden[yindex]=true
		}
	}
	
	hideHiddenObjs()
	
	if (prodprintcolor.length==0 ){	prodprintcolor='000000' }
	if (prodmatcolor.length==0){ prodmatcolor='FFFFFF'; SVGMatColor='FFFFFF' }
	currobj.colorscheme.value = prodprintcolor + ' on '+ prodmatcolor

	if (currobj.signtype.value=='FACILITY'){
		if (backgroundimage.indexOf('bb.gif')>=0){
			currobj.chkborder.checked=true
		}
	}

	yindex=getobjectno("symbol")
	if (yindex!=-1){
		div_hidden[yindex]=true
	}

	if (currobj.signtype.value =='PROJ'){ 
		matcode = 'PRZ-GID' 
		matname = 'Glow-in-the-Dark Plastic'
		projsignStart() 
	}
}

function SetSplInst() {
	//enhance this function based on the need of a wizard.
	var tctr = 0;
	var xspinst = ""
	var xcolorqty = ""
	if (xcatgid == '118' || xcatgid == '119' || xcatgid == '120') {
		if (document.preview.SpecialInstructions) {
			for(var i=1; i<num_divs; i++) {
				if (document.preview["Qty" + i]){
					if (document.preview["Qty" + i].value > 0){
						tctr = tctr + 1
						xspinst = xspinst + tctr + ". Legend: " + div_text[i] + ", Qty: " + document.preview["Qty" + i].value + "<br>"
					}
				}
			}
			document.preview.SpecialInstructions.value = xspinst;
		}

		if (document.preview.ColorQty) {
			tctr=0
			for(var i=1; i<num_divs; i++) {
				if (document.preview["Qty" + i]){
					if (document.preview["Qty" + i].value > 0){
						tctr = tctr + 1
						tobj = document.preview["color" + i]
						tcolorvalue = tobj.options[tobj.selectedIndex].text
						tqty = document.preview["Qty" + i].value
						if (xcolorqty.indexOf(tcolorvalue) < 0) {
							if (xcolorqty.length > 0) {
								xcolorqty = xcolorqty + "|"
							}
							xcolorqty = xcolorqty + tcolorvalue + ";" + tqty 
						}
						else {
							var tcolorqty = ""
							var a_clrqty = xcolorqty.split("|")
							for (var k=0; k<a_clrqty.length; k++) {
								var t_vars = a_clrqty[k].split(";")
								if (t_vars[0] == tcolorvalue) {
									t_vars[1] = parseInt(t_vars[1]) + parseInt(tqty)
								}
								if (tcolorqty.length > 0) {
									tcolorqty = tcolorqty + "|"
								}
								tcolorqty = tcolorqty + t_vars[0] + ";" + t_vars[1]
							}
							xcolorqty = tcolorqty
						}
					}
				}
			}
			document.preview.ColorQty.value = xcolorqty;
		}
	}
}

function ValidateForDummyData() {
	var xmsg=""
	for (var k=num_divs-1; k>=1; k--) {
		if (div_contents[k]) {
			if (div_contents[k].indexOf('label') >= 0) {
				if (document.preview["textfield" + k]) {
					if (document.preview["textfield" + k].value.length > 0) {
						if (!a_cleared[k]) {
							if (xmsg.length <= 0) {
								xmsg = "You have not changed the default text for following fields:\n\n"
							}
							if (div_prompt[k].indexOf('javascript:') >= 0) {
								xmsg = xmsg +  div_text[k] + "\n"
							}
							else {
								xmsg = xmsg + div_prompt[k] + ": " + div_text[k] + "\n"
							}
							
						}
					}
				}
			}
		}
	}
	var xflag = true
	if (xmsg.length > 0) {
		if (!confirm(xmsg + "\nProceed with the default text?")) {
			xflag = false;
		}
	}
	return xflag;
}

function nextstep(yflag, ynextpage, ysaveandcreatemore){
	if (flag_Graphic_QualitySensor) {
		if (!VerifyImageResolution()) {
			return;
		}
	}	
	
	if (flag_Text_ClearOnFocus) {
		if (!ValidateForDummyData()) {
			return;
		}
	}
		
	if (yflag == '1') {
		GenerateNVP();
		SendVars()
		currobj.dspecsB.value=currobj.dspecs.value
		if (xcatgid == 777) {
			if (currobj.backtype.value == 2) {   //when back side is blank
				//alert(LOTOBACKTYPE)
				//currobj.dspecsB.value = ''
				//currobj.dspecs.value = currobj.dspecsF.value
				//if (currobj.templateXML.value.indexOf(";") >= 0) {
				//	t_xml = currobj.templateXML.value.split(";") 
				//	currobj.templateXML.value = t_xml[0]
				//	currobj.TemplateXML1.value = ""
				//}
			}

			//alert(LOTOBACKTYPE+'\n'+currobj.numcolor.value)
			if (LOTOBACKTYPE=="D;1" || LOTOBACKTYPE=="C;1" || LOTOBACKTYPE=="W;1" || LOTOBACKTYPE=="N;1"){
				currobj.numcolor.value = parseFloat(xnumcolor)*2;
			}else if (LOTOBACKTYPE=="D;3"){
				currobj.numcolor.value = parseFloat(xnumcolor)+2;
			}else if (LOTOBACKTYPE=="D;4"){
				currobj.numcolor.value = parseFloat(xnumcolor)+1;
			}else{
				currobj.numcolor.value = parseFloat(xnumcolor);
			}
			
			if (typeof(LOTOBACKTYPE)=="undefined"){	//If back side not clicked then assume first selection (back same as front)
				currobj.numcolor.value = parseFloat(xnumcolor)*2;
				//alert(1)
			}
			//alert(LOTOBACKTYPE+'\n'+currobj.numcolor.value)
		}
		currobj.currside.value='0'
	}
	else {

		GenerateNVP();
		SendVars()

	}
	
	SetSplInst()
	
	xsubcatgid = xsubcatgid.toLowerCase()
	if (xsubcatgid == "holidaycards") {
		StorePrintInfo()
	}
	
	if ((xsubcatgid == 'logo' || xsubcatgid == 'value' || xsubcatgid == 'economy' || xsubcatgid.indexOf('letterhead') >= 0 || xsubcatgid.indexOf('envelope') >= 0 ) && xcatgid == '512') {
		StoreColorInfo(xsubcatgid)
	}
	if (xsubcatgid.indexOf('stamp') >= 0) {
		StoreLinesEntered()	
	}

	if (flag_Bg_Validate) {
		if (backgroundimage.toLowerCase().indexOf('blank') >= 0 || backgroundimage.toLowerCase().indexOf('null') >= 0) {
			alert("Place the background graphic first.")
			return;
		}
	}

	if (flag_Photo_Validate) {
		yindex=getobjectno(flag_PhotoField)
		if (yindex > 0) {
			isrcimagename = trim_(div_text[yindex])
			if (isrcimagename.toLowerCase().indexOf("croppedimages") < 0 && isrcimagename.toLowerCase().indexOf("medres/") < 0) {
				alert("Place the photo first.")
				return;
			}
			if (isrcimagename.toLowerCase().indexOf('null.gif') >= 0) {
				alert("Place the photo first.")
				return
			}	
			if (flag_PhotoField.toUpperCase() == 'PHOTO2' || flag_PhotoField.toUpperCase() == 'PHOTO3') {
				if (flag_PhotoField.toUpperCase() == 'PHOTO2') {
					xnextfld = 'PHOTO3'
				}
				else {
					xnextfld = 'PHOTO2'
				}
				
				yindex=getobjectno(xnextfld)
				if (yindex > 0) {
					isrcimagename = trim_(div_text[yindex])
					
					if (isrcimagename.toLowerCase().indexOf("croppedimages") < 0 && isrcimagename.toLowerCase().indexOf("medres/") < 0) {
						alert("Place the photo first.")
						return;
					}
					if (isrcimagename.toLowerCase().indexOf('null.gif') >= 0) {
						alert("Place the photo first.")
						return
					}	
				}
			}
		}
	}

	var xsideprefix = ""
	if (xThisSide == "Back") {
		xsideprefix = "B_"
	}
	var xprefix = "xp5_" + document.preview.CompName.value + "_" + xsideprefix 
	StoreWizardPreferences(xprefix)
	if (xcompname.toLowerCase() == "officemax" && xsubcatgid == "holidaycards") {
		if (xThisSide == "Back" ) {
			xctr=0
			for (var k=1; k< num_divs; k++) {
				if (div_contents[k]) {
					if (div_contents[k].indexOf('label') >= 0) {
						if (div_fields[k].indexOf('GROUP') < 0) {
							if (trim_(div_text[k]).length > 0) {
								xctr=xctr+1
							}
						}
					}
				}
			}
			if (xctr > 0 && xctr < 2) {
				alert("You must enter at least 2 lines of text on envelope.")
				return;
			}			
		}
	}

	if (!ynextpage) {
		if (xcompname.toUpperCase() == "ODE" && xevent.toUpperCase() == "ORDER" && xproducttype.toUpperCase() == "DYNAMIC TEMPLATE")  {
			document.preview.action="accessories.asp"
		}
		else {
			document.preview.action="materialY.asp"
			if (document.preview.artworkChoice){
				if (document.preview.artworkChoice.value=="wizard"){
					document.preview.action="accessories.asp"
				}else{
					document.preview.action="materialY.asp"
				}
			}
		}
	}
	else {
		if (ysaveandcreatemore) {
			document.preview.SaveAndCreateMore.value = "1"
		}
		document.preview.action=ynextpage
	}
	if (flag_Wizard_Flow.toLowerCase().indexOf("idbadges") >= 0) {
			tindex = getobjectno(F_FULLNAME)
			if (tindex > 0) {
				document.preview.designname.value = div_text[tindex]
			}
			else {
				tindex = getobjectno("TEXTLINE1")
				if (tindex > 0) {
					document.preview.designname.value = div_text[tindex]
				}
			}
	}

	currobj.HologramCharge.value=""
	if (xcatgid == '77' && xsubcatgid.toLowerCase() == 'hanging2'){
		if (currobj.dspecs.value.toLowerCase().indexOf('-holo1')>=0 || currobj.dspecsF.value.toLowerCase().indexOf('-holo1')>=0){
			currobj.HologramCharge.value="holo1"
		}
		if (currobj.dspecs.value.toLowerCase().indexOf('-holo2')>=0 || currobj.dspecsF.value.toLowerCase().indexOf('-holo2')>=0){
			currobj.HologramCharge.value="holo2"
		}
	}

	if (xsubcatgid.toLowerCase() == 'slider'){
		var yindex=getobjectno("TEXTLINE2")
		if (yindex != -1){
			currobj.SliderPanelCharge.value=""
			if (div_text[yindex].length>0){
				currobj.SliderPanelCharge.value="1"
			}
		}
	}

	CalculateQty()

	//Label Quoter
	if (xcatgid == '789') {
		document.preview.action='xt_Add_Quotation_Cart.asp'
	}else if ( xMatRequested.length>0 ){
		document.preview.action="/xp5/xt_AddCustomtoCart.asp"
	}

	document.preview.target = "_self"

	document.preview.submit()

}

function CalculateQty() {
	if (xcatgid == "118" || xcatgid == "119" || xcatgid == "120") {
		xqty=0
		for (var k=1; k< num_divs; k++) {
			if (div_contents[k]) {
				if (div_contents[k].indexOf('label') >= 0) {
					if (div_fields[k].indexOf('TEXT') >= 0) {
						if (document.preview["Qty" + k]) {
							tqty = parseInt(document.preview["Qty" + k].value)
							xqty = parseInt(xqty) + parseInt(tqty)
						}
					}
				}
			}
		}
		document.preview.Qty.value = xqty
	}
}

function StoreWizardPreferences(yprefix) {
	var varnames = "";
	var varvalues = "";
	var a_curr_nvp = getCurrentNVP(xsep)
	if (a_curr_nvp.length > 0) {
		varnames = varnames + a_curr_nvp[0]
		varvalues = varvalues + a_curr_nvp[1]
	}
	varnames = varnames + xsep + "$###$"
	varvalues = varvalues + xsep + "$###$"
	varnames = varnames + xsep + "catgid" + xsep + "SubCatgId"
	varvalues = varvalues + xsep + document.preview.catgid.value + xsep + document.preview.SubCatgId.value
	var a_nvp = getOtherStoredNVP(varnames, varvalues, xsep)
	if (a_nvp.length > 0) {
		varnames = varnames.split(xsep + '$###$').join(xsep + a_nvp[0])
		varvalues = varvalues.split(xsep + '$###$').join(xsep + a_nvp[1])
	}
	else {
		varnames = varnames.split(xsep + '$###$').join('')
		varvalues = varvalues.split(xsep + '$###$').join('')
	}
	setCookie_(yprefix + "names", varnames)
	setCookie_(yprefix + "values", varvalues)
}

function getCurrentNVP(ysep) {
	var t_curr_nvp = new Array()
	t_curr_nvp[0] = ""
	t_curr_nvp[1] = ""

	for (var k=1; k< num_divs; k++) {
		if (div_contents[k]) {
			if (div_contents[k].indexOf('label') >= 0) {
				if (div_fields[k].length > 0) {
					if (t_curr_nvp[0].length > 0) {
						t_curr_nvp[0] = t_curr_nvp[0] + xsep
						t_curr_nvp[1] = t_curr_nvp[1] + xsep
					}
					t_curr_nvp[0] = t_curr_nvp[0] + div_fields[k]
					t_curr_nvp[1] = t_curr_nvp[1] + div_text[k] + "~" + div_size[k] + "~" + div_font[k] + "~" + div_style[k] + "~" + div_align[k] 
					t_curr_nvp[1] = t_curr_nvp[1] + "~" + div_color[k] + "~" + div_color_hex[k] 
					t_curr_nvp[1] = t_curr_nvp[1] + "~" + div_x[k] + "~" + div_y[k] 
					t_curr_nvp[1] = t_curr_nvp[1] + "~" + div_w[k] + "~" + div_h[k] 
					t_curr_nvp[1] = t_curr_nvp[1] + "~" + div_leading[k] + "~" + div_rule[k] + "~" + div_valign[k] 
					t_curr_nvp[1] = t_curr_nvp[1] + "~" + div_hidden[k] 
					
				}
			}
			else if (div_contents[k].indexOf('image') >= 0) {
				if (div_fields[k].length > 0) {
					if (t_curr_nvp[0].length > 0) {
						t_curr_nvp[0] = t_curr_nvp[0] + xsep
						t_curr_nvp[1] = t_curr_nvp[1] + xsep
					}
					t_curr_nvp[0] = t_curr_nvp[0] + div_fields[k]
					t_curr_nvp[1] = t_curr_nvp[1] + div_text[k] 
					t_curr_nvp[1] = t_curr_nvp[1] + "~" + div_x[k] + "~" + div_y[k] 
					t_curr_nvp[1] = t_curr_nvp[1] + "~" + div_w[k] + "~" + div_h[k] 
					t_curr_nvp[1] = t_curr_nvp[1] + "~" + div_transcolor[k] + "~" + div_imagecolor[k] 
					t_curr_nvp[1] = t_curr_nvp[1] + "~" + div_hidden[k] 
				}
			}
			else if (div_contents[k].indexOf('rectangle') >= 0) {
				if (t_curr_nvp[0].length > 0) {
					t_curr_nvp[0] = t_curr_nvp[0] + xsep
					t_curr_nvp[1] = t_curr_nvp[1] + xsep
				}
				
				t_curr_nvp[0] = t_curr_nvp[0] + ("RECT" + k)
				t_curr_nvp[1] = t_curr_nvp[1] + div_text[k] 
				t_curr_nvp[1] = t_curr_nvp[1] + "~" + div_x[k] + "~" + div_y[k] 
				t_curr_nvp[1] = t_curr_nvp[1] + "~" + div_w[k] + "~" + div_h[k] 
				t_curr_nvp[1] = t_curr_nvp[1] + "~" + div_color[k] + "~" + div_bgcolor[k] + "~" + div_outlinewt[k]  
				t_curr_nvp[1] = t_curr_nvp[1] + "~" + div_hidden[k] 
			}
		}
	}
	if (t_curr_nvp[0].length > 0) {
		t_curr_nvp[0] = t_curr_nvp[0] + xsep
		t_curr_nvp[1] = t_curr_nvp[1] + xsep
	}
	t_curr_nvp[0] = t_curr_nvp[0] + "XML"
	if (XP_CSREDIT == 'Y' || XP_CSREDIT == 'y') {
		t_curr_nvp[1] = t_curr_nvp[1] + document.preview.savedXML.value
	}
	else {
		t_curr_nvp[1] = t_curr_nvp[1] + document.preview.templateXML.value
	}

	t_curr_nvp[0] = t_curr_nvp[0] + xsep + "hcolorno0" + xsep + "hcolorno1" + xsep + "hcolorno2" + xsep + "hcolorno3" + xsep + "hcolorno4"
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.hcolorno0.value
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.hcolorno1.value
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.hcolorno2.value
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.hcolorno3.value
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.hcolorno4.value

	t_curr_nvp[0] = t_curr_nvp[0] + xsep + "hpantone0" + xsep + "hpantone1" + xsep + "hpantone2" + xsep + "hpantone3" + xsep + "hpantone4"
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.hpantone0.value
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.hpantone1.value
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.hpantone2.value
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.hpantone3.value
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.hpantone4.value


	t_curr_nvp[0] = t_curr_nvp[0] + xsep + "BGWT"
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + bkoutline_weight
	
	t_curr_nvp[0] = t_curr_nvp[0] + xsep + "BGFG"
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + iforecolornum
	
	t_curr_nvp[0] = t_curr_nvp[0] + xsep + "BGBG"
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + ibackcolornum
	
	t_curr_nvp[0] = t_curr_nvp[0] + xsep + "BGIMG"
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + backgroundimage

	/*Zoom Treatment Starts*/
	t_curr_nvp[0] = t_curr_nvp[0] + xsep + "ZOOMPER"
	t_curr_nvp[1] = t_curr_nvp[1] + xsep + xzoomper
	/*Zoom Treatment Ends*/

	if (xsubcatgid.toLowerCase() == "holidaycards") {
		t_curr_nvp[0] = t_curr_nvp[0] + xsep + "VerseImageName"
		t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.VerseImageName.value

		t_curr_nvp[0] = t_curr_nvp[0] + xsep + "PrintColors"
		t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.PrintColors.value
	}
	if (flag_Numbering1) {
		t_curr_nvp[0] = t_curr_nvp[0] + xsep + "chknumbering"
		xchecked = false
		if (document.preview.chknumbering) {
			xchecked = document.preview.chknumbering.checked
		}
		t_curr_nvp[1] = t_curr_nvp[1] + xsep + xchecked
	}
	if (flag_Numbering2) {
		t_curr_nvp[0] = t_curr_nvp[0] + xsep + "NumberingCharge"
		t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.NumberingCharge.value
	}

	if (flag_ANSICompliant) {
		t_curr_nvp[0] = t_curr_nvp[0] + xsep + "ansicompliant"
		xchecked = false
		if (document.preview.chkansicompliant) {
			xchecked = document.preview.chkansicompliant.checked
		}
		t_curr_nvp[1] = t_curr_nvp[1] + xsep + xchecked
	}

	if (xLogoPositions.length > 0) {
		if (document.preview.logo_pos) {
			t_curr_nvp[0] = t_curr_nvp[0] + xsep + "LOGOPOS"
			t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.logo_pos.options[document.preview.logo_pos.selectedIndex].value
		}
	}
	
	if (flag_Text_GroupFonts) {
		if (document.preview.optfonttype) {
			t_curr_nvp[0] = t_curr_nvp[0] + xsep + "DefaultFont"
			t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.optfonttype.options[document.preview.optfonttype.selectedIndex].value
		}
	}

	if (flag_BarCode) {
		if (document.preview.listbarcode) {  //specially for id badges
			t_curr_nvp[0] = t_curr_nvp[0] + xsep + "Symbology"
			t_curr_nvp[1] = t_curr_nvp[1] + xsep + document.preview.listbarcode.options[document.preview.listbarcode.selectedIndex].value
		}
	}

	if (currobj.catgid.value==77){

//11-03-05
		t_curr_nvp[0] = t_curr_nvp[0] + xsep + "LogoColorFlag"
		t_curr_nvp[1] = t_curr_nvp[1] + xsep +  document.preview.LogoColorFlag.value
//11-03-05

		t_curr_nvp[0] = t_curr_nvp[0] + xsep + "PadColor"
		t_curr_nvp[1] = t_curr_nvp[1] + xsep + xPadColor

		t_curr_nvp[0] = t_curr_nvp[0] + xsep + "Swapped"
		t_curr_nvp[1] = t_curr_nvp[1] + xsep + xswapped
	}
	return t_curr_nvp;
}

function RetrieveWizardPreferences(yprefix) {
	var txml = ""  // getValueFromCookie("XML")
	// comment the following block if you want the data be available for other designs
	// of same subcatgid 'holidaycards".
	if (xsubcatgid.toLowerCase() == "holidaycards") {
		var tVerseImageName = getValueFromCookie("VerseImageName")
		if (tVerseImageName.length > 0 && tVerseImageName != document.preview.VerseImageName.value) {
			//if a new card is selected then do not read from cookie.
			return;
		}
	}
	if (xcatgid.toLowerCase() == "511" || xcatgid.toLowerCase() == "999513") {
		return;
	}
	if (xcatgid.toLowerCase() == "101" && xsubcatgid.toLowerCase() == "rssheets") {
		return;
	}	
	if (XP_CSREDIT == 'Y' || XP_CSREDIT == 'y' ) {
		return;
	}
	else {
	    txml = getValueFromCookie("XML")
		if  (txml.length > 0){
			if ( txml.toLowerCase() != document.preview.templateXML.value.toLowerCase()) {
				//Do Not Use the Cookie.
				return
			}
		}else{
			return;
		}
				
	}
//	alert("I am in here2...")
	// We are using cookies only if it is the same design template.
	// This helps save users data across the pages, when he goes to the previous or next
	// page using browser's back and forward buttons.
		
	var thcolorno0 = getValueFromCookie("hcolorno0")
	var thcolorno1 = getValueFromCookie("hcolorno1")
	var thcolorno2 = getValueFromCookie("hcolorno2")
	var thcolorno3 = getValueFromCookie("hcolorno3")
	var thcolorno4 = getValueFromCookie("hcolorno4")
	if (thcolorno0.length > 0) {
		for (var n=0; n<=4; n++) {
			document.preview["hcolorno" + n].value = eval("thcolorno" + n)
			if (GetElement(["felementcolor_" + n])) {
				GetElement(["felementcolor_" + n]).bgColor = "#" + eval("thcolorno" + n)
			}


			if (GetElement(["printcolor"+n])){
				GetElement(["printcolor"+n]).bgColor = "#" + eval("thcolorno" + n)
				if (GetElement(["printcolorname"+n])) {
					GetElement(["printcolorname"+n]).innerHTML = ""
					   //I have not stored this value on cookie so just making it blank.
				}
			}

			if (GetElement(["logocolor_"+n])){
				GetElement(["logocolor_"+n]).bgColor = "#" + eval("thcolorno" + n)
			}			
		}
	}
	var thpantone0 = getValueFromCookie("hpantone0")
	var thpantone1 = getValueFromCookie("hpantone1")
	var thpantone2 = getValueFromCookie("hpantone2")
	var thpantone3 = getValueFromCookie("hpantone3")
	var thpantone4 = getValueFromCookie("hpantone4")
	if (thpantone0.length > 0 || thpantone1.length > 0 || thpantone2.length > 0 || thpantone3.length > 0 || thpantone4.length > 0) {
		for (var n=0; n<=4; n++) {
			if (document.preview["hpantone" + n]) {
				document.preview["hpantone" + n].value = eval("thpantone" + n)
			}
		}
	}	
	
	var tbgwt = getValueFromCookie("BGWT")
	var tbgfg = getValueFromCookie("BGFG")
	var tbgbg = getValueFromCookie("BGBG")
	var tbgimg = getValueFromCookie("BGIMG")
	
	/*Zoom Treatment Starts*/
	var tzoomper = getValueFromCookie("ZOOMPER")
	if (tzoomper.length > 0) {
		ApplyZoomToBackground(tzoomper)
	}
	/*Zoom Treatment Ends*/
	
	if (tbgwt.length > 0) {
	
		bkoutline_weight=tbgwt
		iforecolornum = tbgfg
		ibackcolornum = tbgbg
		
		if (flag_Bg_OutlineWeight) {
			if (currobj.listWeight) {
				for (var n=0; n<currobj.listWeight.length; n++) {
					if (currobj.listWeight.options[n].value == bkoutline_weight) {
						currobj.listWeight.selectedIndex = n
					}
				}
			}
		}
	
		if (iforecolornum.length >0) {
			outline_color_RGB = document.preview["hcolorno" + iforecolornum].value 
		}
		
		if (ibackcolornum.length >0) {
			fill_color_RGB = document.preview["hcolorno" + ibackcolornum].value  
		}
	}
	if (tbgimg.length > 0) {
		backgroundimage = tbgimg
		if (backgroundimage.substring(0,4).toLowerCase() == '/xp2' || backgroundimage.substring(0,4).toLowerCase() == '\\xp2'){
            //
		}else{
			backgroundimage = "/xp2/clipart/" + backgroundimage
		}
    }

    for (var k=num_divs-1; k>=1; k--) {
		if (div_contents[k]) {
			if (div_contents[k].indexOf('label') >= 0) {
				if (div_fields[k].length > 0) {
					tval = getValueFromCookie(div_fields[k])
					if (tval.length > 0 || div_fields[k].toUpperCase().indexOf('GROUP') >= 0) {
						if (flag_Text_ClearOnFocus) {
							if (!a_cleared[k]) {
								SetTextfieldProperties(k, true)
							}
						}

						var a_textval = tval.split('~')
						if (a_textval.length > 0) {
							if (document.preview["textfield" + k]) {
								document.preview["textfield" + k].value = a_textval[0].split("&quot;").join("\"")
							}
							
							//alert("textfield" + k+'\n'+a_textval[0])
							
							div_text[k] = a_textval[0]
						}
						if (a_textval.length > 1) {
							div_size[k] = a_textval[1]
						}
						if (txml.toLowerCase() == document.preview.templateXML.value.toLowerCase() || txml.length <= 0) {
							if (a_textval.length > 2) {
								div_font[k] = a_textval[2]
							}
						}
						if (a_textval.length > 3) {
							div_style[k] = a_textval[3]
						}
						if (txml.toLowerCase() == document.preview.templateXML.value.toLowerCase() || txml.length <= 0) {
							if (a_textval.length > 4) {
								div_align[k] = a_textval[4]
							}
							if (a_textval.length > 5) {
								div_color[k] = a_textval[5]
							}
							if (a_textval.length > 6) {
								div_color_hex[k] = a_textval[6]
								//050306if (a_textval[6] == "#C2DFFC" && div_color[k] == "4")  {
								//	div_color[k] == "0"
								//}
							}
							if (a_textval.length > 7) {
								div_x[k] = parseFloat(a_textval[7])
							}
							if (a_textval.length > 8) {
								div_y[k] = parseFloat(a_textval[8])
							}
							if (a_textval.length > 9) {
								div_w[k] = parseFloat(a_textval[9])
							}
							if (a_textval.length > 10) {
								div_h[k] = parseFloat(a_textval[10])
							}

							if (a_textval.length > 11) {
								div_leading[k] = a_textval[11]
							}
							if (a_textval.length > 12) {
								div_rule[k] = false
								if (a_textval[12].toLowerCase() == "true")  {
									div_rule[k] = true
								}
							}
							if (a_textval.length > 13) {
								div_valign[k] = a_textval[13]
							}
							if (a_textval.length > 14) {
								div_hidden[k] = false
								if (a_textval[14].toLowerCase() == "true")  {
									div_hidden[k] = true
								}
							}
						}		
						
						if (GetElement(["elementcolor_" + k + "_" + div_color[k]])) {
							GetElement(["elementcolor_" + k + "_" + div_color[k]]).bgColor = "#" + eval("thcolorno" + div_color[k])
						}										
						if (flag_Numbering2) {
							if (div_fields[k] == flag_NumField2) {
								var tNumberingCharge = getValueFromCookie("NumberingCharge")
								document.preview.NumberingCharge.value = tNumberingCharge
							}
						}
						if (flag_Numbering1) {
							if (div_fields[k] == flag_NumField1) {
							//alert(div_fields[k] + "..." + flag_NumField1)
								if (document.preview.chknumbering) {
									document.preview.chknumbering.checked = false
									div_hidden[k] = true
									if (getValueFromCookie("chknumbering") == "true") {
										document.preview.chknumbering.checked = true
										div_hidden[k] = false
									}
									//alert("div_hidden[k] :" + div_hidden[k])
									document.preview.numbering.value = div_text[k]
								}
							}
						}						
					}
				}
			}
			else if (div_contents[k].indexOf('image') >= 0) {
				if (div_fields[k].length > 0) {
					tval = getValueFromCookie(div_fields[k])
					var a_textval = tval.split('~')
					if (a_textval[0].length > 0) {
						div_text[k] = a_textval[0]
					}
					if (txml.toLowerCase() == document.preview.templateXML.value.toLowerCase() || txml.length <= 0) {
						if (a_textval.length > 1) {
							div_x[k] = parseFloat(a_textval[1])
						}
						if (a_textval.length > 2) {
							div_y[k] = parseFloat(a_textval[2])
						}
						if (a_textval.length > 3) {
							div_w[k] = parseFloat(a_textval[3])
						}
						if (a_textval.length > 4) {
							div_h[k] = parseFloat(a_textval[4])
						}
						if (a_textval.length > 5) {
							div_transcolor[k] = a_textval[5]
						}
						if (a_textval.length > 6) {
							div_imagecolor[k] = a_textval[6]
						}
						if (a_textval.length > 7) {
							if (a_textval[7].toLowerCase() == "true")  {
								div_hidden[k] = a_textval[7]
							}
						}
					}
				}
			}
			else if (div_contents[k].indexOf('rectangle') >= 0) {
				tval = getValueFromCookie('RECT' + k)
				if (tval.length > 0) {
					var a_textval = tval.split('~')
					if (txml.toLowerCase() == document.preview.templateXML.value.toLowerCase() || txml.length <= 0) {
						if (a_textval.length > 1) {
							div_x[k] = parseFloat(a_textval[1])
						}
						if (a_textval.length > 2) {
							div_y[k] = parseFloat(a_textval[2])
						}
						if (a_textval.length > 3) {
							div_w[k] = parseFloat(a_textval[3])
						}
						if (a_textval.length > 4) {
							div_h[k] = parseFloat(a_textval[4])
						}
						if (a_textval[5].length > 0) {
							div_color[k] = a_textval[5]
						}
						if (a_textval[6].length > 0) {
							div_bgcolor[k] = a_textval[6]
						}
						if (a_textval[7].length > 0) {
							div_outlinewt[k] = a_textval[7]
						}
						if (a_textval.length > 8) {
							if (a_textval[8].toLowerCase() == "true")  {
								div_hidden[k] = a_textval[8]
							}
						}
					}
				}			
			
				if (div_color[k].length > 0) {
					if (document.preview["hcolorno" + div_color[k]].value.length > 0) {
						div_color_hex[k] = "#" + document.preview["hcolorno" + div_color[k]].value
					}
				}
				if (div_bgcolor[k].length > 0) {
					if (document.preview["hcolorno" + div_bgcolor[k]].value.length > 0) {
						div_bgcolor_hex[k] = "#" + document.preview["hcolorno" + div_bgcolor[k]].value
					}
				}
				
			}
			
		}
	}
	
	Flash_UpdateFlashObjects();
	
    //alert("Objects Variables set")
	if (flag_ANSICompliant) {
		if (document.preview.chkansicompliant) {
			document.preview.chkansicompliant.checked = true
			if (getValueFromCookie("ansicompliant") == "false") {
				document.preview.chkansicompliant.checked = false
			}
			RefillMarkerColors()
		}
	}		

	if (xcatgid == '512' && xsubcatgid.toLowerCase() == "holidaycards") {
		tPrintColors = getValueFromCookie("PrintColors")
		if (tPrintColors.length > 0) {
			document.preview.ColorCode.value = GetColorCode(tPrintColors)	
			document.preview.PrintColors.value = tPrintColors
		}
	}
	
	if (xLogoPositions.length > 0) {
		if (currobj.logo_pos) {
			var tlogopos = getValueFromCookie("LOGOPOS")
			if (tlogopos.length > 0) {
				var xindex = getobjectno(flag_GraphicField)
				if (xindex > 0) {
					SetIndicativePos(tlogopos)
				}
			}
		}
	}
	
	if (flag_Text_GroupFonts) {
		if (document.preview.optfonttype) {
			SetLBLastSel(document.preview.optfonttype, "DefaultFont")
		}
	}
	
	if (flag_BarCode) {
		if (document.preview.listbarcode) {
			SetLBLastSel(document.preview.listbarcode, "Symbology")
		}
	}

	if (currobj.catgid.value==77){
		var tPadColor = getValueFromCookie("PadColor")
		currobj.PadColor.value = tPadColor
		xPadColor = tPadColor
		//Swapped state is also stored in cookies. Thought, some one might want to use it.

		//11-03-05
		document.preview.LogoColorFlag.value = getValueFromCookie("LogoColorFlag")
		//alert(document.preview.LogoColorFlag.value)
		//11-03-05

	}
    //	alert("Objects Variables init complete")
}

function SetLBLastSel(tobj, tvar) {
	var tvalue = getValueFromCookie(tvar)
	if (tvalue.length > 0) {
		for (k=0; k<tobj.length; k++) {
			if (tobj.options[k].value == tvalue) {
				tobj.selectedIndex = k;
				break;
			}
		}
	}
}

function getValueFromCookie(yfield) {
	var xvalue = "";
	var c_subcatgid="";
	var c_catgid="";
	if (a_names.length > 1) {
		c_subcatgid = a_values[a_names.length-1].toUpperCase();
		c_catgid = a_values[a_names.length-2].toUpperCase();
		if (c_catgid == document.preview.catgid.value.toUpperCase() && c_subcatgid == document.preview.SubCatgId.value.toUpperCase()) {
			for (var j=0; j<a_names.length; j++) {
				if (a_names[j].toUpperCase() == yfield.toUpperCase()) {
					xvalue = a_values[j]
				}
			}
		}
	}
	return xvalue;
}

function getOtherStoredNVP(ynames, yvalues, ysep) {
	var t_nvp = new Array()
	t_nvp[0] = ""
	t_nvp[1] = ""
	var xvalue = "";
	var c_subcatgid="";
	var c_catgid="";

	var t_names = ynames.split(ysep)
	var t_values = ynames.split(ysep)

	if (a_names.length > 1) {
	    //alert(a_names.length + "name length")
	    //alert(a_values.length + "value length")
	    if (a_names.length == a_values.length) {
		    c_subcatgid = a_values[a_names.length-1].toUpperCase();
		    c_catgid = a_values[a_names.length-2].toUpperCase();
		    if (c_catgid == document.preview.catgid.value.toUpperCase() && c_subcatgid == document.preview.SubCatgId.value.toUpperCase()) {
			    for (var j=0; j<a_names.length; j++) {
				    xfound = false
				    for (var m=0; m<t_names.length; m++) {
					    if (t_names[m] == a_names[j]) {
						    xfound = true
						    break;
					    }
				    }
				    if (!xfound) {
					    if (t_nvp[0].length > 0) {	
						    t_nvp[0] = t_nvp[0] + ysep
						    t_nvp[1] = t_nvp[1] + ysep
					    }
					    t_nvp[0] = t_nvp[0] + a_names[j]
					    t_nvp[1] = t_nvp[1] + a_values[j]
				    }
			    }
		    }
		}
	}

	return t_nvp;
}

function StoreLinesEntered() {
	xlinectr=0;
	for (k=1; k<num_divs; k++) {
		if (div_contents[k]) {
			if (div_contents[k].indexOf("label") >= 0) {
				if (div_fields[k].toUpperCase().indexOf('GROUP') < 0) {
					if (trim_(div_text[k]).length > 0) {
						xlinectr++;
					}
				}
			}
		}
	}
	if (document.preview.LinesEntered) {
		document.preview.LinesEntered.value = xlinectr
	}
}

function StorePrintInfo() {
	var xNOL = 0;
	xprintflag = 'B';
	for (k=1; k<num_divs; k++) {
		if (div_fields[k]) {
			if (div_fields[k].toUpperCase().indexOf("TEXTLINE") >= 0) {
				if (trim_(div_text[k]).length > 0) {
					xprintflag = 'P';
					xNOL = xNOL + 1
				}
			}
		}
	}
	if (xreq_currside == '1') {
		document.preview.NOLEnvelope.value = xNOL
		document.preview.PrintInfoEnvelope.value = xprintflag
	}
	else {
		document.preview.NOLCard.value = xNOL
		document.preview.PrintInfo.value = xprintflag
	}
}

function StoreColorInfo(yCategory) {
	var xused = "";
	var xusednum = "";
	var xhexcolor="";
	var xblack, xred, xreflexblue, xburgundy;
	for (k=1; k<num_divs; k++) {
		xhexcolor="";
		if (div_contents[k]) {
			if (div_contents[k].indexOf('label') >= 0) {
				if (trim_(div_text[k]).length > 0) {
					if (div_color_hex[k]) {
						if (div_color_hex[k].length > 0 && div_color_hex[k].indexOf('#') < 0) {
							div_color_hex[k] = '#' + div_color_hex[k]
						}
						xhexcolor = div_color_hex[k]
						xcolornum = div_color[k]
					}
				}
			}
			else if (div_contents[k].indexOf('image') >= 0) {
				if (div_imagecolor[k]) {
					if ( div_imagecolor[k].length > 0 && (!div_hidden[k]) && (div_text[k].indexOf('null.gif') < 0) ) {
						xhexcolor = div_imagecolor[k]
						xcolornum = 4
						for (j=0; j<=4; j++) {
							if (document.preview["hcolorno" + j].value == xhexcolor.split('#').join('')) {
								xcolornum = j
							}
						}
					}
				}
			}
			xhexcolor = xhexcolor.split('undefined').join('')
			if (xhexcolor.length > 0) {
				if (xhexcolor == C_BLACK || xhexcolor == C_PROCESS_BLACK) {
					xblack = true
				}
				if (xhexcolor == C_REFLEX_BLUE) {
					xreflexblue = true
				}
				if (xhexcolor == C_RED) {
					xred= true
				}
				if (xhexcolor == C_BURGUNDY) {
					xburgundy = true
				}
				if (xused.indexOf(xhexcolor) < 0) {
					if (xhexcolor.length > 0) {
						if (xused.length > 0) {
							xused = xused + ";"
							xusednum = xusednum + ";"
						}
						xused = xused + xhexcolor
						xusednum = xusednum + xcolornum
					}
				}
			}
		}
	}

	var xcolorgroup = "STD";
	if (xused.length > 0 && (yCategory == 'logo' || yCategory == 'value' || yCategory.indexOf('letterhead') >= 0 || yCategory.indexOf('envelope') >= 0 ) ) {
		var a_used  = xused.split(";")
		var xcolorused = a_used.length
		if (xcolorused == 1) {
			if (xblack) {
				xcolorgroup = "STD"
			}
			else {
				xcolorgroup = "ECO"
			}
		}
		else if (xcolorused >= 2) {
			if (xblack) {
				if (xred || xreflexblue) {
					xcolorgroup = "VAL"
				}
				else {
					xcolorgroup = "PRE"
				}
			}
			else {
				xcolorgroup = "PRE"
			}
		}
	}
	document.preview.HexColorsUsed.value = xused
	document.preview.ColorNumbersUsed.value = xusednum
	document.preview.ColorGroup.value = xcolorgroup
}

function changeSide(icurrside) {
var ppmtVars='', yindex
	if (flag_Graphic_QualitySensor) {
		if (!VerifyImageResolution()) {
			return;
		}
	}
	
	if (xsubcatgid == 'holidaycards') {
		StorePrintInfo()
	}
	if (icurrside == '0') {
		currobj.currside.value='0'
		SendVars()
		currobj.currside.value='1'
		
		if (xcatgid == "777" || xcatgid == "38") {
			//This is not a good idea. It messes up the design after the order is placed. 
			//And I also believe that just to reapeat the same text on the back side is little bit of a shock for the user. 
			//I think it is better to avoid this at this time. 04/24/2007
			document.preview.dspecsB.value = document.preview.dspecs.value
		}

		if (xcatgid == "77") {
			yindex=getobjectno("COMPANY")
			if (yindex!=-1){
				currobj.ppmtVars.value=div_text[yindex]+'~~'+div_font[yindex]+'~~'+backgroundimage
			}else{	//if company not found
				if (document.preview.optfonttype) {
					currobj.ppmtVars.value=''+'~~'+document.preview.optfonttype.options[document.preview.optfonttype.options.selectedIndex].value+'~~'+backgroundimage
				}
			}
		}	

		if (flag_Bg_Validate) {
			if (backgroundimage.toLowerCase().indexOf('blank') >= 0 || backgroundimage.toLowerCase().indexOf('null') >= 0) {
				alert("Place the background graphic first.")
				return;
			}
		}
		
		if (flag_Photo_Validate) {
			yindex=getobjectno(flag_PhotoField)
			isrcimagename = trim_(div_text[yindex])
			if (isrcimagename.toLowerCase().indexOf("croppedimages") < 0 && isrcimagename.toLowerCase().indexOf("medres/") < 0) {
				alert("Place the photo first.")
				return;
			}
			if (isrcimagename.toLowerCase().indexOf('null.gif') >= 0) {
				alert("Place the photo first.")
				return
			}	
		}

		var xsideprefix = ""
		if (xThisSide == "Back") {
			xsideprefix = "B_"
		}

		var xprefix = "xp5_" + document.preview.CompName.value + "_" + xsideprefix

		StoreWizardPreferences(xprefix)

		if (xsubcatgid.toLowerCase().indexOf("idbadges") >= 0) {
			tindex = getobjectno(F_FULLNAME)
			if (tindex > 0) {
				document.preview.designname.value = div_text[tindex]
			}
			else {
				tindex = getobjectno("TEXTLINE1")
				if (tindex > 0) {
					document.preview.designname.value = div_text[tindex]
				}
			}
		}
		currobj.action = 'WizardA.asp'
		currobj.target = '_self'
		currobj.submit()
	}
	if (icurrside == '1') {
		currobj.currside.value='1'
		SendVars()
		currobj.currside.value='0'
		var xsideprefix = ""
		if (xThisSide == "Back") {
			xsideprefix = "B_"
		}

		var xprefix = "xp5_" + document.preview.CompName.value + "_" + xsideprefix
		StoreWizardPreferences(xprefix)
		currobj.action = 'WizardA.asp'
		currobj.target = '_self'
		currobj.submit()
	}
}

function getobjectno(fldname) {
	for(var i=1; i<num_divs; i++) {
		if (div_fields[i]){
			if (div_fields[i].toUpperCase()==fldname.toUpperCase()) {
				return i
			}
		}
	}
	return -1
}

function showColors(colorno, yindex) {
var urlstr=''
	if (!yindex) {
		yindex = 0
	}
	xwidth=300;
	xheight=370;
	
	xleft = (screen.width-xwidth)/2
	xtop = (screen.height-xheight)/2
	
	urlstr='select_print_color.asp?colorno='+colorno+'&yindex='+yindex+'&vendor='+xvendor+'&subcatgid='+xsubcatgid
	xwin = window.open(urlstr,'colorwin', 'left='+xleft+',top='+xtop+',width='+xwidth+',height='+xheight+',resizable')
}

function showAdvanceColors(colorno, yindex) {
var urlstr=''

	if (IfBarcodeExists() && colorno == "1") {
		alert("This color can not be changed. \nIt is reserved for Barcode.") 
		return;
	}
	
	if (!yindex) {
		yindex = 0
	}
	xwidth=320;
	xheight=430;
	
	xleft = (screen.width-xwidth)/2
	xtop = (screen.height-xheight)/2
		
	urlstr='select_advance_colors.asp?colorno='+colorno+'&yindex='+yindex
	xwin = window.open(urlstr,'colorwin', 'left='+xleft+',top='+xtop+',width='+xwidth+',height='+xheight+',resizable')
}

function AddtoColorList_Old(ycolor, ycolorhex) {
	if (ycolor != 0) {
		if (xusedcolors.indexOf(ycolor) < 0) {
			if (xusedcolors.length > 0) {
				xusedcolors = xusedcolors + "," 
			}
			xusedcolors = xusedcolors + ycolor
		}
	}
}

function AddtoColorList(ycolor, ycolorhex) {
	if (ycolor != 0) {
		if (xusedhexcolors.indexOf(ycolorhex) < 0) {
			if (xusedhexcolors.length > 0) {
				xusedhexcolors = xusedhexcolors + "," 
				xusedcolors = xusedcolors + "," 
			}
			xusedhexcolors = xusedhexcolors + ycolorhex
			xusedcolors = xusedcolors + ycolor
		}
	}
}

var xusedcolors = "";
var xusedhexcolors = "";

var xTotalUsedColors=0;
function CalcColorsUsed() {

	xusedcolors = "";
	xusedhexcolors = "";
	xTotalUsedColors = 0
	for (var k=1; k<num_divs; k++) {
		if (div_contents[k]) {
			if (div_contents[k].indexOf('label') >= 0) {
				if (div_color[k]) {
					if (div_text[k].length > 0 && div_fields[k].indexOf('GROUP') < 0 && div_fields[k].indexOf('SPACE') < 0) {
						//alert(div_fields[k])
						AddtoColorList(div_color[k], div_color_hex[k])
					}
				}
			}
			else if (div_contents[k].indexOf('rectangle') >= 0) {
				if (div_color[k]) {
					AddtoColorList(div_color[k], div_color_hex[k])
				}
				if (div_bgcolor[k]) {
					if (document.preview["hcolorno"+div_bgcolor[k]].value!='F6F6F6'){	//colorno 4 is used to make the rectangle transparent, ignore it
						AddtoColorList(div_bgcolor[k], div_bgcolor_hex[k])
					}
				}
			}
		}
	}
	//alert(xusedhexcolors + "..." + xusedcolors)
	a_usedcolors = xusedcolors.split(',')
	xTotalUsedColors = a_usedcolors.length

	document.preview.usedcolors.value = xTotalUsedColors
	return xTotalUsedColors;
}

function change_arrow_image(arrowtype){
	if (arrowtype==0){
		placeArrow('ARROW1', 'null.gif')
		placeArrow('ARROW2', 'null.gif')
	}
	else if (arrowtype==1){
		placeArrow('ARROW1', 'arrow3l.gif')
		placeArrow('ARROW2', 'arrow3l.gif')
	}
	else if (arrowtype==2){
		placeArrow('ARROW1', 'arrow3r.gif')
		placeArrow('ARROW2', 'arrow3r.gif')
	}
	else if (arrowtype==3){
		placeArrow('ARROW1', 'arrow3u.gif')
		placeArrow('ARROW2', 'arrow3u.gif')
	}
	else if (arrowtype==4){
		placeArrow('ARROW1', 'arrow3d.gif')
		placeArrow('ARROW2', 'arrow3d.gif')
	}

	if (currobj.templateXML.value.toLowerCase().indexOf('ware_racks_')>=0){
		swap_arrow_textboxes(arrowtype)
	}
}

function placeArrow(arrowfld, arrowimgname){
var yindex
	yindex = getobjectno(arrowfld)
	if (yindex!=-1){
		changeImage(yindex, "", arrowimgname, arrowimgname, 0);
	}
}

function show_hide_numbering(val) 
{	
	//alert("show_hide_numbering of wizard_wizarda.js")
	for(var i =0; i < num_divs; i++) {
		if ( div_fields[i])	{
			if (div_fields[i].toLowerCase().indexOf('number') >= 0)	{	
					
				if (val == true) {
					//numbering present 
					div_text[i] = document.preview.numbering.value;	
					div_hidden[i] = false;
					currobj.NumberingCharge.value = 1;
				}			
				else {
					//numbering absent
					div_hidden[i] = true;
					currobj.NumberingCharge.value = 0;
				}
				
				FlashShowHideNumEntry(i)
				break;
			}
		}
	}
}

function save_exit(){
	GenerateNVP()  

	SendVars()
	
	SetSplInst()
	CalculateQty()	
	
	currobj.action='resaveartwork.asp'
	currobj.submit()
}

function ChangeOutlineWeight(yval) {
	if (yval == "0") {
		bkoutline_weight = "1"
		bkoutline_weight = 1
		outline_color_RGB = "#AAAAAA"
	}
	else {
		bkoutline_weight = yval
		bkoutline_weight = yval
		outline_color_RGB = "#" + document.preview["hcolorno" + iforecolornum].value

	}
	
	Flash_UpdateFlashObjects()
}

function ChangeOutlineColor() {
	if (bkoutline_weight > 0) {
		GetElement("background").style.borderColor = tColor
	}
}

function SaveAndCreateMore() {
	document.preview.SaveAndCreateMore.value = "1"

	if (xcatgid == '50') {	
		//XpressTabs or any wizard which may have "set" system of ordering.
		document.preview.action = "productset_ReadyToOrder.asp"
	}else{
		document.preview.action = "product_ReadyToOrder.asp"
	}
	document.preview.submit()
}

function AccessReadyToOrderBadges() {
	if (xcatgid == '50') {	
		//XpressTabs or any wizard which may have "set" system of ordering.
		document.preview.action = "productset_ReadyToOrder.asp"
	}else{
		document.preview.action = "product_ReadyToOrder.asp"
	}
	document.preview.submit();
}

var xwinpop = null;
function PopupSelect(xfilename, xwidth, xheight) {
	var xleft = (screen.width - xwidth)/2
	var xtop = (screen.height - xheight)/2
	
	xurlstr = "catgid=" + xcatgid + "&subcatgid=" + xsubcatgid
	if (xfilename.indexOf("?") < 0) {
		xfilename = xfilename + "?"
	}
	else {
		xurlstr = "&" + xurlstr 
	}
	xfilename = xfilename + xurlstr
	xwinpop = window.open(xfilename, 'winpop', 'left='+xleft+',top='+xtop+',width='+xwidth+',height='+xheight+',resizable,scrollbars')
}

var xwindata = null;
function TestWindow(xfilename, xwidth, xheight) {
	var xleft = (screen.width - xwidth)/2
	var xtop = (screen.height - xheight)/2
	
	xside = ""
	
	xfilename = "ListUserData.asp"
	
	xurlstr = "catgid=" + xcatgid + "&subcatgid=" + xsubcatgid + "&side=" + xside
	xurlstr = xurlstr + "&text_historygroup=" + flag_Text_HistoryGroup 
	if (xfilename.indexOf("?") < 0) {
		xfilename = xfilename + "?"
	}
	else {
		xurlstr = "&" + xurlstr 
	}
	xfilename = xfilename + xurlstr
	xwinpop = window.open(xfilename, 'windata', 'left='+xleft+',top='+xtop+',width='+xwidth+',height='+xheight+',resizable,scrollbars')
}

function ApplyIt(ytext, yfield) {
	for (var k=1; k<num_divs; k++) {
		if (div_contents[k]) {
			if (div_contents[k].indexOf('label') >= 0) {
				if (div_fields[k]) {
					if (div_fields[k].toUpperCase() == yfield) {
						if (document.preview["textfield" + k]) {
							document.preview["textfield" + k].value = ytext
						}
						div_text[k] = ytext;
						if (flag_Text_ClearOnFocus) {
							if (!a_cleared[k]) {
								SetTextfieldProperties(k, true)
							}
						}
						changeText(div_text[k], k)
					}
				}
			}
		}
	}
	if (xwinpop) {
		xwinpop.close();
	}
}

function ShowPopupImage(yzoomimage) {
	var xwidth = 600
	var xheight= 500
	var xleft = (screen.width - xwidth)/2
	var xtop = (screen.height - xheight)/2
	
	var xwin1 = window.open("showdetails.asp?myimage=" + yzoomimage	, 'win1', 'left='+xleft+',top='+xtop+',width='+xwidth+',height='+xheight+',resizable')
}

function GetColorCode(ypms) {
	for (k=0; k<a_hcpms.length; k++) {
		if (a_hcpms[k] == ypms) {
			return a_hccode[k];
		}
	}
	return 'ZZ';
}

function RestoreDefaults() {
	for (var k=1; k<num_divs; k++) {
		div_x[k] = olddiv_x[k]
		div_y[k] = olddiv_y[k]
		div_w[k] = olddiv_w[k]
		div_h[k] = olddiv_h[k]
	}
	
	for (var k=1; k<num_divs; k++) {
		if (div_contents[k]) {
			if (div_contents[k].indexOf('label') >= 0) {
				yindex=getgroupdivno(i)
				if (div_group[k].indexOf('-0') >= 0) {
					changeText(div_text[k], k)
				}
			}
		}
	}
}

function MM_openBrWindow(theURL,winName,features) { 
	if (theURL.toLowerCase().indexOf('showdetails.asp')>=0){
		window.open(theURL,winName,features);
	}else if (theURL.toLowerCase().indexOf('.gif')>0 || theURL.toLowerCase().indexOf('.jpg')>0){
		window.open('showimagefromurl.asp?myimage='+theURL,'','resizable=yes,width=220,height=22')
	}else{
		window.open(theURL,winName,features);
	}
}

function ShowHideTextSection(yval) {
	if (yval == "2") {
		currobj.BacksidePrintCharge.value = 0
	}else{
		currobj.BacksidePrintCharge.value = 1
	}

	for (k=1; k<num_divs;k++) {
		if (div_contents[k]) {
			if (div_contents[k].indexOf('label') >= 0) {
				if (document.preview["textfield" + k]) {
					if (document.preview["textfield" + k]) {
						if (yval == "2") {
							document.preview["textfield" + k].disabled = true
							div_text[k] = ""
							changeText(div_text[k], k)
						}
						else {
							document.preview["textfield" + k].disabled = false
							div_text[k] = document.preview["textfield" + k].value
							changeText(div_text[k], k)
						}
					}
				}
			}
		}
	}
}

function ShowBarCodeGuide() {
	xleft = (screen.width - 600) / 2
	xtop = (screen.height - 550) / 2
	winhandle = window.open('BarCodeGuide.asp', 'hidden', 'left=' + xleft + ',top=' + xtop + ',width=600, height=550, location=no, resizable=yes, scrollbars=yes')
}

function SetRuleState() {
	for (var k=1; k<num_divs; k++) {
		if (div_contents[k]) {
			if (div_contents[k].indexOf('label') >= 0) {
				if (div_rule[k]) {
					if (document.preview["cb_ruletext" + k]) {
						document.preview["cb_ruletext" + k].checked = true
						ShowHideRule(k, document.preview["cb_ruletext" + k])
						if (GetElement(["cb_rulediv" + k])) {
							GetElement(["cb_rulediv" + k]).style.display = "block"
						}
					}
				}
			}
		}
	}
}

function HideAllObjects() {
	for(var i=1; i<num_divs; i++) {
	    div_hidden[i] = true;
	}
}

function MM_showHideLayers() { 
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function HideImage(xfieldname) {
	if (flag_GraphicField.length > 0) {
		xindex = GetFieldIndex(xfieldname)
		if (xindex > 0) {
			div_hidden[xindex] = true
		}
	}
}

function ShowImage(xfieldname) {
	if (flag_GraphicField.length > 0) {
		xindex = GetFieldIndex(xfieldname)
		if (xindex > 0) {
			div_hidden[xindex] = false
		}
	}
}

function ReplaceBgColor(ypms, yhex) {
	//In case of equipment nameplates, 
	//the background fill color is color no. 1
	document.preview.hcolorno1.value = yhex.split('#').join('')	
	fill_color_RGB= yhex
	Flash_UpdateFlashObjects()
}

function HideGroup(xgroupno) {
	for (var k=num_divs-1; k>=1; k--) {
		if (div_group[k]) {
			if (div_group[k].indexOf(xgroupno + "-") >= 0) {
				if (!div_hidden[k]) {
					div_hidden[k] = true
				}
			}
		}
	}
}

function ShowGroup(xgroupno) {
	for (var k=num_divs-1; k>=1; k--) {
		if (div_group[k]) {
			if (div_group[k].indexOf(xgroupno + "-") >= 0) {
				div_hidden[k] = false
			}
		}
	}
}

function BackColorSwatch_NoLink() {
	var tstr = '';
	tstr = '		<table border="0" cellspacing="0" cellpadding="0">'
	tstr = tstr + '		<tr>'
	tstr = tstr + '			<td id="printcolor3" bgcolor="#' + document.preview.hcolorno3.value + '" width="36"><img src="images/space.gif" width="36" height="15" style="border-color:#AAAAAA;border-width:1px;border-style=solid;"></td>'
	tstr = tstr + '		</tr>'
	tstr = tstr + '	</table>'
	if (GetElement(div_backswatch)) {
		GetElement(div_backswatch).innerHTML = tstr
	}
}

function BackColorSwatch_WithLink() {
	var tstr = '';
	tstr = '		<table border="0" cellspacing="0" cellpadding="0">'
	tstr = tstr + '		<tr>'
	tstr = tstr + '			<td id="printcolor3" bgcolor="#' + document.preview.hcolorno3.value + '"  width="36"><a href="javascript:showAdvanceColors(3)"><img src="images/space.gif" width="36" height="15" style="border-color:#AAAAAA;border-width:1px;border-style=solid;"></a></td>'
	tstr = tstr + '		</tr>'
	tstr = tstr + '	</table>'
	if (GetElement(div_backswatch)) {
		GetElement(div_backswatch).innerHTML = tstr
	}
}

function UpdateDyeSubColors(yradval) {
	if (yradval == 1) {
		BackColorSwatch_NoLink()
		ShowGroup(2)
		ShowImage(flag_GraphicField + "2")
		colorno=3
		iColor = document.preview.hcolorno2.value.split("#").join("")
		iColorName = document.preview.hcolorname2.value
		
		changePrintColors(colorno, iColor, iColorName, 0, "")

		colorno=4
		iColor = document.preview.hcolorno1.value.split("#").join("")
		iColorName = document.preview.hcolorname1.value
		changePrintColors(colorno, iColor, iColorName, 0, "")
	}
	else if (yradval == 2) {
		BackColorSwatch_NoLink()
		ShowGroup(2)
		ShowImage(flag_GraphicField + "2")
		//reverse text and fill color for the back side
		colorno=3
		iColor = document.preview.hcolorno1.value.split("#").join("")
		iColorName = document.preview.hcolorname1.value
		changePrintColors(colorno, iColor, iColorName, 0, "")
		
		colorno=4
		iColor = document.preview.hcolorno2.value.split("#").join("")
		iColorName = document.preview.hcolorname2.value
		changePrintColors(colorno, iColor, iColorName, 0, "")
	}
	else if (yradval == 3) {
		BackColorSwatch_WithLink()
		HideGroup(2)		
		HideImage(flag_GraphicField + "2")
	}
}

function MM_preloadImages() { 
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ChangeCurrentFont(yfont) {
	if (document.preview.selection) {
		var xobj = document.preview.selection
		yindex = xobj.options[xobj.selectedIndex].value
		if (yindex > 0) {
			if (div_contents[yindex]) {
				if(div_contents[yindex]==zz_label || div_contents[yindex]==zz_plabel) {
					div_font[yindex] = yfont
					changeText(div_text[yindex], yindex)
				}
			}
		}
	}

}

function ChangeCurrentSize(ysize) {
	if (document.preview.selection) {
		var xobj = document.preview.selection
		yindex = xobj.options[xobj.selectedIndex].value
		if (yindex > 0) {
			if (div_contents[yindex]) {
				if(div_contents[yindex]==zz_label || div_contents[yindex]==zz_plabel) {
					div_size[yindex] = ysize
					changeText(div_text[yindex], yindex)
				}
			}
		}
	}

}

function ChangeCurrentLeading(yleading) {
	if (document.preview.selection) {
		var xobj = document.preview.selection
		yindex = xobj.options[xobj.selectedIndex].value
		if (yindex > 0) {
			if (div_contents[yindex]) {
				if(div_contents[yindex]==zz_label || div_contents[yindex]==zz_plabel) {
					div_leading[yindex] = yleading
					Flash_UpdateLeading(yindex, div_leading[yindex])
				}
			}
		}
	}
}

function ChangeCurrentAlign(yalign) {
	if (document.preview.selection) {
		var xobj = document.preview.selection
		yindex = xobj.options[xobj.selectedIndex].value
		if (yindex > 0) {
			if (div_contents[yindex]) {
				if(div_contents[yindex]==zz_label || div_contents[yindex]==zz_plabel) {
					div_align[yindex] = yalign
					flashAlignAll(yalign, yindex)
				}
			}
		}
	}
	
    
}

function DrawBorderAndCorner(yindex) {
//	var xindex = getgroupdivno(yindex)
//	movehotspots(xindex)
//	hidehotspots()


//	for (k=1;k<num_divs;k++) {
//		if (div_contents[k]=="image" || div_contents[k]=="pimage" || div_contents[k]=="label" || div_contents[k]=="plabel") {
//			xobjname = getRS(zz_bgnestref, zz_document, zz_all, joinParam(zz_div, k))
//			if (xobjname){
//				removeborder(xobjname, k)
//			}
//		}
//	}

//	xobjname = getRS(zz_bgnestref, zz_document, zz_all, joinParam(zz_div, xindex))
//	if (xobjname){
//		if (div_contents[xindex] == zz_plabel) {
//			drawborder(xobjname,div_bordersize[yindex]*xzoomper, "solid", defbordercolor, xindex)   
//		}
//		else {
//			if (div_contents[yindex] == zz_pimage) {
//				origwidth = parseFloat(div_w[yindex]) * 2 
//				origheight = parseFloat(div_h[yindex]) * 2 
//			    drawborder(xobjname,defborderwidth, "solid", defbordercolor, yindex)
//		    	showhotspots()
//			}
//		}
//	}
}

function SetUserDefinedColors(ycolorno, yhexcolor, ypcolor) {
	xobj = document.preview.schemes
	if (xobj) {
		if (xobj.options[xobj.selectedIndex].text == "User Defined") {
			if (ycolorno == 1) {
				a_hbanner[xmaxindex] = yhexcolor
				a_banner[xmaxindex] = ypcolor
			}
			else if (ycolorno == 2) {
				a_hbannertext[xmaxindex] = yhexcolor
				a_bannertext[xmaxindex] = ypcolor
			}
			else if (ycolorno == 3) {
				a_hheading[xmaxindex] = yhexcolor
				a_heading[xmaxindex] = ypcolor
			}
			else if (ycolorno == 4) {
				a_htext[xmaxindex] = yhexcolor
				a_text[xmaxindex] = ypcolor
			}
		}
	}
}

function ShowSchemeColors(yscheme) {

	changePrintColors('1', a_hbanner[yscheme], a_banner[yscheme], '-1', a_banner[yscheme], 'PMS')
	changePrintColors('2', a_hbannertext[yscheme], a_bannertext[yscheme], '-1', a_bannertext[yscheme], 'PMS')
	changePrintColors('3', a_hheading[yscheme], a_heading[yscheme], '-1', a_heading[yscheme], 'PMS')
	changePrintColors('4', a_htext[yscheme], a_text[yscheme], '-1', a_text[yscheme], 'PMS')

	document.preview.hcolorno1.value = a_hbanner[yscheme]
	document.preview.hcolorno2.value = a_hbannertext[yscheme]
	document.preview.hcolorno3.value = a_hheading[yscheme]
	document.preview.hcolorno4.value = a_htext[yscheme]

	document.preview.hpantone1.value = a_banner[yscheme]
	document.preview.hpantone2.value = a_bannertext[yscheme]
	document.preview.hpantone3.value = a_heading[yscheme]
	document.preview.hpantone4.value = a_text[yscheme]


	for(var k=1; k<num_divs; k++) {
		if(div_contents[k]==zz_label || div_contents[k]==zz_plabel) {
			if (div_color[k] == 1) {
				div_color_hex[k] = "#" + document.preview.hcolorno1.value	
			}
			if (div_color[k] == 2) {
				div_color_hex[k] = "#" + document.preview.hcolorno2.value
			}
			if (div_color[k] == 3) {
				div_color_hex[k] = "#" + document.preview.hcolorno3.value
			}
			if (div_color[k] == 4) {
				div_color_hex[k] = "#" + document.preview.hcolorno4.value
			}
			
		}

		if(div_contents[k]==zz_rectangle || div_contents[k]==zz_prectangle) {
			if (div_bgcolor[k] == 1) {
				div_bgcolor_hex[k] = "#" + document.preview.hcolorno1.value
			}
			if (div_bgcolor[k] == 2) {
				div_bgcolor_hex[k] = "#" + document.preview.hcolorno2.value
			}
			if (div_bgcolor[k] == 3) {
				div_bgcolor_hex[k] = "#" + document.preview.hcolorno3.value
			}
			if (div_bgcolor[k] == 4) {
				div_bgcolor_hex[k] = "#" + document.preview.hcolorno4.value
			}
		}
	}
	
	Flash_Update_RectAndTextObjColors();
	
}

function FillUserDefined(xgroupname, xhexcolor, xpcolor) {
	xhexcolor = "" + xhexcolor
	xud = 0
	var xobj = document.preview.schemes;
	
	if (!xobj) return;
	
	for (var k=0;k<xobj.length;k++) {
		if (xobj.options[k].text == "User Defined") {
			xud = k
			break;
		}
	}
	xcurrindex = xobj.selectedIndex
	xmaxindex = xobj.length
	if (xud == 0) {
		xmaxindex++;
		xcurrindex++;
		a_id[xmaxindex] = xmaxindex+1;
		a_colorscheme[xmaxindex] = "User Defined" ;
		a_banner[xmaxindex] = a_banner[xcurrindex] ;
		a_bannertext[xmaxindex] = a_bannertext[xcurrindex] ;
		a_heading[xmaxindex] = a_heading[xcurrindex] ;
		a_text[xmaxindex] = a_text[xcurrindex] ;
		a_hbanner[xmaxindex] = a_hbanner[xcurrindex] ;
		a_hbannertext[xmaxindex] = a_hbannertext[xcurrindex] ;
		a_hheading[xmaxindex] = a_hheading[xcurrindex] ;
		a_htext[xmaxindex] = a_htext[xcurrindex] ;
		FillSchemes(false)
		xobj.options[xobj.length-1].selected = true

	} else {
		a_banner[xmaxindex] = a_banner[xcurrindex+1] ;
		a_bannertext[xmaxindex] = a_bannertext[xcurrindex+1] ;
		a_heading[xmaxindex] = a_heading[xcurrindex+1] ;
		a_text[xmaxindex] = a_text[xcurrindex+1] ;
		a_hbanner[xmaxindex] = a_hbanner[xcurrindex+1] ;
		a_hbannertext[xmaxindex] = a_hbannertext[xcurrindex+1] ;
		a_hheading[xmaxindex] = a_hheading[xcurrindex+1] ;
		a_htext[xmaxindex] = a_htext[xcurrindex+1] ;

		xobj.options[xobj.length-1].selected = true
	}
}

function ChangeCellColor(ygroupname, xhexcolor, xpcolor) {
	if (ygroupname == "BANNER") return;
	
	if (ygroupname == "BANNERTEXT") {
		ygroupname = "BANNER"
	}
	else if (ygroupname == "TEXT") {
		ygroupname = "TEXTAREA"
	}
	var xobj = document.preview.selection;
	var xfstr1 = '<font face="verdana" size="1">'
	var xfstr2 = '</font>'
	if (xobj.options[xobj.selectedIndex].text.toUpperCase().indexOf(ygroupname) >= 0) {
		div_color_hex[xobj.options[xobj.selectedIndex].value] = "#" + xhexcolor
		SetColorSelections(xobj.options[xobj.selectedIndex].value)
		ChangeInnerHTML("pcolor", xfstr1 + "#" + xpcolor + xfstr2)
	}
}

function SetGroupColor(xgroupname, xmaxindex, xhexcolor, xpcolor) {
	if (xgroupname == "BANNER") {
		a_hbanner[xmaxindex] = xhexcolor
		a_banner[xmaxindex] = xpcolor
	}
	else if (xgroupname == "BANNERTEXT") {
		a_hbannertext[xmaxindex] = xhexcolor
		a_bannertext[xmaxindex] = xpcolor
	}
	else if (xgroupname == "HEADING" || xgroupname == "COMPANY") {
		a_hheading[xmaxindex] = xhexcolor
		a_heading[xmaxindex] = xpcolor
	}
	else if (xgroupname == "TEXT" || xgroupname == "ADDRESS") {
		a_htext[xmaxindex] = xhexcolor
		a_text[xmaxindex] = xpcolor
	}
	ChangeInnerHTML("pcolor", "&nbsp;#" + xpcolor)
}

function SetColorSelections(yindex) {
	document.getElementById("colorselection").bgColor = div_color_hex[yindex]
}

function SetAltText(yscheme) {
	var xobj1 = document.preview.imgBC
	var xobj2 = document.preview.imgBTC
	var xobj3 = document.preview.imgHC
	var xobj4 = document.preview.imgTC
	xobj1.alt = "Pantone " + a_banner[yscheme]
	xobj2.alt = "Pantone " + a_bannertext[yscheme]
	xobj3.alt = "Pantone " + a_heading[yscheme]
	xobj4.alt = "Pantone " + a_text[yscheme]

	ChangeInnerHTML("nBannerColor", "#" + a_banner[yscheme])
	ChangeInnerHTML("nBannerTextColor", "#" + a_bannertext[yscheme])
	ChangeInnerHTML("nHeadingColor", "#" + a_heading[yscheme])
	ChangeInnerHTML("nTextColor", "#" + a_text[yscheme])

}

function SetFillColorText(yindex) {
	var xobj1 = document.preview.schemes
	var xschindex = xobj1.options[xobj1.selectedIndex].value
	xfstr1 = '<font face="verdana" size="1">'
	xfstr2 = '</font>'
	if (div_fields[yindex].toUpperCase().indexOf("BANNER") >= 0) {
		ChangeInnerHTML("pcolor", xfstr1 + "#" + a_bannertext[xschindex] + xfstr2)
	}
	else if (div_fields[yindex].toUpperCase().indexOf("HEADING") >= 0 || div_fields[yindex].toUpperCase().indexOf("COMPANY") >= 0) {
		ChangeInnerHTML("pcolor", xfstr1 + "#" + a_heading[xschindex] + xfstr2)
	}
	else if (div_fields[yindex].toUpperCase().indexOf("TEXT") >= 0 || div_fields[yindex].toUpperCase().indexOf("ADDRESS") >= 0) {
		ChangeInnerHTML("pcolor", xfstr1 + "#" + a_text[xschindex] + xfstr2)
	}
}

function ShowHideRule(yindex, yobj) {
	if (yobj.checked) {
		div_rule[yindex] = true
	}
	else {
		div_rule[yindex] = false
	}
	Flash_ShowHideRule(yindex, div_rule[yindex])
}

function change_LanyardBack(yBgColorName, ycode){

	xheight = document.preview.templateH.value.split(".").join("")
	
	backgroundimage= "lanyard_" + xheight + "_" + yBgColorName + ".gif"
	tbackgroundimage= "lanyard_" + yBgColorName + ".gif"

	if (backgroundimage.substring(0,4).toLowerCase() == '/xp2' || backgroundimage.substring(0,4).toLowerCase() == '\\xp2'){
		//
	}else{
		backgroundimage = "/xp2/clipart/" + backgroundimage
	}
		
    Flash_UpdateFlashObjects();
    
	for (var j=0; j<LanyardBgCell.length; j++) {
		GetElement(LanyardBgCell[j]).background = "images/" + tbackgroundimage
	}
	
	document.images.ImageLanyard.src = "images/adders/ACC-H-80-" + ycode + "-10.gif"
}

function change_TextColor(yColor, yColorName) {
	currobj.hcolorno1.value = yColor
	currobj.hcolorname1.value = yColorName
	for(i=1; i<num_divs; i++) {
		if (div_color[i] == '1') {
			div_color_hex[i] = "#"+yColor
		}
	}
	
	Flash_Update_RectAndTextObjColors();
	
}

function change_BadgeReel(yColor, yColorName, yBgColorName, yQualifier){

	var xheight = document.preview.templateH.value
	var xwidth = document.preview.templateW.value
	document.preview.AdderQualifier.value = yQualifier

	for(i=1; i<num_divs; i++) {
		if (div_fields[i]) {
			if (div_fields[i].indexOf('BADGEIMAGE') >= 0) {
				var timage = "badge_reel_" + yBgColorName + ".gif"
				changeImage(i, timage, timage, timage)
				break;
			}
		}
	}
}

function change_TemplateBackground(yBgColorName){

	backgroundimage= yBgColorName

	if (backgroundimage.substring(0,4).toLowerCase() == '/xp2' || backgroundimage.substring(0,4).toLowerCase() == '\\xp2'){
		//
	}else{
		backgroundimage = "/xp2/clipart/" + backgroundimage
	}

    Flash_UpdateFlashObjects();
    
}

function InitializeCropArray() {
	for(var k=1; k<num_divs; k++) {
		if(div_contents[k]==zz_image || div_contents[k]==zz_pimage) {
			if (crop_w[k]) {
				crop_w[k] = null
				crop_h[k] = null
			}
		}
	}
}

function VerifyImageResolution() {
	var ximgstr="";
	var verifyflag = true
	for(var k=1; k<num_divs; k++) {
		if(div_contents[k]==zz_image || div_contents[k]==zz_pimage) {
			xhiresimage = div_text[k].split("_(m).").join(".")
			xhiresimage = xhiresimage.split('croppedimages/').join('')
			xhiresimage = xhiresimage.split('uploads/').join('')
			xextension = xhiresimage.substring(xhiresimage.lastIndexOf("."), xhiresimage.length)
			xpos1 = xhiresimage.lastIndexOf("_")
			if (xpos1 >= 0) {
				xhiresimage = xhiresimage.substring(0, xpos1) + xextension
			}
			if (crop_w[k]) {
				if ((2*div_w[k]*1.5/xzoomper) > crop_w[k] || (2*div_h[k]*1.5/xzoomper) > crop_h[k]) {
					ximgstr = ximgstr + "WARNING\n"
					ximgstr = ximgstr + "Your image (" + xhiresimage + ") is of poor quality. We do not want you to be disappointed.\n"
					ximgstr = ximgstr + "If possible, please upload a higher quality image. Or, for cropped images, please do not crop so tightly.\n"
					ximgstr = ximgstr + "Your image: " + (parseInt(crop_w[k])) + " x " + (parseInt(crop_h[k])) + " pixels\n\n"
				}
			}
		}		
	}	
	if (ximgstr.length > 0) {
		ximgstr = ximgstr + "Re-crop image(s) or upload high resolution image(s). "    
		alert(ximgstr)
	}
	return verifyflag;
}

function increaseLineSpacing(yindex) {
    Flash_IncreaseLeading(yindex,1)
}

function decreaseLineSpacing(yindex) {
    Flash_DecreaseLeading(yindex, 1)
}

function ShowHideMultipleColors(yobj) {
	if (yobj.checked) {
		GetElement(div_multiple_colors).style.visibility = "hidden";
	}
	else {
		GetElement(div_multiple_colors).style.visibility = "visible";
	}
	SavePrintColors()
}

function SavePrintColors() {
	var tctr=0;
	var tadd_color_count = 0;
	var tpms_color_count = 0;
	var xmultiplecolors = ""
	if (! document.preview.cb_process4color.checked) {
		xmultiplecolors = "Basic Colors :<br>"
		for (var k=0; k<document.preview.cb_color.length; k++) {
			if (document.preview.cb_color[k].checked) {
				tctr=tctr+1
				xmultiplecolors = xmultiplecolors + "Color No. " + tctr + ". " + document.preview.cb_color[k].value + "<br>"
			}
		}
		tadd_color_count = tctr
		jctr = tctr
		for (var j=0; j<3; j++) {
			if (trim_(document.preview.custom_color[j].value).length > 0) {
				if (tctr == jctr) {
					xmultiplecolors = xmultiplecolors + "Custom Colors :<br>"
				}
				tctr = tctr + 1				
				xmultiplecolors = xmultiplecolors + "Color No. " + tctr + ". " + document.preview.custom_color[j].value + "<br>"
			}
		}
		tpms_color_count = tctr - tadd_color_count
	}
	if (tctr <= 0 || tctr > 3) {
		tctr = 4
		tadd_color_count = 0
		tpms_color_count = 0
	}

	document.preview.numcolor.value = tctr;
	document.preview.add_color_count.value = tadd_color_count
	document.preview.pms_color_count.value = tpms_color_count
	document.preview.SpecialInstructions.value = xmultiplecolors;
}

function ChangeColor2(tColor, tColorNo) {
	var xfieldcount=0;
	currobj['hcolorno' + tColorNo].value = tColor.split('#').join('')
	for(var i=1; i<num_divs; i++) {
		if (div_color[i]) {
			if (div_color[i] == tColorNo) {
				if (div_fields[i]) {
					if (div_fields[i].toLowerCase().indexOf('code') >= 0 || div_fields[i].toLowerCase().indexOf('number') >= 0) {    //do not convert barcode color, it should remain black
					}
					else {
						var xallowit = true
						if (div_group[i]) {
							if (div_group[i].indexOf('-0') > 0) {
								xallowit = false
							}
						}
						if (xallowit) {
							//color 0 should not be affected. 
							div_color_hex[i] = tColor
							if (div_contents[i].indexOf('label') >= 0) {
								xfieldcount++;
							}
							if (div_contents[i].indexOf('rectangle') >= 0) {	
								xfieldcount++;
							}
						}
					}
				}
				else if (div_contents[i].indexOf('rectangle') >= 0) {
					xfieldcount++;
					div_color_hex[i] = tColor				}
			}
		}
		if (div_bgcolor[i]) {
			if (div_contents[i].indexOf('rectangle') >= 0) {
				xfieldcount++;
				div_bgcolor_hex[i] = tColor
            }
		}
	}	
	
	Flash_Update_RectAndTextObjColors();
	
	if (xfieldcount <= 0) {
		yindex = getobjectno("logoimage")	
		if (yindex > 0) {
			if (div_text[yindex].toLowerCase().indexOf('null.gif') < 0) {	
				ChangeLogoColor(yindex, tColor)
				div_transcolor[yindex] = "#" + xtranscolor.split('#').join('')
				div_imagecolor[yindex] = "#" + tColor.split('#').join('')
			}
		}
	}
}

function changeImage_afterchange(yindex) {
	if (flag_MultiplePhoto) {
		SetSelectionPhoto(yindex)
	}
	if (flag_MultipleGraphic) {
		SetSelectionGraphic(yindex)
	}
	if (xsubcatgid.toLowerCase() == "dyesub" && flag_GraphicField.length > 0) {
		MatchBackSideLogo(yindex)
	}
}

function manualCropApply_afterchange(yindex) {
	if (flag_MultiplePhoto) {
		SetSelectionPhoto(yindex)
	}
}

function AutoCropnApply_afterchange(yindex) {
	if (flag_MultiplePhoto) {
		SetSelectionPhoto(yindex)
	}
}

function downHandler_afterchange(yindex) {
	if (flag_MultiplePhoto) {
		if (div_contents[yindex]) {
			if (div_contents[yindex].indexOf('image') >= 0) {
				SelectThisPhoto(yindex, div_fields[yindex])
			}
		}
	}
}

function MatchBackSideLogo(yindex) {
	xlogofield = flag_GraphicField + "2"
	xindex = GetFieldIndex(xlogofield.toUpperCase())
	if (xindex > 0) {
		div_x[xindex] = div_x[yindex]
		div_w[xindex] = div_w[yindex]
		div_text[xindex] = div_text[yindex]
	}
}

function GetFieldIndex(xfieldname) {
	xindex = 0
	for(var n=1; n<num_divs; n++) {
		if (div_contents[n]) {
			if (div_contents[n].indexOf('image') >= 0) {
				if (div_fields[n].toUpperCase() == xfieldname) {
					xindex = n
					break;
				}
			}
		}
	}
	return xindex;
}

function ModifySelectedColor(ypms, yhex, objno) {
	var xSpacing=0;
	var xVHt = 0;
	var yactualpms = ypms
	ypms = ypms.split(" ").join("")
	
	var colorno;
	if (objno) {
		colorno = div_color[objno];
	}
	
	for (k=1; k<num_divs; k++) {
		if (div_fields[k]) {
			//if (div_fields[k] == "LOGOIMAGE") {
			//	if (div_text[k].indexOf('null.gif') < 0) {
			//		grayscale=true	//When placing logo for the firsttime then set it to true
			//		convert_logo_color(k, div_text[k], '', grayscale)				
			//	}
			//}
			if (div_color[k] == colorno) {
				if (div_fields[k].toUpperCase().indexOf("TEXTLINE") >= 0) {
					document.preview["hcolorno" + div_color[k]].value = yhex.split('#').join('')
					div_color_hex[k] = yhex
                    var colid = div_color[k]
                    Flash_ChangeLabelColor_FromTB(colid)
				}
				if (div_fields[k].toUpperCase().indexOf("GROUP") >= 0) {
					if (xsubcatgid.toLowerCase().indexOf('holidaycards') >= 0 && xverseimage.length > 0) {  
						if (xverseimage.length > 0) {
							div_y[k] = xVHt + (2 * xSpacing) - 12
						}
						else {
							div_y[k] = (back_height - (2 * div_h[k])) / 2
						}
					}
				    //Vj - Changes according to New Js
				    Flash_ResetObjectsPosition()
				}
			}
		}
	}
	
	Flash_Update_RectAndTextObjColors();
	
	CalcColorsUsed()
}

/*Zoom Treatment Starts*/
function ApplyZoomToBackground(newzoomper) {
	zobj = document.preview.ZoomLevel
	if (zobj) {
		oldzoomper = xzoomper
		newzoomper = parseFloat(newzoomper)
		xzoomper = newzoomper
		xcurrzoomper = newzoomper
		if (oldzoomper != xzoomper) {
			resizetemplate_ht_wd(oldzoomper);
		}
		
		if (oldzoomper != xzoomper) {
			resizetemplate(oldzoomper)
		}
	
		for (var p=0; p<zobj.length; p++) {
			if (zobj.options[p].value == xzoomper) {
				zobj.selectedIndex = p
			}
		}
	}
}
/*Zoom Treatment Ends*/


function VldQty(ifld, minqty, tPackage1, multiple) {
//var qtyfld=ifld;
var checkOK = "0123456789";
var checkStr;
var ValidNum = true;
var decPoints = 0;
var allNum = "";
var allow=true;
var xstr = null;
//var minqty=0;
//var multiple=0;
var tvar=0
var currindex=0


    //alert(ifld+'\r\n'+minqty+'\r\n'+tPackage1+'\r\n'+multiple)
	xstr = trim_(ifld.value)

	if (xstr.length <= 0) {	alert("Quantity field cannot be blank"); ifld.focus(); ifld.select(); return false;}
	if (parseFloat(xstr) < 0) {	alert("Quantity cannot be negative"); ifld.focus(); ifld.select(); return false;}
	if (xstr =='-') {	alert("Please enter quantity"); ifld.focus(); ifld.select(); return false;}

	checkStr = ifld.value
  	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
	    	if (j == checkOK.length) {
      			ValidNum = false;
      			break;
    		}
    		allNum += ch;
  	}
  	if (!ValidNum) {
   		alert("Quantity entered is invalid...");
   		ifld.focus();
		ifld.select();
   		return false;
	}

	if (xstr == 0) { alert("Quantity cannot be negative"); ifld.focus(); ifld.select(); return false;}

	if (currobj.SubCatgId.value.toUpperCase()=='NFL'){
		currobj.Qty1.value=currobj.Qty.value
	}

	//if (evttype!='up'){
	//alert(ifld.value+'   '+minqty)
		if (parseInt(ifld.value) < parseInt(minqty)) {
			alert('Minimum order quantity is ' + minqty+' '+ tPackage1+'(s)')
			ifld.value=parseInt(minqty)
			//ShowTotalCost(); 
			ifld.focus(); ifld.select();
   			return false;
		}
	
		tvar=ifld.value-minqty
		if (tvar%multiple>0){
			if (minqty>1)
				alert("Please order in multiples of " + multiple + " beyond minimum quantity of " + minqty + ' '+tPackage1+'(s)')
			else
				alert("Please order in multiples of " + multiple + " beyond minimum quantity of " + minqty + ' '+tPackage1)
   			ifld.focus(); ifld.select();
   			return false;
		}
	//}

    return true;
}
