function validateForm(theForm, type, debug) {
	if( type == null ) {
		var type = false;
	}
	
	if( debug == null ) {
		var debug = false;
	}
	
	// validate first name
	if( theForm.firstName && theForm.firstName.value == "" ) {
		alert("Please supply your First Name.");
		theForm.firstName.focus();
		return false;
	}
	
	// validate last name
	if( theForm.lastName && theForm.lastName.value == "" ) {
		alert("Please supply your Last Name.");
		theForm.lastName.focus();
		return false;
	}
	
	// validate email address
	if(theForm.eMail){
    	if( theForm.eMail && theForm.eMail.value == "" ) {
    		alert("Please supply your Email Address.");
    		theForm.eMail.focus();
    		return false;
    	} else {
    		var isVEmail = isEmail(theForm.eMail.value);
    		if( isVEmail == false ) {
    			alert("Please enter a valid email address in the form of: you@yourdomain.com");
    			theForm.eMail.focus();
    			return false;
    		}
    	}
	}
	
	// validate age
	if( theForm.agegroup && theForm.agegroup.value == "" ) {
			alert("Please select your age range");
			theForm.agegroup.focus();
			return false;
	}
	
	// validate zip code
	if( theForm.zipCode && theForm.zipCode.value == "" ) {
		alert("Please supply your Zip or Postal Code.");
		theForm.zipCode.focus();
		return false;
	}
	
	// validate comment reason code
	if( theForm.reasonCode && theForm.reasonCode.value == "" ) {
		alert("Please indicate the Type of Message you are sending.");
		theForm.reasonCode.focus();
		return false;
	}
	
	// validate comment
	if( theForm.comment && theForm.comment.value == "" ) {
		alert("Please enter your Comments.");
		theForm.comment.focus();
		return false;
	}
	
	// validate newsletter signup opt-in (if type = newsletter)
	if( type == "newsletter" && theForm.newsletter.checked == false) {
	   	alert("Please opt-in to receive our newsletter.");
		theForm.newsletter.focus();
		return false;
	}
	
	// debug alert fields
	if( debug == true ) {
		var msg, confirmed;
	
		msg = "required fields data:\n";
		if( theForm.firstName	) msg += "\nfirst name: " + theForm.firstName.value;
		if( theForm.lastName	) msg += "\nlast name: " + theForm.lastName.value;
		if( theForm.eMail		) msg += "\nemail: " + theForm.eMail.value;
		if( theForm.agegroup	) msg += "\nage group: " + theForm.agegroup.value;
		if( theForm.zipCode		) msg += "\nzip code: " + theForm.zipCode.value;
		if( theForm.reasonCode	) msg += "\nreason code: " + theForm.reasonCode.value;
		if( theForm.comment		) msg += "\ncomment: " + theForm.comment.value;
		if( theForm.newsletter	) msg += "\nnewsletter opt-in: " + theForm.newsletter.checked;
		msg += "\n\nwould you like to submit this data?";
		confirmed = confirm(msg);
		if( confirmed ) {
			return true;
		} else {
			return false;
		}
	}
	
	// if get this far, form is fully validated, return true
    return true;
}

// validate email address
function isEmail(str) {
	// declare and set vars
	var TLDs = ["AC", "AD", "AE", "AERO", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AQ", "AR", "ARPA", "AS", "ASIA", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BIZ", "BJ", "BM", "BN", "BO", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CAT", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "COM", "COOP", "CR", "CU", "CV", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EDU", "EE", "EG", "ER", "ES", "ET", "EU", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GOV", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "INFO", "INT", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JOBS", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MG", "MH", "MIL", "MK", "ML", "MM", "MN", "MO", "MOBI", "MP", "MQ", "MR", "MS", "MT", "MU", "MUSEUM", "MV", "MW", "MX", "MY", "MZ", "NA", "NAME", "NC", "NE", "NET", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "ORG", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PRO", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SU", "SV", "SY", "SZ", "TC", "TD", "TEL", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TP", "TR", "TRAVEL", "TT", "TV", "TW", "TZ", "UA", "UG", "UK", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "XN--0ZWM56D", "XN--11B5BS3A9AJ6G", "XN--80AKHBYKNJ4F", "XN--9T4B11YI5A", "XN--DEBA0AD", "XN--G6W251D", "XN--HGBK6AJ7F53BBA", "XN--HLCJ6AYA9ESC7A", "XN--JXALPDLP", "XN--KGBECHTV", "XN--ZCKZAH", "YE", "YT", "YU", "ZA", "ZM", "ZW"]
	
	// check if at(@) symbol exists
	if( str.indexOf('@') == -1 ) {
		return false;
	}
	
	// check that a dot(.) comes after the at(@) symbol
	var email = str.split('@');
	if( email[1].indexOf('.') == -1 ) {
		return false;
	}
	
	// check that last characters in domain are a TLD
	domain = email[1].split('.');
	TLD = domain[domain.length-1];
	for( var i = 0; i < TLDs.length; i++ ) {
		if( TLD == TLDs[i].toLowerCase() ) {
			return true;
		}
	}
}

// uncheck all 'yes' checkbox opt-in options
function resetYesBoxes(yesBoxes) {
	yesBoxes = yesBoxes.split(',');
	for( i = 0; i < yesBoxes.length; i++ ) {
		document.getElementById(yesBoxes[i]).checked = false;
	}
}

// uncheck the opt-out checkbox option
function resetNoBox(noBox) {
	document.getElementById(noBox).checked = false;
}

// scrolls to top of page
function scroller() {
	parent.scroll(0,0);
}