function setcorrectimage(val)
{
	document.getElementById('imglarge').src="products/big/"+val;	
	document.getElementById('popbigimg').href="products/main/"+val;	
}
function validNumbers(text)
{
	if(text.value.length==0)return;
	if(text.value==0)
		{
		alert('Invalid Number');
		text.value='1';
		return false;
		}
var regexp=/^[0-9]*$/;
if(text.value.search(regexp)==-1)
{
	text.value=text.value.substring(0,(text.value.length-1));
	alert('Numbers Only');
	if(text.value.search(regexp)==-1)
	text.value="";
}
}
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';
				text.value="";
			}
		}
	}
}
function LTrim(str)
{
	for(var i=0;((str.charAt(i)<=" ")&&(str.charAt(i)!=""));i++);
	return str.substring(i,str.length);
}
	function RTrim(str)
	{
		for(var i=str.length-1;((str.charAt(i)<=" ")&&(str.charAt(i)!=""));i--);
		return str.substring(0,i+1);
	}
	function Trim(str)
	{
		return LTrim(RTrim(str));
	}
	
		function changefocusfields(txt,txtvalue)
		{
			if(txt.value==txtvalue)
			{
				txt.value="";
			}
		}
		function changeonblurfields(txt,val)
		{
			if(txt.value=="")
			{
				txt.value=val;
			}
		}
function chkemailnews(ctrl,strcheck)
	{
		if((document.getElementById(ctrl).value==strcheck)||(document.getElementById(ctrl).value==""))
			{
			alert("Please Enter Email");
			document.getElementById(ctrl).focus();
			return false;
			}
			else
			{
				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(ctrl).value.search(regexp)==-1)
				{
				 document.getElementById(ctrl).value="";
					alert('Please Enter Valid Email');
					document.getElementById(ctrl).focus();
				return false;
				}
			else
			{
				SimpleModal.open('newsletter.php?email='+document.getElementById(ctrl).value,200,400);
				return true;
			}
		  }
	}
	function validatenewsletterpage()
		{
			if(
				RequiredField('pfname','Please Enter First Name')&&
				validMinCount('pfname',3,'Please Enter Minimum 3 Characters For First Name')&&
				RequiredField('plname','Please Enter Last Name')&&
				validMinCount('plname',3,'Please Enter Minimum 3 Characters For Last Name')&&
				RequiredField('pphone','Please Enter Phone')
				)
				{
				document.form.action="functions/update.php";
				document.form.submit();
				}
				else
					{
					return false;
					}
		}
					function skipnewsletterinfo(email)
						{
							document.form.target='_self';
							document.form.action="newsletter.php?type=skip&emailid="+email;
							document.form.submit();
						}

		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 chkdiv(text,msg)
		{
			if((Trim(document.getElementById(text).innerHTML))!="")
				{
				alert(msg);
				return false;
				}
				else
				{
					return true;
					}
					}
					

function validMinCount(text,long,msg)
	{
		if(document.getElementById(text).value!="")
			{
			var maxlength=new Number(long);
			if(document.getElementById(text).value.length<maxlength)
				{
				alert(msg);document.getElementById(text).focus();
				return false;
				}
			else
		return true;	
			}
			else
		return true;
			}
			function validCount(text,len)
				{
					if(text.value.length>len)
						{
						alert(len+' Characters only');
						text.value=text.value.substring(0,len);
						}
				}
		function changePwd(newpwd,confirmpwd)
			{
				var newpassword=document.getElementById(newpwd).value;
				var confirmpassword=document.getElementById(confirmpwd).value;
				if((newpassword)!=(confirmpassword))
					{
					alert('New Password and Confirm Password Should be Same');
					document.getElementById(newpwd).value="";
					document.getElementById(confirmpwd).value="";									
					document.getElementById(newpwd).focus();
					return false;
					}
					else
					return true;
			}
	function chkrdbtn()
	{
		if(document.getElementById('rd_paymentpaypal').checked)
		{
			 document.getElementById('chkradiobtn').value="1";
		}
		if(document.getElementById('rd_paymentsagepay').checked)
		{
			document.getElementById('chkradiobtn').value="2";
		}
	}
function chknewsletter()
	{
		if(document.getElementById('chk_newsletter').checked)
			{
			document.getElementById('chknewslettervalue').value=1;
			}
		else
		{
			document.getElementById('chknewslettervalue').value=0;
		}
	}
			function chkaddnowpopup(pid)
				{
					document.getElementById('div_showaddnow').style.display="block";
			        document.getElementById('div_showaddnow').innerHTML=SimpleModal.open('addnow.php?pid='+pid,210,400);
			}
			function chkclose()
			{
				SimpleModal.close();
			}




function chkregister()
{
 if(
 RequiredField('reg_surname','Please Enter Surname') &&
 RequiredField('reg_name','Please Enter Firstname') && 
 RequiredField('reg_address','Please Enter Address1') &&
 RequiredField('reg_emailAddress','Please Enter Email Address') &&
 EmailValidation('reg_emailAddress') &&
 RequiredField('reg_city','Please Enter City') &&
 RequiredField('reg_zip','Please Enter Postcode') &&
 //chkdiv('div_showemailexists','Email Address existed already, Please try with another Email Address')&&
 chkRadioField()
) 
	{	
	document.frmcheckout.action="functions/insert.php";
	//document.frmcheckout.submit();	
	}
    else
    {
     return false;
    }    
}

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_grandtotalamtOriginal').value;
		shippricevat=shipprice*(hdntax/100);
		shipprice=shipprice+shippricevat;
		gtot=parseFloat(shipprice)+parseFloat(gtotincvat);
		
		taxvalnoship=document.getElementById('hdn_vatvalue_original').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:#fff">(this includes <strong>'+parseFloat(taxval).toFixed(2)+'</strong> VAT at <strong>'+hdntax+'%</strong>)</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_grandtotalamtOriginal').value;
		shippricevat=shipprice*(hdntax/100);
		shipprice=shipprice+shippricevat;
		gtot=parseFloat(shipprice)+parseFloat(gtotincvat);
		
		taxvalnoship=document.getElementById('hdn_vatvalue_original').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:#fff">(this includes <strong>'+parseFloat(taxval).toFixed(2)+'</strong> VAT at <strong>'+hdntax+'%</strong>)</span>';
		document.getElementById('hdn_vatvalue').value=parseFloat(taxval).toFixed(2);
		document.getElementById('hdn_ship_id').value=document.getElementById('hidshipid'+id).value
	}

}

//contact us validations By madhavi 05 july 2010

function contactvalid()
{
	if((document.getElementById('Txt_Name').value=="")||(document.getElementById('Txt_Name').value==" "))
	{
		alert("Please Enter  Name");
		document.getElementById('Txt_Name').focus();
		return false;
	}

	if((document.getElementById('Txt_Email').value=="")||(document.getElementById('Txt_Email').value==" "))
	{
		alert("Please Enter  Email");
		document.getElementById('Txt_Email').focus();
		return false;
	}

	if (document.getElementById('Txt_Email').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_Email').value.search(regexp)==-1)
		{
			document.getElementById('Txt_Email').value="";
			alert('Please Enter Valid Email Address');
			document.getElementById('Txt_Email').focus();
			return false;
		}	   
	}


    if((document.getElementById('Txt_Phone').value=="")||(document.getElementById('Txt_Phone').value==" "))
	{
		alert("Please Enter  Telephone");
		document.getElementById('Txt_Phone').focus();
		return false;
	}

	/*if (document.getElementById('telephone').value!="")
	{		  
		regexp=/^\d{3}[- .]?\d{3}[- .]?\d{4}$/;
		if(document.getElementById('telephone').value.search(regexp)==-1)
		{
			document.getElementById('telephone').value="";
			alert('Please Enter Valid Telephone Format');
			document.getElementById('telephone').focus();
			return false;
		}	   
	}*/

	 if((document.getElementById('Txt_Comments').value=="")||(document.getElementById('Txt_Comments').value==" "))
	{
		alert("Please Enter  Comments");
		document.getElementById('Txt_Comments').focus();
		return false;
	}

	return true;

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

}
