﻿/*
当前版本：1.8.0522.1

修改历史：

版本：1.8.0522.1
========================
1 对城市推荐添加拼音显示
2 在input输入框中添加suggestType属性，没有采用默认处理，如果suggestType=“city”，对应处理城市推荐

版本：1.7.1029.1
========================
1 在隐藏suggest时，清空里面的内容。
  这样做避免了当从一个suggest框到另一个suggest框后，直接按下左右箭头键
  会显示上一个suggest框的内容。

版本：1.7.1012.2
========================
1 修改bind方法，为每个suggest文本框指定单独的posturl。
2 增加用户选择关键字后的回调函数。

版本：1.7.810
========================
1 增加请求处理方式参数（requestMode），根据参数调用相应的请求处理函数。
  
  
版本：1.7.718.2
========================
1 解决当页面载入，输入框中有默认值也会自动请求服务器的问题。

版本：1.7.629.1
========================
1 IE中无建议关键字时会显示一个空行

版本：1.7.628.1
========================
1 IE下无法选中一行，只有当鼠标滑动在文字上才会选中一行
2 输入法打开状态下，无法显示suggest
3 输入法打开状态下，按下回车键会隐藏suggest
4 进行了部分代码优化
5 自动设置inputText的autocomplete属性为off


版本：1.7.627.1
========================
1 window.onResize改为附加（attach）方式
2 keyUp增加了timeout控制
3 当用户在suggest选择项目进行回车键（keyCode:13）确定时阻止窗体的自动提交

*/


/*
使用说明：
在input文本框标签中增加issuggest="yes"属性后，
然后调用mapbarInputSuggest.bind()方法。

mapbarInputSuggest.bind()参数说明：
posturl: 建议关键字查询接口url。
requestMode: 请求处理方式。
requestDelegate: 当请求处理方式为custom时的处理函数，用它来覆盖默认的请求处理方式。
                 方法特征为：
				 requestDelegate(posturl,callback)
				 posturl: 查询接口url
				 callback: 回调函数

文本框可使用的自定义属性：
issuggest: 如果值为"yes"则表示为本文本框增加suggest。
city: 用户查询的城市范围，默认为"北京市"。
enterkey_bubble: 当用户在suggest选择项目进行回车键（keyCode:13）确定时是否阻止窗体的自动提交。
posturl: 此文本框数据源的接口url。
selectdone_callback: 用户选择关键字后的回调函数。
*/



/*
mapbarInputSuggest构造函数options参数说明
options是一个结构，有如下属性：
inputid: 文本框ID
posturl: 默认的数据源接口url，文本框本身的posturl会覆盖此设置
requestMode: 请求处理方式，可选值有：
             ajax: 采用标准的ajax方式处理。
			 script: 采用script块的方式处理.（默认）
			 custom: 由调用方提供处理函数
requestDelegate: 函数指针，覆盖默认的数据请求方式。
selectDoneCbk: 用户选择关键字后的回调函数。
               函数声明格式为：selectDoneCbk(suggest_text)，suggest_text参数为用户选择的关键字。
*/


/////TEST_MS_BUG//////
var ms_bug_value;
/////TEST_MS_BUG//////

function mapbarInputSuggest(options)
{
    //如果options.inputid标识的文本输入框不存在则退出
    var inputid = options.inputid || "";
    this.inputField = document.getElementById(inputid);
    if (!this.inputField) return;
    else
    {
         this.inputField.setAttribute("autocomplete", "off");
    }
    this.className = "citySuggest"||"";
	this.suggestType = this.inputField.getAttribute("suggestType")||"";
	this.requestMode = options.requestMode || "script";
	this.requestDelegate = options.requestDelegate;
	this.selectDoneCbk = options.selectDoneCbk || "";
    this.lastKeyCode = -1;
    this.eventKeycode = "";
    this.lastText = this.inputField.value;
    this.cursorUpDownPressed=false;
    this.xmlHttp=null;
    this.selectSuggestIndex = 0 ;
    this.suggestDiv = null;
    this.keyupTimer = null;
    this.filterEnterKey = false;
    this.keyupTimerId = "";
    this.lostFocus = true;
    //滚动始，终位置
    this.startIndex = 1;
    this.endIndex = 0;
    this.divTag = "div";
    //suggest style
    this.suggestid = "suggestDiv";
    this.ca=1;
    this.Aa=1;
    this.bgColor = "#0000ff";
    this.foreColor = "#FFFFFF";
    //post url
    this.url = options.posturl || "";
    if (this.url =="") return;



    //***********************注册键盘事件部分*******************************//
    this.onBlurHandler = function(event){

      this.lostFocus = true;

      if(!event&&window.event) {
        event=window.event;
      }

      if(!this.cursorUpDownPressed){
        this.hidesuggestDiv();
        // check if tab pressed...
        if(this.lastKeyCode==9){
          this.lastKeyCode=-1;
        }
      }
      this.cursorUpDownPressed=false;
    }

    this.onFocusHandler = function()
    {
        this.lostFocus = false;
    }

    this.onKeyPressHandler = function(obj)
    {

      //当用户在suggest选择项目回车确定时阻止窗体的自动提交
      var e = this.onKeyPressHandler.caller.arguments[0] || window.event;
      var keycode = e.keyCode || e.which;
      if (keycode == 13 && obj.filterEnterKey)
      {
        if ( this.suggestDiv.style.display != "none" && this.selectSuggestIndex != 0)
        {
            if (window.event) {
                e.returnValue = false;
                e.cancelBubble = true;

            } else {
                e.preventDefault();
                e.stopPropagation();
            }
        }
      }
    }

    //
    this.okuh=function(obj){

      var e = this.okuh.caller.arguments[0] || window.event;
      obj.eventKeycode=e.keyCode || e.which;
      obj.handleKeyEvent();


    };

    this.onChangeHandler = function(thisObj)
    {

		if (thisObj.inputField.value == thisObj.inputField.defaultValue) return;

        var V = thisObj.inputField.value;
        if (thisObj.lastText!=V)
        {

            if (V!="")
            {
                V = V.substring(V.length-1,V.length);
            }
            thisObj.eventKeycode=V;
            thisObj.handleKeyEvent();
        }
    }

    //
    this.setInputFieldFocus=function(){
      this.inputField.focus();
    };

    //
    this.handleKeyEvent = function (){

      // 39 is right cursor key 37 is left cursor key
      // show div
      if (this.eventKeycode==39 || this.eventKeycode==37)
      {
          if (this.suggestDiv == null || (this.suggestDiv != null && this.suggestDiv.style.display!="none"))
          {
            return;
          }
      }
      // 38 is up cursor key, 40 is down cursor key...
      if(this.eventKeycode==40||this.eventKeycode==38) {
        this.setInputFieldFocus();
      }
      var V=this.inputField.value;

      if(this.eventKeycode!=0){
          if(this.eventKeycode==13||this.eventKeycode==3){
              var d=this.inputField;
              if(d.createTextRange){
                var t=d.createTextRange();
                t.moveStart("character",d.value.length);
                t.select();
              } else if (d.setSelectionRange){
                d.setSelectionRange(d.value.length,d.value.length);
              }
        } else {
          if(this.inputField.value!=V) {
            this.selectEntry(V);
          }
        }
      }
      if(this.handleCursorUpDownEnter(this.eventKeycode)&&this.eventKeycode!=0)
      {
         if (this.lastText!=V || this.eventKeycode==39 || this.eventKeycode==37)
         {
            this.lastText = V;

            window.clearTimeout(this.keyupTimerId);

            if (V!="")
            {
                var delegate = function(thisObj,para1,para2)
                {
                    return function()
                    {
                        thisObj.getSuggestInfo(para1,para2);
                    }
                }

                //this.keyupTimerId = window.setTimeout(delegate(this,V,this.inputField.getAttribute("city")||"北京市"),250);
                var hidectrl = document.getElementsByName("city")[0] || {value:"北京市"};
                this.keyupTimerId = window.setTimeout(delegate(this,V,this.inputField.getAttribute("city")||hidectrl.value),250);

            }
            else
            {
                //this.showSuggestList([],document.getElementById(this.suggestid));
                this.showSuggestList([],this.suggestDiv);
            }
         }
      }


    }



    //文本框赋值
    this.selectEntry = function(text){
      this.inputField.value=text;
      this.lastText = text;
	  if(this.selectDoneCbk != "") eval(this.selectDoneCbk + "('" + text + "')");
    }

    this.getDivInnerHtml = function(div_id){
        var value = "";
        //if(document.getElementById(div_id)) value = document.getElementById(div_id).innerHTML;
        if(document.getElementById(div_id)) value = document.getElementById(div_id).getAttribute("value");
        
		/////TEST_MS_BUG//////
		ms_bug_value=value;
		/////TEST_MS_BUG//////
		
		return value;
    }

    this.setStyleForPerElement = function(c){
        if(document.getElementById(c)){
        	document.getElementById(c).style.background=""; 
        	document.getElementById(c).style.color="";
        }
    }

    this.setStyleForElement = function(c,km){
    	
    	if(this.suggestType.length!=0&&this.suggestType == "city") {
    		var temp = c ;
    		var pre = c-1;
        	var next = c+1;

        	c="s_"+c;
        	if(pre==this.startIndex-1)pre=this.endIndex;
        	if(next==this.endIndex+1)next=this.startIndex;
        	pre = "s_"+pre;
       	 	next = "s_"+next;
        	if(document.getElementById(c)) {
        	//alert(document.getElementById("ul_"+temp).style.height);
        	document.getElementById(c).style.background=this.bgColor;document.getElementById(c).style.color=this.foreColor;}
        	if(document.getElementById(pre)&&km=="key"){
        	document.getElementById(pre).style.background="";document.getElementById(pre).style.color="";}
        	if(document.getElementById(next)&&km=="key"){
        	document.getElementById(next).style.background="";document.getElementById(next).style.color="";}
        	if(document.getElementById(c)&&km=="key")this.selectEntry(this.getDivInnerHtml(c));
    	}
    	else {
        	var pre = c-1;
        	var next = c+1;

        	c="s_"+c;
        	if(pre==this.startIndex-1)pre=this.endIndex;
        	if(next==this.endIndex+1)next=this.startIndex;
        	pre = "s_"+pre;
        	next = "s_"+next;
        	if(document.getElementById(c)){document.getElementById(c).style.background=this.bgColor;document.getElementById(c).style.color=this.foreColor;}
        	if(document.getElementById(pre)&&km=="key"){document.getElementById(pre).style.background="";document.getElementById(pre).style.color="";}
        	if(document.getElementById(next)&&km=="key"){document.getElementById(next).style.background="";document.getElementById(next).style.color="";}
        	if(document.getElementById(c)&&km=="key")this.selectEntry(this.getDivInnerHtml(c));
        }
    }

    this.highlightNewValue = function(index,km){
      if(index<this.startIndex){
        index = this.endIndex;
      }
      if(index>this.endIndex){
        index = this.startIndex;
      }

		/////TEST_MS_BUG//////
		ms_bug_value=this.getDivInnerHtml("s_"+index);
		/////TEST_MS_BUG//////

      this.setStyleForElement(index,km);
      this.selectSuggestIndex =index;
    }

    //上下滚动选择 flag
    this.handleCursorUpDownEnter = function(eventCode){
      this.clearStyle();
      var keyEnable = true;
      if(eventCode==40){
        this.highlightNewValue(parseInt(this.selectSuggestIndex)+1,"key");
        return false;
      }else if(eventCode==38){
        this.highlightNewValue(parseInt(this.selectSuggestIndex)-1,"key");
        return false;
      }else if(eventCode==13||eventCode==3){
        if ( this.suggestDiv.style.display != "none" && this.selectSuggestIndex != 0)
        {
            this.hidesuggestDiv();
        }

		/////TEST_MS_BUG//////
		if(typeof ms_bug_value!="undefined" && ms_bug_value!="undefined"){
			this.selectEntry(ms_bug_value);
			ms_bug_value="undefined";
		}
		/////TEST_MS_BUG//////

        return false;
      }
      //继续添加不屏蔽键

      return keyEnable;
    }

    //初始化层及相应事件　
    this.initACPartTwo = function(){

      if (this.inputField.getAttribute("enterkey_bubble") == "yes")
      {
          this.filterEnterKey = true;
      }

      var eventHandler = function (obj)
      {
        return function()
        {
          obj.onBlurHandler(obj);
        }
      }

      this.inputField.onblur=eventHandler(this);

      eventHandler = function (obj)
      {
        return function()
        {
          obj.onFocusHandler(obj);
        }
      }

      this.inputField.onfocus = eventHandler(this);

      eventHandler = function (obj)
      {
        return function()
        {
          obj.onKeyPressHandler(obj);
        }
      }
      

      this.inputField.onkeypress = eventHandler(this);

      eventHandler = function(obj)
      {
        return function()
        {
            obj.okuh(obj);
        }
      }

      this.inputField.onkeyup = eventHandler(this);

      if (!(this.suggestDiv = document.getElementById(this.suggestid)))
      {
          this.suggestDiv=document.createElement("DIV");
          this.suggestDiv.className = this.className;
          this.suggestDiv.id=this.suggestid;
          this.suggestDiv.style.borderRight="black "+this.ca+"px solid";
          this.suggestDiv.style.borderLeft="black "+this.ca+"px solid";
          this.suggestDiv.style.borderTop="black "+this.Aa+"px solid";
          this.suggestDiv.style.borderBottom="black "+this.Aa+"px solid";
          this.suggestDiv.style.zIndex="100";
          this.suggestDiv.style.paddingRight="0";
          this.suggestDiv.style.paddingLeft="0";
          this.suggestDiv.style.paddingTop="0";
          this.suggestDiv.style.paddingBottom="0";
          this.setsuggestDivSize();
          this.suggestDiv.style.display="none";
          this.suggestDiv.style.position="absolute";
          this.suggestDiv.style.backgroundColor="white";
          document.body.appendChild(this.suggestDiv);

          eventHandler = function(obj)
          {
              return function()
              {
                  obj.resizeHandler(obj);
              }
          }

          if (window.HTMLElement)
          {
              //fire fox
              window.addEventListener("resize",eventHandler(this),false);
          }
          else
          {
              //ie
              window.attachEvent("onresize",eventHandler(this));
          }

      }

      eventHandler = function(thisObj)
      {
          return function()
          {
              thisObj.onChangeHandler(thisObj);
          }
      }
      window.setInterval(eventHandler(this),100);

    }
    //捕获浏览器改变大小事件　
    this.resizeHandler = function(instance){
      instance.setsuggestDivSize();
    }


    this.setinputFieldSize = function(){
      var xa=document.body.scrollWidth-220;
      xa=0.73*xa;
      this.inputField.size=Math.floor(xa/6.18);
    }

    this.lb = function(n){
      var N=-1;
      if(n.createTextRange){
        var fa=document.selection.createRange().duplithis.cate();
        N=fa.text.length;
      }else if(n.setSelectionRange){
        N=n.selectionEnd-n.selectionStart;
      }
      return N;
    }

    this.bb = function(n){
      var v=0;
      if(n.createTextRange){
        var fa=document.selection.createRange().duplicate();
        fa.moveEnd("textedit",1);
        v=n.value.length-fa.text.length;
      }else if(n.setSelectionRange){
        v=n.selectionStart;
      }else{
        v=-1;
      }
      return v;
    }
    this.cc = function(d){
      if(d.createTextRange){
        var t=d.createTextRange();
        t.moveStart("character",d.value.length);
        t.select()
      } else if(d.setSelectionRange) {
        d.setSelectionRange(d.value.length,d.value.length)
      }
    }
    //**************************设置suggest框的位置********************************
    this.calculateWidth = function(){
      if(navigator&&navigator.userAgent.toLowerCase().indexOf("msie")==-1){
        return this.inputField.offsetWidth-this.ca*2;
      }else{
        return this.inputField.offsetWidth;
      }
    }
    this.calculateOffsetLeft = function(r){
      return this.Ya(r,"offsetLeft");
    }
    this.calculateOffsetTop = function(r){
      return this.Ya(r,"offsetTop");
    }
    this.Ya = function(r,attr){
      var kb=0;
      while(r){
        kb+=r[attr];
        r=r.offsetParent;
      }
      return kb;
    }
    this.setsuggestDivSize = function(){
      if(this.suggestDiv){
        this.suggestDiv.style.left=this.calculateOffsetLeft(this.inputField)+"px";
        this.suggestDiv.style.top=this.calculateOffsetTop(this.inputField)+this.inputField.offsetHeight-1+"px";
        
        if(null==this.suggestType || this.suggestType.length==0) {
        	this.suggestDiv.style.width=this.calculateWidth()+"px";
        }
        else {
        	this.suggestDiv.style.width=2*this.calculateWidth()+"px";
        }
      }
    }
    //**************************控制suggest框的显示和隐藏*******************************************
    this.showsuggestDiv = function(){
      if (!this.lostFocus)
      {
          document.getElementById(this.suggestid).style.display="";
          this.setsuggestDivSize();
      }
    }
    this.hidesuggestDiv = function(){
	  document.getElementById(this.suggestid).innerHTML = "";
      document.getElementById(this.suggestid).style.display="none";
    }
    //***********************获取信息并显示部分*******************************//
    //获取xmlHttpRequest对象
    this.getxmlHttp = function (){
        var A=null;
        if (window.ActiveXObject)
        {
          try{

            A=new ActiveXObject("Msxml3.XMLHTTP");

          }catch(e){
          try{

            A=new ActiveXObject("Microsoft.XMLHTTP");

          } catch(oc){

            A=null;

          }}
        }
        else if (window.XMLHttpRequest)
        {
            A=new XMLHttpRequest();
            if (A.overrideMimeType)
                A.overrideMimeType('text/xml');

        }
        
        return A;
    }
    this.getSuggestInfo = function (keyword,city){

      var para = "keyword="+encodeURI(keyword)+"&city="+encodeURI(city);
	    var posturl = this.url + para;
	        
		if(this.requestMode=="ajax"){

    		
			if(this.xmlHttp&&this.xmlHttp.readyState!=0) this.xmlHttp.abort();

			this.xmlHttp=this.getxmlHttp();
			if(this.xmlHttp){

				this.xmlHttp.open("GET",posturl,true);

				var stateChangeWrapper = function()
				{
					return function()
					{
						if(this.xmlHttp.readyState==4&&this.xmlHttp.responseText) {
							if(this.xmlHttp.responseText.charAt(0)!="<"){
								eval(this.xmlHttp.responseText);
								this.createlist();
							}
						}
					}
				}

				this.xmlHttp.onreadystatechange=stateChangeWrapper();
				this.xmlHttp.send(null);

			}

		}else if(this.requestMode=="script"){

			this.getSuggestInfoByScriptBlock(posturl);

		}else if(this.requestMode=="custom"&&this.requestDelegate){
    		
			var getCallback = function(thisObj){

				return function(){

					thisObj.createlist();

				}

			}
    		this.requestDelegate(posturl,getCallback(this));
    		
    	}
      
    }
	this.getSuggestInfoByScriptBlock = function(url){

		var id = "__suggestRequest";
        var head=document.getElementsByTagName("head")[0];
        var sT = document.getElementById(id);
        if (sT) {sT.parentNode.removeChild(sT);}
        var s = document.createElement("script");
        head.appendChild(s);
        s.setAttribute("language", "javascript");
		s.setAttribute("type", "text/javascript");
		s.setAttribute("id", id);
		s.setAttribute("src", url);

		var cFun = function(thisObj){

			return function(){

				if (typeof ActiveXObject!="undefined") 
				{
					if(s.readyState&&s.readyState=="loaded")
					{
						thisObj.createlist();
					}
				}
				else
				{

					thisObj.createlist();

				}

			}

		}

        s.onload=s.onreadystatechange=cFun(this);

	}
    this.createlist = function (){
        if (typeof jsondata == "undefined") {
            jsondata = {results:[]};
        }
        var aSuggestions = [];
        for (var i = 0; i < jsondata.results.length; i++)
        {
        	//add by zzx on 20080514
        	var ename = jsondata.results[i].ename;
        	if( typeof ename =="undefined" ) {
        		aSuggestions.push({ 'id':jsondata.results[i].id, 'value':jsondata.results[i].value, 'info':jsondata.results[i].info });
        	}
        	else {
        		aSuggestions.push({ 'id':jsondata.results[i].id, 'value':jsondata.results[i].value, 'info':jsondata.results[i].info, 'ename':jsondata.results[i].ename });
        	}
            //end 
        }

        this.showSuggestList(aSuggestions);
    }
    //显示suggest列表
    this.showSuggestList = function(arr){
    	
	  if(document.getElementById("lessCityList")) {
	  	document.getElementById("lessCityList").style.display="none";
	  }

      //避免叠加显示,每次清空一次
      var cdiv = this.suggestDiv;
      while(cdiv.childNodes.length>0) {
        cdiv.removeChild(cdiv.childNodes[0]);
      }
      if(this.suggestType.length!=0&&this.suggestType == "city") {
			if(arr.length == 0) {
				if(this.inputField.value.length == 0) {
					this.hidesuggestDiv();
					return;
				} else {
					/*var div=document.createElement("DIV"); 
		 			div.className = "divsuggest";
		 			div.innerHTML = "对不起，找不到"+this.inputField.value;
		 			cdiv.appendChild(div);*/
		 			this.hidesuggestDiv();
					return;	
				}
		 				
      		} else {
				var div=document.createElement("DIV"); 
				div.className = "divsuggest";  
				var value = this.inputField.value; 
				/*if(null != value && value.length>7) {
					value = value.substring(0,7);
				}*/
		 		div.innerHTML = value+"，按拼音排序";	   
		 		cdiv.appendChild(div);	   		
     	 	}
      } else {
      		if (arr.length==0){
      			this.hidesuggestDiv();
      			return;
      		}
      }
      
      //取出数据放入div ,同时为div注册鼠标事件　
      for(var i=0; i<arr.length; i++){
        var u=document.createElement("DIV");
        u.id = "s_" + arr[i].id;
        u.style.fontSize = "13px";
        u.style.width = "100%";
        u.setAttribute("value",arr[i].value);
		
        var eventWrapper = function(obj)
        {
            return function()
            {
                obj.MOver(obj);
            }
        }
        u.onmouseover = eventWrapper(this);
        

        eventWrapper = function(obj)
        {
            return function()
            {
                obj.MDown(obj);
            }
        }
        u.onmousedown = eventWrapper(this);

        eventWrapper = function(obj)
        {
            return function()
            {
                obj.MOut(obj);
            }
        }
        u.onmouseout = eventWrapper(this);
		
		//add by zzx on 20080514 for 
		//添加对拼音的排序的输出 
		if( this.suggestType.length==0 || this.suggestType == "") {
			u.innerHTML=arr[i].value;
		}
        else {
        	//为下面技术数据总数使用
        	//this.divTag = "ul";
        	
        	/*ul = document.createElement("p");
        	ul.id = "ul_"+arr[i].id;
			ul.className="ulcss";
			
			var ll = document.createElement("p");
			ll.className = "lititlecss";
			ll.id = "ename_" + arr[i].id ;
			ll.innerHTML = arr[i].ename;
			ll.setAttribute("value", arr[i].value);
			u.appendChild(ll);
		
			var ll2 = document.createElement("p");
			ll2.className = "lititlecss";
			ll2.id = "value_" + arr[i].id ;
			ll2.innerHTML = arr[i].value;
			ll2.setAttribute("value", arr[i].value);
			
			u.appendChild(ll2);
			//u.appendChild(ul);
			*/
			u.innerHTML=("<table border='0px' style='width:100%;' id='tb_"+arr[i].id+"'><tr id='tr_"+
			arr[i].id+"'><td valign='top' style='width:50%' id='td_"+arr[i].id+"' value ="+arr[i].value+">"+arr[i].value+"</td><td id='td2_"+arr[i].id+
			"' style='text-align:right' value="+arr[i].value+">"+arr[i].ename+"</td></tr></table>");
        }
        // End 
        cdiv.appendChild(u);
        if( i>10 && this.suggestType.length!=0 && this.suggestType == "city") {
       		var ua=document.createElement("div");
       		ua.style.textAlign = "right";
       		ua.style.padding = "2px";
        	var lessArr=[];
        	lessArr.push("<a class=\"morecityspan\" style = 'color:#000000;' href ='javascript:void(0)' id=\"moreCityA\" onmousedown=\"window.open('/help/city.html','_blank')\">更多&nbsp;&raquo;</a>");
        	ua.innerHTML = lessArr.join("");
        	cdiv.appendChild(ua);
        	break;
        }
      }

      this.selectSuggestIndex = 0;
      this.showsuggestDiv();
      this.getTagCountByName(this.suggestDiv);
    }

    //获取列表总条数
    this.getTagCountByName = function (tag){
        var count = tag.getElementsByTagName(this.divTag);
        this.endIndex = count.length;
    }
    //清除样式
    this.clearStyle = function (){
//        for(var i=0;i<this.endIndex;i++){
//            if(document.getElementById("s_"+i)){
//                document.getElementById("s_"+i).style.background="";
//                document.getElementById("s_"+i).style.color="";
//            }
//        }
        if (this.selectSuggestIndex!=0)
        {
            if(document.getElementById("s_"+this.selectSuggestIndex)){
                document.getElementById("s_"+this.selectSuggestIndex).style.background="";
                document.getElementById("s_"+this.selectSuggestIndex).style.color="";
            }
        }
    }
    //**************************鼠标经过事件*********************************
    this.MDown=function(instance){
        var e = this.MDown.caller.arguments[0] || window.event;
        var srcElement = e.srcElement || e.target;
        var value = document.getElementById(srcElement.id).getAttribute("value");
        if(this.suggestType=="city") {
        	value = document.getElementById(srcElement.id).getAttribute("value");
        }

		/////TEST_MS_BUG//////
		this.inputField.blur();
		this.inputField.focus();
		ms_bug_value="undefined";
		/////TEST_MS_BUG//////

        instance.selectEntry(value);
        instance.hidesuggestDiv();
    }
    this.MOver=function(instance){
    
        instance.clearStyle();
        var e = this.MOver.caller.arguments[0] || window.event;
        var srcElement = e.srcElement || e.target;
        var s_id = srcElement.id.substring(2);
        if( this.suggestType.length!=0 && this.suggestType=="city" )  {
        	s_id = srcElement.id.split("_")[1];
        }
        instance.highlightNewValue(s_id,"Mouse");
    }
    this.MOut=function(instance){
        var e = this.MOut.caller.arguments[0] || window.event;
        var srcElement = e.srcElement || e.target;
        instance.setStyleForPerElement(srcElement.id);
    };


    //初始化
    this.initACPartTwo();
}

mapbarInputSuggest.bind = function(posturl,requestMode,requestDelegate)
{
    var elements = document.getElementsByTagName("input");
    for(var i=0;i<elements.length;i++)
    {
        if (elements[i].type == "text" && elements[i].getAttribute("issuggest")=="yes")
        {
            var posturl2 = elements[i].getAttribute("posturl") || posturl;
			var selectdone_callback = elements[i].getAttribute("selectdone_callback");
            new mapbarInputSuggest({inputid: elements[i].id,posturl: posturl2,requestMode:requestMode,requestDelegate: requestDelegate,selectDoneCbk: selectdone_callback});
        }
    }
}
