////////////////// VALIDATOR FUNCTIONS //////////////////

/****** Check required fields in forms script *******/

function formCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("name", "FirstName", "LastName", "email", "homeaddress", "hometype", "proptype", "pricerange", "Neighborhood", "bedrooms", "bathrooms", "beds", "baths", "halfbaths", "parktype", "realtor", "nightphone", "mailingAddress", "mailingCity", "mailingState", "mailingZip");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Name", "First Name", "Last Name", "Email Address", "Address", "Type of Home", "Property Type", "Price Range", "Neighborhoods", "Bedrooms", "Bathrooms", "Bedrooms", "Bathrooms", "Half Bathrooms", "Parking Type", "Are you working with a Realtor?", "Night Phone", "Street Address", "City", "State", "ZIP Code");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].value == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

function contactformCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("name","phone","city","state","email","howheard","comments");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Name","Phone Number","City","State","Email Address","How did you hear about us?","Questions/Comments?");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].value == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

/******* Validate Member Login box on left navigation *******/

    var bCancel = false; 

    function validateLogonForm(form) {                                                                   
        if (bCancel) 
	return true; 
	else 
	return validateRequired(form) && validateMinLength(form); 
	}
    function required () { 
	this.aa = new Array("username", "Please enter a valid username.", new Function ("varName", " return this[varName];"));
	this.ab = new Array("password", "Please enter a valid password.", new Function ("varName", "this.minlength='3';  return this[varName];"));
	}
    function minlength () { 
	this.aa = new Array("password", "Passwords cannot be less than 3 characters.", new Function ("varName", "this.minlength='3';  return this[varName];"));
	}