function windowEvent(){
 if(window.event) return window.event;
 var caller = arguments.callee.caller;
 while(caller){
  var ob = caller.arguments[0];
  if(ob && ob.constructor == MouseEvent) return ob;
  caller = caller.caller;
 }
 return null;
}

function chase( id,offsetX,offsetY )
{
	var e = windowEvent();
	
	var d = document.getElementById(id);
	if(e.y != undefined){ //IE
		
		d.style.top = document.body.scrollTop + e.y + offsetX;
		d.style.left = document.body.scrollLeft + offsetY;
		calendar.location.href = "/index_calendar_new.php?n="+ document.activeElement.name;
		
		
	}else{ //other
		var pageX = e.pageX -110;
		var pageY = e.pageY + 15;
		d.style.top = pageY + 'px';
		d.style.left = pageX + 'px';
		calendar.location.href = "/index_calendar_new.php?n="+ document.activeElement.name;
		
	}
}

function date_set(y,m,d,n)
{
//クリックした日付に選択日を置き換える、あさってより過去日の場合はエラーメッセージを出す
		today = new Date();
		today_y_new = today.getFullYear();
		today_m_new = today.getMonth() + 1;
		today_d_new = today.getDate();
		
		tomorrow2 = new Date();
		tomorrow2.setFullYear(today_y_new);
		tomorrow2.setMonth(today_m_new - 1);
		tomorrow2.setDate(today_d_new + 2);
		
		tomorrow2_y_new = tomorrow2.getFullYear();
		tomorrow2_m_new = tomorrow2.getMonth() + 1;
		tomorrow2_d_new = tomorrow2.getDate();
		tomorrow2_y = "" + tomorrow2_y_new;
		tomorrow2_m = "" + tomorrow2_m_new;
		tomorrow2_d = "" + tomorrow2_d_new;
		
		tomorrow2_ymd = tomorrow2_d+tomorrow2_d+tomorrow2_d;
		tomorrow2_ymd_num = parseInt(tomorrow2_ymd);

	if(n=='ci'){
		if (y.length == 2 ) {
			y_new = ""+"20"+y;
			y = ""+y_new;
		}
		if (m.length < 2 ) {
			m_new = "0"+m;
			m     = ""+"0"+m_new;
		}
		if (d.length < 2 ) {
			d_new = "0"+d;
			d = ""+"0"+d_new;
		}
		sel_date = y + m + d;
		sel_date_num = parseInt(sel_date);
		
		if (sel_date_num >= tomorrow2_ymd_num) {
			document.search.ci.value= y+'/'+m+'/'+d;
		} else {
			alert("当日翌日は専用画面から予約可能です");
		}
	}
	else if(n=='date_md'){
		month = new String("");
		month = ""+m;
		if (month.length == 1) {
		    month = "0"+m;
		}
    //alert(month.length);
		day = new String("");
		day = ""+d;
		if (day.length == 1) {
		    day   = "0"+d;
		}

    //alert(day.length);
		if (y.length == 2 ) {
			y_new = ""+"20"+y;
			y = ""+y_new;
		}
		if (m.length < 2 ) {
			m_new = "0"+m;
			m     = ""+"0"+m_new;
		}
		if (d.length < 2 ) {
			d_new = "0"+d;
			d = ""+"0"+d_new;
		}
		sel_date = y + month + day;
		sel_date_num = parseInt(sel_date);
		if (sel_date_num >= tomorrow2_ymd_num) {
			document.search.date_md.value= y+'/'+month+'/'+day;
		} else {
			alert("当日翌日は専用画面から予約可能です");
		}
	}
	else{
		sel_date = y + m + d;
		sel_date_num = parseInt(sel_date);
		if (sel_date_num >= tomorrow2_ymd_num) {
			document.search.co.value= y+'/'+m+'/'+d;
		} else {
			alert("当日翌日は専用画面から予約可能です");
		}
	}
}

function div_on(id)
{
	document.getElementById(id).style.visibility="visible";
	document.getElementById(id).style.display="inline";
}
function div_off(id)
{
	document.getElementById(id).style.visiblity="hidden";
	document.getElementById(id).style.display="none";
}
function div_on2(id,id2)
{
	document.getElementById(id).style.visibility="visible";
	document.getElementById(id).style.display="inline";
	document.getElementById(id2).style.visibility="visible";
	document.getElementById(id2).style.display="inline";
}
function div_off2(id,id2)
{
	document.getElementById(id).style.visiblity="hidden";
	document.getElementById(id).style.display="none";
	document.getElementById(id2).style.visiblity="hidden";
	document.getElementById(id2).style.display="none";
}

function inputday_chk(id){
	//入力日が今日明日ならエラーを出す(index_hotel.phpの検索専用)
		today = new Date();
		today_y_new = today.getFullYear();
		today_m_new = today.getMonth() + 1;
		today_d_new = today.getDate();
		//alert(today_y_new+today_m_new+today_d_new);

		tomorrow2 = new Date();
		tomorrow2.setFullYear(today_y_new);
		tomorrow2.setMonth(today_m_new - 1);
		tomorrow2.setDate(today_d_new + 2);
		
		tomorrow2_y_new = tomorrow2.getFullYear();
		tomorrow2_m_new = tomorrow2.getMonth() + 1;
		tomorrow2_d_new = tomorrow2.getDate();
		if (tomorrow2_y_new.length == 2 ) {
			y_new = ""+"20"+tomorrow2_y_new;
			tomorrow2_y = ""+y_new;
		} else {
			tomorrow2_y = ""+tomorrow2_y_new;
		}
		//if (tomorrow2_m_new.length < 2 ) {
		if (tomorrow2_m_new < 10 ) {
			m_new = "0"+tomorrow2_m_new;
			tomorrow2_m = ""+m_new;
		//alert("1桁");
		} else {
			tomorrow2_m = ""+tomorrow2_m_new;
		//alert("2桁");
		}
		//if (tomorrow2_d_new.length < 2 ) {
		if (tomorrow2_d_new < 10 ) {
			d_new = "0"+tomorrow2_d_new;
			tomorrow2_d = ""+d_new;
		} else {
			tomorrow2_d = ""+tomorrow2_d_new;
		}
		
		tomorrow2_ymd = tomorrow2_y+tomorrow2_m+tomorrow2_d;
		//alert(tomorrow2_ymd);
		tomorrow2_ymd_num = parseInt(tomorrow2_ymd);

	date_md = document.search.date_md.value;
	date_md_array = date_md.split("/");
	date_md_new = date_md_array[0]+date_md_array[1]+date_md_array[2];
	if (date_md_new >= tomorrow2_ymd_num) {
		//alert("OK"+date_md_new+tomorrow2_ymd_num);
		return true;
	} else {
		alert("当日翌日は専用画面から予約可能です");
		return false;
	}
}

function inputday_chk2(id){
	//入力日が今日明日ならlist_today.phpに遷移先を変更するデフォルトは、list.php(index_hotel.phpの検索専用)
	if(document.search.homen.options[document.search.homen.selectedIndex].value==0){
		alert('方面を選択してください。');
		return false;
	}

	//今日
	today = new Date();
	today_y_new = today.getFullYear();
	today_m_new = today.getMonth() + 1;
	today_d_new = today.getDate();
	//alert(today_y_new+today_m_new+today_d_new);

	if (today_m_new < 10 ) {
		m_new = "0"+today_m_new;
		today_m = ""+m_new;
	//alert("1桁");
	} else {
		today_m = ""+today_m_new;
	//alert("2桁");
	}
	if (today_d_new < 10 ) {
		d_new = "0"+today_d_new;
		today_d = ""+d_new;
	} else {
		today_d = ""+today_d_new;
	}
	today_ymd = today_y_new+today_m+today_d;
	today_ymd_num = parseInt(today_ymd);

	//明日
	tomorrow = new Date();
	tomorrow.setFullYear(today_y_new);
	tomorrow.setMonth(today_m_new - 1);
	tomorrow.setDate(today_d_new + 1);

	tomorrow_y_new = tomorrow.getFullYear();
	tomorrow_m_new = tomorrow.getMonth() + 1;
	tomorrow_d_new = tomorrow.getDate();
	if (tomorrow_m_new < 10 ) {
		m_new = "0"+tomorrow_m_new;
		tomorrow_m = ""+m_new;
	//alert("1桁");
	} else {
		tomorrow_m = ""+tomorrow_m_new;
	//alert("2桁");
	}
	if (tomorrow_d_new < 10 ) {
		d_new = "0"+tomorrow_d_new;
		tomorrow_d = ""+d_new;
	} else {
		tomorrow_d = ""+tomorrow_d_new;
	}

	tomorrow_ymd = tomorrow_y_new+tomorrow_m+tomorrow_d;
	//alert(tomorrow_ymd);
	tomorrow_ymd_num = parseInt(tomorrow_ymd);

	date_md = document.search.date_md.value;
	date_md_array = date_md.split("/");
	date_md_new = date_md_array[0]+date_md_array[1]+date_md_array[2];
	//検索結果ページ分岐list_rank.phpを作る。かなり無理やりの遷移だ…
	if (date_md_new > tomorrow_ymd_num) {
		//alert("OK"+date_md_new+tomorrow_ymd_num);
			if(document.search.sen_i[0].checked){
				document.search.action = "/list_rank.php";
			} else if (document.search.sen_i[1].checked){
				document.search.action = "/list_rank.php";
			}else{
				document.search.action = "/list.php";
			}
		return true;
	} else if (date_md_new == tomorrow_ymd_num || date_md_new == today_ymd_num) {
		//alert("当日翌日");
		//return false;
		document.search.action = "/list_today.php";
	} else {
		//alert("当日翌日は専用画面から予約可能です");
		return false;
	}
}
