function checkStr(str){
	var result = true;
	validate = new String(str);
	re = /<|>|&/g;
	if (validate.search(re)>-1){
		alert("Sorry, special characters are not allowed.");
		result=false;
	}
	return result;
}

function isEmailAddr(email){
	var result = false
	var theStr = new String(email)
	var index = theStr.indexOf("@");
	if (index > 0){
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1)){
			result = true;
		}
	}
	return result;
}

function cleanString (str) {
	var checkPhone = str.replace(/[\(\)\.\-\s,]/g, "");
	if (checkPhone.length!=10){
		alert("Please enter a valid phone number in the format ###-###-####");
		return "0";
	}else{
//		alert (checkPhone);
		return checkPhone;
	}
}
			
function valRequestForm(theForm){
	var result = true;

	if (!checkStr(theForm.name.value)){
		theForm.name.value="";
		theForm.name.focus();
		return (false);
	}
	if (!checkStr(theForm.phone.value)){
		theForm.phone.value="";
		theForm.phone.focus();
		return (false);
	}
	if (!checkStr(theForm.email.value)){
		theForm.email.value="";
		theForm.email.focus();
		return (false);
	}
	if (!checkStr(theForm.message.value)){
		theForm.message.value="";
		theForm.message.focus();
		return (false);
	}

	if (theForm.name.value == ""){
		alert("Please enter your name to request information.");
		theForm.name.focus();
		return (false);
	}
	if (cleanString(theForm.phone.value)==0){
		theForm.phone.value="";
		theForm.phone.focus();
		return (false);
	}else{
		theForm.phone.value=cleanString(theForm.phone.value);
	}
	if (theForm.phone.value == "" || theForm.phone.value.length < 10 || theForm.phone.value.length > 20 ){
		alert("Please enter your phone number to request information. \n\nPlease enter a phone number with area code in the format ###-###-####.");
		theForm.phone.focus();
		return (false);
	}
	if (theForm.email.value == "" || !isEmailAddr(theForm.email.value)){
		alert("Please enter your email address to request information.");
		theForm.email.focus();
		return (false);
	}  
  return (true);
}

