function doCustomPanel(n1,n2){
 sTmp = "nQuanity = document.frmLexan.Custom"+n1+"1.value"
 eval(sTmp)
 sTmp = "nWidth = document.frmLexan.Custom"+n1+"2.value"
 eval(sTmp)
 sTmp = "nHeight = document.frmLexan.Custom"+n1+"3.value"
 eval(sTmp)
 
 nLexanCustomPrice = formatStrip(document.frmLexan.LexanCustomPrice.value)
 sTmp = "nHoldPrice = formatStrip(Custom"+n1+"4.innerText)"
 eval(sTmp)
  
 if((nQuanity > 0 && nWidth > 0 && nHeight > 0) || nHoldPrice >0){
  nPrice = cVal(nQuanity) * ((cVal(nWidth)*cVal(nHeight))/144) * cVal(nLexanCustomPrice)
  if(nPrice == 0){
   sTmp="Custom"+n1+"4.innerText = ''"
   eval(sTmp)
   sTmp="document.frmLexan.CustomPrice"+n1+"4.value = ''"
   eval(sTmp)
  }else{
   sTmp="Custom"+n1+"4.innerText = '$"+formatNumber(nPrice)+"'"
   eval(sTmp)
   sTmp="document.frmLexan.CustomPrice"+n1+"4.value = '"+formatNumber(nPrice)+"'"
   eval(sTmp)
  } 
  
  nPriceDiff = MakeDbl((nPrice - nHoldPrice))
  nCurrentPrice = formatNumber(document.frmLexan.TotalSale.value)
  nTmp = nCurrentPrice.replace(',','')
 
  nTmp = (nTmp*1) + (nPriceDiff*1)
  nTmp = formatCurrency(nTmp)
  sTmp = "document.frmLexan.TotalSale.value = nTmp"
  eval(sTmp)
 
 } 
}





function doTPSCustomPanel(n1,n2){
 sTmp = "nQuanity = document.frmTPS.Custom"+n1+"1.value"
 eval(sTmp)
 sTmp = "nWidth = document.frmTPS.Custom"+n1+"2.value"
 eval(sTmp)
 sTmp = "nHeight = document.frmTPS.Custom"+n1+"3.value"
 eval(sTmp)
 
 nTPSCustomPrice = formatStrip(document.frmTPS.TPSCustomPrice.value)
 sTmp = "nHoldPrice = formatStrip(Custom"+n1+"4.innerText)"
 eval(sTmp)
  
 if((nQuanity > 0 && nWidth > 0 && nHeight > 0) || nHoldPrice >0){
  nPrice = cVal(nQuanity) * ((cVal(nWidth)*cVal(nHeight))/144) * cVal(nTPSCustomPrice)
  if(nPrice == 0){
   sTmp="Custom"+n1+"4.innerText = ''"
   eval(sTmp)
   sTmp="document.frmTPS.CustomPrice"+n1+"4.value = ''"
   eval(sTmp)
  }else{
   sTmp="Custom"+n1+"4.innerText = '$"+formatNumber(nPrice)+"'"
   eval(sTmp)
   sTmp="document.frmTPS.CustomPrice"+n1+"4.value = '"+formatNumber(nPrice)+"'"
   eval(sTmp)
  } 
  
  nPriceDiff = MakeDbl((nPrice - nHoldPrice))
  nCurrentPrice = formatNumber(document.frmTPS.TotalSale.value)
  nTmp = nCurrentPrice.replace(',','')
 
  nTmp = (nTmp*1) + (nPriceDiff*1)
  nTmp = formatCurrency(nTmp)
  sTmp = "document.frmTPS.TotalSale.value = nTmp"
  eval(sTmp)
 
 } 
}


function doPolyCarbonateCustomPanel(n1,n2){
 sTmp = "nQuanity = document.frmPolyCarbonate.Custom"+n1+"1.value"
 eval(sTmp)
 sTmp = "nWidth = document.frmPolyCarbonate.Custom"+n1+"2.value"
 eval(sTmp)
 sTmp = "nHeight = document.frmPolyCarbonate.Custom"+n1+"3.value"
 eval(sTmp)
 
 nPolyCarbonateCustomPrice = formatStrip(document.frmPolyCarbonate.PolyCarbonateCustomPrice.value)
 sTmp = "nHoldPrice = formatStrip(Custom"+n1+"4.innerText)"
 eval(sTmp)
  
 if((nQuanity > 0 && nWidth > 0 && nHeight > 0) || nHoldPrice >0){
  nPrice = cVal(nQuanity) * ((cVal(nWidth)*cVal(nHeight))/144) * cVal(nPolyCarbonateCustomPrice)
  if(nPrice == 0){
   sTmp="Custom"+n1+"4.innerText = ''"
   eval(sTmp)
   sTmp="document.frmPolyCarbonate.CustomPrice"+n1+"4.value = ''"
   eval(sTmp)
  }else{
   sTmp="Custom"+n1+"4.innerText = '$"+formatNumber(nPrice)+"'"
   eval(sTmp)
   sTmp="document.frmPolyCarbonate.CustomPrice"+n1+"4.value = '"+formatNumber(nPrice)+"'"
   eval(sTmp)
  } 
  
  nPriceDiff = MakeDbl((nPrice - nHoldPrice))
  nCurrentPrice = formatNumber(document.frmPolyCarbonate.TotalSale.value)
  nTmp = nCurrentPrice.replace(',','')
 
  nTmp = (nTmp*1) + (nPriceDiff*1)
  nTmp = formatCurrency(nTmp)
  sTmp = "document.frmPolyCarbonate.TotalSale.value = nTmp"
  eval(sTmp)
 
 } 
}


function doAluminumCustomPanel(n1,n2){
 sTmp = "nQuanity = document.frmAluminum.Custom"+n1+"1.value"
 eval(sTmp)
 sTmp = "nWidth = document.frmAluminum.Custom"+n1+"2.value"
 eval(sTmp)
 sTmp = "nHeight = document.frmAluminum.Custom"+n1+"3.value"
 eval(sTmp)
 
 nAluminumCustomPrice = formatStrip(document.frmAluminum.AluminumCustomPrice.value)
 sTmp = "nHoldPrice = formatStrip(Custom"+n1+"4.innerText)"
 eval(sTmp)
 if((nQuanity > 0 && nWidth > 0 && nHeight > 0) || nHoldPrice >0){
  nPrice = cVal(nQuanity) * ((cVal(nWidth)*cVal(nHeight))/144) * cVal(nAluminumCustomPrice)
  if(nPrice == 0){
   sTmp="Custom"+n1+"4.innerText = ''"
   eval(sTmp)
   sTmp="document.frmAluminum.CustomPrice"+n1+"4.value = ''"
   eval(sTmp)
  }else{
   sTmp="Custom"+n1+"4.innerText = '$"+formatNumber(nPrice)+"'"
   eval(sTmp)
   sTmp="document.frmAluminum.CustomPrice"+n1+"4.value = '"+formatNumber(nPrice)+"'"
   eval(sTmp)
  } 
  
  nPriceDiff = MakeDbl((nPrice - nHoldPrice))
  nCurrentPrice = formatNumber(document.frmAluminum.TotalSale.value)
  nTmp = nCurrentPrice.replace(',','')
 
  nTmp = (nTmp*1) + (nPriceDiff*1)
  nTmp = formatCurrency(nTmp)
  sTmp = "document.frmAluminum.TotalSale.value = nTmp"
  eval(sTmp)
 
 } 
}



function doAddSub(nW,nL,nAdd,nLexanPrice,frmName){
  // Get current value
 sTmp = "nTot = document.forms[0].L"+nW+nL+".value;"
 eval(sTmp);
 // convert to number
 nTot = nTot*1
 // Add / subtract
 nTot = nTot + nAdd
 // If less than 0 than 0
 if(nTot < 0){
  nTot = 0
  nAdd = 0 
 }
 // If greater than 99 than 99
 if(nTot > 99){
  nTot = 9
  nAdd = 0
 }
 // Update Panel Total
 if(nTot == 0){
  nTot = "''"
  sTmp = "document.forms[0].L"+nW+nL+".style.background = 'Gainsboro'"  
  eval(sTmp);
 }else{
  sTmp = "document.forms[0].L"+nW+nL+".style.background = 'Salmon'"  
  eval(sTmp);
 }
 sTmp = "document.forms[0].L"+nW+nL+".value = "+nTot  
 eval(sTmp);
 // Get Pricing Information
 sTmp = "nTot = document.forms[0].TotalSale.value"  
 eval(sTmp);
 nTot = formatNumber(nTot)
 nTot = nTot.replace(/,/g, '')
 // Calculate Difference 
 nPrice = (((nW*nL)/144)*nLexanPrice)*nAdd
 nPrice = MakeDbl(nTot)+MakeDbl(nPrice)
 nPrice = formatCurrency(nPrice)
 sTmp = "document.forms[0].TotalSale.value = '"+nPrice+"'"
 eval(sTmp);
 }


function doAddSubTrack(sTrack,nLength,nAdd,nPrice,nText){
 // Get current value
 sTmp = "nTot = document.forms[0]."+sTrack+".value;"
 eval(sTmp);
 // convert to number
 nTot = nTot*1
 // Add / subtract
 nTot = nTot + nAdd
 // If less than 0 than 0
 if(nTot < 0){
  nTot = 0
  nAdd = 0 
 }
 // If greater than 99 than 99
 if(nTot > 99){
  nTot = 99
  nAdd = 0
 }
 // Update Panel Total
 if(nTot == 0){
  nTot = "''"
  sTmp = "document.forms[0]."+sTrack+".style.background = 'Gainsboro'"  
  eval(sTmp);
 }else{
  sTmp = "document.forms[0]."+sTrack+".style.background = 'Salmon'"  
  eval(sTmp);
 }

 sTmp = "document.forms[0]."+sTrack+".value = "+nTot  
 eval(sTmp);

 // Get Pricing Information
 sTmp = "nTot = document.forms[0].TotalSale.value"  
 eval(sTmp);
 nTot = formatNumber(nTot)
 nTot = nTot.replace(/,/g, '')
 // Calculate Difference 
 nPrice = nLength*nPrice*nAdd
 nPrice = MakeDbl(nTot)+MakeDbl(nPrice)
 nPrice = formatCurrency(nPrice)
 sTmp = "document.forms[0].TotalSale.value = '"+nPrice+"'"
 eval(sTmp);
 
 nTot = 0
 sTmp = "nTot = nTot + formatNumber((document.forms[0]."+nText+"20.value)) * 20"
 eval(sTmp)
 sTmp = "nTot = nTot + formatNumber((document.forms[0]."+nText+"10.value)) * 10"
 eval(sTmp)
 sTmp = "nTot = nTot + formatNumber((document.forms[0]."+nText+"5.value)) * 5"
 eval(sTmp)
 if(nTot == 0){
  sTmp = nText + "Div.innerText = ''"
 }else{
  sTmp = nText + "Div.innerText = '" + nTot + "ft to be ordered'"
 } 
 eval(sTmp)
 
}

function doAddSubOther(sTrack,nLength,nAdd,nPrice,nText){
 // Get current value
 sTmp = "nTot = document.forms[0]."+sTrack+".value;"
 eval(sTmp);
 // convert to number
 nTot = nTot*1
 // Add / subtract
 nTot = nTot + nAdd
 // If less than 0 than 0
 if(nTot < 0){
  nTot = 0
  nAdd = 0 
 }
 // If greater than 99 than 99
 if(nTot > 99){
  nTot = 99
  nAdd = 0
 }
 // Update Material Total
 if(nTot == 0){
  nTot = "''"
  sTmp = "document.forms[0]."+sTrack+".style.background = 'Gainsboro'"  
  eval(sTmp);
 }else{
  sTmp = "document.forms[0]."+sTrack+".style.background = 'Salmon'"  
  eval(sTmp);
 } 
 sTmp = "document.forms[0]."+sTrack+".value = "+nTot  
 eval(sTmp);

 // Get Pricing Information
 sTmp = "nTot = document.forms[0].TotalSale.value"  
 eval(sTmp);
 nTot = formatNumber(nTot)
 nTot = nTot.replace(/,/g, '')
 // Calculate Difference 
 nPrice = nLength*nPrice*nAdd
 nPrice = MakeDbl(nTot)+MakeDbl(nPrice)
 nPrice = formatCurrency(nPrice)
 sTmp = "document.forms[0].TotalSale.value = '"+nPrice+"'"
 eval(sTmp);
 
 nTot = 0
 sTmp = "nTot = nTot + formatNumber((document.forms[0]."+nText+"1.value)) * 1"
 eval(sTmp)
 
 
}

function doAddSubMaterial(sTrack,nLength,nAdd,nPrice,nText){
 // Get current value
 sTmp = "nTot = document.forms[0]."+sTrack+".value;"
 eval(sTmp);
 // convert to number
 nTot = nTot*1
 // Add / subtract
 nTot = nTot + nAdd
 // If less than 0 than 0
 if(nTot < 0){
  nTot = 0
  nAdd = 0 
 }
 // If greater than 99 than 99
 if(nTot > 99){
  nTot = 99
  nAdd = 0
 }
 // Update Material Total
 if(nTot == 0){
  nTot = "''"
  sTmp = "document.forms[0]."+sTrack+".style.background = 'Gainsboro'"  
  eval(sTmp);
 }else{
  sTmp = "document.forms[0]."+sTrack+".style.background = 'Salmon'"  
  eval(sTmp);
 } 
 sTmp = "document.forms[0]."+sTrack+".value = "+nTot  
 eval(sTmp);

 // Get Pricing Information
 sTmp = "nTot = document.forms[0].TotalSale.value"  
 eval(sTmp);
 nTot = formatNumber(nTot)
 nTot = nTot.replace(/,/g, '')
 // Calculate Difference 
 nPrice = nLength*nPrice*nAdd
 nPrice = MakeDbl(nTot)+MakeDbl(nPrice)
 nPrice = formatCurrency(nPrice)
 sTmp = "document.forms[0].TotalSale.value = '"+nPrice+"'"
 eval(sTmp);
 
 nTot = 0
 sTmp = "nTot = nTot + formatNumber((document.forms[0]."+nText+"20.value)) * 20"
 eval(sTmp)
 sTmp = "nTot = nTot + formatNumber((document.forms[0]."+nText+"10.value)) * 10"
 eval(sTmp)
 sTmp = "nTot = nTot + formatNumber((document.forms[0]."+nText+"5.value)) * 5"
 eval(sTmp)
 
 if(nTot == 0){
  sTmp = nText + "Div.innerText = ''"
 }else{
  sTmp = nText + "Div.innerText = '" + nTot + " to be ordered'"
 } 
 eval(sTmp)
 
}
 
function formatCurrency(num) {
 	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	 cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}


function formatStrip(num){
 num = num.toString().replace(/\$|\,/g,'');
 num = num.toString().replace(',','');
 return(num)
}

function formatNumber(num) {
	num = num.toString().replace(/\$|\,/g,'');
	num = num.toString().replace(',','');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '' + num + '.' + cents);
}

function MakeDbl(iVal) {
	if(isNaN(iVal)) {
		iVal = 0;
	}
	else {
		iVal = iVal * 1;
	}
	return iVal;
} 
 

//Convert a value - strip commas from a string so arithmetic can be performed
function cVal(val) {
  var sTmp = "" ;
  
  if (val > ""){
   sTmp = val.replace(/,/g,"") ;
   sTmp = sTmp.replace(/$/g,"") ;
  } 
  
  // If alpha return 0
  lNum = "N";
  for (i = 0; i < sTmp.length; i++) {
   if (sTmp.substr(i,1).search(/[0123456789]/) >= 0){
    lNum = "Y";
   } 
  }
  if (lNum == "Y") { 
   return sTmp * 1 ;
  }
  else {
   return 0;
  } 
}