﻿// JScript 文件
function setInfo(obj){
  obj.input.value=obj.innerHTML;
  var div=$('autoCompleteCity'); 
  if(div){
   div.remove();
  }
}
function autoCompleteCity(input,vi){
if(input.value.length<1){
     return;
  }
  if(parseInt(vi)==0)
  {
    //var url="Domestic_Hotel/CityList.aspx?key="+input.value;
    var url="internal_Hotel/CityList.aspx?key="+input.value;
    imgsrc="image/close.gif";
  }
  else
  {
    var url="CityList.aspx?key="+input.value;
    imgsrc="../image/close.gif";
  }
  new Ajax.Request(
     url,{
	    onSuccess:function(r){
		   var data = r.responseText.evalJSON();
		   {
		      //返回数据成功!
			  try{
			  var div=$('autoCompleteCity'); 
			  if(div){
			   div.remove();
			  }
			  div=new Element('div');
			  div.id='autoCompleteCity';
			  input.parentNode.appendChild(div);
			  div.setStyle(
			    {
				  position:'absolute',
				  width:'120px',
				  height:'100px', 
				  overflowY:'scroll',
				  background:'#CFEAFF',
				  padding:'5px 0 5px 10px',
				  left:'auto',
				  top:'auto',
				  margin:'0px'
				}
			  );
			  var ul=new Element('ul');
			  ul.setStyle({
			    textAlign:'left',
			    listStyle:'none',
			    padding:'0',
			    margin:'0'
			  });
			  div.appendChild(ul);
			  var li=new Element('li');
			  ul.appendChild(li);
			  li.setStyle({
			    textAlign:'right',
			    color:'red'
			  });
			  li.innerHTML=(data.message+'<a href="JAVASCRIPT:;" onclick="$(\'autoCompleteCity\').remove();"><img src='+imgsrc+' border="0"></a>');
			  if(data.data)
			  {
			      data.data.each(
			        function (i){
				      li=new Element('li');
				      li.onmouseover=function(){this.setStyle({
				         'background':'#FFFFFF',
					     cursor:'pointer' 
				      });
				      this.input.value=this.innerHTML;
				      this.input.select();
				      }
				      li.onmouseout=function(){this.setStyle({
				         'background': '' 
				      })}
				      li.input=input;
				      li.onclick=function(){setInfo(this)};
				      li.update(i.cityname);
				      ul.appendChild(li);
				    }
			      );
			  }
			  else
			  {
			     li=new Element('li');
			     li.innerHTML="无";
			     ul.appendChild(li);
			  }
              }
              catch(ex){
			    alert(ex.message+':'+ex.name);
			  }
		   }
		},//onsuccess end
	  onFailure:function(r)
	  {
	     alert(r.responseText);
	  }	
	 }//object options
  );
}