// JavaScript Document

function validateForm(){
	myForm = document.getElementById('theform');
	
	if(myForm.userName.value==""){
		alert("Please enter username")
		myForm.userName.focus();
		return false
	}
	if(myForm.userPassword.value==""){
		alert("Please enter password")
		myForm.userPassword.focus();
		return false
	}
	
	return true;
}
function validateForm1(){
	myForm = document.getElementById('theform');
	
	if(myForm.item_no.value==""){
		alert("Please enter product model")
		myForm.item_no.focus();
		return false
	}
	
	
	if(myForm.prod_name.value==""){
		alert("Please enter product name")
		myForm.prod_name.focus();
		return false
	}
	
	
	
	if(myForm.item_no.value==""){
		alert("Please enter item number")
		myForm.item_no.focus();
		return false
	}

	if(myForm.caption.value==""){
		alert("Please enter caption")
		myForm.caption.focus();
		return false
	}


if(myForm.item_width.value==""){
		alert("Please enter item size")
		myForm.item_width.focus();
		return false
	}
	if(myForm.item_height.value==""){
		alert("Please enter item height")
		myForm.item_height.focus();
		return false
	}
	
	if(myForm.retail_price.value==""){
		alert("Please enter retail price")
		myForm.retail_price.focus();
		return false
	}
if(isNaN(myForm.retail_price.value)){
		alert("Please enter valid retail price")
		myForm.retail_price.focus();
		return false
	}

	
	
	
	if(myForm.item_price.value==""){
		alert("Please enter sale price")
		myForm.item_price.focus();
		return false
	}
if(isNaN(myForm.item_price.value)){
		alert("Please enter valid sale price")
		myForm.item_price.focus();
		return false
	}
	if(myForm.file1.value==""){
		alert("Please select an image")
		myForm.file1.focus();
		return false
	}
	if(checkExt2(myForm.file1)==false)
	{
		alert ("You can only upload gif or jpg images !");
		myForm.file1.value="";
		myForm.file1.focus();
		return false;
	}
	
	
	
	
	if(myForm.text_file.value !="" ){
	
	if(checkExt3(myForm.text_file)==false)
	{
		alert ("You can only upload pdf file!");
		myForm.text_file.value="";
		myForm.text_file.focus();
		return false;
	}
	
	
	}
	
	
	if(tinyMCE.get('description').getContent()==""){
		alert("Please enter details")
		//myForm.description.focus();
		return false
	}
	
function checkExt2(txtcrlt)
{
	var filename = txtcrlt.value;
	var filelength = parseInt(filename.length) - 3;
	var fileext = filename.substring(filelength,filelength + 3);

// Check file extenstion
		if ( fileext != "gif" && fileext != "jpg" && fileext != "JPG" && fileext != "GIF")
			return false;
		else
			return true;	
}	



function checkExt3(txtcrlt)
{
	var filename = txtcrlt.value;
	var filelength = parseInt(filename.length) - 3;
	var fileext = filename.substring(filelength,filelength + 3);
// Check file extenstion         fileext == "doc" || fileext == "Doc" || 
		if ( fileext == "pdf" || fileext == "PDF")
			return true;
		else
			return false;	
}	


}	


function validate_resources(){
	
	
	myForm = document.getElementById('theform');
	
	if(myForm.heading.value==""){
		alert("Please enter heading")
		myForm.heading.focus();
		return false;
	}
	/*
	if(myForm.html.value==""){
		alert("Please enter content ");
	//  myForm.html.focus();
		return false;
	}*/
	
	if(tinyMCE.get('html').getContent()=="")
	{
		alert("Please enter content");
		tinyMCE.get('html').focus();
		return false;
	}	


return true;

}	



function validateFormUpdate1(){
	myForm = document.getElementById('theform');
	
	if(myForm.item_no.value==""){
		alert("Please enter product model")
		myForm.item_no.focus();
		return false
	}
	
	if(myForm.prod_name.value==""){
		alert("Please enter product name")
		myForm.prod_name.focus();
		return false
	}
	
	
	if(myForm.caption.value==""){
		alert("Please enter caption")
		myForm.caption.focus();
		return false
	}

	
	if(myForm.file1.value!=""){
		if(checkExt2(myForm.file1)==false)
		{
			alert ("You can only upload gif or jpg images !");
			myForm.file1.value="";
			myForm.file1.focus();
			return false;
		}
	}
	


	if(myForm.item_width.value==""){
		alert("Please enter item size")
		myForm.item_width.focus();
		return false
	}
	

	if(myForm.retail_price.value==""){
		alert("Please enter retail price")
		myForm.retail_price.focus();
		return false
	}
if(isNaN(myForm.retail_price.value)){
		alert("Please enter valid retail price")
		myForm.retail_price.focus();
		return false
	}


	if(myForm.item_price.value==""){
		alert("Please enter sale  price")
		myForm.item_price.focus();
		return false
	}
if(isNaN(myForm.item_price.value)){
		alert("Please enter valid sale  price")
		myForm.item_price.focus();
		return false
	}	



if(myForm.file1.value !="" )
	if(checkExt2(myForm.file1)==false)
	{
		alert ("You can only upload gif or jpg images !");
		myForm.file1.value="";
		myForm.file1.focus();
		return false;
	}


if(myForm.text_file.value !="" ){
	
	if(checkExt3(myForm.text_file)==false)
	{
		alert ("You can only upload pdf file!");
		myForm.text_file.value="";
		myForm.text_file.focus();
		return false;
	}
	
	
	}

if(tinyMCE.get('description').getContent()==""){
		alert("Please enter details")
		//myForm.description.focus();
		return false
	}
	
function checkExt2(txtcrlt)
{
	var filename = txtcrlt.value;
	var filelength = parseInt(filename.length) - 3;
	var fileext = filename.substring(filelength,filelength + 3);

// Check file extenstion
		if ( fileext != "gif" && fileext != "jpg" && fileext != "JPG" && fileext != "GIF")
			return false;
		else
			return true;	
}	

function checkExt3(txtcrlt)
{
	var filename = txtcrlt.value;
	var filelength = parseInt(filename.length) - 3;
	var fileext = filename.substring(filelength,filelength + 3);
// Check file extenstion         fileext == "doc" || fileext == "Doc" || 
		if ( fileext == "pdf" || fileext == "PDF")
			return true;
		else
			return false;	
}	
}
function validateForm2(){
	myForm = document.getElementById('theform');
	
	if(myForm.prod_name.value==""){
		alert("Please enter name")
		myForm.prod_name.focus();
		return false
	}
	if(myForm.file1.value!=""){
		if(checkExt2(myForm.file1)==false)
		{
			alert ("You can only upload gif or jpg images !");
			myForm.file1.value="";
			myForm.file1.focus();
			return false;
		}	
	}
	if(myForm.item_no.value==""){
		alert("Please enter item number")
		myForm.item_no.focus();
		return false
	}
	if(myForm.description.value==""){
		alert("Please enter details")
		myForm.description.focus();
		return false
	}
	
function checkExt2(txtcrlt)
{
	var filename = txtcrlt.value;
	var filelength = parseInt(filename.length) - 3;
	var fileext = filename.substring(filelength,filelength + 3);

// Check file extenstion
		if ( fileext != "gif" && fileext != "jpg" && fileext != "JPG" && fileext != "GIF")
			return false;
		else
			return true;	
}	
}	
function validateForm3(){
	myForm = document.getElementById('theform');
	
	if(myForm.subcat_name.value==""){
		alert("Please enter subcategory title")
		myForm.subcat_name.focus();
		return false
	}
	/*if(myForm.size.value=="" || isNaN(myForm.size.value)){
		alert("Please enter valid size")
		myForm.size.focus();
		return false
	}
	if(myForm.mwp.value=="" || isNaN(myForm.mwp.value)){
		alert("Please enter valid mwp")
		myForm.mwp.focus();
		return false
	}
	if(myForm.fuel_type.value==""){
	alert("Please enter fuel type")
	myForm.fuel_type.focus();
	return false
	}	
	if(myForm.mfd.value==""){
		alert("Please enter manufacturing year ")
		myForm.mfd.focus();
		return false
	}	
	if(myForm.pcondition.value==""){
		alert("Please enter condition")
		myForm.pcondition.focus();
		return false
	}*/
}		
function validateForm4(){
	myForm = document.getElementById('theform');
	
	if(myForm.brand.value==""){
		alert("Please enter brand name")
		myForm.brand.focus();
		return false
	}
	if(myForm.inputsize.value=="" || isNaN(myForm.inputsize.value)){
		alert("Please enter valid size")
		myForm.inputsize.focus();
		return false
	}
	if(myForm.design_temp.value=="" || isNaN(myForm.design_temp.value)){
		alert("Please enter valid design temperature")
		myForm.design_temp.focus();
		return false
	}
	if(myForm.fuel_type.value==""){
	alert("Please enter fuel type")
	myForm.fuel_type.focus();
	return false
	}
	if(myForm.psi.value==""){
		alert("Please enter valid value for PSI")
		myForm.psi.focus();
		return false
	}
	if(myForm.mfyear.value==""){
		alert("Please enter manufacturing year ")
		myForm.mfyear.focus();
		return false
	}	
	
}	
function validateForm5(){
	theForm = document.getElementById('theform');
	var re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	  if(theForm.userName.value == '')
	  {
		  alert("Please enter username");
		  theForm.userName.focus();
		  return false;
	  }
	
	  if(theForm.userEmail.value == '')
	  {
		  alert("Please enter an email");
		  theForm.userEmail.focus();
		  return false;
	  }
	 
	 if(theForm.userEmail.value != '')
	  
		if(!theForm.userEmail.value.match(re))
		{
			alert("Please enter correct email");
			theForm.userEmail.focus();
			return false;
		}
	 			
  	if(theForm.userPassword.value=="")
	{
		alert("Please enter password");
		theForm.userPassword.focus();
		return false;
	}	
  	if(theForm.userPassword.value != "")
	  {
		if(theForm.userPassword.value.length<6 || theForm.userPassword.value.length > 15 ){
		alert("Password length should be between 6 and 15 characters");
			theForm.userPassword.focus();
			return false;
		}
	  }
	
	  if(theForm.userPassword.value != theForm.userPassword1.value )
	  {
		alert("Your password don't match");
		theForm.userPassword1.focus();
		 return false;
	  }
			
  return true;
}

function checkMail(obj)
{
	if(obj.userEmail.value=="")
		{
			alert("please type Email Address !");	
			obj.userEmail.focus();
			return false;
		}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.userEmail.value)))
		{	
			alert("Please enter a valid email address");
			obj.userEmail.focus();
			return false;
		}
		
	return true;
}



function maxLen(obj)
{
	if(obj.value.length < 5)
		{
			alert("please type more than five characters !");	
			obj.focus();
			return false;
		}
	return true;
}	

function validate()
{
	theForm = document.getElementById('theform');
	
	if(theForm.userPassword1.value=="")
	{
		alert ("Please enter old password!");
		theForm.userPassword1.focus();
		return false;
	}	
	if(theForm.userPassword.value=="")
	{
		alert ("Please enter new password!");
		theForm.userPassword.focus();
		return false;
	}
	 /*if(myform.newpass.value != "")
	  {
		if(myform.newpass.value.length<6 || myform.newpass.value.length > 15 ){
		alert("Password length should be between 6 and 15 characters");
			myform.newpass.focus();
			return false;
		}
	  }*/
	  if(theForm.userPassword.value.length<6 || theForm.userPassword.value.length > 15 ){
		alert("Password length should be between 6 and 15 characters");
			theForm.userPassword.focus();
			return false;
		}
	 if(theForm.userPassword2.value=="")
	{
		alert ("Please retype new password!");
		theForm.userPassword2.focus();
		return false;
	}
	
		if(theForm.userPassword2.value.length<6 || theForm.userPassword2.value.length > 15 ){
		alert("Password length should be between 6 and 15 characters");
			theForm.userPassword2.focus();
			return false;
		}
	   	
	if(theForm.userPassword.value!=theForm.userPassword2.value)
	{
		alert ("Your passwords don't match!");
		theForm.userPassword2.focus();
		return false;
	}
	//myform.submit();
	//return true;
}	
	function checkExt(txtcrlt)
	{
		var filename = txtcrlt.value;
		
		fileext =  filename.split('.').pop();
		
	// Check file extenstion
			if (fileext != "gif" && fileext != "jpg" && fileext != "jpeg" && fileext != "bmp" && fileext != "png" && fileext != "GIF" && fileext != "JPG" && fileext != "JPEG" && fileext != "BMP" && fileext != "PNG")
				return false;
			else
				return true;
		
	}		

function validateForm6(){
	theForm = document.getElementById('form1');
	var re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	if(theForm.first_name.value == '')
	  {
		  alert("Please enter first name");
		  theForm.first_name.focus();
		  return false;
	  }
	  if(theForm.last_name.value == '')
	  {
		  alert("Please enter last name");
		  theForm.last_name.focus();
		  return false;
	  }
	  if(theForm.address1.value == '')
	  {
		  alert("Please enter address");
		  theForm.address1.focus();
		  return false;
	  }
	
	if ((theForm.zip.value==null)||(theForm.zip.value=="")){
		alert("Please enter zip code")
		theForm.zip.focus()
		return false
	}

	if (validatezipcode(theForm.zip.value)==false){
			theForm.zip.focus()
			return false
		}

	/*
	
	
	if(theForm.zip.value == '')
	  {
		  alert("Please enter zip code");
		  theForm.zip.focus();
		  return false;
	  }
	  
	  if(isNaN(theForm.zip.value))
	  {
		  alert("Please enter valid zip code");
		  theForm.zip.focus();
		  return false;
	  }	
	  */
	  if(theForm.city.value == '')
	  {
		  alert("Please enter city name");
		  theForm.city.focus();
		  return false;
	  }
	   if(theForm.state.options[theForm.state.selectedIndex].value  == -1)
	  {
		  alert("Please select a state");
		  theForm.state.focus();
		  return false;
	  }
	 
	 
	 if ((theForm.phone.value==null)||(theForm.phone.value=="")){
		alert("Please enter phone no")
		theForm.phone.focus()

		return false
	}

	if (phonevalidate(theForm.phone.value)==false){
			theForm.phone.focus()
			return false
		}
	  
	  /*
	  if(theForm.phone.value == '')
	  {
		  alert("Please enter phone no");
		  theForm.phone.focus();
		  return false;
	  }
	  
	  */
	  if(theForm.email.value == '')
	  {
		  alert("Please enter email address");
		  theForm.email.focus();
		  return false;
	  }
	  if(!theForm.email.value.match(re))
	{
		alert("Please enter correct email address");
		theForm.email.focus();
		return false;
	}
	  if(theForm.shipfirst_name.value == '')
	  {
		  alert("Please enter shipping first name");
		  theForm.shipfirst_name.focus();
		  return false;
	  }
	   if(theForm.shiplast_name.value == '')
	  {
		  alert("Please enter shipping last name");
		  theForm.shiplast_name.focus();
		  return false;
	  }
	   if(theForm.ship_address1.value == '')
	  {
		  alert("Please enter shipping address");
		  theForm.ship_address1.focus();
		  return false;
	  }
	   if(theForm.ship_zip.value == '')
	  {
		  alert("Please enter shipping zip code");
		  theForm.ship_zip.focus();
		  return false;
	  }
	  if(isNaN(theForm.ship_zip.value))
	  {
		  alert("Please enter valid zip code");
		  theForm.ship_zip.focus();
		  return false;
	  }		  
	   if(theForm.ship_city.value == '')
	  {
		  alert("Please enter shipping city");
		  theForm.ship_city.focus();
		  return false;
	  }
	  if(theForm.ship_state.options[theForm.ship_state.selectedIndex].value == -1)
	  {
		  alert("Please select a shipping state");
		  theForm.ship_state.focus();
		  return false;
	  }
	/*
	  if(theForm.shipmethod.options[theForm.shipmethod.selectedIndex].value == -1)
	  {
		  alert("Please select shipping method");
		  theForm.shipmethod.focus();
		  return false;
	  }
	
*/
	theForm.submit();
}
function validateForm7(){
	theForm = document.getElementById('form1');
	if(theForm.method_name.value=="")
	{
		alert("Please enter shipping method!");
		theForm.method_name.focus();
		return false;
	}
	if(theForm.method_price.value=="")
	{
		alert("Please enter shipping charges.");
		theForm.method_price.focus();
		return false;
	}	
	
	if(! /^[-+]?[0-9]+(\.[0-9]+)?$/.test(theForm.method_price.value))
	{
		alert("Invalid Value, please enter numeric only in the charges field.");
		theForm.method_price.focus();
		return false;
	} 
 //return true;
	
}
function sameValues_admin(myform){
	if(myform.transfer.checked){
		myform.shipFirstName.value=myform.billFirstName.value;
		myform.shipLastName.value=myform.billLastName.value;
		myform.shipAddress1.value=myform.billAddress1.value;
		myform.shipAddress2.value=myform.billAddress2.value;
		myform.shipCity.value=myform.bilCity.value;
		myform.shipState.value=myform.billState.value;
		myform.shipZip.value=myform.billZip.value;
		myform.ship_Country.value=myform.country.value;
	} else {
		myform.shipFirstName.value='';
		myform.shipLastName.value='';
		myform.shipAddress1.value='';
		myform.shipAddress2.value='';
		myform.shipCity.value='';
		myform.shipState.value==-1;
		//myform.shipZip.value=-1;
		myform.shipZip.value="";
		
		myform.ship_Country.value=-1;
	}
	
}

function sameValues(myform){
	if(myform.transfer.checked){
		myform.shipfirst_name.value=myform.first_name.value;
		myform.shiplast_name.value=myform.last_name.value;
		myform.ship_address1.value=myform.address1.value;
		myform.ship_address2.value=myform.address2.value;
		myform.ship_zip.value=myform.zip.value;
		myform.ship_city.value=myform.city.value;
		myform.ship_state.value=myform.state.value;
		myform.ship_country.value=myform.country.value;
	} else {
		myform.shipfirst_name.value='';
		myform.shiplast_name.value='';
		myform.ship_address1.value='';
		myform.ship_address2.value='';
		myform.ship_zip.value='';
		myform.ship_city.value='';
		myform.ship_state.value=-1;
		myform.ship_country.value='us';
	}
	
}


function creditCardCheck(){
	
		theForm = document.getElementById('form1');
			if(theForm.cc_type.selectedIndex == 0)
			{
				alert("Please Select Card Type");
				theForm.cc_type.focus();
				return false;
			}
			if(theForm.cc_no.value=="")
			{
				alert("Please Enter Card Number");
				theForm.cc_no.focus();
				return false;
			}
			if(isNaN(theForm.cc_no.value))
			{
				alert("Please Enter A Valid Card Number");
				theForm.cc_no.focus();
				return false;
			}
			if(theForm.cvv.value=="")
			{
				alert("Please Enter CVV Number");
				theForm.cvv.focus();
				return false;
			}
			if(theForm.ccmonth.value == "")
			{
				alert("Please Enter Card Expiration Month");
				theForm.ccmonth.focus();
				return false;
			}
			if(theForm.ccyear.value == "")
			{
				alert("Please Enter Card Expiration Year");
				theForm.ccyear.focus();
				return false;
			}
		if (validatecardfunc() == false){
			
			alert ("Credit card not valid!");
			return false;
		}

	theForm.submit();
}

function validateForm8(){
	theForm = document.getElementById('form1');
	var re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	
	if(theForm.Country.value == '')
	  {
		  alert("Please enter country name");
		  theForm.Country.focus();
		  return false;
	  }
	  /*
	  if(theForm.Company.value == '')
	  {
		  alert("Please enter company name");
		  theForm.Company.focus();
		  return false;
	  }*/
	  if(theForm.Your_Name.value == '')
	  {
		  alert("Please enter name");
		  theForm.Your_Name.focus();
		  return false;
	  }
	  if(theForm.Address.value == '')
	  {
		  alert("Please enter address");
		  theForm.Address.focus();
		  return false;
	  }
	  
	  if(theForm.City.value == '')
	  {
		  alert("Please enter city name");
		  theForm.City.focus();
		  return false;
	  }
	
	  if(theForm.State.value == '')
	  {
		  alert("Please enter state");
		  theForm.State.focus();
		  return false;
	  }
	  if(theForm.Zip_Code.value == '')
	  {
		  alert("Please enter zip code");
		  theForm.Zip_Code.focus();
		  return false;
	  }

	  if(isNaN(theForm.Zip_Code.value))
	  {
		  alert("Please enter valid zip code");
		  theForm.Zip_Code.focus();
		  return false;
	  }

	  if(theForm.Phone_Number.value == '')
	  {
		  alert("Please enter phone number");
		  theForm.Phone_Number.focus();
		  return false;
	  }
	 
	 if (phonevalidate(theForm.Phone_Number.value)==false){
			theForm.Phone_Number.focus()
			return false
		}
	if(theForm.Email.value == '')
	{
	alert("Please enter the Email Address.");
	theForm.Email.focus();
	return false;
	}
	
	  if(!theForm.Email.value.match(re))
	{
		alert("Please enter correct email address");
		theForm.Email.focus();
		return false;
	}	
	
	if(theForm.Retypt_Email_Address.value == '')
	{
	alert("Please enter the Retype Email Address.");
	theForm.Retypt_Email_Address.focus();
	return false;
	}	

	if(!theForm.Retypt_Email_Address.value.match(re))
	{
		alert("Please enter correct retype email address");
		theForm.Retypt_Email_Address.focus();
		return false;
	}
	
	
	if(theForm.Retypt_Email_Address.value != theForm.Email.value)
	{
		alert("Your email address and retype email address does not match");
		theForm.Retypt_Email_Address.focus();
		return false;
	}
	
	
	  if(theForm.Hear_About_us.value == '')
	  {
		  alert("Please enter from where you here about us");
		  theForm.Hear_About_us.focus();
		  return false;
	  }
  
	  if ((theForm.code.value==null)||(theForm.code.value=="")){
		alert("Please type the security code?")
		theForm.code.focus()
		return false
	}
	
	  
	 
	/*
	if(theForm.Subscribe_to_Newsletters.checked)
	{
		
	$.ajax({
   type: "POST",
   url: "http://208.109.88.138/save_email.php",
   data: "subscribe=Yes&email=" + theForm.Email.value,
   success: function(productprice){ }
 });
	  }*/
	theForm.submit();
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}



function validateRequestForm2()
{

	var name=document.myform.name
	var address=document.myform.address
	var phone=document.myform.phone
	var hearus=document.myform.hearus
	
	
	var city=document.myform.city
	var state=document.myform.state
	var zip=document.myform.zip
	var email=document.myform.email
	var reemail=document.myform.reemail
	var code=document.myform.code
	var Subscribe_to_Newsletters=document.myform.Subscribe_to_Newsletters
	
	
	
	if ((name.value==null)||(name.value=="")){
		alert("Please enter your name")
		name.focus()
		return false
	}
	
	if ((address.value==null)||(address.value=="")){
		alert("Please enter address")
		address.focus()
		return false
	}

	if ((city.value==null)||(city.value=="")){
		alert("Please enter city name")
		city.focus()
		return false
	}

	if ((state.value==null)||(state.value=="")){
		alert("Please enter state name")
		state.focus()
		return false
	}

	if ((zip.value==null)||(zip.value=="")){
		alert("Please enter zip code")
		zip.focus()
		return false
	}

	if (isNaN(zip.value)){
		alert("Please enter valid zip code!")
		zip.focus()
		return false
	}

	/*if (validatezipcode(zip.value)==false){
			zip.focus()
			return false
		}*/


	if ((phone.value==null)||(phone.value=="")){
		alert("Please enter phone number")
		phone.focus()

		return false
	}

	
	if (phonevalidate(phone.value)==false){
			phone.focus()
			return false
		}


	if ((email.value==null)||(email.value=="")){
		alert("Please enter email")
		email.focus()
		return false
	}
	
	if (echeck(email.value)==false){
		email.focus()
		return false
	}
	
	if ((reemail.value==null)||(reemail.value=="")){
		alert("Please retype email address")
		reemail.focus()
		return false
	}
	
	if (echeck(reemail.value)==false){
		reemail.focus()
		return false
	}

	if(email.value!=reemail.value)
	{
		alert("Email and re-type email does not match")
		reemail.focus()
		return false
	}

	if ((hearus.value==null)||(hearus.value=="")){
		alert("Please enter Where did you hear about us?")
		hearus.focus()
		return false
	}
	
	if ((code.value==null)||(code.value=="")){
		alert("Please type the security code?")
		code.focus()
		return false
	}
	
	//return true
	
	/*
	if(Subscribe_to_Newsletters.checked)
	{
		
	$.ajax({
   type: "POST",
   url: "http://208.109.88.138/save_email.php",
   data: "subscribe=Yes&email=" + email.value,
   success: function(productprice){ }
 });
	}*/
	
	document.myform.submit();
}




function validatecardfunc() {
	
validcard = false;
var num = /^[0-9]/;
theForm = document.getElementById('form1');
ret = theForm.cc_no.value;
//alert(ret);
item1 = theForm.cc_type.selectedIndex;
result =theForm.cc_type.options[item1].value;
//alert(result);
if (result == "MasterCard") {
	if (ret.length == 16 && ret.match(num))
	validcard = true;
	if ((ret.substring (0, 2) >= "51") &&
	(ret.substring (0, 2) <= "55"))
	validcard = true;
	else
	validcard = false;
}
if (result == "Visa") {
	if (((ret.length == 16) || (ret.length ==13)) && ret.match(num))
	validcard = true;
	if (ret.substring (0, 1) != "4")
	validcard = false;
}
if (result == "Amex") {
	if (ret.length == 15 && ret.match(num))
	validcard = true;
	if ((ret.substring (0, 2) != "34") &&
	(ret.substring (0, 2) != "37"))
	validcard = false;
}
if (result == "Discover") {
	if (ret.length == 16 && ret.match(num))
	validcard = true;
	if (ret.substring (0, 4) != "6011")
	validcard = false;
}
return (validcard);
}

function validate_addorder_form(myform)
{
	
	
	if(myform.billFirstName.value == '')
	{
	alert("Please enter billing first name");
	myform.billFirstName.focus();
     return false;
	}
	
	if(myform.billLastName.value == '')
	{
	alert("Please enter billing last name");
	myform.billLastName.focus();
     return false;
	}
	
	if(myform.billAddress1.value == '')
	{
	alert("Please enter billing address 1");
	myform.billAddress1.focus();
     return false;
	}
	
	if(myform.bilCity.value == '')
	{
	alert("Please enter billing city ");
	myform.bilCity.focus();
     return false;
	}
	
	
	
	if(myform.billState.value == '-1')
	{
	alert("Please select billing state");
	myform.billState.focus();
     return false;
	}
	
	if(myform.billZip.value == '')
	{
	alert("Please enter billing zip code");
	myform.billZip.focus();
     return false;
	}
	if(isNaN(myform.billZip.value))
	{
	alert("Please enter valid billing zip code");
	myform.billZip.focus();
     return false;
	}	
	

  if(myform.billPhone.value == '')
	  {
		  alert("Please enter phone number");
		  myform.billPhone.focus();
		  return false;
	  }
	 
	 if (phonevalidate(myform.billPhone.value)==false){
			myform.billPhone.focus()
			return false
		}
	


	if(myform.country.value == '-1')
	{
	alert("Please select billing country");
	myform.country.focus();
     return false;
	}


	if(myform.email.value == '')
	{
	alert("Please enter e-mail address");
	myform.email.focus();
     return false;
	}

	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myform.email.value)))
	{
	alert("Please enter valid e-mail address");
	myform.email.focus();
     return false;
	}
	

	if(myform.shipFirstName.value == '')
	{
	alert("Please enter shipping first name");
	myform.shipFirstName.focus();
     return false;
	}
	
	if(myform.shipLastName.value == '')
	{
	alert("Please enter shipping last name");
	myform.shipLastName.focus();
     return false;
	}
	
	if(myform.shipAddress1.value == '')
	{
	alert("Please enter shipping address 1");
	myform.shipAddress1.focus();
     return false;
	}
	
	if(myform.shipCity.value == '')
	{
	alert("Please enter shipping city ");
	myform.shipCity.focus();
     return false;
	}
	
	
	
	if(myform.shipState.value == '-1')
	{
	alert("Please select shipping state");
	myform.shipState.focus();
     return false;
	}
	
	if(myform.shipZip.value == '')
	{
	alert("Please enter shipping zip code!");
	myform.shipZip.focus();
     return false;
	}
	
	if(isNaN(myform.shipZip.value))
	{
	alert("Please enter valid shipping zip code!");
	myform.shipZip.focus();
     return false;
	}	
	

	if(myform.ship_Country.value == '-1')
	{
	alert("Please select shipping country");
	myform.ship_Country.focus();
     return false;
	}



if(myform.paypal_transaction.checked)
	{// check only if cc_type is not -1	
	if(myform.cc_type.value == '-1')
	{
	alert("Please enter credit card type");
	myform.cc_type.focus();
     return false;
	}	
	
	if(myform.cardNumber.value == '')
	{
	alert("Please enter credit card number");
	myform.cardNumber.focus();
     return false;
	}
	
	if(myform.cvv.value == '')
	{
	alert("Please enter cvv ");
	myform.cvv.focus();
     return false;
	}
	
if(myform.month.value == '-1')
	{
	alert("Please select month");
	myform.month.focus();
     return false;
	}

if(myform.year.value == '-1')
	{
	alert("Please select year");
	myform.year.focus();
     return false;
	}
}
	

if(myform.subtotal0.value == '0' || myform.subtotal0.value == 'NaN')
	{
	alert("Please select at least one product");
	
	
     return false;
	}

/*
if(myform.note.value == '')
	{
	alert("Please enter  note");
	
	myform.note.focus();
	
	
     return false;
	}*/



//====================================



	for(x=0; x<10; x++ )
		{
		
			var newprice="price" +x+""
			var newqty="qty" +x+""
			
			var tempprice = document.getElementById(newprice).value
			var tempqty = document.getElementById(newqty).value
			
			
	
		if(tempprice!="")
		{
				
				if (validateCurrenty(tempprice)==false)
				{
					document.getElementById(newprice).focus();
					return false;
				}
				
				if(tempqty=="")
				{
					alert("Please enter product qty")	;
					document.getElementById(newqty).focus();
					return false;
				}
				if(validateQty(tempqty)==false)
				{
					document.getElementById(newqty).focus();
					return false;
				}
				
				if (tempqty=="0" || tempqty=="00" || tempqty=="000" || tempqty=="0000")
				{
					alert("Please enter valid quantity");
					document.getElementById(newqty).focus();
					return false
				}				
				
					
		
		}

	}//eend of for loop.
	

//==========================
/*

	if(myform.shippingmethod.value == '-1')
	{
	alert("Please select shipping method");
	myform.shippingmethod.focus();
     return false;
	}*/

return true;
	 
	
}





<!-- This script is based on the javascript code of Roman Feldblum (web.developer@programmer.net) -->
<!-- Original script : http://javascript.internet.com/forms/format-phone-number.html -->
<!-- Original script is revised by Eralper Yilmaz (http://www.eralper.com) -->
<!-- Revised script : http://www.kodyaz.com -->
<!-- Format : "(123) 456-7890" -->

var zChar = new Array(' ', '(', ')', '-', '.');
var maxphonelength = 14;
var phonevalue1;
var cursorposition;

function ParseForNumber1(object){
  phonevalue1 = ParseChar(object.value, zChar);
}

function backspacerUP(object,e) {
  if(e){
    e = e
  } else {
    e = window.event
  }
  if(e.which){
    var keycode = e.which
  } else {
    var keycode = e.keyCode
  }

  ParseForNumber1(object)

  if(keycode >= 48){
    ValidatePhone(object)
  }
}

function backspacerDOWN(object,e) {
  if(e){
    e = e
  } else {
    e = window.event
  }
  if(e.which){
    var keycode = e.which
  } else {
    var keycode = e.keyCode
  }
  ParseForNumber2(object)
}

function GetCursorPosition(){

  var t1 = phonevalue1;
  var t2 = phonevalue2;
  var bool = false
  for (i=0; i<t1.length; i++)
  {
    if (t1.substring(i,1) != t2.substring(i,1)) {
      if(!bool) {
        cursorposition=i
        window.status=cursorposition
        bool=true
      }
    }
  }
}

function ValidatePhone(object){

  var p = phonevalue1

  p = p.replace(/[^\d]*/gi,"")

  if (p.length < 3) {
    object.value=p
  } else if(p.length==3){
    pp=p;
    d4=p.indexOf('(')
    d5=p.indexOf(')')
    if(d4==-1){
      pp="("+pp;
    }
    if(d5==-1){
      pp=pp+")";
    }
    object.value = pp;
  } else if(p.length>3 && p.length < 7){
    p ="(" + p;
    l30=p.length;
    p30=p.substring(0,4);
    p30=p30+") "

    p31=p.substring(4,l30);
    pp=p30+p31;

    object.value = pp;

  } else if(p.length >= 7){
    p ="(" + p;
    l30=p.length;
    p30=p.substring(0,4);
    p30=p30+") "

    p31=p.substring(4,l30);
    pp=p30+p31;

    l40 = pp.length;
    p40 = pp.substring(0,9);
    p40 = p40 + "-"

    p41 = pp.substring(9,l40);
    ppp = p40 + p41;

    object.value = ppp.substring(0, maxphonelength);
  }

  GetCursorPosition()

  if(cursorposition >= 0){
    if (cursorposition == 0) {
      cursorposition = 2
    } else if (cursorposition <= 2) {
      cursorposition = cursorposition + 1
    } else if (cursorposition <= 4) {
      cursorposition = cursorposition + 3
    } else if (cursorposition == 5) {
      cursorposition = cursorposition + 3
    } else if (cursorposition == 6) {
      cursorposition = cursorposition + 3
    } else if (cursorposition == 7) {
      cursorposition = cursorposition + 4
    } else if (cursorposition == 8) {
      cursorposition = cursorposition + 4
      e1=object.value.indexOf(')')
      e2=object.value.indexOf('-')
      if (e1>-1 && e2>-1){
        if (e2-e1 == 4) {
          cursorposition = cursorposition - 1
        }
      }
    } else if (cursorposition == 9) {
      cursorposition = cursorposition + 4
    } else if (cursorposition < 11) {
      cursorposition = cursorposition + 3
    } else if (cursorposition == 11) {
      cursorposition = cursorposition + 1
    } else if (cursorposition == 12) {
      cursorposition = cursorposition + 1
    } else if (cursorposition >= 13) {
      cursorposition = cursorposition
    }

    var txtRange = object.createTextRange();
    txtRange.moveStart( "character", cursorposition);
    txtRange.moveEnd( "character", cursorposition - object.value.length);
    txtRange.select();
  }

}

function ParseChar(sStr, sChar)
{

  if (sChar.length == null)
  {
    zChar = new Array(sChar);
  }
    else zChar = sChar;

  for (i=0; i<zChar.length; i++)
  {
    sNewStr = "";

    var iStart = 0;
    var iEnd = sStr.indexOf(sChar[i]);

    while (iEnd != -1)
    {
      sNewStr += sStr.substring(iStart, iEnd);
      iStart = iEnd + 1;
      iEnd = sStr.indexOf(sChar[i], iStart);
    }
    sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);

    sStr = sNewStr;
  }

  return sNewStr;
}



function validatezipcode(zipcode)
{

	var no="0123456789"
	var temp

	if(	zipcode.length<5)
	{
		alert("Please enter valid zip code");
		return false;														
	}

	for (var i=0;i<zipcode.length;i++)
	{
	   temp=zipcode.substring(i,i+1)
		if (no.indexOf(temp)==-1)
		{
			alert("Please enter valid zip code");
			return false;
		}
	}
	return true;

	
}

function phonevalidate(phonenumber)
{
	
	
	var vph="()0123456789-"
	var no="0123456789"
	var temp


	for (var i=0;i<phonenumber.length;i++)
	{
	   temp=phonenumber.substring(i,i+1)
		if (vph.indexOf(temp)==-1)
		{
			alert("Please enter phone no, like 999-999-9999 or (999)-999-9999");
			return false;
		}
	}

	

	if(	phonenumber.length<12)
	{
		alert("Please enter phone no, like 999-999-9999 or (999)-999-9999");
		return false;														
	}

	
	

//	if(phonenumber.substring(0,1)=="("
	
	
	/*
	if(phonenumber.substring(0,1)=="-" || phonenumber.substring(1,2)=="-" || phonenumber.substring(2,3)=="-" || phonenumber.substring(4,5)=="-" || phonenumber.substring(5,6)=="-"  || phonenumber.substring(6,7)=="-" || phonenumber.substring(8,9)=="-" || phonenumber.substring(9,10)=="-" || phonenumber.substring(10,11)=="-" || phonenumber.substring(11,12)=="-" || phonenumber.substring(12,12)=="-")
	{
		alert("Please enter phone number, like 999-999-9999");
		return false;
	}
	*/
	// To check either phone has all "0".
	if(phonenumber.substring(0,1)==0 && phonenumber.substring(1,2)==0 && phonenumber.substring(2,3)==0  && phonenumber.substring(4,5)==0 && phonenumber.substring(5,6)==0  && phonenumber.substring(6,7)==0  && phonenumber.substring(8,9)==0 && phonenumber.substring(9,10)==0 && phonenumber.substring(10,11)==0 && phonenumber.substring(11,12)==0)
	{
		alert("Please enter valid phone no, not all zero's");
		return false;
	}
	//To check,if 4th and 8th positions have "-".
	if (phonenumber.substring(0,1)=="(")
	{
		if(phonenumber.substring(0,1)!="("|| phonenumber.substring(4,5)!=")" || phonenumber.substring(8,9)!="-")
		{
			alert("Please enter phone no, like 999-999-9999 or (999)-999-9999");
			return false;
		}
	
		if(	phonenumber.length!=13)
		{
			alert("Please enter phone no, like 999-999-9999 or (999)-999-9999");
			return false;														
		}

	
	}
	else
	{
		if(phonenumber.substring(3,4)!="-"|| phonenumber.substring(7,8)!="-")
		{
			alert("Please enter phone no, like 999-999-9999 or (999)-999-9999");
			return false;
		}
		if(	phonenumber.length!=12)
		{
			alert("Please enter phone no, like 999-999-9999 or (999)-999-9999");
			return false;														
		}

	}
	

	return true;

}


function validatebuynowform(productId,myPath)
{
	
	
	
	myForm = document.getElementById('buynowform');
	
	
		    var no="0123456789"
	        var txt="0123456789"
	      var temp
          var tempVal = document.getElementById('qty'+productId).value;
			var tempID = document.getElementById('qty'+productId).id;
		
		
		if(tempVal=="")
			{
				if(tempID.indexOf("~")==-1)
				{
					alert("Please enter quantity");
					document.getElementById('qty'+productId).focus();
					return false;
				}
			}
			
			if(document.getElementById('qty'+productId).value=="0" || document.getElementById('qty'+productId).value=="00")  // To get the value of control.
			{
				alert("Please enter valid qty ")
				document.getElementById('qty'+productId).focus();
				return false;
			}

			if(tempVal!="0")
			{
				
				
				if(tempID.indexOf("~")==-1)
				{
					for (var i=0;i<document.getElementById('qty'+productId).value.length;i++)
						{
							temp=document.getElementById('qty'+productId).value.substring(i,i+1)
								if (txt.indexOf(temp)==-1)
								{
									alert("Please enter valid quantity, number only")
									document.getElementById('qty'+productId).focus();
									return false;
								}
						}
				}
			}
	
	
	document.getElementById('qty').value = tempVal;
  

  myForm.action= myPath + 'shopping_cart.php?product_id=' + productId+'&action=add';
  myForm.submit();
  

//return true;
}



function validQuanity()
{
	
	var no="0123456789"
	var txt="0123456789"
	var temp
	var frmLen = document.form1.length      // To get the length of all controls in the form.
	
	for(x=0;x<frmLen;x++)
	{
	
			var tempVal = document.form1.elements[x].value
			var tempID = document.form1.elements[x].id
			if(tempVal=="")
			{
				if(tempID.indexOf("~")==-1)
				{
					alert("Please enter quantity");
					document.form1.elements[x].focus();
					return false;
				}
			}
			
			if(document.form1.elements[x].value=="0" || document.form1.elements[x].value=="00")  // To get the value of control.
			{
				alert("Please enter valid qty ")
				document.form1.elements[x].focus();
				return false;
			}

			if(tempVal!="0")
			{
				if(tempID.indexOf("~")==-1)
				{
					for (var i=0;i<document.form1.elements[x].value.length;i++)
						{
							temp=document.form1.elements[x].value.substring(i,i+1)
								if (txt.indexOf(temp)==-1)
								{
									alert("Please enter valid quantity , number only")
									document.form1.elements[x].focus();
									return false;
								}
						}
				}
			}
	}
	return true;
}


function validateCurrenty(currencty)
{
	var vph="0123456789"
	var no="0123456789"
	var temp
	var vnumber="0123456789";
	var vcurrency="0123456789.";
	
	
	for (var i=0;i<currencty.length;i++)
	{
		temp=currencty.substring(i,i+1)
		if (vcurrency.indexOf(temp)==-1)
		{
			alert("Please enter valid unit price like 12.50 or 10")
			return false;
		}
	}
			val1 = currencty;
			if(currencty=="." || val1.substring(0,1)==".")
			{
				alert("Please enter valid unit price like 12.50 or 10")
				return false;
			}
	
			pLength = currencty.length;
			val1 = currencty;
			if(val1.substring(pLength-1,pLength)==".")
			{
				alert("Please enter valid unit price like 12.50 or 10")
				return false;
			}
			// To check product price has something after "." or not
			for (var ii=0;ii<currencty.length;ii++)
			{
				val1 = currencty;
				if (val1.substring(ii,ii+1)=="."){
					pLength = currencty.length;
					val1 = val1.substring(ii+1,pLength);
					if(val1.length>2){
						alert("Please enter maximum 2 digits after dot");
						return false;
					}
				}
			}

}


function validateQty(qty)
{

	var vph="0123456789";
	var temp
	
	for (var i=0;i<qty.length;i++)
	{
		temp=qty.substring(i,i+1)
		if (vph.indexOf(temp)==-1)
		{
			alert("Please enter valid quantity");
			return false;
		}
	}
	return true;
}



var digitsOnly = /[1234567890]/g;
var floatOnly = /[0-9\.]/g;
var alphaOnly = /[A-Za-z]/g;
function restrictCharacters(myfield, e, restrictionType) {
	if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);
	// if they pressed esc... remove focus from field...
	if (code==27) { this.blur(); return false; }
	// ignore if they are press other keys
	// strange because code: 39 is the down key AND ' key...
	// and DEL also equals .
	if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40) {
		if (character.match(restrictionType)) {
			return true;
		} else {
			return false;
		}
	}
}

