﻿function PageLoad() {
  forminit_fit()
  selectOnChange();
}
function forminit_fit() {
  for(i=document.airfrg.Choice2.length-1;i>=0;i--)
  	document.airfrg.Choice2.options[i] = null;
  for(i=0;i<LINE_FIT.length;i++) {
  	document.airfrg.Choice2.options[i] = LINE_FIT[i];
  }	
  findex = document.airfrg.Choice2.selectedIndex;
  for(i=document.airfrg.Choice3.length-1;i>=0;i--)
  	document.airfrg.Choice3.options[i] = null;
  for(i=0;i<COUNTRY_FIT[findex].length;i++) {
  	document.airfrg.Choice3.options[i] = COUNTRY_FIT[findex][i];	
  }	
  document.airfrg.Choice3.options[0].selected = true;
  findex1 = document.airfrg.Choice3.selectedIndex;
  for(i=document.airfrg.Choice4.length-1;i>=0;i--)
  	document.airfrg.Choice4.options[i] = null;
  for(i=0;i<CITY_FIT[findex][findex1].length;i++) {
  	document.airfrg.Choice4.options[i] = CITY_FIT[findex][findex1][i];
  }	
  document.airfrg.Choice4.options[0].selected = true;
}	
function Choice2Change()
{
  oi=document.airfrg.Choice2.selectedIndex;
  for(i=document.airfrg.Choice3.length-1;i>=0;i--)
    document.airfrg.Choice3.options[i] = null;
  for(cx=0;cx<COUNTRY_FIT[oi].length;cx++) {
    document.airfrg.Choice3.options[cx]= COUNTRY_FIT[oi][cx];
  }
  document.airfrg.Choice3.options[0].selected=true;
  findex1 = document.airfrg.Choice3.selectedIndex;
  for(i=document.airfrg.Choice4.length-1;i>=0;i--)
    document.airfrg.Choice4.options[i] = null;
  for(i=0;i<CITY_FIT[findex][findex1].length;i++) {
    document.airfrg.Choice4.options[i] = CITY_FIT[oi][findex1][i];
  }
  document.airfrg.Choice4.options[0].selected = true;
}
function Choice3Change()
{
  fi=document.airfrg.Choice2.selectedIndex;
  ri=document.airfrg.Choice3.selectedIndex;
  for(i=document.airfrg.Choice4.length-1;i>=0;i--)
    document.airfrg.Choice4.options[i] = null;
  for(cx=0;cx<CITY_FIT[fi][ri].length;cx++) {
    document.airfrg.Choice4.options[cx]= CITY_FIT[fi][ri][cx];
  }
  document.airfrg.Choice4.options[0].selected = true;
}
function airFrgSend()
{
  var urlParams = "";
  var tktType = document.airfrg.tkt_type.options[document.airfrg.tkt_type.selectedIndex].value ;
  var oneWay = document.airfrg.Choice5.options[document.airfrg.Choice5.selectedIndex].value ;
  document.airfrg.city_from.value = document.airfrg.cityTo.options[document.airfrg.cityTo.selectedIndex].value ;
  var dest = document.airfrg.Choice4[document.airfrg.Choice4.selectedIndex].value;
  var country = document.airfrg.Choice3[document.airfrg.Choice3.selectedIndex].value;
  //urlParams = "?arg=1&arg=&arg=&arg=" + fromCity + "&arg=" + dest + "&arg=" + oneWay + "&arg=19000101&arg=0000";
  if (country == '' || dest == ''){
    alert("請選擇目的地國家與城市！");
    return false;
  }else if(tktType =='1' && oneWay =='1'){
    alert("計畫旅行票為來回票!!");
    return false;
  }else{
    document.airfrg.city_to.value = dest;
	document.airfrg.ticket_type.value = oneWay;
	document.airfrg.ticket_class_section.value = tktType;
	SetCookie("agent","airfrg",new Date(today.getTime() +  24 * 60 * 60 * 1000));
    document.forms["airfrg"].submit();
  }
}
function selectOnChange(){
if(document.forms["airfrg"].cityTo.value =="HKG"){
  document.forms["airfrg"].Choice5.value = 'S';
  document.forms["airfrg"].Choice5.disabled=true;
  document.forms["airfrg"].Choice2.value = '203';
  document.forms["airfrg"].Choice2.disabled=true;
  Choice2Change();
  document.forms["airfrg"].Choice3.value = 'CN'
  document.forms["airfrg"].Choice3.disabled=true;
  Choice3Change();
  }else{
  document.forms["airfrg"].Choice5.value = 'R';
  document.forms["airfrg"].Choice5.disabled=false;
  document.forms["airfrg"].Choice2.disabled = false;
  document.forms["airfrg"].Choice2.value=''
  document.forms["airfrg"].Choice3.disabled= false;
  document.forms["airfrg"].Choice3.value=''
  Choice3Change();
	}
}
document.write("                      <table width=\"330\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\"><form name='airfrg' action='/ezec/fit/ec_fit_airline_query.jsp' method='post'>");
document.write("  <input type=\"hidden\" name=\"city_from\" value=\"\"> ");
document.write("  <input type=\"hidden\" name=\"city_to\" value=\"\"> ");
document.write("  <input type=\"hidden\" name=\"ticket_type\" value=\"\"> ");
document.write("  <input type=\"hidden\" name=\"service_type\" value=\"1\"> ");
document.write("  <input type=\"hidden\" name=\"ticket_class_section\" value=\"\"> ");
document.write("  <input type=\"hidden\" name=\"international_cd\" value=\"\"> ");
document.write("                        <tr><td> ");
document.write("                          出發地 ");
document.write("                            <select name=\"cityTo\" onChange='selectOnChange();'>");
document.write("                              <option value=\"TPE\" selected>台北</option>");
document.write("                              <option value=\"KHH\">高雄</option>");
document.write("                              <option value=\"HKG\">香港</option>");
document.write("                            </select>");
document.write("                            </td></tr><tr><td>行程 ");
document.write("                            <select name=\"Choice5\">");
document.write("                              <option value='R' SELECTED>來回</option>");
document.write("                              <option value='S'>單程</option>");
document.write("                            </select>");
document.write("                            　　票種 ");
document.write("                            <select name=\"tkt_type\">");
document.write("                             <option value=2  SELECTED>不限</option>");
document.write("                             <option value=1>個人機票</option>");
document.write("                             <option value=10>學生票</option>");
document.write("                             <option value=4>外勞票</option>");
document.write("                             <option value=5>移民票</option>");
document.write("                             <option value=6>資深公民票</option>");
//document.write("                             <option value=7>計劃旅行票</option>");
document.write("                            </select>");
document.write("                          </td>");
document.write("                        </tr>");
document.write("                        </td></tr><tr><td>");
document.write("目的地 ");
document.write("<select name=\"Choice2\" onChange=\"Choice2Change();\"></select>");
document.write("&nbsp;&nbsp;<select name=\"Choice3\" onChange=\"Choice3Change();\">");
document.write("</select>");
document.write("</td></tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name=\"Choice4\" ></select></td></tr><tr><td align=right><input type=\"button\" name=\"s1\" value=\"搜尋>>\" onclick='airFrgSend();'>");
document.write("                            ");
document.write("                          </td>");
document.write("                        </tr></form>");
document.write("                      </table>");
