
//検索ボタン押下 検索開始
function search_start(){
  document.frm.select_area.value = '02';
  	nodes = document.forms['frm'].getElementsByTagName('input');
    clsname = 'peculiarity_item';
    peculiarity_list = '';
  	for (i = 0; i < nodes.length; i++) {
		if (nodes[i].type == 'checkbox' && nodes[i].checked) {
            if ( (new String(nodes[i].getAttribute('class'))).indexOf(clsname) != -1 || (new String(nodes[i].getAttribute('className'))).indexOf(clsname) != -1 )
                peculiarity_list += (nodes[i].name).substr(0, nodes[i].name.length - 1).substr(20) + '+';
		}
	}

  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 (peculiarity_list.length > 0) {
    action_url = action_url + '/select_peculiarity3';
    action_prm = action_prm + '/' + peculiarity_list.substr(0, peculiarity_list.length - 1);
  }
  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;
  }
  if (document.frm.select_freeword.value != '') {
    action_url = action_url + '/select_freeword';
    action_prm = action_prm + '/' + document.frm.select_freeword.value;
  }
  action_url = action_url + '/page_no';
  action_prm = action_prm + '/1';

  document.frm.target = '_self';
  document.frm.action = action_url + action_prm + '/';
  document.frm.submit();
}



//詳細画面へ遷移
function work_detail(work_id, office_id){
  document.frm.select_area.value = '02';
  action_url = '/work/details/select_area';
  action_prm = '/02';
  action_url = action_url + '/select_work_id';
  action_prm = action_prm + '/' + work_id;
  action_url = action_url + '/select_office_id';
  action_prm = action_prm + '/' + office_id;
  document.frm.target = '_self';
  document.frm.action = action_url + action_prm + '/';
  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 = 2;
    document.frm.select_service[2].checked = true;
  }

}

//路線会社変更（関連する路線を再設定）
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_to.length = 1;
    document.frm.select_station_to.selectedIndex = 0;
    document.frm.select_station_to.options[0].text = 'こだわらない';
    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_to.length = 1;
      document.frm.select_station_to.selectedIndex = 0;
      document.frm.select_station_to.options[0].text = 'こだわらない';
      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){
  document.frm.select_station_to.disabled = true;
  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_from.options[0].text = '全て';
    document.frm.select_station_to.options[0].text = '全て';
    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;
  }
}

//フリーワード検索開始
function freeword_keypress(evt){
  var keyCode;
  if (evt) {
    keyCode = evt.keyCode;
  } else {
    keyCode = event.keyCode;
  }
  // [Enter]キーが押されたかどうかの判定
  if (keyCode != 10 && keyCode != 13) {
    return true;
  } else {
    search_start();
  }
}

