
function onPageLoadMethods() {
	setPlateSize();
	/**
	var mainDiv = document.getElementById("main_scroll");
	if (mainDiv !== null) {
		mainDiv.style.height = "575px";
	}
	*/
	reloadPlateText();
}

function setPlateSize() {
	var plateWidthObj = document.getElementById("plate_width");
	var plateHeightObj = document.getElementById("plate_height");
	
	var designPlateObj = document.getElementById("design_plate");
	
	var tempWidth = parseInt(plateWidthObj.value);
	if (tempWidth <= 0) {
		tempWidth = 1;
	}

	var tempHeight = parseInt(plateHeightObj.value);
	if (tempHeight <= 0) {
		tempHeight = 1;
	}

	var heightPixels = 45;
	var widthPixels = 50;

	if (tempWidth >= 8 && tempWidth<=11) {
		widthPixels = 35;
		heightPixels = 35;
	} else if (tempWidth >= 12 && tempWidth<=15) {
		widthPixels = 30;
		heightPixels = 30;
	}
	
	//alert(tempWidth+' x '+tempHeight);
	tempWidth = tempWidth * widthPixels;
	tempHeight = tempHeight * heightPixels;
	//alert(tempWidth+' x '+tempHeight);
	
	//alert(designPlateObj.style.width+' x '+designPlateObj.style.height);
	designPlateObj.style.width = tempWidth+"px";
	designPlateObj.style.height = tempHeight+"px";
	//alert(designPlateObj.style.width+' x '+designPlateObj.style.height);
	
	// Added 8.8.2007
	var numLines = document.getElementById("dimension_num_lines");
	var spaceLeft = tempHeight-(numLines.value*25);
	var newPadding = Math.round(spaceLeft/2);
	//alert(spaceLeft);
	if (newPadding>0) {
		// Explorer
		designPlateObj.style.paddingTop = newPadding+"px";
		//designPlateObj.style.paddingBottom = newPadding;
	} 
	
}

function updateNumDisplayItems(inObj) {
	if (inObj !== null) {
		var arrowDiv = document.getElementById('sectionMessageDiv');
		if(inObj.value<=1) {
			//Hide checkboxes, arrow div and extra products
			toggleCheckboxes("hidden");
			arrowDiv.style.visibility = "hidden";
			
			hideMultipleProducts();
		} else {
			//Display checkboxes, arrow div and extra products
			toggleCheckboxes("");
			arrowDiv.style.visibility = "";
			
			displayMultipleProducts(inObj.value);
		}
	}
}

function displayMultipleProducts(numProducts) {
	var divObj = document.getElementById('multipleProducts');
	divObj.style.visibility = "";
	
	var newHtml = "";
	
	var numLines = document.getElementById('dimension_num_lines').value;
	var totalLines = numLines * numProducts;
	
	for (prodIndex=2;prodIndex<=numProducts;prodIndex++) {
		newHtml += "<p>Product #"+prodIndex+"</p>";
		for (i=1;i<=numLines;i++) {
			newHtml += "<div>";
			newHtml += "<span>"+i+".</span>";
			newHtml += "<input type='text' name='line_"+prodIndex+"_"+i+"' id='line_"+prodIndex+"_"+i+"' /> <br>";
			newHtml += "</div>";
		}
		newHtml += "<br>";
	}
	
	//alert(newHtml);
	divObj.innerHTML = newHtml;
	
	for (lineNum=1;lineNum<=numLines;lineNum++) {
		changeMultipleProductsLines(lineNum);
	}
}

function hideMultipleProducts() {
	var divObj = document.getElementById('multipleProducts');
	divObj.style.visibility = "hidden";
	divObj.innerHTML = "";
}

function checkboxClicked(checkBoxObj, lineNum) {

	//alert("line "+lineNum+"="+checkBoxObj.checked);
	
	var prodIndex = 2;
	var mainLineObj = document.getElementById('line_1_'+lineNum);
	var lineObj = document.getElementById('line_'+prodIndex+'_'+lineNum);
	//alert('line_'+prodIndex+'_'+lineNum);
	while (lineObj != null) {
		if (checkBoxObj.checked) {
			//lineObj.disabled = "";
			lineObj.style.borderStyle = "solid";
			lineObj.style.borderWidth = "1px";
			lineObj.style.borderColor = "gray";
			lineObj.style.backgroundColor = "maroon";
			lineObj.style.color = "white";
		} else {
			lineObj.value = mainLineObj.value;
			//lineObj.disabled = "disabled";
			lineObj.style.borderStyle = "solid";
			lineObj.style.borderWidth = "1px";
			lineObj.style.borderColor = "white";
			lineObj.style.backgroundColor = "white";
			lineObj.style.color = "black";
		}
		
		prodIndex++;
		lineObj = document.getElementById('line_'+prodIndex+'_'+lineNum);
	}
	
	
}

function toggleCheckboxes(displayStr) {
	var index = 1;
	var chkBox = document.getElementById('chk_line_'+index);
	
	while (chkBox != null) {
		chkBox.style.visibility = displayStr;
		index++;
		chkBox = document.getElementById('chk_line_'+index);
	}
	
}

function reloadPlateText() {
	var index = 1;
	var nextObj = document.getElementById('line_1_'+index);
	while (nextObj != null) {
		changePlateText(nextObj, index);
		index++;
		nextObj = document.getElementById('line_1_'+index);
	}
	
	nextObj = document.getElementById('line_1_1');
	nextObj.focus();
}

function changePlateOrnament(inputObj, lineNum) {
	//alert(inputObj.value + " " + lineNum);
	var pObj = document.getElementById('plate_line_1_'+lineNum);
	var textObj = document.getElementById('line_1_'+lineNum);

	if (inputObj.value!=0) {
		pObj.innerHTML = "<img src='images/design/ornament_"+inputObj.value+".jpg' />";
		textObj.value = "Ornament " + inputObj.value;
	} else {
		pObj.innerHTML = "";
		textObj.value = "";
	}
	
	changeMultipleProductsLines(lineNum);
}

function changePlateText(inputObj, lineNum) {
	var pObj = document.getElementById('plate_'+inputObj.id);

	pObj.innerHTML = inputObj.value;
	
	changeMultipleProductsLines(lineNum);
	
	var ornamentObj = document.getElementById('ornament_'+lineNum);
	ornamentObj.selectedIndex = 0;
}

function changeMultipleProductsLines(lineNum) {
	var checkBoxObj = document.getElementById('chk_line_'+lineNum);
	
	checkboxClicked(checkBoxObj, lineNum);
}

function changePlateStyle(id) {

	var fontTypeObj = document.getElementById('line_font_type_'+id);
	var fontSizeObj = document.getElementById('line_font_size_'+id);
	var fontAlignObj = document.getElementById('line_font_align_'+id);
	
	var pObj = document.getElementById('plate_line_1_'+id);
	
	pObj.style.fontFamily = fontTypeObj.value;
	//alert(pObj.style.fontSize);
	//alert(parseInt(fontSizeObj.value));
	pObj.style.fontSize = parseInt(fontSizeObj.value)+"px";
	//alert(pObj.style.fontSize);
	pObj.style.textAlign = fontAlignObj.value;
	
	// 8.9.2007
	var newPadding = (parseInt(fontSizeObj.value)/10)*2;
	newPadding = Math.round(newPadding);
	if (newPadding>0) {
		//alert(newPadding);
		pObj.style.paddingTop = newPadding+"px";
		pObj.style.paddingBottom = newPadding+"px";
	}
}

function clickBold(id) {
	var boldObj = document.getElementById('bold_line_'+id);
	var boldImgObj = document.getElementById('bold_img_'+id);
	var pObj = document.getElementById('plate_line_1_'+id);
	
	if (boldObj.value=="true") {
		boldObj.value = "false";
		boldImgObj.style.borderColor = "";
		boldImgObj.style.borderWidth = "";
		boldImgObj.style.borderStyle = "";
		pObj.style.fontWeight = "";
	} else {
		boldObj.value = "true";
		boldImgObj.style.borderColor = "black";
		boldImgObj.style.borderWidth = "1px";
		boldImgObj.style.borderStyle = "solid";
		pObj.style.fontWeight = "bold";
	}
}

function clickItalic(id) {
	var italicObj = document.getElementById('italic_line_'+id);
	var italicImgObj = document.getElementById('italic_img_'+id);
	var pObj = document.getElementById('plate_line_1_'+id);
	
	if (italicObj.value=="true") {
		italicObj.value = "false";
		italicImgObj.style.borderColor = "";
		italicImgObj.style.borderWidth = "";
		italicImgObj.style.borderStyle = "";
		pObj.style.fontStyle = "";
	} else {
		italicObj.value = "true";
		italicImgObj.style.borderColor = "black";
		italicImgObj.style.borderWidth = "1px";
		italicImgObj.style.borderStyle = "solid";
		pObj.style.fontStyle = "italic";
	}
}

function toggleLogoDisplay(checkboxObj) {
	if(checkboxObj.checked) {
		document.getElementById('newLogoDiv').style.visibility = "visible";
		document.getElementById('prevLogoNameDiv').style.visibility = "hidden";
		document.getElementById('logoName').value = "";
	} else {
		document.getElementById('prevLogoNameDiv').style.visibility = "visible";
		document.getElementById('newLogoDiv').style.visibility = "hidden";
	}
}
