var cart_itemId = '';
var cart_itemData = '';
var cart_itemPath = '';
function gid(id) {
	return document.getElementById(id);
};
function show(id) {
	document.getElementById(id).style.display = 'block';
};
function hide(id) {
	document.getElementById(id).style.display = 'none';
};
function updateEmailAddr() {
	gid('ma1').href = "ma" + ("il" + "to: sales") + "@m" + ("ike-patrick" + ".") + "com?subject=[International Order]";
};
function cart_showItem(itemId, cap) {
	cart_itemId = itemId;
	if (cap == undefined) {
		cap = "Add Item to Cart";
	};
	updateEmailAddr();

	gid('ciTitle').innerHTML = cap;
	show('dh');
	gid('cartItem').style.top = "389px";
	gid('ci_contents').style.height = "144px";
	hide('ci_btnsBilling');
	hide('ci_billingItem');
	hide('frmCart');
	hide('bi_rightCol');
	show('cartItem');
	show('ci_btnsItem');
	show('ci_contentsItem');
	show('ci_scheme');
	show('ci_desclbl');
	show('ci_desc');
	show('ci_vd');
};
function cart_showPayPalLoading() {
	show('dh');
	show('paypalloading');
};
function cart_showOrderForm() {
	window.location = "orderform.php";
};
function cart_close() {
	gid('cartItem').style.display = 'none';
	gid('dh').style.display = 'none';
};
function cart_empty() {
	gid('action').value = 'empty';
	gid('checkout').value = '0';
	gid('itemId').value = cart_itemId;
	gid('itemData').value = cart_itemData;
	gid('itemPath').value = cart_itemPath;
	gid('qty').value = '';
	document.forms['frmCart'].submit();
};
function cart_removeItem(itemId) {
	if (itemId == undefined) {
		itemId = cart_itemId;
	};
	gid('action').value = 'removeItem';
	gid('checkout').value = '0';
	gid('itemId').value = itemId;
	gid('itemData').value = cart_itemData;
	gid('itemPath').value = cart_itemPath;
	gid('qty').value = '';
	document.forms['frmCart'].submit();
};
function cart_getQtyArray() {
	var sch = gid('ci_scheme');
	var rows = sch.getElementsByTagName('tr');
	var qty = new Array();
	for(var i=0;i<rows.length;i++) {
		cols = rows[i].getElementsByTagName('td');
		var inpqty = cols[3].getElementsByTagName('input')[0];
		var	iQty = parseInt(inpqty.value);
		if (isNaN(iQty)) {
			iQty = 0;
			inpqty.value = "0";
		};
		qty.push(inpqty.name);
		qty.push(iQty);
	};
	return (qty.join("|"));
};
function cart_checkOut(stage) {
	var f = document.forms['frmCart'];
	var valid = true;
	var errMsg = "";
	if (stage == 2) {
		if (valid && (f.bi_name.value == "")) { valid = false; errMsg = "The name was not specified."; };
		if (valid && (f.bi_surname.value == "")) { valid = false; errMsg = "The surname was not specified."; };
		if (valid && (f.bi_addr1.value == "")) { valid = false; errMsg = "The address was not specified."; };
		if (valid && (f.bi_city.value == "")) { valid = false; errMsg = "The city was not specified."; };
		if (valid && (f.bi_country.value == "")) { valid = false; errMsg = "The country was not specified."; };
		if (valid && (f.bi_postcode.value == "")) { valid = false; errMsg = "The post code was not specified."; };
		if (valid && (f.bi_email.value == "")) { valid = false; errMsg = "The e-mail address was not specified."; };
	};
	if (valid) {
		gid('action').value = 'saveItem';
		gid('checkout').value = stage;
		gid('itemId').value = cart_itemId;
		gid('itemData').value = cart_itemData;
		gid('itemPath').value = cart_itemPath;
		gid('qty').value = cart_getQtyArray();
		document.forms['frmCart'].submit();
	} else {
		alert(errMsg);
	};
};
function cart_saveItem() {
	gid('action').value = 'saveItem';
	gid('checkout').value = '0';
	gid('itemId').value = cart_itemId;
	gid('itemData').value = cart_itemData;
	gid('itemPath').value = cart_itemPath;
	gid('qty').value = cart_getQtyArray();
	document.forms['frmCart'].submit();
};
function cart_addItem(t, p) {
	var a = t.split("|");
	cart_itemId = a[0];
	cart_itemData = t;
	cart_itemPath = p;
	gid('action').value = 'addItem';
	gid('checkout').value = '0';
	gid('itemId').value = cart_itemId;
	gid('itemData').value = cart_itemData;
	gid('itemPath').value = cart_itemPath;
	gid('qty').value = '';
	document.forms['frmCart'].submit();
};
function cart_nosel() {
	alert("To use this function you must first select a photo from the list on the right.");
};
function cart_updateTotal() {
	var sch = gid('ci_scheme');
	var rows = sch.getElementsByTagName('tr');
	var dTotal = 0;
	for(var i=0;i<rows.length;i++) {
		cols = rows[i].getElementsByTagName('td');
		var dUnitPrice = parseFloat(cols[1].getElementsByTagName('label')[0].innerHTML);
		var inpqty = cols[3].getElementsByTagName('input')[0];
		var	iQty = parseInt(inpqty.value);
		if (isNaN(iQty)) {
			iQty = 0;
			inpqty.value = "0";
		};
		var dRowTotal = dUnitPrice * iQty;
		dTotal+=dRowTotal;
		cols[5].getElementsByTagName('label')[0].innerHTML = dRowTotal.toFixed(2);
	};
	gid('ci_ctot').getElementsByTagName('label')[0].innerHTML = dTotal.toFixed(2);
	//gid('chktot').innerHTML = dTotal.toFixed(2);
};
function showTerms() {
	cart_close();
	content.location.href = "terms.html";
};
function scrollToBottom() {
  window.scrollBy(0, 1000); 
};

