String.prototype.trim = function()
{
	//trims all whitespace from the beginning and end of a string and returns it
	
	return this.replace(/^\s+|\s+$/g,"");
}

function emptyInput(ctrlid)
{
	return document.getElementById(ctrlid)==null || document.getElementById(ctrlid).value.trim().length==0;
}

function validEmailAddress(val)
{
	apos = val.indexOf("@");
	dotpos = val.lastIndexOf(".");
	
	if(apos < 1 || dotpos-apos < 2)
    	return false;
    
    return true;
}

function validEmail()
{
	var errors = "";
	
	if(emptyInput('email_name'))
		errors += "You must enter your name.\n";
	if(emptyInput('email_email'))
		errors += "You must enter your email address.\n";
	else if(!validEmailAddress(document.getElementById('email_email').value))
		errors += "The email address you entered is invalid.\n";
	if(emptyInput('email_message'))
		errors += "You must enter a message.\n";
	if(emptyInput('email_captcha'))
		errors += "You must enter the security code.\n";
		
	if(errors=="")
		return true;
		
	alert('You did not fill out the form properly:\n\n' + errors);
	return false;
}
