
var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;

function isEmpty(str)
{
    strRE = new RegExp( );
    strRE.compile( '^[\s ]*$', 'gi' );

    return strRE.test( str.value );
}
 
function notValidEmail(str)
{
    mailRE = new RegExp( );
    mailRE.compile( '^[\._a-z0-9-]+@[\.a-z0-9-]+[\.]{1}[a-z]{2,4}$', 'gi' );

    return !(mailRE.test( str.value ));
}
  
function checkForm(form)
{
	if(isEmpty(form.first_Name))
	{ alert('Please fill in your First name'); 
		form.first_Name.focus();
	return false; }
	
/*	if(isEmpty(form.last_Name))
	{ alert('Please fill in your Last name'); 
		form.last_Name.focus();
	return false; }

	if(isEmpty(form.hphone1) || isEmpty(form.hphone2) || isEmpty(form.hphone3))
	{ alert('Please fill in your Primary phone number'); return false; }

*/

	if(isEmpty(form.email))
	{ alert('Please fill in your Email address!'); 
		form.email.focus();
	return false; }
	
	if(notValidEmail(form.email))
	{ alert('Incorrect or missing email address!');
		form.email.focus();
	 return false; }

	 
/* if(isEmpty(form.incomegoal))
	{ alert('Please fill in your incomegoal'); 
		form.incomegoal.focus();
	return false; }
	
	if(isEmpty(form.occupation))
	{ alert('Please fill in your occupation'); 
		form.occupation.focus();
	return false; }
	
	*/
	return true;
}


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 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)
{
	s = stripCharsInBag(strPhone, validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
	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;
}
