var pageLoad='cart';
var loadedPage='Y';

var prevDiv='cat_0_div';



function loadPageFunction()
{
	//goExpand();
}
		
function delFromCart(id,msg)
{
	if(confirm(msg))
	{
		getVar='del_id='+id;
		submitFormAndLoadCart('','del_from_cart',getVar,base_url+'/cart');
	}
}

function goCheckout(redirect)
{
	location=redirect;
}





function expandSubcat(catid,ni)
{
	if(ni!=-1)
	{
		for(i=0;i<ttl_cats;i++)
		{
			document.getElementById('sublist'+i).style.display='none';
			document.getElementById('sublist'+i).innerHTML='';
		}
		document.getElementById('sublist'+ni).style.display='block';
		
		getVar='pro_cat_id='+catid;
		
		submitForm('sublist'+ni,'get_subcat_list',getVar,'','');
	}
}




function changeCartQty(dgnid,ttln)
{
	document.getElementById('btn'+dgnid).value='Updating...';
	
	ttlqty=0;
	qtystr='';
	qtycomma='';
	for(ni=0;ni<ttln;ni++)
	{
		qtystr+=qtycomma+document.getElementById('szbox'+dgnid+ni).value;
		qtycomma=',';
		ttlqty+=parseInt(document.getElementById('szbox'+dgnid+ni).value);
	}
		
	
	getVar='dgn_id='+dgnid+'&qty_str='+qtystr+'&ttl_qty='+ttlqty;	
	submitFormAndLoadCart('','change_cart_qty',getVar,'');
	return false;
}




function load_cart()
{
	submitForm('cart_details','get_cart_details','','','');
}



function verifyCoupon()
{
	couponcode=document.getElementById('coupon_code').value;
	var xmlHttp;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		try
		  {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		catch (e)
		  {
			  alert("Your browser does not support AJAX!");
			  return false;
		  }
		}
	  }
	  xmlHttp.onreadystatechange=function()
		{
		if(xmlHttp.readyState==4)
		  {
			//alert(xmlHttp.responseText);
			if(xmlHttp.responseText=='Y')
			{						
				load_cart();
				readCartHeader();
			}
			else
			{
				document.getElementById('coupon_info').innerHTML=xmlHttp.responseText;
				load_cart();
				readCartHeader();
			}
			
		  }
		}
	
	  getVar='c_code='+couponcode;
	  xmlHttp.open("GET",base_url+"/site/user/php/pbox/verify_coupon.php?"+getVar,true);
	  xmlHttp.send(null);
	  
   return false;	  
}


function submitFormAndLoadCart(loadtoid,pageName,getVar,redirect)
{
	
	if(loadtoid!='')document.getElementById(loadtoid).innerHTML='Loading...';
	
	var xmlHttp;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		try
		  {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		catch (e)
		  {
			  alert("Your browser does not support AJAX!");
			  return false;
		  }
		}
	  }
	  xmlHttp.onreadystatechange=function()
		{
		if(xmlHttp.readyState==4)
		  {
			//alert(xmlHttp.responseText);
			if(loadtoid!='')document.getElementById(loadtoid).innerHTML=xmlHttp.responseText;
			if(redirect!='')location=redirect;
			
			load_cart();
			readCartHeader();
			
		  }
		}
	
	  xmlHttp.open("GET",base_url+"/site/user/php/pbox/"+pageName+".php?"+getVar,true);
	  xmlHttp.send(null);
}

