var e=0;
var t=0;
var u=0;
var v=0;
var w=0;
var x=0;
var y=0;
var z=0;
var o=0;
var p=0;
var q=0;
var r=0;
var s=0;
var n=0;

function CalculateTax(Cost, ID, CostID, Formula) 
 { 
	document.getElementById(ID).innerHTML=formatCurrency(Cost*eval(Formula));
	return Cost*eval(Formula);
 } 
// *********************************************************
//The following functions do all the utilty work for the
//Tax Calculation Functions above.
//
// formatCurrency
// This function takes the number given it and
//  returns a number formatted for Currency Display 
//  as a string for your Tax label.
//********************************************************* 
 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);
 }

// *********************************************************
// resetAllForms
// This function sets all the tax labels to 00.00 and
// clears all the Total variables to 0, so the form is
// reset and ready for new input
//********************************************************* 
 function resetAllForms (windowOrLayer) 
 {
	document.getElementById("tax").innerHTML="00.00";
	document.getElementById("tax2").innerHTML="00.00";
	document.getElementById("tax3").innerHTML="00.00";
	document.getElementById("tax4").innerHTML="00.00";
	document.getElementById("tax5").innerHTML="00.00";
	document.getElementById("tax6").innerHTML="00.00";
	document.getElementById("tax7").innerHTML="00.00";
    document.getElementById("tax8").innerHTML="00.00";
	document.getElementById("tax9").innerHTML="00.00";
	document.getElementById("tax10").innerHTML="00.00";
	document.getElementById("tax11").innerHTML="00.00";
	document.getElementById("tax12").innerHTML="00.00";
    document.getElementById("tax13").innerHTML="00.00";
	document.getElementById("grandtotal").innerHTML= "00.00";
	document.getElementById("equiptotal").innerHTML= "00.00";
        
        
	  if (!windowOrLayer)
	    windowOrLayer = window;
	  for (var f = 0; f < document.forms.length; f++)
	    windowOrLayer.document.forms[f].reset();
	  if (document.layers)
	    for (var l = 0; l < windowOrLayer.document.layers.length; l++)
	      resetAllForms(windowOrLayer.document.layers[l]);


} 
   
// *********************************************************
// DoGrandTotal
// This function calculates the GrandTotal using all
// the Global variables set at the beginning of this
// script block
//********************************************************* 
function DoGrandTotal () 
{
	document.getElementById("grandtotal").innerHTML= formatCurrency(t + +u + +e + +n);
}

// *********************************************************
// DoEquipTotal
// This function does the same as DoGrantTotal, except
// it only sums the Global Variables associated with 
// Equipment Totals
//********************************************************* 
function DoEquipTotal () 
{
	document.getElementById("equiptotal").innerHTML= formatCurrency(v + +w + +x + +y + +z + +o + +p + +q + +r + +s);
	e = v + +w + +x + +y + +z + +o + +p + +q + +r + +s;
}
// *********************************************************
// refresh
// This function reloads the page.
//********************************************************* 
function refresh()
{
    window.location.reload( false );
}
// *********************************************************
// PrintForm
// This function prints the page.
//********************************************************* 
function PrintForm ()
{
	if (window.print)
	    window.print();

}
// *********************************************************
// Protypes the LEFT function
//********************************************************* 
String.prototype.left = function(lng) {
  return this.substr(0,lng);
}
// *********************************************************
// Protypes the RIGHT function
//*********************************************************
String.prototype.right = function(lng) {
  return this.substr(this.length-lng,lng);
}
// *********************************************************
// Protypes the MID function
//*********************************************************
String.prototype.mid = function(pos) {
  return this.substr(pos);
}
// *********************************************************
// Protypes the INVMID function
//*********************************************************
String.prototype.invmid = function(pos) {
  return this.substr(0,this.length-pos);
}
