/*
**	TEKNIVISION.COM COPYRIGHTS 2007
*/
	function createRequestObject() 
	{
		var ro;
		var browser = navigator.appName;
		if (browser == "Microsoft Internet Explorer") {
			try {
				ro = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					ro = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {}
			}
		} else { //safari Mozilla
			ro = new XMLHttpRequest();
			if (ro.overrideMimeType)
				ro.overrideMimeType('text/xml');
		}
		if (!ro) {
			alert('Abandon :( Impossible de créer une instance XMLHTTP');
			return false;
		}
		else
			return ro;
   }
   
   var http = createRequestObject();
   checkAtStart();
   
   //show product when new page is loaded
   function checkAtStart()
   {
		http.open('GET', 'cart.php', true);
		http.onreadystatechange = handleResponse;
		http.send(null);
   }
  
/*
**
** pages 'boutique' and 'recettes'
**
*/
   function addProduct(product_id, price)
   {
		http.open('POST', 'cart.php', true);
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		http.onreadystatechange = handleResponse;
		var data = "product_id=" + product_id + "&price=" + price + "&add=" + 1;
		http.send(data);
   }
   
   function delProduct(product_id, price)
   {
		http.open('POST', 'cart.php', true);
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		http.onreadystatechange = handleResponse;
		var data = "product_id=" + product_id + "&price=" + price + "&del=" + 1;
		http.send(data);
   }
   
   function handleResponse() {
	if (http.readyState == 4) {
		if (http.status == 200) {
			if (document.getElementById('shoppingtext') != null) {
				//former method without xml
				//document.getElementById('shoppingtext').innerHTML = http.responseText;
				//new method xml
				var DaValue = "";
				var docXML= http.responseXML;
				var items = docXML.getElementsByTagName("davalue")
				for (i=0;i<items.length;i++)
					DaValue += (items.item(i).firstChild.data) + "<br />";
				document.getElementById('shoppingtext').innerHTML = DaValue;
			}
		}
		else
		{
			if (document.getElementById('shoppingtext') != null)
				document.getElementById('shoppingtext').innerHTML = http.status;
		}
	}
   }