/*	##################################################################
	## 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, SKU, QTY, PRODUCTBAND){
		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?q=" + escape(SKU) + "&t=" + escape(DIVTAG) + "&c=" + escape(QTY) + "&pb=" + escape(PRODUCTBAND);
		var url = WEBSITEURL + url;
		PARENTDIVTAG = null
		PARENTDIVTAG = DIVTAG
		http.open("GET", url, true);
		http.onreadystatechange = viewquantity;
		http.send(null);
	}
	
	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 setquantity(DIVTAG, VALUE, SKU){
		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?q=" + escape(SKU) + "&t=" + escape(DIVTAG) + "&v=" + escape(VALUE);
		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|productoptions|theerror
		    RESULTS = http.responseText.split("|");
			THECODE = null;
			THEID = RESULTS[0];
			THEQUANTITY = RESULTS[1];
			THEPRICE = RESULTS[2];
			THETOTALNET = RESULTS[3];
			THETOTAL = RESULTS[4];
			THECODE = RESULTS[5];
			THEWEIGHT = RESULTS[6];
			THEVAT = RESULTS[7];
			THEERROR = RESULTS[8];
			
			QUANTITYDIV = "quantity_"+THEID
			PRICEDIV = "price_"+THEID
			ERRORDIV = "basketerror_"+THEID

			document.getElementById(QUANTITYDIV).innerHTML = THEQUANTITY;
			document.getElementById(PRICEDIV).innerHTML = "&pound;"+THEPRICE;
			document.getElementById("basket_total").innerHTML = "<b>&pound;"+THETOTALNET+"</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";
			}
		}
	}