// JavaScript Document

var re_email = /^\w+([\.-]?\w+)*\@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
/* a little fall-through validation... */
function ValThis(x) {
	if (x.first_name.value=='') {
		alert("Please enter your first name.");
		x.first_name.focus();
		return false;
		}
	if (x.last_name.value=='') {
		alert("Please enter your last name.");
		x.last_name.focus();
		return false;
		}
	if (x.p_resume.value=='') {
		alert("Please enter your resume.");
		x.p_resume.focus();
		return false;		
		}
	if (x.zip.value=='') {
		alert("Please enter your zip code.");
		x.zip.focus();
		return false;		
		}	
	if (x.email.value=='') {
		alert("Please enter your email address.");
		x.email.focus();
		return false;		
		}		
	x.submit();
	}
	
function doValidate_resumeSubmit(f) {
		var badchars = /[\&\,\#\;\?\\\:\+\*\{\}\[\]\^\|\$\?\`\!\<\>\/\'\_\"\~\=\%\(\)]+/g;
		var oneword  = /^\w+[ ]+?\w/g;
		if (f.keyword.value.match(badchars)) {
	/*		alert("Please, only use AlphaNumeric characters in your search.");
			f.keyword.value = "";
			f.keyword.focus();
	*/		}
		else {
				f.submit();
			}
		}
		
function handleEmail(formElement, email) {
	
	x = readCookie("emailString");
	if(x) {
		var theValues = x.split(',');
		var theOutput = "";
		for (i=0;i<theValues.length;i++) {
			if (theValues[i]!=email && theValues[i]!="") {
				theOutput = theValues[i] + ", " + theOutput;
				}
			}
			if (formElement.checked==true) {
				createCookie("emailString",theOutput + email, 1);
				}
			else {
				if (theOutput!="") {
					createCookie("emailString",theOutput, 1);
					}
				else {
					eraseCookie("emailString");
					}
				}
		}
	else {
		createCookie("emailString",email,1);
		}
	}
	
	
function sendEmail() {
	x = readCookie("emailString");
	if(x) {
		var theValues = x.split(',');
		var theOutput = "";
		for (i=0;i<theValues.length;i++) {
			if (theValues[i]!="") {
				theOutput = trim(theValues[i]) + "; " + theOutput;
				}
			}	
		location.href="mailto:?bcc=" + theOutput;
		}
	else {
		alert("no email addresses are selected");
		}
	}
function trim(s) {
  	return s.replace(/^\s+|\s+$/, '');
	} 
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}