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 stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("productdetails_id").innerHTML=xmlHttp.responseText;
	}
}


function productdetails(product_id)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="product_details.php";
	url=url+"?product_id="+product_id;
	
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function add_product(product_id,cnt)	//product_id
{	
	//alert "I m in Add Prof";
	xmlHttp=GetXmlHttpObject()
	obj=GetXmlHttpObject()
	basket=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	if (obj==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	if (basket==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	var qtyname = "qty"+cnt;
	var qtyval   = document.getElementById(qtyname).value;
	
	
	var url="add_product.php";
	url=url+"?product_id="+product_id+"&qty="+qtyval;
	
	
	var url2="add_product2.php";
	url2=url2+"?product_id="+product_id+"&qty="+qtyval;
	
	var url_basket="basket.php";
	url_basket=url_basket+"?product_id="+product_id+"&qty="+qtyval;
	
	
	xmlHttp.onreadystatechange=function()
	{
	if (xmlHttp.readyState==4)
		{ 
			divid = "addprod"+cnt;
			
			document.getElementById(divid).innerHTML=xmlHttp.responseText;
			//document.getElementById("mytot").innerHTML=xmlHttp.responseText;
		}
	}
	//xmlHttp.onreadystatechange=add_product_statechanged(cnt)
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	obj.onreadystatechange=function()
	{
	if (obj.readyState==4)
		{ 
			//divid2 = "addprod"+cnt;
			
			//document.getElementById(divid).innerHTML=xmlHttp.responseText;
			document.getElementById("mytot").innerHTML=obj.responseText;
		}
	}
	obj.open("GET",url2,true);
	obj.send(null);
	
	
	basket.onreadystatechange=function()
	{
	if (basket.readyState==4)
		{ 
			//divid2 = "addprod"+cnt;
			
			//document.getElementById(divid).innerHTML=xmlHttp.responseText;
			document.getElementById("basket_img").innerHTML=basket.responseText;
		}
	}
	basket.open("GET",url_basket,true);
	basket.send(null);
}
/*function add_product_statechanged(cnt_d) 
{ 
	alert
	alert cnt_d;
	if (xmlHttp.readyState==4)
	{ 
	divid = "addprod"+cnt_d;
	document.getElementById(divid).innerHTML=xmlHttp.responseText;
	}
}
*/


function total(product_id)
{
	xmlHttp=GetXmlHttpObject()
	var url="total_ajax.php";
	url=url+"?product_id="+product_id;
	
	xmlHttp.onreadystatechange=totalcount
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function totalcount(product_id) 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("total").innerHTML=xmlHttp.responseText;
	}
}
