// holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();

// creates an XMLHttpRequest instance
function createXmlHttpRequestObject() 
{
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // this should work for all browsers except IE6 and older
  try
  {
    // try to create XMLHttpRequest object
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    // try every prog id until one works
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        // try to create XMLHttpRequest object
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
    return xmlHttp;
}


 // read a file from the server
function addtocart(pid,kid)
{

  // only continue if xmlHttp isnt void
  if (xmlHttp)
  {
    // try to connect to the server
    try
    {
      // create the params string
      var params = "pid=" + pid + 
                   "&kid=" + kid;
      // initiate the asynchronous HTTP request
      xmlHttp.open("GET", ajax_url+"cart.php?" + params, true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.send(null);
    }
    // display the error in case of failure
    catch (e)
    {
    }
  }
}

function sclck(ii,ll,vt,tt) {

  // only continue if xmlHttp isnt void
  if (xmlHttp)
  {
    // try to connect to the server
    try
    {
      // create the params string
      var params = "i=" + ii + 
					"&l=" + ll +
					"&t=" + tt +
                   "&vt=" + vt;
      // initiate the asynchronous HTTP request
      xmlHttp.open("GET", ajax_url+"go1.php?" + params, true);
      xmlHttp.onreadystatechange = handleRequestStateChange2;
      xmlHttp.send(null);
    }
    // display the error in case of failure
    catch (e)
    {
    }
  }
}

function handleRequestStateChange() {
  if (xmlHttp.readyState == 4)   {
    if (xmlHttp.status == 200)   {
		  try 
		  { 
				handleServerResponse();
		  } 
		  catch (e) {}
    } 
  }
}

function handleRequestStateChange2() {
  if (xmlHttp.readyState == 4)   {
    if (xmlHttp.status == 200)   {
		  try 
		  { 
				handleServerResponse2();
		  } 
		  catch (e) {}
    } 
  }
}

// handles the response received from the server
function handleServerResponse()
{
  // retrieve the servers response packaged as an XML DOM object
  var response = xmlHttp.responseText;
  myDiv = document.getElementById("cart");
  myDiv.innerHTML = response;
}	

function handleServerResponse2()
{
	return true;
}	
