var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject() 
{
  var xmlHttp;
  try{
    xmlHttp = new XMLHttpRequest();
  }catch(e){
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++){
      try{ 
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      }catch (e) {}
    }
  }
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

 
function add_bonus_bottles(products_id)
{
  if (xmlHttp){
    try{
      var params = "products_id=" + products_id;
      xmlHttp.open("GET", "/service/add_bonus_bottles.php?" + params, true);
      xmlHttp.onreadystatechange = function(){
      	if (xmlHttp.readyState == 4){
		    if (xmlHttp.status == 200){
		      try{
		        handleServerResponse();
		      }catch(e){
		        alert("Error reading the response: " + e.toString());
		      }
		    }else{
		      alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		    }
		  }
      }
      xmlHttp.send(null);
    }catch (e){
      alert("Can't connect to server:\n" + e.toString());
    }
  }
}

function handleServerResponse(element_to_show)
{
  var myResponse = new String( xmlHttp.responseText );
//  supPays = document.getElementById(element_to_show);
//  supPays.innerHTML = myResponse;
	//alert(myResponse);
}


function add_to_shoppingcart(product_id, site_id, cart_id, form_submit_id)
{
  if (xmlHttp){
    try{
      var params = "product_id=" + product_id + "&site_id=" + site_id + "&cart_id=" + cart_id;
      xmlHttp.open("GET", "/service/add_to_shoppingcart.php?" + params, true);
      xmlHttp.onreadystatechange = function(){
      	if (xmlHttp.readyState == 4){
		    if (xmlHttp.status == 200){
		      try{
		        SubmitFrom(form_submit_id);
		      }catch(e){
		        alert("Error reading the response: " + e.toString());
		      }
		    }else{
		      alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		    }
		  }
      }
      xmlHttp.send(null);
    }catch (e){
      alert("Can't connect to server:\n" + e.toString());
    }
  }
}

function SubmitFrom(form_submit_id)
{
  var form_to_submit = document.getElementById(form_submit_id);
  
  form_to_submit.submit();

}