function validate(form,goal){
	// Trim whitespace
	for(var x = 0; x < form.elements.length; x++) {
		if(form.elements[x].type == 'text' || form.elements[x].type == 'hidden') {
	    	form.elements[x].value = Trim(form.elements[x].value);
		}
	}
	// set contactby flag
	var contactby = 'phone';
	if (form.contactby){
		if (form.contactby[0].checked==true){
			contactby='phone'
		}else{
			contactby='email'
		}
	}
	// first_name
	if (form.first_name && form.first_name.type!='hidden'){
		str = form.first_name.value;
		if (isWhitespace(str)) {
			alert("Please enter your first name.");
			form.first_name.focus();
			return false;
		}
		var firstnameRegxp 	= /^([0-9a-zA-Z\'\-\,\. ]{1,})$/;
		if (firstnameRegxp.test(str) != true){
			alert("Invalid character in your first name.");
			form.first_name.focus();
			form.first_name.select();
			return false;
		}
	}
	// last_name
	if (form.last_name && form.last_name.type!='hidden'){
		str = form.last_name.value;
		if (isWhitespace(str)) {
			alert("Please enter your last name.");
			form.last_name.focus();
			return false;
		}
		if (firstnameRegxp.test(str) != true){
			alert("Invalid character in your last name.");
			form.last_name.focus();
			form.last_name.select();
			return false;
		}
	}
	// phone number
	if (form.phone && form.phone.type!='hidden'){
		var phonRegxp 	= /^([0-9a-zA-Z\-\.\(\)\ ]{10,40})$/;
		// check if contactby is set to phone, validate it
		if (contactby=='phone'){
			str = form.phone.value;
			if (isWhitespace(str)) {
				alert("Please enter your phone number.");
				form.phone.focus();
				return false;
			}
			// check length
			if (str.length < 10){
				alert("Please enter your full phone number, including area code.");
				form.phone.focus();
				form.phone.select();
				return false;
			}
			// check for bad chars
			if (phonRegxp.test(str) != true){
				alert("Invalid character in phone number.");
				form.phone.focus();
				form.phone.select();
				return false;
			}
		}else{
			// if contactby is NOT set to phone, only validate if its NOT blank
			str = form.phone.value;
			if (!(isWhitespace(str))) {
				// check length
				if (str.length < 10){
					alert("Please enter your full phone number, including area code.");
					form.phone.focus();
					form.phone.select();
					return false;
				}
				// check for bad chars
				if (phonRegxp.test(str) != true){
					alert("Invalid character in phone number.");
					form.phone.focus();
					form.phone.select();
					return false;
				}
			}
		}
	}
	// email
	if (form.email && form.email.type!='hidden'){
		str = form.email.value;
		// check if contactby is set to email, validate it
		if (contactby=='email'){
			if (isWhitespace(str)) {
				alert("Please enter your email address.");
				form.email.focus();
				return false;
			}
			if (!(isValidEmail(str))){
				alert("Please enter a valid email address.");
				form.email.focus();
				form.email.select();
				return false;
			}
		}else{
			// if contactby is NOT set to email, only validate if its not blank
			if (!(isWhitespace(str))) {
				if (!(isValidEmail(str))){
					alert("Please enter a valid email address or else leave it blank.");
					form.email.focus();
					form.email.select();
					return false;
				}
			}
		}
	}
	// block exit traffic popup
	leaving = false;
	// track the step one goal conversion
	pageTracker._trackPageview(goal);
	return true;
}

function isValidEmail(email){
	email		= email.toLowerCase();
    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(RegExp.test(email)){
        return true;
    }else{
        return false;
    }
}

function changeDisplay(elementid,displayVal){
	if (document.getElementById){
		var obj = document.getElementById(elementid);
		obj.style.display=displayVal;
	}
}

