/**
 * Request suggestions for the given autosuggest control. 
 * @scope protected
 * @param oAutoSuggestControl The autosuggest control to provide suggestions for.
 */

// INPUT CLEARING FUNCTION // 

function prepareInputs() {
	
	$("#searchterm input").attr("id", "txtSearch");
	$("#searchterm input").val("Enter a city, state or ZIP code");	

	
    $("#searchterm input").focus( function() {
        if ($("#searchterm input").attr("value") == "Enter a city, state or ZIP code") {
            $("#searchterm input").attr("value", "");	
        }        
  });


		$("adv_webid_input").focus( function() {
        if ($("adv_webid_input").attr("value") == "Enter a MLS or Web ID") {
            $("adv_webid_input").attr("value", "");
        }
    });
}


function idsearch(form,urlPath) {    
	
var webID = document.searchform.userinput.value;
var fValue = parseFloat( webID );

if ( isNaN( fValue ) )
{
alert( "Please enter a valid number for the MLS/WebID/Photo Search " );
}

if ( isFinite( fValue ) )
{
window.open("http://homes.ajchomefinder.com/"+urlPath+"/id/" + webID, "_self"); 
}
}

// ASSIGNS INPUT TOGGLE FUNCTIONALITY //



function prepareAdv() {
$("#l-link").click( function() {
		$("#adv-search-submit").attr("style", "display:block")
		$("#l-link").attr("class", "active");
		$("#w-link").removeClass("active");
		$("#location-wrapper").attr("style", "display:block")
		$("#webid-wrapper").attr("style", "display:none")
	});
	
	$("#w-link").click( function() {
		$("#adv-search-submit").attr("style", "display:none")
			$("#w-link").attr("class", "active");
			$("#l-link").removeClass("active");
			$("#location-wrapper").attr("style", "display:none")
			$("#webid-wrapper").attr("style", "display:block")
		});
	
	

}

//DISABLES INACTIVE INPUTS AND SETS DEFAULT SEARCH VALUES //

function prepareValidateSubmit() {
    $("#adv-search-submit").click( function() {
        validateForm();
    });
}

/*
function validateForm() {

    if ($("l-link").hasClassName("active")) {
        $("webid-wrapper").remove();

        if ($("txSearch").value == "Enter a city, state or ZIP code" || $("txSearch").value == "") {
            $("txSearch").value = "GEORGIA, USA";
        }
}
    }
*/


		function FoeSearch(locSch) {
			if ($("#txSearch").attr("value") == "Enter a city, state or ZIP code" || $("#txSearch").attr("value") == "") {
			      $("#txSearch").attr("value", locSch);
			  }
		    }

// ONLOAD FUNCTIONS //

addLoadEvent(prepareValidateSubmit);
addLoadEvent(prepareAdv);
addLoadEvent(prepareInputs);