function emailCheck (emailStr)   
{
	emailStr = emailStr.toLowerCase();	
/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("Invalid Email address");
signUpForm.email.focus();
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

var firstChar = user.substr(0,1);
if (firstChar.charCodeAt(0)>47 && firstChar.charCodeAt(0)<58)
{
	alert("Invalid Email address");	
	signUpForm.email.focus();
	return false;
}

        
var vindex=emailStr.indexOf('@');         
if(vindex<0){}
else{
var subvindex=emailStr.substr(0,vindex);
var charpos1 = subvindex.search("[^A-Za-z0-9\._]");           
if(charpos1 >= 0) 
	{ 
	    alert("Invalid Email address");	
		signUpForm.email.focus();
		return false;
	 }//if 

}          


// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++)
{	
	if (user.charCodeAt(i)>127)
	{

		alert("Invalid Email address");		
		signUpForm.email.focus();
		return false;
   }
}
for (i=0; i<domain.length; i++) 
{
	if (domain.charCodeAt(i)>127)
	{
	alert("Invalid Email address");	
	signUpForm.email.focus();
	return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("Invalid Email address");
signUpForm.email.focus();
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null)
{
  // this is an IP address
	for (var i=1;i<5;i++)
		{
		if (IPArray[i]>255)
			{
				alert("Invalid Email address");
				signUpForm.email.focus();
				return false;
			 }
		}
	return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("Invalid Email address");
signUpForm.email.focus();
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("Invalid Email address");
signUpForm.email.focus();
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2){
alert("Invalid Email address");
signUpForm.email.focus();
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

function isPasswordOK(){
	var field_val=signUpForm.password.value.replace(/[ ]/g, "");
	if (field_val.length==0){
		alert('Please type your Password');
		signUpForm.password.focus();
		return false;
		}
	return true;
}

function checkPasswordOK(){	
	var field_val=signUpForm.password.value.replace(/[ ]/g, "");
	var field_val2=signUpForm.password2.value.replace(/[ ]/g, "");

	if (field_val2.length==0 || field_val!=field_val2){
		alert('Your password entries did not match.');
		signUpForm.password2.focus();
		return false;
	}
	return true;
}
function isNameOK(){
	var field_val=signUpForm.name.value.replace(/[ ]/g, "");	
	if (field_val.length==0){
		alert('Please type your Username');
		signUpForm.name.focus();
		return false;
	}
	var firstChar = field_val.substr(0,1);
	if (firstChar.charCodeAt(0)>47 && firstChar.charCodeAt(0)<58){
		alert("Username should start with alphabets only");
		signUpForm.name.focus();
		return false;
	}

	var charpos = signUpForm.name.value.search("[^A-Za-z0-9]"); 
	if(signUpForm.name.value.length > 0 &&  charpos >= 0){ 
	    alert("Username accepts only alpha-numeric characters "); 
		signUpForm.name.focus();
		return false; 
	 }//if    

	return true;
}


function isFirstnameOK(){
	var field_val=signUpForm.fname.value.replace(/[ ]/g, "");	
	if (field_val.length==0){
		alert('Please type your first name');
		signUpForm.fname.focus();
		return false;
	}
	var firstChar = field_val.substr(0,1);
	if (firstChar.charCodeAt(0)>47 && firstChar.charCodeAt(0)<58){
		alert("First name should start with alphabets only");
		signUpForm.fname.focus();
		return false;
	}

	var charpos = signUpForm.fname.value.search("[^A-Za-z0-9\._]"); 
	if(signUpForm.fname.value.length > 0 &&  charpos >= 0){ 
	    alert("First name accepts only alpha-numeric characters "); 
		signUpForm.fname.focus();
		return false; 
	 }//if    

	return true;
}


// chceck lastname is ok
function isLastnameOK(){ 	
	var field_val=signUpForm.lname.value.replace(/[ ]/g, "");		
	if (field_val.length==0){
		alert('Please type your last name');
		signUpForm.lname.focus();
		return false;
		}
	var firstChar = field_val.substr(0,1);
	if (firstChar.charCodeAt(0)>47 && firstChar.charCodeAt(0)<58)
	{
		alert("Last name should start with alphabets only");
		signUpForm.lname.focus();
		return false;
	}

	var charpos = signUpForm.lname.value.search("[^A-Za-z0-9\._]"); 
	if(signUpForm.lname.value.length > 0 &&  charpos >= 0) 
	{ 
	    alert("Last name accepts only alpha-numeric characters"); 
		signUpForm.lname.focus();
		return false; 
	 }//if 
	return true;
}


//check phone no
function isPhone_dayOK(){
	var field_val1=signUpForm.phone1_day.value.replace(/[ ]/g, "");
	var field_val2=signUpForm.phone2_day.value.replace(/[ ]/g, "");
	var field_val3=signUpForm.phone3_day.value.replace(/[ ]/g, "");
	if(field_val1 == "000"){
		alert('Please type your phone Area Code.');
		signUpForm.phone1_day.value=""
		signUpForm.phone1_day.focus();
		return false;
	}
	if(!isInteger(field_val1)){		
		alert("phone Area Code accepts only numbers");
		
		signUpForm.phone1_day.focus();
		return false;
		
	}
	if (field_val2 == "000"){
		alert('Please type your phone prefix.');
		signUpForm.phone2_day.value=""
		signUpForm.phone2_day.focus();
		return false;
	}
	if(!isInteger(field_val2))
	{
		alert("Phone prefix accepts only numbers");		
		
		signUpForm.phone2_day.focus();
		return false;		
	}
	if (field_val3 == "0000"){
		alert('Please type your phone number.');
		signUpForm.phone3_day.value=""
		signUpForm.phone3_day.focus();
		return false;
	}
	if(!isInteger(field_val3)){
		alert("Phone number accepts only numbers");				
		
		signUpForm.phone3_day.focus();
		return false;		
	}
	if (field_val1.length<3){
		alert('Please type your phone Area Code.');
		
		signUpForm.phone1_day.focus();
		return false;
	}
	if (field_val2.length<3){
		alert('Please type your phone prefix.');
		
		signUpForm.phone2_day.focus();
		return false;
	}
	if (field_val3.length<4){
		alert('Please type your phone number.');
		
		signUpForm.phone3_day.focus();
		return false;
	}
return true;
}


//check captcha is ok
function isCaptchaOK(){
	var field_val=signUpForm.captcha.value.replace(/[ ]/g, "");
	if (field_val.length<5){
		alert('Please type your code shown below.');
		signUpForm.captcha.focus();		
		return false;
	}	
	return true;
}


function isTermsOk(){
	if (!signUpForm.terms.checked){
		alert('Please select Terms and Conditions option');
		signUpForm.terms.focus();
		return false;
	}else{
		return true;
	}	
}

function isClaimIDOK(){
	var field_val1=signUpForm.oldClaimID.value.replace(/[ ]/g, "");
	var field_val2=signUpForm.claimID.value.replace(/[ ]/g, "");

	if(field_val1 != field_val2 ){
		alert('Your ClaimID did not match.');
		return false;
	}
	return true;
}


//check zipcode is ok
function isZipcodeOK(){
	var field_val=signUpForm.zip.value.replace(/[ ]/g, "");
	if (field_val.length<5){
		c=confirm('Please type your postal Zip Code.');
		if(c!=false){
			signUpForm.zip.focus();
		}else{
			signUpForm.zip.value="";
			signUpForm.country.focus();
		}
		return false;
	}
	if(!isInteger(field_val)){
		c=confirm("Zip code accepts only digits");
		if(c!=false){
			signUpForm.zip.focus();
		}else{
			signUpForm.zip.value="";
			signUpForm.country.focus();
		}
		return false;
	}
	return true;
}

function isZipCodeValid(target){
	browserDetect();
	var zip  =  signUpForm.zip.value ;
	if(isZipcodeOK(zip)){
		target = target+"?zip="+zip;
		doCompletionSignUp(target);
	}
}

/**
* check existancy of username	
*/
function isUserNameValid(target){
	browserDetect();
	var userName = signUpForm.name.value ;
	
	if(isNameOK()){
		target = target+"?userName="+userName;
		doCompletionSignUp(target);
	}
}

function doCompletionSignUp(target){
	initRequestSignUp();
	reqSignUp.onreadystatechange = useHttpResponseSignUp;
	reqSignUp.open("GET", target, true);
	reqSignUp.send(null);
}

function initRequestSignUp(){
	if (window.XMLHttpRequest){
		reqSignUp = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		reqSignUp = new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function useHttpResponseSignUp(){
	var error = "Invalid / Already Exists data fields ";
	var numArray = new Array(" 1) " , " 2) " ," 3) ");
	var email = document.signUpForm.email.value
	var userID = document.signUpForm.name.value
	var zipCode = document.signUpForm.zip.value

	if (reqSignUp.readyState == 4){
		if (reqSignUp.status == 200){
			var textout = reqSignUp.responseText;
			if("checkEmail"==isSignUp){
				if(textout!="ok"){
					showLoadingDiv(false);
					clearError();

					var ele=textout.split(",");
					var part_num=0;
					while (part_num < ele.length){
						document.getElementById(ele[part_num]).style.display='';
						if(ele[part_num] == "emailError")
						{
							error = error + "\n\n "+numArray[part_num]+" Email ["+email+"]  already exist ";
						}
						else if(ele[part_num] == "userIDError")
						{
							error = error + "\n\n "+numArray[part_num]+" BigDevil ID ["+userID+"] already exist  ";	
						}
						else if(ele[part_num] == "zipError")
						{
							error = error + "\n\n "+numArray[part_num]+" Invalid Zip code  ";	
						}
						part_num+=1;
					}
					alert(error);
					document.getElementById("errorSymbol").style.display='';
					isSignUp=false;
				}else{
					signUpForm.submit();
				}
			}else{
				if(textout.match("Invalid Zip Code")){
					alert("Invalid Zip Code");
					signUpForm.city.value = "";
					signUpForm.country.focus();
					//signUpForm.zip.focus();
					return true;
				}else if(textout.match("I'm sorry, that user name is already in use. Please select another username")){
					showDiv("notAvlUserName");				
					hideDiv("avlUserName");
					signUpForm.name.focus();
				}else if(textout.match("Valid Username")){
					showDiv("avlUserName");
					hideDiv("notAvlUserName");
				}else{
					signUpForm.city.value = textout ;
					return false;
				}
			}
		}
	}
}

var isSignUp="";
function checkEmail(target){
	showLoadingDiv(false);
	isSignUp="checkEmail";
	target= target + "&e="+document.signUpForm.email.value+"&n="+document.signUpForm.name.value+"&z="+document.signUpForm.zip.value;
	doCompletionSignUp(target);
}

function showLoadingDiv(isLoadingOn){
	if(isLoadingOn){
		document.getElementById("loadingDiv").style.display='';
		document.getElementById("signUpDiv").style.display='none';
	}else{
		document.getElementById("loadingDiv").style.display='none';
		document.getElementById("signUpDiv").style.display='';
	}
}

function clearError(){
	document.getElementById("emailError").style.display='none';
	document.getElementById("userIDError").style.display='none';
	document.getElementById("zipError").style.display='none';
	document.getElementById("errorSymbol").style.display='none';
}

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 browserDetect(){
	 if(document.layers){
		thisbrowser="NN4";
		signUpForm = document.signUpForm;
	 }
	 if(document.all){
		thisbrowser="ie";
	 }
	 if(!document.all && document.getElementById){
		thisbrowser="NN6";
		signUpForm = document.signUpForm;
	 }
}

<!-- Original:  Cyanide_7 (leo7278@hotmail.com) -->
<!-- Web Site:  http://members.xoom.com/cyanide_7 -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	
function autoTab(input,len, e)
{
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode))
	{
	input.value = input.value.slice(0, len);
	input.form[(getIndex(input)+1) % input.form.length].focus();
	}		
	function containsElement(arr, ele)
	{
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
		found = true;
		else
		index++;
		return found;
	}
	
	function getIndex(input)
	{
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
	}
	return true;
}

var reqSignUp ;


