(function ($) {
	$(document).ready(function () {
		$("#departCityName1").autocomplete(system_js_basepath_support+"/code-table-auto-compelete.dhtml",{
			minChars : 0 ,//最少输入几个字符
			width : 200 ,
			hidden : "departCity1",
			mustMatch: true,
			extraParams : {codeGroup : "code.cn3codeCities"},
			formatItem: function(data, i, n, value) {
				return data.name +" -- "+ data.airportName;
			},
			formatHidden : function(data , value){
				return data.code;				
			}
		}); //出发
		$("#arriveCityName1").autocomplete(system_js_basepath_support+"/code-table-auto-compelete.dhtml",{
			minChars : 0,//最少输入几个字符
			width : 200 ,
			hidden : "arriveCity1",
			mustMatch: true,
			extraParams : {codeGroup : "code.cn3codeCities"},
			formatItem: function(data, i, n, value) {
				return data.name +" -- " + data.airportName;
			},
			formatHidden : function(data , value){
				return data.code;				
			}
		}); //返回
		$("#searchForm").bind("submit", function () {
			return checkSearchForm();
		});
		$("#i18nRadio").click(function(){
		    /*$("#departCityName1").setOptions({
				width : 300 ,
				cacheLength : 0 ,
				extraParams : {codeGroup : "code.cn3codeCities"}
			});*/
			$("#arriveCityName1").setOptions({
				width : 300 ,
				cacheLength : 0 ,
				extraParams : {codeGroup : "code.i18n3codeCities"}
			});
		});
		$("#nationalRadio").click(function(){
			/*$("#departCityName1").setOptions({
				width : 300 ,
				cacheLength : 0 ,
				extraParams : {codeGroup : "code.cn3codeCities"}
			});*/
			$("#arriveCityName1").setOptions({
				width : 200 ,
				cacheLength : 0 ,
				extraParams : {codeGroup : "code.cn3codeCities"}
			});
		});
	});
})(jQuery);


function checkSearchForm(){
	if(jQuery.trim($('#departCityName1').val())==''){
		$('#departCityName1').focus();
		return false;
	}
	else if(jQuery.trim($('#arriveCityName1').val())==''||($('#arriveCityName1').val()==$('#departCityName1').val())){
		$('#arriveCityName1').focus();
		return false;
	}
	else if(jQuery.trim($('#fc_departDT').val())==''){
		$('#fc_departDT').focus();
		return false;
	}
	if($('#typeOfFlight01').attr('checked')){
		if(jQuery.trim($('#fc_arriveDT').val())==''||($('#fc_arriveDT').val()<$('#fc_departDT').val())){
			$('#fc_arriveDT').focus();
			return false;
		}
	}
	return true;
}

function initIndex(city) {
	jQuery("#results").html("<img src='"+FLIGHT_ROOT_PATH+"/images/loading.gif'/> \u6b63\u5728\u88c5\u8f7d\u6570\u636e...");
	jQuery("#results").load(
		CONTEXT_PATH+"/proxy/proxy.dhtml", 
		{url : FLIGHT_ROOT_PATH+"/flight-search!specialFlight.dhtml?fc.specialCity=" + city}, 
		null
	);
}

function setItem(form,item,itemvalues,div,submit) {
	var vals=itemvalues.split('|');
	$("#"+item+'_departTime').val(vals[0]);
	$("#"+item+'_arriveTime').val(vals[1]);
	$("#"+form+'[name=dateTime]').val(vals[1]);
	$("#"+item+'_flightNo').val(vals[2]);
	$("#"+item+'_cabinNo').val(vals[3]);
	$("#"+item+'_fromCity').val(vals[4]);
	$("#"+item+'_toCity').val(vals[5]);
	$("#"+item+'_fullPrice').val(vals[6]/div);
	$("#"+item+'_buildFee').val(vals[7]/div);
	$("#"+item+'_fuelFee').val(vals[8]/div);
	$("#"+item+'_discount').val(vals[9]);
	$("#"+item+'_planeType').val(vals[10]);
	$("#"+item+'_basePrice').val(vals[11]);
	$("#"+item+'_cabinInfoId').val(vals[12]);
	$("#"+item+'_totalPrice').val((vals[6]*1+vals[7]*1+vals[8]*1)/div);
	$("#"+item+'_supplierId').val(vals[13]);
	$("#"+item+'_commision').val(vals[14]);
	$("#"+form+'[name=sign]').val(vals[15]?vals[15]:2);
	if(submit)
		$("#"+form).submit();
}
function nTabsIndex(thisObj, Num) {
	if (thisObj.className == "active") {
		return;
	}
	var tabObj = thisObj.parentNode;
	var liList = tabObj.getElementsByTagName("li");
	for (i = 0; i < liList.length; i++) {
		if (i == Num) 
			thisObj.className = "okbg";
		else 
			liList[i].className = "nobg";
	}
}

function initFlightSearch(type, index) {
	if (type == 0) {
		$("#thirdCity" + index).hide();
		$("#backTime" + index).hide();
		$("#backCity" + index).html("\u76ee\u7684\u57ce\u5e02\uff1a");
	} else {
		if (type == 1) {
			$("#thirdCity" + index).hide();
			$("#backTime" + index).show();
			$("#backCity" + index).html("\u8fd4\u56de\u57ce\u5e02\uff1a");
			$("#backTimeName" + index).html("\u8fd4\u56de\u65e5\u671f\uff1a");
		} else {
			$("#thirdCity" + index).show();
			$("#backTime" + index).show();
			$("#backCity" + index).html("\u4e2d\u8f6c\u57ce\u5e02\uff1a");
			$("#backTimeName" + index).html("\u4e2d\u8f6c\u65e5\u671f\uff1a");
		}
	}
}
