// YUI Autocomplete
YAHOO.example.ACJson = new function() {
	this.oACDS = new YAHOO.widget.DS_XHR("/response/json.airport_list.asp", ["result", "query", "code", "idx"]);
	this.oACDS.queryMatchContains = true;
	this.oACDS.scriptQueryAppend = "method=from";

	this.xACDS = new YAHOO.widget.DS_XHR("/response/json.airport_list.asp", ["result", "query", "code", "idx"]);
	this.xACDS.queryMatchContains = true;
	this.xACDS.scriptQueryAppend = "method=to";

	this.fromComplete = new YAHOO.widget.AutoComplete('frombox', 'fromComplete', this.oACDS);
	this.fromComplete.useIFrame = true;
	this.fromComplete.minQueryLength = 3;
	this.fromComplete.queryDelay = 0;
	this.fromComplete.formatResult = completeResult;
	this.fromComplete.maxResultsDisplayed = 256;
	this.fromComplete.itemSelectEvent.subscribe(function(oSelf, elItem, oData) {
		$("_frombox").value = elItem[2][1];
		reserveButton(chkForm());
	});

	this.toComplete = new YAHOO.widget.AutoComplete('tobox', 'toComplete', this.xACDS);
	this.toComplete.useIFrame = true;
	this.toComplete.minQueryLength = 3;
	this.toComplete.queryDelay = 0;
	this.toComplete.formatResult = completeResult;
	this.toComplete.maxResultsDisplayed = 256;
	this.toComplete.itemSelectEvent.subscribe(function(oSelf, elItem, oData) {
		$("_tobox").value = elItem[2][1];
		reserveButton(chkForm());
		_processDeal(elItem[2][0], elItem[2][1]);
	});

	function completeResult(oResultItem, sQuery) {
		var oReg = new RegExp(sQuery, "i");
		return "<span class='right'>" + oResultItem[1].replace(oReg, "<strong>" + sQuery.toUpperCase() + "</strong>") + "</span> " + oResultItem[0].replace(oReg, "<strong>" + sQuery + "</strong>");
	}
};

// Flight Type (Oneway, Round trip)
$("reserved").select("li.method input.radio").invoke("observe", "click", function(s) {
	if (this.value == "1") {
		$("blockOneway").hide();
	} else {
		$("blockOneway").show();
	}
});


function checkCar(obj) {
	if (obj.checked != true) {
		var curType;
		$("reserved").getInputs("radio", "singlemenu").each(function(s){
			if (s.checked == true) curType = s.value;
		});

		switch (curType) {
			case "air_hotel_car":
				curType = "air_hotel";
				break;
			case "air_car":
				curType = "air";
				break;
			default:
				curType = "air";
				break;
		}

		changePackage(curType);
	}
}