function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//
function dispTot()
{
	greenpasteTotsm = parseFloat(document.form.Green_Paste_sm.value);
	greenpasteTot = parseFloat(document.form.Green_Paste.value);
	greenTot = greenpasteTotsm+greenpasteTot
	totFormated = format(greenTot);
	document.form.Green_Paste_Tot.value = totFormated;
	hotchillsm = parseFloat(document.form.Hot_Chilli_Sauce_sm.value);
	hotchill = parseFloat(document.form.Hot_Chilli_Sauce.value);
	hotTot = hotchillsm+hotchill
	totFormated = format(hotTot);
	document.form.Hot_Chilli_Sauce_Tot.value = totFormated;
	mildchillsm = parseFloat(document.form.Mild_Chilli_Sauce_sm.value);
	mildchill = parseFloat(document.form.Mild_Chilli_Sauce.value);
	mildTot = mildchillsm+mildchill
	totFormated = format(mildTot);
	document.form.Mild_Chilli_Sauce_Tot.value = totFormated;
	sweetchillsm = parseFloat(document.form.Sweet_Chilli_Sauce_sm.value);
	sweetchill = parseFloat(document.form.Sweet_Chilli_Sauce.value);
	sweetTot = sweetchillsm+sweetchill
	totFormated = format(sweetTot);
	document.form.Sweet_Chilli_Sauce_Tot.value = totFormated;
	return true;
}
//
function reSet()
{
	//alert("boo")
	itemCost = 0;
	itemTotal = 0;
	qty = 0;
	freightTotal = 0;
	NSW_Freight = 7.50;
	Australian_Freight = 9.50;
	OS_Freight = 0;
	orderTotal = 0;
	//calcFreight = 0;
}

function format(num)
<!-- function format based on code from Tim Wallace.  (Thanx)
   {

   finished=Math.floor(num)+".";

   var base=100*(num-Math.floor(num))+0.5;

   finished += Math.floor(base/10);

   finished += Math.floor(base%10);

   return finished;

   }
// display totals

// Calculate Freight.
function calcFreight()
{
	// freight initialised to zero for overseas purchases
	freightTotal = 0;
	currentFreight = document.form.Freight.value;
	bill_state = document.form.R_Bill_State.selectedIndex;
	ship_state = document.form.Ship_State.selectedIndex;
	bill_Postcode = document.form.R_Bill_Postcode.value;
	ship_Postcode = document.form.Ship_Postcode2.value;
	freight_state = bill_state;
	if (ship_state > "0")
	{
			freight_state = ship_state;
	}
		//alert ("Ship state = "+freight_state+ " Postcode = "+ship_Postcode);
	if (freight_state == "2")
	{
		freightTotal = NSW_Freight;
	}
		
	if (freight_state == "1" || freight_state == "3" || freight_state == "4" || freight_state == "5" || freight_state == "6" || freight_state == "7" || freight_state == "8")
	{
		freightTotal = Australian_Freight;
	}
		
	if (currentFreight > "0")
	{
		orderTotal = (orderTotal - currentFreight) + freightTotal;
	}
	else
	{
		orderTotal = orderTotal + freightTotal;
	}
	showFreight = format(freightTotal);
	showTotal = format(orderTotal);
	document.form.Freight.value = showFreight; // value wil be zero for OS purchases.
	document.form.order_total.value = showTotal;
	return true;
}



// Extract the line item name and price
function itemPrice(name, price) 
{
  this.name = name;
  this.price = price;
}

// Create price list for calculating order. ... CHANGE ITEM and PRICE HERE ...

	lineItem = new Array;
	lineItem[1] = new itemPrice("Green_Paste_sm" , 4.50) ;
	lineItem[2] = new itemPrice("Green_Paste" , 6.60) ;
	lineItem[3] = new itemPrice("Hot_Chilli_Sauce_sm" , 4.50) ;
	lineItem[4] = new itemPrice("Hot_Chilli_Sauce" , 6.00) ;
	lineItem[5] = new itemPrice("Mild_Chilli_Sauce_sm" , 4.50) ;
	lineItem[6] = new itemPrice("Mild_Chilli_Sauce" , 6.00) ;
	lineItem[7] = new itemPrice("Sweet_Chilli_Sauce_sm" , 4.50) ;
	lineItem[8] = new itemPrice("Sweet_Chilli_Sauce" , 6.00) ;
	lineItem[9] = new itemPrice("Fiery_Harissa_Paste" , 4.50) ;

// Calculate items purchased and order Total
function calcPrice(item, qty)
{	
	itemName = lineItem[item].name;
	itemCost = lineItem[item].price;
	itemTotal = itemCost * qty;
	itemFormated = format(itemTotal);
	previousValue = document.form.elements[itemName].value;
	if (previousValue > 0)
	{
		orderTotal = (orderTotal - previousValue) + itemTotal;
	} else {
		orderTotal = orderTotal + itemTotal;
	}
	//alert ("total: "+orderTotal);
	
	totalFormated = format(orderTotal);
	document.form.order_total.value = totalFormated;
	document.form.elements[itemName].value = itemFormated;
	document.form.order_total.focus();
	dispTot();
	//document.form.elements[itemName].focus();
	//document.form.elements[itemName].select();
	//document.form.order_total.focus();
	//document.form.order_total.select();
	calcFreight();
	return true;
}