// JavaScript Document

// ロールオーバー
function initRollOverImages() {
	var image_cache = new Object();
	$("img.rover,input.rover").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_ro = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_ro;
		$(this).hover(function(){
			this.src = imgsrc_ro;
		},function(){
			this.src = imgsrc;
		});
	});
}

$(document).ready(initRollOverImages);

//メニューアクティブ化
//画面ロード時にimgタグを_onの付いた画像に張り替える
function Menu_active(id){
	var target_img = "img#"+id;
	$(target_img).each(function(i) {
		dot = this.src.lastIndexOf('.');
    	var imgsrc_ro = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		this.src = imgsrc_ro;
		//既に割り当てられているロールオーバー関数を上書き
		$(this).hover(function(){
			this.src = imgsrc_ro;
		},function(){
			this.src = imgsrc_ro;
		});
	});
}

//グローバルメニューアクティブ化
function GlobalNavi(navi){
	var target_img = "#globalNavi li."+navi+" img";
	$(target_img).each(function(i){
		dot = this.src.lastIndexOf('.');
    	var imgsrc_ro = this.src.substr(0, dot) + '_act' + this.src.substr(dot, 4);
		this.src = imgsrc_ro;
		//既に割り当てられているロールオーバー関数を上書き
		$(this).hover(function(){
			this.src = imgsrc_ro;
		},function(){
			this.src = imgsrc_ro;
		});
	});
}

//メニューアクティブ化(テキスﾄ)
//画面ロード時にclass="on"をつける
function localMenu_active(id){
	var target_img = "li#"+id;
	$(target_img).each(function(i){
		$(this).addClass("on");
	});
	var target_img = "dd#"+id;
	$(target_img).each(function(i){
		$(this).addClass("on");
	});
}

//form フォーカス
function InputFocus(){
	$('input[type=text]').addClass('input-text');
	$('input[type=text],textarea').focus(function(){
		$(this).addClass('focus');
	});
	$('input[type=text],textarea').blur(function(){
		if($(this).find('.focus')){
			$(this).removeClass('focus');
		}
	});
}
$(document).ready(InputFocus);

//高さ取得
function Content_Height(name){
	var window = $(window).height();
	var ContentHeight = window-'220';
	$(name).height(ContentHeight);
}

function selectForm(){
	var baseDate = new Date();
	var year = baseDate.getYear();
	var year4 = (year < 2000) ? year+1900 : year;
	var month = baseDate.getMonth()+1;
	var day = baseDate.getDate();
	
	for(index = 0; index < document.myFORM.chkin_mm.length; index++){
		var elementin = document.myFORM.chkin_mm.options[index];
		var elementout = document.myFORM.chkout_mm.options[index];
		if(elementin.value == month){
			document.myFORM.chkin_mm.selectedIndex = index;
			document.myFORM.chkout_mm.selectedIndex = index;
		break;
		}
	}
	for(index = 0; index < document.myFORM.chkin_dd.length; index++){
		var elementin = document.myFORM.chkin_dd.options[index];
		var elementout = document.myFORM.chkout_dd.options[index];
		if(elementin.value == day){
			document.myFORM.chkin_dd.selectedIndex = index;
			document.myFORM.chkout_dd.selectedIndex = index+1;
			if(month == 2 && day == 29){
				document.myFORM.chkout_dd.selectedIndex = 0;
				document.myFORM.chkout_mm.selectedIndex++;
			}if((month == 4 || month == 6 || month == 9 || month == 11) && day == 30){
				document.myFORM.chkout_dd.selectedIndex = 0;
				document.myFORM.chkout_mm.selectedIndex++;
			}if(month == 12 && day == 31){
				document.myFORM.chkout_dd.selectedIndex = 0;
				document.myFORM.chkout_mm.selectedIndex = 0;
			}
		break;
		}
	}
	for(index = 0; index < document.myFORM.chkin_dd.length; index++){
		var elementin = document.myFORM.chkin_yy.options[index];
		var elementout = document.myFORM.chkout_yy.options[index];
		if(elementin.value == year4){
			document.myFORM.chkin_yy.selectedIndex = index;
			document.myFORM.chkout_yy.selectedIndex = index;
			if(month == 12 && day == 31 && year4==2010){
				document.myFORM.chkout_yy.selectedIndex = index+1;
			}
		break;
		}
	}
}
function changeInDate(){
	year = document.myFORM.chkin_yy.value;
	month = document.myFORM.chkin_mm.value;
	day = document.myFORM.chkin_dd.value;

	if(month == 2 && day > 28){
		document.myFORM.chkin_dd.selectedIndex = 27;
	}
	if((month == 4 || month == 6 || month == 9 || month == 11) && day > 30){
		document.myFORM.chkin_dd.selectedIndex = 29;
	}

	month = document.myFORM.chkin_mm.value;
	day = document.myFORM.chkin_dd.value;
	
	document.myFORM.chkout_yy.selectedIndex = document.myFORM.chkin_yy.selectedIndex;
	if(month == 2 && day == 29){
		document.myFORM.chkout_dd.selectedIndex = 0;
		document.myFORM.chkout_mm.selectedIndex++;
		return true;
	}if((month == 4 || month == 6 || month == 9 || month == 11) && day == 30){
		document.myFORM.chkout_dd.selectedIndex = 0;
		document.myFORM.chkout_mm.selectedIndex++;
		return true;
	}if(month == 12 && day == 31){
		document.myFORM.chkout_dd.selectedIndex = 0;
		document.myFORM.chkout_mm.selectedIndex = 0;
		if(year == 2010){
			document.myFORM.chkout_yy.selectedIndex++;
		}
		return true;
	}
	if(day == 31){
		document.myFORM.chkout_dd.selectedIndex = 0;
		document.myFORM.chkout_mm.selectedIndex = document.myFORM.chkin_mm.selectedIndex + 1;
		return true;
	}else{
		document.myFORM.chkout_dd.selectedIndex = document.myFORM.chkin_dd.selectedIndex + 1;
		document.myFORM.chkout_mm.selectedIndex = document.myFORM.chkin_mm.selectedIndex;
		return true;
	}
}
function changeOutDate(){
	month = document.myFORM.chkout_mm.value;
	day = document.myFORM.chkout_dd.value;

	if(month == 2 && day > 28){
		document.myFORM.chkout_dd.selectedIndex = 27;
	}
	if((month == 4 || month == 6 || month == 9 || month == 11) && day > 30){
		document.myFORM.chkout_dd.selectedIndex = 29;
	}
}
