//search.js ver5.0 Copyright (c)2008 H.I.S. Co.,Ltd. Web Site Planning Div.(TOKYO) All Rights Reserved

// ---------- 国オプション作成 ---------- //
function setCountry(arg, id){
	//フォームオブジェクトへのショートカット作成
	var d = document.forms[id];
	d.location.value = "";
	d.country.length = 1;
	d.city.length = 1;
	
	//選択なしはReturn
	if (arg==""){
		return;
	}
	
	var selectedArea = new Array();
	
	//Areaを設定
	selectedArea = eval('area_' + arg);
	
	//Areaのcountryオプションを設定
	d.country.length = selectedArea.length + 1;
	for (var i = 0; i < selectedArea.length; i++){
		d.country.options[i + 1]=new Option(selectedArea[i].name, selectedArea[i].code);
	}
}

// ---------- 都市オプション作成 ---------- //
function setCity(argu, id){
	var d = document.forms[id];
	d.location.value = "";
	
	//選択なしはReturn
	if (argu==""){
		return;
	}
	
	var selectedCity = new Array();
	
	selectedCity = eval(argu);
	
	d.city.length = selectedCity.length + 1;
	for (var i = 0; i < selectedCity.length; i++){
		if(selectedCity[i].type == 'city'){
			var queryLoca = 'voyage_list.aspx?' + selectedCity[i].type;
		}else{
			var queryLoca = 'country.aspx?' + selectedCity[i].type;
		}
		d.city.options[i + 1]=new Option(selectedCity[i].name, (queryLoca + '\=' + selectedCity[i].code));
	}
}

// ---------- Location確定 ---------- //
function setLocation(argu, id){
	var d = document.forms[id];
	
	d.location.value = argu;
	
	//国一覧選択チェック
	if(d.year.selectedIndex != 0){
		if(checkcountry()){
			return;
		}
	}
}

// ---------- 国一覧選択チェック ---------- //
function checkcountry(id){
	var d = document.forms[id];
	
	if(d.location.value.indexOf('country') != -1){
		alert("都市一覧を選択した場合、日付・航空会社は選択できません。\nこのまま検索ボタンを押してください。");
		d.carrier.selectedIndex = 0;
		d.year.selectedIndex = 0;
		d.month.length = 1;
		d.month.selectedIndex = 0;
		d.day.length = 1;
		d.day.selectedIndex = 0;
		d.date.value = "";
		var cc = 1;
	}
	
	return cc;
}

// ---------- month設定 ---------- //
function setMonth(argu, id){
	var d = document.forms[id];
	
	//国一覧選択チェック
	if(checkcountry(id)){
		return;
	}
	
	d.day.length = 1;
	d.date.value = "";
	d.month.length = 1;

	lmDate=new Date();
	lmY=lmDate.getFullYear();
	lmM=lmDate.getMonth() + 1;
	lmD=lmDate.getDate();
	//alert(lmY + '/' + lmM + '/' + lmD);
	
	//2008年設定
	if(argu == '2008'){
  d.month.length = 1;
  d.month.selectedIndex = 0;
  d.day.length = 1;
  d.day.selectedIndex = 0;
  d.date.value = "";
		for(i = 0, m = lmM; m < 13; i++, m++){
			if(lmM == m){
				d.month.options[i + 1]=new Option(m, m, true, true);
			}else{
				d.month.options[i + 1]=new Option(m, m);
			}
		}
	
	//日付設定
		setdate(lmM);
		
	}
	else{
	//2009年設定
	d.month.length = 1;
	d.month.selectedIndex = 0;
	d.day.length = 1;
	d.day.selectedIndex = 0;
	d.date.value = "";;
		//2009年の露出してる最後の月
		lastmonth = 12;
		for(i = 0; i < lastmonth; i++){
				d.month.options[i + 1]=new Option(i + 1, i + 1);
		}
	}
}

// ---------- 日付設定 ---------- //
function setdate(argu, id){
	
	var d = document.forms[id];
	d.day.length = 1;
	d.date.value = "";
	
	//月別日数
	var monthday = new Array("31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31");
	
	lmDate=new Date();
	lmY=lmDate.getFullYear();
	lmM=lmDate.getMonth()+1;
	lmD=lmDate.getDate();
	
	for(i = 0; i < monthday[argu -1]; i++){
		//桁数調整
		if(i < 3){
			thisday = '0' + (i + 1);
		}else{
			thisday = i + 1;
		}

		if(lmD == i && lmM == argu){
			d.day.options[i + 1]=new Option(i + 1, thisday, true, true);
			if(d.month.value < 3){
				monthvalue = '0' + d.month.value;
			}else{
				monthvalue = d.month.value;
			}
			//一応日付確定
			d.date.value = 'leave_dt=' + d.year.value + '/' + monthvalue + '/' + d.day.value;
		}else{
			d.day.options[i + 1]=new Option(i + 1, thisday);
		}
	}
}

// ---------- 日付確定 ---------- //
function setdday(argu, id){
	var d = document.forms[id];
	if(d.month.value < 9){
		monthvalue = '0' + d.month.value;
	}else{
		monthvalue = d.month.value;
	}
	
	d.date.value = 'leave_dt=' + d.year.value + '' + monthvalue + '' + d.day.value;
}

// ---------- クエリ作成 ---------- //
function createQuery(id){
	var d = document.forms[id];
	
	//チェック
	if(d.dep.value == ""){
		alert("出発地が選択されていません！");
		return;
	}
	if(d.location.value == ""){
		alert("目的地が選択されていません！");
		return;
	}else{
		var dep = [];
		dep = d.dep.value.split('/');
		if(d.date.value){
			var q = 'http://e.his-j.com/shop/air/' + d.location.value + '&' + 'portal=' + dep[0] + '&jarea=' + dep[1] + '&' + d.date.value + '&seat_class=C';
			
			//キャリア指定チェック
			if(addCrrier(d.carrier.value)){
				q += addCrrier(d.carrier.value);
			}
		}else if(d.year.value !=0 && d.month.value == 0 && d.day.value == 0){
			alert("出発の月が選択されていません！");
			return;
		}else if(d.year.value !=0 && d.month.value != 0 && d.day.value == 0){
			alert("出発の日付が選択されていません！");
			return;
		}else{
			//都市一覧選択チェック
			if(d.location.value.indexOf('country') != -1){
				var q = 'http://e.his-j.com/shop/air/' + d.location.value + '&' + 'portal=' + dep[0] + '&jarea=' + dep[1];
			}else{
				var q = 'http://e.his-j.com/shop/air/' + d.location.value + '&seat_class=C' + '&' + 'portal=' + dep[0] + '&jarea=' + dep[1];
				//キャリア指定チェック
				if(addCrrier(d.carrier.value)){
					q += addCrrier(d.carrier.value);
				}
			}
		}
		
		//フォーム初期化
		d.area.selectedIndex = 0;
		d.country.length = 1;
		d.city.length = 1;
		d.month.selectedIndex = 0;
		d.day.length = 1;
		
		//ページ遷移
		//window.location = q;
		
		//リセット
		createReset(id)
		
		//別窓開く
		window.open(q);
	}
}

//キャリア指定チェック
function addCrrier(carrier){
	if(carrier != 0){
		return '&carrier_flg=01&carrier=' + carrier;
	}else{
		return false;
	}
}

// ---------- リセット ---------- //
function createReset(id){
	var d = document.forms[id];
	d.day.length = 1;
	d.date.value = "";
	d.month.length = 1;
	d.month.selectedIndex = "";
}

// ---------- フォーム初期化 ---------- //
//function cqreset(){
//	var d = document.cq;
//	d.reset();
//}

// ---------- 読み込み時に実行 ---------- //
//window.onload = function(){
//	cqreset();
//}

