// JavaScript Document

function formValidator(vtype,theid){
	var searchbox = document.getElementById(theid);
		if(vtype =='cityzip') // city,st or city, st
		{
			if(isAlphanumeric(searchbox, "Please enter your location in this format:  City, State or Zip Code")){
				return true;
			} 
		} else { // zip only
			if(isZip(searchbox, "Please enter a valid zip code")){
				return true;
			} 
		}
	return false;
	
}

function isAlphanumeric(elem, helperMsg){
	// previous rules
	//var alphaExp = /(^(\w+[\-]\w+\,{1})\s[a-zA-Z]{2})|(^(\w+\,{1})\s[a-zA-Z]{2})|(^(\w+\s[a-zA-Z]+\,{1})\s[a-zA-Z]{2})|(^\d{5}$)/;
	//var alphaExp = /(^(\w+\,{1})\s[a-zA-Z]{2})|(^(\w+\,{1})[a-zA-Z]{2})|(^\d{5}$)|(^\d{5}-\d{4}$)/;
	var alphaExp = /(^(\w+\s[a-zA-Z]{2}))|(^(\w+\,{1})\s[a-zA-Z]{2})|(^(\w+\s[a-zA-Z]+\,{1})\s[a-zA-Z]{2})|(^\d{5}$)/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


function isZip(elem, helperMsg){
	var numericExpression = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
