/** validates the contactUs form for submission **/
function checkContact(form) {
	if (form.nameVal.value == "" || form.email.value == "") {
		alert("Name and Email are required fields");
		if (form.nameVal.value == "") { form.nameVal.focus(); } else { form.email.focus(); }
		return false;
	} else if (!validEmail(form.email.value)) {
		alert("A valid email address is required");
		return false;
	} else if (form.referral.value == "") {
		alert("Please tell us how you heard about us");
		form.referral.focus();
		return false;
	}
	return true;
}

/** toggles on/off the model sub-menus for the model-lines 
 * dependant upon setElementPropertyId()
 **/
function showMapDiv(container) {
	var divs = document.getElementsByTagName('div'); 
        
	for(z=0; z<divs.length; z++) { 
		if(divs[z].id.substring(0,5) == "locs_" && divs[z].id != ("locs_" + container)) { 
			setElementProperty(divs[z].id, 'display', 'none'); 
		} else if (divs[z].id.substring(0,5) == "locs_" && divs[z].id == ("locs_" + container)) {
			setElementProperty(divs[z].id, 'display', 'block'); 
		}
	}
}

/** used by above function to show/hide page elements 
 * dependant upon typeElement();
 **/
function setElementProperty(id, id_property, id_value){ 
     var menuDiv = typeElement(id); 
     if((menuDiv != null) && (menuDiv.style != null)){ 
          menuDiv = menuDiv.style; 
          menuDiv[ id_property ] = id_value; 
     } 
}

/** used by above function to show/hide page elements **/
function typeElement(id) { 
     var type = null; 
     if(typeof(id) == "object"){ 
          type = id; 
     } else { 
          type = document.getElementById(id); 
     } 
     return (type); 
}

/* email validator */
function validEmail(str) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/;
	return (filter.test(str));  //returns true if valid, false if not
}
