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 showcatproducts(origcatid,catid,val)
{		
	document.getElementById("hdn_catid").value=catid;
	if(origcatid!="")
	{
		document.getElementById("category_selectclass"+origcatid).className="";
	}
	var finalval=0;
	finalval=parseInt(document.getElementById("hidsidemenu").value)-1;
	for (var s=1;s<document.getElementById("hidsidemenu").value ;s++)
	{
		if(s==1)
			document.getElementById("category_selectclass"+document.getElementById("hidsidemenucatid"+s).value).className="first";
		else if(s==finalval)
			document.getElementById("category_selectclass"+document.getElementById("hidsidemenucatid"+s).value).className="last";
		else 
			document.getElementById("category_selectclass"+document.getElementById("hidsidemenucatid"+s).value).className="";
	}
	if(val=="000")
	document.getElementById("category_selectclass"+catid).className="first-select";
	else if(val=="111")
	document.getElementById("category_selectclass"+catid).className="last-select";
	else if(val=="222")
	document.getElementById("category_selectclass"+catid).className="select";
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="showcatproducts.php";
	url=url+"?catid="+catid;
	xmlhttp.onreadystatechange=productsChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function productsChanged()
{
	if (xmlhttp.readyState==4)
		{		 
		currentOpac('div_hidden', 100, 300);
		document.getElementById("div_showloader").style.display="none";
		document.getElementById("div_hidden").innerHTML=xmlhttp.responseText;
		//document.title="gia London - "+document.getElementById('pg_title').value;
		//document.getElementById("product_title").innerHTML=document.getElementById('pg_title').value;
		}
	else
		{
			currentOpac('div_hidden', '%2020', '%20300');
			document.getElementById("div_showloader").style.display="block";
		}
}
function getajaxquantityoffer(PCID,PID)
{		
	document.getElementById('divoutstockmsgoffer'+PID).innerHTML="";
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
	  alert ("Browser does not support HTTP Request");
	  return;
	}
	targetid = "divajaxqtyoffer"+PID;
	var url="refresherofferajax.php";
	url=url+"?id="+PCID+"&pid="+PID;
	xmlhttp.onreadystatechange=getajaxquantitychanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function getajaxquantity(PCID,PID)
{	
	document.getElementById('divoutstockmsg'+PID).innerHTML="";
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
	  alert ("Browser does not support HTTP Request");
	  return;
	}
	targetid = "divajaxqty"+PID;
	var url="refresherajax.php";
	url=url+"?id="+PCID+"&pid="+PID;
	xmlhttp.onreadystatechange=getajaxquantitychanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function getajaxquantityrel(PCID,PID)
{		
	document.getElementById('divoutstockmsgrel'+PID).innerHTML="";
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
	  alert ("Browser does not support HTTP Request");
	  return;
	}
	targetid = "divajaxqty"+PID;
	var url="relatedajax.php";
	url=url+"?id="+PCID+"&pid="+PID;
	xmlhttp.onreadystatechange=getajaxquantitychanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function getajaxquantitychanged()
{
	if (xmlhttp.readyState==4)
		{	 
			document.getElementById("div_showloader").style.display="none";
			document.getElementById(targetid).innerHTML=xmlhttp.responseText;			
		}
	else
		{
			document.getElementById("div_showloader").style.display="block";
		}
}
function addproducttobasketoffer(PID)
{
	var units=document.getElementById("selunitsoffer"+PID).value;
	var qty=document.getElementById("selqtyoffer"+PID).value;
	var stock=document.getElementById('hidstockoffer'+PID).value;
	
	if(stock==0)
	{
		document.getElementById('divoutstockmsgoffer'+PID).innerHTML="NOT IN STOCK:  Available in "+document.getElementById('hiddaysoffer'+PID).value+" days.";
		return false;
	}
	else
	{
		var stk=stock-qty;
		if((stk<=0)&&(qty>stock))
		{
			alert('Stock now available: '+stock+' only');
			//return false;
		}
		//else
		//{
			xmlhttp=GetXmlHttpObject();
			if (xmlhttp==null)
			{
			  alert ("Browser does not support HTTP Request");
			  return;
			}
			var url="shoppingbag.php";
			url=url+"?action=add&p="+PID+"&u="+units+"&q="+qty;
			xmlhttp.onreadystatechange=addproducttobasketchanged;
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
		//}
	}
}
function addproducttobasket(PID)
{
	var units=document.getElementById("selunits"+PID).value;
	var qty=document.getElementById("selqty"+PID).value;
	var stock=document.getElementById('hidstock'+PID).value;
	
	/*if(stock==0)
	{
		document.getElementById('divoutstockmsg'+PID).innerHTML="NOT IN STOCK:  Available in "+document.getElementById('hiddays'+PID).value+" days.";
		return false;
	}
	else
	{*/

	if(qty=="")
	{
		alert("Please Enter Quantity");
		document.getElementById('selqty'+PID).focus();
		return false;
	}
	else
	{
		var stk=stock-qty;
		if((stk<=0)&&(qty>stock)&&stock>0)
		{
			alert('Stock now available: '+stock+' only');
			//return false;
		}
		//else
		//{
			xmlhttp=GetXmlHttpObject();
			if (xmlhttp==null)
			{
			  alert ("Browser does not support HTTP Request");
			  return;
			}
			var url="shoppingbag.php";
			url=url+"?action=add&p="+PID+"&u="+units+"&q="+qty;
			xmlhttp.onreadystatechange=addproducttobasketchanged;
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
		//}
	//}
	}
}
function addproducttobasketrel(PID)
{
	var units=document.getElementById("selunitsrel"+PID).value;
	var qty=document.getElementById("selqtyrel"+PID).value;
	var stock=document.getElementById('hidstockrel'+PID).value;
	
	if(stock==0)
	{
		document.getElementById('divoutstockmsgrel'+PID).innerHTML="NOT IN STOCK:  Available in "+document.getElementById('hiddaysrel'+PID).value+" days.";
		return false;
	}
	else
	{
		var stk=stock-qty;
		if((stk<=0)&&(qty>stock))
		{
			alert('Stock now available: '+stock+' only');
			//return false;
		}
		//else
		//{
			xmlhttp=GetXmlHttpObject();
			if (xmlhttp==null)
			{
			  alert ("Browser does not support HTTP Request");
			  return;
			}
			var url="shoppingbag.php";
			url=url+"?action=add&p="+PID+"&u="+units+"&q="+qty;
			xmlhttp.onreadystatechange=addproducttobasketchanged;
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
		//}
	}
}
function addproducttobasketchanged()
{
	if (xmlhttp.readyState==4)
		{		 
			document.getElementById("div_showloader").style.display="none";
			document.getElementById("divshoppingbag").innerHTML=xmlhttp.responseText;	
			hs.close();
		}
	else
		{
			document.getElementById("div_showloader").style.display="block";
		}
}
function gotocheckout()
{
	document.location.href="checkout.php";
}
function enlargeviewaddproducttobasket(PID,PCID)
{
	var stock=document.getElementById('hidstock'+PCID).value;
	
	/*if(stock==0)
	{
		alert("NOT IN STOCK:  Available in "+document.getElementById('hiddays'+PCID).value+" days.");
		return false;
	}
	else
	{*/
		var qty=document.getElementById("selqty"+PCID).value;

	if(qty=="")
	{
		alert("Please Enter Quantity");
		document.getElementById('selqty'+PCID).focus();
		return false;
	}
	else
	{
		var stk=stock-qty;
		
		
		if((stk<=0)&&(qty>stock)&&(stock>0))
		{
				alert('Stock now available: '+stock+' only');
				//return false;
		}
		
		//else
		//{
			xmlhttp=GetXmlHttpObject();
			if (xmlhttp==null)
			{
			  alert ("Browser does not support HTTP Request");
			  return;
			}
			var url="shoppingbag.php";
			url=url+"?action=add&p="+PID+"&u="+PCID+"&q="+qty;
			xmlhttp.onreadystatechange=enlargeviewaddproducttobasketchanged;
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
		//}
	//}
	}
}
function enlargeviewaddproducttobasketchanged()
{
	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 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 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 continueshopping()
{
	document.location.href="search-products.php";
}
function checkspace(text)
{
  var str=text.value;
  var first=str.substring(0,1);
  var second=str.substring(0,1);
  var val='false';
  if(first==' ')
  {
		val='true';
		if(val=='true')
		{
		   if(second==' ')
		   {
			 val='true';
			 //alert('Please Enter Valid Information');
			 text.value = "";
		   }
		}
  }
		 
}
function RequiredField(text,msg)
{
    if((document.getElementById(text).value)== "" )
    {
        alert(msg);
        document.getElementById(text).focus();
        return false;
    } 
    else
    {
      return true;
    }   
}
function EmailValidation(txt)
{
    if(((document.getElementById(txt).value)!="")&&((document.getElementById(txt).value)!=""))
     {
            regexp=/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
            if(document.getElementById(txt).value.search(regexp)==-1)
            {
                  document.getElementById(txt).value="";
                  alert('Invalid Email, Please Re-Enter');
                  document.getElementById(txt).focus();
                  return false;
            }
            else
	            return true;
	 }
	 else
	    return true;
}
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
function chkPostcode()
{
	
	if(document.getElementById("hidishaz").value=="1")
	{
		if(document.getElementById("reg_country").value=="GB")
		{
			var pcode=document.getElementById('postcode').value;
			var pcodesub=pcode.substring(0,4);
			var nongfscodes=document.getElementById('hidnongfscode').value;
			var nongfscodesarr=nongfscodes.split(",");
			var a=0;
			for(var i=0;i<nongfscodesarr.length;i++)
			{
				if((pcodesub.toUpperCase()==nongfscodesarr[i])&&a==0)
					a=1;
			}
			if(a==1)
			{					
				document.getElementById("hdn_ship_name").value="GFS";
				document.getElementById("hdn_shipprice").value="9.95";
				document.getElementById("hdn_cons").value="1";
				document.getElementById('div_zoneship').innerHTML="&pound; 9.95";
				var tot=parseFloat(document.getElementById("hdn_shipprice").value)+parseFloat(document.getElementById("hdn_noshiptotalamt").value);
				document.getElementById('div_showgtot').innerHTML="<b>Total inc VAT<br/>&pound;"+roundNumber(tot,"2")+"</b>";
				document.getElementById('hdn_grandtotalamt').value=roundNumber(tot,"2");
				return true;
			}
			else
			{
				document.getElementById("hdn_shipprice").value=document.getElementById("hdn_mainshipprice").value;
				document.getElementById("hdn_cons").value="0";
				document.getElementById('div_zoneship').innerHTML="&pound;"+document.getElementById("hdn_mainshipprice").value;
				var tot=parseFloat(document.getElementById("hdn_shipprice").value)+parseFloat(document.getElementById("hdn_noshiptotalamt").value);
				document.getElementById('div_showgtot').innerHTML="<b>Total inc VAT<br/>&pound;"+roundNumber(tot,"2")+"</b>";
				document.getElementById('hdn_grandtotalamt').value=roundNumber(tot,"2");			
			}
		}
		document.getElementById("hdn_ship_name").value="GFS";
		return true;
	}
	else
	{
		if(parseFloat(document.getElementById("hdn_totshipwgt").value)>parseFloat("2.00"))
		{	
			if(document.getElementById("reg_country").value=="GB")
			{
				var pcode=document.getElementById('postcode').value;
				var pcodesub=pcode.substring(0,4);
				var nongfscodes=document.getElementById('hidnongfscode').value;
				var nongfscodesarr=nongfscodes.split(",");
				var a=0;
				for(var i=0;i<nongfscodesarr.length;i++)
				{
					if((pcodesub.toUpperCase()==nongfscodesarr[i])&&a==0)
						a=1;
				}
				if(a==1)
				{					
					document.getElementById("hdn_ship_name").value="GFS";
					document.getElementById("hdn_shipprice").value="9.95";
					document.getElementById("hdn_cons").value="1";
					document.getElementById('div_zoneship').innerHTML="&pound; 9.95";
					var tot=parseFloat(document.getElementById("hdn_shipprice").value)+parseFloat(document.getElementById("hdn_noshiptotalamt").value);
					document.getElementById('div_showgtot').innerHTML="<b>Total inc VAT<br/>&pound;"+roundNumber(tot,"2")+"</b>";
					document.getElementById('hdn_grandtotalamt').value=roundNumber(tot,"2");
					return true;
				}
				else
				{
					document.getElementById("hdn_shipprice").value=document.getElementById("hdn_mainshipprice").value;
					document.getElementById("hdn_cons").value="0";
					document.getElementById('div_zoneship').innerHTML="&pound;"+document.getElementById("hdn_mainshipprice").value;
					var tot=parseFloat(document.getElementById("hdn_shipprice").value)+parseFloat(document.getElementById("hdn_noshiptotalamt").value);
					document.getElementById('div_showgtot').innerHTML="<b>Total inc VAT<br/>&pound;"+roundNumber(tot,"2")+"</b>";
					document.getElementById('hdn_grandtotalamt').value=roundNumber(tot,"2");			
				}
			}
			document.getElementById("hdn_ship_name").value="GFS";
		}
		else
			document.getElementById("hdn_ship_name").value="Royal Mail";
		return true;
	}
		
	
}
function proceedtopayment(val)
{
 if( 
 RequiredField('reg_name','Please Enter Firstname') && 
 RequiredField('reg_surname','Please Enter Surname') &&
 RequiredField('reg_phone','Please Enter Phone ') &&
 RequiredField('reg_emailAddress','Please Enter Email Address') &&
 EmailValidation('reg_emailAddress') &&
 RequiredField('address2','Please Enter Building Number and Street Name') &&
 RequiredField('town','Please Enter Town') &&
 RequiredField('postcode','Please Enter Postcode')&& 
 chkPostcode()
) 
{
	if(document.getElementById("rdsagepay").checked==true)
		document.getElementById("hdn_paytype").value="sagepay";
	else if(document.getElementById("rdpaypal").checked==true)
		document.getElementById("hdn_paytype").value="paypal";

	if(val=="1"||val=="2")
	{
		if(val=="1"&&document.getElementById("reg_password").value=="")
		{
			alert("Please Enter Password");
			document.getElementById("reg_password").focus();
			return false;
		}
		document.frmcheckout.action="functions/insert.php?chkpwd=1";
	}
	else
		document.frmcheckout.action="functions/insert.php";
	document.frmcheckout.submit();
}
else
{
	return false;
}    
}

function chkemailfp(val)
{
if(
 RequiredField('forgot_email','Please Enter Email Address') &&
 EmailValidation('forgot_email') 
) 
{
	if(val=="1")
		document.fp.action="chkfp.php";
	else if(val=="2")
		document.frmcheckout.action="chkfp.php?f=1";
}
else
{
	return false;
}    
}
function updatecart(PCID)
{
	var qty=document.getElementById('txtqty'+PCID).value;

	if(qty=="")
	{
		alert("Please Enter Quantity");
		document.getElementById('txtqty'+PCID).focus();
		return false;
	}
	else
	{
		var stock=document.getElementById('hidstock'+PCID).value;

		var stk=stock-qty;
		
		if((stk<=0)&&(qty>stock)&&(stock>0))
		{
			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 chksearch()
{
	var searchstr=document.getElementById('txtsearch').value;
	if(searchstr!="Search the site")
	{
		return true;
	}
	else
	{
		alert('Please Enter Search Keyword');
        document.getElementById('txtsearch').focus();
        return false;
	}
}
function sendcomments()
{
	if(document.getElementById('txtfname').value=="" || document.getElementById('txtfname').value=="Your full name")
    {
		alert('Please Enter Your full name');
        document.getElementById('txtfname').focus();
        return false;
	}
	if(document.getElementById('txtcity').value=="" || document.getElementById('txtcity').value=="Your city")
    {
		alert('Please Enter Your city');
        document.getElementById('txtcity').focus();
        return false;
	}
	if(document.getElementById('txtreview').value=="" || document.getElementById('txtreview').value=="Your review")
    {
		alert('Please Enter Your review');
        document.getElementById('txtreview').focus();
        return false;
	}
	document.frmcomments.action="functions/insert.php";
	document.frmcomments.submit();
}
function contactus()
{
	if(
	 RequiredField('txtname','Please Enter Name') && 
	 RequiredField('txtemail','Please Enter Email Address') &&
	 EmailValidation('txtemail') &&
	 RequiredField('txtphone','Please Enter Phone Number') &&
	 RequiredField('txtmsg','Please Enter Message')
	) 
	return true;
    else
    {
     return false;
    }  
	//document.frmcontactus.action="functions/insert.php";
	document.frmcontactus.submit();
}
function customerlogin()
{
	if(
	 RequiredField('txt_email','Please Enter Email Address') &&
	 EmailValidation('txt_email') &&
	 RequiredField('txt_password','Please Enter Password') 
	) 
	{
		document.frmcheckout.action="functions/insert.php?l=1";
		document.frmcheckout.submit();
	}
    else
    {
     return false;
    }
}
function closedetails(val)
{
	document.getElementById('aclose'+val).className="pound-a";
}
function opendetails(val)
{
	document.getElementById('aclose'+val).className="tpop pound-a";
}
function chkcouponcode()
{
	if(document.getElementById('txt_couponcode').value=="")
	{
		alert("Please enter Coupon or Voucher code");
		document.getElementById('txt_couponcode').focus();
		return false;
	}
	else
	{
		document.frmcheckout.action="chkpromocde.php";
		document.frmcheckout.submit();
	}
}
//Personal details by madhavi 06july2010
function updateprofile()
	{
		if(
			RequiredField('txt_fname','Please Enter First Name')&&
			RequiredField('txt_lname','Please Enter Surname')&&
			RequiredField('txt_address1','Please Enter Building Number and Street Name')&&
			RequiredField('txt_city','Please Enter Town')&&
			RequiredField('reg_zip','Please Enter Postcode')
			)
			{
			return true;
			}
			else
			{
				return false;
			}
	}
//Changepassword
function validchangepwd()
	{
		if(RequiredField('txtoldpwd','Please enter Old Password')&&
			RequiredField('txtnewpwd','Please enter New Password')&&
			validMinCount('txtnewpwd',5,'New Password Should be Minimum of 5 Characters')&&
			RequiredField('txtcnfpwd','Please enter Confirm Password')&&
			validMinCount('txtcnfpwd',5,'Confirm Password Should be Minimum of 5 Characters')&&
			changePwd('txtnewpwd','txtcnfpwd')
			)
			{
			return true;
			}
			else
					return false;
	}
	//Shipping 
function chkRadioField()
{
	if(document.getElementById('hdn_shipnumrows'))
	{
	var shippricename="";
	
	coutshiprows=document.getElementById('hdn_shipnumrows').value;
	var x=0;
	for(i=1;i<=coutshiprows;i++)
	{
		shippricename="rd_shippriceid"+i;
			if(document.getElementById(shippricename))
			{
				if(document.getElementById(shippricename).checked==true)
				{
					x=x+1;
				} 				
			}
	}
	if(x==0)
	{
		alert("Please Select Shipping");
		return false;
	}
	else
	{
		return true;
	}
	}
	else
	{
		return true;
	}
}
function chkshipping(shipprice,id)
{
	if(document.getElementById('hdn_shipprice').value=="0.00")
	{
		hdntax=document.getElementById('hdn_tax').value;

		gtotincvat=document.getElementById('hdn_noshiptotalamt').value;
		shippricevat=shipprice*(hdntax/100);
		shipprice=shipprice+shippricevat;
		gtot=parseFloat(shipprice)+parseFloat(gtotincvat);
		
		taxvalnoship=document.getElementById('hdn_noshipvatvalue').value;
		taxval=parseFloat(taxvalnoship)+parseFloat(shippricevat);

		totexvat=gtot-taxval;
		document.getElementById('div_showgtot').innerHTML="<b>Total inc VAT<br/>&pound; "+parseFloat(gtot).toFixed(2)+"</b>";
		document.getElementById('hdn_grandtotalamt').value=parseFloat(gtot).toFixed(2);
		document.getElementById('hdn_shipprice').value=shipprice;
		document.getElementById('div_tax').innerHTML="<b>Total ex VAT</b><br/>&pound; "+parseFloat(totexvat).toFixed(2);
		document.getElementById('chkout_showvatmsg').innerHTML='<span style="font-size:10pt; color:#36567E">(this includes '+parseFloat(taxval).toFixed(2)+' VAT at '+hdntax+'%)</span>';
		document.getElementById('hdn_vatvalue').value=parseFloat(taxval).toFixed(2);
		document.getElementById('hdn_ship_id').value=document.getElementById('hidshipid'+id).value;
		
	}
	else if(document.getElementById('hdn_shipprice').value!="0.00"&&document.getElementById('hdn_ship_id').value!=document.getElementById('hidshipid'+id).value)
	{
		hdntax=document.getElementById('hdn_tax').value;

		gtotincvat=document.getElementById('hdn_noshiptotalamt').value;
		shippricevat=shipprice*(hdntax/100);
		shipprice=shipprice+shippricevat;
		gtot=parseFloat(shipprice)+parseFloat(gtotincvat);
		
		taxvalnoship=document.getElementById('hdn_noshipvatvalue').value;
		taxval=parseFloat(taxvalnoship)+parseFloat(shippricevat);

		totexvat=gtot-taxval;

		document.getElementById('div_showgtot').innerHTML="<b>Total inc VAT<br/>&pound; "+parseFloat(gtot).toFixed(2)+"</b>";
		document.getElementById('hdn_grandtotalamt').value=parseFloat(gtot).toFixed(2);
		document.getElementById('hdn_shipprice').value=shipprice;
		document.getElementById('div_tax').innerHTML="<b>Total ex VAT</b><br/>&pound; "+parseFloat(totexvat).toFixed(2);
		document.getElementById('chkout_showvatmsg').innerHTML='<span style="font-size:10pt; color:#36567E">(this includes '+parseFloat(taxval).toFixed(2)+' VAT at '+hdntax+'%)</span>';
		document.getElementById('hdn_vatvalue').value=parseFloat(taxval).toFixed(2);
		document.getElementById('hdn_ship_id').value=document.getElementById('hidshipid'+id).value
	}

}

function changeshipping(val)
{
	if(val=="GB")
	{
		if(document.getElementById("divpcode"))
		document.getElementById("divpcode").style.display="block";
		if(document.getElementById("divnopcode"))
		document.getElementById("divnopcode").style.display="none";
	}
	else
	{
		if(document.getElementById("divpcode"))
		document.getElementById("divpcode").style.display="none";
		if(document.getElementById("divnopcode"))
		document.getElementById("divnopcode").style.display="block";
	}

	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";
	}
	
	

	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="checkoutajax.php?";
	url=url+"cou="+val;
	xmlhttp.onreadystatechange=changeshippingres;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function changeshippingres()
{
	if (xmlhttp.readyState==4)
	{	
		document.getElementById("divshipping").innerHTML=xmlhttp.responseText;
	}
	else
	{
	}
}
function showdivforgopwd()
{
	document.getElementById('div_forgotpassword').style.display="block";
	document.getElementById('div_login').style.display="none";
	document.title="Corrosion Protection - Rust Removal - Car Wax - Car Polish - Bilt-Hamber UK - Forgot Password";
	//document.getElementById('loginpagetitle').innerHTML="<strong>Forgot Password</strong>";
	//document.getElementById('loginpagetitle').className="pnk_title";
}
function hidedivforgopwd()
{
	document.getElementById('div_forgotpassword').style.display="none";
	document.getElementById('div_login').style.display="block";
	document.title="Corrosion Protection - Rust Removal - Car Wax - Car Polish - Bilt-Hamber UK - Login";
	//document.getElementById('loginpagetitle').innerHTML="<strong>User Login</strong>";
	//document.getElementById('loginpagetitle').className="pnk_title";
}
function chkloginindex()
{
	if(
		RequiredField('login_email','Please Enter Email Address')&&
		RequiredField('login_password','Please Enter Password')
	)
	{
		document.frm_login.action="chk.php";document.frm_login.submit();
	}
	else
	{
		return false;
	}
}
function gotoforgotpwd()
{
	document.getElementById('divforgot').style.display="block";
	document.getElementById('divlogin').style.display="none";
	document.getElementById('popup_exitinstructions').innerHTML="CLOSE AND RETURN TO CHECKOUT";
	document.getElementById('popup_loginstructions').innerHTML="GO";
	var popid=document.getElementById('popup_loginstructions');
	popid.setAttribute('onclick','gotopopupforgot();');
}
/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();
/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function gotopopuplogin()
{
	if(
	 RequiredField('txt_email','Please Enter Email Address') &&
	 EmailValidation('txt_email') &&
	 RequiredField('txt_password','Please Enter Password') 
	)
	{
	// Optional: Show a waiting message in the layer with ID login_response
	document.getElementById('insert_responselogin').style.display="none";
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	var email=encodeURI(document.getElementById('txt_email').value);
	email=email.replace(/&/g, "txt_amp123");
	email=email.replace(/#/g, "txt_ash123");
	var pwd=encodeURI(document.getElementById('txt_password').value);

	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable

	http.open('get', 'functions/insert.php?lpopup=1&email='+email+'&pwd='+pwd+'&nocache ='+nocache);		
	
	http.onreadystatechange = insertReplylogin;
	http.send(null);
		
	}
	else
	{
		return false;
	}
}
function gotopopupforgot()
{
	if(
	 RequiredField('txt_foremail','Please Enter Email Address') &&
	 EmailValidation('txt_foremail')
	)
	{
	// Optional: Show a waiting message in the layer with ID login_response
	document.getElementById('insert_responselogin').style.display="none";
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	var email=encodeURI(document.getElementById('txt_foremail').value);
	email=email.replace(/&/g, "txt_amp123");
	email=email.replace(/#/g, "txt_ash123");

	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable

	http.open('get', 'functions/insert.php?forpopup=1&foremail='+email+'&nocache ='+nocache);		
	
	http.onreadystatechange = insertReplylogin;
	http.send(null);
		
	}
	else
	{
		return false;
	}
}
function insertReplylogin() {
if(http.readyState == 4){ 
var response = http.responseText;
scroll(0,0);
if(response=="Invalid Username or Password")
{
	document.getElementById('insert_responselogin').style.display="Block";
	document.getElementById('insert_responselogin').innerHTML = '<div><span style="color:#D81F28; font:bold normal 13pt/120% Arial Narrow,Arial">Incorrect login</span></div><div style="color:#D93531">Invalid Email address/Password, Please try again, use the Forgotten Password button below. or continue without logging in.</div>';
	document.getElementById('txt_email').value="";
	document.getElementById('txt_password').value="";
}
else if(response=="Invalid Email Address")
{
	document.getElementById('insert_responsefor').style.display="Block";
	document.getElementById('insert_responsefor').innerHTML = response;
	document.getElementById('txt_foremail').value="";
}
else if(response=="Password Sent To Your Email Address")
{
	document.getElementById('insert_responsefor').style.display="Block";
	document.getElementById('insert_responsefor').innerHTML =response;
	document.getElementById('txt_foremail').value="";
}
else
{		
	window.location=response;
}
}
}
function gotopopupcreateacct(val,id)
{
	if(chkPostcode()) 
	{
		if(document.getElementById("rdsagepay").checked==true)
			document.getElementById("hdn_paytype").value="sagepay";
		else if(document.getElementById("rdpaypal").checked==true)
			document.getElementById("hdn_paytype").value="paypal";

		if(val=="1"||val=="2")
		{
			if(val=="1"&&document.getElementById(id).value=="")
			{
				alert("Please Enter Password");
				document.getElementById(id).focus();
				return false;
			}
			document.getElementById("reg_password").value=document.getElementById(id).value;
			document.frmcheckout.action="functions/insert.php?chkpwd=1";
		}
		else
			document.frmcheckout.action="functions/insert.php";
		document.frmcheckout.submit();
	}
	else
	{
		return false;
	}    
}
function opentermswin(page,title)
{
	testwindow=window.open(page,title,"menubar=1,scrollbars=1,width=790,height=600"); 
	testwindow.moveTo(150, 50);
}
