//调用示例:
//<input name="StartInput" type="text" value="中文/拼音" onfocus="javascript:this.value='';AutoSearch(1,FlightFrm.StartCity)">
document.write("<div id='SearchLayer' style='position:absolute;z-index:9999;width:200px;height:300px;background:red;display:none'>");
document.write("<iframe name='SearchIframe' scrolling='no' frameborder='0' width='100%' height='100%'></iframe></div>");
function writeAutoSelIframe(){
    var strIframe = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>";
    strIframe += "<style>body{margin:0;}div{font-size:12px;font-family:Arial;font-weight:normal;color:#0055AD}#Main{width:200px;height:260px;border:1px solid #7B9EDB;padding:4px;}#Title{border-bottom:1px dotted #ADAAAD;color:#636563;height:20px;line-height:20px;text-indent:5px;}#Content{margin-top:5px;}#Content span{float:right;}#Content div{padding:0 5px;height:21px;line-height:21px;border-left:none;border-right:none;}#List{text-align:center;height:30px;line-height:30px;color:#333333;display:none;}#List u{font-family:Webdings;}a{color:#0055AD;text-decoration:underline;cursor:pointer;}.Line{background:#FFFFFF;border:1px solid #FFFFFF;}.LineSel{background:#CEE3FF;border:1px solid #FFFFFF;}.LineMounseOn{background:#E7F3FF;border:1px solid #7E9EBD;}</style>";
	strIframe += "</head><body oncontentmenu='return false' onselectstart='return false'><div id='Main'><div id='Title'></div><div id='Content'></div><div id='List'></div</div></body></html>";
    with(SearchSelect.iframe)
    {
        document.writeln(strIframe);document.close();
    }
}
function AutoSearchSelect()
{
	this.PageItem = 10;												//每页显示数据
	this.Page = 1;													//当前页数
	this.PageCount = null;											//当前总页数
	this.Text = null;												//查询的文本
	this.Type = null;												//查询的类型：1:机场；2:酒店
	this.Flag = false;												//搜索结果标志
	this.Item = -1;													//当前结果下标索引
	this.layer = new Array();										//结果显示层数组
	this.eventSrc = null;											//触发控件
	this.objExport = null;											//显示控件 
    this.iframe = window.frames("SearchIframe");					//iframe载体
	this.selectLayer = document.getElementById("SearchLayer");		//控件层
}
var SearchSelect = new AutoSearchSelect();
var xml = null;

function AutoSearch() //主调函数
{
    var e = window.event.srcElement;writeAutoSelIframe();
    var o = SearchSelect.selectLayer.style;
	SearchSelect.eventSrc = e;
	if(e.value.trim() == e.tip){
		//e.className = "";
		e.value = "";}
	SearchSelect.eventSrc.onkeyup = SearchKeyUp;
	SearchSelect.eventSrc.onkeydown = function(){if(window.event.keyCode==13){return false;}};
	SearchSelect.Type = eval(arguments[0]);
	SearchSelect.Page = 1;
	if (arguments.length == 2) SearchSelect.objExport = eval(arguments[1]);
    else SearchSelect.objExport = e;

	var t = e.offsetTop,  h = e.clientHeight, l = e.offsetLeft, p = e.type;
	while (e = e.offsetParent){t += e.offsetTop; l += e.offsetLeft;}
    o.display = "";
    var cw = SearchSelect.selectLayer.clientWidth, ch = SearchSelect.selectLayer.clientHeight;
    var dw = document.body.clientWidth, dl = document.body.scrollLeft, dt = document.body.scrollTop;
    if (document.body.clientHeight + dt - t - h >= ch) o.top = (p=="image")? t + h : t + h + 6;
    else o.top  = (t - dt < ch) ? ((p=="image")? t + h : t + h + 6) : t - ch;
    if (dw + dl - l >= cw) o.left = l; else o.left = (dw >= cw) ? dw - cw + dl : dl;

    try{
		CallSearch();}
	catch(e){}
	
}
function hiddenSearch(){SearchSelect.selectLayer.style.display = "none";};
function String.prototype.trim(){return this.replace(/(^\s*)|(\s*$)/g,"");}
function document.onclick(){
 if(SearchSelect.eventSrc != window.event.srcElement){
	if(SearchSelect.Flag)
		ReturnValue();
	hiddenSearch();}
}
function SearchKeyUp(){
 var k = window.event.keyCode;
 if(k == 13)
	ReturnValue();
 else if(k == 37)
	KeyValueLeft();
 else if(k == 39)
	KeyValueRight();
 else if(k == 38)
	KeyValueUp();
 else if(k == 40)
	KeyValueDown();
 else
	CallSearch();
 return false;
}
function ReturnValue(){
 if(SearchSelect.Flag && SearchSelect.objExport.value == ""){
	SearchSelect.eventSrc.value = SearchSelect.layer[SearchSelect.Item].title;
	SearchSelect.objExport.value = SearchSelect.layer[SearchSelect.Item].returnValue;}
 hiddenSearch();
}
function KeyValueLeft(){
 if(SearchSelect.Page != 1){
	SearchSelect.Page--;
	CallSearch();}
}
function KeyValueRight(){
 if(SearchSelect.Page != SearchSelect.PageCount){
	SearchSelect.Page++;
	CallSearch();}
}
function KeyValuePageTo(i){SearchSelect.Page=i;CallSearch();}
function KeyValueUp(){
 if(SearchSelect.Item != 0){
	SearchSelect.layer[SearchSelect.Item].className = "Line";
	SearchSelect.Item--;
	SearchSelect.layer[SearchSelect.Item].className = "LineSel";}
}
function KeyValueDown(){
 if(SearchSelect.Item != SearchSelect.layer.length - 1){
	SearchSelect.layer[SearchSelect.Item].className = "Line";
	SearchSelect.Item++;
	SearchSelect.layer[SearchSelect.Item].className = "LineSel";}
}
function GBKCode(s){var regexp1 = /[\u4e00-\u9fa5]/;
 return regexp.test(s);
}
function CallSearch(){
 SearchSelect.Text = SearchSelect.eventSrc.value.trim();
 SearchSelect.Flag = false;
 SearchSelect.layer = new Array();
 
 SearchSelect.selectLayer.style.display = "";
 SearchSelect.objExport.value = "";
 var s = SearchSelect.Text;
 if(window.XMLHttpRequest)
	xml = new XMLHttpRequest();
 else if(window.ActiveXObject)
	xml = new ActiveXObject("Microsoft.XMLHTTP");
 xml.onreadystatechange = XMLData;
 try{	 
     //document.write("/include/SelectValue.asp?s="+encodeURI(s)+"&t="+SearchSelect.Type+"&n="+SearchSelect.PageItem+"&p="+SearchSelect.Page+"&nocache="+Math.random());
	xml.open("GET","/include/SelectValue0.asp?s="+encodeURI(s)+"&t="+SearchSelect.Type+"&n="+SearchSelect.PageItem+"&p="+SearchSelect.Page+"&nocache="+Math.random(),true);
	xml.send(null);	}
 catch(e){}
}
function XMLData(){
	//alert(xml.responseText);
 if(xml.readyState == 4){
	var outXML = xml.responseXML;
	var n = outXML.getElementsByTagName("Data");
	if(n.length !== 0){
		var div,name,code,ename;
		SearchSelect.Flag = true;
		SearchSelect.Item = 0;
		SearchSelect.iframe.document.getElementById("Content").innerHTML = "";
		SearchSelect.Page = outXML.getElementsByTagName("Page")[0].firstChild.nodeValue;
		SearchSelect.PageCount = outXML.getElementsByTagName("PageCount")[0].firstChild.nodeValue;
		for(var i=0;i<n.length;i++){
			code = n[i].getElementsByTagName("Code")[0].firstChild.nodeValue;
			name = n[i].getElementsByTagName("ShortName")[0].firstChild.nodeValue;
			ename = n[i].getElementsByTagName("EnglishName")[0].firstChild.nodeValue;
			div = document.createElement("div");
			if(i == 0)
				div.className = "LineSel";
			else
				div.className = "Line";
			div.title = name;
			div.returnValue = code+","+name;
			div.innerHTML = "<span>"+name+"</span>"+ename;
			SearchSelect.layer[i] = div;}}
	FillFrame();}
}
function FillFrame(){
 if(!SearchSelect.Flag)
	SearchSelect.iframe.document.getElementById("Title").innerHTML = "对不起,找不到:" + SearchSelect.Text;
 else if(SearchSelect.Text == "")
	SearchSelect.iframe.document.getElementById("Title").innerHTML = "输入中文/拼音或↑↓选择";
 else
	SearchSelect.iframe.document.getElementById("Title").innerHTML = SearchSelect.Text + ",按拼音排序";
 for(var i=0;i<SearchSelect.layer.length;i++){
	SearchSelect.layer[i].onmouseover = function(){this.className = "LineMounseOn";this.style.cursor="pointer";}
	SearchSelect.layer[i].onmouseout = function(){if(SearchSelect.layer[SearchSelect.Item] == this)this.className = "LineSel";else this.className = "Line";}
	SearchSelect.layer[i].onclick = function(){SearchSelect.eventSrc.value=this.title;SearchSelect.objExport.value=this.returnValue;hiddenSearch();}
	SearchSelect.iframe.document.getElementById("Content").insertAdjacentElement("beforeEnd",SearchSelect.layer[i]);}
 var text="";
 if(SearchSelect.PageCount > 1){
	SearchSelect.iframe.document.getElementById("List").style.display = "block";
	var p=SearchSelect.Page,c=SearchSelect.PageCount;
	if(p > 1)
		text += "<a onclick='javascript:parent.KeyValuePageTo(1);'><u>3</u></a>";
	if(c <= 5){
		for(i=1;i<=c;i++){
			if(i == p)
				text += " " + p;
			else
				text += " <a onclick='javascript:parent.KeyValuePageTo(" + i + ");'>" + i + "</a>";}}
	else if(p <= 3){
		for(i=1;i<=5;i++){
			if(i == p)
				text += " " + p;
			else
				text += " <a onclick='javascript:parent.KeyValuePageTo(" + i + ");'>" + i + "</a>";}}
	else if(c - p <= 3){
		for(i=4;i>=0;i--){
			if((c-i) == p)
				text += " " + p;
			else
				text += " <a onclick='javascript:parent.KeyValuePageTo(" + (c-i) + ");'>" + (c-i) + "</a>";}}
	else{
		for(i=2;i>-3;i--){
			if(i == 0)
				text += " " + p;
			else
				text += " <a onclick='javascript:parent.KeyValuePageTo(" + (p-i) + ");'>" + (p-i) + "</a>";}}
	if(p - c < 0)
		text += " <a onclick='javascript:parent.KeyValuePageTo(" + c + ");'><u>4</u></a>";}
 SearchSelect.iframe.document.getElementById("List").innerHTML = text;
}


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



function HidAS(){
var e = window.event.srcElement;
SearchSelect.eventSrc = e;
if(SearchSelect.Flag)
SearchSelect.selectLayer.style.display = "none";
}