arr_no_page_regions=[];
arr_regions=[];

function getBlankPrefNode(str_type,int_form_num){
  if (typeof int_form_num == "undefined"){
    var int_form_num='';
  }
  var obj_blank_pref_node=document.createElement("select");
  obj_blank_pref_node.setAttribute("id","hoteljp_" + str_type + "_pref_en" + int_form_num);
  obj_blank_pref_node.setAttribute("name","pref_en");
  var tmp_opt_node=document.createElement("option");
  tmp_opt_node.setAttribute("value","");
  var tmp_txt_node=document.createTextNode("都道府県選択");
  tmp_opt_node.appendChild(tmp_txt_node);
  obj_blank_pref_node.appendChild(tmp_opt_node);
  
  return obj_blank_pref_node;
}

function getBlankMidAreaNode(str_type,int_form_num){
  if (typeof int_form_num == "undefined"){
    var int_form_num='';
  }
  var obj_blank_mid_area_node=document.createElement("select");
  obj_blank_mid_area_node.setAttribute("id","hoteljp_" + str_type + "_mid_area_en" + int_form_num);
  obj_blank_mid_area_node.setAttribute("name","mid_area_en");
  var tmp_opt_node=document.createElement("option");
  tmp_opt_node.setAttribute("value","");
  var tmp_txt_node=document.createTextNode("エリア選択");
  tmp_opt_node.appendChild(tmp_txt_node);
  obj_blank_mid_area_node.appendChild(tmp_opt_node);
  return obj_blank_mid_area_node;
}

function getBlankSmallAreaNode(str_type,int_form_num){
  if (typeof int_form_num == "undefined"){
    var int_form_num='';
  }
  var obj_blank_small_area_node=document.createElement("select");
  obj_blank_small_area_node.setAttribute("id","hoteljp_" + str_type + "_small_area_en" + int_form_num);
  obj_blank_small_area_node.setAttribute("name","small_area_en");
  var tmp_opt_node=document.createElement("option");
  tmp_opt_node.setAttribute("value","");
  var tmp_txt_node=document.createTextNode("詳細エリア選択");
  tmp_opt_node.appendChild(tmp_txt_node);
  obj_blank_small_area_node.appendChild(tmp_opt_node);
  
  return obj_blank_small_area_node;
}

//イベントリスナの設定
function setListener(observer, eventType, callFunc){
  if (!observer){
    return false;
  }
  else if(observer.attachEvent){
    observer.attachEvent('on' + eventType, callFunc);
  }else if(observer.addEventListener){
    observer.addEventListener(eventType, callFunc, false);
  }else {
    alert('No support on Your Browser');
    return false;
  }
}




//エスケープ
function htmlEscape(_strTarget){
  var div = document.createElement('div');
  var text =  document.createTextNode('');
  div.appendChild(text);
  text.data = _strTarget;
  return div.innerHTML;
}

function getHoteljpAreaData(res_data,res_data2,res_data3,res_data4,res_data5){
  arr_regions=res_data;
  arr_no_page_regions=res_data2;
  has_prefs=res_data3;
  has_mid_areas=res_data4;
  has_small_areas=res_data5;
}

function makePlanForm(bol_focus,int_form_num){
  if (typeof int_form_num == "undefined"){
    var int_form_num='';
  }


  makeDateForm("stay_date",int_form_num,"hoteljp_plan_date" + int_form_num);
  
  var sel_node=document.createElement("select");
  sel_node.setAttribute("id","hoteljp_plan_region_en"+ int_form_num);
  sel_node.setAttribute("name","region_en");

  var opt_node=document.createElement("option");
  opt_node.setAttribute("value","");
  var txt_node=document.createTextNode("地方選択");
  opt_node.appendChild(txt_node);
  sel_node.appendChild(opt_node);

  for (var int_i=0;int_i<arr_regions.length;int_i++){
    var opt_node=document.createElement("option");
    opt_node.setAttribute("value",htmlEscape(arr_regions[int_i]["region_en"]));
    var txt_node=document.createTextNode(htmlEscape(arr_regions[int_i]["region_jp"]));
    opt_node.appendChild(txt_node);
    sel_node.appendChild(opt_node);
  }

  $("hoteljp_plan_region" + int_form_num).appendChild(sel_node);
  $("hoteljp_plan_pref"+ int_form_num).appendChild(document.createTextNode("　>　"));
  $("hoteljp_plan_pref"+ int_form_num).appendChild(getBlankPrefNode("plan",int_form_num));
  $("hoteljp_plan_mid_area"+ int_form_num).appendChild(document.createTextNode("　>　"));
  $("hoteljp_plan_mid_area" + int_form_num).appendChild(getBlankMidAreaNode("plan",int_form_num));  
  removeAllChildNodes("hoteljp_plan_small_area" + int_form_num);
  $("hoteljp_plan_region_en" + int_form_num).value="";
  
  var hid_node=document.createElement("input");
  hid_node.setAttribute("type","hidden");
  hid_node.setAttribute("name","charge_min");
  hid_node.setAttribute("value",1);
  $("hoteljp_plan_search_form"+ int_form_num).appendChild(hid_node);
  
  hid_node=document.createElement("input");
  hid_node.setAttribute("type","hidden");
  hid_node.setAttribute("name","charge_max");
  hid_node.setAttribute("value",0);
  $("hoteljp_plan_search_form" + int_form_num).appendChild(hid_node);

  setListener($("hoteljp_plan_region_en" + int_form_num),"change",function(){onChangeRegion(int_form_num);} );


  
  makeIntegerOption(10,"hoteljp_plan_term_form" + int_form_num,"term",1,"hoteljp_plan_term"+ int_form_num);
  makeIntegerOption(10,"hoteljp_plan_heads_form" + int_form_num,"heads",1,"hoteljp_plan_heads"+ int_form_num);
  makeIntegerOption(10,"hoteljp_plan_rooms_form" + int_form_num,"rooms",1,"hoteljp_plan_rooms"+ int_form_num);
  if(typeof bgcolor != 'undefined'){
    setListener($("hoteljp_plan_term_form" + int_form_num),"change",function(){clearPlanBackGround(int_form_num);$("hoteljp_plan_heads_form"+int_form_num).style.backgroundColor=bgcolor;} );
    setListener($("hoteljp_plan_heads_form" + int_form_num),"change",function(){clearPlanBackGround(int_form_num);$("hoteljp_plan_rooms_form"+int_form_num).style.backgroundColor=bgcolor;} );
    setListener($("hoteljp_plan_rooms_form" + int_form_num),"change",function(){clearPlanBackGround(int_form_num);} );
  }

  if (bol_focus){
    $("hoteljp_plan_region_en" + int_form_num).focus();
    if (typeof bgcolor != 'undefined'){
      $("hoteljp_plan_region_en" + int_form_num).style.backgroundColor=bgcolor;
    }
  }
}


function clearPlanBackGround(int_form_num){
  if (typeof int_form_num == "undefined"){
    var int_form_num='';
  }
  var nodes=$("hoteljp_plan_search_form" + int_form_num).getElementsByTagName("select");
  for (i=0;i<nodes.length;i++){
    nodes[i].style.backgroundColor='';
  }
}


function onChangeRegion(int_form_num){
  if (typeof int_form_num == 'undefined'){
   var  int_form_num='';
  }


  var str_selected_region=$("hoteljp_plan_region_en" + int_form_num).value;
  var int_selected_region_id;

  removeAllChildNodes("hoteljp_plan_mid_area"+ int_form_num);  
  removeAllChildNodes("hoteljp_plan_small_area"+ int_form_num);
  removeAllChildNodes("hoteljp_plan_pref"+ int_form_num);
  
  $("hoteljp_plan_mid_area"+ int_form_num).appendChild(document.createTextNode("　>　"));
  $("hoteljp_plan_mid_area"+ int_form_num).appendChild(getBlankMidAreaNode("plan",int_form_num));

  
  if (str_selected_region==''){
    if(typeof bgcolor != 'undefined'){
      clearPlanBackGround(int_form_num);
      $("hoteljp_plan_region_en"+ int_form_num).style.backgroundColor=bgcolor;
    }
    $("hoteljp_plan_pref"+ int_form_num).appendChild(document.createTextNode("　>　"));
    $("hoteljp_plan_pref"+ int_form_num).appendChild(getBlankPrefNode("plan",int_form_num));
    return;
  }

  int_selected_region_id=getRegionId(str_selected_region)
  if (typeof has_prefs[int_selected_region_id] != 'undefined'){
    if (has_prefs[int_selected_region_id].length==1){
      var hid_node=document.createElement("input");
      hid_node.setAttribute("type","hidden");
      hid_node.setAttribute("id","hoteljp_plan_pref_en"+ int_form_num);
      hid_node.setAttribute("name","pref_en");
      hid_node.setAttribute("value",has_prefs[int_selected_region_id][0]["pref_en"]);

      var txt_pref_node=document.createTextNode(htmlEscape(has_prefs[int_selected_region_id][0]["pref_jp"]));
      var str_div="　>　";
      for(var i=0;i<arr_no_page_regions.length;i++){
        if(arr_no_page_regions[i]==str_selected_region){
          txt_pref_node=document.createTextNode("");
          str_div="";
          break;
        }
      }
      
      $("hoteljp_plan_pref"+ int_form_num).appendChild(hid_node);
      $("hoteljp_plan_pref"+ int_form_num).appendChild(document.createTextNode(str_div));
      $("hoteljp_plan_pref"+ int_form_num).appendChild(txt_pref_node);

      onChangePref(int_form_num);
    }
    else{
      var sel_node=getBlankPrefNode("plan",int_form_num);

      for (var i=0;i<has_prefs[int_selected_region_id].length;i++){
        var opt_node=document.createElement("option");
        opt_node.setAttribute("value",htmlEscape(has_prefs[int_selected_region_id][i]["pref_en"]));
        var txt_node=document.createTextNode(htmlEscape(has_prefs[int_selected_region_id][i]["pref_jp"]));
        opt_node.appendChild(txt_node);
        sel_node.appendChild(opt_node);
      }

      
      $("hoteljp_plan_pref"+ int_form_num).appendChild(document.createTextNode("　>　"));
      $("hoteljp_plan_pref"+ int_form_num).appendChild(sel_node);
      
      if (typeof bgcolor != 'undefined'){
        clearPlanBackGround(int_form_num);
        $("hoteljp_plan_pref_en"+ int_form_num).style.backgroundColor=bgcolor;
      }

      setListener($("hoteljp_plan_pref_en"+ int_form_num),"change",function(){onChangePref(int_form_num);} );

    }
  }
  else{
    if(typeof bgcolor != 'undefined'){
      clearPlanBackGround(int_form_num);
      $("hoteljp_plan_region_en"+ int_form_num).style.backgroundColor=bgcolor;
    }
    $("hoteljp_plan_pref"+ int_form_num).appendChild(getBlankPrefAreaNode("plan",int_form_num));
  }
}

function onChangePref(int_form_num){
  if (typeof int_form_num == 'undefined'){
   var  int_form_num='';
  }


  var str_selected_region=$("hoteljp_plan_region_en"+ int_form_num).value;
  var str_selected_pref=$("hoteljp_plan_pref_en"+ int_form_num).value;
  removeAllChildNodes("hoteljp_plan_small_area"+ int_form_num);
  removeAllChildNodes("hoteljp_plan_mid_area"+ int_form_num);
  
  if (str_selected_region=='' || str_selected_pref==''){
    $("hoteljp_plan_mid_area"+ int_form_num).appendChild(getBlankMidAreaNode("plan",int_form_num));
    if(typeof bgcolor != 'undefined'){
      clearPlanBackGround(int_form_num);
      $("hoteljp_plan_pref_en"+ int_form_num).style.backgroundColor=bgcolor;
    }
    return;
  }

  int_selected_region_id=getRegionId(str_selected_region);
  int_selected_pref_id=getPrefId(int_selected_region_id,str_selected_pref);

  if(typeof has_mid_areas[int_selected_pref_id] != 'undefined'){
    if(has_mid_areas[int_selected_pref_id].length==1){
      var hid_node=document.createElement("input");
      hid_node.setAttribute("type","hidden");
      hid_node.setAttribute("id","hoteljp_plan_mid_area_en"+ int_form_num);
      hid_node.setAttribute("name","mid_area_en");
      hid_node.setAttribute("value", htmlEscape(has_mid_areas[int_selected_pref_id][0]["mid_area_en"]));
      var txt_node=document.createTextNode(has_mid_areas[int_selected_pref_id][0]["mid_area_jp"]);

      $("hoteljp_plan_mid_area"+ int_form_num).appendChild(hid_node);
      $("hoteljp_plan_mid_area"+ int_form_num).appendChild(document.createTextNode("　>　"));
      $("hoteljp_plan_mid_area"+ int_form_num).appendChild(txt_node);
      onChangeMidArea();
    }
    else{
      var sel_node=getBlankMidAreaNode("plan",int_form_num);

      for (var i=0;i<has_mid_areas[int_selected_pref_id].length;i++){
        var opt_node=document.createElement("option");
        opt_node.setAttribute("value",htmlEscape(has_mid_areas[int_selected_pref_id][i]["mid_area_en"]));
        var txt_node=document.createTextNode(has_mid_areas[int_selected_pref_id][i]["mid_area_jp"]);
        opt_node.appendChild(txt_node);
        sel_node.appendChild(opt_node);
      }
      $("hoteljp_plan_mid_area"+ int_form_num).appendChild(document.createTextNode("　>　"));
      $("hoteljp_plan_mid_area"+ int_form_num).appendChild(sel_node);
      
      if(typeof bgcolor != 'undefined'){
        clearPlanBackGround(int_form_num);
        $("hoteljp_plan_mid_area_en"+ int_form_num).style.backgroundColor=bgcolor;
      }
      setListener($("hoteljp_plan_mid_area_en"+ int_form_num),"change",function(){onChangeMidArea(int_form_num);} );

    }
  }
  else{

    $("hoteljp_plan_mid_area_area"+ int_form_num).appendChild(getBlankMidAreaNode("plan",int_form_num));
    if(typeof bgcolor != 'undefined'){
      clearPlanBackGround(int_form_num);
      $("hoteljp_plan_pref_en"+ int_form_num).style.backgroundColor=bgcolor;
    }
  }
}


function onChangeMidArea(int_form_num){

  if (typeof int_form_num == 'undefined'){
   var  int_form_num='';
  }

  var str_selected_region=$("hoteljp_plan_region_en" + int_form_num).value;
  var str_selected_pref=$("hoteljp_plan_pref_en" + int_form_num).value;
  var str_selected_mid_area=$("hoteljp_plan_mid_area_en" + int_form_num).value;

  removeAllChildNodes("hoteljp_plan_small_area" + int_form_num);
  if (typeof str_selected_region == 'undefined' || typeof str_selected_pref  == 'undefined' || typeof str_selected_mid_area  == 'undefined' || str_selected_region=='' || str_selected_pref=='' || str_selected_mid_area ==''){
    if(typeof bgcolor != 'undefined'){
      clearPlanBackGround(int_form_num);
      $("hoteljp_plan_mid_area_en" + int_form_num).style.backgroundColor=bgcolor;
    }
    return;
  }
  int_selected_region_id=getRegionId(str_selected_region);
  int_selected_pref_id=getPrefId(int_selected_region_id,str_selected_pref);
  int_selected_mid_area_id=getMidAreaId(int_selected_pref_id,str_selected_mid_area);

  if(typeof has_small_areas[int_selected_mid_area_id] != 'undefined'){
    if(has_small_areas[int_selected_mid_area_id].length==1){
      var hid_node=document.createElement("input");
      hid_node.setAttribute("type","hidden");
      hid_node.setAttribute("id","hoteljp_plan_small_area_en" + int_form_num);
      hid_node.setAttribute("name","small_area_en");
      hid_node.setAttribute("value", htmlEscape(has_small_areas[int_selected_mid_area_id][0]["small_area_en"]));
      var txt_node=document.createTextNode(has_small_areas[int_selected_mid_area_id][0]["small_area_jp"]);
      $("hoteljp_plan_small_area" + int_form_num).appendChild(hid_node);
      $("hoteljp_plan_small_area"+ int_form_num).appendChild(document.createTextNode("　>　"));
      $("hoteljp_plan_small_area" + int_form_num).appendChild(txt_node);
      
    }
    else{
      var sel_node=getBlankSmallAreaNode("plan",int_form_num);
      
      for (var i=0;i<has_small_areas[int_selected_mid_area_id].length;i++){
        var opt_node=document.createElement("option");
        opt_node.setAttribute("value",htmlEscape(has_small_areas[int_selected_mid_area_id][i]["small_area_en"]));
        var txt_node=document.createTextNode(has_small_areas[int_selected_mid_area_id][i]["small_area_jp"]);
        opt_node.appendChild(txt_node);
        sel_node.appendChild(opt_node);
      }
      $("hoteljp_plan_small_area"+ int_form_num).appendChild(document.createTextNode("　>　"));
      $("hoteljp_plan_small_area" + int_form_num).appendChild(sel_node);
      if(typeof bgcolor != 'undefined'){
        clearPlanBackGround(int_form_num);
        $("hoteljp_plan_small_area_en" + int_form_num).style.backgroundColor=bgcolor;
      }


      setListener($("hoteljp_plan_small_area_en" + int_form_num),"change",function(){onChangeSmallArea(int_form_num);} );

    }
  }
  else{
    if(typeof bgcolor != 'undefined'){
      clearPlanBackGround(int_form_num);
      $("hoteljp_plan_mid_area_en" + int_form_num).style.backgroundColor=bgcolor;
    }
  }
}

function onChangeSmallArea(int_form_num){
  var str_selected_small_area=$("hoteljp_plan_small_area_en" + int_form_num).value;
  if(str_selected_small_area !=''){
    if(typeof bgcolor != 'undefined'){
      clearPlanBackGround(int_form_num);
      $("hoteljp_plan_stay_date_form" +  int_form_num + "_y" ).style.backgroundColor=bgcolor;
    }
  }
}



function getRegionId(str_region_en){
  for (var i =0;i<arr_regions.length;i++){
    if(arr_regions[i].region_en==str_region_en){
      return arr_regions[i]["id"];
    }
  }
  return null;
}

function getPrefId(int_region_id,str_pref_en){
  if (typeof has_prefs[int_region_id]!= 'undefined'){
    for (var i =0;i<has_prefs[int_region_id].length;i++){
      if(has_prefs[int_region_id][i].pref_en==str_pref_en){
        return has_prefs[int_region_id][i]["id"];
      }
    }
  }
  return null;
}

function getMidAreaId(int_pref_id,str_mid_area_en){
  if (typeof has_mid_areas[int_pref_id]!= 'undefined'){
    for (var i =0;i<has_mid_areas[int_pref_id].length;i++){
      if(has_mid_areas[int_pref_id][i].mid_area_en==str_mid_area_en){
        return has_mid_areas[int_pref_id][i]["id"];
      }
    }
  }
  return null;
}


function makeDateForm(str_form_name,int_form_num,str_target_id,date_def){
  var str_form_id = "hoteljp_plan_stay_date_form" + int_form_num
  var sel_year_node=document.createElement("select");
  sel_year_node.setAttribute("id",str_form_id + "_y");
  sel_year_node.setAttribute("name",str_form_name + "_y");

  if (typeof date_def == 'undefined'){
    date_def=new Date();
    date_def.setTime(date_def.getTime() + 3* 1000*60*60*24);
  }

  date_today=new Date();
  for (var i=0;i<2;i++){
    int_year=date_today.getYear() ;
    if (int_year < 2000){
      int_year +=1900;
    }
    var tmp_opt_node=document.createElement("option");
    tmp_opt_node.setAttribute("value",int_year + i);
    var tmp_txt_node=document.createTextNode(int_year+ i);
    tmp_opt_node.appendChild(tmp_txt_node);
    sel_year_node.appendChild(tmp_opt_node);

  }
  $(str_target_id).appendChild(sel_year_node)
  $(str_form_id + "_y").value=date_def.getYear()
  $(str_target_id).appendChild(document.createTextNode("年"))
  
  var sel_month_node=document.createElement("select");
  sel_month_node.setAttribute("id",str_form_id + "_m");
  sel_month_node.setAttribute("name",str_form_name + "_m");

  for (var i=1;i<=12;i++){
    var tmp_opt_node=document.createElement("option");
    tmp_opt_node.setAttribute("value",i);
    var tmp_txt_node=document.createTextNode(i);
    tmp_opt_node.appendChild(tmp_txt_node);
    sel_month_node.appendChild(tmp_opt_node);
  }

  $(str_target_id).appendChild(sel_month_node)
  $(str_form_id + "_m").value=date_def.getMonth()+1;

  $(str_target_id).appendChild(document.createTextNode("月"))

  var sel_day_node=document.createElement("select");
  sel_day_node.setAttribute("id",str_form_id + "_d");
  sel_day_node.setAttribute("name",str_form_name + "_d");
  
  if(date_def.getMonth()==11){
    var date_tmp=new Date(date_def.getYear()+1,1,1);
  }
  else{
    var date_tmp=new Date(date_def.getYear(),date_def.getMonth()+1,1);
  }

  date_tmp.setTime(date_tmp.getTime() - 1000*60*60*24);
  

  for (var i=1;i<=date_tmp.getDate();i++){
    var tmp_opt_node=document.createElement("option");
    tmp_opt_node.setAttribute("value",i);
    var tmp_txt_node=document.createTextNode(i);
    tmp_opt_node.appendChild(tmp_txt_node);
    sel_day_node.appendChild(tmp_opt_node);
  }

  $(str_target_id).appendChild(sel_day_node)
  $(str_form_id + "_d").value=date_def.getDate();
  $(str_target_id).appendChild(document.createTextNode("日"))

  setListener($(str_form_id + "_y"),"change",function(){onChangeDate(str_form_id,int_form_num);onChageYear(str_form_id,int_form_num);} );
  setListener($(str_form_id + "_m"),"change",function(){onChangeDate(str_form_id,int_form_num);onChageMonth(str_form_id,int_form_num);} );
  setListener($(str_form_id + "_d"),"change",function(){onChangeDate(str_form_id,int_form_num);onChageDay(str_form_id,int_form_num);} );

}

function onChageYear(str_form_id,int_form_num){
  if(typeof bgcolor != 'undefined'){
    clearPlanBackGround(int_form_num);
    $(str_form_id + "_m").style.backgroundColor=bgcolor;
  }
}

function onChageMonth(str_form_id,int_form_num){
  if(typeof bgcolor != 'undefined'){
    clearPlanBackGround(int_form_num);
    $(str_form_id + "_d").style.backgroundColor=bgcolor;
  }
}

function onChageDay(str_form_id,int_form_num){
  if(typeof bgcolor != 'undefined'){
    clearPlanBackGround(int_form_num);
    $("hoteljp_plan_term_form"+ int_form_num).style.backgroundColor=bgcolor;
  }
}

function onChangeDate(str_form_id,int_form_num){
  //日付は無視　2/31を3/3とみなすため
  date_selected=new Date($(str_form_id + "_y").value,$(str_form_id + "_m").value-1,1);
  int_selected_day= $(str_form_id + "_d").value;
  arr_cnodes=$(str_form_id + "_d").childNodes;

  for(i=arr_cnodes.length-1;i>=0;i--){
    arr_cnodes[i].parentNode.removeChild(arr_cnodes[i]);
  }
  
  if(date_selected.getMonth()==11){
    var date_tmp=new Date(date_selected.getYear()+1,1,1);
  }
  else{
    var date_tmp=new Date(date_selected.getYear(),date_selected.getMonth()+1,1);
  }
  date_tmp.setTime(date_tmp.getTime() - 1000*60*60*24);
  for (var i=1;i<=date_tmp.getDate();i++){
    var opt_node=document.createElement("option");
    var txt_node=document.createTextNode(i);
    opt_node.setAttribute("value",i);
    opt_node.appendChild(txt_node);
    $(str_form_id + "_d").appendChild(opt_node);
  }
  $(str_form_id + "_d").value= int_selected_day;
}

function makeIntegerOption(int_max,str_id,str_name,int_def,str_target){
  var sel_node=document.createElement("select");
  sel_node.setAttribute("id",str_id);
  sel_node.setAttribute("name",str_name);
  for(i=1;i<=int_max;i++){
    var opt_node=document.createElement("option");
    opt_node.setAttribute("value",i);
    var txt_node=document.createTextNode(i);
    opt_node.appendChild(txt_node);
    sel_node.appendChild(opt_node);
  }
  sel_node.value=int_def;
  $(str_target).appendChild(sel_node);
}

function removeAllChildNodes(str_id){
  while ($(str_id).firstChild) {
    $(str_id).removeChild($(str_id).firstChild);
  }
}


function makeHotelForm(bol_focus){
  var sel_node=document.createElement("select");
  sel_node.setAttribute("id","hoteljp_hotel_region_en");
  sel_node.setAttribute("name","region_en");

  var opt_node=document.createElement("option");
  opt_node.setAttribute("value","");
  var txt_node=document.createTextNode("地方選択");
  opt_node.appendChild(txt_node);
  sel_node.appendChild(opt_node);
  for (var int_i=0;int_i<arr_regions.length;int_i++){
    var opt_node=document.createElement("option");
    opt_node.setAttribute("value",htmlEscape(arr_regions[int_i]["region_en"]));
    var txt_node=document.createTextNode(htmlEscape(arr_regions[int_i]["region_jp"]));
    opt_node.appendChild(txt_node);
    sel_node.appendChild(opt_node);
  }
  $("hoteljp_hotel_region").appendChild(sel_node);
  removeAllChildNodes("hoteljp_hotel_pref");
  removeAllChildNodes("hoteljp_hotel_mid_area");
  removeAllChildNodes("hoteljp_hotel_small_area");
  
  hid_node=document.createElement("input");
  hid_node.setAttribute("type","hidden");
  hid_node.setAttribute("name","pht_sw");
  hid_node.setAttribute("value",0);
  $("hoteljp_hotel_search_form").appendChild(hid_node);
  
  setListener($("hoteljp_hotel_region_en"),"change",function(){onChangeHotelRegion()} );
  if (bol_focus){
    $("hoteljp_hotel_region_en").focus();
    if (typeof bgcolor != 'undefined'){
      $("hoteljp_hotel_region_en").style.backgroundColor=bgcolor;
    }
  }
}

function clearHotelBackGround(){
  var nodes=$("hoteljp_hotel_search_form").getElementsByTagName("select");
  for (i=0;i<nodes.length;i++){
    nodes[i].style.backgroundColor='';
  }
  $("hoteljp_hotel_keyword").style.backgroundColor='';
}

function onChangeHotelRegion(int_form_num){

  var str_selected_region=$("hoteljp_hotel_region_en").value;
  var int_selected_region_id;

  removeAllChildNodes("hoteljp_hotel_mid_area");
  removeAllChildNodes("hoteljp_hotel_small_area");
  removeAllChildNodes("hoteljp_hotel_pref");
  
  if (str_selected_region==''){
    if(typeof bgcolor != 'undefined'){
      clearHotelBackGround();
      $("hoteljp_hotel_region_en").style.backgroundColor=bgcolor;
    }
    return;
  }

  int_selected_region_id=getRegionId(str_selected_region)
  if (typeof has_prefs[int_selected_region_id] != 'undefined'){
    if (has_prefs[int_selected_region_id].length==1){
      var hid_node=document.createElement("input");
      hid_node.setAttribute("type","hidden");
      hid_node.setAttribute("id","hoteljp_hotel_pref_en");
      hid_node.setAttribute("name","pref_en");
      hid_node.setAttribute("value",has_prefs[int_selected_region_id][0]["pref_en"]);

      var txt_pref_node=document.createTextNode(htmlEscape(has_prefs[int_selected_region_id][0]["pref_jp"]));
      var str_div="　>　";
      for(var i=0;i<arr_no_page_regions.length;i++){
        if(arr_no_page_regions[i]==str_selected_region){
          txt_pref_node=document.createTextNode("");
          str_div='';
          break;
        }
      }
      
      $("hoteljp_hotel_pref").appendChild(hid_node);
      $("hoteljp_hotel_pref").appendChild(document.createTextNode(str_div));
      $("hoteljp_hotel_pref").appendChild(txt_pref_node);
      onChangeHotelPref();
    }
    else{
      var sel_node=getBlankPrefNode("hotel");

      for (var i=0;i<has_prefs[int_selected_region_id].length;i++){
        var opt_node=document.createElement("option");
        opt_node.setAttribute("value",htmlEscape(has_prefs[int_selected_region_id][i]["pref_en"]));
        var txt_node=document.createTextNode(htmlEscape(has_prefs[int_selected_region_id][i]["pref_jp"]));
        opt_node.appendChild(txt_node);
        sel_node.appendChild(opt_node);
      }

      removeAllChildNodes("hoteljp_hotel_pref");
      $("hoteljp_hotel_pref").appendChild(document.createTextNode("　>　"));
      $("hoteljp_hotel_pref").appendChild(sel_node);
      
      
      if (typeof bgcolor != 'undefined'){
        clearHotelBackGround();
        $("hoteljp_hotel_pref_en").style.backgroundColor=bgcolor;
      }
      setListener($("hoteljp_hotel_pref_en"),"change",function(){onChangeHotelPref();} );
    }
  }
  else{
    if(typeof bgcolor != 'undefined'){
      clearHotelBackGround();
      $("hoteljp_hotel_region_en").style.backgroundColor=bgcolor;
    }
  }
}

function onChangeHotelPref(){
  var str_selected_region=$("hoteljp_hotel_region_en").value;
  var str_selected_pref=$("hoteljp_hotel_pref_en").value;
  removeAllChildNodes("hoteljp_hotel_small_area");
  removeAllChildNodes("hoteljp_hotel_mid_area");
  
  if (str_selected_region=='' || str_selected_pref==''){
    if(typeof bgcolor != 'undefined'){
      clearHotelBackGround();
      $("hoteljp_hotel_pref_en").style.backgroundColor=bgcolor;
    }
    return;
  }

  int_selected_region_id=getRegionId(str_selected_region);
  int_selected_pref_id=getPrefId(int_selected_region_id,str_selected_pref);

  if(typeof has_mid_areas[int_selected_pref_id] != 'undefined'){
    if(has_mid_areas[int_selected_pref_id].length==1){
      var hid_node=document.createElement("input");
      hid_node.setAttribute("type","hidden");
      hid_node.setAttribute("id","hoteljp_hotel_mid_area_en");
      hid_node.setAttribute("name","mid_area_en");
      hid_node.setAttribute("value", htmlEscape(has_mid_areas[int_selected_pref_id][0]["mid_area_en"]));
      var txt_node=document.createTextNode(has_mid_areas[int_selected_pref_id][0]["mid_area_jp"]);
      $("hoteljp_hotel_mid_area").appendChild(hid_node);
      $("hoteljp_hotel_mid_area").appendChild(document.createTextNode("　>　"));
      $("hoteljp_hotel_mid_area").appendChild(txt_node);
      onChangeMidArea();
    }
    else{
      var sel_node=getBlankMidAreaNode("hotel");

      for (var i=0;i<has_mid_areas[int_selected_pref_id].length;i++){
        var opt_node=document.createElement("option");
        opt_node.setAttribute("value",htmlEscape(has_mid_areas[int_selected_pref_id][i]["mid_area_en"]));
        var txt_node=document.createTextNode(has_mid_areas[int_selected_pref_id][i]["mid_area_jp"]);
        opt_node.appendChild(txt_node);
        sel_node.appendChild(opt_node);
      }

      $("hoteljp_hotel_mid_area").appendChild(document.createTextNode("　>　"));
      $("hoteljp_hotel_mid_area").appendChild(sel_node);
      
      if(typeof bgcolor != 'undefined'){
        clearHotelBackGround();
        $("hoteljp_hotel_mid_area_en").style.backgroundColor=bgcolor;
      }
      setListener($("hoteljp_hotel_mid_area_en"),"change",function(){onChangeHotelMidArea();} );
    }
  }
  else{
    if(typeof bgcolor != 'undefined'){
      clearHotelBackGround();
      $("hoteljp_hotel_pref_en").style.backgroundColor=bgcolor;
    }
  }
}

function onChangeHotelMidArea(){
  var str_selected_region=$("hoteljp_hotel_region_en").value;
  var str_selected_pref=$("hoteljp_hotel_pref_en").value;
  var str_selected_mid_area=$("hoteljp_hotel_mid_area_en").value;

  removeAllChildNodes("hoteljp_hotel_small_area");
  if (typeof str_selected_region == 'undefined' || typeof str_selected_pref  == 'undefined' || typeof str_selected_mid_area  == 'undefined' || str_selected_region=='' || str_selected_pref=='' || str_selected_mid_area ==''){
    if(typeof bgcolor != 'undefined'){
      clearHotelBackGround();
      $("hoteljp_hotel_mid_area_en").style.backgroundColor=bgcolor;
    }
    return;
  }
  int_selected_region_id=getRegionId(str_selected_region);
  int_selected_pref_id=getPrefId(int_selected_region_id,str_selected_pref);
  int_selected_mid_area_id=getMidAreaId(int_selected_pref_id,str_selected_mid_area);

  
  if(typeof has_small_areas[int_selected_mid_area_id] != 'undefined'){
  
    if(has_small_areas[int_selected_mid_area_id].length==1){
      var hid_node=document.createElement("input");
      hid_node.setAttribute("type","hidden");
      hid_node.setAttribute("id","hoteljp_hotel_small_area_en");
      hid_node.setAttribute("name","small_area_en");
      hid_node.setAttribute("value", htmlEscape(has_small_areas[int_selected_mid_area_id][0]["small_area_en"]));
      var txt_node=document.createTextNode(has_small_areas[int_selected_mid_area_id][0]["small_area_jp"]);
      $("hoteljp_hotel_small_area").appendChild(hid_node);
      $("hoteljp_hotel_small_area").appendChild(document.createTextNode("　>　"));
      $("hoteljp_hotel_small_area").appendChild(txt_node);
      
    }
    else{
      var sel_node=getBlankSmallAreaNode("hotel");
      
      for (var i=0;i<has_small_areas[int_selected_mid_area_id].length;i++){
        var opt_node=document.createElement("option");
        opt_node.setAttribute("value",htmlEscape(has_small_areas[int_selected_mid_area_id][i]["small_area_en"]));
        var txt_node=document.createTextNode(has_small_areas[int_selected_mid_area_id][i]["small_area_jp"]);
        opt_node.appendChild(txt_node);
        sel_node.appendChild(opt_node);
      
      }

      $("hoteljp_hotel_small_area").appendChild(document.createTextNode("　>　"));
      $("hoteljp_hotel_small_area").appendChild(sel_node);
      if(typeof bgcolor != 'undefined'){
        clearHotelBackGround();
        $("hoteljp_hotel_small_area_en").style.backgroundColor=bgcolor;
      }
      setListener($("hoteljp_hotel_small_area_en"),"change",function(){onChangeHotelSmallArea();} );
    }
  }
  else{
    
    if(typeof bgcolor != 'undefined'){
      clearHotelBackGround();
      $("hoteljp_hotel_mid_area_en").style.backgroundColor=bgcolor;
    }
  }
}

function onChangeHotelSmallArea(){
  var str_selected_small_area=$("hoteljp_hotel_small_area_en").value;
  if(str_selected_small_area !=''){
    if(typeof bgcolor != 'undefined'){
      clearHotelBackGround();
      $("hoteljp_hotel_keyword").style.backgroundColor=bgcolor;
    }
  }
}

function setDefaultArea(region_en,pref_en,mid_area_en,small_area_en,int_form_num){
  if (typeof int_form_num == "undefined"){
    var int_form_num='';
  }
  if (typeof $("hoteljp_plan_region_en" + int_form_num) != "undefined" && typeof $("hoteljp_plan_region_en" + int_form_num) != "null" && region_en != ''){
    $("hoteljp_plan_region_en"+ int_form_num).value=region_en;
    onChangeRegion(int_form_num);
  }
  
  if (typeof $("hoteljp_plan_pref_en"+ int_form_num) != "undefined" && typeof $("hoteljp_plan_pref_en"+ int_form_num) != "null" && pref_en != ''){
    $("hoteljp_plan_pref_en"+ int_form_num).value=pref_en;
    onChangePref(int_form_num);
  }
  
  if (typeof $("hoteljp_plan_mid_area_en"+ int_form_num) != "undefined" && typeof $("hoteljp_plan_mid_area_en"+ int_form_num) != "null" && mid_area_en != ''){
    $("hoteljp_plan_mid_area_en"+ int_form_num).value=mid_area_en;
    onChangeMidArea(int_form_num);
  }
  
  if (typeof $("hoteljp_plan_small_area_en"+ int_form_num) != "undefined" && typeof $("hoteljp_plan_small_area_en"+ int_form_num) != "null" && small_area_en != ''){
    $("hoteljp_plan_small_area_en"+ int_form_num).value=small_area_en;
    onChangeSmallArea(int_form_num);
  }
}

function setDefaultDayTerm(year,month,day,term,int_form_num){
  if (typeof int_form_num == "undefined"){
    var int_form_num='';
  }
  if (typeof $("hoteljp_plan_stay_date_form" + int_form_num + "_y") != "undefined" && typeof $("hoteljp_plan_stay_date_form" + int_form_num + "_y") != "null" && year != ''){
    $("hoteljp_plan_stay_date_form" + int_form_num + "_y").value=year;
  }
  
  if (typeof $("hoteljp_plan_stay_date_form" + int_form_num + "_m") != "undefined" && typeof $("hoteljp_plan_stay_date_form" + int_form_num + "_m") != "null" && month != ''){
    $("hoteljp_plan_stay_date_form" + int_form_num + "_m").value=month;
  }
  
  if (typeof $("hoteljp_plan_stay_date_form" + int_form_num + "_d") != "undefined" && typeof $("hoteljp_plan_stay_date_form" + int_form_num + "_d") != "null" && day != ''){
    $("hoteljp_plan_stay_date_form" + int_form_num + "_d").value=day;
  }
  
  if (typeof $("hoteljp_plan_term_form"+ int_form_num) != "undefined" && typeof $("hoteljp_plan_term_form"+ int_form_num) != "null" && term != ''){
    $("hoteljp_plan_term_form"+ int_form_num).value=term;
  }
}

function setDefaultHeadsRoom(heads,rooms,int_form_num){
  if (typeof int_form_num == "undefined"){
    var int_form_num='';
  }
  if (typeof $("hoteljp_plan_heads_form"+ int_form_num) != "undefined" && typeof $("hoteljp_plan_heads_form"+ int_form_num) != "null" && heads != ''){
    $("hoteljp_plan_heads_form"+ int_form_num).value=heads;
  }

  if (typeof $("hoteljp_plan_rooms_form"+ int_form_num) != "undefined" && typeof $("hoteljp_plan_rooms_form"+ int_form_num) != "null" && rooms != ''){
    $("hoteljp_plan_rooms_form"+ int_form_num).value=rooms;
  }
}

