﻿var cityAction = [null, null, null, null, null, null, null, null, null];//当前点击的城市插件
//城市插件,参数说明：obj(显示全部城市名称的控件的dom对象),value_id(把城市id存进去的隐藏控件的id)
var show_input_id;
var value_input_id;
function city(show_id,value_id,city_arr_id,defalut_id,default_value) {
	if(eval('typeof(' + city_arr_id + ')') == 'undefined') {
		if(city_arr_id == 'city_arr') {//时刻表
			cityAction = ['city_arr','city', show_id, value_id, city_arr_id, defalut_id, default_value, null, null];
		}else if(city_arr_id == 'timetable_city_arr') {
			cityAction = ['timetable_city_arr','city', show_id, value_id, city_arr_id, defalut_id, default_value, null, null];
		}
	}else {
		calbackCity(show_id,value_id,city_arr_id,defalut_id,default_value);
	}
}
function calbackCity(show_id,value_id,city_arr_id,defalut_id,default_value) {
	var city_arr_local;
	eval('city_arr_local = ' + city_arr_id);
	show_input_id = show_id;
	value_input_id = value_id;
	var show_obj = document.getElementById(show_id);
	var value_obj = document.getElementById(value_id);
	var left = show_obj.offsetLeft;//文本框的左边位置
	var bottom = show_obj.offsetTop + 25;//文本框的下边位置
	var obj = show_obj;
	while(obj=obj.offsetParent){
		bottom += obj.offsetTop; 
		left += obj.offsetLeft; 
	} 
	/*先给body一个值*/
	if(typeof(document.getElementById('city')) != 'undefined' && document.getElementById('city') != null) {
		document.getElementById('city').style.display = 'block';
	}else {
		/*先拼个空的城市控件来*/
		var bodyHtml = '<div id="city" class="city_tips" style="z-index:1000;width:300px;position: absolute;top:100px;left:0;">';
		bodyHtml += '<div class="city_tips_boder">';
		bodyHtml += '<ul class="fenl_list">';
		bodyHtml += '<li id="top_city_tip_id" onclick="tab_city(\'top_city\')">热门</li>';
		bodyHtml += '<li id="ag_city_tip_id" onclick="tab_city(\'ag_city\')">A-G</li>';
		bodyHtml += '<li id="hl_city_tip_id" onclick="tab_city(\'hl_city\')">H-L</li>';
		bodyHtml += '<li id="mt_city_tip_id" onclick="tab_city(\'mt_city\')">M-T</li>';
		bodyHtml += '<li id="uz_city_tip_id" onclick="tab_city(\'uz_city\')">U-Z</li>';
		bodyHtml += '</ul>';
		bodyHtml += '<div class="clear"></div>';
		bodyHtml += '<ul id="top_city" class="city_list"></ul>';
		bodyHtml += '<ul id="ag_city" class="city_list" style="display:none;"></ul>';
		bodyHtml += '<ul id="hl_city" class="city_list" style="display:none;"></ul>';
		bodyHtml += '<ul id="mt_city" class="city_list" style="display:none;"></ul>';
		bodyHtml += '<ul id="uz_city" class="city_list" style="display:none;"></ul>';
		bodyHtml += '</div>';
		bodyHtml += '</div>';
		if(typeof (document.getElementById('iframe'))=='undefined'||document.getElementById('iframe')==null){
					bodyHtml += '<iframe id="iframe" style="border:0;z-index:999;position:absolute"></iframe>';
		}
		$("body").append(bodyHtml);
		//document.body.innerHTML = document.body.innerHTML + bodyHtml;
	}
	/*往城市控件里面塞值*/
	var inner_flag = 0;
	var inner_str = '';
	for(var i = 0;i < city_arr_local.length;i++) {//先拼热门的
		var one_city_arr = city_arr_local[i];
		if(one_city_arr[4] == true) {
			inner_str += '<li><a  href="javascript:return_value(\'' + one_city_arr[0] + '|' + one_city_arr[7] + '|' + one_city_arr[5] + '|' + one_city_arr[6] + '\',\'' + one_city_arr[3] + '\')" class="blue_31">' + one_city_arr[3] + '</a></li>';
		}
	}
	document.getElementById('top_city').innerHTML = inner_str;
	var num = 0;
	inner_flag = 0;
	inner_str = '';
	for(var i = 0;i < city_arr_local.length;i++) {//再拼a到z的
		var one_city_arr = city_arr_local[i];
		if(pub_a_to_g(one_city_arr[1].substr(0,1).toLowerCase())) {
			inner_str += '<li><a  href="javascript:return_value(\'' + one_city_arr[0] + '|' + one_city_arr[7] + '|' + one_city_arr[5] + '|' + one_city_arr[6] + '\',\'' + one_city_arr[3] + '\')" class="blue_31">' + one_city_arr[3] + '</a></li>';
			num++;
			if(num == 50) {
				break;
			}
		}
	}
	document.getElementById('ag_city').innerHTML = inner_str;
	num = 0;
	inner_flag = 0;
	inner_str = '';
	for(var i = 0;i < city_arr_local.length;i++) {//再拼h到l的
		var one_city_arr = city_arr_local[i];
		if(pub_h_to_l(one_city_arr[1].substr(0,1).toLowerCase())) {
			inner_str += '<li><a  href="javascript:return_value(\'' + one_city_arr[0] + '|' + one_city_arr[7] + '|' + one_city_arr[5] + '|' + one_city_arr[6] + '\',\'' + one_city_arr[3] + '\')" class="blue_31">' + one_city_arr[3] + '</a></li>';
			num++;
			if(num == 50) {
				break;
			}
		}
	}
	document.getElementById('hl_city').innerHTML = inner_str;
	num = 0;
	inner_flag = 0;
	inner_str = '';
	for(var i = 0;i < city_arr_local.length;i++) {//再拼m到t的
		var one_city_arr = city_arr_local[i];
		if(pub_m_to_t(one_city_arr[1].substr(0,1).toLowerCase())) {
			inner_str += '<li><a  href="javascript:return_value(\'' + one_city_arr[0] + '|' + one_city_arr[7] + '|' + one_city_arr[5] + '|' + one_city_arr[6] + '\',\'' + one_city_arr[3] + '\')" class="blue_31">' + one_city_arr[3] + '</a></li>';
			num++;
			if(num == 50) {
				break;
			}
		}
	}
	document.getElementById('mt_city').innerHTML = inner_str;
	num = 0;
	inner_flag = 0;
	inner_str = '';
	for(var i = 0;i < city_arr_local.length;i++) {//再拼u到z的
		var one_city_arr = city_arr_local[i];
		if(pub_u_to_z(one_city_arr[1].substr(0,1).toLowerCase())) {
			inner_str += '<li><a  href="javascript:return_value(\'' + one_city_arr[0] + '|' + one_city_arr[7] + '|' + one_city_arr[5] + '|' + one_city_arr[6] + '\',\'' + one_city_arr[3] + '\')" class="blue_31">' + one_city_arr[3] + '</a></li>';
			num++;
			if(num == 50) {
				break;
			}
		}
	}
	document.getElementById('uz_city').innerHTML = inner_str;
	bindClick(defalut_id,default_value);
	
	/*改变城市控件的位置*/
	var cityObj = document.getElementById('city');
	var iframeObj = document.getElementById('iframe');
	cityObj.style.top = bottom + 'px';
	cityObj.style.left = left + 'px';
	iframeObj.style.width = '300px';
	iframeObj.style.display = 'block';
	iframeObj.style.top = bottom + 'px';
	iframeObj.style.left = left + 'px';
	iframeObj.style.height=$('#city').height()+"px";
	tab_city('top_city');
}

/*把值返回到页面，并且关闭控件*/
function return_value(city_id,city_name,show_id,value_id) {
	cityAction = [null, null, null, null, null, null, null, null, null];
	document.getElementById(show_input_id).value = city_name;
	document.getElementById(value_input_id).value = city_id;
	document.getElementById(show_input_id).style.color = '#000000';
	document.getElementById('city').style.display = 'none';
	document.getElementById('iframe').style.display = 'none';
	if(typeof(document.getElementById('nowDate')) != 'undefined' && document.getElementById('nowDate') != null && value_input_id=='bookStartCityId') {
		changeDateSelect(value_input_id);
	}
}

/*判断字符在a到g的范围内*/
function pub_a_to_g(str) {
	if(str == 'a' || str == 'b' || str == 'c' || str == 'd' || str == 'e' || str == 'f' || str == 'g') {
		return true;
	}
	return false;
}

/*判断字符在h到l的范围内*/
function pub_h_to_l(str) {
	if(str == 'h' || str == 'i' || str == 'j' || str == 'k' || str == 'l') {
		return true;
	}
	return false;
}

/*判断字符在m到t的范围内*/
function pub_m_to_t(str) {
	if(str == 'm' || str == 'n' || str == 'o' || str == 'p' || str == 'q' || str == 'r' || str == 's' || str == 't') {
		return true;
	}
	return false;
}

/*判断字符在u到z的范围内*/
function pub_u_to_z(str) {
	if(str == 'u' || str == 'v' || str == 'w' || str == 'x' || str == 'y' || str == 'z') {
		return true;
	}
	return false;
}

/*切换城市*/
function tab_city(id) {
	block_to_none('top_city');
	block_to_none('ag_city');
	block_to_none('hl_city');
	block_to_none('mt_city');
	block_to_none('uz_city');
	document.getElementById('top_city_tip_id').className = '';
	document.getElementById('ag_city_tip_id').className = '';
	document.getElementById('hl_city_tip_id').className = '';
	document.getElementById('mt_city_tip_id').className = '';
	document.getElementById('uz_city_tip_id').className = '';
	document.getElementById(id + '_tip_id').className = 'fl_active';
	document.getElementById(id).style.display = 'block';
	//document.getElementById('iframe').style.height = $('#'+id).height()<60?60:$('#'+id).height();
	document.getElementById('iframe').style.height=$('#city').height();
}

/*隐藏标签*/
function block_to_none(id) {
	document.getElementById(id).style.display = 'none';
}

/*关闭城市插件*/
function close_city(obj,defalut_id,default_value) {
	cityAction = [null, null, null, null, null, null, null, null, null];
	if(typeof(document.getElementById('city')) != 'undefined' && document.getElementById('city') != null && obj != document.getElementById('city')) {
		if(document.getElementById('city').style.display != 'none') {
			document.getElementById('city').style.display = 'none';
			document.getElementById('iframe').style.display = 'none';
		}
	}
	if(typeof(document.getElementById('city_select')) != 'undefined' && document.getElementById('city_select') != null && obj != document.getElementById('city_select')) {
		if(document.getElementById('city_select').style.display != 'none') {
			document.getElementById('city_select').style.display = 'none';
			document.getElementById('iframe').style.display = 'none';
		}
	}
	if(glob_city != null) {
		return_select_value(glob_city[0]+'|'+glob_city[7]+'|'+glob_city[5]+'|'+glob_city[6],glob_city[3]);
	}else {
		if(document.getElementById(show_input_id).value.replace(/(^\s+)|\s+$/g, "") == '') {
			return_select_value(defalut_id,default_value);
		}
	}
	golb_city_arr = null;
	glob_city = null;
}

/*给body下面的所有dom节点绑定事件*/
function bindClick(defalut_id,default_value) {
	 /*document.body.onclick = function() {
	  close_city(this,defalut_id,default_value);
	};*/
	var oHtml=document.body.childNodes;
	for(var i = 0;i < oHtml.length;i++) {
		try{
		oHtml[i].onmouseup = function() {
		  close_city(this,defalut_id,default_value);
		};
		}catch(e){}
	}
}

/*事件绑定*/
addEventListenerNew = function(control, eventName, fn) {
  // IE下
	if (window.attachEvent) {
		control.attachEvent('on' + eventName, function(e) {fn.call(control, e);});
	  // Firefox and Chrome
	} else if (window.addEventListener) {
		control.addEventListener(eventName, fn, false);
	  // 一般情况
	} else {
		control['on' + eventName] = fn;
	}
};




var golb_city_arr;
var glob_city;
var choose_num;
/*根据输入文字显示可选择的城市*/
var citySelectTmpValue = '';
function city_select(show_id,value_id,city_arr_id,defalut_id,default_value,e,clickStr) {
	if(eval('typeof(' + city_arr_id + ')') == 'undefined') {
		if(city_arr_id == 'city_arr') {//时刻表
			cityAction = ['city_arr','city_select', show_id, value_id, city_arr_id, defalut_id, default_value, e, clickStr];
		}else if(city_arr_id == 'timetable_city_arr') {
			cityAction = ['timetable_city_arr','city_select', show_id, value_id, city_arr_id, defalut_id, default_value, e, clickStr];
		}
	}else {
		calbackCity_select(show_id,value_id,city_arr_id,defalut_id,default_value,e,clickStr);
	}
}
function calbackCity_select(show_id,value_id,city_arr_id,defalut_id,default_value,e,clickStr) {
	var tmpValue = document.getElementById(show_id).value;
	//38表示向上，40表示向下，13表示回车
	var city_code = e.keyCode;//键盘码
	show_input_id = show_id;
	value_input_id = value_id;
	var show_obj = document.getElementById(show_id);
	var value_obj = document.getElementById(value_id);
	var left = show_obj.offsetLeft;//文本框的左边位置
	var bottom = show_obj.offsetTop + 25;//文本框的下边位置
	var obj = show_obj;
	while(obj=obj.offsetParent){
		bottom += obj.offsetTop; 
		left += obj.offsetLeft; 
	} 
	if(city_code == 38) {//向上的键
		if(golb_city_arr.length > 0) {
			if(choose_num == 0) {
				choose_num = golb_city_arr.length - 1;
			}else {
				choose_num = choose_num - 1;
			}
			up_down();
		}
	}else if(city_code == 40) {//向下键
		if(golb_city_arr.length > 0) {
			if(choose_num == golb_city_arr.length - 1) {
				choose_num = 0;
			}else {
				choose_num = choose_num + 1;
			}
			up_down();
		}
	}else if(city_code == 13 && citySelectTmpValue == tmpValue) {//回车键
		if(glob_city != null) {
			return_select_value(glob_city[0]+'|'+glob_city[2]+'|'+glob_city[5]+'|'+glob_city[6],glob_city[3]);
		}else if(typeof(clickStr) != 'undefined') {
			eval(clickStr);
		}
	}else {
		choose_num = '';
		glob_city = null;
		golb_city_arr = null;
		var input_value = document.getElementById(show_id).value;
		if(input_value == '') {
			if(typeof(document.getElementById('city_select')) != 'undefined' && document.getElementById('city_select') != null) {
				document.getElementById('city_select').style.display = 'none';
				document.getElementById('iframe').style.display = 'none';
			}
		}else {
			/*先拼出字符串*/
			if(typeof(document.getElementById('city_select')) != 'undefined' && document.getElementById('city_select') != null) {
				document.getElementById('city_select').style.display = 'block';
			}else {
				var bodyHtml = '<div id="city_select" style="z-index:1000;position: absolute;top:100px;left:0;width:190px;background:#fff;border:1px solid #7f9eb9;padding:0px 5px;">';
				bodyHtml += '<div style="height:26px;line-height:26px;border-bottom:1px dashed #cccccc;">';
				bodyHtml += '输入中文/拼音后上下键选择';
				bodyHtml += '</div>';
				bodyHtml += '<div id="city_select_choose" class="select_city_list"></div>';
				bodyHtml += '<div class="clear"></div></div>';
				if(typeof (document.getElementById('iframe'))=='undefined'||document.getElementById('iframe')==null){
					bodyHtml += '<iframe id="iframe" style="border:0;z-index:999;position:absolute"></iframe>';
				}
				$("body").append(bodyHtml);
				//document.body.innerHTML = document.body.innerHTML + bodyHtml;
			}
			/*得到选择城市的列表*/
			var city_choose_arr = initials_city(input_value,city_arr_id);
			if(city_choose_arr.length <10) {
				city_choose_arr = spelling_city(city_choose_arr,input_value,city_choose_arr.length,city_arr_id);
			}
			if(city_choose_arr.length <10) {
				city_choose_arr = name_city(city_choose_arr,input_value,city_choose_arr.length,city_arr_id);
			}
			/*开始拼进城市列表*/
			var city_select = document.getElementById('city_select_choose');
			var inner_str = '';
			if(city_choose_arr.length == 0) {
				inner_str += '<div class="select_city">暂无收录</div>';
			}else {
				for(var i = 0;i < city_choose_arr.length;i++) {
					inner_str += '<div><a id="choose_city' + i + '" class="select_city" href="javascript:return_select_value(\'' + city_choose_arr[i][0] + '|' + city_choose_arr[i][7] + '|' + city_choose_arr[i][5] + '|' + city_choose_arr[i][6] + '\',\'' + city_choose_arr[i][3] + '\')">' + city_choose_arr[i][3] + '</a></div>';
				}
			}
			inner_str += '<div class="clear"></div>';
			city_select.innerHTML = inner_str;
			bindClick(defalut_id,default_value);
			golb_city_arr = city_choose_arr;
			if(city_choose_arr.length > 0) {
				choose_num = 0;
				up_down();
			}
			
			/*改变城市选择控件的位置*/
			var cityObj = document.getElementById('city_select');
			var iframeObj = document.getElementById('iframe');
			iframeObj.style.display = 'block';
			iframeObj.style.width='190px';
			iframeObj.style.height=$('#city_select').height()+"px";
			cityObj.style.top = bottom + 'px';
			cityObj.style.left = left + 'px';
			iframeObj.style.top = bottom + 'px';
			iframeObj.style.left = left + 'px';
		}
		citySelectTmpValue = tmpValue;
	}
}

/*返回一个根据头字母判断的列表*/
function initials_city(str,city_arr_id) {
	var city_arr_local;
	eval('city_arr_local = ' + city_arr_id);
	var len = str.length;//字符的长度
	var num = 0;
	var city_choose_arr=new Array();
	for(var i = 0;i < city_arr_local.length;i++) {
		var one_city_arr = city_arr_local[i];
		if(one_city_arr[1].length >= len && one_city_arr[1].substr(0,len).toLowerCase() == str.toLowerCase()) {
			city_choose_arr.push(one_city_arr);
			num++;
			if(num == 10) {
				break;
			}
		}
	} 
	return city_choose_arr;
}

/*返回一个根据全拼判断的列表*/
function spelling_city(city_choose_arr,str,num,city_arr_id) {
	var city_arr_local;
	eval('city_arr_local = ' + city_arr_id);
	var len = str.length;//字符的长度
	if(len > 1) {
		for(var i = 0;i < city_arr_local.length;i++) {
			var one_city_arr = city_arr_local[i];
			if(one_city_arr[2].length >= len && one_city_arr[2].substr(0,len).toLowerCase() == str.toLowerCase()) {
				city_choose_arr.push(one_city_arr);
				num++;
				if(num == 10) {
					break;
				}
			}
		} 
	}
	return city_choose_arr;
}

/*返回根据全名判断的列表*/
function name_city(city_choose_arr,str,num,city_arr_id) {
	var city_arr_local;
	eval('city_arr_local = ' + city_arr_id);
	var len = str.length;//字符的长度
	for(var i = 0;i < city_arr_local.length;i++) {
		var one_city_arr = city_arr_local[i];
		if(one_city_arr[3].length >= len && one_city_arr[3].substr(0,len).toLowerCase() == str.toLowerCase()) {
			city_choose_arr.push(one_city_arr);
			num++;
			if(num == 10) {
				break;
			}
		}
	} 
	return city_choose_arr;
}

function return_select_value(city_id,city_name,show_id,value_id) {
	cityAction = [null, null, null, null, null, null, null, null, null];
	document.getElementById(show_input_id).value = city_name;
	document.getElementById(value_input_id).value = city_id;
	document.getElementById(show_input_id).style.color = '#000000';
	if(document.getElementById('city_select') != null) {
		document.getElementById('city_select').style.display = 'none';
		document.getElementById('iframe').style.display = 'none';
	}
	citySelectTmpValue = city_name;
	glob_city = null;
	if(typeof(document.getElementById('nowDate')) != 'undefined' && document.getElementById('nowDate') != null && value_input_id=='bookStartCityId') {
		changeDateSelect(value_input_id);
	}
}

/*点击上下键的效果*/
function up_down() {
	glob_city = golb_city_arr[choose_num];
	for(var i = 0;i < golb_city_arr.length;i++) {
		document.getElementById('choose_city' + i).style.color = '#000000';
		document.getElementById('choose_city' + i).className = 'select_city';
	}
	document.getElementById('choose_city' + choose_num).style.color = '#ffffff';
	document.getElementById('choose_city' + choose_num).className = 'select_city_new';
}




/*获取字符串长度，中文算两个字符，英文算一个字符*/
function getLength(str) {
   str = str.replace(/(^\s*)|(\s*$)/g, "");//删除二边空格
   var totallength=0;   
   for (var i=0;i<str.length;i++)
   {
    var intCode=str.charCodeAt(i); 
      if (intCode>=0&&intCode<=128) {
      totallength=totallength+1; //非中文单个字符长度加 1
      }
     else {
      totallength=totallength+2; //中文字符长度则加 2
      }
   } 
   return totallength;
};

/*预订目的城市插件*/
var end_golb_city_arr = new Array();
var end_glob_city;
var end_choose_num;
var end_last_choose_num;
function inner_city_str(st_city_id,end_city_id,end_city_str,levelStr,end_loading_id,e,clickStr) {
	var tmpValue = document.getElementById(end_city_str).value;
	var st_city_id_value = document.getElementById(st_city_id).value;
	if(st_city_id_value != null && st_city_id_value.indexOf('|') != -1) {
		//38表示向上，40表示向下，13表示回车
		var city_code = e.keyCode;//键盘码
		
		var end_city_id_obj = document.getElementById(end_city_id);
		var end_city_name_obj = document.getElementById(end_city_str);
		var st_city_id = st_city_id_value.split('|')[0];
		var left = end_city_name_obj.offsetLeft;//文本框的左边位置
		var bottom = end_city_name_obj.offsetTop + 25;//文本框的下边位置
		var obj = end_city_name_obj;
		while(obj=obj.offsetParent){
			bottom += obj.offsetTop; 
			left += obj.offsetLeft; 
		} 
		if(city_code == 38) {//向上的键
			if(end_golb_city_arr.length > 0) {
				if(end_choose_num == 0) {
					end_choose_num = end_golb_city_arr.length - 1;
				}else {
					end_choose_num = end_choose_num - 1;
				}
				end_up_down();
			}
		}else if(city_code == 40) {//向下键
			if(end_golb_city_arr.length > 0) {
				if(end_choose_num == end_golb_city_arr.length - 1) {
					end_choose_num = 0;
				}else {
					end_choose_num = end_choose_num + 1;
				}
				end_up_down();
			}
		}else if(city_code == 13 && citySelectTmpValue == tmpValue) {//回车键
			if(end_glob_city != null) {
				return_select_end_value(end_glob_city[0],end_glob_city[1],end_city_id,end_city_str);
			}else if(typeof(clickStr) != 'undefined') {
				eval(clickStr);
			}
		}else if(end_city_name_obj.value.replace(/(^\s*)|(\s*$)/g, "") != '' && getLength(end_city_name_obj.value.replace(/(^\s*)|(\s*$)/g, "")) >= 2) {//只有字符数大于等于2才提交ajax) {
			end_city_id_obj.value='';
			end_golb_city_arr.splice(0,end_golb_city_arr.length);
			end_glob_city = null;
			end_choose_num = null;
			var url = encodeURI(encodeURI("http://www.trip8080.com/endcity.htm?bookStartCityId=" + st_city_id + "&bookEndCityName=" + end_city_name_obj.value));
			$.ajax({
				url : url,
				type : "post",
				dataType : "json",
				cache: false,
				beforeSend : function() {
					$('#' + end_loading_id).show();
				},
				success : function(city_menu) {
					//alert(1)
					if(typeof(document.getElementById('city_select')) != 'undefined' && document.getElementById('city_select') != null) {
						document.getElementById('city_select').style.display = 'block';
					}else {
						var bodyHtml = '<div id="city_select" style="z-index:1000;position: absolute;top:100px;left:0;width:190px;background:#fff;border:1px solid #7f9eb9;padding:0px 5px;overflow-y:auto;overflow-x:hidden;max-height:400px;_height:expression(this.scrollHeight>400?400:this.scrollHeight);">';
						bodyHtml += '<div style="height:26px;line-height:26px;border-bottom:1px dashed #cccccc;">';
						bodyHtml += '输入中文/拼音后上下键选择';
						bodyHtml += '</div>';
						bodyHtml += '<div id="city_select_choose" class="select_city_list"></div>';
						bodyHtml += '<div class="clear"></div></div>';
						if(typeof (document.getElementById('iframe'))=='undefined'||document.getElementById('iframe')==null){
							bodyHtml += '<iframe id="iframe" style="border:0;z-index:999;position:absolute"></iframe>';
						}
						$("body").append(bodyHtml);
					}
					var inner_str = '';
					end_golb_city_arr.splice(0,end_golb_city_arr.length);
					if(city_menu.length > 0) {
						for(var i in city_menu) {
							if(city_menu[i].carryStaId == -1) {
								inner_str += '<div><a id="choose_city' + i + '" class="select_city" href="javascript:return_select_end_value(\'' + city_menu[i].carryStaId + '|' + city_menu[i].endCityId + '\',\'' + city_menu[i].endCityName + '\',\'' + end_city_id + '\',\'' + end_city_str + '\')">' + city_menu[i].endCityName + '<' + city_menu[i].provName + '>' + '</a></div>';
							}else {
								inner_str += '<div><a id="choose_city' + i + '" class="select_city" href="javascript:return_select_end_value(\'' + city_menu[i].carryStaId + '|' + city_menu[i].endCityId + '\',\'' + city_menu[i].endCityName + '\',\'' + end_city_id + '\',\'' + end_city_str + '\')">' + city_menu[i].endCityName + '(' + city_menu[i].CarryStaName + ')' + '<' + city_menu[i].provName + '>' + '</a></div>';
							}
							end_golb_city_arr.push([city_menu[i].carryStaId + '|' +city_menu[i].endCityId ,city_menu[i].endCityName]);
						}
					}else {
						inner_str += '<div class="select_city">暂无收录</div>';
					}
					inner_str += '<div class="clear"></div>';
					var city_select = document.getElementById('city_select_choose');
					city_select.innerHTML = inner_str;
					bindClickNew(end_city_id,end_city_str);
					if(end_golb_city_arr.length > 0) {
						end_choose_num = 0;
						end_up_down();
					}
					/*改变城市选择控件的位置*/
					var cityObj = document.getElementById('city_select');
					var iframeObj = document.getElementById('iframe');
					cityObj.style.top = bottom + 'px';
					cityObj.style.left = left + 'px';
					iframeObj.style.display = "block";
					iframeObj.style.width = '190px';
					iframeObj.style.height=$('#city_select').height()+"px";
					iframeObj.style.top = bottom + 'px';
					iframeObj.style.left = left + 'px';
					$('#' + end_loading_id).hide();
				}
			});
			citySelectTmpValue = tmpValue;
		}else {
			if(typeof(document.getElementById('city_select')) != 'undefined' && document.getElementById('city_select') != null && obj != document.getElementById('city_select')) {
				if(document.getElementById('city_select').style.display != 'none') {
					document.getElementById('city_select').style.display = 'none';
					document.getElementById('iframe').style.display = 'none';
				}
			}
			document.getElementById(end_city_id).value = '';
		}
	}
}

/*点击目的城市插件上下键的效果*/
function end_up_down() {
	end_glob_city = end_golb_city_arr[end_choose_num];
	if(typeof(document.getElementById("choose_city" + end_last_choose_num)) != 'undefined' && document.getElementById("choose_city" + end_last_choose_num) != null) {
		document.getElementById('choose_city' + end_last_choose_num).style.color = '#000000';
		document.getElementById('choose_city' + end_last_choose_num).className = 'select_city';
	}
	document.getElementById('choose_city' + end_choose_num).style.color = '#ffffff';
	document.getElementById('choose_city' + end_choose_num).className = 'select_city_new';
	end_last_choose_num = end_choose_num;
}


function bindClickNew(end_city_id,end_city_str) {
	/*document.body.onclick = function() {
		close_city_new(this,end_city_id,end_city_str);
	};*/
	var oHtml=document.body.childNodes;
	for(var i = 0;i < oHtml.length;i++) {
		oHtml[i].onmouseup = function() {
		  close_city_new(this,end_city_id,end_city_str);
		};
	}
}

/*关闭目的城市插件*/
function close_city_new(obj,end_city_id,end_city_str) {
	if(typeof(document.getElementById('city_select')) != 'undefined' && document.getElementById('city_select') != null && obj != document.getElementById('city_select')) {
		if(document.getElementById('city_select').style.display != 'none') {
			document.getElementById('city_select').style.display = 'none';
			document.getElementById('iframe').style.display = 'none';
		}
	}
	if(end_glob_city != null) {
		return_select_end_value(end_glob_city[0],end_glob_city[1],end_city_id,end_city_str);
	}
	end_golb_city_arr.splice(0,end_golb_city_arr.length);
	end_glob_city = null;
}

function return_select_end_value(end_city_id,end_city_name,end_city_id_input,end_city_name_input) {
	document.getElementById(end_city_id_input).value = end_city_id;
	document.getElementById(end_city_name_input).value = end_city_name;
	document.getElementById(end_city_name_input).style.color = '#000000';
	document.getElementById('city_select').style.display = 'none';
	document.getElementById('iframe').style.display = 'none';
	citySelectTmpValue = end_city_name;
	end_glob_city = null;
}



/*提交查询预订列表的表单*/
function booklist_click() {
	var startCityId = document.getElementById('bookStartCityId').value;
	var endCityId = document.getElementById('bookEndCityId').value;
	var searchDate = document.getElementById('bookStartDate').value;
	if(startCityId.replace(/(^\s*)|(\s*$)/g, "") != '' && endCityId.replace(/(^\s*)|(\s*$)/g, "") != '' && searchDate.replace(/(^\s*)|(\s*$)/g, "") != '') {
		pv(1,[startCityId.split("|")[0],endCityId.split("|")[1],searchDate.replace(/(^\s*)|(\s*$)/g, ""),document.getElementById('bookStartCityName').value,document.getElementById('bookEndCityName').value]);
		var url = document.booklist_form.action;
		if(url.indexOf('search=') == -1) {
			startCityId = startCityId.replace("|","-");
			endCityId = endCityId.replace("|","-");
			if(url.split('?').length > 1) {
				url += '&search=' + document.getElementById('bookStartCityName').value + '_' + document.getElementById('bookEndCityName').value + '的汽车票--' + startCityId + '--' + endCityId;
			}else {
				url += '?search=' + document.getElementById('bookStartCityName').value + '_' + document.getElementById('bookEndCityName').value + '的汽车票--' + startCityId + '--' + endCityId;
			}
			url = encodeURI(encodeURI(url));
			//window.location.href = url;
			document.booklist_form.action = url;
			document.booklist_form.submit();
		}
	}
}

function date_key(e) {
	var date_code = e.keyCode;//键盘码
	if(date_code == 13) {
		booklist_click();
	}
}


/*根据出发城市动态的改变出发时间的限制*/
function changeDateSelect(startCityId) {
	var nowDate = document.getElementById('nowDate').value;
	if(typeof(nowDate) == 'undefined' || nowDate == null || nowDate == '') {
		nowDate = book_pre_today;
	}
	var cityId = document.getElementById(startCityId).value.split('|')[0];
	eval('var preDay = pre_city_' + cityId + '[1];');
	eval('var maxSellDay = pre_city_' + cityId + '[2];');
	eval('var preMaxDay = pre_city_' + cityId + '[0];');
	var str = '';
	preDay = preDay<=preMaxDay?preDay:preMaxDay;
	var tempPreDay = 0;
	for(var i = 0;i < preDay; i++) {
		var dd = addDate(nowDate,i);
		if(comparDate(maxSellDay,dd) >= 0) {
			if(tempPreDay == 1) {
				str += '<option selected="selected" value="' + dd + ' ' + getWeek(dd) + '">' + dd + ' ' + getWeek(dd) + '</option>';
			}else {
				str += '<option value="' + dd + ' ' + getWeek(dd) + '">' + dd + ' ' + getWeek(dd) + '</option>';
			}
			tempPreDay++;
		}
	}
	preDay = tempPreDay;
	$('#bookStartDate').html(str);
	document.getElementById('bookEndCityId').value = '';
	document.getElementById('bookEndCityName').value = '输入汉字/简拼';
	document.getElementById('bookEndCityName').style.color = '#999999';
	//document.getElementById('bookEndCityName').value = '';
	changePreBtn(startCityId);
}

function changePreBtn(startCityId) {
	//alert(1)
	var cityId = document.getElementById(startCityId).value.split('|')[0];
	eval('var searchFlag = pre_city_' + cityId + '[4];');
	if(searchFlag == 'Y') {
		document.getElementById('searchBooklistBtn').disabled = false;
	}else {
		document.getElementById('searchBooklistBtn').disabled = true;
	}
}

/*选中预订目的城市时*/
function clearEndCityStr() {
	var str = document.getElementById('bookEndCityName').value;
	if(str.replace(/(^\s*)|(\s*$)/g, "") == '输入汉字/简拼') {
		document.getElementById('bookEndCityName').value = '';
		document.getElementById('bookEndCityName').style.color = '#000000';
	}
}

function innerEndCityStr() {
	var str = document.getElementById('bookEndCityName').value;
	if(str.replace(/(^\s*)|(\s*$)/g, "") == '') {
		document.getElementById('bookEndCityName').value = '输入汉字/简拼';
		document.getElementById('bookEndCityName').style.color = '#999999';
	}
}

