// JavaScript Document
<!--
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
function ConvrtAmt (valin) {
   srchstr = valin;
   offset = srchstr.indexOf(".");
   if (offset == -1) {
      valin = (srchstr + ".00");
   } else {
        difrnc=(srchstr.length - offset)
        if (difrnc <= 2) {
            valin= (srchstr + "0");
        }
   }
   return valin
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
function MakeCurrency(floatnumber)
//   This function rounds to two decimal places
  {
   	 return Math.round(floatnumber*100)/100;
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
function CalcTotal(){
// Calculate Subtotal & total order
    bookprc = 11.95;
    inklingprc = 4.00;

    f=document.orderfrm;
   
    if (f.qty_1.value == null || f.qty_1.value == "") {
        f.qty_1.value = 0;
            }    
    if (f.qty_2.value == null || f.qty_2.value == "") {
        f.qty_2.value = 0;
          
    }
    if (f.qty_3.value == null || f.qty_3.value == "") {
        f.qty_3.value = 0;
           }
    if (f.qty_4.value == null || f.qty_4.value == "") {
        f.qty_4.value = 0;
         }
    if (f.qty_5.value == null || f.qty_5.value == "" || f.qty_5.value == 0) {
        f.qty_5.value = 0;
    }


    totl1=MakeCurrency(parseInt(f.qty_1.value)* parseFloat(bookprc));
    totl2=MakeCurrency(parseInt(f.qty_2.value)* parseFloat(inklingprc));
    totl3=MakeCurrency(parseInt(f.qty_3.value)* parseFloat(inklingprc));
    totl4=MakeCurrency(parseInt(f.qty_4.value)* parseFloat(inklingprc));
    totl5=MakeCurrency(parseInt(f.qty_5.value)* parseFloat(inklingprc));

    subtotal=MakeCurrency(parseFloat(totl1)
            +parseFloat(totl2)  +parseFloat(totl3)  +parseFloat(totl4) +parseFloat(totl5));


 // Convert numbers to display (text) values
    if (totl1 > 0) {
       f.totl1.value=ConvrtAmt(totl1.toString());
    } else {
       f.totl1.value=0
    }
     if (totl2 > 0) {
       f.totl2.value=ConvrtAmt(totl2.toString());
    } else {
       f.totl2.value=0
    }
    if (totl3 > 0) {
       f.totl3.value=ConvrtAmt(totl3.toString());
    } else {
       f.totl3.value=0
    }
    if (totl4 > 0) {
       f.totl4.value=ConvrtAmt(totl4.toString());
    } else {
       f.totl4.value=0
    }
    if (totl5== 0) {
       f.totl5.value=0
    } else {
       f.totl5.value=ConvrtAmt(totl5.toString());
    }

    if (subtotal > 0) {
        f.totaldue.value=ConvrtAmt(subtotal.toString());
    } else {
       f.totaldue.value=0    }
    
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// Check for positive integer in quantity fields 
function isPosInt(inputVal) { 
   inputStr = inputVal.toString() 


   for (var i = 0; i < inputStr.length; i++) { 
      var oneChar = inputStr.charAt(i) 
      if (oneChar < "0" || oneChar > "9") {
          return false 
      }  
   } 
   return true 
} 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
function CalcLineTotal(field) {
   f=document.orderfrm;
   var curfld = field.name;
   var crntline = curfld.charAt(4);

 
       //assign the price
       if (crntline==1) {
          liprice=12.5;
       } else {
          liprice=5;
       } 
  
       //check for qty being zeroed out
       curqty= eval("document.orderfrm.qty_" + crntline +".value");
       if (curqty == 0) {
          liprice=0;
       }

   // load the unit price
   if (crntline==1) {
     
       f.totl1.value=(liprice*f.qty_1.value);
   } else if (crntline==2) {
      
       f.totl2.value=(liprice*f.qty_2.value);
   } else if (crntline==3) {
      
       f.totl3.value=(liprice*f.qty_3.value);
   } else if (crntline==4) {
      
       f.totl4.value=(liprice*f.qty_4.value);
   } else if (crntline==5) {
   f.totl5.value=(liprice*f.qty_5.value);
   }
     
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
function TotlOrdr () {
    CalcTotal();
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
function ProcLine(field) {
    CalcLineTotal(field);
    TotlOrdr();
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
function QtyChk(field) {
 
  qtyval= field.value;
  
  if (isPosInt(field.value)) {
      liprice=999;
      CalcLineTotal(field);
      TotlOrdr(); 
  } else {
    alert("Please enter a whole number (1-99) in Qty.");
    curfld = eval("document.orderfrm." + field.name);
    curfld.focus();
    return;
    }
}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&