//--------------------------------------------------------------------------------------------
// JavaScript Code
//--------------------------------------------------------------------------------------------
function NewPrices ()
{
	var Printed = new Array();
	var NoPrints = new Array();
	var Prices = new Array();
	var NPPrices = new Array();
	NoPrints = AOA['NP'].QA;
	Printed = AOA['PT'].QA;

	CloseregisterCB = getObject('CloseRegCheckBox')
	if (CloseregisterCB != null)
	{
		if (CloseregisterCB.checked == true)
		CloseregisterTable = AOA['Tbl0400'].QA;
	}

	InkAddOn1 = getObject('Color1');
	if (InkAddOn1 != null)
		Ink1 = InkAddOn1.options[InkAddOn1.selectedIndex].value;
	else
		Ink1 = null;
		
	InkAddOn2 = getObject('Color2');
	if (InkAddOn2 != null)
		Ink2 = InkAddOn2.options[InkAddOn2.selectedIndex].value;
	else
		Ink2 = null;
	
	if (((Ink1 == Ink2) || (Ink2 == 0)) && (Ink2!=7))
	{
	//one color
		if (CloseregisterCB != null)
			CloseregisterCB.checked = false
		if (CloseRegRowo != null)
			CloseRegRowo.style.display = "none";
		//if (CloseRegDescCello != null)
		//	CloseRegDescCello.style.display = "none";
		//if (CloseRegCello != null)
		//	CloseRegCello.style.display = "none";
		if (Ink1 < 3)
			Ink1 = null;
		else if (Ink1 <5)
			InkTable = AOA['Tbl0301'].QA;
		else
			InkTable = AOA['Tbl0302'].QA;
	}
	else
	{
	//two color
		if (CloseRegRowo != null)
			CloseRegRowo.style.display = "";
		//if (CloseRegDescCello != null)
		//	CloseRegDescCello.style.display = "";
		//if (CloseRegCello != null)
		//	CloseRegCello.style.display = "";
		if (((Ink1 < 5) && (Ink2 == 1)) || ((Ink1 == 1) && (Ink2 < 5)))
			InkTable = AOA['Tbl0303'].QA;
		else if ((Ink1 > 1) && (Ink1 < 5) && (Ink2 > 1) && (Ink2 < 5))
			InkTable = AOA['Tbl0304'].QA;
		else if (((Ink1 > 4) && (Ink2 == 1)) || ((Ink1 == 1) && (Ink2 > 4)))
			InkTable = AOA['Tbl0305'].QA;
		else if (((Ink1 > 4) && ((Ink2 > 1) && (Ink2 < 5))) || ((Ink2 > 4) && ((Ink1 > 1) && (Ink1 < 5))))
			InkTable = AOA['Tbl0306'].QA;
		else if ((Ink1 >4) && (Ink2 > 4))
			InkTable = AOA['Tbl0307'].QA;
		else
			alert('Ink Error!   ' + Ink1 + '   ' + Ink2);
	}
	if (PMS1Rowo != null)
	{
		if (Ink1 == 7)
			PMS1Rowo.style.display = "";
		else
			PMS1Rowo.style.display = "none";
	}
	if (PMS2Rowo != null)
	{
		if (Ink2 == 7)
			PMS2Rowo.style.display = "";
		else
			PMS2Rowo.style.display = "none";
	}
	
	CoverageFace = getObject('CoverageFace');
	if (CoverageFace != null)
	{
		if (CoverageFace.selectedIndex > 1){
			CF = CoverageFace.options[CoverageFace.selectedIndex].value;
			CoverageFaceTable = AOA['Tbl' + CF].QA;
			}
		else{
			CoverageFace = null;
		}
	}
	//alert('Coverage Face is done')
	CoverageBack = getObject('CoverageBack');
	if (CoverageBack != null)
	{
		CB = CoverageBack.options[CoverageBack.selectedIndex].value;
		if (CB != 'None')
			CoverageBackTable = AOA['Tbl' + CB].QA;
		else
			CoverageBack = null;
	}
	ClosureOptions = getObject('ClosureOptions');
	if (ClosureOptions != null)
	{
		CO = ClosureOptions.options[ClosureOptions.selectedIndex].value;
		if (CO != 'None')
			ClosureOptionsTable = AOA['Tbl' + CO].QA;
		else
			ClosureOptions = null;
	}
	for (var j = 0; j < Printed.length; j++)
	{
		Prices[j] = Printed[j].nAO;
	}
	
	for (var j = 0; j < NoPrints.length; j++)
	{
		NPPrices[j] = NoPrints[j].nAO;
	}
	
// Add the Add Ons
	for (var t = 0; t < 5; t++)
	{
		switch (t)
		{
			case 0:
				if (Ink1 != null)
				{
					AddOns = InkTable;
				}
				else
					AddOns = null;
				break;
			case 1:
				if (CloseregisterCB != null)
					if (CloseregisterCB.checked)
						AddOns = CloseregisterTable;
					else
						AddOns = null;
				else
					AddOns = null;
				break;
			case 2:
				if (CoverageFace != null)
					AddOns = CoverageFaceTable;
				else
					AddOns = null;
				break;
			case 3:
				if (CoverageBack != null)
					AddOns = CoverageBackTable;
				else
					AddOns = null;
				break;
			case 4:
				if (ClosureOptions != null)
				{
					AddOns = ClosureOptionsTable;
					for (var j = 0; j < NoPrints.length; j++)
					{
						FoundAddOn = false;
						for (var i = 0; i < AddOns.length; i++)
						{
							if ((AddOns[i].nFromQty == NoPrints[j].nFromQty) && (NPPrices[j] != -1))
							{
								FoundAddOn = true;
								NPPrices[j] = NPPrices[j] + AddOns[i].nAO;
								break
							}
						}
						if (!FoundAddOn)
						{
							NPPrices[j] = -1;
						}
					}
				}
				else
					AddOns = null;
				break;			
		}
		
		if (AddOns != null)
		{
			for (var j = 0; j < Printed.length; j++)
			{
				FoundAddOn = false;
				for (var i = 0; i < AddOns.length; i++)
				{
					if ((AddOns[i].nFromQty == Printed[j].nFromQty) && (Prices[j] != -1))
					{
						FoundAddOn = true;
						Prices[j] = Prices[j] + AddOns[i].nAO;
						break
					}
				}
				if (!FoundAddOn)
				{
					Prices[j] = -1;
				}
			}
		}
	}
// Display the prices
	for (var j = 0; j < Printed.length; j++)
	{
		if (Prices[j] != -1)
		{
			if (getObject('QtyPrintedCell' +j) != null)
			{
			getObject('QtyPrintedCell' + j).childNodes[0].style.display = '';
			getObject('QPLabel' + (j)).childNodes[0].firstChild.nodeValue = FormatCurrency(Prices[j], '$XXXYYY.ZZ') + '\u00a0';
			}
		}
		else
		{
			if (getObject('QtyPrintedCell' +j) != null)
			{
				if (getObject('QPLabel' + (j)) != null)
				{	
					getObject('QtyPrinted' + j).checked = false;
					getObject('QPLabel' + (j)).childNodes[0].firstChild.nodeValue = '' + '\u00a0';
					getObject('QtyPrintedCell' + j).childNodes[0].style.display = 'none';
				}
			}
		}
		
		if (NPPrices[j] != -1)
		{
			if (getObject('QtyBlankCell' +j) != null)
			{
			getObject('QtyBlankCell' + j).childNodes[0].style.display = '';
			getObject('QBLabel' + (j)).childNodes[0].firstChild.nodeValue = FormatCurrency(NPPrices[j], '$XXXYYY.ZZ') + '\u00a0';
			}
		}
		else
		{
			if (getObject('QtyBlankCell' +j) != null)
			{
				if (getObject('QBLabel' + (j)) != null)
				{
					getObject('QtyBlankCell' + j).childNodes[0].childNodes[0].checked = false;
					getObject('QBLabel' + (j)).childNodes[0].firstChild.nodeValue = '' + '\u00a0';
					getObject('QtyBlankCell' + j).childNodes[0].style.display = 'none';
				}
			}
		}
	}
}

function FormatCurrency (nValue, sCurrencyFormat)
{	
	var sTempValue = RoundPrice (Math.abs (nValue), 2);	
	var sRemainder = "";
	if (sTempValue.match (/\./) != null) {
		sRemainder = sTempValue.replace (/^.*\./, '');
		sTempValue = sTempValue.replace (/\..*$/, '');
	}		

	var sThousands = "";	
	if (sTempValue.length > 3)
		sThousands = sTempValue.replace (/^(\d+)(\d\d\d)$/, '$1');		
	var sHundreds = sTempValue.substr (sThousands.length, sTempValue.length);		
	if (!sThousands.length)
		sCurrencyFormat = sCurrencyFormat.replace (/XXX.*YYY/, "YYY");
				
	sCurrencyFormat = sCurrencyFormat.replace (/XXX/, sThousands);			
	sCurrencyFormat = sCurrencyFormat.replace (/YYY/, sHundreds);			
	sCurrencyFormat = sCurrencyFormat.replace (/ZZ/,  sRemainder);
	
	if (nValue < 0)
		sCurrencyFormat = "-" + sCurrencyFormat;		
	return sCurrencyFormat;			
}

function RoundPrice (dPrice, nDecimal)
{		
	dPrice = Round (dPrice, nDecimal);
	var sDig = "000000000";
	var sTempValue = dPrice.toString();	
	if (nDecimal > 0) {
		var nPos = sTempValue.indexOf(".");
		if (nPos == -1) {
			sTempValue += ".";
			nPos = sTempValue.length - 1;
		}		
		var nDec = sTempValue.length - nPos - 1;	
		sTempValue += sDig.substr(0, nDecimal - nDec);
	}					
	return sTempValue;	
}

function Round (dPrice, nDecimal)
{	
	var dPowerOfTen = Math.pow(10, nDecimal);

	var dTempPrice = dPrice * dPowerOfTen;
	var dRoundedPrice = Math.floor (dTempPrice);
	var dFloorRemainder = dTempPrice - dRoundedPrice;

	if (dFloorRemainder > 0.5 || (dFloorRemainder == 0.5 && dRoundedPrice % 2 != 0))
		dRoundedPrice += 1;

	return dRoundedPrice / dPowerOfTen;
}

function MM_hidePanels(){
	//getObject('Metallic-Panel').style.display = 'none';
	//getObject('Brilliant-Panel').style.display = 'none';
	//getObject('Pastel-Panel').style.display = 'none';
	//getObject('Blank-Panel').style.display = 'none';
	//getObject('Tyvek-Panel').style.display = 'none';
	var c;
	c = getObject('Color_Panels');
	for (var i = 0; i < c.childNodes.length; i++){if (c!=null){c.childNodes[i].style.display = 'none';}}
}

function MM_swapPanel(pnid) {
	MM_hidePanels();
	getObject(pnid).style.display = '';
}

function show_color_panel() {
	var c, CDrp, PName, P;
	c = getObject('Color_Panels');
	for (var i = 0; i < c.childNodes.length; i++){if (c!=null){c.childNodes[i].style.display = 'none';}}
	CDrp = getObject('PaperName');
	PName = CDrp.options[CDrp.selectedIndex].value;
	P = getObject(PName);
	if (P!=null){P.style.display = '';}
}

function MM_swapLableandImage(imgId, newImg, labelId, newLbl, labelHyperLink) {
	var xlbl;
	MM_swapImage(imgId, '', newImg, 1);
	xlbl = getObject(labelId);
	if (xlbl!=null) {
		xlbl.firstChild.nodeValue=newLbl;
		xlbl.href=labelHyperLink;
	}
}

function MM_findObj(n, d) { //v4.01
  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;
}
/* Functions that swaps images. */
function MM_swapImage() { //v3.0
   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 MM_swapImgRestore() { //v3.0
  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_preloadImages() { //v3.0
  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_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
