var xmlhttp;
function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
}

// for displaying category products start here //

function addtocartindex(txt1,txt2)
{
	var pid=document.getElementById(txt1).value;
	var pcid=document.getElementById(txt2).value;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="shoppingcart.php?action=add";
	url=url+"&p="+pid+"&u="+pcid;
	xmlhttp.onreadystatechange=addtocartindexres;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function addtocartindexres()
{
	if (xmlhttp.readyState==4)
	{	
		document.getElementById("div_showloader").style.display="none";
		document.getElementById("divshoppingbag").innerHTML=xmlhttp.responseText;
	}
	else
	{
		document.getElementById("div_showloader").style.display="block";
	}
}
function addtocart(txt1,txt2)
{
	var pid=document.getElementById(txt1).value;
	var pcid=document.getElementById(txt2).value;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="shoppingcart.php?action=add";
	url=url+"&p="+pid+"&u="+pcid;
	xmlhttp.onreadystatechange=addtocartres;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	setTimeout('yourshopping('+pid+','+pcid+')',1000);
}

function addtocartres()
{
	if (xmlhttp.readyState==4)
	{		 
		document.getElementById("divshoppingbag").innerHTML=xmlhttp.responseText;
	}
	else
	{
		document.getElementById("div_showloader").style.display="block";
	}
}

function yourshopping(pid,pcid)
{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="yourshopping.php?action=add";
	url=url+"&p="+pid+"&u="+pcid;
	xmlhttp.onreadystatechange=yourshoppingres;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function yourshoppingres()
{
	if (xmlhttp.readyState==4)
	{		 
		document.getElementById("div_showloader").style.display="none";
		document.getElementById("divyourshopping").innerHTML=xmlhttp.responseText;
	}
	else
	{
		document.getElementById("div_showloader").style.display="block";
	}
}

// for displaying category products start here //
function showcatproducts(catname)
{		
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="product-listmenuajax.php";
	url=url+"?catid="+catname;
	xmlhttp.onreadystatechange=productsChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function productsChanged()
{
	if (xmlhttp.readyState==4)
		{		 
			currentOpac('container', 100, 300);
			document.getElementById("div_showloader").style.display="none";
			document.getElementById("container").innerHTML=xmlhttp.responseText;
		}
	else
		{
			currentOpac('container', '%2020', '%20300');
			document.getElementById("div_showloader").style.display="block";
		}
}
function continueshopping()
{
	window.location="product-list.php";
}
function updatecart(PCID)
{
	var qty=document.getElementById('txtqty'+PCID).value;
	/*var stock=document.getElementById('hidstock'+PCID).value;

	var stk=stock-qty;
	if((stk<=0)&&(qty>stock))
	{
		alert('Stock now available: '+stock+' only');
		document.frmcheckout.action="checkout.php?action=update&p="+PCID+"&uq="+stock;
		document.frmcheckout.submit();
	}
	else
	{*/
	document.frmcheckout.action="checkout.php?action=update&p="+PCID;
	document.frmcheckout.submit();
	//}
}
function removecart(PID,PCID)
{
	if(confirm("Are you sure you want to delete this product?"))
	{
		document.location.href="checkout.php?action=remove&p="+PID+"&pc="+PCID;
	}
}
function qtyupdate(text)
{
	 if(text.value==0)
		{			
	    alert('Please enter valid Information');
		text.value="1";		
		text.focus();
		} 

	if(text.value!="")
	{		
	  regexp=/^[0-9]{1,3}$/;
	  if(text.value.search(regexp)==-1)
	  {
	    text.value="1";		
	    alert('Please enter only numbers 1-9');
		text.focus();
	  } 
	 
	}	
}

function changesearchmanufac(val)
{
	if(val>0)
		document.getElementById("selscat").disabled=false;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="searchajax.php";
	url=url+"?manid="+val;
	xmlhttp.onreadystatechange=changesearchmanufacres;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function changesearchmanufacres()
{
	if (xmlhttp.readyState==4)
		{		 
			document.getElementById("div_showloader").style.display="none";			
			document.getElementById("divsearchcat").innerHTML=xmlhttp.responseText;
		}
	else
		{
			document.getElementById("div_showloader").style.display="block";
		}
}
function changesearchcategory(val)
{
	document.getElementById("div_showloader").style.display="block";
	if(val>0)
		document.getElementById("selscat").disabled=false;
	document.getElementById("selssubcat").options[document.getElementById("selssubcat").selectedIndex].text="Loading, Please Wait....";
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="searchajax.php";
	url=url+"?mid="+document.getElementById("selsmanu").value+"&cid="+val;
	//xmlhttp.onreadystatechange=changesearchmanufacres;
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	document.getElementById("div_showloader").style.display="none";			
	document.getElementById("divsearchcat").innerHTML=xmlhttp.responseText;
}
function changefocusfields(txt,txtvalue,val)
{
	if(txt.value==txtvalue)
	{
	txt.value="";
	if(val=="")
	txt.style.color ='#000000';
	else
		txt.style.color ='#949494';
	}
}
/*change from focus to normal ends here*/ 

/*change to focus from normal starts here------------bindu on08-05-2009*/ 
function changeonblurfields(txt,val)
{
	if(txt.value=="")
	{
		txt.value=val;
		txt.style.color ='#999999';
	}
}
/*change to focus from normal ends here*/ 

function searchnow()
{	
	/*if(document.getElementById("chknew").checked==true)
		var chknew=1;
	else
		var chknew=0;
	if(document.getElementById("chkused").checked==true)
		var chkused=1;
	else
		var chkused=0;
	if(document.getElementById("chkexdemo").checked==true)
		var chkexdemo=1;
	else
		var chkexdemo=0;
	document.frmheadersearch.action=
		"product-list.php?s=1&n="+chknew+"&u="+chkused+"&e="+chkexdemo;
	document.frmheadersearch.submit();
	var ptype="0";
	if(document.getElementById("chknew").checked==true)
		ptype+=",1";
	if(document.getElementById("chkused").checked==true)
		ptype+=",2";
	if(document.getElementById("chkexdemo").checked==true)
		ptype+=",3";
	document.frmheadersearch.action=
		"product-list.php?s=1&ptype="+ptype;*/
	document.frmheadersearch.action="product-list.php";
	document.frmheadersearch.submit();
}
function changeshipping(val)
{
	if(val=="US")
	{
		document.getElementById("divcounall").style.display="none";
		document.getElementById("divsatte").style.display="block";
	}
	else
	{
		document.getElementById("divcounall").style.display="block";
		document.getElementById("divsatte").style.display="none";
	}
}
