/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1)
	   return false;

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	   return false;

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		return false;

	 if (str.indexOf(at,(lat+1))!=-1)
		return false;

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		return false;

	 if (str.indexOf(dot,(lat+2))==-1)
		return false;
	
	 if (str.indexOf(" ")!=-1)
		return false;

	 return true;
}

function validateContactForm ()
{
	var validation = '';
	if (document.getElementById('lem_name').value == '')
		validation+= '* You must specify your name\n';
	if (document.getElementById('lem_email').value == '')
		validation+= '* You must specify your email address\n';
	else if (!echeck(document.getElementById('lem_email').value))
		validation+= '* You must specify a valid email address\n';
	if (document.getElementById('lem_telephone').value == '')
		validation+= '* You must specify your telephone number\n';
	if (document.getElementById('lem_questions_comments').value == '')
		validation+= '* Please enter a question or comment\n';
	if (document.getElementById('lem_consent').checked != true)
		validation+= '* You must consent to receive emails\n';
	
	if (validation == '')
	{
		return true;
	}
	else
	{
		alert (validation)
		return false;
	}
}
