// JavaScript Document

function Inint_AJAX() {

	   try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE

	   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE

	   try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript

	   alert("XMLHttpRequest not supported");

	   return null;

}

	

function dateDoChange(src, val, from, effectdate, yearSelected) {

	var month = val;

	var dd;

	//var month_arr = new Array("April", "June", "September", "November");

	var month_arr = new Array("4", "6", "9", "11");



    //if(month=="February"){

	if(month=="2"){

	   dd = check_feb(month,from);

	}else{

	   // check only that month have 30 days

	   for($i=0;$i<=3;$i++)	{

	      if(month==month_arr[$i])

		  {

			  dd = 30;

			  break;

		  }



		  else

		      dd = 31;

	   }

	}

	  

     var req = Inint_AJAX();

     req.onreadystatechange = function () { 

          if (req.readyState==4) {

               if (req.status==200) {

                    document.getElementById(src).innerHTML=req.responseText; 

               } 

          }

     };

     req.open("GET", "apply_form_condition.php?dd="+dd+"&from="+from+"&effectdate="+effectdate+"&Smonth="+month+"&chooseyear="+yearSelected); 

     req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=tis-620"); 

     req.send(null); 

}



function monthDoChange(val, src, from, effectdate) {



     var req = Inint_AJAX();

     req.onreadystatechange = function () { 

          if (req.readyState==4) {

               if (req.status==200) {

                    document.getElementById(src).innerHTML=req.responseText; 

               } 

          }

     };

     req.open("GET", "apply_form_condition.php?selected="+val+"&from="+from+"&effectdate="+effectdate); 

     req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=tis-620"); 

     req.send(null); 

}



function check_feb(id,from)

{   

    var month = id;

	if(month=="2")

	{

		if(from == "chkin_a")  year = parseInt(document.frm_1.dr_chkin_yyyy_a.value);	

		if(from == "chkout_a") year = parseInt(document.frm_1.dr_chkout_yyyy_a.value);

		if(from == "chkin_b")  year = parseInt(document.frm_1.dr_chkin_yyyy_b.value);	

		if(from == "chkout_b") year = parseInt(document.frm_1.dr_chkout_yyyy_b.value);

		

		check_year = (year - 2004)%4;

		if(check_year == 0)

		   feb = 29;

		else

		   feb = 28;

	}

	return feb;

}





function checkform(theform){ 





      if (theform.dr_chkin_yyyy_a.value == "any" || theform.dr_chkin_mm_a.value == "any" || theform.dr_chkin_dd_a.value == "any")

		{ alert("チェックイン日を選択または記入して下さい。");

		  document.getElementById('err_chk_in_a').innerHTML = "** チェックイン日を選択または記入して下さい。";

		  theform.dr_chkin_yyyy_a.focus();

		  return(false);

		} 

	if (theform.dr_chkout_yyyy_a.value == "any" || theform.dr_chkout_mm_a.value == "any" || theform.dr_chkout_dd_a.value == "any")

		{ alert("チェックアウト日を選択または記入して下さい。");

		  document.getElementById('err_chk_out_a').innerHTML = "** チェックアウト日を選択または記入して下さい。";

		  theform.dr_chkout_yyyy_a.focus();

		  return(false);

		} 

	

	// chk conflic date ----------------------

	    var chkin_d  = theform.dr_chkin_dd_a.value+"/"+theform.dr_chkin_mm_a.value+"/"+theform.dr_chkin_yyyy_a.value;

		var chkout_d = theform.dr_chkout_dd_a.value+"/"+theform.dr_chkout_mm_a.value+"/"+theform.dr_chkout_yyyy_a.value;

		

	   message = "復路日が往路日よりも早く設定されています。日付を指定し直して下さい。";



		var check = check_conflic_date(chkin_d, chkout_d);	

		if(check != true){

		   alert(message);

		   document.getElementById('err_chk_out_a').innerHTML = message;

		   theform.dr_chkout_yyyy_a.focus();

		   return(false);

		}	

	

	

	 // second choice -----------------------//

	   if (theform.dr_chkin_yyyy_b.value != "any" && theform.dr_chkin_mm_b.value != "any" && theform.dr_chkin_dd_b.value != "any" && theform.dr_chkout_yyyy_b.value != "any" && theform.dr_chkout_mm_b.value != "any" && theform.dr_chkout_dd_b.value != "any")

		{ 

			var chkin_e  = theform.dr_chkin_dd_b.value+"/"+theform.dr_chkin_mm_b.value+"/"+theform.dr_chkin_yyyy_b.value;

			var chkout_e = theform.dr_chkout_dd_b.value+"/"+theform.dr_chkout_mm_b.value+"/"+theform.dr_chkout_yyyy_b.value;

					

			var check2 = check_conflic_date(chkin_e, chkout_e);	

			if(check2 != true){

			   alert(message);

			   document.getElementById('err_chk_out_b').innerHTML = message;

			   theform.dr_chkout_yyyy_b.focus();

			   return(false);

			}	

		}

		

		

	//--------------------------------------

	

		

/*	if(theform.dr_adult_amt.value == "any" && theform.dr_child_amt.value == "any" && theform.dr_infant_amt.value == "any")

		{ alert("ご宿泊予定人数");

		  document.getElementById('err_noguest').innerHTML = "** ご宿泊予定人数";

		  theform.dr_adult_amt.focus();

		  return(false);

		}  */

    if(theform.dr_room_type.value == "any")

		{ alert("ルームタイプを選択または記入して下さい。");

		  document.getElementById('err_room_type').innerHTML = "** ルームタイプを選択または記入して下さい。";

		  theform.dr_room_type.focus();

		  return(false);

		}

	

/*	if(theform.txt_lastname_1.value == "")

	  { alert("お名前ローマ字・姓を選択または記入して下さい。");

		document.getElementById('err_quest').innerHTML = "** お名前ローマ字・姓を選択または記入して下さい。";

		theform.txt_lastname_1.focus();

		return(false);

	 }

	 if(theform.txt_first_1.value == "")

	  { alert("名を選択または記入して下さい。");

		document.getElementById('err_quest').innerHTML = "** 名を選択または記入して下さい。";

		theform.txt_first_1.focus();

		return(false);

	 }

	 if(theform.dr_sex_1.value == "any")

	  { alert("性別を選択または記入して下さい。");

		document.getElementById('err_quest').innerHTML = "** 性別を選択または記入して下さい。";

		theform.dr_sex_1.focus();

		return(false);

	 }

	 if(theform.dr_age_1.value == "any")

	  { alert("年齢を選択または記入して下さい。");

		document.getElementById('err_quest').innerHTML = "** 年齢を選択または記入して下さい。";

		theform.dr_age_1.focus();

		return(false);

	 }

	 if(theform.dr_nationality_1.value == "any")

	  { alert("国籍を選択または記入して下さい。");

		document.getElementById('err_quest').innerHTML = "** 国籍を選択または記入して下さい。";

		theform.dr_nationality_1.focus();

		return(false);

	 }*/

	if(theform.txt_Lname_kanji.value == "")

	  { alert("氏名（漢字） : 姓を選択または記入して下さい。");

		document.getElementById('err_contactPerson').innerHTML = "** 氏名（漢字） : 姓を選択または記入して下さい。";

		theform.txt_Lname_kanji.focus();

		return(false);

	 }

	 if(theform.txt_Fname_kanji.value == "")

	  { alert("氏名（漢字） : 名を選択または記入して下さい。");

		document.getElementById('err_contactPerson').innerHTML = "** 氏名（漢字） : 名を選択または記入して下さい。";

		theform.txt_Fname_kanji.focus();

		return(false);

	 }

	 if(theform.dr_sex.value == "any")

	  { alert("性別を選択または記入して下さい。");

		document.getElementById('err_contactPerson').innerHTML = "** 性別を選択または記入して下さい。";

		theform.dr_sex.focus();

		return(false);

	 }

	 if(theform.dr_age.value == "any")

	  { alert("年齢を選択または記入して下さい。");

		document.getElementById('err_contactPerson').innerHTML = "** 年齢を選択または記入して下さい。";

		theform.dr_age.focus();

		return(false);

	 }

/*	 if(theform.txt_Lname_kana.value == "")

	  { alert("氏名（全角カナ） : セイを選択または記入して下さい。");

		document.getElementById('err_LastNamekana').innerHTML = "** 氏名（全角カナ） : セイを選択または記入して下さい。";

		theform.txt_Lname_kana.focus();

		return(false);

	 }

	 if(theform.txt_Fname_kana.value == "")

	  { alert("氏名（全角カナ） : メイを選択または記入して下さい。");

		document.getElementById('err_FirstNameKana').innerHTML = "** 氏名（全角カナ） : メイを選択または記入して下さい。";

		theform.txt_Fname_kana.focus();

		return(false);

	 }*/

	 if(theform.dr_live.value == "any" && theform.txt_live_other.value == "")

	  { alert("お住まいの国を選択または記入して下さい。");

		document.getElementById('err_live').innerHTML = "** お住まいの国を選択または記入して下さい。";

		theform.dr_live.focus();

		return(false);

	 }

/*	 if(theform.txt_cellphone.value == "" && theform.txt_mobile.value == "")

	  { alert("電話番号を選択または記入して下さい。");

		document.getElementById('err_contact_no').innerHTML = "** 電話番号を選択または記入して下さい。";

		theform.txt_cellphone.focus();

		return(false);

	 }*/

	

    if(theform.txt_mail1.value == "")

	  { alert("メールアドレスを選択または記入して下さい。");

		document.getElementById('err_mail1').innerHTML = "** メールアドレスを選択または記入して下さい。";

		theform.txt_mail1.focus();

		return(false);

	 }

	 if(theform.txt_mail2.value == "")

	  { alert("メールアドレスを選択または記入して下さい。");

		document.getElementById('err_mail1').innerHTML = "** メールアドレスを選択または記入して下さい。";

		theform.txt_mail2.focus();

		return(false);

	 }

	 if(theform.txt_mail3.value == "")

	 {

		alert("メールアドレス（確認用）を選択または記入して下さい。");

		document.getElementById('err_mailConfirm').innerHTML = "** メールアドレス（確認用）を選択または記入して下さい。";

		theform.txt_mail3.focus();

		return(false);

	 }

	 if(theform.txt_mail4.value == "")

	 {

		alert("メールアドレス（確認用）を選択または記入して下さい。");

		document.getElementById('err_mailConfirm').innerHTML = "** メールアドレス（確認用）を選択または記入して下さい。";

		theform.txt_mail4.focus();

		return(false);

	 }

	 if(theform.txt_mail1.value != "" && theform.txt_mail2.value != "")

	  { 

		   var src = theform.txt_mail1.value + "@" + theform.txt_mail2.value;

		   var emailFilter=/^.+@.+\..{2,3}$/;

		   if (!(emailFilter.test(src))) { 

				alert ("Please Fill in the right e-mail format");

				document.getElementById('err_mail1').innerHTML = "** Please Fill in the right e-mail format";

				theform.txt_mail2.focus();

				return(false);

			}

	 }

	 if(theform.txt_mail1.value != "" && theform.txt_mail2.value != "")

	  { 

		if(theform.txt_mail3.value != "" && theform.txt_mail4.value != ""){

			var src  = theform.txt_mail1.value + "@" + theform.txt_mail2.value;

			var src2 = theform.txt_mail3.value + "@" + theform.txt_mail4.value;

			

			if(src != src2){

			    alert ("上記と同じメールアドレスを記入して下さい。");

				document.getElementById('err_mailConfirm').innerHTML = "** 上記と同じメールアドレスを記入して下さい。";

				theform.txt_mail3.focus();

				return(false);

			}

		 }

	  }

	 if(theform.chk_ok.checked == false ){

		alert("「ご予約手順・キャンセルについて」をお読みになったらチェックして下さい。");

		document.getElementById('err_submit').innerHTML = "** 「ご予約手順・キャンセルについて」をお読みになったらチェックして下さい。";

		theform.chk_ok.focus();

		return(false);

	 }

	 

}



function dateDiff(where){

  if(where == "first")

   {    

        oy = document.frm_1.dr_chkout_yyyy_a.value;

		om = document.frm_1.dr_chkout_mm_a.value;

		od = document.frm_1.dr_chkout_dd_a.value;

		

		iy = document.frm_1.dr_chkin_yyyy_a.value;

		im = document.frm_1.dr_chkin_mm_a.value;

		id = document.frm_1.dr_chkin_dd_a.value;

   }

  if(where == "second"){

        oy = document.frm_1.dr_chkout_yyyy_b.value;

		om = document.frm_1.dr_chkout_mm_b.value;

		od = document.frm_1.dr_chkout_dd_b.value;

		

		iy = document.frm_1.dr_chkin_yyyy_b.value;

		im = document.frm_1.dr_chkin_mm_b.value;

		id = document.frm_1.dr_chkin_dd_b.value;

  }

       

		if(oy != "any" && om != "any" && od != "any" && iy != "any" && im != "any" && id != "any")

		{

			

			if(om < 10 ) 

			   out_month = "0"+om;

			else

			   out_month = om;

			   

			if(od < 10 )

			   out_day  = "0"+od;

			else

			   out_day  = od;

			   

			

			if(im < 10 ) 

			   in_month = "0"+im;

			else

			   in_month = im;

			   

			if(id < 10 )

			   in_day  = "0"+id;

			else

			   in_day  = id;

			 

			

			var chkOut = out_month+"/"+out_day+"/"+oy;

			var chkIn  = in_month+"/"+in_day+"/"+iy;

			

			days = calDate(chkOut, chkIn);

			

			 if(where == "first")  document.getElementById('numStay').innerHTML  = "("+days+"泊）";

			 if(where == "second") document.getElementById('numStay2').innerHTML = "("+days+"泊）";																	   

		}

		

		

 	 function calDate(chkOut, chkIn)

	 {

		date1 = new Date();

		date2 = new Date();

		diff  = new Date();

		

		  date1temp = new Date(chkOut + " " + "00:00:00");

		  date1.setTime(date1temp.getTime());



		  date2temp = new Date(chkIn + " " + "00:00:00");

		  date2.setTime(date2temp.getTime());



	

		diff.setTime(Math.abs(date1.getTime() - date2.getTime()));

		timediff = diff.getTime();

		

		days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 

		timediff -= days * (1000 * 60 * 60 * 24);

		

		return days;

     }

	

}



function call_chk_future_date(where){

	if(where=="chkin_a"){

		if((document.frm_1.dr_chkin_dd_a.value != "any") && (document.frm_1.dr_chkin_mm_a.value != "any") && (document.frm_1.dr_chkin_yyyy_a.value != "any")){

			var txtdepart = document.frm_1.dr_chkin_dd_a.value+"/"+document.frm_1.dr_chkin_mm_a.value+"/"+document.frm_1.dr_chkin_yyyy_a.value;

			var check_future = chk_future_with_currdate(txtdepart);	

				if(check_future != true){

				   alert("Please Specify future date");

				   document.getElementById("err_chk_in_a").innerHTML="** Please Specify future date";

				   document.frm_1.dr_chkin_yyyy_a.focus();

				   return(false);

				}

				if(check_future == true) document.getElementById("err_chk_in_a").innerHTML= "";

		}	

	}

	if(where=="chkout_a"){

		if((document.frm_1.dr_chkout_dd_a.value != "any") && (document.frm_1.dr_chkout_mm_a.value != "any") && (document.frm_1.dr_chkout_yyyy_a.value != "any")){

			var txtdepart = document.frm_1.dr_chkout_dd_a.value+"/"+document.frm_1.dr_chkout_mm_a.value+"/"+document.frm_1.dr_chkout_yyyy_a.value;

			var check_future = chk_future_with_currdate(txtdepart);	

				if(check_future != true){

				   alert("Please Specify future date");

				   document.getElementById("err_chk_out_a").innerHTML="** Please Specify future date";

				   document.frm_1.dr_chkout_yyyy_a.focus();

				   return(false);

				}

				if(check_future == true) document.getElementById("err_chk_out_a").innerHTML= "";

		}	

	}

	

	if(where=="chkin_b"){

		if((document.frm_1.dr_chkin_dd_b.value != "any") && (document.frm_1.dr_chkin_mm_b.value != "any") && (document.frm_1.dr_chkin_yyyy_b.value != "any")){

			var txtdepart = document.frm_1.dr_chkin_dd_b.value+"/"+document.frm_1.dr_chkin_mm_b.value+"/"+document.frm_1.dr_chkin_yyyy_b.value;

			var check_future = chk_future_with_currdate(txtdepart);	

				if(check_future != true){

				   alert("Please Specify future date");

				   document.getElementById("err_chk_in_b").innerHTML="** Please Specify future date";

				   document.frm_1.dr_chkin_yyyy_b.focus();

				   return(false);

				}

				if(check_future == true) document.getElementById("err_chk_in_b").innerHTML= "";

		}	

	}

	if(where=="chkout_b"){

		if((document.frm_1.dr_chkout_dd_b.value != "any") && (document.frm_1.dr_chkout_mm_b.value != "any") && (document.frm_1.dr_chkout_yyyy_b.value != "any")){

			var txtdepart = document.frm_1.dr_chkout_dd_b.value+"/"+document.frm_1.dr_chkout_mm_b.value+"/"+document.frm_1.dr_chkout_yyyy_b.value;

			var check_future = chk_future_with_currdate(txtdepart);	

				if(check_future != true){

				   alert("Please Specify future date");

				   document.getElementById("err_chk_out_b").innerHTML="** Please Specify future date";

				   document.frm_1.dr_chkout_yyyy_b.focus();

				   return(false);

				}

				if(check_future == true) document.getElementById("err_chk_out_b").innerHTML= "";

		}	

	}



}



function chk_future_with_currdate(dd){

	   

	    var chk_date = dd;

	    var date_for_chk_arr = chk_date.split("/");

	   

		var current_date = new Date();

		var cmonth = current_date.getMonth() + 1;

		var cday   = current_date.getDate();

		var cyear  = current_date.getFullYear();

		

		 var month_arr = new Array("1","2","3","4","5","6","7","8","9","10","11","12");

		 for(i=0;i<month_arr.length;i++)

		 {

			if(date_for_chk_arr[1] == month_arr[i]) month_chk = i+1;

		 }

		 

		 if(date_for_chk_arr[2] < cyear)

		    return false;

		else if(date_for_chk_arr[2] > cyear)

		    return true;

		 else {

		    if(month_chk < cmonth)

			   return false;

			else if(month_chk > cmonth)

			   return true;

			else{

			     if(date_for_chk_arr[0] <= cday )

				    return false;

				 else

				    return true;

			}

		}

		

	}

	

function check_conflic_date(depart_d, return_d)

{  

      // for check future date

     var date_a = depart_d;

	 var date_b = return_d;

	 var date_a_arr, date_b_arr, message;

	 

	 date_depart_arr = date_a.split("/");

	 date_return_arr = date_b.split("/");

	 

	 //alert(depart_d +" , "+return_d);

	 

	 //var month_arr = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

	 var month_arr = new Array("1","2","3","4","5","6","7","8","9","10","11","12");

	 for(i=0;i<month_arr.length;i++)

	 {

	    if(date_return_arr[1] == month_arr[i]) month_return = i;

		if(date_depart_arr[1] == month_arr[i]) month_depart = i;

	 }

	 	 

	if(date_return_arr[2] < date_depart_arr[2])

	    return(false);

	else if(date_return_arr[2] > date_depart_arr[2])

	    return(true);

	else{

	    if(parseInt(month_return) < parseInt(month_depart))	

		    return(false);

		else if(parseInt(month_return) > parseInt(month_depart))

		    return(true);

		else{

			if(parseInt(date_return_arr[0]) <= parseInt(date_depart_arr[0]))

			     return(false);

			else

			     return(true);

		}

	}

}





function frm_sort_submit(val){

	

	  if(val=="reccommend"){

		   var id = document.frm_sort_2.txt_reccommend.value;

		   

		   if(id==1)  

		     document.frm_sort_2.txt_reccommend.value = 2;

		   else if(id==2)  

		     document.frm_sort_2.txt_reccommend.value = 1;

		   else

		     document.frm_sort_2.txt_reccommend.value = 1;

		   

		  

		   document.frm_sort_2.txt_price.value    = "-";

		   document.frm_sort_2.txt_grade.value    = "-";

		   document.frm_sort_2.txt_japanese.value = "-";

	  }

	  

	  if(val=="grade"){

		   var id = document.frm_sort_2.txt_grade.value;

		   

		   if(id==1) 

		      document.frm_sort_2.txt_grade.value = 2;

		   else if(id==2) 

		      document.frm_sort_2.txt_grade.value = 1;

		   else

		      document.frm_sort_2.txt_grade.value = 1;

		   

		   document.frm_sort_2.txt_reccommend.value = "-";

		   document.frm_sort_2.txt_price.value      = "-";		   

		   document.frm_sort_2.txt_japanese.value   = "-";

	  }

	  

	  if(val=="japanese"){

		   var id = document.frm_sort_2.txt_japanese.value;

		   

		   if(id==1)  document.frm_sort_2.txt_japanese.value = 2;

		   if(id!=1)  document.frm_sort_2.txt_japanese.value = 1;

		   if(id=="") document.frm_sort_2.txt_japanese.value = 1;

		   

		   document.frm_sort_2.txt_reccommend.value = "-";

		   document.frm_sort_2.txt_price.value      = "-";		   

		   document.frm_sort_2.txt_grade.value      = "-";

	  }

	  

	  if(val=="price"){

		   var id = document.frm_sort_2.txt_price.value;

		   

		   if(id==1)  document.frm_sort_2.txt_price.value = 2;

		   if(id!=1)  document.frm_sort_2.txt_price.value = 1;

		   if(id=="") document.frm_sort_2.txt_price.value = 1;

		   

		   document.frm_sort_2.txt_reccommend.value = "-";

		   document.frm_sort_2.txt_japanese.value      = "-";		   

		   document.frm_sort_2.txt_grade.value      = "-";

	  }

	  

	   

		  

	   document.frm_sort_2.submit();

}

	



function hotel_searching()

{

  if((document.frmadvanced.dr_search_area.value=="any") || (document.frmadvanced.dr_search_area.value==""))

	{

		alert(" Please Choose Area ");

		document.frmadvanced.dr_search_area.value = "";

		document.frmadvanced.dr_search_area.focus();

		return(false); 

	}else

		document.frmadvanced.submit();

	

}



function setValue(val)

{     

      document.frmadvanced.dr_search_area.value = val;

	  document.frmadvanced.dr_search_zone_jp.value = "any";

	  document.frmadvanced.submit();

}



function hotel_list_floating_box(src) {

     var req = Inint_AJAX();

     req.onreadystatechange = function () { 

          if (req.readyState==4) {

               if (req.status==200) {

                    document.getElementById(src).innerHTML=req.responseText; 

               } 

          }

     };

	 

	  hcate = document.frmadvanced.dr_category.value;

	  harea = document.frmadvanced.dr_search_area.value;

	  hzone = document.frmadvanced.dr_search_zone_jp.value;

	  hrank = document.frmadvanced.dr_rank.value;

	  hpriceStart = document.frmadvanced.dr_price_start.value;

	  hpriceEnd   = document.frmadvanced.dr_price_end.value;

	 

     req.open("GET", "1a_condition.php?hcate="+hcate+"&harea="+harea+"&hzone="+hzone+"&hrank="+hrank+"&hpriceStart="+hpriceStart+"&hpriceEnd="+hpriceEnd); 

     req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=tis-620"); 

     req.send(null); 

}



