var preError = "The following errors have been found:\n------------------------------------\n";
var errorString = "";
var postError = "------------------------------------\nPlease correct these errors and re-submit.";
var errorNumber = 0;
var errorNumDot = ". ";


var itemType = "placecard";
var typename="";
var styleID, monogramStyle, colorID, foilColorID;
var fontFaceOne, fontSizeOne, fontFaceTwo, fontSizeTwo, fontFaceThree, fontSizeThree, initialOneFont, initialOneSize, initialTwoFont, initialTwoSize, initialThreeFont, initialThreeSize, designID;
var lineOneCopy, lineTwoCopy, lineThreeCopy, initialOneCopy, initialTwoCopy, initialThreeCopy, lineOneEnvCopy, lineTwoEnvCopy;
var numLines, includeDesign;
var currentStepDiv = "styleStep";
var currentStepNum = "1";
var pictureUrl, layoutChosen;
var fontID1, fontID2, fontID3, size1, size2, size3;
var productName = "";
var colorChoice = 1;
var choices = 2;
var colorName = "";  
var colorName2 = "";  
var colorName3 = "";  
var colorName4 = "";
var brtag = "<br />";
var doshadow = false;
var doapplique = false;
var dolayout = true;
var dodesign = true;
var dofoil = true;
var docolor = true;
//var previewButton = false;

function getAllValues() {
	typename = document.productForm.typename.value;
	styleID = document.productForm.styleID.value;
	colorID = document.productForm.colorID.value; 
	colorID2 = document.productForm.colorID2.value; 
	colorID3 = document.productForm.colorID3.value; 
	colorID4 = document.productForm.colorID4.value; 
	foilColorID = document.productForm.foilColorID.value;
	itemLayout = document.productForm.itemLayout.value;
	itemContent = getRadioValue(document.productForm.itemContent);
	fontFaceOne = getSelectValue(document.productForm.fontFaceOne);
	fontSizeOne = getSelectValue(document.productForm.fontSizeOne);
	fontFaceTwo = getSelectValue(document.productForm.fontFaceTwo);
	fontSizeTwo = getSelectValue(document.productForm.fontSizeTwo);
	fontFaceThree = getSelectValue(document.productForm.fontFaceThree);
	fontSizeThree = getSelectValue(document.productForm.fontSizeThree);
	fontFaceFour = getSelectValue(document.productForm.fontFaceFour);
	fontSizeFour = getSelectValue(document.productForm.fontSizeFour);
	designID = document.productForm.designID.value;
	lineOneCopy = document.productForm.lineOneCopy.value;
	lineTwoCopy = document.productForm.lineTwoCopy.value;
	lineThreeCopy = document.productForm.lineThreeCopy.value;
	lineFourCopy = document.productForm.lineFourCopy.value;
}
//function hideAndSeek(hideDivsArray,showDiv,showDivTwo,showDivThree,showDivFour) {
//	var index;
//	var arrayLength = hideDivsArray.length;
//	for (index = 0; index < arrayLength; index++) {
//		eval(navRefOne + hideDivsArray[index] + navRefTwo + ".display = 'none'");
//	}
//	eval(navRefOne + showDiv + navRefTwo + ".display = 'block'");
//	if (showDivTwo != null) {
//		eval(navRefOne + showDivTwo + navRefTwo + ".display = 'block'");
//	}
//	if (showDivThree != null) {
//		eval(navRefOne + showDivThree + navRefTwo + ".display = 'block'");
//	}
//	if (showDivFour != null) {
//		eval(navRefOne + showDivFour + navRefTwo + ".display = 'block'");
//	}
//}
function seek(showDiv) {
	eval(navRefOne + showDiv + navRefTwo + ".display = 'block'");
}
function hide(hideDiv) {
	eval(navRefOne + hideDiv + navRefTwo + ".display = 'none'");
}
//function resetLists(resetListsArray) {
//	var index;
//	var arrayLength = resetListsArray.length;
//	for (index = 0; index < arrayLength; index++) {
//		eval('document.productForm.' + resetListsArray[index] + '.selectedIndex = 0');
//	}
//}
var stepArray = new Array();
stepArray["styleStep"] = 1;
stepArray["typeStep"] = 2;
stepArray["colorStep"] = 3;
stepArray["foilStep"] = 4;
stepArray["copyStep"] = 5;
stepArray["copyArtStep"] = 6;
stepArray["layoutStep"] = 7;
stepArray["previewStep"] = 8;

function backStep() {
	if (currentStepNum == stepArray['colorStep']) {
		colorChoice = 1;
	}
	var newStepNum = currentStepNum; 
	if (currentStepNum > 1) {
		newStepNum = currentStepNum - 1;
	}
	if (newStepNum == 3 && styleID >=226 && styleID <= 227) {
		newStepNum = 2;
	}
	for (newStep in stepArray) {
		if (stepArray[newStep] == newStepNum) {
			changeStep(newStep);
		}
	}
}			
function changeStep(stepDiv) {
	stepnum = stepArray[stepDiv];

	var cat = "";
	getAllValues();
	if (designID > 4000 && designID < 100100) {
		if (stepDiv == "styleStep" || stepDiv == "typeStep") {
			stepDiv = "colorStep";
			stepnum = "3";
		}
		if (stepDiv == "copyArtStep") {
			if (currentStepDiv != "previewStep" && currentStepDiv != "layoutStep") {
				stepDiv = "layoutStep";
				stepnum = "7";
			} else {
				stepDiv = "copyStep";
				stepnum = "5";
			}
		}
	}
	if (stepDiv == "colorStep" && !docolor) {
		if (currentStepNum > "3") {
			stepDiv = "styleStep";
			stepnum = "2";
		} else {
			if (!dofoil) {
				stepDiv = "copyStep";
				stepnum = "5";
			} else {
				stepDiv = "foilStep";
				stepnum = "4";
			}
		}
	}
	if (stepDiv == "foilStep" && !dofoil) {
		if (currentStepNum < "4") {
			stepDiv = "copyStep";
			stepnum = "5";
		} else {
			if (!docolor) {
				stepDiv = "styleStep";
				stepnum = "2";
			} else {
				stepDiv = "colorStep";
				stepnum = "3";
			}
		}
	}
	if (stepDiv == "copyArtStep" && !dodesign) {
		if (currentStepDiv != "previewStep" && currentStepDiv != "layoutStep") {
			if (!dolayout) {
				stepDiv = "previewStep";
				stepnum = "8";
			} else {
				stepDiv = "layoutStep";
				stepnum = "7";
			}
		} else {
			stepDiv = "copyStep";
			stepnum = "5";
		}
	}
//	if (designID != "") {
//		dolayout = false;
//	}
	if (stepDiv == "layoutStep" && (!dolayout || designID != "")) {
		if (currentStepDiv != "previewStep") {
			stepDiv = "previewStep";
			stepnum = "8";
		} else if ((designID > 4000 && designID < 100100) || !dodesign) {
			stepDiv = "copyStep";
			stepnum = "5";
		} else {
			stepDiv = "copyArtStep";
			stepnum = "6";
		}
	}
		
	if (currentStepDiv.slice(0,9) == "colorStep") {
		eval(navRefOne + "colorStepNo" + navRefTwo.replace(/.style/,".className") + " = 'inactive-step'");
	} else {
		eval(navRefOne + currentStepDiv + "No" + navRefTwo.replace(/.style/,".className") + " = 'inactive-step'");
	}
	eval(navRefOne + stepDiv + "No" + navRefTwo.replace(/.style/,".className") + " = 'active-step'");
	if (stepDiv == "colorStep" && colorChoice > 1) { // && choices >= colorChoice) {
			stepDiv = stepDiv + colorChoice;
	}
	eval(navRefOne + currentStepDiv + "Desc" + navRefTwo + ".display = 'none'");
	eval(navRefOne + stepDiv + "Desc" + navRefTwo + ".display = 'block'");
	eval(navRefOne + currentStepDiv + navRefTwo + ".display = 'none'");
	eval(navRefOne + stepDiv + navRefTwo + ".display = 'block'");
	if (currentStepDiv != stepDiv || stepDiv == "colorStep") {
		if (stepDiv.slice(0,9) == "colorStep") {
			if (choices != 1 && colorChoice >= choices) {
				cat = "tab";
			} else {
				cat = "pl";
			}
			if (colorChoice > 1) {
				setTimeout('loadIframe("colorSamples' + colorChoice + '", "samplePages/showPaperColors.php?cat=' + cat + '")',300);
			} else {
				setTimeout('loadIframe("colorSamples", "samplePages/showPaperColors.php?cat=' + cat + '")',300);
			}
		} else if (stepDiv == "foilStep") {
			setTimeout('loadIframe("foilSamples", "/samplePages/showFoils.php")',300);
		} else if (stepDiv == "layoutStep") {
			setTimeout('loadIframe("layoutSamples", "/samplePages/showPlacecardLayouts.php")',300);
		} else if (stepDiv == "copyArtStep") {
			setTimeout('loadIframe("copyArtSamples", "/samplePages/showDesigns.php")',300);
		} else if (stepDiv == "typeStep") {
			setTimeout('loadIframe("typeSamples", "/samplePages/showPlacecardStyles.php")',300);
		}
	}
	if (stepDiv == "copyStep" && itemContent.substr(0,8) == "monogram") {
		seek("lines34");
	}
	currentStepDiv = stepDiv;
	currentStepNum = stepnum;
	updatePreview();
//	nextTip();
}

function selectLayout(selectItem) {
	document.productForm.itemLayout.value=selectItem;
	getAllValues();
	layoutSelect();
}
//function selectContent(selectItem) {
//	document.productForm.bagContentList.selectedIndex=selectItem;
//	getAllValues();
//	contentSelect();
//}
//function selectMonogram(selectItem) {
//	document.productForm.monogramStyleList.selectedIndex=selectItem;
//	getAllValues();
//	monogramSelect();
//}

function selectStyle(selectItem,selectName) {
	document.productForm.styleID.value=selectItem;
	productName=selectName;
	if (selectItem == 226) {
		colorName = "";
	} else if (selectItem == 227) {
		colorName = "";
	}
	if (!(selectItem >= 92 && selectItem <= 94) && selectItem != 99) {
		typename = "";
		colorName2 = "";
		colorName3 = "";
		colorName4 = "";
	}
	var d=document.getElementById('product_type');
	d.innerHTML=productName + " " + typename + colorName;
	getAllValues();
	styleSelect();
}
function selectType(selectName) {
	document.productForm.typename.value=selectName;
	typename=selectName;
	var d=document.getElementById('product_type');
	d.innerHTML=productName + " " + typename + colorName;
	getAllValues();
	typeSelect();
}
function selectColor(selectItem,selectName) {
	switch (colorChoice) {
		case 1:
			document.productForm.colorID.value=selectItem;
			colorName=selectName;
			break;
		case 2:
			document.productForm.colorID2.value=selectItem;
			colorName2=selectName;
			break;
		case 3:
			document.productForm.colorID3.value=selectItem;
			colorName3=selectName;
			break;
		case 4:
			document.productForm.colorID4.value=selectItem;
			colorName4=selectName;
			break;
	}
	var d=document.getElementById('product_type');
	d.innerHTML=productName + " " + typename + " " + colorName;
	if (colorName2 != "") {
		d.innerHTML+=brtag + colorName2;
	}
	if (colorName3 != "") {
		d.innerHTML+=brtag + colorName3;
	}
	if (colorName4 != "") {
		d.innerHTML+=brtag + colorName4;
	}
	getAllValues();
	colorSelect();
}
function selectFoil(selectItem,foilName) {
	document.productForm.foilColorID.value=selectItem;
	var d=document.getElementById('foil_type');
	d.innerHTML=foilName;
	getAllValues();
	foilColorSelect();
}
function selectBlank() {
	document.productForm.foilColorID.value="";
	var d=document.getElementById('foil_type');
	d.innerHTML="";
	getAllValues();
	changeStep("previewStep");
}
function selectDesign(selectItem) {
	document.productForm.designID.value=selectItem;
	getAllValues();
	designSelect();
}
function selectFont(selectItem) {
	ffield.selectedIndex=selectItem;
	hidebox('fontBox');
	hidebox('allFontBox');
	getAllValues();
	fontSelect();
}
function updateCopy(EW_this) {
	getAllValues();
	var nxtFldName = EW_this.name.replace(/line/,"fontFace");
	nxtFldName = nxtFldName.replace(/Copy/,"");  
	var lineNo = nxtFldName.slice(8);
	var lstFld;
	var lstFldName;
	var lstFldNo = "";
	switch (lineNo) {
		case "Two":
			lstFldNo = "One";
			break;
		case "Three":
			lstFldNo = "Two";
			break;
	}
	var nxtFld = eval(navRefOne + nxtFldName + navRefTwo.replace(/.style/,"")); 
	if (EW_this.value != "") {
		if (nxtFld.selectedIndex == 0) {
			if (lstFldNo != "") {
				lstFldName = nxtFldName.replace(lineNo,lstFldNo);
				lstFld = eval(navRefOne + lstFldName + navRefTwo.replace(/.style/,"")); 
				nxtFld.selectedIndex = lstFld.selectedIndex;
	    } else {
	    	if (doshadow) {
					nxtFld.selectedIndex = findItem("82", nxtFld);
				} else if (doapplique) {
					nxtFld.selectedIndex = findItem("86", nxtFld);
				} else {
					nxtFld.selectedIndex = findItem("2", nxtFld);
				}
			}
		}
	} else {
		nxtFld.selectedIndex = 0;
	}
	nxtFldName = nxtFldName.replace(/Face/,"Size");  
	nxtFld = eval(navRefOne + nxtFldName + navRefTwo.replace(/.style/,"")); 
	if (EW_this.value != "") {
		if (nxtFld.selectedIndex == 0) {
			if (lstFldNo != "") {
				lstFldName = nxtFldName.replace(lineNo,lstFldNo);
				lstFld = eval(navRefOne + lstFldName + navRefTwo.replace(/.style/,"")); 
				nxtFld.selectedIndex = lstFld.selectedIndex;
	    } else {
	    	if (doshadow) {
					nxtFld.selectedIndex = findItem("72", nxtFld);
				} else if (doapplique) {
					nxtFld.selectedIndex = findItem("60", nxtFld);
				} else {
					nxtFld.selectedIndex = findItem("21", nxtFld);
				}
			}
		} 
	} else {
		nxtFld.selectedIndex = 0;
	}
	updatePreview();
}
function findItem(seekValue, seekList) {
	var index;
	var arrayLength = seekList.length;
	for (index = 0; index < arrayLength; index++) {
	  if (seekList.options[index].value == seekValue) {
	  	return index;
	  }
	}
}

function loadFonts(cat1, cat2) {
	var newbox = document.productForm.elements['fontFaceOne'];
	var newsize = document.productForm.elements['fontSizeOne'];
	setFonts(newbox, newsize, cat1, cat2)
	var newbox = document.productForm.elements['fontFaceTwo'];
	var newsize = document.productForm.elements['fontSizeTwo'];
	setFonts(newbox, newsize, cat1, cat2)
	var newbox = document.productForm.elements['fontFaceThree'];
	var newsize = document.productForm.elements['fontSizeThree'];
	setFonts(newbox, newsize, cat1, cat2)
	var newbox = document.productForm.elements['fontFaceFour'];
	var newsize = document.productForm.elements['fontSizeFour'];
	setFonts(newbox, newsize, cat1, cat2)
}	
function setFonts(newbox, newsize, cat1, cat2) {
	var index;
	for (var index = newbox.length-1; index > 0;index--) {
		newbox.options[index] = null;
	}	
	var arrayLength = fontArray.length; 
	for (index = 1; index < arrayLength; index++) {
		if (fontArray[index][0] >= cat1 && fontArray[index][0] <= cat2) {
			var optionName = new Option(fontArray[index][2], fontArray[index][1], false, false)
			var length = newbox.length;
			newbox.options[length] = optionName;
		}
	}
	var sizeArray = new Array();
	if (cat1 < 9) {
		sizeArray = [9,10,11,12,13,14,16,18,21,24,30,36,42,48];
	} else {
		for (i=0; i<15; i++) {
			sizeArray.push(30 + (i * 6));
		}
	}
	for (var index = newsize.length-1; index > 0;index--) {
		newsize.options[index] = null;
	}	
	var arrayLength = sizeArray.length; 
	for (index = 0; index < arrayLength; index++) {
		var optionName = new Option("" + sizeArray[index] + "pt.", sizeArray[index], false, false)
		var length = newsize.length;
		newsize.options[length] = optionName;
	}
}
/* ================================= Begin onChange functions ================================= */
function styleSelect() {
	getAllValues();
	dolayout = true;
	dodesign = true;
	dofoil = true;
	docolor = true;
	if (!(styleID >= 92 && styleID <= 94) && styleID != 99) {
		doshadow = false;
		doapplique = false;
		typename = "";
		document.productForm.colorID2.value = "";
		document.productForm.colorID3.value = "";
		document.productForm.colorID4.value = "";
		colorName2 = "";
		colorName3 = "";
		colorName4 = "";
	}
	if (styleID == 226) {
		document.productForm.colorID.value=134;
		colorName = "";
	} else if (styleID == 227) {
		document.productForm.colorID.value=135;
		colorName = "";
	} else if (colorID == 134 || colorID == 135) {
		document.productForm.colorID.value="";
	}
	document.productForm.itemLayout.value = "";
	var d2=document.getElementById('line1');
	d2.innerHTML="Line 1 (if any)";
	var d=document.getElementById('linelbl');
	var l=document.getElementById('lineOneCopy');
	l.maxLength = 40;
	seek("radios24");
	if (styleID == 95 || styleID == 97 || styleID == 98) {
		d.innerHTML="1-3 Lines of Text";
		seek("lines34");
		dolayout = false;
		dodesign = false;
		if (designID != "") { //no art
			designID = "";
			document.productForm.designID.value=""; 
			alert("Designs cannot be added on cards with envelopes. Your design selection has been cleared.");
		}
		document.productForm.itemLayout.value = "middleCenter";
	} else {
		if (doshadow || doapplique) {
			if (designID != "") { //no art
				designID = "";
				document.productForm.designID.value=""; 
				alert("Designs cannot be added on Shadow Cut or Applique cards. Your design selection has been cleared.");
			}          
			choices = 2;
			hide("radios24");
			if (doshadow) {
				d.innerHTML="Initial";
				d2.innerHTML="Initial (if any)";
				l.maxLength = 1;
			} else {
				d.innerHTML="1 Line of Text";
			}
		} else {
			d.innerHTML="1 Line of Text and/or a design";
			choices = 1;
		}
		if (styleID == 226 || styleID == 227) {
			docolor = false;
		}
		lineTwoCopy = "";
		lineThreeCopy = "";
		document.productForm.lineTwoCopy.value="";
		document.productForm.lineThreeCopy.value="";
		hide("lines34");
	}
	itemLayout = document.productForm.itemLayout.value;
	changeStep("typeStep");
//	if ((styleID >= 1 && styleID <= 3) || (styleID >= 41 && styleID <= 43) || styleID == 5 || styleID == 45) { /* bev or gt napkin */
//		eval(navRefOne + "giftboxDiv" + navRefTwo + ".display = 'block'");
//	} else {
//		document.productForm.giftbox.checked = false;
//		eval(navRefOne + "giftboxDiv" + navRefTwo + ".display = 'none'");
//	}
}
function typeSelect() {
	getAllValues();
	if (styleID >= 172 && styleID <= 179) {
		styleID = parseInt(styleID) - 80;
	} else if (styleID >= 182 && styleID <= 189) {
		styleID = parseInt(styleID) - 90;
	} else if (styleID >= 192 && styleID <= 199) {
		styleID = parseInt(styleID) - 100;
	}
	var d2=document.getElementById('line1');
	d2.innerHTML="Line 1 (if any)";
	var d=document.getElementById('linelbl');
	var l=document.getElementById('lineOneCopy');
	l.maxLength = 40;
	seek("radios24");
	if (typename != "" && styleID != "" && !(styleID >= 92 && styleID <= 94) && styleID != 99) {
		alert("The place card you have chosen is not available in Layered, Shadow Cut or Applique styles. Please select \"Foil Printing\" or a different place card.");
		document.productForm.typename.value = "";
		typename = "";
	}
	dolayout = true;
	dodesign = true;
	dofoil = true;
	if (typename == "Shadow Cut ") {
		styleID = parseInt(styleID) + 90;
		if (!doshadow) {
			if (lineOneCopy.length > 1) {
				document.productForm.lineOneCopy.value = lineOneCopy.slice(0,1);
			}
			document.productForm.fontFaceOne.selectedIndex = 0;
			document.productForm.fontSizeOne.selectedIndex = 0;
		}
		loadFonts(10, 10);
		doshadow = true;
		doapplique = false;
		dolayout = false;
		dodesign = false;
		dofoil = false;
		document.productForm.colorID3.value = "";
		document.productForm.colorID4.value = "";
		colorName3 = "";
		colorName4 = "";
	} else {
		if (doshadow) {
			document.productForm.fontFaceOne.selectedIndex = 0;
			document.productForm.fontSizeOne.selectedIndex = 0;
			document.productForm.colorID2.value = "";
			document.productForm.colorID3.value = "";
			document.productForm.colorID4.value = "";
			colorName2 = "";
			colorName3 = "";
			colorName4 = "";
		}
		doshadow = false;
		if (typename == "with Applique ") {
			styleID = parseInt(styleID) + 100;
			loadFonts(12, 13);
			doapplique = true;
			dolayout = false;
			dodesign = false;
			dofoil = false;
			document.productForm.colorID2.value = "";
			document.productForm.colorID3.value = "";
			colorName3 = "";
			colorName4 = "";
		} else {
			choices = 1;
			if (typename == "2 Layer ") {
				styleID = parseInt(styleID) + 80;
				choices = 2;
			}
			doapplique = false;
			loadFonts(1, 3);
			document.productForm.colorID2.value = "";
			document.productForm.colorID3.value = "";
			document.productForm.colorID4.value = "";
			colorName2 = "";
			colorName3 = "";
			colorName4 = "";
		}
	}
	if (doshadow || doapplique) {
		if (designID != "") { //no art
			designID = "";
			document.productForm.designID.value=""; 
			alert("Designs cannot be added on Shadow Cut or Applique cards. Your design selection has been cleared.");
		}          
		choices = 2;
		hide("radios24");
		if (doshadow) {
			d.innerHTML="Initial";
			d2.innerHTML="Initial (if any)";
			l.maxLength = 1;
		} else {
			d.innerHTML="1 Line of Text";
		}
	} else {
		d.innerHTML="1 Line of Text and/or a design";
	}
	document.productForm.styleID.value = styleID;
	changeStep("colorStep");
}
function colorSelect() {
	getAllValues();
	if (choices > colorChoice) {
		colorChoice++;
		if (doapplique && colorChoice == choices) {
			colorChoice = 4;
		}
		changeStep("colorStep");
	} else {
		colorChoice = 1;
		changeStep("foilStep");
	}
}
function foilColorSelect() {
	getAllValues();
	changeStep("copyStep");
}
function contentSelect() {
	getAllValues();
	if (itemContent.substr(0,8) == "monogram") {
		if (designID != "") {
			designID = "";
			document.productForm.designID.value="";
			alert("Designs cannot be added with Monograms. Your design selection has been cleared.");
		}
		seek("lines34");
		var d=document.getElementById('line1');
		d.innerHTML="first initial";
		var d=document.getElementById('line2');
		d.innerHTML="second initial (if any)";
		var d=document.getElementById('line3');
		d.innerHTML="third initial (if any)";
	} else {
		var d=document.getElementById('line1');
		d.innerHTML="Line 1 (if any)";
		if (styleID == 95 || styleID == 97 || styleID == 98) {
			seek("lines34");
			var d=document.getElementById('line2');
			d.innerHTML="Line 2 (if any)";
			var d=document.getElementById('line3');
			d.innerHTML="Line 3 (if any)";
		} else {
			lineTwoCopy = "";
			lineThreeCopy = "";
			document.productForm.lineTwoCopy.value="";
			document.productForm.lineThreeCopy.value="";
			hide("lines34");
		}
	}
	updatePreview();
}
function designSelect() {
	getAllValues();
	if (designID != "" && (itemContent.substr(0,8) == "monogram" || !dodesign)) { //no art on monograms, 3+ lines of text
		designID = "";
		document.productForm.designID.value=""; 
		if (itemContent.substr(0,8) == "monogram") {
			alert("Designs cannot be added with Monograms. Your design selection has been cleared.");
		} else { 
			alert("Designs cannot be added on cards with envelopes. Your design selection has been cleared.");
		}
	} 
	if (designID != "") {
		document.productForm.itemLayout.value = "center";
	}
	changeStep("layoutStep");
}
function layoutSelect() {
	getAllValues();
	changeStep("previewStep");
}
function fontSelect() {
	getAllValues();
	updatePreview();
}

var previewDelay;
var previewUrl;
function getPictUrl() {
	pictureUrl =
	"placecardPicture.php?item=placecard&" +
	"styleID=" + document.urlPlaceholderForm.styleID.value + "&" +
	"colorID=" + document.urlPlaceholderForm.colorID.value + "&" +
	"colorID2=" + document.urlPlaceholderForm.colorID2.value + "&" +
	"colorID3=" + document.urlPlaceholderForm.colorID3.value + "&" +
	"colorID4=" + document.urlPlaceholderForm.colorID4.value + "&" +
	"foilID=" + document.urlPlaceholderForm.foilColorID.value + "&" +
	"designID=" + document.urlPlaceholderForm.designID.value + "&" +
	"design=" + document.urlPlaceholderForm.includeDesign.value + "&" +
	"layout=" + document.urlPlaceholderForm.layoutChosen.value + "&" +
	"numLines=" + document.urlPlaceholderForm.numberOfLines.value + "&" +
	"fontID1=" + document.urlPlaceholderForm.fontID1.value + "&" +
	"fontID2=" + document.urlPlaceholderForm.fontID2.value + "&" +
	"fontID3=" + document.urlPlaceholderForm.fontID3.value + "&" +
	"fontID4=" + document.urlPlaceholderForm.fontID4.value + "&" +
	"size1=" + document.urlPlaceholderForm.size1.value + "&" +
	"size2=" + document.urlPlaceholderForm.size2.value + "&" +
	"size3=" + document.urlPlaceholderForm.size3.value + "&" +
	"size4=" + document.urlPlaceholderForm.size4.value + "&" +
	"line1=" + escape(document.urlPlaceholderForm.line1.value).replace(/\+/g,"%2B") + "&" +
	"line2=" + escape(document.urlPlaceholderForm.line2.value).replace(/\+/g,"%2B") + "&" +
	"line3=" + escape(document.urlPlaceholderForm.line3.value).replace(/\+/g,"%2B") + "&" +
	"line4=" + escape(document.urlPlaceholderForm.line4.value).replace(/\+/g,"%2B") + "&" +
	"monoStyle=" + document.urlPlaceholderForm.ms.value;
	return(pictureUrl);
}

function updatePreview() {
	getAllValues();                                       
	document.urlPlaceholderForm.styleID.value = styleID;
	document.urlPlaceholderForm.colorID.value = colorID;
	document.urlPlaceholderForm.colorID2.value = colorID2;
	document.urlPlaceholderForm.colorID3.value = colorID3;
	document.urlPlaceholderForm.colorID4.value = colorID4;
	document.urlPlaceholderForm.foilColorID.value = foilColorID;
	document.urlPlaceholderForm.designID.value = designID;
	document.urlPlaceholderForm.line1.value = lineOneCopy;
	document.urlPlaceholderForm.fontID1.value = fontFaceOne;
	document.urlPlaceholderForm.size1.value = fontSizeOne;
	document.urlPlaceholderForm.line2.value = lineTwoCopy;
	document.urlPlaceholderForm.fontID2.value = fontFaceTwo;
	document.urlPlaceholderForm.size2.value = fontSizeTwo;
	document.urlPlaceholderForm.line3.value = lineThreeCopy;
	document.urlPlaceholderForm.fontID3.value = fontFaceThree;
	document.urlPlaceholderForm.size3.value = fontSizeThree;
	document.urlPlaceholderForm.line4.value = lineFourCopy;
	document.urlPlaceholderForm.fontID4.value = fontFaceFour;
	document.urlPlaceholderForm.size4.value = fontSizeFour;
	document.urlPlaceholderForm.layoutChosen.value = itemLayout;
	contentDisplayed = itemContent;
	ms = "noneChosen";
	if (contentDisplayed.substr(0,8) == "monogram") {
		if (document.urlPlaceholderForm.line3.value != "") {
			ms = "threeLetters" + contentDisplayed.substr(8);
		} else if (document.urlPlaceholderForm.line2.value != "") {
			ms = "twoLetters" + contentDisplayed.substr(8);
		} else if (document.urlPlaceholderForm.line1.value != "") {
			ms = "oneLetter";
		}
	}
	document.urlPlaceholderForm.ms.value = ms; 
	if ((currentStepDiv == "foilStep" || currentStepDiv == "copyStep" || (currentStepDiv.slice(0,9) == "colorStep" && (doapplique || doshadow))) && lineOneCopy == "" && lineTwoCopy == "" && lineThreeCopy == "" && designID == "") {
		if (doshadow) {
			document.urlPlaceholderForm.line1.value = "D";
		} else {
			document.urlPlaceholderForm.line1.value = "Font/Design Color";
		}
	}
	if (doshadow && (colorID2 == "" || colorID2 == 0)) {
		document.urlPlaceholderForm.colorID2.value = (colorID != 153)?153:16;
	}
	if (doapplique && (colorID4 == "" || colorID4 == 0)) {
		document.urlPlaceholderForm.colorID4.value = (colorID != 153)?153:16;
	}
	if (document.urlPlaceholderForm.line4.value != "") {
		numberOfLines = 4;
	} else if (document.urlPlaceholderForm.line3.value != "") {
		numberOfLines = 3;
	} else if (document.urlPlaceholderForm.line2.value != "") {
		numberOfLines = 2;
	} else if (document.urlPlaceholderForm.line1.value != "") {
		numberOfLines = 1;
	} else {
		numberOfLines = 0;
	}
	document.urlPlaceholderForm.numberOfLines.value = numberOfLines;
	includeDesign = "no";
	if (document.urlPlaceholderForm.designID.value != "" && document.urlPlaceholderForm.designID.value != 0) {
		includeDesign = "yes";
	}
	document.urlPlaceholderForm.includeDesign.value = includeDesign;

//alert(itemContent + "\n" + getPictUrl());    
	previewUrl = getPictUrl();
//document.productForm.comments.value = previewUrl;
	previewDelay = setTimeout("displayPreview()",500);
}

function displayPreview() {
	eval(navRefOne + "previewboxcontainer" + navRefTwo + ".background = \"url('" + previewUrl + "') no-repeat center center\"");
}
//	eval(navRefOne + "" + navRefTwo + ".background = \"url('/" + getPictUrl() + "') no-repeat center center\"");
//}

function largePreview(e) {
	getAllValues();
//alert(itemContent + "\n" + getPictUrl());
	if (!e) var e = window.event;
	
	enlarge("/" + getPictUrl() + "&large=y",e,'center',300,300);
//	var newWin = window.open("/" + getPictUrl() + "&large=y", 'samples', 'width=700,height=750,top=0,left=0,resizable,scrollbars=yes,statusbar');
//	newWin.focus();
}

function checkErrors() {
	getAllValues();
	contentDisplayed = itemContent;
	if (lineOneCopy == "" && lineTwoCopy == "" && lineThreeCopy == "" && lineFourCopy == "" && designID == "" && foilColorID == "") {
		contentDisplayed = "blank"
	}
	/* reset errors */
	errorString = "";
	errorNumber = 0;
	/* -------------- check style -------------- */
	if (styleID == "") {;
		errorNumber++;
		errorString += errorNumber + errorNumDot + "A place card style has not been chosen!\n";
	}
	/* -------------- check color -------------- */
	if (colorID == "" && styleID != 226 && styleID != 227) {
		errorNumber++;
		errorString += errorNumber + errorNumDot + "A place card color has not been chosen!\n";
	}
	if (choices >= 2) {
		if (colorID2 == "" && !(choices == 2 && doapplique)) {
			errorNumber++;
			if (doshadow) {
				errorString += errorNumber + errorNumDot + "A place card shadow cut layer color has not been chosen!\n";
			} else {
				errorString += errorNumber + errorNumDot + "A place card first layer color has not been chosen!\n";
			}
		}
		if (choices >= 3 && !(choices == 3 && doapplique)) {
			if (colorID3 == "") {
				errorNumber++;
				errorString += errorNumber + errorNumDot + "A place card second layer color has not been chosen!\n";
			}                               
		}
		if (doapplique && colorID4 == "") {
			errorNumber++;
			errorString += errorNumber + errorNumDot + "A place card applique layer color has not been chosen!\n";
		}                                                                                                         
	}
	/* -------------- check foil -------------- */
	if (contentDisplayed != "blank" && !doshadow && !doapplique) {
		if (foilColorID == "") {
			errorNumber++;
			errorString += errorNumber + errorNumDot + "A foil color has not been chosen!\n";
		}
	}
	/* -------------- check line or initial one (if neccessary) -------------- */
	if (lineOneCopy == "" && contentDisplayed.substr(0,8) == "monogram") {
		errorNumber++;
		errorString += errorNumber + errorNumDot + "Initial one is empty!\n";
	} else if (lineOneCopy == "" && designID == "" && contentDisplayed == "textDesign") {
		errorNumber++;
		errorString += errorNumber + errorNumDot + "Line one and design are empty!\nIf you wanted NO PRINTING please return to Imprint Color Step and select BLANK/NO PRINTING.\nIf you wanted CUSTOM ART please return to Design Step and select CUSTOM ART.\n";
	}
	/* -------------- check line one (if neccessary) -------------- */
	if (lineOneCopy != "") {
		if (fontFaceOne == "noneChosen") {
			errorNumber++;
			errorString += errorNumber + errorNumDot + "A font for line or initial one has not been chosen!\n";
		}
		if (fontSizeOne == "noneChosen") {
			errorNumber++;
			errorString += errorNumber + errorNumDot + "A font size for line or initial one has not been chosen!\n";
		}
	}
	/* -------------- check line two (if neccessary) -------------- */
	if (lineTwoCopy != "") {
		if (fontFaceTwo == "noneChosen") {
			errorNumber++;
			errorString += errorNumber + errorNumDot + "A font for line or initial two has not been chosen!\n";
		}
		if (fontSizeTwo == "noneChosen") {
			errorNumber++;
			errorString += errorNumber + errorNumDot + "A font size for line or initial two has not been chosen!\n";
		}
	}
	/* -------------- check line three (if neccessary) -------------- */
	if (lineThreeCopy != "") {
		if (fontFaceThree == "noneChosen") {
			errorNumber++;
			errorString += errorNumber + errorNumDot + "A font for line or initial three has not been chosen!\n";
		}
		if (fontSizeThree == "noneChosen") {
			errorNumber++;
			errorString += errorNumber + errorNumDot + "A font size for line or initial three has not been chosen!\n";
		}
	}
	/* -------------- check line four (if neccessary) -------------- */
	if (lineFourCopy != "") {
		if (fontFaceFour == "noneChosen") {
			errorNumber++;
			errorString += errorNumber + errorNumDot + "A font for line four has not been chosen!\n";
		}
		if (fontSizeFour == "noneChosen") {
			errorNumber++;
			errorString += errorNumber + errorNumDot + "A font size for line four has not been chosen!\n";
		}
	}
	/* -------------- check layout (if neccessary)-------------- */
	if (contentDisplayed != "blank" && dolayout && !doshadow && !doapplique) {
		if (itemLayout == "") {
			errorNumber++;
			errorString += errorNumber + errorNumDot + "A layout has not been chosen!\n";
		}
	}
	/* -------------- check design (if neccessary)-------------- */
//	if (lineOneCopy == "" && contentDisplayed == "textDesign" && designID == "") {
//		errorNumber++;
//		errorString += errorNumber + errorNumDot + "A design has not been chosen!\n";
//	}
	if (errorNumber != 0) {
		return true;
	} else {
		return false;
	}
}

function addToCart() {
	if (checkErrors()) {
		alert(preError + errorString + postError);
	} else {

		var monogramStyleName;
		var contentType;
		document.addCartForm.cart_url.value = getPictUrl(); 
			
		document.addCartForm.cart_productID.value = document.urlPlaceholderForm.styleID.value;

		var layArray = new Array();
		layArray.flushLeft = "Flush Left";
		layArray.flushRight = "Flush Right";
		layArray.center = "Top Center";
		layArray.middleCenter = "Middle Center";
		var layChosen = document.urlPlaceholderForm.layoutChosen.value;
		document.addCartForm.cart_layout.value = layArray[layChosen];

		var monoArray = new Array();
		monoArray.oneLetter = "One Letter";
		monoArray.twoLettersHoriz = "Two Letters Horizontal";
		monoArray.twoLettersVert = "Two Letters Vertical";
		monoArray.twoLettersOffset = "Two Letters Offset";
		monoArray.threeLettersHoriz = "Three Letters Horizontal";
		monoArray.threeLettersVert = "Three Letters Vertical";
		monoArray.threeLettersOffset = "Three Letters Offset";
		if (document.urlPlaceholderForm.ms.value != "noneChosen") {
			var monoChoice = document.urlPlaceholderForm.ms.value;
			monogramStyleName = monoArray[monoChoice];
			contentType = "Monogram " + "(" + monogramStyleName + ")";
		} else {
		 	contentType = document.urlPlaceholderForm.numberOfLines.value + " line(s)";
		}
		if (document.urlPlaceholderForm.includeDesign.value == "yes") {
			contentType += " plus a design";
			document.addCartForm.cart_designID.value = document.urlPlaceholderForm.designID.value;
		}
		document.addCartForm.cart_contentType.value = contentType;

		document.addCartForm.cart_colorID.value = document.urlPlaceholderForm.colorID.value;
		document.addCartForm.cart_colorID2.value = document.urlPlaceholderForm.colorID2.value;
		document.addCartForm.cart_colorID3.value = document.urlPlaceholderForm.colorID3.value;
		document.addCartForm.cart_colorID4.value = document.urlPlaceholderForm.colorID4.value;
		document.addCartForm.cart_foilID.value = document.urlPlaceholderForm.foilColorID.value;

		document.addCartForm.cart_lineOneCopy.value = document.urlPlaceholderForm.line1.value;
		document.addCartForm.cart_fontOneID.value = document.urlPlaceholderForm.fontID1.value;
		document.addCartForm.cart_fontOneSize.value = document.urlPlaceholderForm.size1.value;

		document.addCartForm.cart_lineTwoCopy.value = document.urlPlaceholderForm.line2.value;
		document.addCartForm.cart_fontTwoID.value = document.urlPlaceholderForm.fontID2.value;
		document.addCartForm.cart_fontTwoSize.value = document.urlPlaceholderForm.size2.value;

		document.addCartForm.cart_lineThreeCopy.value = document.urlPlaceholderForm.line3.value;
		document.addCartForm.cart_fontThreeID.value = document.urlPlaceholderForm.fontID3.value;
		document.addCartForm.cart_fontThreeSize.value = document.urlPlaceholderForm.size3.value;

		document.addCartForm.cart_lineFourCopy.value = document.urlPlaceholderForm.line4.value;
		document.addCartForm.cart_fontFourID.value = document.urlPlaceholderForm.fontID4.value;
		document.addCartForm.cart_fontFourSize.value = document.urlPlaceholderForm.size4.value;

		document.addCartForm.cart_comments.value = document.productForm.comments.value;

		if (document.productForm.giftbox.checked) {
			document.addCartForm.cart_giftbox.value = "yes";
		} else {
			document.addCartForm.cart_giftbox.value = "no";
		}
		document.addCartForm.cart_insert.value = "yes";

		document.addCartForm.submit();
	} 
}


/* var test; */
/* test = "url = " + document.addCartForm.cart_url.value + "\n"; */
/* test += "product ID = " + document.addCartForm.cart_productID.value + "\n"; */
/* test += "layout = " + document.addCartForm.cart_layout.value + "\n"; */
/* test += "content = " + document.addCartForm.cart_contentType.value + "\n"; */
/* test += "color ID = " + document.addCartForm.cart_colorID.value + "\n"; */
/* test += "foil ID = " + document.addCartForm.cart_foilID.value + "\n"; */
/* test += "design ID = " + document.addCartForm.cart_designID.value + "\n"; */
/* test += "line one = " + document.addCartForm.cart_lineOneCopy.value + "\n"; */
/* test += "font one ID = " + document.addCartForm.cart_fontOneID.value + "\n"; */
/* test += "font one size = " + document.addCartForm.cart_fontOneSize.value + "\n"; */
/* test += "line two = " + document.addCartForm.cart_lineTwoCopy.value + "\n"; */
/* test += "font two ID = " + document.addCartForm.cart_fontTwoID.value + "\n"; */
/* test += "font two size = " + document.addCartForm.cart_fontTwoSize.value + "\n"; */
/* test += "line three = " + document.addCartForm.cart_lineThreeCopy.value + "\n"; */
/* test += "font three ID = " + document.addCartForm.cart_fontThreeID.value + "\n"; */
/* test += "font three size = " + document.addCartForm.cart_fontThreeSize.value + "\n"; */
/* alert(test); */
