$(function() {
	$(".search dd input:checked").each(function() {
		var isl = $(this).attr("id");
		$("label[for="+isl+"]").css({"border":"solid 2px #666"});
	});

	$(".search dd input[type=checkbox]").click(function() {
		var isl = $(this).attr("id");
		if($(this).attr('checked') == true) {
			$("label[for="+isl+"]").css({"border":"solid 2px #666"});
		} else {
			$("label[for="+isl+"]").css({"border":"solid 2px #fff"});
		}
	});

	$("a[rel=external]").click(function(){
		window.open(this.href,'');
		return false;
	});

    var onSubCategoryChange = function() {
        var selected_main_ctg = $(this).find("option:selected").parent().attr("label");
        $("#main_category option").each(function() {
                if ($(this).text() == selected_main_ctg) {
                    $("#main_category").val($(this).val());
                }
            });
    };
    //サブカテゴリのプルダウン内容を保持
    var sc = $("#sub_category").clone();
    $("#main_category").change(function() {
        $("#sub_category").replaceWith(sc.clone());
        //JQuery("#id").clone(true)でIEでイベントのコピーができないので直接イベントを付与する
        $("#sub_category").change(onSubCategoryChange);
        $("#sub_category").val(0);

        if ($(this).val()) {
            var selected_main_ctg = $(this).find('option:selected').text();

            $("#sub_category optgroup").each(function() {
                    if ($(this).attr('label') != selected_main_ctg) {
                        $(this).remove();
                    }
                });
        }
    });
    $("#sub_category").change(onSubCategoryChange);

});

