function submit_depart_url(){
    $("#update_depart_url_notice").hide();
    $.ajax({
        url: "/managements/check_depart_identifier",
        data: {depart: $("input[name='depart']").val().trim(), identifier: $("input[name='identifier']").val().trim()},
        success: function(data){
            if(data.result){
                $("#update_depart_url_notice").hide();
                $('#update_depart_url_form').submit();
                hideModal();
            } else {
                $("#update_depart_url_notice").html("url不能重复").show();
            }
        }

    });
}

function submit_depart_host_count(){
    if($("input[name='host_count']").val().trim() == ""){
        $("#update_depart_host_count_notice").html("请输入云主机数").show();
    } else {
        $("#update_depart_host_count_notice").hide();
        $('#update_host_count_form').submit();
        hideModal();
    }
}

function submit_depart_name_form(){
    if($("input[name='depart_name']").val().trim() == ""){
        $("#update_depart_name_notice").html("名称不能为空").show();
    } else {
        $.ajax({
            type: "GET",
            url: '/managements/check_depart_name',
            data: {depart_id: $("#update_depart_name_depart_id").val(), depart_name: $("input[name='depart_name']").val().trim()},
            success: function (data) {
                if(data.status == 0){
                    $("#update_depart_name_notice").hide();
                    $('#update_depart_name_form').submit();
                    hideModal();
                } else{
                    $("#update_depart_name_notice").html("该名称已存在").show();
                }
            }
        });
    }
}

/*--------------------------- 用户授权全选 -------------------------------*/
$("#all_member_select").live('click', function(){
    if($("#all_member_select").is(':checked')){
        $("input[name='member_ids[]']").attr("checked", "checked");
    } else {
        $("input[name='member_ids[]']").removeAttr("checked");
    }
});
$("input[name='member_ids[]']").live('click', function(){
    if($("input[name='member_ids[]']:checked").length == $("input[name='member_ids[]']").length){
        $("#all_member_select").attr("checked", "checked");
    } else{
        $("#all_member_select").removeAttr("checked");
    }
});

/*-------------------------- 下拉框点击事件 -------------------------------*/
$(".edu-admin-option").live("click", function(ev){
    var tText = $(ev.target).html();
    var tVal = $(ev.target).attr("data-val");
    var $hMain = $(ev.target).parent().parent();
    $hMain.find('p').html(tText + "<i class='fa fa-caret-down ml10'></i>");
    $hMain.find('input').attr("value", tVal);
    $(ev.target).parent().hide();
    console.log($(ev.target).parent()[0]);
    console.log($(ev.target).html());
    console.log(tVal);
    // 只有授权按钮才提交表单
    var sub = ["trial_agree", "trial_cancel", "realname_agree", "realname_cancel", "occupation_agree", "occupation_cancel"];
    if(sub.indexOf(tVal) >= 0){
        $('#management_search_user').submit();
        $hMain.find('input').attr("value", "");
    }
});

/*------------------- 绑定按钮移入移除效果 --------------------------*/
$(".edu-position").live("mouseover", function(){
    $(this).find('ul').show();
});
$(".edu-position").live("mouseout", function(){
    $(this).find('ul').hide();
});

/*------------------------清除按钮-------------------------*/
$("#clear_contents").live("click", function(){
    $("input[name='research_contents']").val("");
});

/*-----------------------试用授权列表的只看t,只看e---------------------*/
$(function(){
    $("#only_t, #only_e").on("click", function () {
        $.ajax({
            type: "get",
            url: '/managements/users_trial',
            data: {t:$("#only_t").is(":checked") ? 1 : 0,
                    e:$("#only_e").is(":checked") ? 1 : 0},
            dataType: "script"
        });
    });
});