// Default the search type to mls
var SearchType = "";

function onBlurFunc(stype)
{
	//SearchType = stype;
}

function RemoveInputText(I)
{
	SearchType = "";
	ClearFields(false);
	I.value = "";
}

function InputMouseOut(T, text)
{
	
	T.value = text;
}

function ClearFields(SetToBlank)
{
	// This will check the quick search fields and reset all of them except the current field passed in
	if (SetToBlank) {
		// These need to remain set to empty string
		//if (document.getElementById("Search")) document.getElementById("Search").value = ""; 
		if (document.getElementById("pCity")) document.getElementById("pCity").value = ""; 
		if (document.getElementById("pArea")) document.getElementById("pArea").value = "";
		if (document.getElementById("HomeID")) document.getElementById("HomeID").value = ""; 
		if (document.getElementById("AgentNameSearch")) document.getElementById("AgentNameSearch").value = ""; 
		if (document.getElementById("pSchoolDistrict")) document.getElementById("pSchoolDistrict").value = ""; 
		if (document.getElementById("pSubdivision")) document.getElementById("pSubdivision").value = ""; 
		if (document.getElementById("pSuburb")) document.getElementById("pSubdivision").value = ""; 
		if (document.getElementById("pZip")) document.getElementById("pZip").value = "";
	} else {
		// These are set to the default value to display when the user is not typing in a box.  Search should remain set to empty string here
		//if (document.getElementById("Search")) document.getElementById("Search").value = ""; 
		if (document.getElementById("pCity")) document.getElementById("pCity").value = "City"; 
		if (document.getElementById("pArea")) document.getElementById("pArea").value = "Area"; 
		if (document.getElementById("HomeID")) document.getElementById("HomeID").value = "Listing Number"; 
		if (document.getElementById("AgentNameSearch")) document.getElementById("AgentNameSearch").value = "Agent Name"; 
		if (document.getElementById("pSchoolDistrict")) document.getElementById("pSchoolDistrict").value = "School District"; 
		if (document.getElementById("pSubdivision")) document.getElementById("pSubdivision").value = "Subdivision"; 
		if (document.getElementById("pSuburb")) document.getElementById("pSubdivision").value = "Suburb";
		if (document.getElementById("pZip")) document.getElementById("pZip").value = "";
	}
}

function searchkeydown(I)
{

	var sType = I.getAttribute("search_type");
	
    if (I.value == '')
    {
        // Don't do anything
    }
    else
    {
		SearchType = sType;
		//alert(SearchType);
	/*
		switch (I.id)
	    {
            case "StreetName": 
                SearchType = "address";
                break;
            case "HomeID": 
                SearchType = "mls";
                break;
            case "AgentNameSearch": 
                SearchType = "agent";
                break;
            case "pCity": 
                SearchType = "city";
                break;
			case "pArea": 
                SearchType = "area";
				break;
            case "pSchoolDistrict":
				SearchType = "schooldistrict";
				break;
			case "pSubdivision":
				SearchType = "subdivision";
				break;
            default : 
                alert("Unknown Search" + I.id);
				
        }
		*/
	}
	if (window.event.keyCode == 13)
	{
	    //alert(SearchType);
		doSearch(SearchType);	
    }
}

function SearchClick()
{   
	doSearch(SearchType);
}

function doSearch(type)
{
	var doSearch = false;
	if (type == "") type = document.frm.SearchType.value;
	else document.frm.SearchType.value = type;
	
	
	switch (type)
	{
        case "mls": 
            if (document.frm.HomeID.value == "")
            {
                document.frm.HomeID.focus();
                alert('Please fill out information on the MLS#');   
                return false;             
            }
            else
            {
                document.frm.action = "viewhome.asp";
				doSearch = true;
            }
            break;
			
		
		case "advanced": 
            document.frm.action = "findhomerequest.asp?TSearch=Advanced";
			doSearch = true;
            break;
        
		case "agent": 
            if (document.frm.AgentNameSearch.value == "")
            {
                document.frm.AgentNameSearch.focus();
                alert('Please fill out information on Agent Name');
                return false;
            }
            else
            {
                document.frm.action = "menuagent.asp";
				doSearch = true;
            }
            break;
			
		case "all": 
            //if (document.frm.StreetName.value == "" && document.frm.pCity.value == "" && document.frm.pZip.value == "" ) {
			//	alert("Please specify search criteria");
			//	return;
			//}
			
          	document.frm.action = "listagenthomes.asp";
			document.frm.Search.value = "TRUE";
			//if (document.frm.pSchoolDistrict && document.frm.pSchoolDistrict.value != "") document.frm.pSchoolDistrict.value = "'" + document.frm.pSchoolDistrict.value + "'";
			if (document.frm.pCity && document.frm.pCity.value != "") document.frm.pCity.value = "'" + document.frm.pCity.value.replace(/'/g, "") + "'";
			if (document.frm.pArea && document.frm.pArea.value != "") document.frm.pArea.value = "'" + document.frm.pArea.value.replace(/'/g, "") + "'";
			if (document.frm.pSuburb && document.frm.pSuburb.value != "") document.frm.pSuburb.value = "'" + document.frm.pSuburb.value.replace(/'/g, "") + "'";
			if (document.frm.pZip && document.frm.pZip.value != "") document.frm.pZip.value = "'" + document.frm.pZip.value.replace(/'/g, "") + "'";
			
			doSearch = true;
            break;
        default:
			document.frm.action = "listagenthomes.asp";
			document.frm.Search.value = "TRUE";
			doSearch = true;
			break;
        
    }	
	
	if (doSearch) {
		document.frm.submit();
	} else {
		alert("Please specify search criteria");
	}
}
