// JavaScript Document



function Currency (val) {  // force to valid doCurrencyllar amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}

function ReadForm (obj1) { // option based discounts
  var i,amt,des,qty;
  amt = obj1.retail_amount.value*1.0; // base amount
  des = obj1.basedes.value;     // base description
  option = "retail";
	for (i=0; i< obj1.on0.length; i++) {
	  on = obj1.on0[i];
	  if (on.checked){
		  option = on.value;
		  break;
	  }
  } 
  //alert (option);
  if (option=="wholesale"){
	  amt = obj1.wholesale_amount.value * 1.0;
	  obj1.item_name.value = des + ", Wholesale Package of 12 items @ &euro;" + Currency (amt) + " each.";
	   obj1.amount.value = Currency (amt *  12 );
  }else{
		obj1.item_name.value = des + ", Retail price: &euro;" + Currency (amt) + ".";  
		obj1.amount.value = Currency (amt );
  }
}


function ReadFormQuantity (obj1) { // quantity based discounts
var i,amt,des,qty;
  amt = obj1.retail_amount.value*1.0; // base amount
  //des = obj1.item_name.value;     // base description
  des = obj1.basedes.value;     // base description
qty = obj1.quantity.value;         // get user quantity
  if (isNaN (qty) || qty < 1) { // make sure it's good
    alert ('"' + qty + '"' + ' is not a valid number!');
    return false;               // th-th-that's all, folks.
  }
  qty = qty*1.0;                // force to numeric
  
  if (qty >= 6){
	  amt = obj1.wholesale_amount.value * 1.0;
	  obj1.item_name.value = des + ", Wholesale Package of " + qty + " items @ &euro;" + Currency (amt) + " each.";
	   obj1.amount.value = Currency (amt * qty);
  }else{
		obj1.item_name.value = des + ", Retail price: &euro;" + Currency (amt) + ".";  
		obj1.amount.value = Currency (amt);
  }
}

