function blurSearchVal()
{
    document.getElementById("srchLocation").value = document.getElementById("srchLocation").value.replace(/^\s+|\s+$/g,"");
    if ((document.getElementById("srchLocation").value == "") || (document.getElementById("srchLocation").value == " "))
    {
        document.getElementById("srchLocation").value = "Enter City, State OR Zip";                                                                    
        document.getElementById("srchLocation").style.color = "#9db7e5";
        document.getElementById("srchLocation").style.textAlign = "center";
    }
    
    //_bsn.DOM.removeElement("as_searchLoc");
    setTimeout(function () { as.clearSuggestions() }, 275);
}
function focusSearchVal()
{
    if (document.getElementById("srchLocation").value == "Enter City, State OR Zip")
    {
        document.getElementById("srchLocation").value = "";    
        document.getElementById("srchLocation").style.color = "#002669";
        document.getElementById("srchLocation").style.textAlign = "left";
    }
    else
    {
        document.getElementById("srchLocation").select();
    }
}
function keypressSearchVal(ev)
{    
    var key = ev.charCode ? ev.charCode : ev.keyCode    
    //window.alert("key : " + key);
    
    var kpEl = document.getElementById("srchLocation");        
    var kpVal = kpEl.value;
    
    //var kpSel = (document.all) ? document.selection.createRange().text : window.getSelection(); 
    var kpSel = "";
    var kpPos = 0;
    if (document.selection)
    {
        kpSel = document.selection.createRange().text;
        //kpPos = document.selection.createTextRange();
        
        var kpCr = document.selection.createRange();
        var kpRg = kpEl.createTextRange();
        kpRg.setEndPoint("EndToStart", kpCr);
        var kpPos = kpRg.text.length;
    }
    else
    {
        kpSel = kpEl.value.substr(kpEl.selectionStart, (kpEl.selectionEnd - kpEl.selectionStart));
        //kpPos = kpEl.selectionEnd;
        kpPos = kpEl.selectionStart;
    }  
         
    if ( (key!=8) && (key!=9) && (key!=13) && (key!=16) && (key!=17) && (key!=18) && (key!=19) && (key!=20) && (key!=27) && (key!=32) && (key!=35) && (key!=36) && (key!=37) && (key!=38) && (key!=39) && (key!=40) && (key!=44) && (key!=46) )
    {        
        if ( (key>=65&&key<=90) || (key>=97&&key<=122) || (key>=48&&key<=57) )
        {          
            if ( (kpVal != "") && (kpVal != kpSel) )
            {                             
                if ((kpVal*1.0)==kpVal) 
                {           
                    if (key<48||key>57)
                    {
                        return false;
                    }
                    if (kpVal.length >= 5)
                    {
                        return false;
                    }    
                }
                else
                {            
                    if (key>48&&key<57)
                    {
                        return false;
                    }            
                    else if (kpVal.indexOf(",") >= 0)
                    {
                        var kpSt = kpVal.substring(kpVal.indexOf(",")+1);
                        var kpTr = kpSt.replace(/^\s+|\s+$/g,"");                        
                                                
                        if ( (kpTr.length >= 2) && (kpPos > kpVal.indexOf(",")) )
                        {
                            return false;
                        }
                    }           
                }
            }
        }
        else
        {
            return false;
        }
    }
    if (key==32)
    {
        if ( (kpVal.toLowerCase() == "st") || (kpVal.toLowerCase() == "st.") )
        {
            document.getElementById("srchLocation").value = "Saint";        
        }
        else if ( (kpVal.toLowerCase() == "ft") || (kpVal.toLowerCase() == "ft.") )
        {
            document.getElementById("srchLocation").value = "Fort";        
        }
        else if ( (kpVal.toLowerCase() == "pt") || (kpVal.toLowerCase() == "pt.") )
        {
            document.getElementById("srchLocation").value = "Point";        
        }
        else if ( (kpVal.toLowerCase() == "mt") || (kpVal.toLowerCase() == "mt.") )
        {
            document.getElementById("srchLocation").value = "Mount";        
        }
        else if ( (kpVal.toLowerCase() == "n") || (kpVal.toLowerCase() == "n.") )
        {
            document.getElementById("srchLocation").value = "North";        
        }
        else if ( (kpVal.toLowerCase() == "e") || (kpVal.toLowerCase() == "e.") )
        {
            document.getElementById("srchLocation").value = "East";        
        }
        else if ( (kpVal.toLowerCase() == "s") || (kpVal.toLowerCase() == "s.") )
        {
            document.getElementById("srchLocation").value = "South";        
        }
        else if ( (kpVal.toLowerCase() == "w") || (kpVal.toLowerCase() == "w.") )
        {
            document.getElementById("srchLocation").value = "West";        
        }
        
        if ( (kpVal == "") || (kpVal.lastIndexOf(" ") == kpVal.length-1) )
        {
            return false;
        }
        if (kpVal.indexOf(",") >= 0)
        {
            var kpSt = kpVal.substring(kpVal.indexOf(",")+1);
            var kpTr = kpSt.replace(/^\s+|\s+$/g,"");

            if ( kpTr.length >= 2 )
            {  
                return false;
            }
        }
        if ((kpVal*1.0)==kpVal) 
        {
            return false;
        }
    }
    if (key==44)
    {        
        if ( (kpVal == "") || (kpVal.indexOf(",") > 0) ) 
        {
            return false;
        }
    }
 }
function changeSearchType()
{
    var srchSearchType = document.getElementById("srchSearchType").value;
    if ((srchSearchType == "sale") || (srchSearchType == "lease") || (srchSearchType == "both"))
    {
        document.getElementById("searchSub").innerHTML =  ''+
            '<select id="srchSubTypeSel" name="srchSubTypeSel" title="Select Property Category" style="width: 118px; font-size: 12px; color: #0d3e95;">'+
                '<option value="all">All Properties</option>'+
                '<option value="office">Office</option>'+
                '<option value="retail">Retail</option>'+
                '<option value="land">Land</option>'+
                '<option value="mixed">Mixed Use</option>'+
                '<option value="indus">Industrial</option>'+
                '<option value="agri">Agriculture</option>'+
                '<option value="multifam">Multifamily</option>'+
                '<option value="hotel">Hotel/Motel</option>'+
                '<option value="health">Health Care</option>'+
                '<option value="entertain">Entertainment</option>'+
            '</select>'+
            '';        
        if (srchSearchType == "sale")
        {
            document.getElementById("searchBtn").title = "Search Properties For Sale";
            document.getElementById("searchStat").innerHTML = "Over $125 Billion Of Property For Sale";
        }
        else if (srchSearchType == "lease")
        {
            document.getElementById("searchBtn").title = "Search Properties For Lease";
            document.getElementById("searchStat").innerHTML = "Over 950 Million Square Feet For Lease";
        }
        else if (srchSearchType == "both")
        {
            document.getElementById("searchBtn").title = "Search Properties For Sale/Lease";
            document.getElementById("searchStat").innerHTML = "Over $125 Billion & 950 Million Sq Ft";
        }
    }
    else if (srchSearchType == "forum")
    {
        document.getElementById("searchSub").innerHTML =  ''+
            '<select id="srchSubTypeSel" name="srchSubTypeSel" title="Select Forum Category" style="width: 118px; font-size: 12px; color: #0d3e95;">'+
                '<option value="all">All Categories</option>'+
                '<option value="lookfor">Looking For...</option>'+
                '<option value="events">Events/Shows</option>'+
                '<option value="helpwant">Help Wanted</option>'+           
                '<option value="invest">Investments</option>'+
                '<option value="special">Special Offers</option>'+
                '<option value="opportun">Opportunities</option>'+
            '</select>'+
            '';        
        document.getElementById("searchBtn").title = "Search Forum";
        document.getElementById("searchStat").innerHTML = "Over 10,000 Forum Comments/Posts";
    }
    else if (srchSearchType == "dir")
    {
        document.getElementById("searchSub").innerHTML =  ''+
            '<select id="srchSubTypeSel" name="srchSubTypeSel" title="Select Professional Category" style="width: 118px; font-size: 12px; color: #0d3e95;">'+
                '<option value="all">All Professions</option>'+
                '<option value="broker">Brokers</option>'+
                '<option value="develop">Developers</option>'+
                '<option value="operate">Owners</option>'+
                '<option value="invest">Investors</option>'+
                '<option value="manage">Managers</option>'+
                '<option value="appraise">Appraisers</option>'+
                '<option value="inspect">Inspectors</option>'+
                '<option value="title">Title Agents</option>'+
            '</select>'+
            '';        
        document.getElementById("searchBtn").title = "Search Professional Directory";
        document.getElementById("searchStat").innerHTML = "Over 150,000 Real Estate Professionals";
    }
    else if (srchSearchType == "demo")
    {
        document.getElementById("searchSub").innerHTML =  ''+
            '<select id="srchSubTypeSel" name="srchSubTypeSel" title="Select Data Category" style="width: 118px; font-size: 12px; color: #0d3e95;">'+
                '<option value="All">All Data Types</option>'+
                '<option value="Population">Population</option>'+
                '<option value="Income">Income</option>'+
                '<option value="Economy">Economy</option>'+
            '</select>'+
            '';        
        document.getElementById("searchBtn").title = "Search Demographics Data";
        document.getElementById("searchStat").innerHTML = "Over 10 Million Demographics Records";
    }
}
function searchSubmit()
{
    var form = document.searchForm; 		
 		
	form.srchLocation.value = form.srchLocation.value.replace(/^\s+|\s+$/g,"");    
    form.srchSubType.value = document.getElementById("srchSubTypeSel").value;
    form.srchPropertyType.value = document.getElementById("srchSubTypeSel").value;    
    
	//window.alert("srchSearchType : " + form.srchSearchType.value);	
	var srchSearchType = form.srchSearchType.value;
	var srchLocation = form.srchLocation.value;
	
	var searchValType = "non";
	var searchValValid = false;
	var searchReq = "ns"
	
	if ((srchLocation == "Enter City, State OR Zip") || (srchLocation == ""))
	{	    
	    if ((srchSearchType == "sale") || (srchSearchType == "lease") || (srchSearchType == "both"))
	    {
	        searchValType = "def";
	        searchValValid = true;
	        searchReq = "def"
	        form.srchLocation.value = "";
	    }
	    else
	    {
	        searchValType = "def";
	        searchValValid = false;
	    }	    
	}
	else if (((srchLocation * 1.0) == srchLocation) && (srchLocation.length == 5))
	{	    
	    var searchLocCity = srchLocation;	    
	    searchValType = "zip";
        searchValValid = true;
	}
	else
	{
	    var searchLocArr = srchLocation.split(",");	    
	    if (searchLocArr.length == 2)
	    {
	        var searchLocCity = searchLocArr[0];
	        var searchLocState = searchLocArr[1];
	        
	        if ((searchLocCity.length > 2) && (searchLocCity.length >= 2))
	        {
	            searchValType = "cs";
                searchValValid = true;
	        }
	    }
	}	
	//window.alert("searchValType : " + searchValType);		
	
    if (!searchValValid)
    {
        window.alert("Please enter a valid Search Location - City, State OR Zip");
    }
    else
	{
	    if ((srchSearchType == "sale") || (srchSearchType == "lease") || (srchSearchType == "both"))
	    {
	       form.action = "/prop.asp";
	    }	   
	    else if (srchSearchType == "dir")
	    {
	       form.action = "/dir.asp";
	    }
	    else if (srchSearchType == "forum")
	    {
	       form.action = "/forum.asp";
	    }	    
	    else if (srchSearchType == "demo")
	    {
	       form.action = "/demo.asp";
	    }
	    else
	    {
	        window.alert("Please enter a valid Search Location - City, State OR Zip");
	    }	    
        form.req.value = searchReq;
        form.submit();
	}
}
function searchAdvanced()
{
    var form = document.searchForm;
 		
	form.srchLocation.value = form.srchLocation.value.replace(/^\s+|\s+$/g,"");

	var srchSearchType = form.srchSearchType.value;
	var srchLocation = form.srchLocation.value;	
	//window.alert(srchSearchType);
	
	if ((srchSearchType == "sale") || (srchSearchType == "lease") || (srchSearchType == "both"))
	{	   
	   form.req.value = "def";
	   form.action = "/prop.asp";
	}	
	else
	{	
        form.req.value = "eadv";
        form.action = "/search.asp?st="+srchSearchType;
    }
    
    form.submit();
}
function loadTop()
{
    blurSearchVal();
    
    //var as = new AutoSuggest('srchLocation', autoOptions);
    //new AutoSuggest('srchLocation', autoOptions);
}
