// JavaScript Document
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 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 isPhone(strPhone){
var minDigitsInIPhoneNumber = 1;
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";

s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function chkValid(){
		
if(document.ContactForm.FirstName2.value==''){
	alert("First Name Can Not be Left Blank!");
	document.ContactForm.FirstName2.focus();
	return false;
}
if(document.ContactForm.last.value==''){
	alert("Last Name Can Not be Left Blank!");
	document.ContactForm.last.focus();
	return false;
}
if(document.ContactForm.email.value==''){
	alert("EMail Can Not be Left Blank!");
	document.ContactForm.email.focus();
	return false;
}

if(document.ContactForm.email.value!=""){
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.ContactForm.email.value))){
		alert("Invalid E-mail Address! Please re-enter.");
		document.ContactForm.email.focus();
		document.ContactForm.email.select();
		return (false)
	}
}


if(document.ContactForm.telephone.value!=''){
	if(!isPhone(document.ContactForm.telephone.value)){
		alert("Invalid Phone Number!");
		document.ContactForm.telephone.focus();
		document.ContactForm.telephone.select();
		return false;		
	}
}

if(document.ContactForm.regarding.selectedIndex ==0){
	alert("Please Select the Subject!");
	document.ContactForm.regarding.focus();
	return false;
}

if(document.ContactForm.word.value==''){
	alert("Please Type the Word Below the Image!");
	document.ContactForm.word.focus();
	return false;
}

return true;
}
