<!--

//parse decimal functions

function parseDec(val,places,sep) {

	// This function takes two arguments:
	//   (string || number)  val
	//            (integer)  places
	//             (string)  sep
	// val is the numeric string or number to parse
	// places represents the number of decimal
	// places to return at the end of the parse.
	// sep is an optional string to be used to separate
	// the whole units from the decimal units (default: '.')

	val = '' + val;
		// Implicitly cast val to (string)
	
	if (!sep) {
		sep = '.';
		// If separator isn't specified, then use a decimal point '.'
	}
	
	if (!places) { places = 0; }
	places = parseInt(places);
		// Make sure places is an integer
	
	if (!parseInt(val)) {
		// If val is null, zero, NaN, or not specified, then
		// assume val to be zero.  Add 'places' number of zeros after
		// the separator 'sep', and then return the value.  We're done here.
		val = '0';
		if (places > 0) {
			val += sep;
			while (val.substring((val.indexOf(sep))).length <= places) {
				val += '0';
			}
		}
		return val;
	}
	
	if ((val.indexOf('.') > -1) && (sep != '.')) {
		val = val.substring(0,val.indexOf('.')) + sep + val.substring(val.indexOf('.')+1);
			// If we're using a separator other than '.' then convert now.
	}
		
	if (val.indexOf(sep) > -1) {
		// If our val has a separator, then cut our value
		// into pre and post 'decimal' based upon the separator.
		pre = val.substring(0,val.indexOf(sep));
		post = val.substring(val.indexOf(sep)+1);
	} else {
		// Otherwise pre gets everything and post gets nothing.
		pre = val;
		post = '';
	}
	
	if (places > 0) {
		// If we're dealing with a decimal then...
		
		post = post.substring(0,(places+1));
			// We care most about the digit after 'places'
		
		if (post.length > places) {
			// If we have trailing decimal places then...
			
			//alert (parseInt(post.substring(post.length - 1)));

			if ( parseInt(post.substring(post.length - 1)) > 4 ) {
				post = '' + Math.round(parseInt(post) / 10);
				//post = '' + post.substring(0,post.length - 2) + (1/Math.pow(10,places));
				//post = ('' + post.substring(0,post.length - 2)) + (parseInt(post.substring(post.length - 1)) + 1);
			} else {
				post = '' + Math.round(parseInt(post));
			}
		}
		
		if (post.length > places) {
			post = '' + Math.round(parseInt(post.substring(0,places)));
		} else if (post.length < places) {
			while (post.length < places) {
				post += '0';
			}
		}
	
	} else {

		if (parseInt((post.substring(0,1))) > 4) {
			pre = '' + (parseInt(pre) + 1);
		} else {
			pre = '' + (parseInt(pre));	
		}
		post = '';
	}
	
	sep = (post.length > 0) ? sep : '';
		// Should we use a separator?

	val = pre + sep + post;
		// Rebuild val

	return val;
}

function parseMoney(val,sep) {

	// Specialized version of parseDec useful for
	// parsing money-related data.  Arguments:
	//   (string || number)  val
	//             (string)  sep
	// val is the monetary value to be parsed,
	// sep is an optional decimal separator (default: '.')
	
	return parseDec(val,2,sep);
}

function sepToDec(val,sep) {

	val = '' + val;

	if ((val.indexOf(sep) > -1) && (sep != '.')) {
		val = val.substring(0,val.indexOf(sep)) + '.' + val.substring(val.indexOf(sep)+1);
	}
	
	return val;
}

function decToSep(val,sep) {

	val = '' + val;
	sep = '' + sep;

	if ((val.indexOf('.') > -1) && (sep.length > 0)) {
		val = val.substring(0,val.indexOf('.')) + sep + val.substring(val.indexOf('.')+1);
	}

	return val;
}



// end parse decimal




function printIt(){ 

code=navigator.appCodeName;
browser=navigator.appName;
version=navigator.appVersion;
user=navigator.userAgent;
platform=navigator.platform;

if (user.indexOf('Mac')!=-1){
	if(user.indexOf('IE')!=-1){
		alert('Your browser does not support this function\n use the print button at the top of the page.');
	}
}

else {
        bName = navigator.appName; 
        bVer = parseInt(navigator.appVersion); 
         if (window.print) self.print();
         else if (bName == "Microsoft Internet Explorer" && bVer >= 4) VBPrint();
         
    }
}


function get_radio_value()
{
for (var i=0; i < document.the_form.deliveryFee.length; i++)
   {
   if (document.the_form.deliveryFee[i].checked)
      {
      var rad_val = document.the_form.deliveryFee[i].value;
	  alert(rad_val);
      }
   }
}



function calculateOrder(){
//       var postage = 8; 

//	   get the deliveryFee value
//	   for (var i=0; i < document.the_form.deliveryFee.length; i++)
//	   		{
//				if {document.the_form.deliveryFee[i].checked)
//					{
//					var orderDeliveryFee = document.the_form.deliveryFee[i].value;
//					}
//				}
//			}
			
//		 alert(orderDeliveryFee);

	for (var i=0; i < document.the_form.deliveryFee.length; i++)
   		{
   			if (document.the_form.deliveryFee[i].checked)
      		{
      			var orderDeliveryFee = document.the_form.deliveryFee[i].value;
      		}	
   		}

       var box1 = document.the_form.displayTotal1.value;
         if (box1 == ""){
         	box1=0
         	}
       
       var box2 = document.the_form.displayTotal2.value;
          if (box2 == ""){
         	box2=0
         	}
       
       var box3 = document.the_form.displayTotal3.value;
          if (box3 == ""){
         	box3=0
           	}
       
       var box4 = document.the_form.displayTotal4.value;
          if (box4 == ""){
         	box4=0
         	}
	
	
	var box5 = document.the_form.displayTotal5.value;
          if (box5 == ""){
         	box5=0
         	}

       
       var box6 = document.the_form.displayTotal6.value;
          if (box6 == ""){
         	box6=0
         	}

       
       var ansTotal = eval(parseDec(box1, 2)) + eval(parseDec(box2, 2)) + eval(parseDec(box3, 2)) + eval(parseDec(box4, 2)) + eval(parseDec(box5, 2)) + eval(parseDec(box6, 2));

         document.the_form.orderSubTotal.value =  parseDec((ansTotal), 2);
	  document.the_form.orderFullTotal.value =  parseDec((ansTotal + parseInt(orderDeliveryFee)), 2);
	  document.the_form.chequeAmount.value =  parseDec((ansTotal + parseInt(orderDeliveryFee)), 2);
}


function clearOrder(line) {
	
switch (line){
     case 1:
         document.the_form.strKite1.value = "SelectProduct";
	  document.the_form.displayCode1.value = "";
	  document.the_form.storeIndex1.value = "";
	  document.the_form.displayThePrice1.value ="";
         document.the_form.quantity1.value = "";
         document.the_form.displayTotal1.value="";
     break;

     case 2:
         document.the_form.strKite2.value = "SelectProduct";
	  document.the_form.displayCode2.value = "";
	  document.the_form.storeIndex2.value = "";
	  document.the_form.displayThePrice2.value ="";
         document.the_form.quantity2.value = "";
         document.the_form.displayTotal2.value="";
     break;

     case 3:
         document.the_form.strKite3.value = "SelectProduct";
	  document.the_form.displayCode3.value = "";
	  document.the_form.storeIndex3.value = "";
	  document.the_form.displayThePrice3.value ="";
         document.the_form.quantity3.value = "";
         document.the_form.displayTotal3.value="";     
     break;
     
     case 4:
         document.the_form.strKite4.value = "SelectProduct";
	  document.the_form.displayCode4.value = "";
	  document.the_form.storeIndex4.value = "";
	  document.the_form.displayThePrice4.value ="";
         document.the_form.quantity4.value = "";
         document.the_form.displayTotal4.value="";
     break;

     case 5:
         document.the_form.strKite5.value = "SelectProduct";
	  document.the_form.displayCode5.value = "";
	  document.the_form.storeIndex5.value = "";
	  document.the_form.displayThePrice5.value ="";
         document.the_form.quantity5.value = "";
         document.the_form.displayTotal5.value="";
     break;

     case 6:
         document.the_form.strKite6.value = "SelectProduct";
	  document.the_form.displayCode6.value = "";
	  document.the_form.storeIndex6.value = "";
	  document.the_form.displayThePrice6.value ="";
         document.the_form.quantity6.value = "";
         document.the_form.displayTotal6.value="";     
     break;

}
       
       
       calculateOrder();
}   



//begin routines to control dropdowns - exported from codebuilder.asp



function displayValue1(val) {
  if (val=="") return false;
  if (val=="undefined") return false;
	 var codeValue1 = Item[val]["code"];
	 document.the_form.displayCode1.value = codeValue1;
 
	 //this one remembers current selection For other parts of form
	 document.the_form.storeIndex1.value = val;
	 displayPrice1();
}
 
 
function displayPrice1() {
	 var getVal1 = document.the_form.storeIndex1.value;
 
	 if (getVal1 == "") {
	 alert("Please Select a product before indicating quantity");
	 document.the_form.quantity1.value = "";
	 }
	 else { 
	 var intQuantity1 = parseDec(document.the_form.quantity1.value, 2);
	 	 
	 //check If If bulk price threshold met
	 var bulkThreshold = Item[getVal1]["priceBulkThreshold"];
	 bulkThreshold *=1;
	 
	 if (bulkThreshold == 0) {
	     var showPrice1 = parseDec(Item[getVal1]["price"], 2);
	  }
	  else if (intQuantity1 >= bulkThreshold) {
		     var showPrice1 = parseDec(Item[getVal1]["priceBulk"], 2);		     
	  }
	  else if (intQuantity1 < bulkThreshold) {
	     var showPrice1 = parseDec(Item[getVal1]["price"], 2);
	  }	  
	 document.the_form.displayThePrice1.value = parseDec(showPrice1, 2);
	 if (intQuantity1 == 0) {
	 document.the_form.displayTotal1.value = 0;
	 } 
	 else {
	  document.the_form.displayTotal1.value = parseDec((showPrice1*intQuantity1),2);
	  calculateOrder();
	    } 
	  }
}


function displayValue2(val) {
  if (val=="") return false;
  if (val=="undefined") return false;
	 var codeValue2 = Item[val]["code"];
	 document.the_form.displayCode2.value = codeValue2;
 
	 //this one remembers current selection For other parts of form
	 document.the_form.storeIndex2.value = val;
	 displayPrice2();
}
 
 
function displayPrice2() {
	 var getVal2 = document.the_form.storeIndex2.value;
 
	 if (getVal2 == "") {
	 alert("Please Select a product before indicating quantity");
	 document.the_form.quantity2.value = "";
	 }
	 else { 
	 var intQuantity2 = document.the_form.quantity2.value;
	//check If If bulk price threshold met
	 var bulkThreshold = Item[getVal2]["priceBulkThreshold"];
	 bulkThreshold *=1;
	 
	 if (bulkThreshold == 0) {
	     var showPrice2 = Item[getVal2]["price"];
	  }
	  else if (intQuantity2 >= bulkThreshold) {
		     var showPrice2 = Item[getVal2]["priceBulk"];
	  }
	  else if (intQuantity2 < bulkThreshold) {
	     var showPrice2 = Item[getVal2]["price"];
	  }
	 document.the_form.displayThePrice2.value = parseDec(showPrice2,2);
	 if (intQuantity2 == 0) {
	 document.the_form.displayTotal2.value = 0;
	 } 
	 else {
	  document.the_form.displayTotal2.value = parseDec((showPrice2*intQuantity2),2);
	  calculateOrder();
	    } 
	  }
}


function displayValue3(val) {
  if (val=="") return false;
  if (val=="undefined") return false;
	 var codeValue3 = Item[val]["code"];
	 document.the_form.displayCode3.value = codeValue3;
 
	 //this one remembers current selection For other parts of form
	 document.the_form.storeIndex3.value = val;
	 displayPrice3();
}
 
 
function displayPrice3() {
	 var getVal3 = document.the_form.storeIndex3.value;
 
	 if (getVal3 == "") {
	 alert("Please Select a product before indicating quantity");
	 document.the_form.quantity3.value = "";
	 }
	 else { 
	 var intQuantity3 = document.the_form.quantity3.value;
	//check If If bulk price threshold met
	 var bulkThreshold = Item[getVal3]["priceBulkThreshold"];
	 bulkThreshold *=1;
	 
	 if (bulkThreshold == 0) {
	     var showPrice3 = Item[getVal3]["price"];
	  }
	  else if (intQuantity3 >= bulkThreshold) {
		     var showPrice3 = Item[getVal3]["priceBulk"];
	  }
	  else if (intQuantity3 < bulkThreshold) {
	     var showPrice3 = Item[getVal3]["price"];
	  }
	 document.the_form.displayThePrice3.value = parseDec(showPrice3,2);
	 if (intQuantity3 == 0) {
	 document.the_form.displayTotal3.value = 0;
	 } 
	 else {
	  document.the_form.displayTotal3.value = parseDec((showPrice3*intQuantity3),2);
	  calculateOrder();
	    } 
	  }
}


function displayValue4(val) {
  if (val=="") return false;
  if (val=="undefined") return false;
	 var codeValue4 = Item[val]["code"];
	 document.the_form.displayCode4.value = codeValue4;
 
	 //this one remembers current selection For other parts of form
	 document.the_form.storeIndex4.value = val;
	 displayPrice4();
}
 
 
function displayPrice4() {
	 var getVal4 = document.the_form.storeIndex4.value;
 
	 if (getVal4 == "") {
	 alert("Please Select a product before indicating quantity");
	 document.the_form.quantity4.value = "";
	 }
	 else { 
	 var intQuantity4 = document.the_form.quantity4.value;
	//check If If bulk price threshold met
	 var bulkThreshold = Item[getVal4]["priceBulkThreshold"];
	 bulkThreshold *=1;
	 
	 if (bulkThreshold == 0) {
	     var showPrice4 = Item[getVal4]["price"];
	  }
	  else if (intQuantity4 >= bulkThreshold) {
		     var showPrice4 = Item[getVal4]["priceBulk"];
	  }
	  else if (intQuantity4 < bulkThreshold) {
	     var showPrice4 = Item[getVal4]["price"];
	  }
	 document.the_form.displayThePrice4.value = parseDec(showPrice4,2);
	 if (intQuantity4 == 0) {
	 document.the_form.displayTotal4.value = 0;
	 } 
	 else {
	  document.the_form.displayTotal4.value = parseDec((showPrice4*intQuantity4),2);
	  calculateOrder();
	    } 
	  }
}


function displayValue5(val) {
  if (val=="") return false;
  if (val=="undefined") return false;
	 var codeValue5 = Item[val]["code"];
	 document.the_form.displayCode5.value = codeValue5;
 
	 //this one remembers current selection For other parts of form
	 document.the_form.storeIndex5.value = val;
	 displayPrice5();
}
 
 
function displayPrice5() {
	 var getVal5 = document.the_form.storeIndex5.value;
 
	 if (getVal5 == "") {
	 alert("Please Select a product before indicating quantity");
	 document.the_form.quantity5.value = "";
	 }
	 else { 
	 var intQuantity5 = document.the_form.quantity5.value;
	//check If If bulk price threshold met
	 var bulkThreshold = Item[getVal5]["priceBulkThreshold"];
	 bulkThreshold *=1;
	 
	 if (bulkThreshold == 0) {
	     var showPrice5 = Item[getVal5]["price"];
	  }
	  else if (intQuantity5 >= bulkThreshold) {
		     var showPrice5 = Item[getVal5]["priceBulk"];
	  }
	  else if (intQuantity5 < bulkThreshold) {
	     var showPrice5 = Item[getVal5]["price"];
	  }
	 document.the_form.displayThePrice5.value = parseDec(showPrice5,2);
	 if (intQuantity5 == 0) {
	 document.the_form.displayTotal5.value = 0;
	 } 
	 else {
	  document.the_form.displayTotal5.value = parseDec((showPrice5*intQuantity5),2);
	  calculateOrder();
	    } 
	  }
}


function displayValue6(val) {
  if (val=="") return false;
  if (val=="undefined") return false;
	 var codeValue6 = Item[val]["code"];
	 document.the_form.displayCode6.value = codeValue6;
 
	 //this one remembers current selection For other parts of form
	 document.the_form.storeIndex6.value = val;
	 displayPrice6();
}
 
 
function displayPrice6() {
	 var getVal6 = document.the_form.storeIndex6.value;
 
	 if (getVal6 == "") {
	 alert("Please Select a product before indicating quantity");
	 document.the_form.quantity6.value = "";
	 }
	 else { 
	 var intQuantity6 = document.the_form.quantity6.value;
	//check If If bulk price threshold met
	 var bulkThreshold = Item[getVal6]["priceBulkThreshold"];
	 bulkThreshold *=1;
	 
	 if (bulkThreshold == 0) {
	     var showPrice6 = Item[getVal6]["price"];
	  }
	  else if (intQuantity6 >= bulkThreshold) {
		     var showPrice6 = Item[getVal6]["priceBulk"];
	  }
	  else if (intQuantity6 < bulkThreshold) {
	     var showPrice6 = Item[getVal6]["price"];
	  }
	 document.the_form.displayThePrice6.value = parseDec(showPrice6,2);
	 if (intQuantity6 == 0) {
	 document.the_form.displayTotal6.value = 0;
	 } 
	 else {
	  document.the_form.displayTotal6.value = parseDec((showPrice6*intQuantity6),2);
	  calculateOrder();
	    } 
	  }
}

//-->
