// JavaScript Document
document.write("<script language=\"javascript\" src=\"/js/inland.js\"></script>");
function triptypeselect()
{
var kind = "";
var str1 = "";
for (var i=0;i<document.form1.elements.length;i++)
{
	var e = document.form1.elements[i];
      	str1 = e.name;
       	if (str1=="triptype"){
       		if (e.checked==1){
       			kind = e.value;
       			break;
       		}
	}
}	
switch (kind) {
case "1": 
		document.getElementById("fsCity").innerHTML="&nbsp; To: ";
		document.getElementById("seCity").style.display = "none";	
		document.getElementById("Depart").innerHTML = "Depart: ";				
		document.getElementById("tReturn").style.display = "none";	
	        break;
case "2": 
		document.getElementById("fsCity").innerHTML="&nbsp; To: ";
		document.getElementById("seCity").style.display = "none";	
		document.getElementById("Depart").innerHTML = "Depart: ";	
		document.getElementById("Return").innerHTML = "Return: ";	
		document.getElementById("tReturn").style.display = "";	
	        break;
case "3": 
		document.getElementById("fsCity").innerHTML="&nbsp; Fst Arrival: ";
		document.getElementById("seCity").style.display = "";
		document.getElementById("Return").innerHTML = "Sec Depart: ";	
		document.getElementById("Depart").innerHTML = "Fst Depart: ";				
		document.getElementById("tReturn").style.display = "";	
	        break;
default: 
		for (var i=0;i<document.form1.elements.length;i++)
		{
			var e = document.form1.elements[i];
		      	str1 = e.name;
		       	if (str1=="triptype"){
		       		if (e.value=="2"){
		       			e.checked = 1;
		       			break;
		       		}
			}
		}
		document.getElementById("fsCity").innerHTML="&nbsp; To: ";
		document.getElementById("seCity").style.display = "none";	
		document.getElementById("Depart").innerHTML = "Depart: ";	
		document.getElementById("Return").innerHTML = "Return: ";	
		document.getElementById("tReturn").style.display = "";	
	        break;
	}
}

//初始化inpute对象的日期值，theDay为偏移当前多少天
function setdateobj(objID,theDay){		
	today=new Date();
	today.setDate(today.getDate()+theDay);
	yeart = today.getFullYear();
	montht = today.getMonth()+1;
	dayt = today.getDate();
	var obj=document.getElementById(objID);
	obj.value=montht+"/"+dayt+"/"+yeart;
}

$(function(){
//机票查询类型 选择操作
//也 修复IE6 Label 不能聚焦BUG
	$("#js_choiceField_li label").click(function(){
		$(this).children("input").attr("checked",true);
		choose_triptype($(this).children("input").val());
			
	});
//机票首页 点击人等聚焦到文本框操作
	$(".js_fligtsList_Form label,.js_fligtsList_Form input").click(function(){
		if($(this).attr("type") == "submit")
			return;
			//$("#js_fligtsList_Form").submit();
		else
			$(this).select().children("input").select();
		
	});	

	
//机票查询表单提交操作，判断城市输入框
	$("#js_flightsform").submit(function(){
		var strCity = ["startCode1Text","destinationCode1Text","destinationCode2Text"];
		var strCityCode = ["startCode1","destinationCode1","destinationCode2"];

		for (s = 0; s < strCity.length; s++)
		{
			for (r = 0; r < Client_CityName.length; r++)
			{
				if ($("#"+strCity[s]).val().toUpperCase() == Client_CityName[r].toUpperCase())
//				if($("#"+strCity[s]).val().toUpperCase().replace(/ /g,"").indexOf(Client_CityName[r].toUpperCase().replace(/ /g,"")) > -1)
				{
					$("#"+strCityCode[s]).val(Client_CityCode[r]);
					break;
				}
//				else
//					$("#"+strCityCode[s]).val("");
			}
		}
	});
/*==================机票查询结果页===============*/
	
//筛选操作
	$("#flightForm input[type=checkbox]").click(function(){
		
		$("#flightForm").submit();
		return;
		
	});

//结果页搜索框切换（简单-高级）
	$(".js_moreLinkButton").click(function(){
		
		switch ($(this).attr("name"))
		{
			case "js_advanced" :
			
			$("#js_advanced").slideToggle(function(){
												   
				$("#js_simple").slideToggle();
				$(".js_moreLinkButton[name=js_advanced]").attr("name","js_simple").html("Less Choice <img  src=\"/images/bg/bg-dropup.gif\" alt=\"more choice\" />");

			});
			break;
			
			case "js_simple" :

			$("#js_simple").slideToggle(function(){

				$("#js_advanced").slideToggle();
				$(".js_moreLinkButton[name=js_simple]").attr("name","js_advanced").html("More Choice <img  src=\"/images/bg/bg-dropdown.gif\" alt=\"less choice\" />");
			});
			break;

			case "js_more" :
			
			$("#flightForm p").slideDown();
			$(".js_moreLinkButton[name=js_more]").attr("name","js_simple").html("Less Choice <img  src=\"/images/bg/bg-dropup.gif\" alt=\"more choice\" />");			
			$(this).attr("name","js_less");
			break;
			
			case "js_less" :
			
			$("#flightForm p").eq(2).slideUp();
			$("#flightForm p").eq(1).slideUp();
			$(".js_moreLinkButton[name=js_less]").attr("name","js_advanced").html("More Choice <img  src=\"/images/bg/bg-dropdown.gif\" alt=\"less choice\" />");
			$(this).attr("name","js_more");
			break;
		}
	});
//条件排序	
	$(".ParamSort").click(function(){
		if($(this).attr("id") == "OrderByTime")
		{
			$("#orderBy_Price").val("");
			$("#orderBy_Time").val($(this).attr("name"));
		}
		else
		{
			$("#orderBy_Time").val("");
			$("#orderBy_Price").val($(this).attr("name"));
		}
		$("#flightForm").submit();
	});
	
//作用页面 flight-list.asp flight-list-02.asp
//机票ALL Classes	展开效果

	$(".flightResult .allclass").click(function(){
		var strtmp = $(this).attr("name");
		var arrstrtmp = strtmp.split("_");

		var cstar = arrstrtmp[0];
		var cdest = arrstrtmp[1];
		var id = arrstrtmp[2];
		var queryId = arrstrtmp[3];
		var blsave = arrstrtmp[4];
		var datapag;
		
		var curr = $("input[name=currency]:checked").val();	//币种，配合货币转换使用

		var that = $(this);
		var thisParentFirstLi = that.parents("ul").children("li").eq(0);
		var thisParentP = that.parents("p");

		var js_Cache = "<div align=\"center\" class=\"js_openClass\"><img src='/images/loading2.gif' /></div>";
		if(that.attr("id") == "js_openClass")
		{
			 
			thisParentFirstLi.after(js_Cache);
 			that.html("Less Choice <img  src=\"/images/bg/bg-dropup.gif\" alt=\"more choice\" />").attr("id","js_closeClass");
			
//缓存后不调用AJAX
			
			if(that.parents("ul").children("li").length > 1)
			{
				that.parents("ul").children("li").eq(0).removeClass("noBorder");
				that.parents("ul").children("li").show();
				$(".js_openClass").remove();
				return;
			}

//缓存后不调用AJAX

			$.post(
				   "/common/include/ajax.asp",
				   {
					   strtemp:"get-other-flight-price",
					   id:id,
					   queryId:queryId,
					   cstar:cstar,
					   cdest:cdest,
					   blsave:blsave,
					   curr:curr
					   },
					   function(data){
							$(".js_openClass").remove();
							//thisParentFirstLi.after(data);
							thisParentP.before(data);
			});
		}
		else
		{
			that.html("More Choice <img  src=\"/images/bg/bg-dropdown.gif\" alt=\"more choice\" />").attr("id","js_openClass");
			if ($.browser.msie)	//判断IE
			{
				that.parents("ul").children("li").children("li").hide();
				that.parents("ul").children("li").children("li").eq(0).addClass("noBorder");
				if ($.browser.version.substring(0,1) == "8")	//判断IE8
					that.parents("ul").children("li").hide().eq(0).show();
			}
			else	//其他浏览器
				that.parents("ul").children("li").hide().eq(0).show();
				that.parents("ul").children("li").eq(0).addClass("noBorder");
		}
	});
//机票ALL Classes	展开效果

	$("#js_flightsform input[type=button]").click(function(){
		
		if($(this).attr("name") == "simple")
		{
			
			$("#adultNum").val("1");
			$("#childNum").val("0");
			$("#babyNum").val("0");
			
			$("#startCode1Text").val($("#startCode1Text_simple").val());
			$("#destinationCode1Text").val($("#destinationCode1Text_simple").val());
			
			
			$("#takeoffDate1").val($("#takeoffDate1_simple").val());
			$("#takeoffDate2").val($("#takeoffDate2_simple").val());
			
			$("#js_flightsform input[name=triptype][value=1]").attr("checked",true);
		}
		else
		{
			$("#startCode1Text").val($("#startCode1Text_advanced").val());
			$("#destinationCode1Text").val($("#destinationCode1Text_advanced").val());
			$("#destinationCode2Text").val($("#destinationCode2Text_advanced").val());
			
			$("#takeoffDate1").val($("#takeoffDate1_advanced").val());
			$("#takeoffDate2").val($("#takeoffDate2_advanced").val());
			
		}
		//return false;
		$("#js_flightsform").submit();
	});
	
//============货币转换===================
	currHTML = "<ul id=\"Country_Currecy\" style=\"display:none;\">"+
	"<li><div id=\"Tbody_Currencies\">"+
	"<a class=\"tab_USD\" href=\"javascript:;\"><img src=\"/pic/flags/USD.gif\"/></a>"+
	"<a class=\"tab_CNY\" href=\"javascript:;\"><img src=\"/pic/flags/CNY.gif\"/></a>"+
	"<a class=\"tab_EUR\" href=\"javascript:;\"><img src=\"/pic/flags/EUR.gif\"/></a>"+
	"</div></li></ul>";
	
	$("body").append(currHTML);	
	$("input[name=currency]:first").click();
	$("input[name=currency]").click(function(){
		$("a.tab_"+$(this).val()).click();
	});
		   
 var dm =  document.URL.split('/', 3)[2] ,empcur=getCookie('Cht_Currencies',dm),curnum = -1,tcur = $("#Top_Currencies"),calist =  $("#Tbody_Currencies a");	 

	if (typeof empcur == "string")
	{
		  curnum = parseInt(empcur); 
		 
	}
 
 calist.each(function(i){
										 var te = $(this); 
										  te.click(function(){ 
// 														tcur.attr("title",te.attr("title")).html(te.html());  
//														setCookie('Cht_Currencies',i,30,dm);
 																				  }); 
										  if(i == curnum )
										  {
//											 tcur.attr("title",te.attr("title")).html(te.html());  
										  }
										 });
//============货币转换===================
	
//点击日期跳转 重新查询航班
	$("#flightsDate li").click(function(){
		var tmp_a = $("<a id=\"js_tmp_a\"></a>");
		tmp_a.html("...");
		tmp_a.attr("href","/china-flights/goto-postquery.asp?tmp=change-data&d="+$(this).attr("id"));
		$("body").append(tmp_a);
		$("#js_tmp_a").click();
	});

	click_order_button($("input[name=Classes]"));
	click_order_button($("input[name=airlines]"));
	
});

function click_order_button(obj)
{
	$.each(obj,function(){
		if($(this).attr("checked"))
		{
			$(".js_moreLinkButton[name=js_more]").click();
		}
	});
}

function choose_triptype(triptypeNum)
{
	switch (triptypeNum)
	{
	
		case "1" : 
			$("span#js_muti_deatination_city").hide();
			$("span#js_to_city .ulTitle").html("Arrival City:");
			$("span#js_round_trip_date").hide();
			break;
		case "2" :
			$("span#js_muti_deatination_city").hide();
			$("span#js_to_city .ulTitle").html("Arrival City:");
			$("span#js_round_trip_date").show();
			break;
		case "3" :
			$("span#js_muti_deatination_city").show();
			$("span#js_round_trip_date").show();
			$("span#js_to_city .ulTitle").html("First Arrival:");
			break;
	}
	
	$("#flightsDate li").click(function(){
		
	});
}

function js_Choose_Tag_Ajax_Data(obj,c,t,num)
{
	$.post(
		   "/common/include/ajax.asp",
		   {
			   strtemp:"get-hotels-list",
			   city:c,
			   type:t,
			   num:num
			   },
			function(d){
				$(".js_hotel_div").hide();
				obj.children(".js_Choose_Tag").after(d);
				$("#loading").hide();
				}
		   );
}

/*==================机票查询结果页===============*/

var Ajax_City
Ajax_City = BindSelEGetData("startCode1Text","/common/include/ajax.asp",1,"startCode1","strtemp=ajax-get-flights-city&value");
Ajax_City = BindSelEGetData("destinationCode1Text","/common/include/ajax.asp",1,"destinationCode1","strtemp=ajax-get-flights-city&value");
Ajax_City = BindSelEGetData("destinationCode2Text","/common/include/ajax.asp",1,"destinationCode2","strtemp=ajax-get-flights-city&value");
