var phone = "()- 0123456789"
var numb = "0123456789";
var zip = "-0123456789";
var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
function res(t,v){
	v = eval(v)
	var w = "";
	for (i=0; i < t.value.length; i++) {
		x = t.value.charAt(i);
		if (v.indexOf(x,0) != -1){
			w += x;
		}
	}
	t.value = w;
}


function ShortFormValidator(theForm) 
{
	var error = ""; 

	if (theForm.first_name.value == "") {
   		error += "Please Enter Your First Name.\n";
  	}	 
	if (theForm.last_name.value == "") {
   		error += "Please Enter Your Last Name.\n";
 	}
	if (theForm.email.value == "") {
   		error += "Please Enter Your Email Address.\n";
	}
	if (theForm.phone.value == "") {
   		error += "Please Enter Your Phone Number.\n";
	}
	if (theForm.address.value == "") {
   		error += "Please Enter Your Address.\n";
	}
	if (theForm.city.value == "") {
   		error += "Please Enter Your City.\n";
	}
	if (theForm.state.value == "") {
   		error += "Please Enter Your State.\n";
	}
	if (theForm.zip.value == "") {
   		error += "Please Enter Your Zip Code.\n";
	}
	
	selInd = theForm.HowHeard.selectedIndex; 
	if (selInd == 0) {
   		error += "Please let us know how you heard about us from selecting from the drop-down menu.\n";
	}

	if (error != "") 
	{
		alert(error);
		return (false);
	} else {
		return (true);
	} 
}


function activateNav(id){
	document.getElementById(id).className = 'active'
}


function showRow(thisRow){
	document.getElementById(thisRow).style.display = ''
}
function hideRow(thisRow){
	document.getElementById(thisRow).style.display = 'none'
}

function highlightNav(navName){
	document.getElementById(navName).className = "active"
}

function makeVisible(thisDiv){
	document.getElementById(thisDiv).style.display = "inline";
}
function makeInvisible(thisDiv){
	document.getElementById(thisDiv).style.display = "none";
}

boxActivated = false
function activateFinder(thisTextbox){
	if (!boxActivated){
		boxActivated = true
		thisTextbox.className = "activeTextfield";
		thisTextbox.value="";
	}
	
}
function deactivateFinder(thisTextbox){
	if (thisTextbox.value==""){
		boxActivated = false
		thisTextbox.className = "inactiveTextField";
		thisTextbox.value="ZIP CODE"
	}
}



newsletterBoxActivated = false
function activateNewsletterSignup(thisTextbox){
	if (!newsletterBoxActivated){
		newsletterBoxActivated = true
		thisTextbox.className = "activeTextfield";
		thisTextbox.value="";
	}
	
}
function deactivateNewsletterSignup(thisTextbox){
	if (thisTextbox.value==""){
		newsletterBoxActivated = false
		thisTextbox.className = "inactiveTextField";
		thisTextbox.value="ENTER E-MAIL ADDRESS"
	}
}


function validateNewsletterForm(theForm) 
{
	var error = ""; 

	if (theForm.email.value == "" || theForm.email.value == "ENTER E-MAIL ADDRESS" ) {
   		error += "Please Enter Your Email Address.\n";
  	} else if (!validateEmail(theForm.email.value)){
   		error += "Please make sure you entered in your email address correctly.\n";
	}

	if (error != "") 
	{
		alert(error);
		return (false);
	} else {
		return (true);
	} 
}


function doPopup(URL,w,h){
	thisWindow = window.open(URL, "popWin", "toolbar=1, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1, width=" + w + ", height= " + h);
}




function validateEmail(incoming) {
	var emailstring = incoming;
	var ampIndex = emailstring.indexOf("@");
	var afterAmp = emailstring.substring((ampIndex + 1), emailstring.length);
		// find a dot in the portion of the string after the ampersand only
	var dotIndex = afterAmp.indexOf(".");
		// determine dot position in entire string (not just after amp portion)
	dotIndex = dotIndex + ampIndex + 1;
		// afterAmp will be portion of string from ampersand to dot
	afterAmp = emailstring.substring((ampIndex + 1), dotIndex);
		// afterDot will be portion of string from dot to end of string
	var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
	var beforeAmp = emailstring.substring(0,(ampIndex));
		//old regex did not allow subdomains and dots in names
		//var email_regex = /^[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+(\.[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~])*\@(((\w+[\w\d\-]*[\w\d]\.)+(\w+[\w\d\-]*[\w\d]))|((\d{1,3}\.){3}\d{1,3}))$/;
	var email_regex = /^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/ 
		// index of -1 means "not found"
	if ((emailstring.indexOf("@") != "-1") &&
		(emailstring.length > 5) &&
		(afterAmp.length > 0) &&
		(beforeAmp.length > 1) &&
		(afterDot.length > 1) &&
		(email_regex.test(emailstring)) ) {
		  return true;
	} else {
			//alert("Please check your email address!");
			return false;
	}
}

