// JavaScript Document

function checkEmail (thisString) {
    var at="@"
	var dot="."
	var lat=thisString.indexOf(at)
	var lstr=thisString.length
	var ldot=thisString.indexOf(dot)

		if (thisString.indexOf(at) == -1 )
				{
				alert('The e-mail address has not been entered or is invalid')
				return false;
				}
		if  (thisString.indexOf(at) == -1 || thisString.indexOf(at) == 0
	    		|| thisString.indexOf(at) == lstr)
				{
				alert('The e-mail address has not been entered or is invalid')
				return false;
				}
		if  (thisString.indexOf(dot) == -1 || thisString.indexOf(dot) == 0
	     		|| thisString.indexOf(dot) == lstr)	
				{
				alert('The e-mail address has not been entered or is invalid')
				return false;
				}
		if (thisString.indexOf(at, (lat+1)) != -1)
				{
				alert('The e-mail address has not been entered or is invalid')
				return false;
				}
		if (thisString.substring(lat-1, lat) == dot || thisString.substring (lat+1, lat+2) == dot )		
				{
				alert('The e-mail address has not been entered or is invalid')
				return false;
				}
		if (thisString.indexOf(dot, (lat+2)) == -1)
				{
				alert('The e-mail address has not been entered or is invalid')
				return false;
				}
		if  (thisString.indexOf(" ") != -1)
				{
				alert('The e-mail address has not been entered or is invalid')
				return false;
				}
		return true
}

function checkFormSubmit (thisForm)
{ 
    if (thisForm.cfname.value == '' || thisForm.cfname.value == null ) 
	 		{
	 		 alert('Please enter your contact name');
	 		 return false;
			 }
	if (thisForm.cfphone.value == '' || thisForm.cfphone.value == null ) 
	 		{
	 		 alert('Please enter your phone number');
	 		 return false;
			 }
	if (thisForm.cfemail.value != ' ' && checkEmail (thisForm.cfemail.value) == false)
	       		{	
		   		thisForm.cfemail.value = ""
				thisForm.cfemail.focus()
				return false;
				}				
	if (thisForm.cfrequest.value == '' || thisForm.cfrequest.value == null ) 
	 		{
	 		 alert('Please enter your message');
			return false;
			 }	
			 
	// Anti-spam section - stop the spammers submitting to this online form by blocking urls and web addresses
	if (/<a href="/i.test(thisForm.cfname.value) ||  /url=http/i.test(thisForm.cfname.value))
			{
				alert('Links to web addresses are not allowed. Please try again');
				return false;
			}
	if (/<a href="/i.test(thisForm.cfphone.value) ||  /url=http/i.test(thisForm.cfphone.value))
			{
				alert('Links to web addresses are not allowed. Please try again');
				return false;
			}		
	if (/<a href="/i.test(thisForm.cfrequest.value) ||  /url=http/i.test(thisForm.cfrequest.value))
			{
				alert('Links to web addresses are not allowed. Please try again');
				return false;
			}		 
			 								
	return true;		 
}
