/**
 * Copyright www.et-china.com 2006
 * Author: eton.liu 
 */

var singleSearchSubmit = "/search/searching.asp";
var returnSearchSubmit = "/search/searching.asp";
var isInternational = false;

var domesticCities = ["CAN","SWA","CTU","KHN","PEK","SIA","CGO","XMN","CSX","KMG","HAK","SYX","KWL","NNG","WUH","SHE","HRB","CGQ","DLC","URC","SHA","PVG"];

var QueryParam = {
	flightTicketType : null,
	depCity : null,
	arrCity : null,
	depDate : null,
	returnDate : null,
	airwaysName : null,
	isInternational : null,
	flyEndDate : null
};

function setQueryParam(form1) {
	if(form1.returnDate.value == ""){
		QueryParam.flightTicketType = "1";		
	}else{
		QueryParam.flightTicketType = "2";		
	}
	QueryParam.depCity = form1.depCity.value;
	QueryParam.arrCity = form1.arrCity.value;
	QueryParam.depDate = form1.depDate.value;
	QueryParam.returnDate = form1.returnDate.value;
	QueryParam.airwaysName = null;
	QueryParam.isInternational = isInternational;	
	
	//alert(QueryParam.depDate + " " + QueryParam.depCity + " " + QueryParam.arrCity + " " + QueryParam.returnDate);
	
	/*
	if(document.form1.returnDate.value == ""){
		QueryParam.flightTicketType = "1";		
	}else{
		QueryParam.flightTicketType = "2";		
	}
	QueryParam.depCity = document.form1.depCity.value;
	QueryParam.arrCity = document.form1.arrCity.value;
	QueryParam.depDate = document.form1.depDate.value;
	QueryParam.returnDate = document.form1.returnDate.value;
	QueryParam.airwaysName = document.form1.airwaysName.value;
	QueryParam.isInternational = isInternational;	
	
	alert(QueryParam.depDate + " " + QueryParam.depCity + " " + QueryParam.arrCity + " " + QueryParam.returnDate);
	*/
}

function submitShow(form1) {	
	if (checkSearchCondition(form1)) {
		if(checkCities(form1)) {
			setQueryParam(form1);
			
			var urlString = encodeURI(JSON.stringify(QueryParam));	
	urlString = urlString.replace(/:/g,"=");
	urlString = urlString.replace(/,/g,"&");
	urlString = urlString.replace(/%7B/g,"");
	urlString = urlString.replace(/%7D/g,"");
	urlString = urlString.replace(/%22/g,"");
	urlString = urlString.replace("depCity1","StartCity01");
	urlString = urlString.replace("arrCity1","EndCity01");
	urlString = urlString.replace("depDate1","StrDate01");
	urlString = urlString.replace("flightTicketType","radio");
			if(document.form1.returnDate.value == "") {
				window.open(singleSearchSubmit + "?" + urlString, null, 'height='+(window.screen.height)+',width='+(window.screen.width)+',top=0,left=0,status=yes,resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=yes');
				//alert("go here...");
				//window.location = singleSearchSubmit + "?" + urlString;				
			} else {
				window.open(returnSearchSubmit + "?" + urlString, null, 'height='+(window.screen.height)+',width='+(window.screen.width)+',top=0,left=0,status=yes,resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=yes');
				//window.location = returnSearchSubmit + "?" + urlString;				
			}		
		}
	}
}
function othersubmitShow(form1) {	
	if (checkSearchCondition(form1)) {
		if(checkCities(form1)) {
			setQueryParam(form1);
			
			var urlString = encodeURI(JSON.stringify(QueryParam));		
			if(document.form1.returnDate.value == "") {
				window.location = "http://booking.et-china.com/engine/com.et_china.flightDisplay/flightDisplay.html" + "?" + urlString;				
			} else {
				window.location = "http://booking.et-china.com/engine/com.et_return.returnFlight/returnFlight.html"+ "?" + urlString;				
			}		
		}
	}
}
function checkCities(form1) {
	//alert(form1.name == "form2");
	if(form1.name == "form2")
		isInternational = true;
		
	if(isInternational==true) {
		var flag = 0;
		var	depCity = form1.depCity.value;
		var arrCity = form1.arrCity.value;
		
		//alert(depCity + " " + arrCity);
		
		if(depCity == "HKG") return true;		
		for(var i=0; i<domesticCities.length; i++) {
			if(domesticCities[i] == depCity) {
				flag++;
			}
			if(domesticCities[i] == arrCity){
				flag++;
			}
		}
		
		if(flag == 1) {
			return true;
		} else {
			alert("国际机票查询中，起飞和抵达城市不能同时为国内城市或同时为国际城市！");
			return false;
		}
	} else {
		return true;
	}
}
