var xmlHttp;
function createXMLHttpRequest()
{
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
}

function handleStateChange_list_ul() 
{ 
	if(xmlHttp.readyState == 4){if(xmlHttp.status == 200){document.getElementById("list_ul").innerHTML=xmlHttp.responseText;}}else{document.getElementById("list_ul").innerHTML="";}
}
function handleStateChange_list_table() 
{ 
	if(xmlHttp.readyState == 4){if(xmlHttp.status == 200){document.getElementById("list_table").innerHTML=xmlHttp.responseText;}}else{document.getElementById("list_table").innerHTML="";}
}
function handleStateChange_map_menu() 
{ 
	if(xmlHttp.readyState == 4){if(xmlHttp.status == 200){document.getElementById("itemopen").innerHTML=xmlHttp.responseText;}}else{document.getElementById("itemopen").innerHTML="";}
}
function handleStateChange_dhtmltooltip() 
{ 
	if(xmlHttp.readyState == 4){if(xmlHttp.status == 200){document.getElementById("dhtmltooltip").innerHTML=xmlHttp.responseText;}}else{document.getElementById("dhtmltooltip").innerHTML="";}
}

var li_i=0;
function document.onkeydown(){
	var tmp="";
	var tmp_array=new Array(); 
	if(document.getElementById("select_list_start")!=null){
		if (event.keyCode == 38){
			for(var k=0;k<select_list_start.childNodes.length;k++){
				select_list_start.childNodes(k).className="";
			}
			if((li_i-1)<0){li_i=select_list_start.childNodes.length}
			select_list_start.childNodes(--li_i%select_list_start.childNodes.length).className="onkey";
			document.getElementById("StartCity01").value=select_list_start.childNodes(li_i%select_list_start.childNodes.length).innerText.slice(1,4);
//			document.getElementById("StartCity01_cn").value=select_list_start.childNodes(li_i%select_list_start.childNodes.length).innerText.slice(5);
			tmp=select_list_start.childNodes(li_i%select_list_start.childNodes.length).innerText.slice(0);
			tmp_array=tmp.split("[");
			document.getElementById("StartCity01_cn").value=tmp_array[0];
			document.getElementById("list_ul").focus();
		}else if (event.keyCode== 40){
			for(var k=0;k<select_list_start.childNodes.length;k++){
				select_list_start.childNodes(k).className="";
			}
			select_list_start.childNodes(++li_i%select_list_start.childNodes.length).className="onkey";
			document.getElementById("StartCity01").value=select_list_start.childNodes(li_i%select_list_start.childNodes.length).innerText.slice(1,4);
//			document.getElementById("StartCity01_cn").value=select_list_start.childNodes(li_i%select_list_start.childNodes.length).innerText.slice(5);
			tmp=select_list_start.childNodes(li_i%select_list_start.childNodes.length).innerText.slice(0);
			tmp_array=tmp.split("[");
			document.getElementById("StartCity01_cn").value=tmp_array[0];
			document.getElementById("list_ul").focus();
		}else if (event.keyCode== 13){
			showAndHide('list_ul','hide');
//		}else{
//			document.getElementById("StartCity01_cn").focus();
		}
	}
	if(document.getElementById("select_list_end")!=null){
		if (event.keyCode == 38){
			for(var k=0;k<select_list_end.childNodes.length;k++){
				select_list_end.childNodes(k).className="";
			}
			if((li_i-1)<0){li_i=select_list_end.childNodes.length}
			select_list_end.childNodes(--li_i%select_list_end.childNodes.length).className="onkey";
			document.getElementById("EndCity01").value=select_list_end.childNodes(li_i%select_list_end.childNodes.length).innerText.slice(1,4);
//			document.getElementById("EndCity01_cn").value=select_list_end.childNodes(li_i%select_list_end.childNodes.length).innerText.slice(5);
			tmp=select_list_end.childNodes(li_i%select_list_end.childNodes.length).innerText.slice(0);
			tmp_array=tmp.split("[");
			document.getElementById("EndCity01_cn").value=tmp_array[0];
			document.getElementById("list_ul").focus();
		}else if (event.keyCode== 40){
			for(var k=0;k<select_list_end.childNodes.length;k++){
				select_list_end.childNodes(k).className="";
			}
			select_list_end.childNodes(++li_i%select_list_end.childNodes.length).className="onkey";
			document.getElementById("EndCity01").value=select_list_end.childNodes(li_i%select_list_end.childNodes.length).innerText.slice(1,4);
//			document.getElementById("EndCity01_cn").value=select_list_end.childNodes(li_i%select_list_end.childNodes.length).innerText.slice(5);
			tmp=select_list_end.childNodes(li_i%select_list_end.childNodes.length).innerText.slice(0);
			tmp_array=tmp.split("[");
			document.getElementById("EndCity01_cn").value=tmp_array[0];
			document.getElementById("list_ul").focus();
		}else if (event.keyCode== 13){
			showAndHide('list_ul','hide');
//		}else{
//			document.getElementById("EndCity01_cn").focus();
		}
	}
}

function read_text_list(id_value,y,x,city_class)
{
	window.scroll(0,0);
	var text_val=document.getElementById(id_value).value;
	if (text_val=="")
	{
		TJ_text_list(id_value,y,x,city_class);
	}else{
		if(text_val!="" && (text_val.charCodeAt() <= 127) && (text_val.charCodeAt() >= 0)){
			url="../web_include/city_ul.asp?val="+text_val+"&city_class="+city_class;
			createXMLHttpRequest(); 
			xmlHttp.onreadystatechange=handleStateChange_list_ul; 
			xmlHttp.open("GET",url,true); 
			xmlHttp.send(null); 
			open_table(event,'list_ul',y,x);
		}else{
			showAndHide('list_ul','hide');
		}
	}
}

function TJ_text_list(id_value,y,x,city_class)
{
	window.scroll(0,0);
	var text_val=document.getElementById(id_value).value;
//	url="../web_include/city_ul.asp?val="+text_val+"&city_class="+city_class;
	url="../web_include/city_ul_TJ.asp?city_class="+city_class;
//	alert(url);
//	if(text_val!=""){
		createXMLHttpRequest(); 
		xmlHttp.onreadystatechange=handleStateChange_list_ul; 
		xmlHttp.open("GET",url,true); 
		xmlHttp.send(null); 
		open_table(event,'list_ul',y,x);
//	}
}

function read_table_list(y,x,city_class)
{
	window.scroll(0,0);
	url="../web_include/city_table.asp?city_class="+city_class;
	createXMLHttpRequest(); 
	xmlHttp.onreadystatechange=handleStateChange_list_table; 
	xmlHttp.open("GET",url,true); 
	xmlHttp.send(null); 
	open_table(event,'list_table',y,x);
}

function setvar(val_cn,val,city_class){
	if(city_class=="start"){
		document.getElementById("StartCity01_cn").value=val_cn;
		document.getElementById("StartCity01").value=val;
		changecity="end";
	}
	if(city_class=="end"){
		document.getElementById("EndCity01_cn").value=val_cn;
		document.getElementById("EndCity01").value=val;
	}
}

var changecity="start"
function mapsetvar(val_cn,val){
	if(document.getElementById("StartCity01_cn").value=="" && changecity!="end"){
		document.getElementById("StartCity01_cn").value=val_cn;
		document.getElementById("StartCity01").value=val;
	}else if(document.getElementById("EndCity01_cn").value=="" && changecity!="start"){
		document.getElementById("EndCity01_cn").value=val_cn;
		document.getElementById("EndCity01").value=val;
	}
	if(changecity=="start"){
		if (document.getElementById("StartCity01_cn").value=="")
		{
			document.getElementById("StartCity01_cn").value=val_cn;
			document.getElementById("StartCity01").value=val;
		}
		changecity="end";	
	}else{
		if (document.getElementById("EndCity01_cn").value=="")
		{
			document.getElementById("EndCity01_cn").value=val_cn;
			document.getElementById("EndCity01").value=val;
		}
//		changecity="start";
	}
//	else{
//		document.getElementById("StartCity01_cn").value=val_cn;
//		document.getElementById("StartCity01").value=val;	
//	}
}

function S(i){
	return document.getElementById(i);
}

function open_table(evt,show_div,left_flag,top_flag){
	
//	var left_flag=-251 //×óÓÒÆ«ÒÆÖµ
//	var top_flag=29 //ÉÏÏÂÆ«ÒÆÖµ
	var left=(document.body.offsetWidth/2)+left_flag+document.getElementById("dot").offsetWidth;
	var top=top_flag+document.getElementById("dot").offsetHeight;
	var list_table = S(show_div);
	list_table.style.top = top + document.body.scrollTop ;
	list_table.style.left = left + document.body.scrollLeft;
//	list_table.style.top = window.event.y + document.body.scrollTop +document.getElementById("dot").offsetTop;
//	list_table.style.left = window.event.x + document.body.scrollLeft-180+document.getElementById("dot").offsetLeft;
//	list_table.style.top = window.event.y + document.body.scrollTop;
//	list_table.style.left = window.event.x + document.body.scrollLeft-180 + document.getElementById("dot").offsetWidth;
	Show(show_div, true );
}

function Show(obj, bShow){
	obj = (typeof(obj) == "string" ? S(obj) : obj);
	if (obj) obj.style.display= (bShow ? "" : "none");
}

function showAndHide(obj,types){ 
	var Layer=window.document.getElementById(obj); 
	switch(types){ 
		case "show": 
			Layer.style.display="block"; 
			break; 
		case "hide": 
			Layer.style.display="none"; 
	} 
}


function mapmenushow(Province) {
	url="../web_include/city_map_menu.asp?Province="+Province;
	createXMLHttpRequest(); 
	xmlHttp.onreadystatechange=handleStateChange_map_menu; 
	xmlHttp.open("GET",url,true); 
	xmlHttp.send(null); 

	newX = window.event.clientX + document.body.scrollLeft + document.body.clientLeft -10;
	newY = window.event.clientY + document.body.scrollTop + document.body.clientTop -15;
	document.all.itemopen.style.display = "";
	document.all.itemopen.style.pixelLeft = newX;
	document.all.itemopen.style.pixelTop = newY;
	
//	menu = document.all.itemopen;
//	menu.style.display = "";
//	menu.style.pixelLeft = newX;
//	menu.style.pixelTop = newY;
}

function mapmenuclose(){
	document.all.itemopen.style.display = "none";
//	menu = document.all.itemopen
//	menu.style.display = "none";
}

function show_go_back_info(tr)
{
	if (document.getElementById(tr).style.display=="none")
	{
		document.getElementById(tr).style.display="block";
	}
	else
	{
		document.getElementById(tr).style.display="none";
	}
}
function show_airtext(name,color,width)
{
	url="../web_include/airtext.asp?name="+name;
	createXMLHttpRequest(); 
	xmlHttp.onreadystatechange=handleStateChange_dhtmltooltip; 
	xmlHttp.open("GET",url,true); 
	xmlHttp.send(null); 
	ddrivetip(document.getElementById("dhtmltooltip").innerHTML,color,width);
}

function show_visor(flyNo,bunk_fly_type_show,bunkvalue,color,width)
{
	url="../web_include/visor.asp?flyNo="+flyNo+"&bunk_fly_type_show="+bunk_fly_type_show+"&bunkvalue="+bunkvalue;
	createXMLHttpRequest(); 
	xmlHttp.onreadystatechange=handleStateChange_dhtmltooltip; 
	xmlHttp.open("GET",url,true); 
	xmlHttp.send(null); 
	ddrivetip(document.getElementById("dhtmltooltip").innerHTML,color,width);
}

function FI_opentabletr(tr_id){
	window.document.getElementById(tr_id).style.display = "";
}