$(function(){

	$("#bookingForm").submit(function(){
		var msg = "";
		if($("#bookName").val() == ""){
			msg += "名前は必須入力です。<br />";
		}

		if($("#bookEmail").val() == ""){
			msg += "名前は必須入力です。<br />";
		}

		if($("#bookEmail").val() == ""){
			msg += "メールアドレスは必須入力です。<br />";
		}

		if($("#bookPhone").val() == ""){
			msg += "電話番号は必須入力です。<br />";
		}
		
		if($("#appointmentdate").val() == ""){
			msg += "希望日は必須入力です。<br />";
		}
		
		if($("#appointmenttime").val() == ""){
			msg += "希望時間は必須入力です。<br />";
		}

		if(msg != ""){
			$("#dialogWindow").dialog({
				'buttons' : {
					'キャンセル': function(){
						$(".ui-dialog-overlay").remove();
						$("[role=dialog]").remove();
					}
				},
				width: 400,
				height: 250,
				modal: true,
				autoOpen: true,
				closeOnEscape: false,
				title: 'エラー',
				open: function(){
					$("#dialogWindow").html(msg);
				},
				overlay: {
					opacity: 0.5,
					background: "black"
				}
			});
			
			return false;
		}
	});
	
	var tabflag = 1;

	$("#reserve").hide();
	$("a[rel=tabs]").click(function(){
		if($(this).attr("id") == "tab1"){
			tabflag = 1;
			$("img",$("#tab1")).attr("src","/img/detailTab_profActive.gif");
			$("img",$("#tab2")).attr("src","/img/detailTab_reserve.gif");
			$("#reserve").hide();
			$("#profile").fadeIn(1000);
		}
		if($(this).attr("id") == "tab2"){
			tabflag = 2;
			$("img",$("#tab1")).attr("src","/img/detailTab_prof.gif");
			$("img",$("#tab2")).attr("src","/img/detailTab_reserveActive.gif");
			$("#profile").hide();
			$("#reserve").fadeIn(1000);
		}
	});

	$("img",$("#tab1")).mouseover(function(){
		if(tabflag == 1){
			$(this).attr("src","/img/detailTab_profActive.gif");
		}else{
			$(this).attr("src","/img/detailTab_prof_on.gif");
		}
	}).mouseout(function(){
		if(tabflag == 1){
			$(this).attr("src","/img/detailTab_profActive.gif");
		}else{
			$(this).attr("src","/img/detailTab_prof.gif");		
		}
	});

	$("img",$("#tab2")).mouseover(function(){
		if(tabflag == 2){
			$(this).attr("src","/img/detailTab_reserveActive.gif");
		}else{
			$(this).attr("src","/img/detailTab_reserve_on.gif");
		}
	}).mouseout(function(){
		if(tabflag == 2){
			$(this).attr("src","/img/detailTab_reserveActive.gif");
		}else{
			$(this).attr("src","/img/detailTab_reserve.gif");		
		}
	});
	

	$("#appointmentdate").datepicker({
		showOn: 'button',
		dateFormat: 'yy-mm-dd',
		yearRange: '2009:2050'
	},$.datepicker.regional['ja']);

	$("#appointmenttime").timepickr({
		trigger: 'click',
		updateLive: false,
		convention: 24,
		format24:"{h:02.d}:{m:02.d}",
		prefix:['午前', '午後'],
		rangeMin: ['00','10','20','30','40','50']
	});

	$("a[rel=girlScroll]").click(function(){
		var targetOffset = $("#"+$(this).attr("rev")).offset().top;
		$('html,body').animate({scrollTop: targetOffset}, 1000);
	});
	
	$("a[rev=window]").click(function(){
		var url = $(this).attr("href");	
		
		window.open(url,"","");
		
		return false;
	});
	

});