// JavaScript Document
if (!newWindow) {
	var newWindow = null;
}
function openWinNoSize(url, n, st){
	var toolbar;
	var location;
	var directories;
	var status;
	var menubar;
	var resizable;
	var scrollbars;
	var dependent;

	st.charAt(0) == '1'	?  toolbar = 'yes' 		: toolbar = 'no';
	st.charAt(1) == '1'	?  location = 'yes' 	: location = 'no';
	st.charAt(2) == '1'	?  directories = 'yes' 	: directories = 'no';
	st.charAt(3) == '1'	?  status = 'yes' 		: status = 'no';
	st.charAt(4) == '1'	?  menubar = 'yes' 		: menubar = 'no';
	st.charAt(5) == '1'	?  resizable = 'yes' 	: resizable = 'no';
	st.charAt(6) == '1'	?  scrollbars = 'yes' 	: scrollbars = 'no';
	st.charAt(7) == '1'	?  dependent = 'yes' 	: dependent = 'no';

	var win_attr = 'toolbar=' + toolbar + ',location=' + location + ',directories=' + directories + ',status=' + status + ',menubar=' + menubar + ',resizable=' + resizable + ',scrollbars=' + scrollbars + ',dependent=' + dependent;

	newWindow = open(url,'_blank', win_attr);
}

//各月の日数チェック
function chk_days(year, month) {
	days = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 29);
	if(month == 2){
		if((year%4==0 && year%100!=0) || year%400==0){
			month = 13;
		}
	}
	return days[month-1];
}
function chg_indays(){
	var form = document.myFORM;
	var sIndex = form.elements["chkin_dd"].selectedIndex;
	var sYear = form.elements["chkin_yy"].options[form.elements["chkin_yy"].selectedIndex].value;
	var sMonth = form.elements["chkin_mm"].options[form.elements["chkin_mm"].selectedIndex].value;
	var days = chk_days(sYear, sMonth);
	var optLength = form.elements["chkin_dd"].options.length;
	for(i=0; i<optLength; i++){
		form.elements["chkin_dd"].options[0] = null;
	}
	for(i=0; i<days; i++){
		form.elements["chkin_dd"].options[i] = new Option(i+1);
		form.elements["chkin_dd"].options[i].value = keta2(i+1);
		if(i==sIndex || (sIndex>=days && i==days-1)){
			form.elements["chkin_dd"].options[i].selected = true;
		}
	}
}
function chg_outdays(){
	var form = document.myFORM;
	var sIndex = form.elements["chkout_dd"].selectedIndex;
	var sYear = form.elements["chkout_yy"].options[form.elements["chkout_yy"].selectedIndex].value;
	var sMonth = form.elements["chkout_mm"].options[form.elements["chkout_mm"].selectedIndex].value;
	var days = chk_days(sYear, sMonth);
	var optLength = form.elements["chkout_dd"].options.length;
	for(i=0; i<optLength; i++){
		form.elements["chkout_dd"].options[0] = null;
	}
	for(i=0; i<days; i++){
		form.elements["chkout_dd"].options[i] = new Option(i+1);
		form.elements["chkout_dd"].options[i].value = keta2(i+1);
		if(i==sIndex || (sIndex>=days && i==days-1)){
			form.elements["chkout_dd"].options[i].selected = true;
		}
	}
}
//------------------------------------------------------

//チェックイン
var date  = new Date();
var year  = date.getFullYear();
var month = date.getMonth();
var day   = date.getDate();
function keta2(d) { return (d < 10) ? ('0' + d) : d; }
function s_yy(name) {
	var x = '<select name="' + name + '" style="font-size:10px" onChange="chg_s(\'yy\');">';
	for(k= year; k <=year+1; k++){
		x +="<option value=" + k + ((k==year) ? " selected" : "") + ">" + k + "</option>";
	}
	x += "</select>";
	return x;
}
function s_mm(name) {
	var y = '<select name="'+ name + '" onChange="chg_indays();chg_s(\'mm\');" style="font-size:10px">';
	for(j= 1; j <=12; j++){
		y +="<option value=" + keta2(j) + ((j==month+1) ? " selected" : "") + ">" + j + "</option>";
	}
	y += "</select>";
	return y;
}
function s_dd(name) {
	var form = document.myFORM;
	var sYear = form.elements["chkin_yy"].options[form.elements["chkin_yy"].selectedIndex].value;
	var sMonth = form.elements["chkin_mm"].options[form.elements["chkin_mm"].selectedIndex].value;
	var days = chk_days(sYear, sMonth);
	var z = '<select name="' + name + '" style="font-size:10px" onChange="chg_s(\'dd\');">';
	for(i = 1; i <= days; i++){
		z += "<option value=" + keta2(i) + ((i==(day)) ? " selected" : "") + ">" + i + "</option>";
	}
	z += "</select>";
	return z;
}
//------------------------------------------------------

//チェックアウト
var wday  = new Date();
wday.setTime(date.getTime() + (24 * 3600 * 1000));
var nyear  = wday.getFullYear();
var nmonth = wday.getMonth();
var nday   = wday.getDate();
function n_yy(name) {
	var x = '<select name="' + name + '" style="font-size:10px">';
	for(k= year; k <=year+2; k++){
		x +="<option value=" + k + ((k==nyear) ? " selected" : "") + ">" + k + "</option>";
	}
	x += "</select>";
	return x;
}
function n_mm(name) {
	var y = '<select name="'+ name + '" onChange="chg_outdays();" style="font-size:10px">';
	for(j= 1; j <=12; j++){
		y +="<option value=" + keta2(j) + ((j==nmonth+1) ? " selected" : "") + ">" + j + "</option>";
	}
	y += "</select>";
	return y;
}
function n_dd(name) {
	var form = document.myFORM;
	var sYear = form.elements["chkout_yy"].options[form.elements["chkout_yy"].selectedIndex].value;
	var sMonth = form.elements["chkout_mm"].options[form.elements["chkout_mm"].selectedIndex].value;
	var days = chk_days(sYear, sMonth);
	var z = '<select name="' + name + '" style="font-size:10px">';
	for(i = 1; i <= days; i++){
		z += "<option value=" + keta2(i) + ((i==(nday)) ? " selected" : "") + ">" + i + "</option>";
	}
	z += "</select>";
	return z;
}
//------------------------------------------------

//チェックイン日変更時の動作
function chg_s(ymd){
	var form = document.myFORM;
	var inDay = Number(form.elements["chkin_dd"].options[form.elements["chkin_dd"].selectedIndex].value);
	var inMonth = Number(form.elements["chkin_mm"].options[form.elements["chkin_mm"].selectedIndex].value);
	var inYear = Number(form.elements["chkin_yy"].options[form.elements["chkin_yy"].selectedIndex].value);
	var inYearIndex = form.elements["chkin_yy"].selectedIndex;
	var outDay = Number(form.elements["chkout_dd"].options[form.elements["chkout_dd"].selectedIndex].value);
	var outMonth = Number(form.elements["chkout_mm"].options[form.elements["chkout_mm"].selectedIndex].value);
	var outYear = Number(form.elements["chkout_yy"].options[form.elements["chkout_yy"].selectedIndex].value);
	switch (ymd) {
		case "dd":
			if(inDay >= outDay){
				if(form.elements["chkin_dd"].length == inDay){
					form.elements["chkout_dd"].options[0].selected = true;
					chg_s("mm");
				}else if(inMonth >= outMonth){
					form.elements["chkout_dd"].options[inDay].selected = true;
				}
			}
			break;
		case "mm":
			if(inMonth >= outMonth){
				if((inMonth == 12) && (form.elements["chkin_dd"].length == inDay)){
					form.elements["chkout_mm"].options[0].selected = true;
					chg_s("yy");
				}else if(form.elements["chkin_dd"].length == inDay){
					form.elements["chkout_mm"].options[inMonth].selected = true;
				}else{
					form.elements["chkout_mm"].options[inMonth-1].selected = true;
				}
			}
			break;
		case "yy":
			if(inYear >= outYear){
				if((inMonth == 12) && (form.elements["chkin_dd"].length == inDay)){
					form.elements["chkout_yy"].options[inYearIndex+1].selected = true;
				}else{
					form.elements["chkout_yy"].options[inYearIndex].selected = true;
				}
			}
			break;
	}
	/*var form = document.myFORM;
	var selectedDayNum = form.elements["chkin_dd"].options[form.elements["chkin_dd"].selectedIndex].value;
	switch (ymd) {
		case "dd":
			if(form.elements["chkin_dd"].length == selectedDayNum){
				form.elements["chkout_dd"].options[0].selected = true;
				chg_s("mm");
			}else{
				form.elements["chkout_dd"].options[selectedDayNum].selected = true;
			}
			break;
		case "mm":
			selectedNum = form.elements["chkin_mm"].options[form.elements["chkin_mm"].selectedIndex].value;
			if(form.elements["chkin_mm"].length == selectedNum){
				form.elements["chkout_mm"].options[0].selected = true;
				chg_s("mm");
			}else{
				if(form.elements["chkin_dd"].length == selectedDayNum){
					form.elements["chkout_mm"].options[selectedNum].selected = true;
				}else{
					form.elements["chkout_mm"].options[selectedNum-1].selected = true;
					if(form.elements["chkout_dd"].options[form.elements["chkout_dd"].selectedIndex].value <= selectedDayNum){
						form.elements["chkout_dd"].options[selectedNum].selected = true;
					}
				}
			}
			break;
		case "yy":
			alert("yy");
			break;
	}*/
}
//チェックアウト日変更時の動作
function chg_n(){
}
//------------------------------------------------

function search_url() {
	var f = document.myFORM;
	var url = 'http://www.rsv.tokyuhotels.co.jp/cgi-bin/ihonex/stay/search_plan.cgi?hid=r_TI_OBIHI&form=jp&search:hid=r_TI_OBIHI&hotel_decision=1';
	var e = new Array('chkin_yy', 'chkin_mm', 'chkin_dd', 'chkout_yy', 'chkout_mm', 'chkout_dd', 'search:ninzu', 'rooms');
	for (var i in e) {
		url += '&' + e[i] + '=' + f.elements[e[i]].options[f.elements[e[i]].selectedIndex].value;
	}
    url += '&search=1';
	return url;
}