function isEmail(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)

	if (str.indexOf(at)==-1){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    //alert("Invalid E-mail ID")
	    return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(" ")!=-1){
	   //alert("Invalid E-mail ID")
	   return false
	}

	return true		
}


function isNumber(str)
{
   var ValidChars = "0123456789.";
   var isNumber=true;
   var Char;

   for (i = 0; i < str.length && isNumber == true; i++)
      {
      Char = str.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         isNumber = false;
         }
      }
   return isNumber;

}


//name
//address
//email
//phone
//dob
//jobtitle
//employer
//salary
//
//parking - radio
//furnished - radio
//smoker - radio
//
//views
//dates


function validate(f) {

	if ((f.name.value == "") || (f.name.length < 3)) {
		alert('Please enter your name');
		f.name.focus();
		return false;
	}
	
	if ((f.address.value == "") || (f.address.length < 3)) {
		alert('Please enter your address');
		f.address.focus();
		return false;
	}
	
	if ((f.email.value == "") || (f.email.length < 3) || !(isEmail(f.email.value))) {
		alert('Please enter your email address');
		f.email.focus();
		return false;
	}

	if ((f.phone.value == "") || (f.phone.length < 3)) {
		alert('Please enter your phone number');
		f.phone.focus();
		return false;
	}

	if ((f.dob.value == "") || (f.dob.length < 3)) {
		alert('Please enter your date of birth');
		f.dob.focus();
		return false;
	}
	
	if ((f.jobtitle.value == "") || (f.jobtitle.length < 3)) {
		alert('Please enter your job title');
		f.jobtitle.focus();
		return false;
	}
	
	if ((f.employer.value == "") || (f.employer.length < 3)) {
		alert('Please enter your employer');
		f.employer.focus();
		return false;
	}

	if ((f.salary.value == "") || (f.salary.length < 4)) {
		alert('Please enter your salary');
		f.salary.focus();
		return false;
	}

	parking = -1;
	for (i=f.parking.length-1; i > -1; i--) {
		if (f.parking[i].checked) {
			parking = i; i = -1;
		}
	}

	if (parking == -1) {
		alert('Please indicate whether dedicated parking is required');
		return false;
	}

	furnished = -1;
	for (i=f.furnished.length-1; i > -1; i--) {
		if (f.furnished[i].checked) {
			furnished = i; i = -1;
		}
	}

	if (furnished == -1) {
		alert('Please indicate whether you require a furnished property');
		return false;
	}

	smoker = -1;
	for (i=f.smoker.length-1; i > -1; i--) {
		if (f.smoker[i].checked) {
			smoker = i; i = -1;
		}
	}
	
	if (smoker == -1) {
		alert('Please indicate whether any smokers will be living at the property');
		return false;
	}

	if ((f.views.value == "") || (f.views.length < 3)) {
		alert('Please enter details of the property you wish to view');
		f.views.focus();
		return false;
	}

	if ((f.dates.value == "") || (f.dates.length < 4)) {
		alert('Please enter details of  your availability');
		f.dates.focus();
		return false;
	}

	return true;

}