/* %~%@ < 2.001 > @%~% */
/* %~%# < 06/10/2008 > #%~% */
/* %~%! < cart > !%~% */

//Remove cookie incase it exists
//DeleteCookie ("subtotal");
//SetCookie ("cart", null,null,"/");
	
if (GetCookie("cart") == null){
	DeleteCookie ("cart");
	SetCookie ("cart", null,null,"/");
}
if (GetCookie("cart") == ""){
	DeleteCookie ("cart");
	SetCookie ("cart", null,null,"/");
}
if (GetCookie("cart") == "null"){
	DeleteCookie ("cart");
	//SetCookie ("cart", "##CART##",null,"/");
	SetCookie ("cart", null,null,"/");
}

if (GetCookie("subtotal") == null){
	SetCookie ("subtotal", "0.00",null,"/");
}
if (GetCookie("subtotal") == ""){
	SetCookie ("subtotal", "0.00",null,"/");
}
if (GetCookie("subtotal") == "null"){
	SetCookie ("subtotal", "0.00",null,"/");
}
	
function toggle_layer (obj) {
	var lay = document.getElementById(obj);
	var dis = lay.style.display;

	//lay.style.display = (dis=='none')?'block':'none';
	lay.style.display = 'block';
}

function ShowCookie() {
	window.defaultStatus="Current Product Subtotal: $"+formatcurrency(parseFloat("0"+GetCookie("subtotal")));
	var sho="Cart is Empty"
	
	if (parseFloat("0"+GetCookie("subtotal")) > 0)
		{
			sho = "$"+formatcurrency(parseFloat("0"+GetCookie("subtotal")));
			sho = sho + ' <b><a href="/basket.asp" class="checkout">CHECKOUT</a></b> ';
		}
	
	//sho = "<span id='CheckoutSpan'>" + sho + "</span>";
	if (document.getElementById) {
		if (document.getElementById("divCart")) {
			document.getElementById("divCart").contents = sho;
			document.getElementById("divCart").innerHTML = sho;
		}
	 }
	if (document.all) {
		if (document.all["divCart"]) {
			document.all["divCart"].contents = sho;
			document.all["divCart"].innerHTML = sho;
		}
	 }
	if (document.layers) { 
		if (document.layers["divCart"]) { 
			var d = document.layers["divCart"]; 
			d.document.open();
			d.document.writeln(sho);
			d.document.close();
		}
	}

	if (document.getElementById) {
		if (document.getElementById("divMasterCart")) {
			document.getElementById("divMasterCart").style.visibility = "visible";
			document.getElementById("divMasterCart").visibility = "visible";
			document.getElementById("divMasterCart").style.display = 'block';
		}
	 }
	if (document.all) {
		if (document.all["divMasterCart"]) {
			document.all["divMasterCart"].style.visibility = "visible";
			document.all["divMasterCart"].visibility = "visible";
			document.all["divMasterCart"].style.display = 'block';
		}
	 }
	if (document.layers) { 
		if (document.layers["divMasterCart"]) { 
			var d = document.layers["divMasterCart"]; 
			d.document.open();
			d.document.writeln("$" + formatcurrency (myPrice));
			d.document.close();
			d.document.style.visibility = "visible";
			d.document.style.display = 'block';
		}
	}
}

function BuyProduct(Item,myPrice) {
	var OldCookie;
	var CartSum = 0;
	var Price=myPrice;
	var PriceShift=0;
	var Size="";
	var Quantity=1;

	if (arguments.length>2) {
			Size=arguments[2];
			var myValue="";
			// Handle single & multiple options by detecting if element 0 has a length
			// If there is no element 0 then there is only one option listed
			try {
				if (Size[0].length){
					// Multiple Options
					for (var h = 0; h < Size.length; h++){
						var opt=Size[h].value
						myValue += opt;
						var parms = opt.split("`")
						PriceShift += parseFloat(parms[1]);
						if ( h < Size.length-1) {
							myValue += ",";
						}
					}
				} else {
					//Single Option
					var opt=Size.value
					myValue = opt;
					var parms = opt.split("`")
					PriceShift = parseFloat(parms[1]);
				}
			}
			catch(er)
			{
				//alert(er);
			}
			
			Size=myValue;
			Price += PriceShift;
	}

	// Quantity addition
	if (arguments.length>3) {
		Qty11=arguments[3];
		Quantity=Qty11.value
	}

	//alert (Item);
	OldCookie=GetCookie("cart");
	if (parseFloat("0"+GetCookie("subtotal")) != 0){
		SetCookie ("cart", OldCookie+"|"+Item+"~"+Price+"~"+Size+"~"+Quantity,null,"/");
		SetCookie ("cart", OldCookie+"|"+Item+"~"+Price+"~"+Size+"~"+Quantity,null,"/_cart/_checkcookie.asp");
	} else {
		SetCookie ("cart", Item+"~"+Price+"~"+Size+"~"+Quantity,null,"/");
	}
	
	OldCookie=GetCookie("subtotal");
	if (OldCookie != "null"){
		CartSum = parseFloat("0" + OldCookie)
		CartSum = CartSum + parseFloat(Price * Quantity)
	} else {
		CartSum=parseFloat(Price * Quantity)
	}

	SetCookie ("subtotal","" + formatcurrency (CartSum),null,"/");

	ShowCookie();
}

function CheckVisible() {
	if (parseFloat("0"+GetCookie("subtotal")) > 0)
		{
			ShowCookie();
		}
}

function tweekprice(pricediv,cbo,baseprice) {
	var sho;
	if (document.getElementById) {
			sho = document.getElementById(pricediv).contents;
			sho = document.getElementById(pricediv).innerHTML;
	 }
	if (document.all) {
			sho = document.all[pricediv].contents;
			sho = document.all[pricediv].innerHTML;
	 }
	var myValue="";
	var mySum=parseFloat(baseprice);
	// Handle single & multiple options by detecting if element 0 has a length
	// If there is no element 0 then there is only one option listed
	try {
		if (cbo[0].length){
			//alert("has length");
			for (var h = 0; h < cbo.length; h++){
				mySum += parseFloat(GetRightString(cbo[h].value,'`'));
			}
		} else {
			//alert("has no length");
			mySum += parseFloat(GetRightString(cbo.value,'`'));
		}
	}
	catch(er)
	{
		//alert(er);
	}
	
	sho = "$"+formatcurrency(parseFloat(mySum));	
	if (document.getElementById) {
			document.getElementById(pricediv).contents = sho;
			document.getElementById(pricediv).innerHTML = sho;
	 }
	if (document.all) {
			document.all[pricediv].contents = sho;
			document.all[pricediv].innerHTML = sho;
	 }
}

function GetRightString(fullString, subString) {
   if (fullString.indexOf(subString) == -1) {
      return "0";
   } else {
      return (fullString.substring(fullString.indexOf(subString)+subString.length, fullString.length));
   }
}

function handleError() {
     return true;
}

//window.onerror = handleError;

function noenter() {
	return true;
}
