var xmlHttp;

var rowid;
var rowida;


function removeitem(sku, rowid)
{
	progressid = "progress_"+ rowid;
	document.getElementById(progressid).style.display ="inline";
	
	
	rowid = "cartrow" + rowid;
	rowida = "cartrow" + rowid + "a";
	

	var url = "/ajax/removeitem.asp?sku=" + sku


	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		window.location = "/updatecart.asp?sku="+ sku;
	} 

	xmlHttp.onreadystatechange=function(){
     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
	
			myrow = document.getElementById(rowid);

			//remove the row from display			
			while (myrow.firstChild) {
				myrow.removeChild(myrow.firstChild);
			}


			//update totals... and limit table disaply
			if (xmlHttp.responseText == "0")
			{
				myrow = document.getElementById('cart');
				while (myrow.firstChild) {
					myrow.removeChild(myrow.firstChild);
				}

				 var div = document.createElement('div');
				 div.classname = "noitems";
				 div.innerHTML = "0 items in your cart.&nbsp;&nbsp;&nbsp;<a href='/'>Continue Shopping</a>";
				 document.getElementById("mainbody").appendChild(div);
    			
			}
			else
			{
				document.getElementById("carttotal").innerHTML=xmlHttp.responseText;
			}

			document.getElementById(progressid).style.display ="none";
        }
     };
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 




function updateqty(itemlist)
{
	document.getElementById("progressqty").style.display ="inline";
	
	
	rowid = "cartrow" + rowid;
	rowida = "cartrow" + rowid + "a";
	

	var url = "/ajax/updateqty.asp?itemlist=" + itemlist


	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		return;
	} 

	xmlHttp.onreadystatechange=function(){
     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
	
			document.getElementById("testdiv").innerHTML=xmlHttp.responseText;

			document.getElementById("progressqty").style.display ="none";
        }
     };
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 



function GetXmlHttpObject()
{
	//alert("getting obj");

	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 dofade() {
	document.getElementById("rcartlihead").style.display ="none";
}

function chkCartform(cartnum) {
	needOption = 0;
	num = 1;
	for (i=0;i<cartnum;i++)
	{
		if (document.getElementById("option" + num)) {
			needOption = 1;
		}
		num = num + 1;
	}
	if (needOption == 1) {
		alert("Please choose options and update cart before checking out.");
		return false;
	} else {
		window.location.href="/Checkout-billing.asp"
	}
}