﻿/**
 * knt.co.jp - image script
 *
 * Copyright (c) All rights reserved by KNT Co., Ltd.
 *
 */

/** submit **/
//コメントアウト tsukamoto
/*
function searchSubmit(form_id) {
	var d = document[form_id];
	d.submit();
}
*/
/** calendar style **/

function setCalendarStyle() {
	var osname = navigator.userAgent.toUpperCase();
		
	if (osname.indexOf("WIN") >= 0) {
		document.getElementById("facilities-charge-fontfix").style.fontSize= "12px";
	} else {
		document.getElementById("facilities-charge-fontfix").style.fontSize= "10px";
	}
}


/** document fold */

function docSwitch(fold_id, expand_id) {
	document.getElementById(fold_id).style.display = "none";
	document.getElementById(expand_id).style.display = "block";
	
	//絞込み開く  2007/05/28 Y
	if (fold_id == "f-index") {
		document.cookie = "planSearch=1;";
	} else {
		document.cookie = "planSearch=2;";
	}
}

/** プランリストページ読み込み時 2007/05/28 Y */

function docSwitch2() {
	var kword = "planSearch";
	//キーワード検索
	if(typeof(kword) == "undefined") return;
	kword = kword + "=";
	kdata = "";
	scookie = document.cookie + ";";　　　　// クッキー情報を読み込む
	start = scookie.indexOf(kword);   　	// キーワードを検索
	// キーワードと一致するものあり
	if (start != -1){ 
		end = scookie.indexOf(";", start);    // 情報の末尾位置を検索
		kdata = unescape(scookie.substring(start + kword.length, end));  // データ取り出し
	}
	
	//Null以外の場合
	if (kdata != null){
		//開く
		if (kdata == "1") {
			document.getElementById("f-index").style.display = "none";
			document.getElementById("e-index").style.display = "block";
		} else if (kdata == "2") {
			document.getElementById("e-index").style.display = "none";
			document.getElementById("f-index").style.display = "block";
		}
	}	
}


/** search **/

function setProperties() {
	// Form ID
	if (document["srchArea"]) form_search = document["srchArea"]; // 条件を指定して探す
}

// 現在のステータス
search_more = "close";

//コメントアウト 2007 07 tsukamoto
/*
function searchMoreSwitch() {
	if (document.getElementById("ps-children").style.display != "block") {
		switch (search_more) {
		case "open":
			document.getElementById("search-more").style.display = "none";
			document.getElementById("search-more-link").className = "search-more-link-active";
			search_more = "close";
			break;
			
		case "close":
			document.getElementById("search-more").style.display = "block";
			document.getElementById("search-more-link").className = "search-more-link-disable";
			search_more = "open";
			break;
		}
	}
}
*/
// こどもA、Bの人数

//chld_a_org = 0;
//chld_b_org = 0;
//コメントアウト 2007 07 tsukamoto
function showChildren() {
	// Form ID
	if (document["srchArea"]) form_search = document["srchArea"];

	//子供人数　2007/06/08 Y
	//コメントアウト 2007 07 tsukamoto
	//chld_a_org = form_search["psChildrenA"].value;
	//chld_b_org = form_search["psChildrenB"].value;

	closeCalendar();

	// 部屋タイプの表示、非表示でボックスの位置を変更
	if (document["srchArea"]) {
		switch (search_more) {
		case "open":
			//コメントアウト 2007 07 tsukamoto
			//document.getElementById("ps-children-body").style.top = "-162px";
			break;
		case "close":
			//コメントアウト 2007 07 tsukamoto
			//document.getElementById("ps-children-body").style.top = "-112px";
			break;
		}
	}

	if (document["srchArea"]) {
		document.getElementById("searchCity").style.visibility = "hidden";
		document.getElementById("searchArea1").style.visibility = "hidden";
//		document.getElementById("searchArea2").style.visibility = "hidden";
	}

	//コメントアウト 2007 07 tsukamoto
	//document.getElementById("ps-children").style.display = "block";
	
	//コメントアウト 2007 07 tsukamoto
	//chld_a_org = form_search["psChildrenA"].value;
	//chld_b_org = form_search["psChildrenB"].value;
}

function inputChildren() {
	if (document["srchArea"]) {
		document.getElementById("searchCity").style.visibility = "visible";
		document.getElementById("searchArea1").style.visibility = "visible";
//		document.getElementById("searchArea2").style.visibility = "visible";
	}

	//コメントアウト 2007 07 tsukamoto
	//document.getElementById("ps-children").style.display = "none";
	
	//コメントアウト 2007 07 tsukamoto
	//var chld_a = form_search["psChildrenA"].value;
	//var chld_b = form_search["psChildrenB"].value;

	//子供人数　2007/05/31 N
	
	//コメントアウト 2007 07 tsukamoto
	//chld_a_org = form_search["psChildrenA"].value;
	//chld_b_org = form_search["psChildrenB"].value;
	
	var chldNum = document.getElementById("search-person-children");
	chldNum.innerHTML = Number(chld_a) + Number(chld_b) + "名";
}

function closeChildren() {
	if (document["srchArea"]) {
		//コメントアウト 2007 07 tsukamoto
		//document.getElementById("ps-children").style.display = "none";
		document.getElementById("searchCity").style.visibility = "visible";
		document.getElementById("searchArea1").style.visibility = "visible";
	}
	//コメントアウト 2007 07 tsukamoto
	//form_search["psChildrenA"].selectedIndex = chld_a_org;
	//form_search["psChildrenB"].selectedIndex = chld_b_org;
}

/** calendar search **/

// SafariにおけるsetMonth関数バグ対応
Date.prototype.setMonth = function (month, date) {
	return this.setFullYear (
		this.getFullYear() + Math.floor(month / 12),
		((month %= 12) < 0) ? month + 12 : month,
		(arguments.length >= 2) ? date : this.getDate()
	);
}

// Date関数の拡張
function sDate() {
	var now = new Date();
	// デバック用：日付指定
	// now.setFullYear(2007); now.setMonth(5); now.setDate(20);
	return now;
}

now = new sDate();
absnow = now;

add_month = 10;  // 10ヵ月先まで（当月含まず）

cal_index = 0;

btn_first_click = true;
btn_last_click = false;
btn_next_click = false;

//相対日　 2007/05/28 Y
soutaibi = 0; 

function showCalendar(cal, soutai) {
	// Form ID
	if (document["srchArea"]) form_search = document["srchArea"];
	

	closeChildren();

	if (cal == 0) {
		//予約可能相対日　2007/05/28 Y
		soutaibi = soutai;
	
		// セレクトボックスの値でカレンダーを初期化
		initCalendar();
	
		// カレンダーの送りを設定　2007/05/29 Y
		var search_month = form_search["searchMonth"].options;
		var search_day = form_search["searchDay"].options;
		var this_date = search_month[search_month.selectedIndex].value.split("-");
		var this_day = search_day[search_day.selectedIndex].value;
		setFormCalendar(this_date[0], this_date[1], this_day);
		
	
		checkButtons();
		
		if (!btn_first_click && !btn_last_click) {
			writeCalendar(0, "", true);
		}
		
		writeCalendar(0, "search-calendar-1", false);
		writeCalendar(1, "search-calendar-2", false);
		btn_last_click = false;
		btn_next_click = false;
		btn_first_click = false;
		
	} else if (cal == 1) {
		checkButtons();
		if (btn_last_click && !btn_next_click) {
			writeCalendar(1, "", true);
		}
		writeCalendar(0, "search-calendar-1", false);
		writeCalendar(1, "search-calendar-2", false);
		btn_last_click = false;
		btn_next_click = true;
		
	} else if (cal == -1) {
		if (!btn_last_click && btn_next_click || !btn_last_click && !btn_next_click) {
			writeCalendar(-1, "", true);
		}
		writeCalendar(0, "search-calendar-2");
		writeCalendar(-1, "search-calendar-1");
		btn_last_click = true;
		btn_next_click = false;
		checkButtons();
	}
}

function closeCalendar() {
	document.getElementById("ps-cal").style.display = "none";
	document.getElementById("searchMonth").style.visibility = "visible";
	document.getElementById("searchDay").style.visibility = "visible";
	//コメントアウト 2007 07 tsukamoto
	//document.getElementById("searchStay").style.visibility = "visible";
}

function setFormCalendar(year, month, day) {
	var flg = false;
	

	// セレクトボックス - 年月
	var search_month = form_search["searchMonth"].options;
	
	// セレクトボックス - 日
	var search_day = document.getElementById("searchDay");
	

	// 総数
	//len = search_month.length;
		
	//1桁の場合、前に「0」を付加　2007/05/29 Y
	var varYear = year+"";
	var varMonth = month+"";
	var MojiSuu = 0;
	if(varMonth != null) {
		var MojiSuu = varMonth.length;
		if (MojiSuu < 2){
			varMonth = "0"+varMonth;
		}
	}
	
	// value値を取得
	indexNumber = search_month.selectedIndex;
	var s_month = new Array();
	for (i = 0; i < search_month.length; i++) {
		s_month[i] = search_month[i].value;
		if (s_month[i] == varYear + '-' + varMonth) {
			indexNumber = i;
			flg = true;
		}
	}
	

	// 年月を指定　2007/05/28 Y
	if(flg == true){	
		/*
		search_month.selectedIndex = indexNumber;
		
		
		
		
		// 日value値を取得＆指定
		
		//indexNumber = search_day.selectedIndex;
		
		var s_day = new Array();
		for (i = 0; i < search_day.length; i++) {
			s_day[i] = search_day[i].value;
			if (s_day[i] == day) {
				indexNumber = i;
			}
		}
		search_day.selectedIndex = indexNumber;
		*/
	
		search_month.selectedIndex = indexNumber;
		
		var dayString = day + "";
		if (dayString.length == 1)
		{
			search_day.value = "0" + day;
		}
		else
		{
			search_day.value = day;
		}
		
		// カレンダーの送りを設定
		var now = new sDate();
		cal_index = (month-1) + (year - now.getFullYear()) * 12 - now.getMonth();

	} else {
		//初期読み込みで、日付指定なし
		// カレンダーの送りを設定
		var now = new sDate();
		cal_index = now.getMonth() + (now.getFullYear() - now.getFullYear()) * 12 - now.getMonth();
	}
	
	closeCalendar();
}

function initCalendar() {
	var search_month = form_search["searchMonth"].options;
	var search_day = form_search["searchDay"].options;
	var this_date = search_month[search_month.selectedIndex].value.split("-");
	var this_day = search_day[search_day.selectedIndex].value;
	
	/*
	if (this_date[0] == "none" || this_day == "none") {
		now = absnow = sDate();
	} else {
		now = absnow = new Date(this_date[0], this_date[1] - 1, this_day);
	}
	*/
	
	//予約開始可能日より後の日付か確認　2007/05/29 Y
	nowDate2 = new Date();
	nowDate2.setTime(nowDate2.getTime() + soutaibi*24*3600*1000);
	var yyymmdd1 = nowDate2.getYear();
	if ((nowDate2.getMonth()+1) < 10){
		yyymmdd1 += "0" + (nowDate2.getMonth()+1);
	} else {
		yyymmdd1 += (nowDate2.getMonth()+1)+"";
	}
	if (nowDate2.getDate() < 10){
		yyymmdd1 += "0" + nowDate2.getDate();
	} else {
		yyymmdd1 += nowDate2.getDate()+"";
	}
	var yyymmdd2 = this_date[0]+this_date[1]+this_day;
	
	
	//日付が未設定の場合、現在の日付+相対日を設定　2007/05/29 Y
	if ((this_date == "" || this_day == "") || (yyymmdd1 > yyymmdd2)){
		now = new Date();
		now.setTime(now.getTime() + soutaibi*24*3600*1000);
		absnow = now;
	} else {
		now = new Date(this_date[0], this_date[1] - 1, this_day);
		absnow = now;
	}

	if (document["srchArea"]) {
		document.getElementById("ps-cal-body").style.top = "-145px";
	}
}


function checkButtons() {	
	var btn_last = document.getElementById("cal-link-last");
	var btn_next = document.getElementById("cal-link-next");

	//現在の日付の場合
	if (cal_index <= 0) {
		btn_last.style.display = "none";
		btn_next.style.display = "block";
	
	//10ヶ月後の日付の場合
	} else if (cal_index >= add_month - 1) {
		btn_last.style.display = "block";
		btn_next.style.display = "none";
	
	//間の日付の場合
	} else {
		btn_last.style.display = "block";
		btn_next.style.display = "block";
	}
}

function calendarNextMonth() {
	cal_index++;
	showCalendar(1, '');　// 2007/05/28 Y
}

function calendarLastMonth() {
	cal_index--;
	showCalendar(-1, ''); // 2007/05/28 Y
}

function writeCalendar(month, target, skip) {

	// 現在年月日取得
	thisdate = new sDate();
	//相対日設定 2007/05/28 Y
	thisdate.setTime(thisdate.getTime() + soutaibi*24*3600*1000);
	thisday = thisdate.getDate();
	thismonth = thisdate.getMonth();
	thisyear = thisdate.getYear();
	if (thisyear < 2000) thisyear += 1900;

	//相対日設定（引く） 2007/05/28 Y
	thisdate.setTime(thisdate.getTime() - soutaibi*24*3600*1000);	
	maxday = thisdate;
	maxday.setMonth(maxday.getMonth() + add_month);
	maxyyyymmdd = maxday.getFullYear() * 10000 + maxday.getMonth() * 100 + thisdate.getDate() + 1;
	
	// オブジェクト年月日取得
	nowdate  = now.getDate();
	nowmonth = now.getMonth();
	nowyear  = now.getYear();

	// 月移動処理
	if (month == 12) {
		nowyear++;
	} else if (month == -12) {
		nowyear--;
	} else if (nowmonth == 11 && month > 0) {
		nowmonth = -1 + month;
		nowyear++;
	} else if (nowmonth == 0 && month < 0) {
		nowmonth = 12 + month;
		nowyear--;
	} else {
		nowmonth += month;
	}

	// 2000年問題対応
	if (nowyear < 1900) nowyear = 1900 + nowyear;

	// 現在月を確定
	now = new Date(nowyear, nowmonth, 1);
	
	// 表示スキップ - ２ヵ月表示用
	if (skip) return false;

	// YYYYMMDD作成
	nowyyyymm = nowyear * 100 + nowmonth;
	nowyyyymmdd = nowyear * 10000 + nowmonth * 100 + nowdate;
	nowtitlemonth = nowmonth + 1;
	//if (nowtitlemonth < 10) nowtitlemonth = '0' + nowtitlemonth;
	nowtitleyyyymm = nowyear + '年' + nowtitlemonth + '月';

	// 週設定
	week = new Array('日','月','火','水','木','金','土');

	// カレンダー構築用基準日の取得
	fstday   = now;  // 今月の1日
	startday = fstday - ( fstday.getDay() * 1000 * 60 * 60 * 24 );  // 最初の日曜日
	startday = new Date(startday);

	// カレンダー構築用HTML
	ddata = '';
	ddata += '<div class="cal-month">' + nowtitleyyyymm + '</div>\n';
	ddata += '<table>\n';
	ddata += '<tr>\n';

	for (i = 0; i < 7; i++) {
		ddata += '<th>' + week[i] + '</th>\n';
	}
	
	ddata += '</tr>\n';

	for(j = 0; j < 6; j++) {
		ddata += '<tr>\n';
		for(i = 0; i < 7; i++) {
			nextday = startday.getTime() + (i * 1000 * 60 * 60 * 24);
			wrtday  = new Date(nextday);

			wrtdate = wrtday.getDate();
			wrtmonth = wrtday.getMonth();
			wrtyear = wrtday.getYear();
			if (wrtyear < 1900) wrtyear = 1900 + wrtyear;
			wrtyyyymm = wrtyear * 100 + wrtmonth;
			wrtyyyymmdd = wrtyear * 10000 + wrtmonth * 100 + wrtdate;
			
			wrtdateA  = '<a href="javascript:setFormCalendar(' + wrtyear + ',' + (wrtmonth + 1) + ',' + wrtdate + ')">' + wrtdate + '</a>';

			if (wrtyyyymm != nowyyyymm) {
				ddata += '<td>';
			} else if (wrtyyyymmdd < thisyear * 10000 + thismonth * 100 + thisday || wrtyyyymmdd >= maxyyyymmdd) {
				ddata += '<td class="passed">' + wrtdate;
			} else if (wrtdate  == absnow.getDate()  &&
			           wrtmonth == absnow.getMonth() &&
			           wrtday.getYear() == absnow.getYear()) {
				ddata += '<td class="current">' + wrtdateA;
				if (i == 1) ++moncnt; // 月曜日をカウントする
			} else {
				// 祝日の取得
				syuku = getNationalHoliday(wrtyear, wrtmonth + 1, wrtdate, i);
				ddata += '<td';
				if (syuku || !i) ddata += ' class="holiday"'; // 日祝日
				else if (!syuku && i == 6) ddata += ' class="saturday"'; // 土曜日
				else ddata += ' class="weekday"'; // 平日
				ddata += '>';
				if (syuku) {
					ddata += '<span title="'+ syuku + '">' + wrtdateA + '</span>';
				} else {
					ddata += wrtdateA;
				}
			}
			ddata += '</td>\n';
		}
		ddata += '</tr>\n';

		startday = new Date(nextday);
		startday = startday.getTime() + (1000 * 60 * 60 * 24);
		startday = new Date(startday);
	}

	ddata += '</table>\n';

	document.getElementById(target).innerHTML = ddata;
	document.getElementById("ps-cal").style.display = "block";
	if (document["srchArea"]) {
		document.getElementById("searchMonth").style.visibility = "hidden";
		document.getElementById("searchDay").style.visibility = "hidden";
		//コメントアウト 2007 07 tsukamoto
		//document.getElementById("searchStay").style.visibility = "hidden";
	}
}


/** 祭日の取得 **/

var moncnt = 0;
var furi   = 0;
var ck     = 0;
var Syunbunpar1 = new Array(19.8277,20.8357,20.8431,21.8510);
var Syunbunpar2 = new Array(22.2588,23.2588,23.2488,24.2488);

function getNationalHoliday(year, month, day, week){

	// 変数の初期化
	syuku = '';
	if (day == 1 && moncnt > 0 && !ck) moncnt = 0;

	// ハッピーマンデーと振替休日
	if (week == 1) {
		if (!ck) ++moncnt;
	
		// 振替休日
		// (2006年まで)「国民の祝日」が日曜日にあたるときは、その翌日を休日とする。
		if (furi == 1 && year <= 2006) {
			syuku = '振替休日';   // 振替フラグが立っていたら休み
			furi = 0;
		}
	
		// 第2月曜
		if (moncnt == 2){
			if(month ==  1) { syuku = '成人の日'; }  // 1月
			if(month == 10) { syuku = '体育の日'; }  // 10月
		}
	
		// 第3月曜
		if (moncnt == 3){
			if (year >= 2003 && month == 7) { syuku = '海の日'; }  // 7月(2003～)
			if (year >= 2003 && month == 9) { syuku = '敬老の日'; }  // 9月(2003～)
		}
	}

	// 春分の日・秋分の日
	var i,tyear;
	if ((year >= 1851) && (year <= 1899)) i = 0;
	else if ((year >= 1900) && (year <= 1979)) i = 1;
	else if ((year >= 1980) && (year <= 2099)) i = 2;
	else if ((year >= 2100) && (year <= 2150)) i = 3;
	else i = 4;   // 範囲外
	if (i < 4) {
		if (i < 2) tyear = 1983; else tyear = 1980;
		tyear = (year - tyear);
		if (month == 3) {      // 春分の日
			if (day == Math.floor(Syunbunpar1[i] + 0.242194 * tyear - Math.floor((tyear + 0.1)/4))) syuku = '春分の日';
		} else if(month == 9) { // 秋分の日
			if(day == Math.floor(Syunbunpar2[i] + 0.242194 * tyear - Math.floor((tyear + 0.1)/4))) syuku = '秋分の日';
		}
	}

	// その他の祝日
	if (month == 1 && day ==  1) syuku = '元日';  //  1月 1日
	if (month == 2 && day == 11) syuku = '建国記念の日';    //  2月11日
	if (month == 4 && day == 29 && year <= 2006) syuku = 'みどりの日';  //  4月29日(2006年まで)
	if (month == 4 && day == 29 && year >= 2007) syuku = '昭和の日';  //  4月29日(2007年から)
	if (month == 5 && day ==  3) syuku = '憲法記念日';  //  5月 3日
	if (month == 5 && day ==  4 && year >= 2007) syuku = 'みどりの日';  //  5月 4日(2007年から)
	if (month == 5 && day ==  5) syuku = 'こどもの日';  //  5月 5日
	if (month == 11 && day ==  3) syuku = '文化の日';  // 11月 3日
	if (month == 11 && day == 23) syuku = '勤労感謝の日';  // 11月23日
	if (month == 12 && day == 23) syuku = '天皇誕生日';  // 12月23日
	if (year < 2003 && month == 7 && day == 20) syuku = '海の日';  // 7月20日(～2002)
	if (year < 2003 && month == 9 && day == 15) syuku = '敬老の日';  //  9月15日(～2002)

	// 振替休日
	// (2007年から)「国民の祝日」が日曜日に当たるときは、その日後においてその日に最も近い「国民の祝日」でない日を休日とする。
	if (furi == 1 && syuku == '' && year >= 2007) {
		syuku = '振替休日';  // 振替フラグが立っていたら休み
		furi = 0;
	} else if (furi == 1 && syuku != '' && year >= 2007) {
		furi = 1;  // 振替フラグが立っていて祝日の場合は振替フラグを立てる
	} else if (week == 0 && syuku != '') {
		furi = 1;  // 日曜で祝日の場合は振替フラグを立てる
	} else {
		furi = 0;
	}

	// 国民の休日(祝日に挟まれた平日)
	// (2006年まで)その前日及び翌日が「国民の祝日」である日（日曜日にあたる日及び前項に規定する休日にあたる日を除く。）は、休日とする。
	// (2007年から)その前日及び翌日が「国民の祝日」である日（「国民の祝日」でない日に限る。）は、休日とする。
	if((week > 0 && syuku == '' && !ck && year <= 2006) || (syuku == '' && !ck && syuku != '振替休日' && year >= 2007)) {
		ck = 1;  //再帰呼び出しでここを通らないようにする
		// 前日と次日が祝日か確認
		// １日と末日が祝日の場合はないので日にちは単純に１を増減する
		// 曜日の設定
		bweek = week - 1; if (bweek < 0) bweek = 6;
		aweek = week + 1; if (bweek > 6) bweek = 0;
		if (getNationalHoliday(year,month,day - 1,bweek) && getNationalHoliday(year,month,day + 1,aweek)) {
			syuku = '国民の休日';
		}
		ck = 0;  // フラグの初期化
	}

	return syuku;
}


/** form check **/

// TOP - 条件を指定して探す
/*
function chkForm_SearchOption() {
	// Form ID
	if (document["formSearchOption"]) form_search = document["srchArea"];
	if (document["formSearchOptionIi04"]) form_search = document["formSearchOptionIi04"];
	if (document["formSearchOptionIi06"]) form_search = document["formSearchOptionIi06"];
	
	if (document.getElementById("searchCity") && !chkCitySelected()) {
		alert("都道府県を選択してください。");
		return false;
	}
	
	if (!chkDate()) {
		alert("正しい日付を選択してください。");
		return false;
	}
	
	if (!chkFee()) {
		alert("最低料金と最高料金を正しく選択してください。");
		return false;
	}
	
	if (!chkRoom()) {
		alert("室数を合計人数以下にしてください。");
		return false;
	}
	// キーワード条件対策
	if (document["srchArea"])
	{
		form_search.elements["txtKeywordText"].value = "";
	}
	
	form_search.submit();
}
*/
// 都道府県の未選択チェック
function chkCitySelected() {
	var search_city = form_search["searchCity"].options;

// 2007/06/01 修正 N
//	// selectedIndex値が1～47の場合都道府県を選択していると判定
//	if (1 <= search_city.selectedIndex && search_city.selectedIndex <= 47) {
//	// search_cityのvalueに値が設定されている場合都道府県を選択していると判定
	if (search_city.value != "" ) {
		return true;
	} else {
		return false;
	}
}

// 日付の存在チェック
function chkDate() {
	var search_month = form_search["searchMonth"];
	var search_day = form_search["searchDay"];
	//コメントアウト 2007 07 tsukamoto
	//var search_stay = form_search["searchStay"];

	//宿泊日数が未設定 2007/06/08 修正 Y
	//if(search_stay[search_stay.selectedIndex].value < 1 || search_stay[search_stay.selectedIndex].value == ""){
	//	return false;
	//}

	var val = search_month[search_month.selectedIndex].value.split("-");

	vYear = val[0];
	vMonth = val[1] - 1;
	vDay = search_day[search_day.selectedIndex].value;

	if (vMonth >= 0 && vMonth <= 11 && vDay >= 1 && vDay <= 31) {
		var vDt = new Date(vYear, vMonth, vDay);
		if (isNaN(vDt)) {
			return false;
		} else if (vDt.getFullYear() == vYear && vDt.getMonth() == vMonth && vDt.getDate() == vDay) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

// 一泊料金の料金範囲チェック
function chkFee() {
	var search_fee_1 = form_search["searchFee1"];
	var search_fee_2 = form_search["searchFee2"];
	
	var fee_1 = Number(search_fee_1[search_fee_1.selectedIndex].value);
	var fee_2 = Number(search_fee_2[search_fee_2.selectedIndex].value);
	
	if (fee_1 && fee_2 && fee_1 > fee_2) {
		return false;
	}
	
	return true;
}

// 室数チェック
function chkRoom() {
	var search_room = form_search["searchRoom"];
	var search_person_man = form_search["searchPersonMan"];
	
	//コメントアウト 2007 07 tsukamoto
	//var search_children_a = form_search["psChildrenA"];
	//var search_children_b = form_search["psChildrenB"];
	
	var room = search_room[search_room.selectedIndex].value;
	var person_man = search_person_man[search_person_man.selectedIndex].value;
	var children_a = search_children_a[search_children_a.selectedIndex].value;
	var children_b = search_children_b[search_children_b.selectedIndex].value;
	
	if (Number(room) > Number(person_man) + Number(children_a) + Number(children_b)) {
		return false;
	}
	
	return true;
}

/** room type **/

function chkRoomType() {
	var option01 = form_search.elements["option01"];
	var option02 = form_search.elements["option02"];
	var option03 = form_search.elements["option03"];
	var option04 = form_search.elements["option04"];
	var option05 = form_search.elements["option05"];
	
	if (option02.checked || option03.checked || option04.checked || option05.checked) {
		option01.checked = false;
	}
	
	//すべてチェックが外れている場合  2007/05/28 Y
	if (option02.checked == false && option03.checked == false && option04.checked == false && option05.checked == false) {
		option01.checked = true;
	}
	
}

function resetRoomType() {
	var option01 = form_search.elements["option01"];
	
	if (option01.checked) {
		form_search.elements["option02"].checked = false;
		form_search.elements["option03"].checked = false;
		form_search.elements["option04"].checked = false;
		form_search.elements["option05"].checked = false;
	}
}

/** dinner type **/

function chkDinnerType() {
	var option06 = form_search.elements["option06"];
	var option07 = form_search.elements["option07"];
	var option08 = form_search.elements["option08"];
	var option09 = form_search.elements["option09"];
	var option10 = form_search.elements["option10"]; // 2007/05/28 Y
	
	if (option07.checked || option08.checked || option09.checked || option10.checked) {
		option06.checked = false;
	}
	
	//すべてチェックが外れている場合  2007/05/28 Y
	if (option07.checked == false && option08.checked == false && option09.checked == false && option10.checked == false) {
		option06.checked = true;
	}
}

function resetDinnerType() {
	var option06 = form_search.elements["option06"];
	
	if (option06.checked) {
		form_search.elements["option07"].checked = false;
		form_search.elements["option08"].checked = false;
		form_search.elements["option09"].checked = false;
		form_search.elements["option10"].checked = false;
	}
}

/** other **/

function closeAll() {
	// Form ID
	if (document["formSearchOption"]) form_search = document["formSearchOption"];
	if (document["formSearchOptionIi04"]) form_search = document["formSearchOptionIi04"];
	if (document["formSearchOptionIi06"]) form_search = document["formSearchOptionIi06"];
	
	//子供人数　2007/06/08 Y
	
	//コメントアウト 2007 07 tsukamoto
	//chld_a_org = form_search["psChildrenA"].value;
	//chld_b_org = form_search["psChildrenB"].value;
	
	closeChildren();
	closeCalendar();
}

/** Keyword Search **/
function chkKeywordArea() {
	var keywordArea = form_search.elements["searchKeywordArea"];
	var keywordStat = form_search.elements["searchKeywordStation"];
	var keywordYado = form_search.elements["searchKeywordYado"];
	
	if (keywordArea.checked) {
		keywordStat.checked = false;
		keywordYado.checked = false;
	}
}
function chkKeywordStat() {
	var keywordArea = form_search.elements["searchKeywordArea"];
	var keywordStat = form_search.elements["searchKeywordStation"];
	var keywordYado = form_search.elements["searchKeywordYado"];
	
	if (keywordStat.checked) {
		keywordArea.checked = false;
		keywordYado.checked = false;
	}
}
function chkKeywordYado() {
	var keywordArea = form_search.elements["searchKeywordArea"];
	var keywordStat = form_search.elements["searchKeywordStation"];
	var keywordYado = form_search.elements["searchKeywordYado"];
	
	if (keywordYado.checked) {
		keywordArea.checked = false;
		keywordStat.checked = false;
	}
}

function chkKeywordText(){
	var keywordText = trim(form_search.elements["txtKeywordText"].value);
	var keywordArea = form_search.elements["searchKeywordArea"];
	var keywordStat = form_search.elements["searchKeywordStation"];
	var keywordYado = form_search.elements["searchKeywordYado"];
	if (keywordText.length == 0)
	{
		alert("キーワードを入力してください。");
		return false;
	}
	if (keywordText.match(/\\|\&|\>|\<|\"|\'|\.|\,|\/|\%|\_/))
	{
		alert("\\ & > < \" \' . , / % _ の文字は利用できません。");
		return false;
	}
	if (keywordStat.checked && keywordText.match(/^駅$/))
	{
		alert("検索条件を変えて再検索してください。");
		return false;
	}
	if (keywordArea.checked)
	{
		errorString = "都道府県市区町村郡";
		if (keywordText.length == 1)
		{
			for (i = 0; i < 9; i++)
			{
				if (keywordText.indexOf(errorString.charAt(i), 0) >= 0)
				{
					alert("検索条件を変えて再検索してください。");
					return false;
				}
			}
		}
	}
	if (keywordYado.checked)
	{
		errorString1 = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゐゆゑよらりるれろわをん";
		errorString2 = "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン";
		errorString3 = "宿旅館";
		if (keywordText.length == 1)
		{
			for (i = 0; i < errorString1.length; i++)
			{
				if (keywordText.indexOf(errorString1.charAt(i), 0) >= 0)
				{
					alert("検索条件を変えて再検索してください。");
					return false;
				}
			}
			for (i = 0; i < errorString2.length; i++)
			{
				if (keywordText.indexOf(errorString2.charAt(i), 0) >= 0)
				{
					alert("検索条件を変えて再検索してください。");
					return false;
				}
			}
			for (i = 0; i < errorString3.length; i++)
			{
				if (keywordText.indexOf(errorString3.charAt(i), 0) >= 0)
				{
					alert("検索条件を変えて再検索してください。");
					return false;
				}
			}
		}
		if (keywordText.match(/^ホテル$/))
		{
			alert("検索条件を変えて再検索してください。");
			return false;
		}
		if (keywordText.match(/^旅館$/))
		{
			alert("検索条件を変えて再検索してください。");
			return false;
		}
	}

	form_search.elements["txtKeywordText"].value = keywordText;
	return true;
}

function trim(text){
	// 引数の文字列の前後のスペース（半角と全角）を削除
	return String(text).replace(/^[ 　]*/gi, "").replace(/[ 　]*$/gi, "");
}

function checkBrowser(){
	var browser = navigator.appName.toUpperCase();
	if(browser.indexOf("MICROSOFT") >= 0){
		return(1);
	} else if(browser.indexOf("NETSCAPE") >= 0){
		return(2);
	} else{
		return(0);
	}
}

function searchKeydown(ev){
	var keycode;
	bkind = checkBrowser();
	if(bkind == 1){
		keycode = ev.keyCode;
	} else if(bkind == 2){
		keycode = ev.which;
	} else {
	}

	if (keycode == 13){
		return chkKeywordText();
	}
}

//都道府県切り替え
//2007 07 tsukamoto add
function showCity(){
	var City1 = document.getElementById("searchCity");
	
	var Area1 = document.getElementById("searchArea1");
		
	var city =[
	[
		["","指定なし"]
	],
[
	["01","ニセコ・ルスツ・小樽"],
	["02","稚内・利尻・礼文"],
	["03","旭川・富良野"],
	["04","釧路・根室"],
	["05","札幌・定山渓・千歳"],
	["06","帯広・日高"],
	["07","稚内・利尻・礼文"],
	["08","洞爺・登別・苫小牧"],
	["09","函館・大沼・松前"],
	["10","網走・知床"]
],
[
	["01","下北・三沢"],
	["02","弘前"],
	["03","十和田・八戸"],
	["04","青森"],
	["05","津軽半島・西津軽"]
],
[
	["01","大曲・横手・鳥海"],
	["02","秋田・田沢湖"],
	["03","大館・鹿角"],
	["04","白神・男鹿"]
],
[
	["01","一関・江刺"],
	["02","花巻・遠野"],
	["03","三陸海岸"],
	["04","盛岡・安比"]
],
[
	["01","山形・天童・上山.・米沢"],
	["02","酒田・鶴岡"],
	["03","尾花沢・新庄・村山"]
],
[
	["01","松島・志津川・気仙沼"],
	["02","仙台"],
	["03","蔵王・白石"],
	["04","鳴子・栗駒"]
],
[
	["01","いわき・相馬"],
	["02","会津若松周辺・南会津"],
	["03","郡山・白河"],
	["04","猪苗代・磐梯高原"],
	["05","福島・二本松"]
],	
[
	["01","つくば・牛久"],
	["02","霞ケ浦・潮来・鹿島"],
	["03","水戸・大洗・笠間"],
	["04","北茨城・奥久慈"]
],
[
	["01","宇都宮・佐野"],
	["02","那須・塩原"],
	["03","日光・鬼怒川"]
],
[
	["01","磯部・前橋・太田"],
	["02","水上・老神・桐生"],
	["03","草津・北軽井沢・伊香保"]
],
[
	["01","熊谷・飯能・森林公園"],
	["02","川越・さいたま"],
	["03","秩父"]
],
[
	["01","館山・白浜・千倉"],
	["02","九十九里・銚子"],
	["03","勝浦・鴨川"],
	["04","成田・柏・野田"],
	["05","千葉・木更津・佐倉"],
	["06","舞浜・幕張・浦安・船橋"]
],
[
	["01","横須賀・三浦"],
	["02","横浜・川崎"],
	["03","湘南・鎌倉・厚木"],
	["04","箱根・湯河原"]
],
[
	["01","上野・浅草・両国・江戸川・江東"],
	["02","東京駅・銀座・お台場"],
	["03","池袋・後楽園・九段下"],
	["04","新宿・渋谷・恵比寿"],
	["05","赤坂・六本木"],
	["06","品川・大森・羽田"]
],
[
	["01","伊豆七島"]
],
[
	["01","八王子・多摩・立川"]
],
[
	["01","甲府・石和・勝沼"],
	["02","八ヶ岳・下部・身延"],
	["03","富士五湖・大月"]
],
[
	["01","長岡・上越・糸魚川"],
	["02","佐渡"],
	["03","新潟・阿賀野川"],
	["04","村上"],
	["05","湯沢・奥只見"]
],
[
	["01","軽井沢・上田・戸倉"],
	["02","松本・安曇野・上高地"],
	["03","諏訪・蓼科・八ヶ岳"],
	["04","長野"],
	["05","白馬"],
	["06","木曽・飯田・伊那"],
	["07","野沢・志賀・斑尾"]
],
[
	["01","三津浜・沼津・御殿場"],
	["02","西伊豆"],
	["03","静岡・焼津・御前崎・大井川"],
	["04","中伊豆"],
	["05","東伊豆"],
	["06","南伊豆"],
	["07","熱海・伊東"],
	["08","浜松・浜名湖"]
],
[
	["01","三河"],
	["02","知多半島"],
	["03","尾張"],
	["04","名古屋"]
],
[
	["01","伊賀・津・松坂"],
	["02","伊勢・鳥羽"],
	["03","四日市・鈴鹿"],
	["04","志摩・奥伊勢"]
],
[
	["01","飛騨高山・奥飛騨温泉郷"],
	["02","下呂・奥美濃"],
	["03","岐阜・美濃"],
	["04","恵那・中津川"]
],
[
	["01","氷見・砺波"],
	["02","富山"],
	["03","立山・黒部・宇奈月"]
],
[
	["01","加賀・白山"],
	["02","金沢"],
	["03","和倉・輪島・能登"]
],
[
	["01","若狭"],
	["02","福井"]
],
[
	["01","奥琵琶湖"],
	["02","草津・近江八幡"],
	["03","大津・雄琴"],
	["04","彦根・長浜"]
],
[
	["01","嵐山・嵯峨野・高雄"],
	["02","祇園・東山・岡崎"],
	["03","宝ヶ池・大原・貴船"],
	["04","丹波・亀岡"],
	["05","伏見・醍醐・山科"],
	["06","宇治"],
	["07","京都洛中"],
	["08","天の橋立・宮津・丹後"]
],
[
	["01","吉野"],
	["02","奈良"],
	["03","飛鳥・室生"]
],
[
	["01","堺・南泉州"],
	["02","大阪中心部"],
	["03","東大阪・河内"],
	["04","北摂・摂津・能勢"]
],
[
	["01","串本・勝浦"],
	["02","新宮"],
	["03","白浜・田辺"],
	["04","有田・御坊・龍神"],
	["05","和歌山・高野山"]
],
[
	["01","城崎・但馬海岸"],
	["02","神戸・明石"],
	["03","神鍋・湯村・養父"],
	["04","淡路島"],
	["05","姫路・播磨"],
	["06","宝塚・尼崎・篠山"]
],
[
	["01","三朝・倉吉"],
	["02","鳥取・鳥取県東部"],
	["03","米子・皆生"]
],
[
	["01","隠岐島"],
	["02","松江・出雲・玉造"],
	["03","津和野・石見"]
],
[
	["01","岡山・牛窓"],
	["02","倉敷・総社"],
	["03","津山・美作三湯"]
],
[
	["01","広島・宮島・呉"],
	["02","三次・庄原・芸北"],
	["03","尾道・福山"]
],
[
	["01","下関"],
	["02","岩国・柳井"],
	["03","湯田・山口"],
	["04","萩・長門"]

],
[
	["01","琴平・丸亀"],
	["02","高松・塩之江"],
	["03","小豆島"]
],
[
	["01","阿南海岸"],
	["02","祖谷・大歩危・剣山"],
	["03","徳島・鳴門"]
],
[
	["02","高知・須崎"],
	["03","足摺・四万十"]
],
[
	["01","宇和島・八幡浜"],
	["02","今治・しまなみ海道・新居浜"],
	["03","松山・道後"]
],
[
	["01","久留米・大牟田"],
	["02","福岡市近郊"],
	["03","北九州周辺"]
],
[
	["01","嬉野・武雄"],
	["02","佐賀・神埼・三瀬"],
	["03","唐津・呼子・伊万里・有田"]
],
[
	["01","壱岐・対馬・五島列島"],
	["02","佐世保・平戸・松浦"],
	["03","長崎市周辺"],
	["04","島原半島"]
],
[
	["01","阿蘇"],
	["02","熊本"],
	["03","人吉・水俣"],
	["04","天草"]
],
[
	["01","九重・久住・竹田"],
	["02","日田・耶馬渓・国後"],
	["03","別府・湯布院・大分"]
],
[
	["01","宮崎・日南・えびの"],
	["02","日向・高千穂"]
],
[
	["01","屋久島・種子島・その他離島"],
	["02","鹿児島・指宿"],
	["03","垂水・佐多"],
	["04","霧島・北薩・川内"]
],
[
	["01","那覇・本島南部"],
	["02","本島中部"],
	["03","本部・名護・国頭"],
	["04","離島"]
]


];
	
	var obj = document.getElementById("searchArea1");
	
	var chilldd_len = document.getElementById("searchCity").selectedIndex;
	
	obj.options.length = 1;
	
	if( chilldd_len != 0){
		for(var i=0; i<=city[chilldd_len].length; i++ ){

			if( i == 0 ){
				obj.options[i] = new Option("指定なし");
				obj.options[i].value = "";
			}
			else{
				obj.options[i] = new Option(city[chilldd_len][i-1][1]);
				obj.options[i].value = city[chilldd_len][i-1][0];
			}
		}
	}
	else{
		obj.options[0] = new Option("指定なし");
		obj.options[0].value = "";
	}
	


}

//地区連結
//2007 07 tsukamoto add
function AreaJoin(){

	//入力画面から入力されたデータ
	var In_City = document.srchArea.searchCity.value
	var In_Area = document.srchArea.searchArea1.value
	var In_month = document.srchSch.searchMonth.value
	var In_day = document.srchSch.searchDay.value

	//実際に送信される値
	var Out_cat = document.SendValue.catid
	var Out_month = document.SendValue.StayYM
	var Out_day = document.SendValue.StayD

	Out_cat.value = In_City + In_Area
	Out_month.value = In_month
	Out_day.value = In_day
	
	if(In_City == ""){
		alert("都道府県を選択してください。");
		return false;
	}
	else{
		return true;
	}
	
}

//日付設定
function setDayNEW(){

	var nowDate = new Date();
	var this_Year = nowDate.getFullYear();
	var this_month = nowDate.getMonth() + 1;
	var this_date = nowDate.getDate();

	var month = document.getElementById("searchMonth");
	var date = document.getElementById("searchDay");
	
	var Out_date = "";
	var Out_month = this_month - 1;
	var Out_year = this_Year;
	
	var arry = ["31","28","31","30","31","30","31","31","30","31","30","31"];
	
	//うるう年計算
	if( this_Year%4 == 0 ){
		if( this_Year%100 == 0 ){
			if( this_Year%400 == 0 ){
				arry[1] = 29;
			}
		}
		else{
			arry[1] = 29;
		}
	}
	
	
	//本日+2
	if( this_date+2 > arry[this_month-1] ){
	
		Out_month = this_month;
		Out_date = (this_date + 2) - arry[this_month-1];
		
	}
	else{
		Out_month = this_month - 1;
		Out_date = this_date + 2;
	}
	
	var Out_month2 = Out_month + 1;
	

	for(var i=0; i<10; i++){
	
		if(Out_month < 12){
			Out_month = Out_month +1;
		}
		else if(Out_month == 12){
			Out_month = 1;
			Out_year = Out_year + 1;
			
		}
		
		month.options[i] = new Option(Out_year + "年" + Out_month + "月");
		
		if( Out_month>=10 ){
			month.options[i].value = String(Out_year) + String(Out_month);
		}
		else{
			month.options[i].value = Out_year + "0" + Out_month;
		}
	
	}
		
	for( var i=0; i<arry[Out_month2 - 1]; i++ ){
		if( i>=9 ){
			date.options[i] = new Option(String(i + 1) + "日");
			date.options[i].value = String(i + 1);
		}
		else{
			date.options[i] = new Option("0" + String(i + 1) + "日");
			date.options[i].value = "0" + String(i + 1);
		}

		if( (i + 1) == Out_date ){
			date.options[i].selected=true;
		}
	
	}

}

function setDayReset(){

	var month = document.getElementById("searchMonth");
	var date = document.getElementById("searchDay");
	var selected = month.value;
	var Selected_month = selected%100;
	var Selected_Year = selected/100 - (selected%100)/100;
	var arry = ["31","28","31","30","31","30","31","31","30","31","30","31"];
	
	//うるう年計算
	if( Selected_Year%4 == 0 ){
		if( Selected_Year%100 == 0 ){
			if( Selected_Year%400 == 0 ){
				arry[1] = 29;
			}
		}
		else{
			arry[1] = 29;
		}
	}

	var date = document.getElementById("searchDay");
	date.length = 0;
	
	for( var i=0; i<arry[Selected_month - 1]; i++ ){
		if( i>=9 ){
			date.options[i] = new Option(String(i + 1) + "日");
			date.options[i].value = String(i + 1);
		}
		else{
			date.options[i] = new Option("0" + String(i + 1) + "日");
			date.options[i].value = "0" + String(i + 1);
		}
	}
}

//出発月設定
function sortByCurrentMonth( el ){
	var arr = [];
	var arr_tmp = [];
	var m = (new Date()).getMonth();

	for(var i=0; i<el.options.length; i++){
		arr.push([el.options[i].text, el.options[i].value])
	}
	for(var i=0; i<m; i++){
		arr_tmp.push(arr.shift());
		arr.push(arr_tmp[i]);
	}
	for(var i=0; i<arr.length; i++){
		el.options[i] = new Option( arr[i][0],arr[i][1] );
	}
}
