//调用示例:
//<input id="StartInput" name="StartInput" type="text" value="中文/拼音" onFocus="javascript:this.value='';Unixo.open('StartInput','StartCity',1);" onKeyUp="Unixo.open('StartInput','StartCity',1);" >
document.write("<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><style>body,div,span,a,ul,li,form{color:#0054AE; font-size:12px;}#seachPanl{width:200px;position:absolute;border:#7B9FDB 1px solid;font-size:12px;color:#555;text-align:center;font-family:Arial;background:#FFFFFF;z-index:9999;}#seachPanl h2{width:95%;margin:2px 0px 0px 6px;font-size:12px;line-height:25px;height:25px;font-weight:normal;text-align:left;border-bottom:#7B9FDB 1px dashed;}#SEACHUL{width:98%;height:220px;margin:2px 0px 0px 2px;}#SEACHUL li{height:22px;*+height:19px;width:100%;}#SEACHUL li div{width:50%;line-height:22px;overflow:hidden;height:22px;float:left;cursor:pointer;}#SPange{width:195px;padding-left:5px;text-indent:4px;height:22px;margin:2px 0px 0px 0px;background-color:#fff;	border-top:#7B9FDB 1px dashed; font-weight:bold;}.onyo{height:22px;width:100%;line-height:22px;color:#0054AE;display:block;background:#CEE3FF; border-top:#7B9FDB 1px solid;border-bottom:#7B9FDB 1px solid;}.seachf{text-align:left;text-indent:5px;}.seacht{text-align:right;}.TfocuCssStyle{float:left;width:22px;height:22px;line-height:22px;text-align:center;}.TfocuCssStyle div{margin-top:3px;cursor:pointer;width:15px;height:15px;line-height:15px;color:#333;background:#CEE3FF;font-family:Arial}.TblueCssStyle{float:left;width:22px;height:22px;line-height:22px;text-align:center;font-family:Arial}.TblueCssStyle div{margin-top:3px;cursor:pointer;width:15px;height:15px;line-height:15px;color:#333;background:#fff;}.focuCssStyle{background:#CEE3FF; border-top:#7B9FDB 1px solid;border-bottom:#7B9FDB 1px solid;}.focuCssStyle div{color:#0054AE;}.blueCssStyle{color:#333;}.blueCssStyle div{color:#0054AE;}</style></head><body><div id=\"seachPanl\" style=\"display:none; height:280px; width:200px;\"><h2 id=\"h2_msg\">输入中文/拼音搜索</h2>		<div id=\"seachlist\"><ul id=\"SEACHUL\"></ul><div id=\"SPange\"><ul id=\"SPangeUL\"></ul></div></div></div></body></html>")


/*常用工具类**/
var IE = document.all;
var _HTTP = 'http://' + location.hostname;

function get$(id) {
			var el = null;
			var doc = document;
			try {
				el = doc.getElementById(id);
			}
			catch (e) {alert('throw is error,pleae close.!!!');}
			return el;
}
String.prototype.Trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.oStr = function(){
	return /^[0-9a-zA-Z_]{5,20}$/.test(this);
}
String.prototype.oChina = function()
{
	return /^[\u4E00-\u9FA5]{2,4}$/.test(this);
} 
String.prototype.oMid = function(o,oo)
{
        return this.substr(o,oo);
}
String.prototype.oChina = function()
{
	return /^[\u4E00-\u9FA5]{2,4}$/.test(this);
} 

Function.prototype.inherit = function(C){
	for(var p in C.prototype){
		this.prototype[p] = C.prototype[p];
	}
}

function Leg(str){
	return str.replace(/[^\x00-\xFF]/g, "le").length;
}

function R(url){ return encodeURIComponent(url); }

function E(str){ return escape(str);}

function U(str){ return unescape(str);}

function L(str){ alert(str);}

function Href( url){ location.href = R(url); }


function StartCity2Value(){
	///////////给联程出发城市赋值/////////////
    try{		
		if(get$('IsTrue').value==2){			
			if(get$("EndCity").value.indexOf(",") != -1){				
				get$("StartCity2").value = get$("EndCity").value;
				var aa = get$("EndCity").value.split(",");
				get$("StartInput2").value = aa[1];				
				}			
			}
		}
	catch(e){}
	///////////////////////
}


String.prototype.Reg = function(n){
	var jobs = 'reg';
	switch(n){
		case 0: jobs = /^[0-9a-zA-Z_]{5,20}$/; break
		case 1: jobs = /^[0-9A-Za-z]$/; break;
		case 2: jobs = /^(((13[0-9]{1})|159|(15[0-9]{1}))+\d{8})$/; break;
		case 3: jobs = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; break;
		case 4: jobs = /^[\u4E00-\u9FA5]*$/; break;
		case 5: jobs = /^http[s]?:\/\/([\w-]+\.)+[\w-]+([\w-./?%&=]*)?$/i; break;
		case 6: jobs = /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/; break;
		case 7: jobs = /^[\d]{6}$/; break; 
		case 8: jobs = /^[0-9]$/; break; 
		case 9: jobs = /^[\d]{4}$/; break; 
	}
	try{  return jobs.test(this.Trim());}
	catch(e){}
}

var Try = {
	these: function(){
		var val;
		for(var i=0;i<arguments.length;i++){
			var li = arguments[i];
			try{
				val = li();
				break;
			}catch(e){}
		}
		return val;
	}
}

function ElemOff(){}

ElemOff.prototype = {
	//获取对象坐标
	__: function(e){
		var X = e.offsetTop,Y = e.offsetLeft;
		while(e = e.offsetParent){
			X+= e.offsetTop;
			Y+= e.offsetLeft;
		}
		return [X,Y];
	}
}

var elemOff = new ElemOff();

function Ajax(){}

Ajax.prototype = {
	createAjax: function(){
		return Try.these(
			function() {return new ActiveXObject('Msxml2.XMLHTTP')},
      		function() {return new ActiveXObject('Microsoft.XMLHTTP')},
      		function() {return new XMLHttpRequest()}
		) || false;
	},
	Request: function( url, obj, msg){
		var HTTP_REQUEST = this.createAjax();
		var return_value,lrr;
		lrr = url + '&GGI=' + Math.round();
		HTTP_REQUEST.open("GET", lrr, true);
		HTTP_REQUEST.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		if(HTTP_REQUEST){
			HTTP_REQUEST.onreadystatechange = function(){
				if (HTTP_REQUEST.readyState == 4) 
				{	
					if (HTTP_REQUEST.status == 200)
					{
						return_value = HTTP_REQUEST.responseText;
						get$(obj).innerHTML = return_value; 
					} 
				}else{get$(obj).innerHTML = msg;}
			}
		}
			HTTP_REQUEST.send(null);
	},
	Get: function( url){
		var HTTP_REQUEST = this.createAjax();
		var return_value,lrr;
		lrr = url + '&GGI=' + Math.round();
		HTTP_REQUEST.open("GET", lrr, true);
		HTTP_REQUEST.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		
		if(HTTP_REQUEST){		
			HTTP_REQUEST.onreadystatechange = function(){
				if (HTTP_REQUEST.readyState == 4) 
				{		
					if (HTTP_REQUEST.status == 200)
					{
						return_value = HTTP_REQUEST.responseText;
						//return HTTP_REQUEST.responseText;
					} 
				}	
			}
			return return_value;
		}
		HTTP_REQUEST.send(null);
		
	},
	Qs: function( name){
		var url = window.location.href;
		var sb = url.indexOf('?');
		var u_Right = url.substr(sb + 1);
		var u_Tmp = u_Right.split("&");
		for(var i = 0;i < u_Tmp.length;i++)
		{
			var d_Temp = u_Tmp[i].split("=");
			if(d_Temp[0].toUpperCase() == name.toUpperCase())
			{
				return d_Temp[1];
			}
		}

		return false;
	}
}


/*
获取鼠标位置
**/
function mousePosition(ev){
     if(ev.pageX || ev.pageY){
      return {x:ev.pageX, y:ev.pageY};
      }
      return {
       x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
       y:ev.clientY + document.body.scrollTop  - document.body.clientTop
      }; 
}

var Unixo = {
				 out: null, //获取操作对象
			   input: null,
			   Stype: null,
				Unix: [],   //存储数据
				_Dup: 0,    //上下键
				_Lrg: 0,    //左右键
			   oText: '',   //搜索文字
		  sPageIndex: 1,    //第几页
		   sPageList: 1,    //总数目
		    PageItem: 10,    //每页显示数据
		   
			    /*
			    关闭搜索层
			    **/
			    close: function(){
					return function(){
						get$('seachPanl').style.display = 'none';
						
					}();	
			    },
			    /*
				实现上键
				**/
				_Down: function(){
					
					var __ = get$('SEACHUL').getElementsByTagName('li');
					if( Unixo._Dup >= __.length){
						Unixo._Dup = __.length - 1;
						return (false);
					}	
					for(var i=0; i<__.length;i++){	
						if(Unixo._Dup == i){	
							__[Unixo._Dup].className = 'focuCssStyle';
						}else{
							__[i].className = 'blueCssStyle';
						}
					}
				},
				/*
				实现下键
				**/
				_Up: function(){
					var __ = get$('SEACHUL').getElementsByTagName('li');
					if( Unixo._Dup < 0){
						Unixo._Dup = 0;
						return (false);
					}
					for(var i=0; i<__.length;i++){
						if(Unixo._Dup == i){
							__[Unixo._Dup].className = 'focuCssStyle';
						}else{
							__[i].className = 'blueCssStyle';
						}
					}
				},
				/*
				实现左键
				**/
				_Left: function(){
					Unixo._Dup = 0;     //但选择下一页的时候光标停在第一个选项上
					var __ = get$('SPange').getElementsByTagName('li');
					if( Unixo._Lrg <= 0){
						Unixo._Lrg = 0;
						return (false);
					}
					for(var i=0; i<__.length;i++){
						if(Unixo._Lrg == i){
							__[Unixo._Lrg].className = 'TfocuCssStyle';
						}else{
							__[i].className = 'TblueCssStyle';
						}
					}
				},
				/*
				实现右键
				**/
				_Right: function(){
					Unixo._Dup = 0;    //但选择上一页的时候光标停在第一个选
					var __ = get$('SPange').getElementsByTagName('li');
					if( Unixo._Lrg >= __.length){
						Unixo._Lrg = __.length - 1;
						return (false);
					}	
					for(var i=0; i<__.length;i++){
						if(Unixo._Lrg == i){
							__[Unixo._Lrg].className = 'TfocuCssStyle';
							
						}else{
							__[i].className = 'TblueCssStyle';
						}
					}
				},				
				/*
				**/
				_Click: function( sput , valu){
					 var _put;
					 
						 Unixo.hideSelect('visible');
						 _put  = get$('fff' + sput).getElementsByTagName('div');
						 get$(Unixo.out).value = _put[1].innerHTML.Trim().replace('<[^>]*>','').replace('&nbsp;&nbsp;', '' ); 
						 
						 get$(Unixo.input).value = valu;
						 Unixo.close();
				}
};
Unixo.click = function(inp){
	var ut = get$(inp);
	if(ut.value.Trim() == ''){
		ut.value = ''
		ut.style.color = '#555555';
		return (false);
	}
}
/*
扩充打开窗口事件
**/
Unixo.open = function(_out , _input,_Stype){
	  //重新设置操作对象/输入框数据
	  Unixo.out     = _out;
	  if(_Vesion() == 6){
	  	Unixo.hideSelect('hidden');
	  }
	  Unixo.click(_out);
      Unixo.input   = _input;
      Unixo.Stype   = _Stype;
	  Unixo.oText   = E(get$(Unixo.out).value.Trim());
	  Unixo.setCss();
	  Unixo.init(Unixo.sPageIndex,Unixo.Stype,arguments[3]);  
	  Unixo.event(event);//开启键盘事件,enter键值还没有实现
};


/*
检测IE浏览器版本
**/
function _Vesion(){
		var IEversion	= window.navigator.appVersion;	
		var __ = IEversion.indexOf("MSIE");	
		if(__>=0){
			__+=4;
			var j=IEversion.indexOf(";",__);
			if(j<0){
				j = IEversion.length-1;
			}
			IEversion	=IEversion.substring( __, j )*1;	
			return IEversion;
		}
}


/*
显示窗口
**/
Unixo.setCss = function(){
	  var ex,_height,_top,_left;
	  var __ = get$(Unixo.out).offsetHeight + 0;
	  ex        = elemOff.__(get$(Unixo.out));
	  _top      = ex[0];
	  _left     = ex[1];
	  get$('seachPanl').style.top     = (_top + __) + 'px';
	  get$('seachPanl').style.left    = _left + 'px';
	  get$('seachPanl').style.display = 'block';
};
/*
获取坐标最大值。最小值
**/
Unixo.getXY = function(){
	  var topMax,topMin,leftMax,leftMin;
	  
	  var __ = get$(Unixo.out).offsetHeight + 1;      //输入框对象高度
	  
	  var ex        = elemOff.__(get$(Unixo.out));    //输入框Top,Left
	  
	  var em        = get$('seachPanl').offsetHeight; //提示框高度
	  var xm        = get$('seachPanl').offsetWidth;  //提示框宽带
	  
	  topMin    = ex[0] - __;            //获取顶部最小值
	  topMax    = ex[0] + __ + em;       //获取顶部最大值
	  leftMin   = ex[1];                 //获取左边最小值
	  leftMax   = ex[1] + xm;            //获取左边最大值
	  
	  
	  return [topMin,topMax,leftMin,leftMax];
};
/*
初始化
**/
Unixo.init = function(sPage){
	var dlg = '';  //组合字符串
	var url = '';  //数据获取连接地址
	var input;
	var http;      //Ajax对象
	

      //DLL: [ "北京机场|BJS|Beijing|北京","上海机场|SHB|shanghai|上海","杭州萧山国际机场|HGH|Hangzhou|杭州#2#1"],
		
		 //如果数据符合要求
		   var DLL,B,A;
		   
		   //url = "/Include/SelectValue.asp?s="+Unixo.oText+"&t="+eval(arguments[1])+"&n="+Unixo.PageItem+"&p="+sPage+"&nocache="+Math.random()
		   url = "/Include/SelectValue.asp?s="+Unixo.oText+"&t="+eval(arguments[1])+"&n="+Unixo.PageItem+"&p="+sPage+"&PID="+arguments[2]+"&nocache="+Math.random()
		   //创建http对象
		   //document.write(url);
		   //alert(url);
		   http = $$A.createAjax();
		   
		   //异步提交
		   http.open("GET", url, true );
		   http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		   if(http){
			   //document.write(DLL);
			   //alert(http.responseText.Trim());
		   		 http.onreadystatechange = function(){
					//get$('azheng').innerHTML = http.readyState + "$$$$" + http.status;			 	
					if (http.readyState == 4){
						if (http.status == 200){
							//获取异步返回的数据
							DLL = http.responseText.Trim();	
							//拆分条件
							//alert(DLL);
							
							B   = DLL.split("#");
							
							//重复赋值给总页数/第几页
							Unixo.sPageList   = B[1]; 
							Unixo.sPageIndex  = B[2];
						
							//重新判断返回的数据,显示友好提示
							if(B[0] == 'undefined' || ''){
								dlg += "<li id=fff0><span class='onyo'>没有您要的数据</span></li>";
							}else{
								//获取数据列表
								A   = B[0].split(",");
								for(var i = 0; i < A.length; i++ ){
									input = A[i].split('|');	
									dlg += "<li id=fff" + i + " onclick=Unixo._Click(" + i + ",'" + input[1] + "," + input[3] + "'); onmousemove=Unixo.Mousemove(" + i + ");>";
									dlg += "<div class='seachf'>" + input[2] + "</div>";
									dlg += "<div class='seacht'>" + input[3] + "&nbsp;&nbsp;</div>";
									dlg += "</li>";
								}
								if(Unixo.Zindex > A.length){
								   Unixo.Zindex = 0;
								   //如果上下键的指针值大于A,那么将指针的位置设置为0
								}
							}	
							get$('SEACHUL').innerHTML = dlg;	
							dlg = '';
							var _____ = get$('SEACHUL').getElementsByTagName('li');
							_____[Unixo._Dup].className = 'focuCssStyle';
							Unixo.ScriptPage();					
						}						
					 else{get$('SEACHUL').innerHTML = "<li id=fff0><span class='onyo'>没有您要的数据</span></li>";}
					}
				 }		   
		   }
		   
		   else{
		         alert('组件未加载错误');
		   }
		   
		   
		   http.send(null);	

}
/*
鼠标经过
**/
Unixo.Mousemove = function(_){
	var __Len = get$('SEACHUL').getElementsByTagName('li');
	for(var i = 0; i < __Len.length; i++ ){
		if(i == _){
			__Len[i].className = 'focuCssStyle';
		}else{
			__Len[i].className = 'blueCssStyle';
		}
	}
}
/*
生产分页数据记录
存在则为1
**/
Unixo.ScriptPage = function(){
		var spangeUL = get$('SPangeUL'); //获取容器对象
		var _input   = '';
		//获取第几页,如果指针值小于0,那么重新赋值为1
		if(Unixo.sPageIndex < 0){
			Unixo.sPageIndex = 1;
		}
		//如果第几页大于页数总值,则重新赋值当前页
		if(Unixo.sPageIndex > Unixo.sPageList){
		   Unixo.sPageIndex = Unixo.sPageList;
		}
		for(var z = 0; z < Unixo.sPageList; z++){
			if(z == Unixo.sPageIndex - 1){
				_input += "<li class='TfocuCssStyle'>"
			}else{
				_input += "<li class='TblueCssStyle'>"
			}
			_input += "<div onclick=Unixo.init('" + (z + 1) + "','" + Unixo.Stype + "') title='第" + (z + 1) + "页'>" + (z + 1) + "</div>";
			_input += "</li>";	
		}
		spangeUL.innerHTML = _input;
}
Unixo.blur = function(ev){
try{
	var evt = window.event || clickitem.caller.arguments[0];
	var srcEl = evt.target || evt.srcElement;		
	//alert(srcEl.id);
	var fcss = get$('flights_code').style.display;
	//alert(get$('flights_code') + '//' + fcss + '//' + srcEl.id);
	if(fcss == '' && srcEl.id != 'StartInput' && srcEl.id != 'EndInput'&& srcEl.id != 'StartInput6' && srcEl.id != 'EndInput6'&& srcEl.id != 'CityInp'&& srcEl.id != 'StartInput2' && srcEl.id != 'EndInput2')
	hideFlights_code();
	rmtips();
	//alert('ok');
	} catch(err) {}
	
	try{
	ev = ev || window.event;
	var x,y,ex;
	ex = Unixo.getXY();
	var Css = get$('seachPanl').style.display;
	if(Css == 'none'){
		//return (false);
	}else{
		var mousePos = mousePosition(ev);
		x = mousePos.x;
		y = mousePos.y - 15;
		
		if(y < ex[0] || y > ex[1]){
			get$('seachPanl').style.display = 'none';
			Unixo.hideSelect('visible');
		}else if(x < ex[2] || x > ex[3]){
			get$('seachPanl').style.display = 'none';
			Unixo.hideSelect('visible');
		}
	}
	} catch(err) {}
}
Unixo.hideSelect = function(visibility){
		var b = document.getElementsByTagName('select');
		for(var i=0;i<b.length;i++){
			b[i].style.visibility = visibility;
		}
};
Unixo.event = function(e){
		//保存所在索引值
		var ___;
		//获取鼠标按键
		var key; e = window.event || e;
		    key = e.keyCode || e.which || e.charCode;
			switch( key ){
				/*
				实现上键
				**/
				case 40:
					Unixo._Dup++;
					Unixo._Down();
					break;
				/*
				实现下键
				**/	
				case 38:
					Unixo._Dup--;
					Unixo._Up();
					break;
				/*
				实现右键
				**/	
				case 39:	
					if(Unixo.sPageList == 1) return (false); 
					Unixo._Lrg++;
					Unixo._Right();
					___ = parseInt(Unixo.sPageIndex) + 1;	
					if( ___ > Unixo.sPageList){
						___ = Unixo.sPageList;
					}
					Unixo.init(___);
					break;
				case 37:	
				    if(Unixo.sPageList == 1) return (false); 
					Unixo._Lrg--;
					Unixo._Left();
					___ = parseInt(Unixo.sPageIndex) - 1;
					if( ___ > Unixo.sPageList){
						___ = Unixo.sPageList;
					}
					Unixo.init(___);
					break;
				//键盘enter事件，还没有传参数
				case 13:	
					get$('fff' + Unixo._Dup).onclick();
					break;
				/*case 27:
					Unixo.close();
					break;*/
			}
}

document.onclick = Unixo.blur;

var $$A = new Ajax();






