
//AJAX update cart with qty
function updcart(sc, pid, qty, messarea) {
	if (document.getElementById("cartTime")) {
		document.getElementById("cartTime").innerHTML='<img src="images/wait.gif" width="10" height="10">&nbsp;Please wait';
	}
	var url="updcart.asp";
	var mypostrequest=new ajaxRequest();
	var pid = encodeURIComponent(pid);
	var qty = encodeURIComponent(qty);
	var sc = encodeURIComponent(sc);
	var parameters="pid="+pid+"&qty="+qty+"&sc="+sc;
	mypostrequest.onreadystatechange=function(){
	 if (mypostrequest.readyState==4){
		if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
			if (mypostrequest.responseText=='') {
				if (document.getElementById("coaddressblock")) {
					if (document.getElementById("thecart")) {
						document.getElementById("thecart").innerHTML=mypostrequest.responseText;
					}
					document.getElementById("coaddressblock").innerHTML="Your cart is empty, please wait while we return you to our home page. Thank you.";
					parent.location="index.asp";
					return;
				}
				if (document.getElementById('fade')) {
    			window.location.reload();
				}
			}
			
			if (mypostrequest.responseText.indexOf('exceeds the maximum weight') !== -1) {
				if (document.getElementById("paymentpanel")) {
					document.getElementById("paymentpanel").innerHTML="";
				}
			}
			if (mypostrequest.responseText.indexOf('exceeds the maximum weight') == -1) {
				if (document.getElementById("paymentpanel")) {
						document.getElementById("paymentpanel").innerHTML='<hr><table border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top:6px;"><tr><td align="center" style="font-size:10px;">Thank you for your order. If you are ready to check out please click the PayPal logo.<br>You do not need a PayPal account and can pay through PayPal with your credit card.</td><td width="20">&nbsp;</td><td align="center"><div  class="general" style="font-size:10px; font-weight:normal; margin-bottom:3px;">Pay now with PayPal</div><div id="submit_mess"><a href="javascript:saveCustForm();"><img src="images/cho_pp.jpg" width="100" height="40" border="0" class="paypal" title="Pay with your PayPal account or credit card"></a></div></td></tr></table>';
				}
			}
			
			if (document.getElementById("thecart")) {
				document.getElementById("thecart").innerHTML=mypostrequest.responseText;
			}
			if (document.getElementById("add2cartmessage"+messarea)) {
				document.getElementById("add2cartmessage"+messarea).innerHTML="<div style='color:#F00;'>You now have "+qty+" in your cart</div>";
			}
			if (document.getElementById("incart"+messarea)) {
				document.getElementById("incart"+messarea).innerHTML='<div onclick="showcartdiv(\'thecart\'); return false;" class="nav"><img src="images/cartfull.png" width="24" height="24" /></div>';
			}
			if (document.getElementById("buyqty"+messarea)) {
				document.getElementById("buyqty"+messarea).value = qty;
			}
			if (document.getElementById("buynowbut"+messarea)) {
				document.getElementById("buynowbut"+messarea).innerHTML="Change qty";
			}
			if (document.getElementById("cnavblank")) {
				if (document.getElementById("cnav").innerHTML == "Your cart is empty") {
					document.getElementById("cnavblank").innerHTML='<div id="cnav" onclick="showcartdiv(\'thecart\'); return false;" class="nav">Show cart</div>';
					showcartdiv('thecart');
				}
			}
		}
		else {
			alert("An error has occured while trying to update your cart")
		}
	 }
	}
	mypostrequest.open("post", url, true)
	mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	mypostrequest.send(parameters)
}


//update cart with coupon 

function updcartcoupons() {
	if (document.getElementById("cartTime")) {
		document.getElementById("cartTime").innerHTML='<img src="images/wait.gif" width="10" height="10">&nbsp;Please wait';
	}
	var url="updcart-coupon.asp";
	var couponUpdate=new ajaxRequest();
	var parameters="";
	couponUpdate.onreadystatechange=function(){
	 if (couponUpdate.readyState==4){
		if (couponUpdate.status==200 || window.location.href.indexOf("http")==-1){
			if (document.getElementById("thecart")) {
				document.getElementById("thecart").innerHTML=couponUpdate.responseText;
				if (couponUpdate.responseText !== '') {
					showcartdiv('thecart');
				}
			}
		}
		else {
			alert(couponUpdate.responseText+"An error has occured while trying to update your cart with the coupon discounts")
		}
	 }
	}
	couponUpdate.open("post", url, true)
	couponUpdate.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	couponUpdate.send(parameters)
}


// update shipping
function updship(sc, shipid) {
	if (document.getElementById("cartTime")) {
		document.getElementById("cartTime").innerHTML='<img src="images/wait.gif" width="10" height="10">&nbsp;Please wait';
	}
	var url="subcart.asp";
	
	if (sc=='c') {
		alert("Check passing parameters");
		url="co-cart.asp";
	}
	var mypostrequest=new ajaxRequest();
	var shipid = encodeURIComponent(shipid);
	var parameters="shipid="+shipid+"&qty="+qty+"&sc="+sc;
	mypostrequest.onreadystatechange=function(){
	 if (mypostrequest.readyState==4){
		if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
			if (document.getElementById("thecart")) {
				document.getElementById("thecart").innerHTML=mypostrequest.responseText;
			}
		}
		else {
			alert("An error has occured while trying to update the shipping for your cart")
		}
	 }
	}
	mypostrequest.open("post", url, true)
	mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	mypostrequest.send(parameters)
}


//AJAX Check country for correct shipping for sub cart
function checkCountrySC(sc) {
	if (document.getElementById("cartTime")) {
		document.getElementById("cartTime").innerHTML='<img src="images/wait.gif" width="10" height="10">&nbsp;Please wait';
	}
	if (sc == "s") {
	var url="subcart.asp";
	}
	if (sc == "c") {
	var url="co-cart.asp";
	}
	var mypostrequest=new ajaxRequest();
//	if (document.getElementById("totalweight")==null) {
//		parent.location="index.asp";
//		return;
//	}
	var country;
	var totalweight = document.getElementById("totalweight").value;
	if (document.getElementById("country")) {
		country = alltrim(document.getElementById("country").value);
	}
	if (document.getElementById("dcountry")) {
		country = alltrim(document.getElementById("dcountry").value);
		document.getElementById('dcountrycode').value=(getCountryName(document.getElementById('dcountry').value));
	}
	country = encodeURIComponent(country);
	totalweight = encodeURIComponent(totalweight);
	var parameters="country="+country+"&totalweight="+totalweight;
	mypostrequest.onreadystatechange=function(){
	 if (mypostrequest.readyState==4){
		if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
			if (mypostrequest.responseText.indexOf('exceeds the maximum weight') !== -1) {
				if (document.getElementById("paymentpanel")) {
					document.getElementById("paymentpanel").innerHTML="";
				}
			}
			if (mypostrequest.responseText.indexOf('exceeds the maximum weight') == -1) {
				if (document.getElementById("paymentpanel")) {
						document.getElementById("paymentpanel").innerHTML='<hr><table border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top:6px;"><tr><td align="center" style="font-size:10px;">Thank you for your order. If you are ready to check out please click the PayPal logo.<br>You do not need a PayPal account and can pay through PayPal with your credit card.</td><td width="20">&nbsp;</td><td align="center"><div  class="general" style="font-size:10px; font-weight:normal; margin-bottom:3px;">Pay now with PayPal</div><div id="submit_mess"><a href="javascript:saveCustForm();"><img src="images/cho_pp.jpg" width="100" height="40" border="0" class="paypal" title="Pay with your PayPal account or credit card"></a></div></td></tr></table>';
				}
			}
			if (document.getElementById("thecart")) {
				document.getElementById("thecart").innerHTML=mypostrequest.responseText;
			}
			if (document.getElementById("errmess")) {
				document.getElementById("errmess").innerHTML="Please check your order, your shipping charges may have changed to "+decodeURIComponent(country);
			}
		}
		else {
			alert("An error has occured while trying to update the shipping for your cart")
		}
	 }
	}
	mypostrequest.open("post", url, true)
	mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	mypostrequest.send(parameters)
}

function showTick(elm) {
	document.getElementById(elm).style.visibility = "visible";
}
function hideTick(elm) {
	document.getElementById(elm).style.visibility = "hidden";
}
// JavaScript Document
var xmlHttp;
var messarea;


function clearSlDiv() {
	if (document.getElementById("slinput")) {
		document.getElementById("slinput").innerHTML='<table border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top:6px;"><tr><td width="9"><img src="../../scripts/images/buy-l.jpg" width="9" height="21"></td><td><a href="javascript:addSlToCart();" class="buynow">Make this order a shopping list</a></td><td width="9"><img src="../../scripts/images/buy-r.jpg" width="9" height="21"></td></tr></table>';
	}
}

//AJAX sh list input
function addSlToCart() {
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

var url="add-sl-input.asp";
url=url+"?sid="+Math.random();
xmlHttp.onreadystatechange=upsldnow;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function upsldnow() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		if (document.getElementById("slinput")) {
			document.getElementById("slinput").innerHTML=xmlHttp.responseText;
		}
	}
}

function rowOut(eltochange)
{
	document.getElementById(eltochange).className="lmenucart";
	document.getElementById("cartmessage").innerHTML=" ";
}

function inFocus(eltochange)
{
	document.getElementById(eltochange).className="lmenucartover";
	document.getElementById("cartmessage").innerHTML="<span style='color:#f00;'>Change your order</span>";
}



function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}



