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)
{
  

  //  alert(price);return false;
  if(document.getElementById('otherqty'))
 	    qty = document.getElementById('otherqty').value;
	
	 if(qty == '')
	    qty = '1';
	
	 //get url of ajax file
	 var url = ajax_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);//return false;
	 
	 http.open("GET", url, true);
	
	 http.onreadystatechange = getCartDataAdd;
   http.send(null);
}

function getCartDataAdd()
{
	if (http.readyState == 4)
	{
   		var xmlDocument = http.responseXML;
      
        //alert(http.responseText);//return false;

		  var set_key  = xmlDocument.getElementsByTagName('set_key').item(0).firstChild.data;
		  //  alert(set_key);return false;

		  if(set_key == 'yes')
			   TB_show("Reduce Quantity","#TB_inline?height=90&width=450&inlineId=reduceqty_message","");
		  else
			   TB_show("Add to Cart","#TB_inline?height=90&width=450&inlineId=cart_message","");
		
		  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 continue_shopping(url)
{
    window.location = url;
  	return false;
}

function view_cart()
{
	window.location = site_url + 'ShoppingCart/';
	return false;
}
function continueshopping(url)
{
	window.location = url;
}
function removeall()
{
	document.frmcart.cartmode.value = "RemoveAll";
	document.frmcart.submit();
}

function updatecart()
{
  if(document.getElementById('sesstype').value == 'Retail')
  {
  	var flag = 0;
  
  	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;
  		  
  		if(parseInt(qyt_entered) > parseInt(qty_available))
  		{
        document.getElementById("qty_"+i).value = document.getElementById("qtyinstock_"+i).value;
        if(flag == '0')
  			{
  			   document.getElementById("qty_"+i).className = 'input-red';
           TB_show("Reduce Quantity","#TB_inline?height=90&width=450&inlineId=reduceqty_message","");
           return false;
           //updatecart();
        }
  			flag++;
  		}
  	}
	}
	document.frmcart.cartmode.value = "UpdateCart";
	document.frmcart.submit();
}

function qty_reduced()
{
	var flag = 0;
	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;
		
		if(parseInt(qyt_entered) > parseInt(qty_available))
		{
			document.getElementById("qty_"+i).value = document.getElementById("qtyinstock_"+i).value;
			flag++;
		}
	}
	document.frmcart.cartmode.value = "UpdateCart";
	document.frmcart.submit();
}

function gotocheckout()
{
  //  alert(document.getElementById('gettotcc').value);
  /*if(document.getElementById('gettotcc').value > 0)
  {
      var flag = 0;
    	for(i = 0 ; i < document.getElementById('total_item_cart').value ; i++)
    	{   
    		  var seltype = 'cattypeid_'+i;
    		  var selid = 'getidonly_'+i;
    		  var applystyle = 'appstyle_'+document.getElementById(selid).value;
    		  if(document.getElementById(seltype).value == '2')
    		      document.getElementById(applystyle).className = 'input-red';
          else
            document.getElementById(applystyle).className = '';
    	}
      return false;
  }*/
	window.location = site_url + 'Review/';
	return false;
}

function removeone_gc(id, val)
{
	var gcamount = 'gcamount_'+ val;
	
	document.getElementById(gcamount).value = 0;
	document.frmcart.cartmode.value = "GCRemoveOne";
//	document.frmcart.vendorid.value = id;
  document.frmcart.vendorid.value = id;
	document.frmcart.submit();
}

function removeone_charity(id, val)
{
	var charityamount = 'charityamount_'+ val;
	
	document.getElementById(charityamount).value = 0;
	document.frmcart.cartmode.value = "CharityRemoveOne";
	document.frmcart.charityid.value = id;
	document.frmcart.submit();
}

function updatecart_gc()
{
	document.frmcart.cartmode.value = "UpdateCart_GC";
	document.frmcart.submit();
}

function removeall_gc()
{
	document.frmcart.cartmode.value = "RemoveAll_GC";
	document.frmcart.submit();
}

function updatecart_charity()
{
	document.frmcart.cartmode.value = "UpdateCart_Charity";
	document.frmcart.submit();
}

function removeall_charity()
{
	document.frmcart.cartmode.value = "RemoveAll_Charity";
	document.frmcart.submit();
}
