﻿
    var hidSearchType = document.getElementById(ucName + "hidSearchType"); 
    var hidAgency = document.getElementById(ucName + "hidAgency"); 
    var spSearchType = document.getElementById("spSearchType");

	function ChangeBGImage(ItemDIV,BGImages){
	     /*ItemDIV.style.background = "url('/Images/HeadSearchButton_Bigbg" + BGImages + ".gif') #fff no-repeat right top;";*/
	     
	}
    //显示所选值在层上
    function SelectValue(id,name,controlName)
    {
        document.getElementById(controlName).style.display = "none";
        var hidControl = document.getElementById(ucName + "hid" + controlName);
        var spControl = document.getElementById("sp" + controlName);
        if(hidControl == null)
        {
            hidControl = hidPrice;
        }
        hidControl.value = id;       
       
        spControl.innerHTML = name; 
    }   
      function HideDiv(divName)
    {
        var divControl = document.getElementById(divName)
        divControl.style.display = "none";
    }
    
  
    function ChangeSearchType(type)
    {
        if(type.length=0){
            type="2";
        }
        document.getElementById("SearchType").style.display = "none";
        if(document.getElementById("SearchTypeFoot"))
            document.getElementById("SearchTypeFoot").style.display = "none";
        var UcName = "SearchControl1_"; 
        var UcNameFoot = "SearchControl2_"; 
        var divAgency = document.getElementById("divAgency");
        
        var TxtKeyword = document.getElementById(UcName + "TxtKeyword");
        var TxtKeywordFoot = document.getElementById(UcNameFoot + "TxtKeyword");
        
        //TxtKeyword.value = "输入小区名称或地址";
        switch(type)
        {
            case "1":
                    spSearchType.innerHTML = "小区";
                  // TxtKeyword.value = "输入小区名称或地址";                     
                    if(TxtKeyword&&TxtKeywordFoot)
                    {
                        spSearchTypeFoot.innerHTML = "小区";
                      //  TxtKeywordFoot.value = "输入小区名称或地址"; 
                    }
                    
                break;
            case "2":                  
                    spSearchType.innerHTML = "二手房";
                   // TxtKeyword.value = "输入小区名称或地址"; 
                    if(TxtKeyword&&TxtKeywordFoot)
                    {
                        spSearchTypeFoot.innerHTML = "二手房";  
                       // TxtKeywordFoot.value = "输入小区名称或地址";    
                    }     
                break;
            case "3":       
                    spSearchType.innerHTML = "租房"; 
                    //TxtKeyword.value = "输入小区名称或地址";                     
                    if(TxtKeyword&&TxtKeywordFoot)
                    { 
                        spSearchTypeFoot.innerHTML = "租房"; 
                       // TxtKeywordFoot.value = "输入小区名称或地址"; 
                    }
                break;
            case "4":           
                    spSearchType.innerHTML = "新房";      
                    spSearchTypeFoot.innerHTML = "新房";  
                break;
            case "5":              
                    spSearchType.innerHTML = "经纪人"; 
                   // TxtKeyword.value = "输入 公司名称 或 经纪人姓名 或 手机";                    
                    if(TxtKeyword&&TxtKeywordFoot)
                    {      
                        spSearchTypeFoot.innerHTML = "经纪人"; 
                       // TxtKeywordFoot.value = "输入 公司名称 或 经纪人姓名 或 手机";
                    }
                break;      
             case "6":              
                    spSearchType.innerHTML = "中介公司";    
                    //TxtKeyword.value = "输入 公司名称 或 经纪人姓名 或 手机";
                    if(TxtKeyword&&TxtKeywordFoot)
                    {
                        spSearchTypeFoot.innerHTML = "中介公司"; 
                       // TxtKeywordFoot.value = "输入 公司名称 或 经纪人姓名 或 手机";       
                    }
                break;        
        }
        hidSearchType.value = type; 
        if(TxtKeyword&&TxtKeywordFoot)
        { 
            hidSearchTypeFoot.value=type; 
        }     
    }          
    function ShowDiv(divName,ShowType)
    {             
        var divControl = document.getElementById(divName);
        var Content = "<ul>";
        switch(ShowType)
        {
            case "SearchType"://显示搜索类型的弹出信息               
                Content += "<li><a href=\"javascript:void(0);\" onClick=\"javascript:ChangeSearchType('2');\">二手房</a></li>";                
                Content += "<li><a href=\"javascript:void(0);\" onclick=\"javascript:ChangeSearchType('3');\">租房</a></li>";
                Content += "<li><a href=\"javascript:void(0);\" onClick=\"javascript:ChangeSearchType('1');\">小区</a></li>";
//                Content += "<li><a href=\"javascript:void(0);\" onclick=\"javascript:ChangeSearchType('5');\">经纪人</a></li>";
//                Content += "<li><a href=\"javascript:void(0);\" onclick=\"javascript:ChangeSearchType('6');\">中介公司</a></li>";
                break;
        }
            Content += "</ul>";
		divControl.innerHTML = Content;
		divControl.style.display = "block";
	}
	
    try{document.forms[0].action=""}catch(ex){}   
    
    var index = 0;
    var j = 0;
    var boxtitle = document.getElementById("box-title");  
    
    function SearchPropertyName(propertyName,e)
    {       
        var len = boxtitle.childNodes.length;
        if(propertyName != "")
        {
            //向下事件            
            var key = window.event ? e.keyCode:e.which;  
           
            if(key==40)
            {
                if(len == 0)
                {
                    return;
                }                 
                if(index == 0 && j== 0)
                {
                    boxtitle.childNodes[index].className="mouseover";          
                    document.getElementById('SearchControl1_TxtKeyword').focus();           
                    document.getElementById('SearchControl1_TxtKeyword').value = boxtitle.childNodes[index].innerHTML;
                    document.getElementById("SearchControl1_hidPropertyID").value=boxtitle.childNodes[index].getAttribute("value"); 
                    j = j+1;
                    return;
                }
                boxtitle.childNodes[index].className="mouseout";
                index = index + 1;
                index == len ? index=0:index;
                index == 0 ? j =0: j;
                boxtitle.childNodes[index].className="mouseover";
                document.getElementById('SearchControl1_TxtKeyword').focus();   
                document.getElementById('SearchControl1_TxtKeyword').value = boxtitle.childNodes[index].innerHTML;     
                document.getElementById("SearchControl1_hidPropertyID").value=boxtitle.childNodes[index].getAttribute("value");                       
                return;
            }   
            //向上事件
            else if(key==38)
            {  
                if(len == 0)
                {
                    return;
                }         
                boxtitle.childNodes[index].className="mouseout";
                index = index -1 ;
                index < 0 ? index=len-1:index;   
                index == 0 ? j =0: j;  
                boxtitle.childNodes[index].className="mouseover";
                document.getElementById('SearchControl1_TxtKeyword').focus();
                document.getElementById('SearchControl1_TxtKeyword').value = boxtitle.childNodes[index].innerHTML; 
                document.getElementById("SearchControl1_hidPropertyID").value=boxtitle.childNodes[index].getAttribute("value");              
                return;
            }       
            else if(key==39 || key== 37)
            {
                return;
            }           
            
            boxtitle.innerHTML = "";
            index = 0;
            j=0;
            boxtitle.style.display="none";
            
            result = AjaxFun.SearchPropertyName(propertyName,DCityID).value    
            
            property = result.split('@@');    
            //小区ID数组
            propertyIDList = property[0].split(',');    
            //小区名称数组
            propertyNameList = property[1].split(',');
            if(propertyIDList != "")
            {
                boxtitle.style.display="block";                
                
                for(i=0 ; i< propertyIDList.length; i ++)
                {                   
                    boxtitle.innerHTML += "<div value=\""+propertyIDList[i]+"\" onclick=\"SelectDone(this);\" onmouseover=\"SetOverStyle(this);\">"+propertyNameList[i]+"</div>";   
                }       
            } 
            else
            {
                boxtitle.style.display="none";
            }          
        }
        else
        {
            boxtitle.innerHTML = "";
            boxtitle.style.display="none";
        }
    }
    
    
function SearchPropertyNameFoot(propertyName,e)
{ 
    var len = boxtitlefoot.childNodes.length;
    if(propertyName != "")
    {
        //向下事件            
        var key = window.event ? e.keyCode:e.which;  
       
        if(key==40)
        {
            if(len == 0)
            {
                return;
            }                 
            if(indexfoot == 0 && j_foot== 0)
            {
                boxtitlefoot.childNodes[indexfoot].className="mouseover";          
                document.getElementById('SearchControl2_TxtKeyword').focus();           
                document.getElementById('SearchControl2_TxtKeyword').value = boxtitlefoot.childNodes[indexfoot].innerHTML;
                document.getElementById("SearchControl2_hidPropertyID").value=boxtitlefoot.childNodes[index].getAttribute("value"); 
                j_foot = j_foot+1;
                return;
            }
            boxtitlefoot.childNodes[indexfoot].className="mouseout";
            indexfoot = indexfoot + 1;
            indexfoot == len ? indexfoot=0:indexfoot;
            indexfoot == 0 ? j_foot =0: j_foot;
            boxtitlefoot.childNodes[indexfoot].className="mouseover";
            document.getElementById('SearchControl2_TxtKeyword').focus();   
            document.getElementById('SearchControl2_TxtKeyword').value = boxtitlefoot.childNodes[indexfoot].innerHTML;
            document.getElementById("SearchControl2_hidPropertyID").value=boxtitlefoot.childNodes[index].getAttribute("value");                         
            return;
        }   
        //向上事件
        else if(key==38)
        {  
            if(len == 0)
            {
                return;
            }         
            boxtitlefoot.childNodes[indexfoot].className="mouseout";
            indexfoot = indexfoot -1 ;
            indexfoot < 0 ? indexfoot=len-1:indexfoot;   
            indexfoot == 0 ? j_foot =0: j_foot;  
            boxtitlefoot.childNodes[indexfoot].className="mouseover";
            document.getElementById('SearchControl2_TxtKeyword').focus();
            document.getElementById('SearchControl2_TxtKeyword').value = boxtitlefoot.childNodes[indexfoot].innerHTML;
            document.getElementById("SearchControl2_hidPropertyID").value=boxtitlefoot.childNodes[index].getAttribute("value");              
            return;
        }       
        else if(key==39 || key== 37)
        {
            return;
        }           
        
        boxtitlefoot.innerHTML = "";
        indexfoot = 0;
        j_foot=0;
        boxtitlefoot.style.display="none";
        
        result = AjaxFun.SearchPropertyName(propertyName,DCityID).value    
        
        property = result.split('@@');    
        //小区ID数组
        propertyIDList = property[0].split(',');    
        //小区名称数组
        propertyNameList = property[1].split(',');
        if(propertyIDList != "")
        {
            boxtitlefoot.style.display="block";                
            
            for(i=0 ; i< propertyIDList.length; i ++)
            {                   
                boxtitlefoot.innerHTML += "<div value=\""+propertyIDList[i]+"\" onclick=\"SelectDoneFoot(this);\" onmouseover=\"SetOverStyleFoot(this);\">"+propertyNameList[i]+"</div>";   
            }       
        } 
        else
        {
            boxtitlefoot.style.display="none";
        }          
    }
    else
    {
        boxtitlefoot.innerHTML = "";
        boxtitlefoot.style.display="none";
    }
}
    
    function SetOverStyle(which)
    {        
        var len = boxtitle.childNodes.length;
        
        for(i=0; i < len ; i ++)
        {
             boxtitle.childNodes[i].className="mouseout";
             if(boxtitle.childNodes[i] == which)
             {
                index = i;                
             }   
        }
        which.className="mouseover";
        j=0;
    }    
    function SetOverStyleFoot(which)
    {        
        var len = boxtitlefoot.childNodes.length;
        
        for(i=0; i < len ; i ++)
        {
             boxtitlefoot.childNodes[i].className="mouseout";
             if(boxtitlefoot.childNodes[i] == which)
             {
                indexfoot = i;                
             }   
        }
        which.className="mouseover";
        j=0;
    }    
    function SelectDone(which)
    {       
        j = 0;
        document.getElementById("SearchControl1_TxtKeyword").value=which.innerHTML;    
        document.getElementById('box-title').style.display='none';
        document.getElementById("SearchControl1_hidPropertyID").value=which.getAttribute("value");   
        document.getElementById('SearchControl1_BtnSearch').click();
    }
    function SelectDoneFoot(which)
    {       
        j = 0;
        document.getElementById("SearchControl2_TxtKeyword").value=which.innerHTML; 
        document.getElementById('box-title-foot').style.display='none';
        document.getElementById("SearchControl2_hidPropertyID").value=which.getAttribute("value");   
        document.getElementById('SearchControl2_BtnSearch').click();
    }
    
    document.onclick = function()
    {
         index = 0;
         j = 0;
         document.getElementById('box-title').style.display='none';
         Agency_index = 0;
         jk = 0;
         indexfoot = 0;
         j_foot = 0;   
         if(document.getElementById('AgencyBoxTitle')!=null)
            document.getElementById('AgencyBoxTitle').style.display='none';
         if(document.getElementById('box-title-foot'))
            document.getElementById('box-title-foot').style.display='none';
    }   