function validateForm( form ) {
    var err_mess = "";
	
	// checks a text field (text,textarea) for: empty string, minimum characters (if used)
	//( text , err message for empty string , min numbers of chars (0 for no minimum) , err message for too few chars)
	err_mess += checkEmpty( form.lname.value , "Please enter a name." , 0 , "" );
	err_mess += checkCity( form.lcity.value , "Please enter a city." , 0 , "" );
	err_mess += checkAddress( form.laddress.value , "Please enter a address." , 0 , "" );

	// checks a phone number for: empty string , all numbers , correct length (10 or 11) digits
	err_mess += checkPhone( form.lphone.value, "(xxx)-xxx-xxxx", 0 , "" );
	err_mess += checkZipcode( form.lzipcode.value, "000000", 0 , "" );
	// checks a text field (text,textarea) for: empty string, minimum characters (if used)
	//( text , err message for empty string , min numbers of chars (0 for no minimum) , err message for too few chars)
	err_mess += checkEmpty( form.lproperty.value , "Please enter a Property." , 0 , "" );

	// checks an email address for: empty string , validity , illegal characters
    err_mess += checkEmail( form.lemail.value );
	
	

if (err_mess != "") {
       alert(err_mess);
       return false;
    }
	return true; 
}

// ----------------------------- check an email address ----------------------------- //
function checkEmail(strEmail) {
	var error = "";
	// check the empty string
	if (strEmail == "") {
   		error = "Please enter an email address.\n";
		return error;
	}
	// check the syntax "*@*.ab" or "*@*.abc"
    var filter=/^.+@.+\..{2,3}$/;
    if (!(filter.test(strEmail))) { 
       error = "Please enter a valid email address.\n";
	   return error;
    }
	// check for invald characters
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
    if (strEmail.match(illegalChars)) {
       error = "The email address contains illegal characters.\n";
	   return error;
    }
	return error;    
}
// ----------------------------- check an email address ----------------------------- //


// ----------------------------- check an phone number ----------------------------- //
function checkPhone(strPhone) {
	var error = "";
	// check for the empty string
	if (strPhone == "") {
   		error = "Please enter a phone number.\n";
		return error;
	}
	// check for all numbers after stripping string
	var stripped = strPhone.replace(/[\(\)\.\-\ ]/g, ''); 
//    if (isNaN(parseInt(stripped))) {
//       error = "Please enter a valid phone number.\n";
//	   return error;
//    }
	// check for the proper length of 10 or 11 digits
    if (!(stripped.length == 10 || stripped.length == 11)) {
		error = "The phone number is the wrong length. Please include the area code.\n";
		return error;
    } 
	return error;
}
// ----------------------------- check an phone number ----------------------------- //


// ----------------------------- check an zipcode ----------------------------- //
function checkZipcode(strZipcode) {
	var error = "";
	// check for the empty string
	if (strZipcode == "") {
   		error = "Please enter a zip code.\n";
		return error;
	}
	// check for all numbers after stripping string
	var stripped = strZipcode.replace(/[\(\)\.\-\ ]/g, ''); 
    if (isNaN(parseInt(stripped))) {
       error = "Please enter a valid zip code.\n";
	   return error;
    }
	// check for the proper length of 10 or 11 digits
    if (!(stripped.length == 5 || stripped.length == 6)) {
		error = "The zip code number is the wrong length. Please include the zicode.\n";
		return error;
    } 
	return error;
}
// ----------------------------- check an zipcode ----------------------------- //




// ----------------------------- check a text element for an empty string ----------------------------- //

function checkEmpty(strText , strMessage , intMinChars , strMinMessage) {
	var error = "";
	// check for the empty string
  	if (strText == "") {
     	error = strMessage.concat("\n");
		return error;
  	}
	// check for minimum number of characters
	if (intMinChars != 0) {
		if (strText.length < intMinChars) {
			error = strMinMessage.concat("\n");
			return error;
		}
	}
	return error;	  
}

function checkCity(strText , strMessage , intMinChars , strMinMessage) {
	var error = "";
	// check for the empty string
  	if (strText == "") {
     	error = strMessage.concat("\n");
		return error;
  	}
	// check for minimum number of characters
	if (intMinChars != 0) {
		if (strText.length < intMinChars) {
			error = strMinMessage.concat("\n");
			return error;
		}
	}
	return error;	  
}

// ----------------------------- check a text element for an empty string ----------------------------- //


// ----------------------------- check a text element for an empty string ----------------------------- //

function checkAddress(strText , strMessage , intMinChars , strMinMessage) {
	var error = "";
	// check for the empty string
  	if (strText == "") {
     	error = strMessage.concat("\n");
		return error;
  	}
	// check for minimum number of characters
	if (intMinChars != 0) {
		if (strText.length < intMinChars) {
			error = strMinMessage.concat("\n");
			return error;
		}
	}
	return error;	  
}

// ----------------------------- check a text element for an empty string ----------------------------- //
// ----------------------------- check a text element for an empty string ----------------------------- //

function checkSubject(strText , strMessage , intMinChars , strMinMessage) {
	var error = "";
	// check for the empty string
  	if (strText == "") {
     	error = strMessage.concat("\n");
		return error;
  	}
	// check for minimum number of characters
	if (intMinChars != 0) {
		if (strText.length < intMinChars) {
			error = strMinMessage.concat("\n");
			return error;
		}
	}
	return error;	  
}

// ----------------------------- check a text element for an empty string ----------------------------- //

