﻿var intIndex0=0;arrList0 = new Array();

//将初始化的列表转换成数组
function dearray0(str)//定义array
{
arrList0 = str.split(",");
intIndex0 = arrList0.length;
}

//初始化下拉列表项
function begin0()
{
init0();
dearray0(strStartCity);
downList0(arrList0,"txtStartCity");
}
//初始化下拉列表项
function begin1()
{
init0();
dearray0(strToCity);
downList0(arrList0,"txtToCity");
}

function init0(){
if(arrList0.constructor!=Array){return;}
arrList0.sort( function(a, b){
if(a.length>b.length)return 1;
else if(a.length==b.length)return a.localeCompare(b);
else return -1;}); }

function downList0(arrList0,objInputId)
{
var objouter=document.getElementById("keysList0"); //显示的DIV对象
var objInput = document.getElementById(objInputId); //文本框对象
var selectedIndex=-1;
var intTmp; //循环用的

if (objInput==null)
{
return;
}
//文本框失去焦点
objInput.onblur=function(){
objouter.style.display="none";
}
//文本框按键抬起
objInput.onkeyup=checkKeyCode;
//文本框得到焦点
objInput.onfocus=checkAndShow0;

//判断按下的安键
function checkKeyCode(evt)
{
evt = evt || window.event;
var keyCode = window.event ? evt.keyCode : evt.which;
//var keyCode = String.fromCharCode(key);
if (keyCode==40||keyCode==38)
{//下上
   var isUp=false
   if(keyCode==40) isUp=true;
   chageSelection0(isUp);
}
else if (keyCode==13)
{//回车
   outSelection0(selectedIndex);
}
else
{
   checkAndShow0(evt);
}
divPosition0(evt);
}

function checkAndShow0(evt)
{
var strInput = objInput.value;
if (strInput!="")
{
   divPosition0(evt);
   selectedIndex=-1;
   objouter.innerHTML ="";
   
   //allNumber=总共显示个数
   var count=0;var allNumber=20;
   for (intTmp=0;intTmp<arrList0.length;intTmp++)
   {
    
	if(arrList0[intTmp].split('|').length==2){
		if (arrList0[intTmp].split('|')[1].substr(0, strInput.length).toLowerCase()==strInput.toLowerCase())
		{
		 addOption0(arrList0[intTmp].replace('|','(')+')');
		 
		 //跳出
		 //count++;if(count>allNumber)break;
		}else if (arrList0[intTmp].split('|')[0].substr(0, strInput.length).toLowerCase()==strInput.toLowerCase())
		{
		 addOption0(arrList0[intTmp].replace('|','(')+')');
		 
		 //跳出
		 //count++;if(count>allNumber)break;
		}
	//document.getElementById("sss").value+="1+|";
	}else if (arrList0[intTmp].split('|').length==3) {
	if (arrList0[intTmp].split('|')[1].substr(0, strInput.length).toLowerCase()==strInput.toLowerCase())
		{
		 addOption0(arrList0[intTmp].replace('|','(')+')');
		 
		 //跳出
		 //count++;if(count>allNumber)break;
		}else if (arrList0[intTmp].split('|')[0].substr(0, strInput.length).toLowerCase()==strInput.toLowerCase())
		{
		 addOption0(arrList0[intTmp].replace('|','(')+')');
		}else if (arrList0[intTmp].split('|')[2].substr(0, strInput.length).toLowerCase()==strInput.toLowerCase())
		{
		 addOption0(arrList0[intTmp].replace('|','(')+')');
		}
	}
	else{
		if (arrList0[intTmp].substr(0, strInput.length).toLowerCase()==strInput.toLowerCase())
		{
		 addOption0(arrList0[intTmp]);
		 
		 //跳出
		 //count++;if(count>allNumber)break;
		}
	}
   }
   objouter.style.display="";
}
else
{
   objouter.style.display="none";
}

//想下拉列表里添加匹配项
function addOption0(value)
{
   objouter.innerHTML +="<div onmouseover=this.className=\"sman_selectedStyle\";document.getElementById(\""+objInputId+"\").value=\"" + value.split('(')[0] + "\" onmouseout=this.className=\"\" onmousedown=document.getElementById(\""+objInputId+"\").value=\"" + value.split('(')[0] + "\">" + value + "</div>" 
}

}//end checkAndShow0()

function chageSelection0(isUp)
{
if (objouter.style.display=="none")
{
   objouter.style.display="";
}
else
{
   if (isUp)
    selectedIndex++;
   else
    selectedIndex--;
}

var maxIndex = objouter.childNodes.length-1;
if (selectedIndex<0){selectedIndex=0;}
if (selectedIndex>maxIndex) {selectedIndex=maxIndex;}
for (intTmp=0;intTmp<=maxIndex;intTmp++)
{
   if (intTmp==selectedIndex)
   {
    objouter.childNodes[intTmp].className="sman_selectedStyle";
    //当上下键移动时，将选中的文本写到文本框中
    document.getElementById(objInputId).value=objouter.childNodes[intTmp].innerHTML.split('(')[0];
   }
   else
   {
    objouter.childNodes[intTmp].className="";
   }
}
}

function outSelection0(Index)
{
objInput.value = objouter.childNodes[Index].innerHTML.split('(')[0];
objouter.style.display="none";
}

//显示下拉列表项
function divPosition0(evt)
{
var e = objInput;
var ie = (document.all)? true:false
//定义列表区在不同浏览器中的位置
if (ie)
{
   var top = 0;
   var left = -2;
}
else
{
   var top = 2;
   var left = 0;
}
   
while (e.offsetParent)
{
   left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
   top += e.offsetTop + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
   e = e.offsetParent;
}

left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
top += e.offsetTop + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
objouter.style.top = (top + objInput.clientHeight) + "px";
objouter.style.left = left + "px"; 
objouter.style.width= objInput.clientWidth+1 + "px";
}

}//end downList0()


function getAbsoluteHeight0(ob)
{
return ob.offsetHeight;
}

function getAbsoluteWidth0(ob)
{
return ob.offsetWidth;
}

function getAbsoluteLeft0(ob)
{
var mendingLeft = ob .offsetLeft;
while( ob != null && ob.offsetParent != null && ob.offsetParent.tagName != "BODY" )
{
mendingLeft += ob .offsetParent.offsetLeft;
mendingOb = ob.offsetParent;
}
return mendingLeft;
}

function getAbsoluteTop0(ob)
{
var mendingTop = ob.offsetTop;
while( ob != null && ob.offsetParent != null && ob.offsetParent.tagName != "BODY" )
{
mendingTop += ob.offsetParent.offsetTop;
ob = ob.offsetParent;
}
return mendingTop;
}

Number.prototype.NaN0 = function()
{
return isNaN(this)?0:this;
}

//出现光标
document.write("<div id=\"keysList0\" style=\"width:auto;height:100px; overflow:auto;overflow-y:auto;position:absolute;display:none;background:#FFFFFF;border: 1px solid #CCCCCC;font-size:14px;cursor: default; Z-INDEX:100;  POSITION:absolute; \" onblur> <iframe src=\"javascript:false\" style=\"Z-INDEX:-1; FILTER:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0); LEFT:0px; VISIBILITY:inherit; width:expression(this.parentNode.offsetWidth); POSITION:absolute; TOP:0px; height:expression(this.parentNode.offsetHeight);\"></iframe></div>");
document.write("<style>.sman_selectedStyle{background-Color:#102681;color:#FFFFFF}</style>");

function enterkey()
{
    if(event.keyCode==13 && event.srcElement.type !="BUTTON" && event.srcElement.type!="SUBMIT")
    event.keyCode=9;
}
