
//show direct debit option
function directDebit(status){
	if (status == 2){
	document.getElementById("Submit1").style.visibility= "hidden";
	document.getElementById("paydata").style.display = "inline";
	} else {
	document.getElementById("Submit1").style.visibility= "visible";
	document.getElementById("paydata").style.display = "none";
	}
}

//show direct debit option
function checkField(){
	if ((document.getElementById("email").value != "") && (document.getElementById("first_name").value != "") && (document.getElementById("phone").value != "") && (document.getElementById("delivery_address").value != "")){
	document.getElementById("ddebit").submit();
	} else {
	alert("Please ensure that you complete the First Name, Email Address, Phone Number and Delivery Address fields.");
	}
}


var xmlHttp
var displaycart

function addToCart(itemid,showcart,itemdel,itemqty)
{ 

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 if (showcart == "x"){
	 displaycart = showCartTotals;
 } else {
 	 displaycart = showCart;
 }
var qfield = "qty"+itemqty
var url="includes/utilities_cart.php"
url=url+"?itemid="+itemid
url=url+"&showcart="+showcart
url=url+"&delete="+itemdel
if (itemqty != "x"){
url=url+"&qty="+document.getElementById(qfield).value
} else {
url=url+"x"
}
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=displaycart
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function showCartTotals() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
 	document.getElementById("cart").innerHTML=xmlHttp.responseText;
}
}

function showCart() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
 	document.getElementById("showcart").innerHTML=xmlHttp.responseText;
	cartAdjust("x", "x");
}
}


//adjust cart values etc here
var totalsid
var updateqty
function cartAdjust(prodid,divid)
{ 

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }

totalsid = "totals"+divid;
updateqty = "qty"+divid;
var url="includes/utilities_cart.php"
url=url+"?prodid="+prodid
if (divid != "x"){
url=url+"&newtot="+document.getElementById(updateqty).value
} else {
url=url+"&newtot=x"
}
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=adjustcart
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

var newtotals;
var agtotals;
var righttotals;
function adjustcart() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
 	//document.getElementById(totalsid).innerHTML=xmlHttp.responseText;
	eval(xmlHttp.responseText);
		if (totalsid != "totalsx"){
		document.getElementById(totalsid).innerHTML = newtotals;
		}
	document.getElementById("carttext").innerHTML = agtotals;
	document.getElementById("cart").innerHTML= righttotals;
}
}

 
 
 function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}


