//検索ボタン押下 検索開始
function search_start(){
  document.frm.select_area.value = '02';
  action_url = '/work/worklist/select_area';
  action_prm = '/02';
  if (document.frm.select_prefecture.value != '') {
    action_url = action_url + '/select_prefecture'
    action_prm = action_prm + '/' + document.frm.select_prefecture.value;
  }
  if (document.frm.select_city.value != '') {
    action_url = action_url + '/select_city'
    action_prm = action_prm + '/' + document.frm.select_city.value;
  }
  if (document.frm.select_job.value != '') {
    action_url = action_url + '/select_job'
    action_prm = action_prm + '/' + document.frm.select_job.value;
  }
  if (document.frm.select_job_detail.value != '') {
    action_url = action_url + '/select_job_detail'
    action_prm = action_prm + '/' + document.frm.select_job_detail.value;
  }
  if (document.frm.select_service[0].checked) {
    action_url = action_url + '/select_service';
    action_prm = action_prm + '/1';
  }
  if (document.frm.select_service[1].checked) {
    action_url = action_url + '/select_service';
    action_prm = action_prm + '/0';
  }
  if (document.frm.select_salary.value != '') {
    action_url = action_url + '/select_salary'
    action_prm = action_prm + '/' + document.frm.select_salary.value;
  }
  if (document.frm.select_work_days.value != '') {
    action_url = action_url + '/select_work_days'
    action_prm = action_prm + '/' + document.frm.select_work_days.value;
  }
  if (document.frm.select_peculiarity.value != '') {
    action_url = action_url + '/select_peculiarity'
    action_prm = action_prm + '/' + document.frm.select_peculiarity.value;
  }
  if (document.frm.select_peculiarity2.value != '') {
    action_url = action_url + '/select_peculiarity2'
    action_prm = action_prm + '/' + document.frm.select_peculiarity2.value;
  }
  if (document.frm.select_route_company.value != '') {
    action_url = action_url + '/select_route_company'
    action_prm = action_prm + '/' + document.frm.select_route_company.value;
  }
  if (document.frm.select_route.value != '') {
    action_url = action_url + '/select_route'
    action_prm = action_prm + '/' + document.frm.select_route.value;
  }
  if (document.frm.select_station_from.value != '') {
    action_url = action_url + '/select_station_from'
    action_prm = action_prm + '/' + document.frm.select_station_from.value;
  }
  if (document.frm.select_station_to.value != '') {
    action_url = action_url + '/select_station_to'
    action_prm = action_prm + '/' + document.frm.select_station_to.value;
  }
  if (document.frm.select_employment.value != '') {
    action_url = action_url + '/select_employment'
    action_prm = action_prm + '/' + document.frm.select_employment.value;
  }
  document.frm.target = '_self';
  document.frm.action = action_url + action_prm + '/';
  document.frm.submit();
}

//おいしい仕事メール登録
function mail_magazine_entry(){
  mail_address = document.mail_magazine.mail_magazine_user.value;
  check_address = mail_address.match(/^\S+@\S+\.\S+$/);
  if(mail_address == '') {
    alert("登録するメールアドレスが入力されていません");
  } else {
    if(!check_address) {
      alert("登録するメールアドレスが正しくありません");
    } else {
      document.mail_magazine.select_area.value = "02";
      document.mail_magazine.target = "_self";
      document.mail_magazine.action = "/top/mail_magazine/";
      document.mail_magazine.submit();
    }
  }
}

//おいしい仕事メール登録(enterキー対応)
function mail_magazine_keypress(evt){
  var keyCode;
  if (evt) {
    keyCode = evt.keyCode;
  } else {
    keyCode = event.keyCode;
  }
  // [Enter]キーが押されたかどうかの判定
  if (keyCode != 10 && keyCode != 13) {
    return true;
  } else {
    mail_magazine_entry();
    return false;
  }
}

//お気に入りリストへ遷移
function favorite_list(){
  document.frm.select_area.value = "02";
  document.frm.func.value = "show";
  document.frm.target = "_self";
  document.frm.action = "/mylist/";
  document.frm.submit();
}

//都道府県変更
function change_prefecture(pref_func){
  if (document.frm.select_prefecture.selectedIndex == 0){
    document.frm.select_city.length = 1;
    document.frm.select_city.selectedIndex = 0;
  } else {
    if (pref_func){
      document.frm.select_city.length = 1;
      document.frm.select_city.selectedIndex = 0;
    }
    var select_city_name = city_names[document.frm.select_prefecture.selectedIndex - 1];
    var select_city_code = city_codes[document.frm.select_prefecture.selectedIndex - 1];
    document.frm.select_city.length = select_city_name.length + 1;
    for (var i = 0; i < select_city_name.length; i++){
      document.frm.select_city.options[i + 1].value = select_city_code[i];
      document.frm.select_city.options[i + 1].text = select_city_name[i];
    }
  }
}

//職種変更
function change_job(job_func){
  if (document.frm.select_job.selectedIndex == 0){
    document.frm.select_job_detail.length = 1;
    document.frm.select_job_detail.selectedIndex = 0;
  } else {
    if (job_func){
      document.frm.select_job_detail.length = 1;
      document.frm.select_job_detail.selectedIndex = 0;
    }
    var select_job_detail_name = job_detail_names[document.frm.select_job.selectedIndex - 1];
    var select_job_detail_code = job_detail_codes[document.frm.select_job.selectedIndex - 1];
    document.frm.select_job_detail.length = select_job_detail_name.length + 1;
    for (var i = 0; i < select_job_detail_name.length; i++){
      document.frm.select_job_detail.options[i + 1].value = select_job_detail_code[i];
      document.frm.select_job_detail.options[i + 1].text = select_job_detail_name[i];
    }
  }
  //フード系・サービス系・アミューズメント系の場合、「接客あり・なし」を条件に追加
  if ((document.frm.select_job.value == 4) ||
      (document.frm.select_job.value == 6) || 
      (document.frm.select_job.value == 7)){
    document.getElementById('service').style.display='block';
  } else {
    document.getElementById('service').style.display='none';
    document.frm.select_service.selectedIndex = 0;
  }
}

//路線会社変更
function change_route_company(route_company_func){
  if (document.frm.select_route_company.selectedIndex == 0){
    document.frm.select_route.length = 1;
    document.frm.select_route.selectedIndex = 0;
    document.frm.select_route.options[0].text = '▼選択してください';
    document.frm.select_route.options[0].value = '';
    document.frm.select_station_from.length = 1;
    document.frm.select_station_from.selectedIndex = 0;
    document.frm.select_station_from.options[0].text = '▼選択してください';
    document.frm.select_station_from.options[0].value = '';
    document.frm.select_station_to.length = 1;
    document.frm.select_station_to.selectedIndex = 0;
    document.frm.select_station_to.options[0].text = '▼選択してください';
    document.frm.select_station_to.options[0].value = '';
    document.frm.select_station_to.disabled = true;
  } else {
    if (route_company_func){
      document.frm.select_route.length = 0;
      document.frm.select_route.selectedIndex = 0;
      document.frm.select_station_from.length = 1;
      document.frm.select_station_from.selectedIndex = 0;
      document.frm.select_station_from.options[0].text = '▼選択してください';
      document.frm.select_station_from.options[0].value = '';
      document.frm.select_station_to.length = 1;
      document.frm.select_station_to.selectedIndex = 0;
      document.frm.select_station_to.options[0].text = '▼選択してください';
      document.frm.select_station_to.options[0].value = '';
      document.frm.select_station_to.disabled = true;
    }
    var select_route_name = route_names[document.frm.select_route_company.selectedIndex - 1];
    var select_route_code = route_codes[document.frm.select_route_company.selectedIndex - 1];
    document.frm.select_route.length = select_route_name.length;
    for (var i = 0; i < select_route_name.length; i++){
      document.frm.select_route.options[i].value = select_route_code[i];
      document.frm.select_route.options[i].text = select_route_name[i];
    }
    change_route(route_company_func)
  }
}

//路線変更
function change_route(route_func){
  if (route_func){
    document.frm.select_station_from.length = 1;
    document.frm.select_station_from.selectedIndex = 0;
    document.frm.select_station_to.length = 1;
    document.frm.select_station_to.selectedIndex = 0;
    document.frm.select_station_to.disabled = true;
  }
  if (document.frm.select_route_company.selectedIndex != 0){
    var select_station_name = station_names[document.frm.select_route_company.selectedIndex - 1][document.frm.select_route.selectedIndex];
    var select_station_code = station_codes[document.frm.select_route_company.selectedIndex - 1][document.frm.select_route.selectedIndex];
    document.frm.select_station_from.length = select_station_name.length + 1;
//    document.frm.select_station_to.length = select_station_name.length + 1;
    document.frm.select_station_to.length = 1;
    document.frm.select_station_from.options[0].text = '全て';
    document.frm.select_station_to.options[0].text = '全て';
    document.frm.select_station_to.selectedIndex = 0;
    document.frm.select_station_to.disabled = true;
    for (var i = 0; i < select_station_name.length; i++){
      document.frm.select_station_from.options[i + 1].value = select_station_code[i];
      document.frm.select_station_from.options[i + 1].text = select_station_name[i];
//      document.frm.select_station_to.options[i + 1].value = select_station_code[i];
//      document.frm.select_station_to.options[i + 1].text = select_station_name[i];
    }
  }
}

//駅～から変更
function change_station_from(){
  if (document.frm.select_station_from.selectedIndex == 0){
    document.frm.select_station_to.selectedIndex = 0;
    document.frm.select_station_to.disabled = true;
    document.frm.select_station_to.options[0].text = '全て';
  } else {
    var select_station_name = station_names[document.frm.select_route_company.selectedIndex - 1][document.frm.select_route.selectedIndex];
    var select_station_code = station_codes[document.frm.select_route_company.selectedIndex - 1][document.frm.select_route.selectedIndex];
    document.frm.select_station_to.length = select_station_name.length;
    for (var i = 0; i < select_station_name.length; i++){
      document.frm.select_station_to.options[i].value = select_station_code[i];
      document.frm.select_station_to.options[i].text = select_station_name[i];
    }
    if (document.frm.select_station_to.disabled){
      document.frm.select_station_to.selectedIndex = document.frm.select_station_from.selectedIndex - 1;
    }
    document.frm.select_station_to.disabled = false
  }
}

