
//Global XMLHTTP Request object
var XmlHttp_1;
var dest_dd;
var dest_field;
var rst;
var chk_itemid;
//Creating and setting the instance of appropriate XmlHttp_1 Request object to a “XmlHttp_1” variable  

function addtocart(itemid,qty,cause)
{
//alert("qty_val");
chk_itemid=itemid;
var qty_val=document.getElementById(itemid).value;

//alert(document.getElementByName("lbl_items"));
//lbl_visibility();
//document.getElementById("div_items").style.visibility="hidden";

//alert("hai");
var Url = "add_to_cart.aspx?dt="+Date()+"&itemid="+itemid+"&qty="+qty_val+"&cause="+cause;
CreateXmlHttp();
get_results(Url);
rst="addcart";
}
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	
	try
	{
		XmlHttp_1 = new ActiveXObject("Msxml2.XMLHTTP");
		//alert("hai");
	}
	catch(e)
	{
	
		try
		{
			XmlHttp_1 = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp_1 = null;
		}
		
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp_1 && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp_1 = new XMLHttpRequest();
		
	}
}

function get_results(url)
{
	CreateXmlHttp();
try{
	// If browser supports XMLHTTPRequest object
	if(XmlHttp_1)
	{
		//Setting the event handler for the response
		XmlHttp_1.onreadystatechange = HandleResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
	//	alert(url);
			
		XmlHttp_1.open("GET",url,true);
		
		//Sends the request to server
		XmlHttp_1.send(null);
				
	}
	}
	catch(e)
	{
	alert(e);
	}

}


//Called when response comes back from server
function HandleResponse()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp_1.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
	//	alert(XmlHttp_1.status);
		if(XmlHttp_1.status == 200)
		{			
			var getvalue=XmlHttp_1.responseText;
			if(rst=="combo")
			{
			splitVal=getvalue.split(" @@@ ");
			 //alert(getvalue);
			var combobox = document.getElementById(dest_dd);
			for (var count = combobox.options.length-1; count >-1; count--)
			{
				combobox.options[count] = null;
			}
			var j=1;
			combobox.options[0]= new Option("Select ",0000)
			for (var i = 0; i < splitVal.length-1; i++)
			{
   				combobox.options[j]= new Option(splitVal[i+1],splitVal[i])
   				i++;
   				j++;
			}
			}
			else if(rst=="stock")
			{
			//alert(getvalue);
			var field=document.getElementById(dest_field);
			field.value=getvalue;
			}
			else if(rst=="addcart")
			{
			
			splitVal=getvalue.split(" @@@ ");
		/*	for (var i = 0; i < splitVal.length-1; i++)
			{
   			splitVal[i+1],splitVal[i])
   			}
		*/
		
		//	field.value=getvalue;alert(getvalue);
			//document.getElemtnById("lbl_total_items").value=splitVal[0];
			//alert(splitVal[0]);
			parent.document.getElementById("div_items").innerHTML=splitVal[0];
			parent.document.getElementById("div_total_cost").innerHTML="Rs. "+splitVal[1];
			chk_itemid="span"+chk_itemid;
			alert("Item Added to Cart");
			
			//	document.getElementById(chk_itemid).innerHTML="Item Added to Cart";
			//alert(splitVal[1]);
		
			}
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}






