	// Andrew Weeks
// 24/09/03
//
// This script checks if a telephone number or email address have been supplied. If an email address
// has been supplied then it validates it.
//
// 1
// Place this code between the head tags:
// <script language=javascript src="checkForm.js">
//
// 2
// Place this code in the <form> tag:
// <form name="emailForm" onSubmit="return checkForm()">
//
// 3
// Place this code immediately before the </form> tag:
// Name the name, email and telephone text boxes as follows:
// <input type="text" name="Name">
// <input type="text" name="Email">
// <input type="text" name="TelWork">
// <input type="text" name="TelHome">


function checkForm() {
	if (document.form.fullname != null) {
    	if(document.form.fullname.value == "")
		{
        	alert("Please enter your name");
        	document.form.fullname.focus();
		
			return false;
		}
   	 } 	else {	
    	if(document.form.surname.value == "")
		{
        	alert("Please enter your name");
        	document.form.surname.focus();
		
			return false;
		}
    }
	if (document.form.captchacode != null) {
		if(document.form.captchacode.value == "")
		{
       		alert("Please enter the code.");
       		document.form.captchacode.focus();
		
			return false;
		}
    }
	if(document.form.email.value == "")
	{
		alert("Please enter a valid email address");
        document.form.email.focus();
		
		return false;
    }
	if(document.form.email.value != "")
	{
		addr = document.form.email.value;

        // Split on at and dot sign
        bits = addr.split("@");
    	bits2 = addr.split(".");

        // Check if length is less than 2
        if(bits.length < 2)	{
            alert("Please enter a valid email address");
            return false;
        } 
			
		if (bits2.length < 2) {
        	alert("Please enter a valid email address");
	        document.form.email.focus();
			
			return false;
    	} 
	} 
    return true;
}
function checkTenantForm() {
	try {
		if ( $('fullname').length ) {
    		if ($('#fullname').val() == "")
			{
        		alert("Please enter your name");
	        	$('#fullname').focus();
		
				return false;
			}
   		} else {	
		 	if ( $('#surname').length ) {

				if(document.form.surname.value == "")
				{
    	    		alert("Please enter your name");
	        		document.form.surname.focus();
		
					return false;
				}
			}
    	}
		if ($('#address').length) {
			if($('#address').val() == "")
			{
    	   		alert("Please enter the address.");
				$('#address').focus()
				
				return false;
			}
    	}
		
		if ($('#telmobile').length) {
			if($('#telmobile').val() == "")
			{
       			alert("Please enter the mobile number.");
	       		$('#telmobile').focus();
		
				return false;
			}
	    }
		if ($('#ages').length) {
			if($('#ages').val() == "")
			{
    	   		alert("Please enter the details for your group.");
       			$('#ages').focus();
		
				return false;
			}
    	}
	}
		catch(err) {
			return false;
	}
    return true;
}
