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, mqty, price, name, weight)
{

  var val ;
  var counter;
  val = 0 ;
  counter = 0;
 
  //  alert(weight);return false;
 
  /* Attribute Selection*/
   var totatt = document.getElementById('selectatt').value;
   var allattribute = '';
   for(var j = 0; j < totatt; j++)
   {
       var selname = 'option_'+j;
       var getopttype = (document.getElementById(selname).name).split('_');
       if(getopttype[2] == 'Radio')
       {
          for(i=0;i<document.frmproduct.elements.length;i++)
        	{        	   
        	  	if(document.frmproduct.elements[i].id == document.getElementById(selname).id)
        	  	{
        			    if(document.frmproduct.elements[i].checked == true)
        			       allattribute +=  document.frmproduct.elements[i].value + '$$';
        			    else
        			       allattribute += '';
        			}
        	}
        	//alert(allattribute);
       }
       if(getopttype[2] == 'Checkbox')
       {
          if(document.getElementById(selname).checked == true)
              allattribute += document.getElementById(selname).value + '$$';
          else
              allattribute += '';
       }
       if(getopttype[2] == 'Dropdown')
       {
          if(document.getElementById(selname).value != '0')
              allattribute += document.getElementById(selname).value + '$$';
          else
              allattribute += '';
       }
   }
   /* end code */
     
  
  var qty = document.getElementById("prdqty").value;
  
  if(qty<=0)
  {
    qty =1;
  
  }
  
	 //  get url of ajax file
	 var url = ajax_url + "ajax_shoppingcart.php";
	
	 url = url + "?productid="+escape(productid)+"&maxqty="+escape(mqty)+"&qty="+ escape(qty)+"&price="+escape(price)+"&name="+escape(name)+"&mode="+escape(mode)+"&getatt="+allattribute+"&weight="+weight;
	 //  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;
     
      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
		    window.location = site_url+'shoppingcart/1';
		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();
}

var qtystockmgmt = new Array();
function updatecart()
{
	var flag = 0;
	
		
	for(i = 0 ; i < document.getElementById('total_item_cart').value ; i++)
	{  
	  // if(document.getElementById('get_qty_id_'+i).value)
	  
		//qyt_entered = document.getElementById("qty_"+i).value;
		qty_available = document.getElementById("qtyinstock_"+i).value;
		var prdid= "qty_"+document.getElementById("get_qty_id_"+i).value;
		var maxtot = 0;
		for(j=0;j<document.frmcart.elements.length;j++)
    {
      if(document.frmcart.elements[j].alt == prdid)
  		{
  			maxtot = maxtot + parseInt(document.frmcart.elements[j].value);
  		}
    }
		if(parseInt(maxtot) > parseInt(qty_available))
		{
		  /*
		  document.getElementById("qty_"+i).value = document.getElementById("qtyinstock_"+i).value;
			if(flag == '0')
			{
			   document.getElementById("qty_"+i).className = 'input-red1';
         tb_show("Reduce Quantity","#TB_inline?height=75&width=450&inlineId=reduceqty_message","");
         return false;
			}
			*/
			for(j=0;j<document.frmcart.elements.length;j++)
      {
        if(document.frmcart.elements[j].alt == prdid)
    		{
    		  document.frmcart.elements[j].className = 'input-red1';    			
    		}
      }      
			tb_show("Reduce Quantity","#TB_inline?height=75&width=450&inlineId=reduceqty_message","");
			return false;
			flag++;
		}
	}
	/*
	alert(qtystockmgmt.length);
  return false;
	*/
	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();
}


//  

