/* $Id: dynacart.js,v 1.0 2008/01/06 13:45:23 bjo Exp $ */
var xmlHttp

function dynacart_load()
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
 		return
 	}

	var url="http://www.tradlost.se/shop/dynacart.php?mode=load"
//	var url="http://server.tradlost.se/shop/dynacart.php?mode=load"

	xmlHttp.onreadystatechange = function()
  {
   	if(xmlHttp.readyState==4)
		{
 			document.getElementById('dynacart').innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function dynacart_add(theform)
{
	var postdata = 'mode=add';

	for (i=0; i<theform.elements.length; i++)
	{
		postdata = postdata + '&' + theform.elements[i].name + '=' + theform.elements[i].value;
	}

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
 		return
 	}

	var url="http://www.tradlost.se/shop/dynacart.php"
//	var url="http://server.tradlost.se/shop/dynacart.php"

	xmlHttp.onreadystatechange = function()
  {
   	if(xmlHttp.readyState==4)
		{
			var splitobj = xmlHttp.responseText;

			var z = splitobj.split("|");
 			document.getElementById('dynacart_total_cost').innerHTML = z[0];
 			document.getElementById('dynacart_items').innerHTML = z[1];
 			document.getElementById('dynacart_incart').innerHTML = z[2];
 			document.getElementById('dynacart_total_label').innerHTML = z[3];
//			document.getElementById('dynacart_total_label').innerHTML = splitobj;

			if(z[1] >=1)
			{
				document.getElementById('dynacart_link').href = 'cart.php';
				splitobj = document.getElementById('dynacart_image').src;
				splitobj = splitobj.replace('empty','full');
				document.getElementById('dynacart_image').src = splitobj;
			}
		}
	}
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttp.send(postdata);
}


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;
}

