function clearCalcs(form) {
form.grandTotal.value = "";
}

function makeOrder() {
   this.totprice = 0;
   this.numitems = 0;
   this.kits = 0;
   this.pcbs = 0;
   this.desc ="";
   this.shipping = 0;
  return this;
 }

function makeItem(Price,Description,Quantity,KitOrPcb) {
   this.price = Price;
   this.desc = Description;
   this.quantity = Quantity;
   this.kittype = KitOrPcb;
 }

 function calcOrder() {
 var Price = 0;
  for (i=0; i<=13; i++) {  Price += ( catalog[i].quantity * catalog[i].price );  }
  this.totprice = Math.round ( 100*Price ) / 100;
 }

 function calctotItems() {
 var kits = 0;
 var pcbs = 0;
 var nitems = 0;
  
  for (i=0; i<=13; i++) {
    if (catalog[i].quantity != 0) {
    switch(catalog[i].kittype) {
     
      case("PCB"):
      pcbs++; nitems++;
      break;
     
      case("KIT"):
      kits+=catalog[i].quantity; nitems++;
      break;
    }
    }
  }
 this.numitems = nitems;
 this.kits = kits;
 this.pcbs = pcbs;
 }

 function calctotShipping(shipto){
 var ship = 8;
  if (shipto=="US") { 
    if (this.kits > 1) ship += 4;
  }
	else if (shipto=="International") {
	ship += 7;
    if (this.kits > 1) ship += 11;
	} 
 this.shipping = ship;
}

 function paypalOrder() {
 var OrderString = "";
 for (i=0; i<=13; i++) {
    if (catalog[i].quantity != 0) OrderString += (" | " + catalog[i].quantity + " " + catalog[i].desc ); 
     }
     OrderString += " |";
  this.desc = OrderString;
 }

function calculate(form) {
    makeOrder.prototype.calctotItems = calctotItems;
    makeOrder.prototype.calcOrder = calcOrder;
    makeOrder.prototype.calctotShipping = calctotShipping;
    makeOrder.prototype.paypalOrder = paypalOrder;

    yourOrder = new makeOrder();

    catalog = new Array();

//LM3886 Products
    catalog[0] = new makeItem(90,"NI3886-KIT-DM",eval(form.lm38861.options[form.lm38861.selectedIndex].value),"KIT");
	catalog[1] = new makeItem(70,"NI3886-KIT-ST",eval(form.lm38862.options[form.lm38862.selectedIndex].value),"KIT");
	catalog[2] = new makeItem(50,"NI3886-KIT-MONO",eval(form.lm38863.options[form.lm38863.selectedIndex].value),"KIT");
	catalog[3] = new makeItem(24,"NI3886-PCB-DM",eval(form.lm38864.options[form.lm38864.selectedIndex].value),"PCB");
	catalog[4] = new makeItem(28,"NI3886-PCB-ST",eval(form.lm38865.options[form.lm38865.selectedIndex].value),"PCB");
	catalog[5] = new makeItem(12,"NI3886-PCB-MONO",eval(form.lm38866.options[form.lm38866.selectedIndex].value),"PCB");
	catalog[6] = new makeItem(3,"NI3886-PCB-AMP",eval(form.lm38867.options[form.lm38867.selectedIndex].value),"PCB");
	catalog[7] = new makeItem(12,"NI3886-2-CHIPS",eval(form.lm38868.options[form.lm38868.selectedIndex].value),"PCB");
	

//Power Supply Kits
    catalog[8] = new makeItem(30,"PS-KIT",eval(form.ps1.options[form.ps1.selectedIndex].value),"KIT");
	catalog[9] = new makeItem(9,"PS-PCB",eval(form.ps3.options[form.ps3.selectedIndex].value),"PCB");
	
//Other Items
	catalog[10] = new makeItem(9, "ALEPH-TH-PCB",eval(form.other1.options[form.other1.selectedIndex].value),"PCB");    
	catalog[11] = new makeItem(9, "AMP-PS-PCB",eval(form.other2.options[form.other2.selectedIndex].value),"PCB");    

//LM1875 Products
    catalog[12] = new makeItem(45,"NI1875-KIT-ST",eval(form.lm18751.options[form.lm18751.selectedIndex].value),"KIT");
catalog[13] = new makeItem(12,"NI1875-PCB-ST",eval(form.lm18752.options[form.lm18752.selectedIndex].value),"PCB");

   	
	var from = form.wherefrom.options[form.wherefrom.selectedIndex].value;
	if (from == 3) { alert('You must select either US or International for shipping options'); return false; }

 // alert and exit if not valid
    yourOrder.calctotItems();
    yourOrder.calcOrder();
    yourOrder.calctotShipping(from);
    yourOrder.paypalOrder();

	if ( 0 == yourOrder.numitems ) { alert('You must buy something!'); return false; }

// display result
	form.grandTotal.value =( yourOrder.totprice + yourOrder.shipping );
	form.amount.value = yourOrder.totprice;
	form.shipping.value = yourOrder.shipping;
	form.item_name.value = yourOrder.desc;
	done = 1;
  }



var done = 0;

