﻿function fillOptions(c, a) {
  for(i = c.length-1 ; i>=0 ; i--)
  c.options[i] = null; 
  for(var i = 0; i < a.length; i++) 
  c.options[i] = a[i];
}

//alert(document.htlfrg.sView.value);

function setLines() {
  fillOptions(document.htlfrg.sLine, directory_frg.lines); 
  document.htlfrg.sLine.selectedIndex = 0; 
  setCountries();
}
function setCountries() {
  fillOptions(document.htlfrg.sCountry,directory_frg.countries[document.htlfrg.sLine.selectedIndex]); 
  document.htlfrg.sCountry.selectedIndex = 0; 
  setCity();
}
function setCity() {
  fillOptions(document.htlfrg.sCity,directory_frg.city[document.htlfrg.sLine.selectedIndex][document.htlfrg.sCountry.selectedIndex]); 
  document.htlfrg.sCity.selectedIndex = 0;
//  setView();
}

function setView() {
  fillOptions(document.htlfrg.sView,directory_frg.view[document.htlfrg.sLine.selectedIndex][document.htlfrg.sCountry.selectedIndex][document.htlfrg.sCity.selectedIndex]); 
  document.htlfrg.sView.selectedIndex = 0;
}

function htlFrgSend() {
	if (document.htlfrg.LINE_CD.value == "") {
		alert("您尚未選擇目的地線別");
		document.htlfrg.sLine.focus();
		return ;
	}
	if (document.htlfrg.COUNTRY_CD.value == "") {
		alert("您尚未選擇目的地國家");
		document.htlfrg.sCountry.focus();
		return ;
	}
	if (document.htlfrg.CITY_CD.value == "") {
		alert("您尚未選擇目的地城市");
		document.htlfrg.sCity.focus();
		return ;
	}
	adate=document.htlfrg.sCyear.value+document.htlfrg.sCmonth.value+document.htlfrg.sCday.value;
	bdate=document.htlfrg.sOyear.value+document.htlfrg.sOmonth.value+document.htlfrg.sOday.value;
	if (eval(adate) >= eval(bdate)) {
		alert("退房日需晚於入住日");
		return ;
	}
	
	//2005.11.30 
	document.htlfrg.CHECK_IN.value = adate;
	document.htlfrg.CHECK_OUT.value = bdate;
	document.htlfrg.action = "/ezec/wshotel/step1_ez.jsp";
	document.htlfrg.submit();
	//window.parent.location.href="/ezec/hotel/HTL_frg_hotel_query.jsp?PROD_NM="+"&COUNTRY_CD="+document.htlfrg.COUNTRY_CD.value+"&CITY_CD="+document.htlfrg.CITY_CD.value+"&VIEW_CD="+document.htlfrg.VIEW_CD.value+"&CHECK_IN="+document.htlfrg.sCyear.value+document.htlfrg.sCmonth.value+document.htlfrg.sCday.value+"&CHECK_OUT="+document.htlfrg.sOyear.value+document.htlfrg.sOmonth.value+document.htlfrg.sOday.value;
}
function sLine_onChange() {
	document.htlfrg.LINE_CD.value = document.htlfrg.sLine.value;
//	document.htlfrg.sView.value="";
	document.htlfrg.VIEW_CD.value="";
	setCountries();
}
function sCountry_onChange() {
	document.htlfrg.COUNTRY_CD.value = document.htlfrg.sCountry.value;
	setCity();
}
function sCity_onChange() {
	document.htlfrg.CITY_CD.value = document.htlfrg.sCity.value;
//	setView();
}
function sView_onChange() {
	document.htlfrg.VIEW_CD.value = document.htlfrg.sView.value;
}
var d = new Date()
function maxDays(mm, yyyy){
var mDay;
	if((mm == 3) || (mm == 5) || (mm == 8) || (mm == 10)){
		mDay = 30;
  	}
  	else{
  		mDay = 31
  		if(mm == 1){
   			if (yyyy/4 - parseInt(yyyy/4) != 0){
   				mDay = 28
   			}
		   	else{
   				mDay = 29
  			}
		}
  }
return mDay;
}
var sDay;
function sCmonth_onChange() {
	var x=document.getElementById("sCday");
	sDay= maxDays(document.htlfrg.sCmonth.selectedIndex,  document.htlfrg.sCyear.value);
	x.options.length=sDay;

	for(i=1;i<=10;i++){
	x.options(i-1).text='0'+i;
	x.options(i-1).value='0'+i;
	}
	for(i=10;i<=sDay;i++){
	x.options(i-1).text=i;
	x.options(i-1).value=i;
	}
	var y=document.getElementById("sCmonth");
	var z=document.getElementById("sOmonth");
	z.selectedIndex=y.selectedIndex;
	sOmonth_onChange();
}
var oDay;
function sOmonth_onChange() {
	var x=document.getElementById("sOday")
	oDay= maxDays(document.htlfrg.sOmonth.selectedIndex,  document.htlfrg.sOyear.value);
	x.options.length=oDay;

	for(i=1;i<=10;i++){
	x.options(i-1).text='0'+i;
	x.options(i-1).value='0'+i;
	}
	for(i=10;i<=oDay;i++){
	x.options(i-1).text=i;
	x.options(i-1).value=i;
	}
}
function sCday_onChange(){
	var x=document.getElementById("sOday");
	var y=document.getElementById("sCday");
	var z=document.getElementById("sOmonth");
	//alert(y.selectedIndex);
	//alert(x.length);
	if(y.selectedIndex+2>x.length){
		x.selectedIndex=y.selectedIndex+1-x.length;
		sOmonth_onChange();
		if(z.selectedIndex==11){
			z.selectedIndex=0;
			var yy=document.getElementById("sOyear");
			yy.selectedIndex=yy.selectedIndex+1;
		}else{
			z.selectedIndex=z.selectedIndex+1;
		}
	}else{
		x.selectedIndex=y.selectedIndex+1;
	}
}

function sCyear_onChange(){
	var x=document.getElementById("sCyear");
	var y=document.getElementById("sOyear");
	y.selectedIndex=x.selectedIndex;
}
var iniD;
iniD = d.getDate()+7;
iniM= d.getMonth() + 1;
if (iniD > maxDays(d.getMonth(), d.getFullYear())){
	iniD = iniD-maxDays(d.getMonth(), d.getFullYear());
	iniM = iniM+1;
}

document.write("                      <table width=\"330\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\"><form action='' method='post' name='htlfrg'>");
document.write("                        <tr> ");
document.write("                          <td width=\"350\">目的地 ");
document.write("                            <select name=\"sLine\" onChange=\"sLine_onChange();\">");
document.write("                            </select>");
document.write("                            <select name=\"sCountry\" onChange=\"sCountry_onChange();\">");
document.write("                            </select>");
document.write("                          </td> ");
document.write("                        </tr> ");
document.write("                        <tr> ");
document.write("                          <td width=\"350\">");
document.write("                            <select name=\"sCity\" onChange=\"sCity_onChange();\">");
document.write("                            </select>");
//document.write("                            <select name=\"sView\" onChange=\"sView_onChange();\">");
//document.write("                            </select>");
document.write("<select class=\"g1\" name='searchRoomCd'>");
document.write("<OPTION value='1' >單人房</OPTION>");
document.write("<OPTION value='2' SELECTED>雙人房</OPTION>");
document.write("<OPTION value='3'>三人房</OPTION>");
document.write("</select>");

document.write("                            <input name=\"COUNTRY_CD\" type=\"Hidden\" ><input name=\"LINE_CD\" type=\"hidden\" value=\"\">");
document.write("                            <input name=\"CITY_CD\" type=\"Hidden\">");
document.write("                            <input name=\"VIEW_CD\" type=\"Hidden\">");

//2005.11.30新增
document.write("                            <input name=\"CHECK_IN\" type=\"Hidden\">");
document.write("                            <input name=\"CHECK_OUT\" type=\"Hidden\">");

document.write("						              </td>");
document.write("						            </tr>");
document.write("                        <tr> ");
document.write("                          <td width=\"600\"> ");
document.write("                            <div align=\"right\"> ");
document.write("                              <input type=\"button\" name=\"Submit24\" value=\"搜尋>>\" onClick='htlFrgSend();'>");
document.write("                            </div>");
document.write("                          </td>");
document.write("                        </tr> ");
document.write("                         <tr width=\"350\">入住日 ");
document.write("                            <select name=\"sCyear\" onChange=\"sCyear_onChange();\">");
document.write("                            <OPTION VALUE=");
document.write(d.getFullYear())
document.write(" SELECTED>");
document.write(d.getFullYear())
document.write(" </OPTION>");
document.write("                            <OPTION VALUE=");
document.write(d.getFullYear()+1)
document.write(" >");
document.write(d.getFullYear()+1)
document.write(" </OPTION>");
document.write("                            </select>年");
document.write("                            <select name=\"sCmonth\" onChange=\"sCmonth_onChange();\">");
for(i=1;i<=9;i++){
	if (iniM == i) {
		//	alert(d.getMonth() + 1);
			document.write(" <OPTION VALUE=0");
			document.write(i);
			document.write(" SELECTED>0");
			document.write(i);
			document.write(" </OPTION>");
	}else{
			document.write(" <OPTION VALUE=0");
			document.write(i);
			document.write(" >0");
			document.write(i);
			document.write(" </OPTION>");	
	}
}
for(i=10;i<=12;i++){
	if (iniM == i) {
			//alert(d.getMonth() + 1);
			document.write(" <OPTION VALUE=");
			document.write(i);
			document.write(" SELECTED>");
			document.write(i);
			document.write(" </OPTION>");
	}else{
			document.write(" <OPTION VALUE=");
			document.write(i);
			document.write(" >");
			document.write(i);
			document.write(" </OPTION>");	
	}
}
document.write("                            </select>月");
document.write("                            <select name=\"sCday\" onChange=\"sCday_onChange();\">");
for(dj=1;dj<=9;dj++){
	if (iniD == dj) {
			//alert(dj);
			document.write(" <OPTION VALUE='0");
			document.write(dj);
			document.write("' SELECTED>0");
			document.write(dj);
			document.write(" </OPTION>");
	}else{
			document.write(" <OPTION VALUE='0");
			document.write(dj);
			document.write("' >0");
			document.write(dj);
			document.write(" </OPTION>");	
	}
}
for(dj=10 ; dj <= maxDays(d.getMonth(), d.getFullYear()) ; dj++){
	if (iniD == dj) {
			document.write(" <OPTION VALUE='");
			document.write(dj);
			//alert(dj);
			document.write("' SELECTED>");
			document.write(dj);
			document.write(" </OPTION>");
	}else{
			document.write(" <OPTION VALUE='");
			document.write(dj);
			document.write("' >");
			document.write(dj);
			document.write(" </OPTION>");	
	}
}

document.write("                            </select>日");
document.write("						  </tr>");
document.write("                          <tr width=\"350\">退房日");
document.write("                            <select name=\"sOyear\" >");
document.write("                            <OPTION VALUE=");
document.write(d.getFullYear())
document.write(" SELECTED>");
document.write(d.getFullYear())
document.write(" </OPTION>");
document.write("                            <OPTION VALUE=");
document.write(d.getFullYear()+1)
document.write(" >");
document.write(d.getFullYear()+1)
document.write(" </OPTION>");
document.write("                            <OPTION VALUE=");
document.write(d.getFullYear()+2)
document.write(" >");
document.write(d.getFullYear()+2)
document.write(" </OPTION>");
document.write("                            </select>年");
document.write("                            <select name=\"sOmonth\" onChange=\"sOmonth_onChange();\">");
for(j=1;j<=9;j++){
	if (iniM == j) {
			//alert(j);
			document.write(" <OPTION VALUE=0");
			document.write(j);
			document.write(" SELECTED>0");
			document.write(j);
			document.write(" </OPTION>");
	}else{
			document.write(" <OPTION VALUE=0");
			document.write(j);
			document.write(" >0");
			document.write(j);
			document.write(" </OPTION>");	
	}
}
for(j=10;j<=12;j++){
	if (iniM == j) {
			//alert(j);
			document.write(" <OPTION VALUE=");
			document.write(j);
			document.write(" SELECTED>");
			document.write(j);
			document.write(" </OPTION>");
	}else{
			document.write(" <OPTION VALUE=");
			document.write(j);
			document.write(" >");
			document.write(j);
			document.write(" </OPTION>");	
	}
}
document.write("                            </select>月");
//document.write("                            <select name=\"sOday\" onChange=\"sOday_onChange();\">");
document.write("                            <select name=\"sOday\">");
for(dj=1;dj<=9;dj++){
	if ((iniD+1) == dj) {
			//alert(dj);
			document.write(" <OPTION VALUE='0");
			document.write(dj);
			document.write("' SELECTED>0");
			document.write(dj);
			document.write(" </OPTION>");
	}else{
			document.write(" <OPTION VALUE='0");
			document.write(dj);
			document.write("' >0");
			document.write(dj);
			document.write(" </OPTION>");	
	}
}
for(dj=10;dj<=31;dj++){
	if ((iniD+1) == dj) {
			//alert(dj);
			document.write(" <OPTION VALUE='");
			document.write(dj);
			document.write("' SELECTED>");
			document.write(dj);
			document.write(" </OPTION>");
	}else{
			document.write(" <OPTION VALUE='");
			document.write(dj);
			document.write("' >");
			document.write(dj);
			document.write(" </OPTION>");	
	}
}
document.write("                            </select>日");
document.write("						  </tr>");
document.write("                        </form>");
document.write("                      </table>");
