// JavaScript Document
<!--
// Product Info
var prodInfo = new Array();
prodInfo[0] = new Array();
prodInfo[0].code = "200DLJ";
prodInfo[0].title = "3 pack Desert Lime Jam";
prodInfo[0].price = "24";

prodInfo[1] = new Array();
prodInfo[1].code = "200DLOM";
prodInfo[1].title = "3 pack Desert Lime & Orange Marmalade";
prodInfo[1].price = "24";

prodInfo[2] = new Array();
prodInfo[2].code = "200DLTJ";
prodInfo[2].title = "3 pack Desert Lime & Tomato Jam";
prodInfo[2].price = "24";

prodInfo[3] = new Array();
prodInfo[3].code = "200SMPL";
prodInfo[3].title = "Jam Delights - 1 of each flavour";
prodInfo[3].price = "24";

prodInfo[4] = new Array();
prodInfo[4].code = "250DLG";
prodInfo[4].title = "3 pack Desert Limes Glac&eacute;";
prodInfo[4].price = "27";

prodInfo[5] = new Array();
prodInfo[5].code = "250ADLS";
prodInfo[5].title = "3 pack Apple & Desert Lime Sauce";
prodInfo[5].price = "27";

prodInfo[6] = new Array();
prodInfo[6].code = "250DLC";
prodInfo[6].title = "3 pack Desert Lime Chutney";
prodInfo[6].price = "27";

prodInfo[7] = new Array();
prodInfo[7].code = "250SMPL";
prodInfo[7].title = "Gourmet Gift Box - 1 of each flavour";
prodInfo[7].price = "27";

prodInfo[8] = new Array();
prodInfo[8].code = "CORDIAL";
prodInfo[8].title = "2 pack Desert Lime Cordial";
prodInfo[8].price = "14";

prodInfo[9] = new Array();
prodInfo[9].code = "PASTE";
prodInfo[9].title = "3 pack Desert Lime Paste";
prodInfo[9].price = "12";

prodInfo[10] = new Array();
prodInfo[10].code = "200DLJCRTN";
prodInfo[10].title = "Desert Lime Jam - 24 in Carton";
prodInfo[10].price = "144";

prodInfo[11] = new Array();
prodInfo[11].code = "200DLOMCRTN";
prodInfo[11].title = "Desert Lime & Orange Marmalade - 24 in Carton";
prodInfo[11].price = "144";

prodInfo[12] = new Array();
prodInfo[12].code = "200DLTJCRTN";
prodInfo[12].title = "Desert Lime & Tomato Jam - 24 in Carton";
prodInfo[12].price = "144";

prodInfo[13] = new Array();
prodInfo[13].code = "200SMPLCRTN";
prodInfo[13].title = "Jam Delights 24 in Carton -  4 of each flavour";
prodInfo[13].price = "144";

prodInfo[14] = new Array();
prodInfo[14].code = "250DLGCRTN";
prodInfo[14].title = "Desert Limes Glac&eacute; - 24 in Carton";
prodInfo[14].price = "168";

prodInfo[15] = new Array();
prodInfo[15].code = "250ADLSCRTN";
prodInfo[15].title = "Apple & Desert Lime Sauce - 24 in Carton";
prodInfo[15].price = "168";

prodInfo[16] = new Array();
prodInfo[16].code = "250DLCCRTN";
prodInfo[16].title = "Desert Lime Chutney - 24 in Carton";
prodInfo[16].price = "168";

prodInfo[17] = new Array();
prodInfo[17].code = "250SMPLCRTN";
prodInfo[17].title = "Gourmet Gift Box 24 in Carton - 4 of each flavour";
prodInfo[17].price = "168";

prodInfo[18] = new Array();
prodInfo[18].code = "CORDIALCRTN";
prodInfo[18].title = "Desert Lime Cordial - 12 in Carton";
prodInfo[18].price = "90";

prodInfo[19] = new Array();
prodInfo[19].code = "PASTECRTN";
prodInfo[19].title = "Desert Lime Paste - 12 in Carton";
prodInfo[19].price = "45";

prodInfo[20] = new Array();
prodInfo[20].code = "VARIETY";
prodInfo[20].title = "Variety box - 6 desert lime products in 100g tubs";
prodInfo[20].price = "22.5";

// AU only
var shipCarton = 12.50;

// Shipping Costs
var shipCosts = new Array();
shipCosts[0] = new Array();
shipCosts[0].id = "AU";
shipCosts[0].text = "Aust Standard";
shipCosts[0].pack = new Array();
shipCosts[0].pack[0] = 8;
shipCosts[0].pack[1] = 9;
shipCosts[0].pack[2] = 10;
shipCosts[0].pack[3] = 11;
shipCosts[0].pack[4] = 12;
shipCosts[1] = new Array();
shipCosts[1].id = "NZ";
shipCosts[1].text = "NZ Economy Air";
shipCosts[1].pack = new Array();
shipCosts[1].pack[0] = 22;
shipCosts[1].pack[1] = 33.50;
shipCosts[1].pack[2] = 42.50;
shipCosts[1].pack[3] = 51.50;
shipCosts[1].pack[4] = 63.50;
shipCosts[2] = new Array();
shipCosts[2].id = "AP";
shipCosts[2].text = "Asia Pacific Economy Air";
shipCosts[2].pack = new Array();
shipCosts[2].pack[0] = 26;
shipCosts[2].pack[1] = 39.50;
shipCosts[2].pack[2] = 50.00;
shipCosts[2].pack[3] = 60.50;
shipCosts[2].pack[4] = 74.50;
shipCosts[3] = new Array();
shipCosts[3].id = "US";
shipCosts[3].text = "USA, Canada & Middle East Economy Air";
shipCosts[3].pack = new Array();
shipCosts[3].pack[0] = 32.50;
shipCosts[3].pack[1] = 53;
shipCosts[3].pack[2] = 69.50;
shipCosts[3].pack[3] = 86;
shipCosts[3].pack[4] = 108;
shipCosts[4] = new Array();
shipCosts[4].id = "REST";
shipCosts[4].text = "Rest of World Economy Air";
shipCosts[4].pack = new Array();
shipCosts[4].pack[0] = 36.50;
shipCosts[4].pack[1] = 60.50;
shipCosts[4].pack[2] = 80;
shipCosts[4].pack[3] = 99.50;
shipCosts[4].pack[4] = 125.50;


// Functions
function getShipLookUp(type) {
	var id = 0;
	for (var i=0; i < shipCosts.length; i++) {
		if (type == shipCosts[i].id) {
			id = i;
			break;
		}
	}
	return id;
}

function getProductInfo(code) {
	for (var j = 0; j < prodInfo.length; j++) {
		if (code == prodInfo[j].code) {
			return j;
		}
	}
	return -1;
}

function setShipping(form, c, pg) {
	var val = eval("form."+c);
	for (var ri=0; ri<val.length; ri++) {
		if (val[ri].checked) {
			var val = "" + val[ri].value;
			writeCookie("ship",val,24);
			break;
		}
	}
	window.location.href = pg;
}

function JRI_FormatNumber(expr, decplaces) {
	if (isNaN(expr)) {
		return "NA";
	}
	var str = "" + Math.round(eval(expr) * Math.pow(10, decplaces))
	while ( str.length <= decplaces )
	{
		str = "0" + str;
	}
	var decpoint = str.length - decplaces;
	var strFNum = (decplaces > 0)? str.substring(0,decpoint) + "." + str.substring(decpoint, str.length):str.substring(0,decpoint);	
	return strFNum;
}

function JRI_Dollarize(expr) {
 return "$" + JRI_FormatNumber(expr, 2)
}
function chkCookiesEnabled() {
	var tmpcookie = new Date();
	chkcookie = (tmpcookie.getTime() + '');
	document.cookie = "chkcookie=" + chkcookie + "; path=/";
	var status = true
	if (document.cookie.indexOf(chkcookie,0) < 0) {
		status = false;
	}
	return status;
}

function clearOrder() {
	writeCookie("cart", "", 24)		
	window.location.href = window.location.href;
}

// Shopping Cart functions
// readCookie("myCookie")
// Reads the cookie "myCookie"
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}
function getNumCartItems () {
	var qty = 0;
	var cart = readCookie("cart");
	var cartItem = String(cart).split("|");
	if (cartItem.length/2 < 1) {
		writeCookie("cart","",24);
		return (0);
	}
	for (q=0; q < cartItem.length; q+=2) {
		qty += parseInt(cartItem[q+1]);
	}
	return (qty);
}

function addItem(form, code, c, q) {
	var cart = readCookie("cart");

	if (code == "") {
		code = ( (eval("form."+c) != null) ? eval("form."+c+".options[form."+c+".selectedIndex].value"):"" );
	}
	
	// if item already in cart - do nothing
	if (String(cart).indexOf(code) >= 0)return;
	
	// Get item quantity and make sure its a valid number
	var qty =  ( (eval("form."+q) != null) ? eval("form."+q+".value"):"" );
	if (isNaN(qty)) {
		alert("You must enter a valid number for the quantity");
		return;
	}
	cart += (String(cart).length > 0)? "|"+code+"|"+qty : ""+code+"|"+qty;

	writeCookie("cart", cart, 24)	
	window.location.href = window.location.href;
}

function updateItem(form, itemNo) {
	var cart = readCookie("cart");
	var cartItem = String(cart).split("|");
	
	var qty =  (eval("form.q"+itemNo) != null) ? eval("form.q"+itemNo+".value"):"" ;
	// If invalid qty is entered - reset to value already in cart
	if (isNaN(qty)) {
		alert("You must enter a valid number for the quantity");
		var obj = eval("form.q"+itemNo)
		obj.value = cartItem[(parseInt(itemNo) + 1)]
	} else {
		// Delete item or Update items quantity
		if (qty == "0") {
			for (i=itemNo*2; i < cartItem.length-1; i++) {
				cartItem[i] = cartItem[i+2];
			}
			cartItem.length -= 2;
		} else {
			// update cart with new item quantity
			cartItem[ (parseInt(itemNo*2) + 1) ] = qty;
		}	
		cart = "";
		for (i=0; i < cartItem.length; i++) {
			cart += (String(cart).length > 0)? "|"+cartItem[i] : ""+cartItem[i];
		}
		writeCookie("cart", cart, 24)	
	}
	window.location.href = "view_cart.html";
}
//-->
