var MAX_PERSON_COUNT = 7;


function OnLoad(nInitAdultA, nInitChildA, nInitInfantA ) {
	
	// TOPTOP検索：航空券 - 人数選択の初期値
	SetPersonCount('frmFlight', 'nopAdult', 7);
	SetPersonCount('frmFlight', 'nopChild', 7);
	SetPersonCount('frmFlight', 'nopBaby', 0);
	document.forms['frmFlight'].elements['nopAdult'].selectedIndex = String(nInitAdultA);
	document.forms['frmFlight'].elements['nopAdult'].onchange();
	document.forms['frmFlight'].elements['nopChild'].selectedIndex = String(nInitChildA);
	document.forms['frmFlight'].elements['nopChild'].onchange();
	document.forms['frmFlight'].elements['nopBaby'].selectedIndex = String(nInitInfantA);
	document.forms['frmFlight'].elements['nopBaby'].onchange();
	
}

function OnLoadDynamic(nInitAdultD, nInitChildD, nInitInfantD ) {
	
	// TOPTOP検索：ダイナミック - 人数選択の初期値
	SetPersonCount('frmDynamic', 'select0', 7);
	SetPersonCount('frmDynamic', 'select1', 7);
	SetPersonCount('frmDynamic', 'select2', 0);
	document.forms['frmDynamic'].elements['select0'].selectedIndex = String(nInitAdultD);
	document.forms['frmDynamic'].elements['select0'].onchange();
	document.forms['frmDynamic'].elements['select1'].selectedIndex = String(nInitChildD);
	document.forms['frmDynamic'].elements['select1'].onchange();
	document.forms['frmDynamic'].elements['select2'].selectedIndex = String(nInitInfantD);
	document.forms['frmDynamic'].elements['select2'].onchange();

}

// 指定のセレクトオブジェクトのOPTION要素を指定の数に設定する
// パラメータ
//	strFormName(String)	: フォーム名
//	strObjName(String)	: オブジェクト名
//	nCount(Number)			: 要素数
function SetPersonCount(strFormName, strObjName, nCount) {
	var nLen;
	var nCnt;
	var objSelect;

	objSelect = window.document.forms[strFormName].elements[strObjName];
	
	// 指定値までオプションを追加する
	nLen = objSelect.length;
	for (nCnt=nLen; nCnt<=nCount; nCnt++) {
		objSelect.options[nCnt] = new Option(String(nCnt)+"人", String(nCnt));
	}
	
	// 指定値より多い分を削除する
	for (nCnt=nCount+1; nCnt<nLen; nCnt++) {
		objSelect.options[nCount+1] = null;
	}
}


// 大人人数の選択が変更された時のイベントハンドラ
// パラメータ
//	strFormName(String)		: フォーム名称
//	strAdultName(String)	: 大人人数選択用オブジェクト名称
//	strChildName(String)	: 子供人数選択用オブジェクト名称
//	strInfantName(String)	: 幼児人数選択用オブジェクト名称
function OnChange_AdultCount(strFormName, strAdultName, strChildName, strInfantName) {
	var objAdult, objChild, objInfant;
	
	// オブジェクト取得
	objAdult = window.document.forms[strFormName].elements[strAdultName];
	objChild = window.document.forms[strFormName].elements[strChildName];
	objInfant = window.document.forms[strFormName].elements[strInfantName];

	// 大人 < 幼児 の場合警告
	if (objAdult.value < objInfant.value) {
		alert('幼児1人に対して大人は1人以上必要です。');
		objInfant.selectedIndex = objAdult.selectedIndex;
	}
	
	// 子供のプルダウンを 7-大人の選択人数 に変更する
	SetPersonCount(strFormName, strChildName, MAX_PERSON_COUNT-objAdult.value);

	// 幼児のプルダウンを 大人の選択人数 に変更する
	SetPersonCount(strFormName, strInfantName, Number(objAdult.value));
}


// 子供人数の選択が変更された時のイベントハンドラ
// パラメータ
//	strFormName(String)		: フォーム名称
//	strAdultName(String)	: 大人人数選択用オブジェクト名称
//	strChildName(String)	: 子供人数選択用オブジェクト名称
//	strInfantName(String)	: 幼児人数選択用オブジェクト名称
function OnChange_ChildCount(strFormName, strAdultName, strChildName, strInfantName) {
	var objChild;
	
	// オブジェクト取得
	objChild = window.document.forms[strFormName].elements[strChildName];

	// 大人のプルダウンを 7-子供の選択人数 に変更する
	SetPersonCount(strFormName, strAdultName, MAX_PERSON_COUNT-objChild.value);
}


// 幼児人数の選択が変更された時のイベントハンドラ
// パラメータ
//	strFormName(String)		: フォーム名称
//	strAdultName(String)	: 大人人数選択用オブジェクト名称
//	strChildName(String)	: 子供人数選択用オブジェクト名称
//	strInfantName(String)	: 幼児人数選択用オブジェクト名称
function OnChange_InfantCount(strFormName, strAdultName, strChildName, strInfantName) {
	var objAdult, objInfant;
	
	// オブジェクト取得
	objAdult = window.document.forms[strFormName].elements[strAdultName];
	objInfant = window.document.forms[strFormName].elements[strInfantName];

	// 大人のプルダウンより多ければ警告
	if (objAdult.value < objInfant.value) {
		alert('幼児1人に対して大人は1人以上必要です。');
		return;
	}
}

// 旅程選択時の動作
function ShapeChange() {
	// 往復選択時
	document.getElementById('air_RT1').style.display = 'block';
	document.getElementById('air_RT2').style.display = 'block';
	document.getElementById('air_OW1').style.display = 'none' ;
	document.getElementById('air_OW2').style.display = 'none' ;

	if(document.getElementById('tsOW').checked) {
		// 片道選択時
		document.getElementById('air_OW1').style.display = 'block' ;
		document.getElementById('air_OW2').style.display = 'block' ;
		document.getElementById('air_RT1').style.display = 'none' ;
		document.getElementById('air_RT2').style.display = 'none' ;
	}
}

// サイド検索：往復
function tsRdoRTChange(strFormName){
	document.forms[strFormName].tsRT.checked = true;
}

// サイド検索：片道
function tsRdoOWChange(strFormName){
	document.forms[strFormName].tsOW.checked = true;
}

// サイド検索：ONLINE予約
function ssDOl(strFormName){
	document.forms[strFormName].dOl.checked = true;
}

// サイド検索：リクエスト予約
function ssDReq(strFormName){
	document.forms[strFormName].dReq.checked = true;
}

// タブ選択動作（航空券・ダイナミック・ホテル）
function seltab(bpref, hpref, id_max, selected) {
  if (! document.getElementById) return;
  for (i = 0; i <= id_max; i++) {
    if (! document.getElementById(bpref + i)) continue;
    if (i == selected) {
      document.getElementById(bpref + i).style.visibility = "visible";
      document.getElementById(bpref + i).style.position = "";
      document.getElementById(hpref + i).style.visibility = "visible";
      document.getElementById(hpref + i).style.position = "";
    } else {
      document.getElementById(bpref + i).style.visibility = "hidden";
      document.getElementById(bpref + i).style.position = "absolute";
      document.getElementById(hpref + i).style.visibility = "hidden";
      document.getElementById(hpref + i).style.position = "absolute";
    }
  }
}