function getHTTPObject()
{
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
  		xmlhttp=new XMLHttpRequest()
	// code for IE
	else if (window.ActiveXObject)
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	return xmlhttp;
}

var http = getHTTPObject();

function AddProduct(mode, productid, qty, price, name, maxqty, contshp)
{
	if(document.getElementById('qty').value == ''){
		alert("Please enter qty.");
		document.getElementById('qty').focus();
		return false;
	}else if(document.getElementById('qty').value < 1){
		alert("please enter qty greater then zero.");
		document.getElementById('qty').focus();
		return false;
	}else
    	qty = document.getElementById('qty').value;
	if(qty == "" )
		qty = '1';
	if(price == "")
		price = '0.00';

	var url = site_url + "ajax_shoppingcart.php";
	url = url + "?productid="+ escape(productid)+"&qty="+ escape(qty)+"&price="+escape(price)+"&name="+escape(name)+"&mode="+escape(mode)+"&maxqty="+maxqty+"&contshp="+contshp;
	//alert(url);
  //window.location = url;
  http.open("GET", url, true);
	http.onreadystatechange = getCartDataAdd;
  http.send(null);
}
function getCartDataAdd()
{
	if (http.readyState == 4)
	{
   		var xmlDocument = http.responseXML;
    	var set_key  = xmlDocument.getElementsByTagName('set_key').item(0).firstChild.data;
		//alert(set_key);return false;
		window.location = site_url+"ShoppingCart/";
		return false;		
	}
}

function removeone(id, val)
{
	
  var qty = 'qty_'+ val;
	document.getElementById(qty).value = 0;
	document.frmcart.cartmode.value = "RemoveOne";
	document.frmcart.productid.value = id;
	document.frmcart.submit();
}

function removeall()
{
	document.frmcart.cartmode.value = "RemoveAll";
	document.frmcart.submit();
}

function continueshopping(url)
{
	window.location = url;
}

function updatecart()
{	
	for(i = 0 ; i < document.getElementById('total_item_cart').value ; i++)
	{
		qyt_entered = document.getElementById("qty_"+i).value;		
		get_qtyid = document.getElementById("get_qtyid_"+i).value;
		
		var set_qtyid = get_qtyid;
		
//		alert(qyt_entered+' >> '+qty_available+ '>>' + set_qtyid[0]);		
		
		document.getElementById("qty_"+i).value = qyt_entered;
		//document.getElementById("setredqty_"+i).className = 'input-red';		
	}
	document.frmcart.cartmode.value = "UpdateCart";
	document.frmcart.submit();
}

/*function updatecart()
{
	var url = ajax_url + "ajax_updatecart.php?totcnt="+document.getElementById('total_item_cart').value;
	for(i = 0 ; i < document.getElementById('total_item_cart').value ; i++)
	{
		qyt_entered = document.getElementById("qty_"+i).value;
		//qty_available = document.getElementById("qtyinstock_"+i).value;
		get_qtyid = document.getElementById("get_qtyid_"+i).value;
		
		var set_qtyid = get_qtyid;
		var js_getqty = qyt_entered+'-'+set_qtyid;
		
		url = url + "&gotqty_"+i+"="+ escape(js_getqty);
	}
	http.open("GET", url, true);
	
//	alert(url);return false;
	
	http.onreadystatechange = getAlertQty;
   	http.send(null);
}
function getAlertQty()
{
	if (http.readyState == 4)
	{
		var flag = '0';    	
		if(flag == '0')
		{
			document.frmcart.cartmode.value = "UpdateCart";
			document.frmcart.submit();
		}
		else
			return false;
	}
}*/

function gotocheckout()
{
	window.location = site_url + 'Billing-Shipping/';	
}
