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(); 
	} 
	return true; 
} 
 
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; 
} 

function copy_address() {
document.signup1.bill_address.value = document.signup1.street.value;
document.signup1.bill_city.value =document.signup1.city.value;	   	   	   
document.signup1.bill_state.value = document.signup1.state.value;	   
document.signup1.bill_zipcode.value = document.signup1.zipcode.value;	   	   
}
function isSTR(val){
        var str = val;
        // Return false if characters are not a-z, A-Z, or a space.
        for (var i = 0; i < str.length; i++){
                var ch = str.substring(i, i + 1);
                if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' '){
                return 1;
                }
        }
        return 0;
}
function isEmail(val)
{
        // Return false if e-mail field does not contain a '@' and '.' .
        if (val.indexOf ('@',0) == -1 || val.indexOf ('.',0) == -1)
        {
                return 1;
        }
        else
        {
                return 0;
        }
}

function isNum(str)
{
        // Return false if characters are not '0-9' or '.' .
        for (var i = 0; i < str.length; i++)
        {
                var ch = str.substring(i, i + 1);
                if ((ch < "0" || "9" < ch) && ch != '.' && ch != '-')
                {
                        return 1;
                }
        }
        return 0;
}

function check_form() {
        var error_message = "There are following errors while processing the RegisterationProcess:\n";
        var error = 0;
       
	   var first_name= document.register.first_name.value;
	   var last_name= document.register.last_name.value;
	   var email= document.register.email.value;
	  var address= document.register.address.value;
	  var city= document.register.city.value;
	  var password= document.register.password.value;

	   
	   // Validation for first name  
        if (first_name == "" || first_name.lenght<3) {
                error_message = error_message + "Please Enter Your Name\n";
                error = 1;
        }
		
		// Validation for Last name  
        if (last_name == "" || last_name.lenght<3) {
                error_message = error_message + "Please Enter Your Last Name\n";
                error = 1;
        }
			
			// Validation for email  
        if (email == "" ||  isEmail(email)) {
                error_message = error_message + "Please Enter correct Email\n";
                error = 1;
        }
	   // Validation for address  
        if (address == "" || address.lenght<3) {
                error_message = error_message + "Please Enter Your Address\n";
                error = 1;
        }
				// Validation for city  
        if (city == "" || city.lenght<3) {
                error_message = error_message + "Please Enter Your city\n";
                error = 1;
        }        
        if (password == "" || password.lenght<6) {
                error_message = error_message + "Please Enter Your Password\n";
                error = 1;
        }        
		if (error == 1) {
                alert(error_message);
                return false;
        } else {
                return true;
        }
}// JavaScript Document