Event.observe(window, "load", system_onload);


function system_onload() {
	var f_U = new ControlGroup( controlDef );
	
	Event.observe("hbtnResearch","click",startNewSearch.bind(this,f_U));

	Event.observe(f_U, "checkpassed", function() {
		window.setTimeout(function() {
			Event.observe(System, "citychange", func);
			Event.observe(System, "checkfailed", func);
			}, 200)
	});
	
	var func = function() {
		var _isInter = $A(f_U.getCityList()).any(function(_city){return _city.isInterCity();});
		if (_isInter) {
			$("hrndRoundTrip").checked = true;
			$("hrndRoundTrip").click();
		}
	}.bind(this);

	$("hrndOneWay").checked = true;
	$("hrndOneWay").click();

	Event.observe(System, "citychange", func);
	
	Event.observe(System, "beforeSearch", function() {
		Event.stopObserving(System, "citychange", func);
	});
	
	f_U.checkAll();

	showAd();
}

function showAd() {
	//$("ifrmTopBanner").src = "/adframe/airchina_banner.htm";
}

function startNewSearch(f_U) {
	Event.fire(System,"beforeSearch");
	f_bD = doSearch.bind(this,f_U);
	Event.observe(f_U,"checkpassed",f_bD);
	Event.observe(f_U,"checkfailed",null);
	f_U.checkAll();
}

function doSearch(f_U) {
	Event.stopObserving(f_U,"checkpassed",f_bD);
	var f_aW = System.constant.SEARCH_URL + f_U.serialize();
	var isInter = $A(f_U.getCityList()).any(function(_city){return _city.isInterCity();});
	if(isInter) {
		f_aW += "&isInter=true&op=2";
	} else {
		f_aW += "&isInter=false&op=1";
	}
	if (location.host.indexOf("local")!=-1) f_aW+=("&host=" + window.location.host);
	window.open(f_aW);
}

function system_onunload() {
}