var alertTimerId = 0;

function resizeDivHeight(divid, height) 
{
   document.getElementById(divid).style.height = height;
}

function GetXmlHttpObject() 
{
   var xmlHttp=null;
   try {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
   } catch (e) {
      //Internet Explorer
      try {
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   return xmlHttp;
}

function addToCartAjax(x_prodcode, x_quantity)
{	 
   var xmlHttp = GetXmlHttpObject();
   document.getElementById('cartItemsDiv').innerHTML = "<img src='images/loading.gif' />";
   xmlHttp.onreadystatechange=function()
   {
      if(xmlHttp.readyState==4) {
	      document.getElementById('cartItemsDiv').innerHTML=xmlHttp.responseText;
         document.getElementById('itemCountDiv').innerHTML = "Items : " + document.getElementById('itemCount').value;
         document.getElementById('cartItemsDiv').style.height = '100px';
         resizeDivHeight('cartItemsDiv','100px');
         alertTimerId = setTimeout("resizeDivHeight('cartItemsDiv','0px')",500);
      }
   }
   xmlHttp.open("GET","scripts/content/ajax/addToCart.php?prodcode="+x_prodcode+"&quantity="+x_quantity,true);
   xmlHttp.send(null); 
}

function deleteFromCartAjax(x_prodcode)
{	 
   var xmlHttp = GetXmlHttpObject();
   document.getElementById('cartItemsDiv').innerHTML = "<img src='images/loading.gif' />";
   xmlHttp.onreadystatechange=function()
   {
      if(xmlHttp.readyState==4) {
	      document.getElementById('cartItemsDiv').innerHTML=xmlHttp.responseText;
         document.getElementById('itemCountDiv').innerHTML = "Items : " + document.getElementById('itemCount').value;
         resizeDivHeight('cartItemsDiv','100px');
         alertTimerId = setTimeout("resizeDivHeight('cartItemsDiv','0px')",1000);
      }
   }
   xmlHttp.open("GET","scripts/content/ajax/deleteFromCart.php?prodcode="+x_prodcode,true);
   xmlHttp.send(null); 
}

function clearCartAjax(x_prodcode)
{	 
   var xmlHttp = GetXmlHttpObject();
   document.getElementById('cartItemsDiv').innerHTML = "<img src='images/loading.gif' />";
   xmlHttp.onreadystatechange=function()
   {
      if(xmlHttp.readyState==4) {
	      document.getElementById('cartItemsDiv').innerHTML=xmlHttp.responseText;
         document.getElementById('itemCountDiv').innerHTML = "Items : " + document.getElementById('itemCount').value;         
      }
   }
   xmlHttp.open("GET","scripts/content/ajax/clearCart.php",true);
   xmlHttp.send(null); 
}

function shipOptionSelect(option, cost)
{	 
   document.getElementById('shipOption').value = option;
   document.getElementById('shipCost').value = cost;
}

function confirmSubmitShipOption()
{
   if (document.getElementById('shipOption').value != "0") {
      return true ;
   } else {
      //return false ;
      return true;
   }
}
