
// 検索フォーム用　カテゴリ選択用 JS 

function makeSublist(parent,child,isSubselectOptional,childVal){
  $("body").append("<select style='display:none' id='"+parent+child+"'></select>");
  $('#'+parent+child).html($("#"+child+" option"));
  var parentValue = $('#'+parent).attr('value');
  $('#'+child).html($("#"+parent+child+" .cat_"+parentValue).clone());
  childVal = (typeof childVal == "undefined")? "0" : childVal ;
  $("#"+child+' option[@value="'+ childVal +'"]').attr('selected','selected');
  $('#'+parent).change( 
      function(){
        var parentValue = $('#'+parent).attr('value');
        $('#'+child).html($("#"+parent+child+" .cat_"+parentValue).clone());
        if(isSubselectOptional) $('#'+child).prepend("<option value='0'> -- すべて -- </option>");
        $('#'+child).trigger("change");
        $('#'+child).focus();
      }
  );
}

$(function(){
  makeSublist('cat_lvl2','cat_lvl3', true, '');
  makeSublist('cat_lvl1','cat_lvl2', true, '');
});

function chgCatId(sel_box){
  if (sel_box.value != 0) {
    document.form_srch.srch_category.value = sel_box.value;
  } else {
    if (sel_box.name == 'cat_lvl3') {
        if (document.form_srch.cat_lvl2.value != 0) {
          document.form_srch.srch_category.value = document.form_srch.cat_lvl2.value;
        } else {
          document.form_srch.srch_category.value = "0";
        }
    }
  }
}

