
var domH_depApoFlag = '';

function init_dom_ticket() {

	// 初期化は1度のみ
//	if(typeof dom_ticket == "object") return false;

	dom_ticket = new formControll(document.segConditionForm);

	dom_ticket.init = function() {
		
		/***************************************************************************
		// 各プルダウンの読み込み
		***************************************************************************/
		
		var airportList = domAirport_list.slice(1);
		this.formView.createPulldown("segConditionForm.selectedDepApo", airportList);						// 出発空港
		this.formView.createPulldown("segConditionForm.selectedArrApo", airportList);						// 到着空港
		
		this.formView.createPulldown("segConditionForm.selectedEmbMonth", getSliceMonth(6));				// 搭乗月
		this.formView.createPulldown("segConditionForm.selectedEmbDay", day_list.slice(0, getDaylength()));	// 搭乗日
		
		//time_list.unshift({value:"-", text:"時刻指定なし"});
		this.formView.createPulldown("segConditionForm.selectedDepTime", time_list);						// 出発時刻
	
			
		/***************************************************************************
		// 各エレメントの初期値のセット
		***************************************************************************/
		
		// いつもの情報設定：空港
		var _depApo1;
		var _arrApo1;
		if (dom_depApo1 == "" && dom_arrApo1 == "") {
            // 第２登録しかない場合は第２登録を表示
            if (dom_depApo2 == "" && dom_arrApo2 == "") {
    			_depApo1 = "HND";
    			_arrApo1 = "HND";
    			domH_depApoFlag = '0';
            } else {
    			_depApo1 = (dom_depApo2 == "") ? "HND" : dom_depApo2;
				_arrApo1 = (dom_arrApo2 == "") ? "HND" : dom_arrApo2;
    			domH_depApoFlag = '1';
            }
		} else {
			_depApo1 = (dom_depApo1 == "") ? "HND" : dom_depApo1;
			_arrApo1 = (dom_arrApo1 == "") ? "HND" : dom_arrApo1;
			domH_depApoFlag = '1';
		}

		//var _depApo1 = (dom_depApo1 == "") ? "HND" : dom_depApo1;
		//var _arrApo1 = (dom_arrApo1 == "") ? "HND" : dom_arrApo1;
		
		this.formView.setPulldown("segConditionForm.selectedDepApo", _depApo1); 							// 出発空港
		this.formView.setPulldown("segConditionForm.selectedArrApo", _arrApo1);								// 到着空港
		
		
		// いつもの情報設定：座席種類
		if(dom_seatKind != "") this.formView.setRadioChecked("segConditionForm.seatKind", dom_seatKind); 	// 座席種類
		
		var monthElem = this.form["segConditionForm.selectedEmbMonth"];
		var dayElem = this.form["segConditionForm.selectedEmbDay"];
		
		
		// いつもの情報設定：搭乗日時（月がその範囲にない場合は？）
		var date = getOffsetDate(0);
		var _embMonth = (embMonth == "") ? date.getMonth(): embMonth;
		var _embDay = (embDay == "") ? date.getDate(): embDay;
		
		this.formView.setPulldown("segConditionForm.selectedEmbMonth", _embMonth*1); 						// 搭乗日時
		this.formView.setPulldown("segConditionForm.selectedEmbDay", _embDay*1);		
		this.resetDay(monthElem);
		//this.formView.addWeekPulldown("segConditionForm.selectedEmbDay");
			
		this.formView.setPulldown("segConditionForm.selectedDepTime", "-");           						// 出発時刻

		//this.formView.setRadioChecked("segConditionForm.ttwCalFlg", "0"); 									// 検索方法
		
		/***************************************************************************
		// 各エレメントのイベントのセット
		***************************************************************************/
		
		
		// イベントの追加（一度追加したら追加しない）
		if(dom_ticket_addEvent_flg == false){
			// 出発日：月変更 => その月の日数を反映
			//this.addEvent("segConditionForm.selectedEmbMonth", "change", this.delegate(this, this.monthListenerAddWeek));
			this.addEvent("segConditionForm.selectedEmbMonth", "change", this.delegate(this, this.monthListener));
			// フォーム送信イベント
			//this.addEvent(document.getElementById("BtnDomTkTk"), "click", this.delegate(this, this.submitForm));

			dom_ticket_addEvent_flg = true;
		}
		
		
		// フォーム送信の前処理
		//this.submitBefore = function() {
			
			//switchEngine();
		//};		
	}
	
	dom_ticket.init();
	
	
	// 会員の場合はいつものボタンをセット
	if(_isMember()) createItsumonoBtn();

	onloadHistoryCookie();

}

// 二度フラグ
ticSubmited = false;


// フォーム送信
function TicOnSubmit() {
	
    with (document.segConditionForm) {
        elements[4].options[elements[4].selectedIndex].value = Number(elements[4].value);
        elements[5].options[elements[5].selectedIndex].value = Number(elements[5].value);
    }

    if (ticSubmited) return false;
    ticSubmited = true;
    //switchEngine();
    return true;
}


// いつものボタンのセット
function createItsumonoBtn() {
	
	var depFlg1 = (dom_depApo1 != "" || dom_arrApo1 != "") ? true: false;
	var depFlg2 = (dom_depApo2 != "" || dom_arrApo2 != "") ? true: false;
	var btnItsumono = "";

	if (_isOftenMember()) {
	
		//上級会員
	
		// 登録がある場合はボタンを表示
		if(depFlg1) {
			btnItsumono += '<a href="javascript:setItsumono(document.segConditionForm[ \'segConditionForm.selectedDepApo\'], document.segConditionForm[\'segConditionForm.selectedArrApo\'], 1);">'
			btnItsumono += '<img  name="buttonItsumono_1" src="/eng/toppage/image/module/sp/btn-day1_elite.gif" width="87" height="18" border="0" alt="Saved Route 1" /></a>';
		}
		if(depFlg2) {
			btnItsumono += '<a href="javascript:setItsumono(document.segConditionForm[ \'segConditionForm.selectedDepApo\'], document.segConditionForm[\'segConditionForm.selectedArrApo\'], 2);">'
			btnItsumono += '<img  name="buttonItsumono_2" src="/eng/toppage/image/module/sp/btn-day2_elite.gif" width="87" height="18" border="0" alt="Saved Route 2" /></a>';
		}
	
		// 逆区間ボタンを表示（空港登録がない場合は逆区間ボタンのみ）
		var html = '<a href="javascript:reverseAirport(document.segConditionForm[\'segConditionForm.selectedDepApo\'], document.segConditionForm[\'segConditionForm.selectedArrApo\']);"><img src="/eng/toppage/image/module/sp/btn-return.gif" width="174" height="23" border="0" alt="Switch Departure and Destination" /></a><br>' + btnItsumono;
		document.getElementById("memberOnlyMenu").innerHTML = html;
	} else {
	
		//一般会員
	
		// 登録がある場合はボタンを表示
		if(depFlg1) {
			btnItsumono += '<a href="javascript:setItsumono(document.segConditionForm[ \'segConditionForm.selectedDepApo\'], document.segConditionForm[\'segConditionForm.selectedArrApo\'], 1);">'
			btnItsumono += '<img  name="buttonItsumono_1" src="/eng/toppage/image/module/basic/btn-day1.gif" width="87" height="18" border="0" alt="Saved Route 1" /></a>';
		}
		if(depFlg2) {
			btnItsumono += '<a href="javascript:setItsumono(document.segConditionForm[ \'segConditionForm.selectedDepApo\'], document.segConditionForm[\'segConditionForm.selectedArrApo\'], 2);">'
			btnItsumono += '<img  name="buttonItsumono_2" src="/eng/toppage/image/module/basic/btn-day2.gif" width="87" height="18" border="0" alt="Saved Route 2" /></a>';
		}
	
		// 逆区間ボタンを表示（空港登録がない場合は逆区間ボタンのみ）
		var html = '<a href="javascript:reverseAirport(document.segConditionForm[\'segConditionForm.selectedDepApo\'], document.segConditionForm[\'segConditionForm.selectedArrApo\']);"><img src="/eng/toppage/image/module/basic/btn-return.gif" width="174" height="23" border="0" alt="Switch Departure and Destination" /></a><br>' + btnItsumono;
		document.getElementById("memberOnlyMenu").innerHTML = html;
	}
}



// いつもの情報空港のセット
function setItsumono(targetDep, targetArr, no) {

	var _dep = "";
	var _arr = "";
	
	if (no == 1) {
		_dep = (dom_depApo1 == "") ? "HND" : dom_depApo1;
		_arr = (dom_arrApo1 == "") ? "HND" : dom_arrApo1;
		
	} else if(no == 2) {
		_dep = (dom_depApo2 == "") ? "HND" : dom_depApo2;
		_arr = (dom_arrApo2 == "") ? "HND" : dom_arrApo2;
	}
		
    dom_ticket.formView.setPulldown(targetDep, _dep);
    dom_ticket.formView.setPulldown(targetArr, _arr);
}


// 逆区間ボタンのイベント（空港を入れ替える）
function reverseAirport(elem1, elem2) {
	
	dom_ticket.formView.reversePulldown(elem1, elem2);
}
