function getHTTPObject()
{
  var xmlhttp;
 
  if(window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject){
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlhttp){
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
}
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
/*
	Funtion Name=requestInfo 
	Param = url >> Url to call : id = Passing div id for multiple use ~ as a seprator for eg. div1~div2 :
	redirectPage >> if you like to redirect to other page once the event success then 
	the response text = 1 and the redirectPage not left empty
*/

function IsChar(sText)
{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = "false";
			//alert ("please enter numeric only.");						
		}
	}
	return IsNumber;   
}//number validation

    function requestInfo(url,id,redirectPage) 
	{
		
		var temp=new Array();
			http.open("GET", url, true);
			http.onreadystatechange = function() {
				if (http.readyState == 4) {
				  if(http.status==200) {
			  		var results=http.responseText;
					if(redirectPage=="" || results!="1") {
						
						var temp=id.split("~"); // To display on multiple div 
						//alert(temp.length);
						var r=results.split("~"); // To display multiple data into the div 
						//alert(temp.length);
						if(temp.length>1) {
							for(i=0;i<temp.length;i++) {	
								//alert(temp[i]);
								document.getElementById(temp[i]).innerHTML=r[i];
							}
						} else {
							if(results == "No products")
							{
								location.href="efl-cart.php?prod=0";
							}
							else
							{
								document.getElementById(id).innerHTML = results;
							}
						}	
					} else {
						window.location.href=redirectPage;
					}
				  } 
  				}
				else
				{
			        document.getElementById(id).innerHTML="<table width=100%><tr><td align=center><img src='images/common/preloader.gif' width=16 height=16 alt='' border='0'> <b>Loading ...... Please wait !</b></td></tr></table>"
				}
			};
			http.send(null);
       }

function init_table(sesid,pmt_type)
{
	requestInfo('ajax/cart-details.php?mode=list&sesid='+sesid+'&pmt_type='+pmt_type,'showcart','');
}
	
    function update_data(sesid,pmt_type,prod_id) {
	//var prod_id=document.getElementById("prod_id").value;
	var prod_qty=document.getElementById("prod_qty").value;
	//===========For Special Characters=============
	var number=IsChar(prod_qty);
	if (number=="false")
	{
        var valid_qty = alert("Product quantity accepts numbers only.");
        return valid_qty; 
	}
   
	//-----------------------------------------------
	requestInfo('ajax/cart-details.php?mode=update_data&id='+prod_id+'&prod_qty='+prod_qty+'&pmt_type='+pmt_type+'&sesid='+sesid,'showcart','');
}

function confirmLink(theLink)
{
   
    var is_confirmed = confirm('Are you sure to remove this product from your cart?');
    if (is_confirmed) {
        theLink.href += '';
    }
    return is_confirmed;
}