var userAgent = navigator.appName + " " + navigator.appVersion;
var agentInfo = userAgent.substring(0, 12);

function computeForm(form)
{
 form.total_10010.value= form.qty_10010.value * 1 * 150.00 * 1;
 form.total_10020.value= form.qty_10020.value * 1 * 110.00 * 1;
 form.total_11030.value= form.qty_11030.value * 1 * 150.00 * 1;
 form.total_11040.value= form.qty_11040.value * 1 * 140.00 * 1;
 form.total_11050.value= form.qty_11050.value * 1 * 175.00 * 1;
 form.total_20020.value= form.qty_20020.value * 1 * 130.00 * 1;
 form.total_20010.value= form.qty_20010.value * 1 * 100.00 * 1;
 form.total_30010.value= form.qty_30010.value * 1 * 40.00 * 1; 
 form.total_20110.value= form.qty_20110.value * 1 * 90.00 * 1;
 form.total_20120.value= form.qty_20120.value * 1 * 115.00 * 1;
 form.total_30110.value= form.qty_30110.value * 1 * 37.00 * 1;
 form.total_50000.value= form.qty_50000.value * 1 * 110.00 * 1;
 form.total_50010.value= form.qty_50010.value * 1 * 130.00 * 1;
 form.total_50020.value= form.qty_50020.value * 1 * 130.00 * 1; 
 form.total_50130.value= form.qty_50130.value * 1 * 120.00 * 1; 
 form.total_40020.value= form.qty_40020.value * 1 * 100.00 * 1; 
 form.total_40030.value= form.qty_40030.value * 1 * 150.00 * 1; 
 form.total_40100.value= form.qty_40100.value * 1 * 50.00 * 1; 
 form.total_40200.value= form.qty_40200.value * 1 * 90.00 * 1; 
form.total_80001.value= form.qty_80001.value * 1 * 78.00 * 0; 
form.total_80002.value= form.qty_80002.value * 1 * 78.00 * 1;
form.total_80003.value= form.qty_80003.value * 1 * 78.00 * 1; 
form.total_80004.value= form.qty_80004.value * 1 * 78.00 * 1; 
form.total_80005.value= form.qty_80005.value * 1 * 78.00 * 1; 
form.total_80006.value= form.qty_80006.value * 1 * 45.00 * 1; 
form.total_80007.value= form.qty_80007.value * 1 * 45.00 * 1; 
form.total_80008.value= form.qty_80008.value * 1 * 45.00 * 1; 
form.total_80009.value= form.qty_80009.value * 1 * 45.00 * 1; 
form.total_80010.value= form.qty_80010.value * 1 * 45.00 * 1; 
form.total_80011.value= form.qty_80011.value * 1 * 45.00 * 1; 
form.total_80012.value= form.qty_80012.value * 1 * 45.00 * 1; 
form.total_90002.value= form.qty_90002.value * 1 * 15.00 * 1; 
form.total_90004.value= form.qty_90004.value * 1 * 10.00 * 1; 
form.total_90011.value= form.qty_90011.value * 1 * 25.00 * 1; 
form.SUBTOTAL.value= form.total_10010.value * 1 + form.total_10020.value * 1 + form.total_11030.value * 1 + form.total_11040.value * 1 + form.total_11050.value * 1 + form.total_20020.value * 1 + form.total_20010.value * 1 + form.total_30010.value * 1 + form.total_20110.value * 1 + form.total_20120.value * 1 + form.total_30110.value * 1 + form.total_50000.value * 1 + form.total_50010.value * 1 + form.total_50020.value * 1 + form.total_50130.value * 1 + form.total_40020.value * 1 + form.total_40030.value * 1 + form.total_40100.value * 1 + form.total_40200.value * 1 +
form.total_80001.value * 1 + 
form.total_80002.value * 1 + 
form.total_80003.value * 1 + 
form.total_80004.value * 1 + 
form.total_80005.value * 1 + 
form.total_80006.value * 1 + 
form.total_80007.value * 1 + 
form.total_80008.value * 1 +
form.total_80009.value * 1 +
form.total_80010.value * 1 +
form.total_80011.value * 1 +
form.total_80012.value * 1 +
form.total_90002.value * 1 +
form.total_90004.value * 1 +
form.total_90011.value * 1;
  if (form.SUBTOTAL.value >= 0 && form.SUBTOTAL.value <= 50){ 
  form.SHIPPING.value= 4.05;
  }
  if (form.SUBTOTAL.value >= 50.01 && form.SUBTOTAL.value <= 100){ 
  form.SHIPPING.value= 5.00;
  }
  if (form.SUBTOTAL.value >= 100.01 && form.SUBTOTAL.value <= 200){ 
  form.SHIPPING.value= 5.95;
  }
  if (form.SUBTOTAL.value >= 200.01 && form.SUBTOTAL.value <= 300){
  form.SHIPPING.value= 6.90;
  }
  if (form.SUBTOTAL.value >= 300.01 && form.SUBTOTAL.value <= 400){
  form.SHIPPING.value= 7.85;
  }
  if (form.SUBTOTAL.value >= 400.01 && form.SUBTOTAL.value <= 500){
  form.SHIPPING.value= 8.80;
  }
  if (form.SUBTOTAL.value >= 500.01 && form.SUBTOTAL.value <= 600){
  form.SHIPPING.value= 9.75;
  }
  if (form.SUBTOTAL.value >= 600.01 && form.SUBTOTAL.value <= 700){
  form.SHIPPING.value= 10.70;
  }
  if (form.SUBTOTAL.value >= 700.01 && form.SUBTOTAL.value <= 800){
  form.SHIPPING.value= 11.65;
  }
  if (form.SUBTOTAL.value >= 800.01 && form.SUBTOTAL.value <= 900){
  form.SHIPPING.value= 12.60;
  }
  if (form.SUBTOTAL.value >= 900.01 && form.SUBTOTAL.value <= 1000){
  form.SHIPPING.value= 13.55;
  }
  if (form.SUBTOTAL.value > 1000){
  form.SHIPPING.value= 0.00;
  }

if (form.Billing_state.options[5].selected){
 temp = form.SUBTOTAL.value * 75;
 lastdigit = temp % 10;
 temp = temp - lastdigit;
 if (lastdigit >= 5){
 temp = temp + 10;
 }
 form.SALES_TAX.value = temp / 1000;
}
else {
 form.SALES_TAX.value = 0.00;
}
 
 form.TOTAL.value= form.SUBTOTAL.value * 1 + form.SALES_TAX.value * 1 + form.SHIPPING.value * 1;  

 temp = Math.round(form.TOTAL.value * 100);
 temp = temp * 5;
 lasttwodigits = temp % 100;
 temp = temp - lasttwodigits;
 if (lasttwodigits >= 50){
 temp = temp + 100;
 }
 form.childreach.value= temp / 10000;

}

 
function validateData(theNum)
{
    var str=theNum;
    if (agentInfo == "Netscape 4.0")
 {
     var correctedNum = 0;
     var decimalPlace = 0;
  var addOn = "0";
  var isDecimal = false;
     for (var i=0; i < str.length; i++)
     {
         var ch=str.substring(i, i+1);
         if (((ch >= "0") && (ch <= "9")) && (!isDecimal))
         {
          correctedNum *= 10;
       correctedNum += ch * 1;
         }
         else if (((ch >= "0") && (ch <= "9")) && (isDecimal))
         {
    addOn += ch;
    ++decimalPlace;
         }
         else if (ch == ".")
          isDecimal = true;
         else if ((ch != ",") && (ch != "$"))
          alert("The invalid character " + ch + " was detected "+
        "and ignored.");
     }
  if (decimalPlace > 0)
   correctedNum += addOn / pow(decimalPlace);
     return correctedNum;
 }
 else
 {
     for (var z=0; z < str.length; z++)
     {
  var ch=str.substring(z, z+1);
  if (((ch < "0") || (ch > "9")) && (ch != "."))
   return false;
     }
     return true;
        }

}

function calc(input)
{
 if (agentInfo == "Netscape 4.0")
 {
     input.value = validateData(input.value);
     computeForm(input.form);
 }
 else
 {
     if (validateData(input.value))
      computeForm(input.form);
     else
     {
       alert("Please do not use any characters besides numbers on"+
       " this line. Your entry will be erased.");
            input.value = 0;
     }
 }

}

function pow(exp)
{
 var returnTotal = 10;
 for (var j = 1; j < exp; j++)
     returnTotal *= 10;
 return returnTotal;
}
