//Order Form and Shopping Cart Routines
//© Copyright Superior Labels Inc. 2006

//GLOBALS
var stockID;
var cornerRadius=0;
var maxTextLines=0;
var labelStockColor="FFFFFF";
var StockDescription=""
var StockImageFileName=""
var labelWidth="0";
var labelHeight="0";
var maxTextLines="0";
var maxTextChars=0;
var LogoImageFileName="./images/nologo.gif";
var GlobalPreview;
var onrolls;
var onstamps;
var onsheets;

function HideLines(){

	if(document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 10 ||
	   document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 11 ||
	   document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 14 ||
	   document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 25 ||
	   document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 26 ||
	   document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 24 ||
	   document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 23 ||
	   document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 29 ||
	   document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 1)
		{
		//3 lines
		toggleLayer('Line1', 1)
		toggleLayer('Line2', 1)
		toggleLayer('Line3', 1)
		toggleLayer('Line4', 0)
		toggleLayer('Line5', 0)
		toggleLayer('Line6', 0)
		toggleLayer('Line7', 0)
		toggleLayer('Line8', 0)

		document.SCfrm.L4.value="";
		document.SCfrm.L5.value="";
		document.SCfrm.L6.value="";
		document.SCfrm.L7.value="";
		document.SCfrm.L8.value="";

		}
		else if (document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 27)
		{
		//4 lines
		toggleLayer('Line1', 1)
		toggleLayer('Line2', 1)
		toggleLayer('Line3', 1)
		toggleLayer('Line4', 1)
		toggleLayer('Line5', 0)
		toggleLayer('Line6', 0)
		toggleLayer('Line7', 0)
		toggleLayer('Line8', 0)

		document.SCfrm.L5.value="";
		document.SCfrm.L6.value="";
		document.SCfrm.L7.value="";
		document.SCfrm.L8.value="";

		}
		else if (document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 8 ||
		     document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 118)
		{
		//5 lines
		toggleLayer('Line1', 1)
		toggleLayer('Line2', 1)
		toggleLayer('Line3', 1)
		toggleLayer('Line4', 1)
		toggleLayer('Line5', 1)
		toggleLayer('Line6', 0)
		toggleLayer('Line7', 0)
		toggleLayer('Line8', 0)

		document.SCfrm.L6.value="";
		document.SCfrm.L7.value="";
		document.SCfrm.L8.value="";

		}
		else if (document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 60)
		{
		//6 lines
		toggleLayer('Line1', 1)
		toggleLayer('Line2', 1)
		toggleLayer('Line3', 1)
		toggleLayer('Line4', 1)
		toggleLayer('Line5', 1)
		toggleLayer('Line6', 1)
		toggleLayer('Line7', 0)
		toggleLayer('Line8', 0)

		document.SCfrm.L7.value="";
		document.SCfrm.L8.value="";

		}
		else if (document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 21 ||
			 document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 30 ||
			 document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 49 ||
			 document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 56)
		{
		//8 lines
		toggleLayer('Line1', 1)
		toggleLayer('Line2', 1)
		toggleLayer('Line3', 1)
		toggleLayer('Line4', 1)
		toggleLayer('Line5', 1)
		toggleLayer('Line6', 1)
		toggleLayer('Line7', 1)
		toggleLayer('Line8', 1)
		}
		else if (document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == 7)
		{
		//0 lines
		toggleLayer('Line1', 0)
		toggleLayer('Line2', 0)
		toggleLayer('Line3', 0)
		toggleLayer('Line4', 0)
		toggleLayer('Line5', 0)
		toggleLayer('Line6', 0)
		toggleLayer('Line7', 0)
		toggleLayer('Line8', 0)

		document.SCfrm.L1.value="";
		document.SCfrm.L2.value="";
		document.SCfrm.L3.value="";
		document.SCfrm.L4.value="";
		document.SCfrm.L5.value="";
		document.SCfrm.L6.value="";
		document.SCfrm.L7.value="";
		document.SCfrm.L8.value="";

		}

}

function HideShippingLines(form){

	if(form.selShipping.options[form.selShipping.selectedIndex].value.slice(0,1) < 6)
	{
	//Show CSZ, Hide Line 4

		toggleLayer('CSZ', 1)
		toggleLayer('ShipLine4', 0)
		form.shipto_line_4.value="";

	}
	else
	{
	//Hide CSZ, Show Line & 4
		toggleLayer('CSZ', 0)
		toggleLayer('ShipLine4', 1)
		form.shipto_city.value="";
		checkout_ManualBilling.state.value="";
		form.shipto_zip.value="";
	}

}

function SetStockValues(SID)
{
		var q;
		for(q=0;q<=document.SCfrm.stockcount.value - 1;q++)
		{
		    if(document.SCfrm.elements["stocks" + q + "00"].value!=null &&
			  document.SCfrm.elements["stocks" + q + "00"].value!='undefined')
		    {
				if(document.SCfrm.elements["stocks" + q + "00"].value==SID)
				{
				stockID=document.SCfrm.elements["stocks" + q + "00"].value;
				StockDescription=document.SCfrm.elements["stocks" + q + "01"].value;
  				labelHeight=document.SCfrm.elements["stocks" + q + "02"].value;
  				labelWidth=document.SCfrm.elements["stocks" + q + "03"].value;
  				cornerRadius=document.SCfrm.elements["stocks" + q + "04"].value;
  				StockImageFileName=document.SCfrm.elements["stocks" + q + "05"].value;
  				maxTextLines=document.SCfrm.elements["stocks" + q + "06"].value;
  				maxTextChars=document.SCfrm.elements["stocks" + q + "07"].value;
  				labelStockColor=document.SCfrm.elements["stocks" + q + "08"].value;
			
					//Change the LOGO ID based on the stock just selected
					if(document.SCfrm.elements["stocks" + q + "11"]!=undefined){
						document.SCfrm.elements["SC_1_LogoID_Add"].value=document.SCfrm.elements["stocks" + q + "11"].value;
					}
			
				break;
				}
		  	}
		}

		if(stockID==81){
				LogoImageFileName="images/iFlag.gif";
				document.SCfrm.monogram.selectedIndex=0;
				document.SCfrm.alignment1[0].checked=true;
				document.SCfrm.alignment2[0].checked=true;
				document.SCfrm.alignment3[0].checked=true;
				document.SCfrm.alignment4[0].checked=true;
				
				document.SCfrm.SC_1_RollSize_Add[0].id="200";
				document.SCfrm.SC_1_RollSize_Add[0].selected=true;
				document.SCfrm.SC_1_RollSize_Add.options[0].text = "200";
				
				document.SCfrm.SC_1_RollSize_Add[1].id="400";
				document.SCfrm.SC_1_RollSize_Add.options[1].text = "400";
			
		}else if(LogoImageFileName=="images/iFlag.gif"){LogoImageFileName="./images/nologo.gif";
				document.SCfrm.alignment1[1].checked=true;
				document.SCfrm.alignment2[1].checked=true;
				document.SCfrm.alignment3[1].checked=true;
				document.SCfrm.alignment4[1].checked=true;
				
				document.SCfrm.SC_1_RollSize_Add[0].id="250";
				document.SCfrm.SC_1_RollSize_Add[0].selected=true;
				document.SCfrm.SC_1_RollSize_Add.options[0].text = "250";
				
				document.SCfrm.SC_1_RollSize_Add[1].id="500";
				document.SCfrm.SC_1_RollSize_Add.options[1].text = "500";
		}

}

function toggleLayer(whichLayer, iState)
{
 if(iState)
 {
 document.getElementById(whichLayer).style.display="";
 }
 else
 {
 document.getElementById(whichLayer).style.display="none";

 }
}

function UpdatePreview()
{

var aLabelText = new Array(document.SCfrm.elements['L1'], document.SCfrm.elements['L2'], document.SCfrm.elements['L3'], document.SCfrm.elements['L4'], document.SCfrm.elements['L5'], document.SCfrm.elements['L6'], document.SCfrm.elements['L7'], document.SCfrm.elements['L8']);
var aTextColor = new Array(document.SCfrm.textcolor1, document.SCfrm.textcolor2, document.SCfrm.textcolor3, document.SCfrm.textcolor4, document.SCfrm.textcolor5, document.SCfrm.textcolor6, document.SCfrm.textcolor7, document.SCfrm.textcolor8);
var aAlignment = new Array(document.SCfrm.alignment1, document.SCfrm.alignment2, document.SCfrm.alignment3, document.SCfrm.alignment4, document.SCfrm.alignment5, document.SCfrm.alignment6, document.SCfrm.alignment7, document.SCfrm.alignment8);
var aBold = new Array(document.SCfrm.elements['chkBold1'], document.SCfrm.elements['chkBold2'], document.SCfrm.elements['chkBold3'], document.SCfrm.elements['chkBold4'], document.SCfrm.elements['chkBold5'], document.SCfrm.elements['chkBold6'], document.SCfrm.elements['chkBold7'], document.SCfrm.elements['chkBold8']);
var aUnderline = new Array(document.SCfrm.chkUnderline1, document.SCfrm.chkUnderline2, document.SCfrm.chkUnderline3, document.SCfrm.chkUnderline4, document.SCfrm.chkUnderline5, document.SCfrm.chkUnderline6, document.SCfrm.chkUnderline7, document.SCfrm.chkUnderline8);
var aItalics = new Array(document.SCfrm.chkItalic1, document.SCfrm.chkItalic2, document.SCfrm.chkItalic3, document.SCfrm.chkItalic4, document.SCfrm.chkItalic5, document.SCfrm.chkItalic6, document.SCfrm.chkItalic7, document.SCfrm.chkItalic8);
var aFont = new Array(document.SCfrm.Font1, document.SCfrm.Font2, document.SCfrm.Font3, document.SCfrm.Font4, document.SCfrm.Font5, document.SCfrm.Font6, document.SCfrm.Font7, document.SCfrm.Font8);
var aFontSize = new Array(document.SCfrm.FontSize1, document.SCfrm.FontSize2, document.SCfrm.FontSize3, document.SCfrm.FontSize4, document.SCfrm.FontSize5, document.SCfrm.FontSize6, document.SCfrm.FontSize7, document.SCfrm.FontSize8);

if(document.SCfrm.elements["Kind_of_labels"]!=null){
var preview = "https://www.superiorlabels.com/scott.aspx?getImage=True"
}
else
{
var preview = "http://www.superiorlabels.com/scott.aspx?getImage=True"
}
if(document.getElementById("enableAutoZoom")!=null){if(document.SCfrm.elements["enableAutoZoom"].checked==true){preview+="&az=1"}}

			var MaxLines = MaxTextLines();
			var StID=0;
			var tColor="";
			var strFont="";
			var strFontSize="";
			var strItalic="";
			var strBold="";
			var strUnderline="";
			var strAlignment="";
						
			StID=document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value;

			for(i=1;i<=MaxLines;i++)
			{
			 
			  	var temp = new String( aLabelText[i - 1].value);
			  
				// &
				while(temp.search(String.fromCharCode(38))!=-1)
				{
					temp=String(temp).replace(String.fromCharCode(38), '%26');
				}

				// +
				while ( temp.indexOf ("+")>=0 )
				{
					var newString = temp.substr(0, temp.indexOf ("+"));
					newString += "%2B";
					newString += temp.substr (temp.indexOf ("+")+1,temp.length );
					temp = newString;
				}

				// #
				while(temp.search(String.fromCharCode(35))!=-1)
				{
					temp=String(temp).replace(String.fromCharCode(35), '%23');
				}
				
				// "
				while(temp.search(String.fromCharCode(34))!=-1)
				{
					temp=String(temp).replace(String.fromCharCode(34), '%22');
				}

				// <
				while(temp.search(String.fromCharCode(60))!=-1)
				{
					temp=String(temp).replace(String.fromCharCode(60), '%3C');
				}

				// >
				while(temp.search(String.fromCharCode(62))!=-1)
				{
					temp=String(temp).replace(String.fromCharCode(62), '%3E');
				}

				// '
				while(temp.search(String.fromCharCode(39))!=-1)
				{
					temp=String(temp).replace(String.fromCharCode(39), '%27');
				}

			    strFont = aFont[i - 1].options[aFont[i - 1].selectedIndex].value;
			    strFontSize = aFontSize[i - 1].options[aFontSize[i - 1].selectedIndex].value;
			    strItalic = ischecked(aItalics[i - 1]);
			    strBold = ischecked(aBold[i - 1]);
			    strUnderline = ischecked(aUnderline[i - 1]);
			    strAlignment = getRadioValue(aAlignment[i - 1]);

			    //For accurate Type I preview
			    if(strFont=='Plain Font')
			    {
			      strFont='Swis721 BT';
			    }
			    else if(strFont=='Script Font')
			    {
			      strFont='CenturyExpd BT';
			  	  strItalic='1';
				  strFontSize='9';
			    }

			    tColor=aTextColor[i - 1].options[aTextColor[i - 1].selectedIndex].value;
			    if(StID==122){tColor="Gold"}

		  	    preview += "&t" + i + "=" + temp + 
		  	    "&fn" + i + "=" + strFont +
			    "&fs" + i + "=" + strFontSize +
			    "&ha" + i + "=" + strAlignment +
			    "&fc" + i + "=" + tColor +
			    "&fb" + i + "=" + strBold +
        	    "&fi" + i + "=" + strItalic +
        	    "&fu" + i + "=" + strUnderline;
			}
			   
			preview += "&BackColor=" + labelStockColor +
			"&pic=" + LogoImageFileName +
			"&TextWidth=" + labelWidth +
			"&TextHeight=" + labelHeight +
			"&mtl=" + MaxLines +
			"&cr=" + cornerRadius;

			document.getElementById('labelpreview').src = preview;
			GlobalPreview=preview;
}

function ischecked(checkbox)
{
 if(checkbox.checked)
 {
 return 1;
 }
 else
 {
 return 0;
 }
}

function StyleString()
{
var aLabelText = new Array(document.SCfrm.elements['L1'], document.SCfrm.elements['L2'], document.SCfrm.elements['L3'], document.SCfrm.elements['L4'], document.SCfrm.elements['L5'], document.SCfrm.elements['L6'], document.SCfrm.elements['L7'], document.SCfrm.elements['L8']);
var aTextColor = new Array(document.SCfrm.textcolor1, document.SCfrm.textcolor2, document.SCfrm.textcolor3, document.SCfrm.textcolor4, document.SCfrm.textcolor5, document.SCfrm.textcolor6, document.SCfrm.textcolor7, document.SCfrm.textcolor8);
var aAlignment = new Array(document.SCfrm.alignment1, document.SCfrm.alignment2, document.SCfrm.alignment3, document.SCfrm.alignment4, document.SCfrm.alignment5, document.SCfrm.alignment6, document.SCfrm.alignment7, document.SCfrm.alignment8);
var aBold = new Array(document.SCfrm.elements['chkBold1'], document.SCfrm.elements['chkBold2'], document.SCfrm.elements['chkBold3'], document.SCfrm.elements['chkBold4'], document.SCfrm.elements['chkBold5'], document.SCfrm.elements['chkBold6'], document.SCfrm.elements['chkBold7'], document.SCfrm.elements['chkBold8']);
var aUnderline = new Array(document.SCfrm.chkUnderline1, document.SCfrm.chkUnderline2, document.SCfrm.chkUnderline3, document.SCfrm.chkUnderline4, document.SCfrm.chkUnderline5, document.SCfrm.chkUnderline6, document.SCfrm.chkUnderline7, document.SCfrm.chkUnderline8);
var aItalics = new Array(document.SCfrm.chkItalic1, document.SCfrm.chkItalic2, document.SCfrm.chkItalic3, document.SCfrm.chkItalic4, document.SCfrm.chkItalic5, document.SCfrm.chkItalic6, document.SCfrm.chkItalic7, document.SCfrm.chkItalic8);
var aFont = new Array(document.SCfrm.Font1, document.SCfrm.Font2, document.SCfrm.Font3, document.SCfrm.Font4, document.SCfrm.Font5, document.SCfrm.Font6, document.SCfrm.Font7, document.SCfrm.Font8);
var aFontSize = new Array(document.SCfrm.FontSize1, document.SCfrm.FontSize2, document.SCfrm.FontSize3, document.SCfrm.FontSize4, document.SCfrm.FontSize5, document.SCfrm.FontSize6, document.SCfrm.FontSize7, document.SCfrm.FontSize8);

	var output = "";
	for(i=1;i<9;i++)
	{
		output += getRadioValue(aAlignment[i - 1]).slice(0,1);
		if(aBold[i - 1].checked){output += ";" + "B";}
		if(aItalics[i - 1].checked){output += ";" + "I";}
		if(aUnderline[i - 1].checked){output += ";" + "U";}

		if(i<8){output += "|SL|"}
	}
	return output;
}

function ColorString()
{
var aLabelText = new Array(document.SCfrm.elements['L1'], document.SCfrm.elements['L2'], document.SCfrm.elements['L3'], document.SCfrm.elements['L4'], document.SCfrm.elements['L5'], document.SCfrm.elements['L6'], document.SCfrm.elements['L7'], document.SCfrm.elements['L8']);
var aTextColor = new Array(document.SCfrm.textcolor1, document.SCfrm.textcolor2, document.SCfrm.textcolor3, document.SCfrm.textcolor4, document.SCfrm.textcolor5, document.SCfrm.textcolor6, document.SCfrm.textcolor7, document.SCfrm.textcolor8);
var aAlignment = new Array(document.SCfrm.alignment1, document.SCfrm.alignment2, document.SCfrm.alignment3, document.SCfrm.alignment4, document.SCfrm.alignment5, document.SCfrm.alignment6, document.SCfrm.alignment7, document.SCfrm.alignment8);
var aBold = new Array(document.SCfrm.elements['chkBold1'], document.SCfrm.elements['chkBold2'], document.SCfrm.elements['chkBold3'], document.SCfrm.elements['chkBold4'], document.SCfrm.elements['chkBold5'], document.SCfrm.elements['chkBold6'], document.SCfrm.elements['chkBold7'], document.SCfrm.elements['chkBold8']);
var aUnderline = new Array(document.SCfrm.chkUnderline1, document.SCfrm.chkUnderline2, document.SCfrm.chkUnderline3, document.SCfrm.chkUnderline4, document.SCfrm.chkUnderline5, document.SCfrm.chkUnderline6, document.SCfrm.chkUnderline7, document.SCfrm.chkUnderline8);
var aItalics = new Array(document.SCfrm.chkItalic1, document.SCfrm.chkItalic2, document.SCfrm.chkItalic3, document.SCfrm.chkItalic4, document.SCfrm.chkItalic5, document.SCfrm.chkItalic6, document.SCfrm.chkItalic7, document.SCfrm.chkItalic8);
var aFont = new Array(document.SCfrm.Font1, document.SCfrm.Font2, document.SCfrm.Font3, document.SCfrm.Font4, document.SCfrm.Font5, document.SCfrm.Font6, document.SCfrm.Font7, document.SCfrm.Font8);
var aFontSize = new Array(document.SCfrm.FontSize1, document.SCfrm.FontSize2, document.SCfrm.FontSize3, document.SCfrm.FontSize4, document.SCfrm.FontSize5, document.SCfrm.FontSize6, document.SCfrm.FontSize7, document.SCfrm.FontSize8);

	var output = "";
	for(i=1;i<9;i++)
	{
		output += aTextColor[i - 1].options[aTextColor[i - 1].selectedIndex].value;

		if(i<8){output += "|SL|"}
	}
	return output;
}

function FontString()
{
var aLabelText = new Array(document.SCfrm.elements['L1'], document.SCfrm.elements['L2'], document.SCfrm.elements['L3'], document.SCfrm.elements['L4'], document.SCfrm.elements['L5'], document.SCfrm.elements['L6'], document.SCfrm.elements['L7'], document.SCfrm.elements['L8']);
var aTextColor = new Array(document.SCfrm.textcolor1, document.SCfrm.textcolor2, document.SCfrm.textcolor3, document.SCfrm.textcolor4, document.SCfrm.textcolor5, document.SCfrm.textcolor6, document.SCfrm.textcolor7, document.SCfrm.textcolor8);
var aAlignment = new Array(document.SCfrm.alignment1, document.SCfrm.alignment2, document.SCfrm.alignment3, document.SCfrm.alignment4, document.SCfrm.alignment5, document.SCfrm.alignment6, document.SCfrm.alignment7, document.SCfrm.alignment8);
var aBold = new Array(document.SCfrm.elements['chkBold1'], document.SCfrm.elements['chkBold2'], document.SCfrm.elements['chkBold3'], document.SCfrm.elements['chkBold4'], document.SCfrm.elements['chkBold5'], document.SCfrm.elements['chkBold6'], document.SCfrm.elements['chkBold7'], document.SCfrm.elements['chkBold8']);
var aUnderline = new Array(document.SCfrm.chkUnderline1, document.SCfrm.chkUnderline2, document.SCfrm.chkUnderline3, document.SCfrm.chkUnderline4, document.SCfrm.chkUnderline5, document.SCfrm.chkUnderline6, document.SCfrm.chkUnderline7, document.SCfrm.chkUnderline8);
var aItalics = new Array(document.SCfrm.chkItalic1, document.SCfrm.chkItalic2, document.SCfrm.chkItalic3, document.SCfrm.chkItalic4, document.SCfrm.chkItalic5, document.SCfrm.chkItalic6, document.SCfrm.chkItalic7, document.SCfrm.chkItalic8);
var aFont = new Array(document.SCfrm.Font1, document.SCfrm.Font2, document.SCfrm.Font3, document.SCfrm.Font4, document.SCfrm.Font5, document.SCfrm.Font6, document.SCfrm.Font7, document.SCfrm.Font8);
var aFontSize = new Array(document.SCfrm.FontSize1, document.SCfrm.FontSize2, document.SCfrm.FontSize3, document.SCfrm.FontSize4, document.SCfrm.FontSize5, document.SCfrm.FontSize6, document.SCfrm.FontSize7, document.SCfrm.FontSize8);

	var output = "";
	for(i=1;i<9;i++)
	{
		output += aFont[i - 1].options[aFont[i - 1].selectedIndex].value;

		if(i<8){output += "|SL|"}
	}
	return output;
}

function FontSizeString()
{
var aLabelText = new Array(document.SCfrm.elements['L1'], document.SCfrm.elements['L2'], document.SCfrm.elements['L3'], document.SCfrm.elements['L4'], document.SCfrm.elements['L5'], document.SCfrm.elements['L6'], document.SCfrm.elements['L7'], document.SCfrm.elements['L8']);
var aTextColor = new Array(document.SCfrm.textcolor1, document.SCfrm.textcolor2, document.SCfrm.textcolor3, document.SCfrm.textcolor4, document.SCfrm.textcolor5, document.SCfrm.textcolor6, document.SCfrm.textcolor7, document.SCfrm.textcolor8);
var aAlignment = new Array(document.SCfrm.alignment1, document.SCfrm.alignment2, document.SCfrm.alignment3, document.SCfrm.alignment4, document.SCfrm.alignment5, document.SCfrm.alignment6, document.SCfrm.alignment7, document.SCfrm.alignment8);
var aBold = new Array(document.SCfrm.elements['chkBold1'], document.SCfrm.elements['chkBold2'], document.SCfrm.elements['chkBold3'], document.SCfrm.elements['chkBold4'], document.SCfrm.elements['chkBold5'], document.SCfrm.elements['chkBold6'], document.SCfrm.elements['chkBold7'], document.SCfrm.elements['chkBold8']);
var aUnderline = new Array(document.SCfrm.chkUnderline1, document.SCfrm.chkUnderline2, document.SCfrm.chkUnderline3, document.SCfrm.chkUnderline4, document.SCfrm.chkUnderline5, document.SCfrm.chkUnderline6, document.SCfrm.chkUnderline7, document.SCfrm.chkUnderline8);
var aItalics = new Array(document.SCfrm.chkItalic1, document.SCfrm.chkItalic2, document.SCfrm.chkItalic3, document.SCfrm.chkItalic4, document.SCfrm.chkItalic5, document.SCfrm.chkItalic6, document.SCfrm.chkItalic7, document.SCfrm.chkItalic8);
var aFont = new Array(document.SCfrm.Font1, document.SCfrm.Font2, document.SCfrm.Font3, document.SCfrm.Font4, document.SCfrm.Font5, document.SCfrm.Font6, document.SCfrm.Font7, document.SCfrm.Font8);
var aFontSize = new Array(document.SCfrm.FontSize1, document.SCfrm.FontSize2, document.SCfrm.FontSize3, document.SCfrm.FontSize4, document.SCfrm.FontSize5, document.SCfrm.FontSize6, document.SCfrm.FontSize7, document.SCfrm.FontSize8);

	var output = "";
	for(i=1;i<9;i++)
	{
		output += aFontSize[i - 1].options[aFontSize[i - 1].selectedIndex].value;

		if(i<8){output += "|SL|"}
	}
	return output;
}

function FillHidden()
{

var resize;
var w;
var h;
var img = MM_findObj('labelpreview');
w = img.width;
h = img.height;

if(document.getElementById("enableAutoZoom")!=null){if(document.SCfrm.elements["enableAutoZoom"].checked==true){document.SCfrm.elements['SC_1_autozoom_Add'].value="1"}else{document.SCfrm.elements['SC_1_autozoom_Add'].value="0"}}
document.SCfrm.elements['SC_1_preview_Add'].value=GlobalPreview + "|SL|" + w + "|SL|" + h;
document.SCfrm.elements['SC_1_Font_Add'].value=FontString();
document.SCfrm.elements['SC_1_FontSize_Add'].value=FontSizeString();
document.SCfrm.elements['SC_1_textcolor_Add'].value=ColorString();
if(document.SCfrm.elements["monogram"]!=undefined)
{
	if(document.SCfrm.monogram.options[document.SCfrm.monogram.selectedIndex].value!="")
	{
		document.SCfrm.elements['SC_1_Styles_Add'].value="L|SL|L|SL|L|SL|L|SL|L|SL|L|SL|L|SL|L";
	}
	else
	{
		document.SCfrm.elements['SC_1_Styles_Add'].value="C|SL|C|SL|C|SL|C|SL|C|SL|C|SL|C|SL|C";
	}
}
else
{
document.SCfrm.elements['SC_1_Styles_Add'].value=StyleString();
}

document.SCfrm.elements['SC_1_Total_Add'].value=document.SCfrm.elements['TotalPrice'].value;

		var w;
		var maxlines = MaxTextLines();
		for(w=1;w<9;w++)
		{
		   if(w > maxlines){document.SCfrm.elements["L" + w].value=""}
		}
		
		var q;
		for(q=0;q<=document.SCfrm.stockcount.value - 1;q++)
		{
			
		   if(document.SCfrm.elements["stocks" + q + "00"].value!=null &&
			  document.SCfrm.elements["stocks" + q + "00"].value!='undefined')
		    {
				if(document.SCfrm.elements["stocks" + q + "00"].value==document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value)
				{	
				if(document.getElementById("RollSize")==null){document.SCfrm.elements['SC_1_Name_Add'].value=document.SCfrm.elements["stocks" + q + "01"].value}
				}
		    }
		}
}

function TotalCost(form) {

	form.SC_1_textcolorcost_Add.value=ColorCost();
	a=eval(form.SC_1_Price_Add.value);
	b=eval(form.SC_1_textcolorcost_Add.value);
	c=eval(form.SC_1_Quantity_Add.options[form.SC_1_Quantity_Add.selectedIndex].value);
	e=eval(StockUpcharge(form));
	
	//Hack to enable $5 clear custom graphics
	if(form.customclearupcharge!=null){
		e=e*2;
	}
	
	d=(a+b+e) * c;
	form.SC_1_Total_Add.value = d;
	form.TotalPrice.value = d;
	form.SC_1_perpagecost_Add.value=a+b+e;

}

function TotalCostStamps(quantity) {

	//sanitize input
	var temp=quantity;
	quantity = quantity.replace(/[^0-9]/g, ''); 
	if(quantity!=""){if(quantity.charAt(0)=="0"){quantity = quantity.substring(1, quantity.length);}}
	if(quantity=="" || quantity<1){quantity=1;}
	if(quantity!=temp && temp!=""){document.SCfrm.SC_1_Quantity_Add.value=quantity;}
	else if(quantity!=temp && temp==""){quantity=0;}

	a=eval(document.SCfrm.SC_1_Price_Add.value);
	c=eval(quantity);
	d=formatAsMoney(Math.round((a*c) * 100) /100);
	document.SCfrm.SC_1_Total_Add.value = d;
	document.SCfrm.TotalPrice.value = d;
	document.SCfrm.SC_1_perpagecost_Add.value=a;
	
}

function TotalCostCustomNoTextColorCost(form)
{
    //ljk
    form.SC_1_textcolorcost_Add.value = ColorCost();
    form.SC_1_textcolorcost_Add.value = "0";
    a = eval(form.SC_1_Price_Add.value);
    b = eval(form.SC_1_textcolorcost_Add.value);
    c = eval(form.SC_1_Quantity_Add.options[form.SC_1_Quantity_Add.selectedIndex].value);
    e = eval(StockUpcharge(form));

    //Hack to enable $5 clear custom graphics
    if (form.customclearupcharge != null) {
        e = e * 2;
    }

    //d = (a + b + e) * c;
    d = (a + e) * c;
    form.SC_1_Total_Add.value = d;
    form.TotalPrice.value = d;
    form.SC_1_perpagecost_Add.value = a + b + e;

}

function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00'
              : ( (mnt*10 == Math.floor(mnt*10)) ?
                       mnt + '0' : mnt);
}

function MaxTextLines() {

	var q;
		for(q=0;q<=document.SCfrm.stockcount.value - 1;q++)
		{
		   if(document.SCfrm.elements["stocks" + q + "00"].value!=null &&
			  document.SCfrm.elements["stocks" + q + "00"].value!='undefined')
		   {
			if(document.SCfrm.elements["stocks" + q + "00"].value==document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value)
			{
			return document.SCfrm.elements["stocks" + q + "06"].value;
			}
		  }
		}
}

function StockUpcharge(form) {

	var q;
		for(q=0;q<=form.stockcount.value - 1;q++)
		{
		   if(form.elements["stocks" + q + "00"].value!=null &&
			  form.elements["stocks" + q + "00"].value!='undefined')
		   {
			if(form.elements["stocks" + q + "00"].value==form.SC_1_StockID_Add.options[form.SC_1_StockID_Add.selectedIndex].value)
			{
			return form.elements["stocks" + q + "10"].value;
			}
		  }
		}
}

function ColorCost() {
	var cost="0";
	var i;
	for(i=1;i<9;i++)
	{
		if(document.SCfrm.elements["textcolor" + i].value!="Black"){cost=".25";break;}
	}
	return cost;
}

function ColorCostRollGFX() {
	var cost="0";
	var i;
	for(i=1;i<9;i++)
	{
		if(document.SCfrm.elements["textcolor" + i].value!="Black"){cost="3";break;}
	}
	return cost;
}

function HideDropDown()
{
	if(BrowserCheck('msie'))
	{
		if(document.getElementById("StockSelect")!=null)
		{
		document.getElementById("StockSelect").style.visibility="hidden";
		}
	}
}

function ShowDropDown()
{
	if(BrowserCheck('msie'))
	{
		if(document.getElementById("StockSelect")!=null)
		{
		document.getElementById("StockSelect").style.visibility="visible";
		}
	}
}

function BrowserCheck(string)
{
	var detect = navigator.userAgent.toLowerCase();

	place = detect.indexOf(string) + 1;

	return place;
}

function chooseMonogram(form, source) {

if (document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == "81" && source=="monogram") {
    alert  ("Monograms are not available on the American flag label stock");
    form.monogram.selectedIndex=0;
    return false;
}
else if(document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value == "81" && source=="StockID") {
    form.monogram.selectedIndex=0;
    return false;
}
// otherwise we have to set the logoID equal to
// the monogram combo value
var s;
if (form.monogram.selectedIndex ==0) { 
	LogoImageFileName="./images/nologo.gif"; 
	for(s=0;s<=document.SCfrm.stockcount.value - 1;s++)
	{
		   if(document.SCfrm.elements["stocks" + s + "00"].value!=null &&
			  document.SCfrm.elements["stocks" + s + "00"].value!='undefined')
		   {
				if(document.SCfrm.elements["stocks" + s + "00"].value==document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value)
				{
					form.SC_1_LogoID_Add.value=document.SCfrm.elements["stocks" + s + "11"].value;
					document.SCfrm.SC_1_Description_Add.value="";
					break;
				}
		   }
	}
}
else
{ form.SC_1_LogoID_Add.value=form.monogram[form.monogram.selectedIndex].value; }

for(s=0;s<=document.SCfrm.logocount.value - 1;s++)
{

	if(document.SCfrm.elements["images" + s + "02"].value!=null &&
	   document.SCfrm.elements["images" + s + "02"].value!='undefined')
	{

		if(document.SCfrm.elements["images" + s + "02"].value==document.SCfrm.monogram.options[document.SCfrm.monogram.selectedIndex].value)
		{

			LogoImageFileName=document.SCfrm.elements["images" + s + "07"].value;

			var nog;
			nog=document.SCfrm.elements["images" + s + "05"].value.split(" - ");

			document.SCfrm.SC_1_Description_Add.value=nog[0];
			break;
		}
	}
}

//if the dispenser is picked, we have to use the logo value
// that includes the dispenser
rd=form.addDispenser.checked ;
if (rd) {
    d = d + 1 ;
    switch  (form.SC_1_LogoID_Add.value) {
    case "31008":
        form.SC_1_LogoID_Add.value="94177";
        break;
    case "31009":
        form.SC_1_LogoID_Add.value="94178";
        break;
    case "31010":
        form.SC_1_LogoID_Add.value="94179";
        break;
    case "31011":
        form.SC_1_LogoID_Add.value="94180";
        break;
    case "31012":
        form.SC_1_LogoID_Add.value="94181";
        break;
    case "99858": //flag logo
        form.SC_1_LogoID_Add.value="99859";
        break;
    case "99860": //monogram A
        form.SC_1_LogoID_Add.value="100668";
        break;
    case "99861":
        form.SC_1_LogoID_Add.value="100669";
        break;
    case "99862":
        form.SC_1_LogoID_Add.value="100670";
        break;
    case "99863":
        form.SC_1_LogoID_Add.value="100671";
        break;
    case "99864":
        form.SC_1_LogoID_Add.value="100672";
        break;
    case "99865":
        form.SC_1_LogoID_Add.value="100673";
        break;
    case "99866":
        form.SC_1_LogoID_Add.value="100674";
        break;
    case "99867":
        form.SC_1_LogoID_Add.value="100675";
        break;
    case "99868":
        form.SC_1_LogoID_Add.value="100676";
        break;
    case "99869":
        form.SC_1_LogoID_Add.value="100677";
        break;
    case "99870":
        form.SC_1_LogoID_Add.value="100678";
        break;
    case "99871":
        form.SC_1_LogoID_Add.value="100679";
        break;
    case "99872":
        form.SC_1_LogoID_Add.value="100680";
        break;
    case "99873":
        form.SC_1_LogoID_Add.value="100681";
        break;
    case "99874":
        form.SC_1_LogoID_Add.value="100682";
        break;
    case "99875":
        form.SC_1_LogoID_Add.value="100683";
        break;
    case "99876":
        form.SC_1_LogoID_Add.value="100684";
        break;
    case "99877":
        form.SC_1_LogoID_Add.value="100685";
        break;
    case "99878":
        form.SC_1_LogoID_Add.value="100686";
        break;
    case "99879":
        form.SC_1_LogoID_Add.value="100687";
        break;
    case "99880":
        form.SC_1_LogoID_Add.value="100688";
        break;
    case "99881":
        form.SC_1_LogoID_Add.value="100689";
        break;
    case "99882":
        form.SC_1_LogoID_Add.value="100690";
        break;
    case "99883":
        form.SC_1_LogoID_Add.value="100691";
        break;
    case "99884":
        form.SC_1_LogoID_Add.value="100692";
        break;
    case "99885":
        form.SC_1_LogoID_Add.value="100693";
        break;

    }
  }

}

function SetStampTextcolor(index){
var i=1;
	for(i=1;i<9;i++)
	{
		document.SCfrm.elements["textcolor" + i].value=index;
	}
}

function SetRollFont(index){
	var i=1;
	for(i=1;i<9;i++)
	{
		document.SCfrm.elements["Font" + i].value=index;
	}
}

function SetImage(image){LogoImageFileName=image;}

function MeasureTextLines(){

	var maxtext = GetMaxCharacter();
	if(maxtext>0){
	
		for(i=1;i<9;i++)
		{
			 if(document.SCfrm.elements["L" + i].value.length>maxtext)
			 {
				 alert("Line " + i + " has too many characters. This label type only allows " + maxtext + " characters per line.");
				 return false;
			 }
		}
		
	}
	
	return true;
}

function GetMaxCharacter(){
		var q;
		for(q=0;q<=document.SCfrm.stockcount.value - 1;q++)
		{
		   if(document.SCfrm.elements["stocks" + q + "00"].value!=null &&
			  document.SCfrm.elements["stocks" + q + "00"].value!='undefined')
		   	{
				if(document.SCfrm.elements["stocks" + q + "00"].value==document.SCfrm.SC_1_StockID_Add.options[document.SCfrm.SC_1_StockID_Add.selectedIndex].value)
				{
					if(document.SCfrm.elements["stocks" + q + "07"].value!=null &&
			  		   document.SCfrm.elements["stocks" + q + "07"].value!='undefined')
					{
						return document.SCfrm.elements["stocks" + q + "07"].value;
					}
					else
					{
						return "0";
					}
				}
		  	}
		}	
}

// This changes the text of the dropdown to display the font's name
function ChangeFontNameText(id, value)
{
	//Use the values passed (the div 'id' and the font name 'value') to change the innerHTML of the span listing the name
	document.getElementById(id).innerHTML = value;
	
	//If the Easy Tab was being used, cycle through and change the text for each of the font dropdowns under the Custom Tab
	if (id=="FontNameEZ")
	{
		for(i=1;i<=8;i++)
   		{
   		    if(document.getElementById('FontNameL' + i) != null)
   		    {
			    document.getElementById('FontNameL' + i).innerHTML = value;
			}
		}
	}
}

function whichDiv(e)
{
	//Set the target to equal the id of whatever the user clicked on
	var target=e?e.target:event.srcElement;
	//Check to see if the target equals the div's for either the dropdown box or the span containing the font's name
	if (target.id=='FontListEZ' || target.id=='FontNameEZ')
	{
		if (document.getElementById('dropdownEZ').style.display=="none")
		{
			document.getElementById('dropdownEZ').style.display="";
			document.getElementById('dropdownEZ').focus();
		}
		else
		{
			document.getElementById('dropdownEZ').style.display="none";
		}
	}
	else
	{
	    if(document.getElementById('dropdownEZ') != null)
	    {
		    document.getElementById('dropdownEZ').style.display="none";
		}
	}
	//Cycle through each single line dropdown to see if it was the one that was clicked
	for(i=1;i<=8;i++)
    {
		if (target.id=='FontListL' + i || target.id=='FontNameL' + i)
		{
			if (document.getElementById('dropdownL' + i).style.display=="none")
			{
				document.getElementById('dropdownL' + i).style.display="";
				document.getElementById('dropdownL' + i).focus();
			}
			else
			{
				document.getElementById('dropdownL' + i).style.display="none";
			}
		}
		else
		{
		    if(document.getElementById('dropdownL' + i) != null)
		    {
			    document.getElementById('dropdownL' + i).style.display="none";
			}
		}
	}
			
	if (target.id=='dropdownEZ')
	{
		document.getElementById('dropdownEZ').style.display="";
	}
}

document.onclick=whichDiv;

function changeFontValue(value, element)
{
	//Take the font value and pass it into the corresponing element (Font1, Font2, etc...)
    document.SCfrm.elements[element].value = value;
}