function validate()
{
	if(checkEmailId(document.frm_specialoffer.email.value)==false)
	{
		document.frm_specialoffer.email.value="";
		document.frm_specialoffer.email.focus()
		return false;
	}
	
}

function checkEmailId(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	
	if (lstr==0)
	{
		alert("Please Enter the Email adress")
		return  false
	}
	
	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 login_validate()
{
	if(document.frm_login.userid.value.length==0)
	{
		alert("Please enter Userid");
		document.frm_login.userid.focus();
		return false
	}
	if(!IsString(document.frm_login.userid.value,4))
	{
		alert("Special Characters are not allowed for User Name");
		document.frm_login.userid.value="";
		document.frm_login.userid.focus();
		return false;
	}
	
	if(document.frm_login.password.value.length==0)
	{
		alert("Please Enter Password")
		document.frm_login.password.focus()
		return false
	}
	if(!IsString(document.frm_login.password.value,4))
	{
		alert("Special Characters are not allowed for Password");
		document.frm_login.password.value="";
		document.frm_login.password.focus();
		return false;
	}
}
function register_validate()
{
	if(document.frm_register.username.value.length==0)
	{
		alert("Please Enter User Name")
		document.frm_register.username.focus()
		return false
	}
	if(!IsString(document.frm_register.username.value,4))
	{
		alert("Special Characters are not allowed for Username");
		document.frm_register.username.value="";
		document.frm_register.username.focus();
		return false;
	}
	if(document.frm_register.password.value.length==0)
	{
		alert("Please Enter Password")
		document.frm_register.password.focus()
		return false
	}
	if(!IsString(document.frm_register.password.value,4))
	{
		alert("Special Characters are not allowed for Password");
		document.frm_register.password.value="";
		document.frm_register.password.focus();
		return false;
	}

	if(document.frm_register.confirm_password.value.length==0)
	{
		alert("Please retype the password")
		document.frm_register.confirm_password.focus()
		return false
	}
	if(!IsString(document.frm_register.confirm_password.value,4))
	{
		alert("Special Characters are not allowed for Password");
		document.frm_register.confirm_password.value="";
		document.frm_register.confirm_password.focus();
		return false;
	}
	if(document.frm_register.password.value != document.frm_register.confirm_password.value)
	 {
		 alert("Password and Confirm Password not matching.");
		 document.frm_register.password.value='';
		 document.frm_register.confirm_password.value='';
		 document.frm_register.password.focus();
		 return false;
	 }
	if(document.frm_register.fname.value=="")
	{
		alert("Please Fill the First Name");
		document.frm_register.fname.focus()
		return false;
	}
	if(document.frm_register.lname.value=="")
	{
		alert("Please Fill the Last Name");
		document.frm_register.lname.focus()
		return false;
	}
	if(checkEmailId(document.frm_register.email.value)==false)
	{
		document.frm_register.email.value="";
		document.frm_register.email.focus()
		return false;
	}
	if(document.frm_register.phonenumber.value=="")
	{
		alert("Please Fill the Phonenumber");
		document.frm_register.phonenumber.focus()
		return false;
	}
}

function IsString(param1, param2)
{
	var str;
	str = param1;
    var str1;
    var str2;
    var fValid;
    
    fValid = true;    
    str1 = "A";
    str2 = "Z";
    str3 = "0";
    str4 = "9";
    str5 = " "; 
    str7 = "_";
	str8 = ".";
    
    str  = str.toUpperCase();
	nLen = str.length;
	
	if (param2 == 1)
	{
		for(i=0; i<nLen; ++i)
		{
			if(((str.charCodeAt(i)  < str1.charCodeAt(0)
			 || str.charCodeAt(i) > str2.charCodeAt(0)) 
			 && (str.charCodeAt(i)< str3.charCodeAt(0) 
			 || str.charCodeAt(i) > str4.charCodeAt(0)))
		  	 && str.charCodeAt(i) != str7.charCodeAt(0))
			

		  	{
		  	  fValid = false;
		  	  break;
		  	}
		}
	}
	if(param2 == 2)
	{
		for(i=0; i<nLen; ++i)
		{
			if(((str.charCodeAt(i)  < str1.charCodeAt(0)
			 || str.charCodeAt(i) > str2.charCodeAt(0)) 
			 && (str.charCodeAt(i)< str3.charCodeAt(0) 
			 || str.charCodeAt(i) > str4.charCodeAt(0)))
		  	 && str.charCodeAt(i) != str5.charCodeAt(0)
		  	 && str.charCodeAt(i) != str7.charCodeAt(0))
		  	{
		  	  fValid = false;
		  	  break;
		  	}
		}
	
	}
	if (param2 == 3)
	{
		for(i=0; i<nLen; ++i)
		{
			if((str.charCodeAt(i)  < str1.charCodeAt(0)
				 || str.charCodeAt(i) > str2.charCodeAt(0))
			  	 && str.charCodeAt(i) != str5.charCodeAt(0)
  				 && str.charCodeAt(i) != str8.charCodeAt(0))
			{
				fValid = false;
    	  		break;
			}
		}
	}
	if (param2 == 4)
	{
		for(i=0; i<nLen; ++i)
		{
			if((str.charCodeAt(i)  < str1.charCodeAt(0)
				|| str.charCodeAt(i) > str2.charCodeAt(0)) 
			 && (str.charCodeAt(i)< str3.charCodeAt(0)
				|| str.charCodeAt(i) > str4.charCodeAt(0)))
			{
		  	  fValid = false;
		  	  break;
		  	}
		}
	}
	if (param2 == 5)
	{
		for(i=0; i<nLen; ++i)
		{
			if((str.charCodeAt(i)  < str1.charCodeAt(0)
				|| str.charCodeAt(i) > str2.charCodeAt(0)))
			{
		  	  fValid = false;
		  	  break;
		  	}
		}
	}
	if (param2 == 6)
	{
		for(i=0; i<nLen; ++i)
		{
			if((str.charCodeAt(i)  < str3.charCodeAt(0)
				|| str.charCodeAt(i) > str4.charCodeAt(0)) && str.charCodeAt(i) != str8.charCodeAt(0))
			{
		  	  fValid = false;
		  	  break;
		  	}
		}
	}
	if (param2 == 7)
	{
		for(i=0; i<nLen; ++i)
		{
			if((str.charCodeAt(i)  < str3.charCodeAt(0)
				|| str.charCodeAt(i) > str4.charCodeAt(0)))
			{
		  	  fValid = false;
		  	  break;
		  	}
		}
	}
	
	return fValid;
}
function jsf_add_adress()
{
	window.open("adressbook.php?mode=add","123haistyles","width=300,height=300");
}

function jsf_edit_adress(id)
{
	window.open("adressbook.php?mode=edit&id="+id,"123haistyles","width=300,height=300");
}

function adress_validate()
{
	if(document.frm1.Address1.value=="")
	{
		alert("Please enter the Address");
		document.frm1.Address1.focus();
		return false;
	}
	/*if(document.frm1.Address2.value=="")
	{
		alert("Please enter the Adress");
		document.frm1.Address2.focus();
		return false;
	}*/
	if(document.frm1.City.value=="")
	{
		alert("Please enter the city");
		document.frm1.City.focus();
		return false;
	}
	if(document.frm1.Zip.value=="")
	{
		alert("Please enter the Zip code");
		document.frm1.Zip.focus();
		return false;
	}
	if(IsString(document.frm1.Zip.value,5))
	{
		alert("Special Characters are not allowed for Zip");
		document.frm1.Zip.value="";
		document.frm1.Zip.focus();
		return false;
	}
	if(document.frm1.Country.value=="")
	{
		alert("Please enter the country ");
		document.frm1.Country.focus();
		return false;
	}

}
function close1()
{
	
	window.close();
	window.opener.document.location.reload();
}
function jfs_delete_address(id)
{
	if(confirm("Are you sure you wish to delete?")==true)
	{
		document.location.href="confirmadress.php?mode=delete&id="+id;
	}
	else
	{
		return false;
	}
}
function jsf_address_confirmation()
{
		var count=document.frm_address.tb_count.value;
		if(count==1) {jsf_address_confirmation1();return true;}
		if(document.frm_address.tb_mode.value!="billing")
		{
			/*if(document.frm_address.cb_adress.checked!=true)
			{
				document.frm_address.action="confirmadress.php?mode=billing";
			}*/
			for(i=0;i<=count-1;i++)
			{
				if(document.frm_address.rb[i].checked==true)
				{
					var id=document.frm_address.rb[i].value;
					document.frm_address.tb_shipping_id.value=id;
					document.frm_address.tb_biling_id.value=id;
				}
			}
		}
		if(document.frm_address.tb_mode.value=="billing")
		{
			for(i=0;i<=count-1;i++)
			{

				if(document.frm_address.rb[i].checked==true)
				{
					var id=document.frm_address.rb[i].value;
					document.frm_address.tb_biling_id.value=id;
				}
			}
		}
}

function jsf_address_confirmation1()
{
		var count=document.frm_address.tb_count.value
		if(document.frm_address.tb_mode.value!="billing")
		{
			/*if(document.frm_address.cb_adress.checked!=true)
			{
				document.frm_address.action="confirmadress.php?mode=billing";
			}*/
			for(i=0;i<=count-1;i++)
			{
				if(document.frm_address.rb.checked==true)
				{
					var id=document.frm_address.rb.value;
					document.frm_address.tb_shipping_id.value=id;
					document.frm_address.tb_biling_id.value=id;
				}
			}
		}
		if(document.frm_address.tb_mode.value=="billing")
		{
			for(i=0;i<=count-1;i++)
			{

				if(document.frm_address.rb.checked==true)
				{
					var id=document.frm_address.rb.value;
					document.frm_address.tb_biling_id.value=id;
				}
			}
		}
return true;
}

