//Validation Script
var focusClr = '#FFCED1';
var clearClr = '#FFFFFF';
function validateMe(form){
	alert("form validation has been called");
	for (i=0; i<form.elements.length; i++) {
		var elm = form.elements[i];
/*		if (elm.options){
			if ( !(selectFilled(elm))){
				return false;
			}
		}
		if (elm.type == "radio"){
			if(!(radioChecked(elm.name))){
				return false;	
			}
		}*/
		if (elm.type == "text" || elm.type == "textarea"){
			if(!(blankT(elm))){
			return false;	
			}
		}
	}
}
/*function selectFilled(elm) {
	if (elm.options[elm.selectedIndex].value =="PS") {
			elm.focus();
			elm.style.backgroundColor = focusClr;
			alert("You missed the "+elm.name+" question.");
			return false;
		}
		if (elm.name == "qmenu1"){
			location.href = elm.options[elm.selectedIndex].value;
		}
		else{
			elm.style.backgroundColor = clearClr;
			return true;
		}
}*/
/*function radioChecked(group) { 
	var rGroup = document.forms[0][group];
	var check = false;
	
	
	
	for (j=0; j<rGroup.length; j++){
		if (rGroup[j].checked == true){
			check = true;
			return true;
		}
	}
		if(check == false){
			alert("The "+ group + " question was not answered");
			return false;
		}
}*/
function blankT(elm){
	if (elm.value == "" || elm.value == null){
		elm.focus();
		elm.style.backgroundColor = focusClr;
		alert("You missed the "+elm.name+" question");
		return false;
	}
	else if (!(elm.name == "question")&& /[<>$#@\^\(\):;\[\]{}]+/i.test(elm.value)){
		alert("Please do not enter code in text area");
		return false;
	}
	else if (elm.name == "email" && !/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(elm.value)){
		elm.focus();
		elm.style.backgroundColor = focusClr;
		alert("There is a problem with your email address, please re-enter it.");
		return false;
	} 
	else if (elm.name == "Phone" && !/^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/.test(elm.value)){
		elm.focus();
		elm.style.backgroundColor = focusClr;
		alert("Please enter a valid phone number with the following format: 123-456-7899");
		return false;
	}
	else if (elm.name == "Age" && !(elm.value >= 18 && elm.value <= 99)){
		elm.focus();
		elm.style.backgroundColor = focusClr;
		alert("Please enter a valid age from 18-99");
		return false;
	}
	else if ((elm.name == "Zip" && !/^[0-9]{5}-?[0-9]{0,4}$/.test(elm.value) )|| (elm.name == "Employer_Zip" && !/^[0-9]{5}-?[0-9]{0,4}$/.test(elm.value))){
		elm.focus();
		elm.style.backgroundColor = focusClr;
		alert("Please enter a valid Zip Code");
		return false;
	}
	else if (elm.name == "Biz_Description" && elm.value == "Briefly describe your business here..."){
		elm.focus();
		elm.style.backgroundColor = focusClr;
		alert("Please briefly describe your business");
		return false;	
	}
	else {
		elm.style.backgroundColor = clearClr;
		return true;
	}	
}

