<!--
var str_products;
var str_quantity;
var arrItems = new Array();
var arrQty = new Array();

var today = new Date();
var date = new Date(today.getYear(),today.getMonth(), today.getDate(),today.getHours() + 1,today.getMinutes(),today.getSeconds());
////var date = new Date(2005,4,23)
//var expiry_date = date; 
var exp=new Date();
exp.setTime(exp.getTime()+(1000*60*60));
var expiry_date = exp.toGMTString(); 


function place(new_item)
{
	str_products = getCookie('products', '#');
	str_quantity = getCookie('quantity', '#');

	str_products = str_products + "prod_" + new_item; 
	str_quantity = str_quantity + "qty_" + new_item + "=1";
    
    document.cookie = "products=#" + str_products + "#;expires=" + expiry_date;
	document.cookie = "quantity=#" + str_quantity + "#;expires=" + expiry_date;
	getBasketSize();
   
}

function getCookie(name, separator)
{
	var strTotal, strCookie;
	var intEnd;
	var arrCookie = new Array();
	
	strTotal = document.cookie;

    

	if (strTotal.indexOf(name) == -1)
	{
		strCookie = '';
	}
	else
	{
		arrCookie = strTotal.split(name);
		strCookie = arrCookie[1] ;
		strCookie = strCookie.substr(2);
		intEnd = strCookie.indexOf(separator);
		strCookie = strCookie.substring(0, intEnd);
	}
	return strCookie;
}

function getBasketSize()
{
	var strQty, strTotal;
	var arrItems;
	var intLength;
	
	strQty = getCookie('quantity', '#');
	if (strQty.indexOf('=') == -1)
	{
		strTotal = 'You have 0 item(s) in your basket';
	}
	else
	{
		arrQty = strQty.split('=');
		strTotal = arrQty.length - 1 + ' item(s) in your basket';
	}
	document.getElementById('total').innerHTML = strTotal
}


function setRegion(region)
{
	if (document.getElementById('select_region').value == 'Ireland')
	{	
		document.cookie = "region=" + region + ";expires=" + expiry_date;	
	}
	else if (document.getElementById('select_region').value == 'UK')
	{	
		document.cookie = "region=" + region + ";expires=" + expiry_date;	
	}
	else if (document.getElementById('select_region').value == 'Europe')
	{	
		document.cookie = "region=" + region + ";expires=" + expiry_date;	
	}
	else if (document.getElementById('select_region').value == 'ROW')
	{	
		document.cookie = "region=" + region + ";expires=" + expiry_date;	
	}
}

function updateCart(array)
{
	var strCookie, strQty, strProducts;
	for(i=1; i<array.length; i++)
	{
		strQty = document.buy['qty_' + i].value;
		strCookie = strCookie + "qty_" + array[i] + "=" + strQty;
		strProducts = strProducts + "prod_" + array[i]; 
	}
	empty_basket();
	document.cookie = "products=#" + strProducts + "#;expires=" + expiry_date;
	document.cookie = "quantity=#" + strCookie + "#;expires=" + expiry_date;
}


function deleteItem(delindex) 
{
	var strCookie, strProducts, strQty, strQuantity, strItem;
	var strTempItem, strTempQty;
	var intPos, intPos1, intEnd;

	updateCart(arrItems);
	
	strCookie = document.cookie;
	intPos = strCookie.indexOf('quantity');
	strProducts = strCookie.substring(0,intPos-2);
	intPos1 = strCookie.indexOf(';');
	strQty = strCookie.substr(intPos);

	arrItems = strProducts.split('prod_');
	arrQty = strQty.split('qty_');
	var size = arrItems.length;
	
	for(i=1; i<size; i++)
	{
		if (i==delindex)
		{
			for (var j=delindex; j<size-1; j++)
			{
				arrItems[j] = arrItems[j+1];
				arrQty[j] = arrQty[j+1];
			}
		}
	}
	
	arrItems.length = size-1;
	arrQty.length = size-1;
	
	for(var k=1; k<arrItems.length; k++)
	{
		strTempItem = strTempItem + 'prod_' + arrItems[k];
		strTempQty = strTempQty + 'qty_' + arrQty[k];
	}
	document.cookie = "products=#" + strTempItem + "#; expires=" + expiry_date;
	document.cookie = "quantity=#" + strTempQty + "#; expires=" + expiry_date;
	
	//document.buy.submit();
}


function display_cart()
{
	var strCookie, strProducts, strQty;
	var intPos, intPos1, intEnd, intPrice, intTotal=0;
	
	strProducts = getCookie('products', '#');
	strQty = getCookie('quantity', '#');
	arrItems = strProducts.split('prod_');
	arrQty = strQty.split('qty_');
	
	if (arrItems.length > 1)
	{
		document.write("<table width='600' border='1' cellpadding='0' cellspacing='0' bordercolor='#A42117'>");
			document.write("<tr>");
				document.write("<td>");

					document.write("<table class='textBody' border='0' width='600' cellspacing='0'>");
					

					document.write("<tr bgcolor='#A42117'>");
						document.write("<td><span class='textBodyBold3'>Item</span></td>");
						document.write("<td><span class='textBodyBold3'>Quantity</span></td>");
						document.write("<td><span class='textBodyBold3'>Price (Individual)</span></td>");
						document.write("<td><span class='textBodyBold3'>Price (Total)</span></td>");
						document.write("<td>&nbsp;</td>");
					document.write("</tr>");
			
					// loop through array, skipping first item
					for (var i=1; i<arrItems.length; i++) 
					{
						strQty = arrQty[i];
						intPos = strQty.indexOf('=');
						strQty = strQty.substr(intPos+1);
						intEnd = strQty.lastIndexOf(':');
						if (intEnd!=-1)
						{
							strQty = strQty.substr(intEnd+1);
						}
						// write items to page
						document.write("<tr>");
							document.write("<td>" + arrProducts[arrItems[i]][1] + "<input type='hidden' name='hdnName_" + i + "' id='hdnName_" + i + "' value='" + arrProducts[arrItems[i]][1] + "'></td>");
							document.write("<td><input name='qty_" + i + "' id='qty_" + i + "' type='text' size='2' value='" + strQty + "' maxlength='3' class='textBodyBold2' onBlur='calc_price(" + i + ")'></td>");
							document.write("<td>&euro;" + arrProducts[arrItems[i]][4] + "<input type='hidden' name='hdnPrice_" + i + "' value='" + arrProducts[arrItems[i]][4] + "'></td>");
							document.write("<td>&euro;<span id='price_" + i + "'>" + arrProducts[arrItems[i]][4] + "</span></td>");
							document.write("<td><span style='cursor:pointer' onClick='updateCart(arrItems);'>Update</span> | <span style='cursor:pointer' onClick='deleteItem(" + i + ", arrItems, arrQty);'>Delete</span></td>");
						document.write("</tr>");
					}
					document.write("<tr>");
						document.write("<td colspan='5'>&nbsp;</td>");
					document.write("</tr>");	

					document.write("<tr>");
						document.write("<td>&nbsp;</td>");
						document.write("<td>&nbsp;</td>");
						document.write("<td><strong>Total:</strong></td>");
						document.write("<td><strong><span id='totalPrice'></span></strong></td>");
						document.write("<td>&nbsp;</td>");
					document.write("</tr>");	

					document.write("<tr>");
						document.write("<td><a href='online.asp'>&raquo; Continue Shopping</a></td>");
						document.write("<td>&nbsp;</td>");
						document.write("<td><span style='cursor:pointer' onClick='showBill();'>Checkout</span></td>");
						document.write("<td>&nbsp;</td>");
						document.write("<td>&nbsp;</td>");
					document.write("</tr>");
					document.write("<tr>");
						document.write("<td>&nbsp;</td>");
						document.write("<td>&nbsp;</td>");
						document.write("<td>&nbsp;</td>");
						document.write("<td>&nbsp;</td>");
						document.write("<td>&nbsp;</td>");
					document.write("</tr>");	
					document.write("</table>");
				document.write("</td>");
			document.write("</tr>");
		document.write("</table>");
		document.write("<input type='hidden' name='size' value='" + arrItems.length + "'>");
	}
	else
	{
		document.write("<span class='textBodyBold'>There are no items in your basket<br/><br/><a href='online.asp'> &raquo; Continue Shopping</a></span>");
	}
}


function empty_basket(){
	var kill_date = new Date("January 1, 1970");
	
	document.cookie = "products=;expires=" + kill_date.toGMTString();
	document.cookie = "quantity=;expires=" + kill_date.toGMTString();
	//document.cookie = "region=;expires=" + kill_date.toGMTString();
	window.location.reload();
}

function calc_price(index)
{
	strTemp = arrItems[index];
	arrTemp = strTemp.split(":");
	document.getElementById('price_' + index).innerHTML = round((arrProducts[arrTemp[0]][4])*(document.getElementById('qty_' + index).value));
}

function calc_total()
{
	var intTotal=0;
	if (arrItems.length > 1)
	{
			for (var j=1; j<arrItems.length; j++)
		{
			intTotal = intTotal + (document.getElementById('qty_' + j).value)*(arrProducts[arrItems[j]][4]);
		}
		document.getElementById('totalPrice').innerHTML = round(intTotal, 2);
		document.getElementById('hdnTotal').value = round(intTotal, 2);
	}
}

function update_prices()
{
	var intTotal=0;
	if (arrItems.length > 1)
	{
		for (var j=1; j<arrItems.length; j++)
		{
			intTotal = (document.getElementById('qty_' + j).value)*(arrProducts[arrItems[j]][4]);
			document.getElementById('price_' + j).innerHTML = round(intTotal, 2);
		}
	}
}


function calc_qty(index)
{
	strTemp = arr_items[index];
	i = strTemp.lastIndexOf(":");
	strTemp = strTemp.substr(i + 1);
	
	return strTemp;
}

function changeLink(id)
{
	var strCookie = getCookie('products', '#');
	if (strCookie.indexOf('prod_' + id) == -1)
	{
		place(id);
		document.getElementById('add_' + id).innerHTML = 'In Basket';
	}
}

function checkLinks()
{
	var strCookie = getCookie('products', '#');
		
	for (var i=0; i<arrProducts.length-1; i++)
	{
		if (strCookie.indexOf('prod_' + i) != -1)
		{
			document.getElementById('add_' + i).innerHTML = 'In Basket';
		}
	}
}

function round(number,X) {
// rounds number to X decimal places, defaults to 2
    X = (!X ? 2 : X);
    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function validateOrder()
{
	var bill_errors = 0
	var bill_error_string = ""
	var strName
	
	
	// validates the billing details
	if (document.getElementById('name').value == "") 
	{
		bill_error_string = bill_error_string + "Customer Name\n";
		bill_errors = 1
	}
	if (document.getElementById('ship_add').value == "")
	{	
		bill_error_string = bill_error_string + "Shipping Address\n";
		bill_errors = 1
	}
	if (document.getElementById('phone').value == "")
	{
		bill_error_string = bill_error_string + "Telephone Number\n";
		bill_errors = 1
	}
	if (document.getElementById('email').value == "")
	{
		bill_error_string = bill_error_string + "Email Address\n";
		bill_errors = 1
	}	
	if (document.getElementById('cc_name').value == "")
	{
		bill_error_string = bill_error_string + "Credit Card Name\n";
		bill_errors = 1
	}	
	if (document.getElementById('cc_type').value == "")
	{
		bill_error_string = bill_error_string + "Credit Card Type\n";
		bill_errors = 1
	}	
	if (document.getElementById('cc_num').value == "")
	{
		bill_error_string = bill_error_string + "Credit Card Number\n";
		bill_errors = 1
	}	
	if (document.getElementById('cc_expiry').value == "")
	{
		bill_error_string = bill_error_string + "Expiry Date\n";
		bill_errors = 1
	}	
	if (document.getElementById('bill_add').value == "")
	{
		bill_error_string = bill_error_string + "Billing Address 1\n";
		bill_errors = 1
	}	
	
	if (bill_errors == 0)
	{	
		document.buy.submit();
	}
	if (bill_errors == 1)
	{
		alert("The following billing items were not completed properly:\n" + bill_error_string)
	}
	

}


function validCreditCardLength(box,cclength)
{	
	if (box.value != "")
	{	
		if (box.value.length != cclength)
		{
			alert ('The value entered has an incorrect number of digits');
			box.innerText = ""
			box.focus();
		}
		if (isNaN(box.value))
		{
			alert ('The value entered must only contain digits');
			box.innerText = ""
			box.focus();
		}
	}
} 

function changeprice(region)
{
	if ((document.getElementById('select_region').value == 'Ireland') || (region == 'Ireland'))
	{	
		document.getElementById('pr_salted_nuts_30').value = "€26.33";
		document.getElementById('pr_salted_nuts_50').value = "€29.06";
		document.getElementById('pr_dry_roast').value = "€29.06";
		document.getElementById('pr_cashew').value = "€35.85";
		document.getElementById('pr_pistachio').value = "€37.10";
		document.getElementById('pr_chilli').value = "€34.45";
		document.getElementById('pr_salted_pop_15').value = "€29.33";
		document.getElementById('pr_salted_pop_30').value = "€28.83";
		document.getElementById('pr_cheese_pop_30').value = "€32.64";
		document.getElementById('pr_cheeseonion_crisp_35').value = "€41.80";
		
		document.cookie = "region=#" + document.getElementById('select_region').value + "#;expires=" + expiry_date;
	}
	else if ((document.getElementById('select_region').value == 'UK') || (region == 'UK'))
	{	
		document.getElementById('pr_salted_nuts_30').value = "€40.82";
		document.getElementById('pr_salted_nuts_50').value = "€43.56";
		document.getElementById('pr_dry_roast').value = "€43.56";
		document.getElementById('pr_cashew').value = "€50.35";
		document.getElementById('pr_pistachio').value = "€51.60";
		document.getElementById('pr_chilli').value = "€48.95";
		document.getElementById('pr_salted_pop_15').value = "€46.83";
		document.getElementById('pr_salted_pop_30').value = "€46.33";
		document.getElementById('pr_cheese_pop_30').value = "€50.14";
		document.getElementById('pr_cheeseonion_crisp_35').value = "€59.30";
		
		document.cookie = "region=#" + document.getElementById('select_region').value + "#;expires=" + expiry_date;
	}
	else if (document.getElementById('select_region').value == 'Europe')
	{	
		document.getElementById('pr_salted_nuts_30').value = "€46.82";
		document.getElementById('pr_salted_nuts_50').value = "€49.56";
		document.getElementById('pr_dry_roast').value = "€49.56";
		document.getElementById('pr_cashew').value = "€56.35";
		document.getElementById('pr_pistachio').value = "€57.60";
		document.getElementById('pr_chilli').value = "€54.95";
		document.getElementById('pr_salted_pop_15').value = "€51.83";
		document.getElementById('pr_salted_pop_30').value = "€51.33";
		document.getElementById('pr_cheese_pop_30').value = "€55.14";
		document.getElementById('pr_cheeseonion_crisp_35').value = "€64.30";
		
		document.cookie = "region=#" + document.getElementById('select_region').value + "#;expires=" + expiry_date;
	}
	else if (document.getElementById('select_region').value == 'ROW')
	{	
		document.getElementById('pr_salted_nuts_30').value = "€46.82";
		document.getElementById('pr_salted_nuts_50').value = "€49.56";
		document.getElementById('pr_dry_roast').value = "€49.56";
		document.getElementById('pr_cashew').value = "€56.35";
		document.getElementById('pr_pistachio').value = "€57.60";
		document.getElementById('pr_chilli').value = "€54.95";
		document.getElementById('pr_salted_pop_15').value = "€51.83";
		document.getElementById('pr_salted_pop_30').value = "€51.33";
		document.getElementById('pr_cheese_pop_30').value = "€55.14";
		document.getElementById('pr_cheeseonion_crisp_35').value = "€64.30";
		
		document.cookie = "region=#" + document.getElementById('select_region').value + "#;expires=" + expiry_date;
	}
		
}

function changeTab(strTab)
{	
	//document.buy.purchase_type.value = strTab;
	
	if (strTab == 'tab_salted')
	{
		//Show and hide correct DIV tags
		document.getElementById('tab_salted').style.display = 'inline';
		document.getElementById('tab_mixed').style.display = 'none';
		document.getElementById('tab_popcorn').style.display = 'none';
		document.getElementById('span_salted').style.color = '#132474';
		document.getElementById('span_mixed').style.color = '#A42117';
		document.getElementById('span_popcorn').style.color = '#A42117';
		
	}
		
	else if (strTab == 'tab_mixed')
	{
		document.getElementById('tab_salted').style.display = 'none';
		document.getElementById('tab_mixed').style.display = 'inline';
		document.getElementById('tab_popcorn').style.display = 'none';
		document.getElementById('span_salted').style.color = '#A42117';
		document.getElementById('span_mixed').style.color = '#132474';
		document.getElementById('span_popcorn').style.color = '#A42117';
	}
	
	else if (strTab == 'tab_popcorn')
	{
		document.getElementById('tab_salted').style.display = 'none';
		document.getElementById('tab_mixed').style.display = 'none';
		document.getElementById('tab_popcorn').style.display = 'inline';
		document.getElementById('span_salted').style.color = '#A42117';
		document.getElementById('span_mixed').style.color = '#A42117';
		document.getElementById('span_popcorn').style.color = '#132474';
	}			
}

//-->

