//
// 就職情報検索(待遇)フォーム専用
//

/**
 * 職種を開く、職種を閉じるボタンで職種選択の表示on/offを切り替える。
 */
function toggleJobTypes() {
    var anchor = $("#toggleJobTypes");
    anchor.click(function() {
        $("div#unitJobtypeList").toggle();

        if ( anchor.parent("p#jobTypeChangeBtn").attr("class") == "open" ) {
            anchor.html("<img src=\"/img/btn/btn_jobopen_01.gif\" alt=\"職種を選択\" width=\"90\" height=\"22\" class=\"btn\" />");
            anchor.parent("p#jobTypeChangeBtn").attr("class", "close");
        } else {
            anchor.html("<img src=\"/img/btn/btn_jobclose_01.gif\" alt=\"職種を閉じる\" width=\"90\" height=\"22\" class=\"btn\" />");
            anchor.parent("p#jobTypeChangeBtn").attr("class", "open");
        }
    });
}

// 検索フォームのセレクトボックスをドロップダウンェックリストにする
function initDropdownchecklist(){

    $("table.searchCondition select[multiple]").each(function(){
        var height, maxHeights;
        maxHeights = {
            prefValue: 260,
            businessValue: 260,
            employValue: 200,
            specialityValue: 190,
            specialistValue: 190
        };
        // 選択肢が少ないときは、少ないなりに高さ調整
        height = jQuery(this).find('option').length * 23;

        if (height > maxHeights[this.id]) {
            height = maxHeights[this.id];
        }

        jQuery(this).dropdownchecklist( {maxDropHeight: height, width: 210} );
    });
}



function initTextField(){
    var target;
    target = jQuery('input:text[title]');
    target.each(function(){
        options = {
            word: jQuery(this).attr('title')
        }
        jQuery(this).placeholder(options);
    });
    // リロード時に文字列がのこってしまうものの対策
    jQuery(window).unload(function(){
        target.each(function(){
            if (jQuery(this).hasClass('placeholder')){
                jQuery(this).val('');
            }
        });
    });
}

function attachFormReset() {
    function formReset() {
        var form;
        form = jQuery('div#blockSearchBody');
        form.find('input:checked').attr('checked', 0);
        form.find('input:text').val('').blur();
        jQuery('.ui-dropdownchecklist-dropcontainer').find('input:checkbox:checked').next('span').click();
        return false;
    }
    $('a#formReset').click(formReset);
}


$(document).ready(toggleJobTypes);
$(document).ready(initDropdownchecklist);
$(document).ready(initTextField);
$(document).ready(attachFormReset);
