/**
 * DHTML email validation script.
 */

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 Validate_email2()
	{
	var emailID2=document.frmRegister.confirmmail
	
	if ((emailID2.value==null)||(emailID2.value==""))
	{
		alert("Please Enter your Email ID")
		emailID2.focus()
		return false
	}
	if (echeck(emailID2.value)==false)
	{
		emailID2.value=""
		emailID2.focus()
		return false
	}
	return true
 }


function Validate_email1(){
				var emailID=document.frmRegister.email
				
				if ((emailID.value==null)||(emailID.value=="")){
					alert("Please Enter your Email ID")
					emailID.focus()
					return false
				}
				if (echeck(emailID.value)==false){
					emailID.value=""
					emailID.focus()
					return false
				}
				return true
			 }
 
 

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
				{   var i;
				    for (i = 0; i < s.length; i++)
				    {   
				        // Check that current character is number.
				        var c = s.charAt(i);
				        if (((c < "0") || (c > "9"))) return false;
				    }
				    // All characters are numbers.
				    return true;
				}
function trim(s)
						{   var i;
						    var returnString = "";
						    // Search through string's characters one by one.
						    // If character is not a whitespace, append to returnString.
						    for (i = 0; i < s.length; i++)
						    {   
						        // Check that current character isn't whitespace.
						        var c = s.charAt(i);
						        if (c != " ") returnString += c;
						    }
						    return returnString;
						}
function stripCharsInBag(s, bag)
					{   var i;
					    var returnString = "";
					    // Search through string's characters one by one.
					    // If character is not in bag, append to returnString.
					    for (i = 0; i < s.length; i++)
					    {   
					        // Check that current character isn't whitespace.
					        var c = s.charAt(i);
					        if (bag.indexOf(c) == -1) returnString += c;
					    }
					    return returnString;
					}

function checkInternationalPhone(strPhone){
					var bracket=3
					strPhone=trim(strPhone)
					if(strPhone.indexOf("+")>1) return false
					if(strPhone.indexOf("-")!=-1)bracket=bracket+1
					if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
					var brchr=strPhone.indexOf("(")
					if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
					if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
					s=stripCharsInBag(strPhone,validWorldPhoneChars);
					return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
					}
					

function ValidateForm_phone1(){
					var Phone1=document.frmRegister.homephone
					
					if ((Phone1.value==null)||(Phone1.value=="")){
						alert("Please Enter your Phone Number")
						Phone1.focus()
						return false
					}
					if (checkInternationalPhone(Phone1.value)==false){
						alert("Please Enter a Valid Phone Number with Area code")
						Phone1.value=""
						Phone1.focus()
						return false
					}
					return true
				 }


function ValidateForm_phone2(){
					var Phone2=document.frmRegister.workphone
					
					if ((Phone2.value==null)||(Phone2.value=="")){
						alert("Please Enter your Phone Number")
						Phone2.focus()
						return false
					}
					if (checkInternationalPhone(Phone2.value)==false){
						alert("Please Enter a Valid Phone Number with Area code")
						Phone2.value=""
						Phone2.focus()
						return false
					}
					return true
				 }

function confirm_pass()
					{
					
					var password=document.frmRegister.password;
					var password1=document.frmRegister.password1;
					
					
					if  (password.value != password1.value)
					{
					alert('Please enter same password')
					password.value="";
					password1.value="";
					password.focus();
					
					}
					
					}
					
					
		function ValidateForm()
{
			txtfirstname= AllTrim(document.frmRegister.txtfirstname.value);
			document.frmRegister.txtfirstname.value =txtfirstname;
			
			txtlastname= AllTrim(document.frmRegister.txtlastname.value);
			document.frmRegister.txtlastname.value =txtlastname;
			
			txtusername= AllTrim(document.frmRegister.txtusername.value);
			document.frmRegister.txtusername.value =txtusername;
			
			
			
			
			
			
			if (txtfirstname=="")
			{
				alert("Please enter first name");
				document.frmRegister .txtfirstname .focus ();
				return false;
			}
			
			if (txtlastname=="")
			{
				alert("Please enter last name");
				document.frmRegister .txtlastname .focus ();
				return false;
			}
			if (txtusername=="")
			{
				alert("Please enter login name");
				document.frmRegister .txtusername .focus ();
				return false;
			}
			
			
								
			
			
			
			
				
password= AllTrim(document.frmRegister.password.value);
			document.frmRegister.password.value =password;

			if (password=="")
			{
				alert("Please enter Password");
				document.frmRegister .password .focus ();
				return false;
			}

			password1= AllTrim(document.frmRegister.password1.value);
			document.frmRegister.password1.value =password1;	
			if (password1=="")
			{
				alert("Please enter confirm password");
				document.frmRegister .password1 .focus ();
				return false;
			}
			if (password1 != "")
{
	 confirm_pass();
}
			
			passwordhint= AllTrim(document.frmRegister.passwordhint.value);
			document.frmRegister.passwordhint.value =passwordhint;	
			if (passwordhint=="")
			{
				alert("Please enter  password hint");
				document.frmRegister .passwordhint .focus ();
				return false;
			}
			
			callinpin= AllTrim(document.frmRegister.callinpin.value);
			document.frmRegister.callinpin.value =callinpin;	
			if (callinpin=="")
			{
				alert("Please enter call in pin");
				document.frmRegister .callinpin .focus ();
				return false;
			}
			
			address1= AllTrim(document.frmRegister.address1.value);
			document.frmRegister.address1.value =address1;
			if (address1=="")
			{
				alert("Please enter address");
				document.frmRegister.address1.focus ();
				return false;
			}
			
			city= AllTrim(document.frmRegister.city.value);
			document.frmRegister.city.value =city;
			
			
			if (city=="")
			{
			 alert("Please selcet  city");
			 document.frmRegister .city.focus ();
			 return false;
			}
			
			if(document.frmRegister.shopper_state.selectedIndex==0)
			{
				alert("Please select state");
				document.frmRegister .shopper_state.focus ();
				return false;
				
				}
				if(document.frmRegister.shopper_country.selectedIndex==0)
			{
				alert("Please select country");
				document.frmRegister .shopper_country.focus ();
				return false;
				
				}
			
			postalcode= AllTrim(document.frmRegister.postalcode.value);
			document.frmRegister.postalcode.value =postalcode;
			if (postalcode=="")
			{
				alert("Please enter postal codee");
				document.frmRegister .postalcode.focus ();
				return false;
			}
			if( isNaN(document.frmRegister.postalcode.value))
	{
	 alert("Please enter number in the \"postalcode\" field.");
	 document.frmRegister.postalcode.focus();
	 return false;
	}
			
			workphone= AllTrim(document.frmRegister.workphone.value);
			document.frmRegister.workphone.value =workphone
			
			if (workphone=="")
			{
				alert("Please enter office phone");
				document.frmRegister.workphone.focus ();
				return false;
			}
			if(workphone!="")
			{
				ValidateForm_phone2();
				
			}
		
		homephone= AllTrim(document.frmRegister.homephone.value);
		document.frmRegister.homephone.value =	homephone;
		if(homephone!="")
			{
				ValidateForm_phone1();
				
			}
			
		if(isNaN(document.frmRegister.workext.value))
		{
			alert("Enter proper value");
			document.frmRegister.workext.focus();
			return false;
			}
		
		if(isNaN(document.frmRegister.mobilephone.value))
		{
			alert("Enter proper value");
			document.frmRegister.mobilephone.focus();
			return false;
		}
				
			if( isNaN(document.frmRegister.fax.value))
	{
	 alert("Please enter number in the \"FAX\" field.");
	 document.frmRegister.fax.focus();
	 return false;
	}
	
			email= AllTrim(document.frmRegister.email.value);
			document.frmRegister.email.value =email
			if (email=="")
			{
				alert("Please enter email");
				document.frmRegister .email.focus ();
				return false;
			}
			if(email != "")
			{
				
				Validate_email1();
			}

			confirmmail= AllTrim(document.frmRegister.confirmmail.value);
			document.frmRegister.confirmmail.value =confirmmail
			if (confirmmail=="")
			{
				alert("Please enter confirm mail ");
				document.frmRegister .confirmmail.focus ();
				return false;
			}
			if(confirmmail != "")
			{
				
				Validate_email12();
			}
			

			

			if(email != confirmmail)
			{
			 alert("Please Confirm the same e-mail ID ");
			 email="";
			 confirmmail="";
			 document.frmRegister .email.focus ();
			 return false;
				
			}

			

				
			
		
			
			





			
						return true;
}


function AllTrim(sStr)
{ 
	while (sStr.substring(0,1) == ' ')
	{
		sStr = sStr.substring(1, sStr.length);
	}
	while (sStr.substring(sStr.length-1, sStr.length) == ' ')
	{
		sStr = sStr.substring(0,sStr.length-1);
	}
	return sStr;
}

			 

