function runMLSSearch(){runSearch(document.getElementById("searchmlsField").value);} 
function runmlsSearch(){runSearch(document.getElementById("searchMLSField").value);} 
function runMFSearch(){runSearch(document.getElementById("searchMFField").value);} 
function runLNDSearch(){runSearch(document.getElementById("searchLNDField").value);} 
function runRNTSearch(){runSearch(document.getElementById("searchRNTField").value);} 
function runSearch(searchText){ 
   document.getElementById("loading").style.visibility="visible"; 
   
    var inputName="";
 	var searchType = getCheckedValue(document.getElementsByName("searchtype"));   
 	if (searchText=="" || searchText==undefined){ 
 	    if (document.getElementById("searchField")!=null){ 			searchText = document.getElementById("searchField").value; 
 		} 
 	}
 	if (searchText=="" || searchText==undefined){ 
 		if (document.getElementById("searchMLSField")!=null){
 			searchText = document.getElementById("searchMLSField").value; 
 		} 
 	}  
 	if (searchText=="" || searchText==undefined){ 
 		if (document.getElementById("searchLNDField")!=null){
 			searchText = document.getElementById("searchLNDField").value; 
 		} 
 	}
    var result="A valid search entry was not provided for the " + searchType.toUpperCase() + " search";
    var parms = {'btnquicksearch':'nav_search'}; 

 	if (searchType.toUpperCase()!="RENTAL_LISTINGS"){
	  	if (isMLSCode(searchText)){	  		inputName="mlsorfsbo";  
	  		parms[inputName]=searchText;
	  		result=searchType.toUpperCase() + " search with MLS Code: " + searchText; 
	  	}
	}    
   if (isValidZipCode(searchText)){   	    inputName="zipcode";
   	    parms[inputName]=searchText;
 		result=searchType.toUpperCase() + " search with Zip Code: " + searchText;
 	}
	if (hasLetters(searchText)){		inputName="street";
		parms[inputName]=searchText;
 		result=searchType.toUpperCase() + " search with Street: " + searchText; 
	}
	
	document.getElementById("result").innerHTML = result;
	window.setInterval("document.getElementById('loading').style.visibility='hidden'", 5000);
		
	if (inputName!=""){     
	    post_to_url("?inc="+searchType, parms); 
	}	
}
  
// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function isValidZipCode(value) {
   var re = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
   return (re.test(value));
}


function isMLSCode(value) {
   var re = /^\d{7}?$/;
   return (re.test(value));
}

function isStreetAddress(value) {
   var re = /^(\d{0,})\s?(\w{0,5})\s([a-zA-Z]{2,30})\s([a-zA-Z]{2,15})\.?\s?(\w{0,5})$/;
   return (re.test(value));
}

function isNumeric(value){ 
    var re = /^-{0,1}\d*\.{0,1}\d+$/; 
    return (re.test(value)); 
}

function hasLetters(value){ 
    var re = /[a-zA-Z]/; 
    return (re.test(value)); 
}

	
function post_to_url(path, params, method) { 
    method = method || "post"; // Set method to post by default, if not specified. 
 
    // The rest of this code assumes you are not using a library. 
    // It can be made less wordy if you use one. 
    var form = document.createElement("form"); 
    form.setAttribute("method", method); 
    form.setAttribute("action", path); 
 
    for(var key in params) { 
        var hiddenField = document.createElement("input"); 
        hiddenField.setAttribute("type", "hidden"); 
        hiddenField.setAttribute("name", key); 
        hiddenField.setAttribute("value", params[key]); 
        form.appendChild(hiddenField); 
    } 
 
    document.body.appendChild(form);
   form.submit(); 
} 

