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, contshp)
{

  var val ;
  var counter;
  val = 0 ;
  counter = 0;
  
  var selgallery_img = encode64(document.productdetail.img_main.src);
  
  if(document.getElementById('procolor').value == '')
  {
    tb_show("Color","#TB_inline?height=80&width=450&inlineId=colorattroption","");
		return false;
  }
  if(document.getElementById('sizeattr').value == '')
  {
    tb_show("Size","#TB_inline?height=80&width=450&inlineId=sizeattroption","");
		return false;
  }
  /*
  if(document.getElementById('stock').value == '')
  {
    tb_show("Quantity","#TB_inline?height=80&width=450&inlineId=qtyattr","");
		return false;
  }	
  */		
  //qty = document.getElementById('stock').value;
  selcolor = document.getElementById('procolor').value;
  selsize = document.getElementById('sizeattr').value;
  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)+"&contshp="+contshp+"&selimage="+selgallery_img+"&selcolor="+escape(selcolor)+"&selsize="+escape(selsize);
	 
	 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;

    
		if(set_key == 'yes')
			 tb_show("Reduce Quantity","#TB_inline?height=80&width=450&inlineId=reduceqty_message","");
		else
			 tb_show("Add To Cart","#TB_inline?height=75&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()
{
    window.location = site_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()
{
	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_QTY_DISP,"#TB_inline?height=75&width=450&inlineId=reduceqty_message","");
         return false;
			}
			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()
{
  window.location = site_url + 'Billing-Shipping/';
	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();
}

