    function formonclick(k)
	{
		var aa="";
		switch (k)
		{
	case "3":
	document.getElementById('d').innerHTML="&nbsp;<input size=13 name=q1 id=q1  onkeyup='lookup(this.value,this.name,event);' style='position:relative' autoComplete='Off'>&nbsp;至&nbsp;<input size=13 name=q2 id=q2  onkeyup='lookup(this.value,this.name,event);' style='position:relative' autoComplete='Off'> ";
	break;
	case "2":
	document.getElementById('d').innerHTML="&nbsp;<input size=24 name=q id=q  onkeyup='lookup(this.value,this.name,event);'  style='position:relative' autoComplete='Off'> ";
	break;
	case "1":
	document.getElementById('d').innerHTML="&nbsp;<input size=24 name=q id=q  style='position:relative' autoComplete='Off'> ";		
	break;
		}
	}
var  _s = true;
var _c = 0;
var _x = null;
//键盘事件
function directionKey(e,_o,_r,_x,obj){
//	var _o =   document.getElementById('autoSuggestionsList') ;
	//var e = _e.keyCode ? _e.keyCode : _e.which;
//	alert(e);
	var l = _o.childNodes.length;
	(_c>l-1 || _c<0) ? _s=false : "";		
	if( e==40 && _s ){
		_o.childNodes[_c].className="mouseout";
		(_c >= l-1) ? _c=0 : _c ++;
		_o.childNodes[_c].className="mouseover";
	 }
	 if( e==38 && _s ){
		_o.childNodes[_c].className="mouseout";
		_c--<=0 ? _c = _o.childNodes.length-1 : "";
		_o.childNodes[_c].className="mouseover";
	 }
	 _r.value = _x[_c];
	 if( e==13 ){//回车键
		if(_o.childNodes[_c] ){
			//_r.value = _x[_c];
			fill(obj,_x[_c]);
			//_o.style.visibility = "hidden";
			
		}
	 }
//	 alert(_r);
//	 alert(_c);
	 if( !_s ){
	  _c = 0;
	  _o.childNodes[_c].className="mouseover";
	  _s = true;
	 }
	
}

function appenditem(msg,_o,obj) { 
	_x.push(msg);
	var div = document.createElement("DIV");
	//alert(div);
	//bind event to object.
	div.onclick = function(){fill(obj,msg) };
	div.style.lineHeight="150%";
//	div.className = "mouseout";
	div.innerHTML = msg;
	div.style.fontFamily = "verdana";
	var sg =   document.getElementById('autoSuggestionsList') ;
	sg.appendChild(div);
};

function loadstop(msg){//装入数据
	this._msg = [];
	if( msg.indexOf("|")>0 ){
		var arrMsg=msg.split("|");
		for(var i=0; i<arrMsg.length; i++){
			arrMsg[i] ? this._msg.push(arrMsg[i]) : "";
		}
	}
	else{
		this._msg.push(msg);
	}
	this._msg.sort();
	return this._msg;
}

function stopslist(_name)
{
this.stops = [];
this.name = _name;
this.add = function(stop) {this.stops.push(stop)};
}

	function lookup(inputString,obj,event) {
		var _e = event;
		_x = [];
		var inputBox = document.getElementById(obj);
		var e = _e.keyCode ? _e.keyCode : _e.which;
		//alert(e);
		var _o = document.getElementById('autoSuggestionsList') ;		
	   // 计算div左上角的位置
	   var x = (document.body.clientWidth-100)/3;
	   $('#suggestions').css("left",document.getElementById(obj).offsetLeft+"px");
	   $('#suggestions').css("top",inputBox.offsetTop+inputBox.clientHeight+3+"px");
	   
		if(inputString.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').hide();
		} else {

	if(!(e==37 || e==39))
		$.post(webhost+"rpc.php", {queryString: ""+inputString+"",obj:""+obj+"",cityid:""+cityid}, function(data){
				//alert(data);
				if(data.length >0) {					
					
				//	_msg = loadstop(data);
				//	alert(e);
				   if(!(e==37 ||e==38 || e==39 || e==40 || e==13)){
						$('#autoSuggestionsList').html(data);
						//n=0;
						//for(var i=0; i<_msg.length; i++){
						//	n=n+1;
						//	appenditem(_msg[i],_o,obj);									
						//}
						_c=0;
						_o.childNodes[_c].className = "mouseover";
						_s=true;						
					}else{
						_x=null;
						_x= new Array();
						for(var j=0;j<_o.childNodes.length;j++){
							_x.push(_o.childNodes[j].innerHTML);
						}
					}

					$('#suggestions').show();					
					//var nod = _o.childNodes[1].innerHTML;
					//alert(_x);		
					if((e==38 || e==40 || e==13)){
						directionKey(e,_o,inputBox,_x,obj)
					}
					else{
						_c=0;
						_o.childNodes[_c].className = "mouseover";
						_s=true;
					}
		
				}
			});
		}
	} // lookup
	
	function fill(obj,thisValue) {
		//$('#q1').val(thisValue);
		//alert(obj.value);
		document.getElementById(obj).value = thisValue;
		setTimeout("$('#suggestions').hide();", 200);
	}
	
function getELXY(e){
	return {x:e.offsetLeft,y:e.offsetTop};
}
function getELWH(e){
	return {w:e.offsetWidth,h:e.offsetHeight};
}
function getClientXY(e){
	e=e||event;
	return {cx:e.clientX,cy:e.clientY};
}


document.onclick = function(e){
	var obj = document.getElementById("suggestions");
	var lt = getELXY(obj)['x'];
	var rt = getELXY(obj)['x'] + getELWH(obj)['w'];
	var topY = getELXY(obj)['y'];
	var bottomY = getELXY(obj)['y'] + getELWH(obj)['h'];
	var mouseXX = getClientXY(e)['cx'];
	var mouseYY = getClientXY(e)['cy'];
	if(mouseXX<lt || mouseXX>rt || mouseYY<topY || mouseYY>bottomY){
//		obj.style.display="none";
			$('#suggestions').hide();		
	}else{
	}
};