﻿// JScript File

var intIndex=0;
var arrList = new Array();

function GetList_callback(response)
{  
    var strList="";
    strList=response.value;
    dearray(strList);
    intIndex = arrList.length;

    smanPromptList(arrList,"ID_SearchBar.ascx_TextBoxQuery");
    //smanPromptList(arrList,"TextBoxQuery_Bottom");
}
function dearray(aa)//difine array
{
    //document.write(aa);
    arrList = aa.split(',');
    intIndex = arrList.length;
}

function GetList() {     
    init();
    Searcher.AjaxList.GetList(GetList_callback);
    document.getElementById("ID_SearchBar.ascx_TextBoxQuery").select();
}

function init() {
if (arrList.constructor!=Array){alert('smanPromptList init error:first para is not array!');return ;}
    arrList.sort( function(a, b) {
    if(a.length>b.length)return 1;
    else if(a.length==b.length)return a.localeCompare(b);
    else return -1;
        }
    ); 
}

function smanPromptList(arrList,objInputId){
        var objouter=document.getElementById("__smanDisp")
        var objInput = document.getElementById(objInputId);
        var selectedIndex=-1;
        var intTmp;

        if (objInput==null) {alert('smanPromptList init error:can not find"'+objInputId+'"textbox');return ;}
        
        objInput.onblur=function(){
            objouter.style.display='none';
        }
       
        objInput.onkeyup=checkKeyCode;
        
        objInput.onfocus=checkAndShow;
        function checkKeyCode(evt){
		    evt = evt || window.event;
            var ie = (document.all)? true:false
            if (ie){
                var keyCode=evt.keyCode
                if (keyCode==40||keyCode==38){
                    var isUp=false
                    if(keyCode==40) isUp=true ;
                    chageSelection(isUp)
                }else if (keyCode==13){
                    outSelection(selectedIndex);
                }else{
                    checkAndShow(evt)
                }
            }else{
                checkAndShow(evt)
            }
            divPosition(evt)
        }

        function checkAndShow(evt){
                    var strInput = objInput.value
                    if (strInput!=""){
                        divPosition(evt);
                        selectedIndex=-1;
                        objouter.innerHTML ="";      
                                          
                        var Limit = 10; //Show 10 Items
                        
                       objouter.innerHTML +="<DIV><table><tr><td>";
                       for (intTmp=0;intTmp<arrList.length;intTmp++){
                            if (arrList[intTmp].substr(0, strInput.length)==strInput){
                                addOption(arrList[intTmp]);
                                Limit = Limit - 1;
                                if(Limit<=0)break;
                            }
                        }
                        objouter.innerHTML +="</td></tr></table>"
			            objouter.innerHTML +="<iframe src=\"javascript:false\" style=\"position:absolute; visibility:inherit; top:0px; left:0px; z-index:-1; filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';\"></iframe>"
                        objouter.innerHTML +="</DIV>"
             
                        objouter.style.display='';
                    }else{
                        objouter.style.display='none';
        }
        function addOption(value){  
            var strTemp = value
            var arrTemp = new Array();
            var strSpace = "";
            var len;
            ////var intLength = objInputId.Width;
            //var intLength = 30;    	
	
            arrTemp = value.split('@');
            //for (len=0;len<intLength - (strTemp.match(/[^ -~]/g)==null?strTemp.length:strTemp.length+strTemp.match(/[^ -~]/g).length-1);len++){
            //    strSpace="&nbsp;&nbsp;"+strSpace;
            //}
            //objouter.innerHTML +="<div onmouseout=\"this.className=''\" onmousedown=\"document.getElementById('"+objInputId+"').value='" + arrTemp[0] + "'\">" + arrTemp[0] + strSpace +"已查询"+arrTemp[1] + "次</div>"    
            
            //objouter.innerHTML +="<div><table border=0 cellspacing=0 cellpadding=0 width=100% style='FONT-SIZE:10pt;'><tr style=\"cursor:default\" onmouseover=\"this.className='sman_selectedStyle'\" onmouseout=\"this.className=''\"  onmousedown=\"document.getElementById('"+objInputId+"').value='" + arrTemp[0] + "'\"><td align=left>"+arrTemp[0]+"</td><td align=right style=\"color:#4A5989\">约"+arrTemp[1]+"次查询</td></tr></table></div>"
            objouter.innerHTML +="<div><table border=0 cellspacing=0 cellpadding=0 width=100% style='FONT-SIZE:10pt;'><tr style=\"cursor:default\" onmouseover=\"this.className='sman_selectedStyle'\" onmouseout=\"this.className=''\"  onmousedown=\"document.getElementById('"+objInputId+"').value='" + arrTemp[0] + "'\" ><td align=left>"+arrTemp[0]+"</td><td align=right style=\"color:#4A5989\">约"+arrTemp[1]+"次查询</td></tr></table></div>"
            
            
        }
        }
        function chageSelection(isUp){
            if (objouter.style.display=='none'){
                objouter.style.display='';
            }else{
                if (isUp)
                    selectedIndex++
                else
                    selectedIndex--
            }
            var maxIndex = objouter.children.length-1;
            if (selectedIndex<0){selectedIndex=0}
            if (selectedIndex>maxIndex) {selectedIndex=maxIndex}
            for (intTmp=0;intTmp<=maxIndex;intTmp++){

                if (intTmp==selectedIndex){
                    objouter.children[intTmp].className="sman_selectedStyle";
                }else{
                    objouter.children[intTmp].className="";
                }
            }
        }
        function outSelection(Index){
            if(objouter.children[Index]!=null)
            {
                var tt = objouter.children[Index].innerText;
                tt = tt.replace(/约(\d+)次查询/g,"");
                objInput.value = tt
                objouter.style.display='none';                
            }
            document.getElementById("ID_SearchBar.ascx_ButtonSearch").click();
        }
        function divPosition(evt){
            var left = 0;
            var top  = 0;				
			var e = objInput;
            while (e.offsetParent){
	            left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
	           top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
	          e     = e.offsetParent;
           }

          left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
          top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);

            objouter.style.top    = (top  + objInput.clientHeight) + 'px' ;
            objouter.style.left    = left + 'px' ; 
            objouter.style.width= objInput.clientWidth;
        }
    }
    
    document.write("<div id='__smanDisp' style='position:absolute;display:none;background:#D6E5FB;border: 1px solid #CCCCCC;font-size:14px;cursor: default;' onbulr> </div>");
    document.write("<style>.sman_selectedStyle{background-Color:#93BCF4;color:#000000}</style>");
    
    function getAbsoluteHeight(ob){
        return ob.offsetHeight
    }
    
    function getAbsoluteWidth(ob){
        return ob.offsetWidth
    }
    
    function getAbsoluteLeft(ob){
        var mendingLeft = ob .offsetLeft;
        while( ob != null && ob.offsetParent != null && ob.offsetParent.tagName != "BODY" ){
            mendingLeft += ob .offsetParent.offsetLeft;
            mendingOb = ob.offsetParent;
        }
        return mendingLeft ;
    }
    
    function getAbsoluteTop(ob){
        var mendingTop = ob.offsetTop;
        while( ob != null && ob.offsetParent != null && ob.offsetParent.tagName != "BODY" ){
            mendingTop += ob .offsetParent.offsetTop;
            ob = ob .offsetParent;
        }
        return mendingTop ;
    }

Number.prototype.NaN0 = function()
{
    return isNaN(this)?0:this;
}

function SubmitKeyClick() 
{    
    if (event.keyCode == 13) 
    {        
        event.returnValue=false;
        event.cancel = true;
//        var objouter=document.getElementById("__smanDisp")
//        if(objouter.style.display=='none')
//        {
//            document.getElementById("ID_SearchBar.ascx_ButtonSearch").click();
//        }
//        else        
//        {
//            objouter.style.display=='none'
//        }
    } 
} 

function ClearText(e) 
{     
    if(e.value=="请输入地理位置或小区名称")
    {
        e.value="";
        e.select();
    }
}
function FillText(e) 
{     
    if(e.value=="")
    {
        e.value="请输入地理位置或小区名称";
        e.select();
    }
}

function ShowHideTable(value) 
{     
    if(document.getElementById(value).style.display=="none")
    {
        if(getOs()=="Firefox")
        {
            document.getElementById(value).style.display="";
        }
        else
            document.getElementById(value).style.display="block";
    }
    else
        document.getElementById(value).style.display="none";
}

function OpenWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function CloseWindow(){
 window.close();
}

function getOs()
{
var OsObject = "";
if(navigator.userAgent.indexOf("MSIE")>0) {
return "MSIE";
}
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
return "Firefox";
}
if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
return "Safari";
}
if(isCamino=navigator.userAgent.indexOf("Camino")>0){
return "Camino";
}
if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
return "Gecko";
}
}