/*	##################################################################
	## Basket AJAX script v1.0 Copyright (c) 2006 Paramiliar.com	##
	## This copyright notice MUST stay intact and unchanged for use	##
	##################################################################
	## Designed by Matthew Bagley									##
	## Paramiliar Design Studios									##
	## http://www.paramiliar.com									##
	##################################################################
	## This code is NOT open source software and limitations apply 	##
	## Licence information can be found at							##
	##		http://www.paramiliar.com/license.php					##
	##################################################################*/
	
	// Begin XML Object loader
	function getHTTPObject() {
	  var xmlhttp;
	  /*@cc_on
	  @if (@_jscript_version >= 5)
		try {
		  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		  try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (E) {
			xmlhttp = false;
		  }
		}
	  @else
	  xmlhttp = false;
	  @end @*/
	  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
		  xmlhttp = new XMLHttpRequest();
		} catch (e) {
		  xmlhttp = false;
		}
	  }
	  return xmlhttp;
	}
	var http = getHTTPObject(); // We create the HTTP Object	
	// End XML Object Loader
	
	var url = "urlhereisvoid"; // The server-side script
	
	function edit_quantity(DIVTAG, KEY, SKU, QTY, OPTIONID){
		THECODE = "<img src=\"images/basket_loader_green.gif\" alt=\"Please Wait Loading Data\" width=\"67\" height=\"24\" />";
		document.getElementById(DIVTAG).innerHTML = THECODE;
		
		// grab the data from the server and change the screen
		var url = "";
		var url = "AJAX/basket_quantity_change.php?key=" + escape(KEY) + "&sku=" + escape(SKU) + "&divtag=" + escape(DIVTAG) + "&qty=" + escape(QTY) + "&optionid=" + escape(OPTIONID);
		var url = WEBSITEURL + url;
		PARENTDIVTAG = null
		PARENTDIVTAG = DIVTAG
		http.open("GET", url, true);
		http.onreadystatechange = viewquantity;
		http.send(null);
	}
	function setquantity(DIVTAG, VALUE, SKU, KEY, OPTIONID){
		THECODE = "<img src=\"/images/basket_loader_green.gif\" alt=\"Please Wait Loading Data\" width=\"67\" height=\"24\" />";
		document.getElementById(DIVTAG).innerHTML = THECODE;
		
		// grab the data from the server and change the screen
		var url = WEBSITEURL + "AJAX/basket_quantity_set.php?sku=" + escape(SKU) + "&divtag=" + escape(DIVTAG) + "&value=" + escape(VALUE) + "&key=" + escape(KEY) + "&optionid=" + escape(OPTIONID);
		PARENTDIVTAG = null
		PARENTDIVTAG = DIVTAG;
		http.open("GET", url, true);
		http.onreadystatechange = updatequantity;
		http.send(null);
	}
	function updatequantity() {
		if (http.readyState == 4) {
			// format of stream is : theid|thequantity|theprice|thetotal|THEDELIVERYTOTAL|productoptions|theerror

			RESULTS = http.responseText.split("|");
			THECODE = null;
			THEID = RESULTS[0];
			THEQUANTITY = RESULTS[1];
			THEPRICE = RESULTS[2];
			THETOTALNET = RESULTS[3];
			THEDELIVERYTOTAL = RESULTS[4];
			THECODE = RESULTS[5];
			THEWEIGHT = RESULTS[6];
			THEVAT = RESULTS[7];
			THEERROR = RESULTS[8];
			
			QUANTITYDIV = "quantity_"+THEID
			PRICEDIV = "price_"+THEID
			ERRORDIV = "basketerror_"+THEID
			DELIVERYDIV = "delivery_total";
			
			document.getElementById(QUANTITYDIV).innerHTML = THEQUANTITY;
			document.getElementById(PRICEDIV).innerHTML = "&pound;"+THEPRICE;
			document.getElementById("basket_total").innerHTML = "<b>&pound;"+THETOTALNET+"</b>";
			document.getElementById("delivery_total").innerHTML = "<b>&pound;"+THEDELIVERYTOTAL+"</b>";
			document.getElementById("basket_qtychanger_"+THEID).innerHTML = THECODE;
			//document.getElementById("basket_vat").innerHTML = "<b>&pound;"+THEVAT+"</b>";
			//document.getElementById("basket_grandtotal").innerHTML = "<b>&pound;"+THETOTAL+"</b>";
			//document.getElementById("basket_weight").innerHTML = "<b>"+THEWEIGHT+"g</b>";
			
			if (THEERROR.length > 0){
				document.getElementById(ERRORDIV).innerHTML = THEERROR;
				document.getElementById(ERRORDIV).style.display = "block";
			}
		}
	}
	
	
	function remove_product(ID, SKU) {
		THECODE = "<img src=\"images/basket_loader_green.gif\" alt=\"Please Wait Loading Data\" width=\"67\" height=\"24\" />";
		var QUANTITYID = "quantity_"+ID;
		document.getElementById(QUANTITYID).innerHTML = THECODE;
		
		// grab the data from the server and change the screen
		var url = WEBSITEURL + "AJAX/basket_remove_product.php?q=" + escape(SKU) + "&i=" + escape(ID);
		http.open("GET", url, true);
		http.onreadystatechange = deleteproduct;
		http.send(null);
	}
	
	function deleteproduct(){
		if (http.readyState == 4) {
			document.getElementById("basket_contents").innerHTML = http.responseText;
		}
	}
		
	function viewquantity() {
		if (http.readyState == 4) {
		  	THECODE = http.responseText;
		  	document.getElementById(PARENTDIVTAG).innerHTML = THECODE;
	  	}
	}
	
	
	
	function clearbasket(){
		var conf = confirm('Are you sure you wish to remove all the products from your basket?  This can not be undone.');
		if (conf){
			document.getElementById('clearbasketid').submit();
		}
	}
	