﻿$(function () {
    //init
    var d = $(document);
    var d_w = d.width();
    var d_h = d.height();
    $('.indsel,')
    $('.overlay').width(d_w).height(d_h);
    $('#sch_industryset').click(function () {
        $('.overlay').fadeTo('fast', 0.7, function () {
            restpos();
            $('.indsel').show();
        });
    });

    $('#sch_jobset').click(function () {
        $('.overlay').fadeTo('fast', 0.7, function () {
            restpos();
            $('.funcsel').show();
        });
    });

    $('#indsel_list input').click(indeselClick);
    $('.seltitle a[rel=close]').click(function () {
        $(this).parent().parent().parent("div").hide();
        $('.overlay').fadeOut();
    });

    $('.seltitle a[rel=clearInd]').click(function () {
        $('#indsel_list :checkbox').each(function (i) {
            this.checked = false;
        });
        $('#SeledInd').empty();

    });
    $('.seltitle a[rel=clearFunc]').click(function () {
        $('#funcselUPP :checkbox').each(function (i) {
            this.checked = false;
        });
        $('#Seled_func').empty();
    });

    $('.funcselUPP_msg').click(function () {
        curmsg = $(this);
        var curid = $(this).attr('rel');

        $('#funcselUPP').css({
            left: function () {
                return curmsg.position().left + 'px';
            },
            top: function () {
                return curmsg.position().top + 21 + 'px';
            }
        }).slideDown('fast').html('加载中...');
        $.get("/scripts/SubFunc.aspx", { id: curid }, function (data) {
            var d = $(data).find('#f').html();
            $('#funcselUPP').html(d);
            bindingClick();
        });
    });

});
function restpos() {
    $('.indsel, .funcsel').css({
        left: function () { return (($(document).width() - $(this).width()) / 2); },
        top: function () { return ($(document).scrollTop() + 40); }
    });
}

function indeselClick() {
    if ($(this).attr("checked") == true) {
        var base = $('#SeledInd span');

        if (base.length >= 5) {
            alert("只能选择最多5项");
            return false;
        }        
        var j8mao = $('<span class="seledInd" title="' + $(this).val() + '"><input name="hidInds" type="hidden" value="' + $(this).val() + '" checked="checked" />' + $(this).val() + "</span>");
        $('#SeledInd').append(j8mao);
    } else {
        $('#SeledInd span[title="' + $(this).val() + '"]').remove();
    }
}

function bindingClick() {
    $('#closeBtn').click(function () {
        $('#funcselUPP').hide();
    });
    $('#funcselUPP input').click(function () {
        if ($(this).attr("checked")) {
            if ($('#Seled_func span').length < 5) {
                var li = $('#Seled_func').find('span[rel=func_' + $(this).val() + ']').length;
                if (li == 0) {
                    var atc = $('<span title="点击删除该项" class="seledFunc" rel="func_' + $(this).val() + '"><input name="hidFunc" type="hidden" value="' + $(this).val() + '" />' + $(this).next('label').html() + '</span>')
                    atc.click(function () {
                        $('#funcselUPP input[value='+ $(this).find('input').val() +']').attr('checked',false);
                        $(this).remove(); 
                    });
                    $('#Seled_func').append(atc);
                }
            } else {
                alert("只能选择最多5项");
                return false;
            }
        } else {
            $('#Seled_func span[rel=func_' + $(this).val() + ']').remove();
        }
    });
}
