


function _id(id) {
    return !id ? null : document.getElementById(id);
}

function SelectAll(aControl) {

    var tempControl = aControl;
    var isChecked = tempControl.checked;

    elem = document.getElementsByTagName("input");

    for (i = 0; i < elem.length; i++)
        if (elem[i].type == "checkbox" && elem[i].id != tempControl.id) {
            if (elem[i].checked != isChecked)
                elem[i].click();
        }
}


function openPop(url) {



    layer.open({
        type: 2,
        title: "",
        area: ['950px', '520px'],
        fix: false, //不固定
        maxmin: true,
        content: url
    });


}


function CheckHasSelect(aControl) {

    var tempControl = aControl;
    var isChecked = tempControl.checked;

    elem = document.getElementsByTagName("input");
    var count = 0;

    for (i = 0; i < elem.length; i++) {
        if (elem[i].type == "checkbox" && elem[i].id != "selectall") {
            if (elem[i].checked) {

                count = count + 1;
            }
        }
    }

    if (count > 0) {

        return confirm('确定删除选择的内容吗?');
    }
    else {
        alert("请选中要删除的内容");
        return false;
    }
}




function ShowCalendar(txt) {
    laydate();
}







function popUser(result, uid, username, displayname, dept, tel, email, staffcode) {

    var _result = result.split("$");
    if (uid != "") {
        $('#' + uid).val(_result[0]);
    }
    if (username != "") {
        $('#' + username).val(_result[1]);
    }

    if (displayname != "") {
        $('#' + displayname).val(_result[2]);
    }

    if (dept != "") {
        $('#' + dept).val(_result[3]);
    }

    if (tel != "") {
        $('#' + tel).val(_result[4]);
    }

    if (email != "") {
        $('#' + email).val(_result[5]);
    }

    if (staffcode != "") {
        $('#' + staffcode).val(_result[6]);
    }

}



/* 表格 行变色*/
function hover() {
    var $bg;
    $('#thetable table tr:not(:has("th"))').hover(

      function () {
          $bg = $(this).css('background-color');
          $(this).css('background-color', 'lightblue');
      },

      function () {
          $(this).css('background-color', $bg);
      }
     );
}






function isselect() {

    var checked = 0;
    var allvalue = '';

    var _c = 0;
    $(".ck_item").each(

     function () {
         if ($(this).is(':checked')) {
             checked++;

             if (checked > 1) {
                 allvalue += ',' + $(this).val();
             }
             else {
                 allvalue = $(this).val();
             }
         }

     });

    $("#hf_ids").val(allvalue);

    if (checked > 0) {
        return true;
    }
    else {
        layer.alert('请至少选择一条记录', 12);
        return false;
    }

}



function selectall(obj) {
    var checkFlag = $(obj).is(':checked');

    $(".ck_item").each(
        function () {
            if ($(this).prop('disabled') == false) {
                $(this).prop("checked", checkFlag);
            }
        }
        );


}












/* PopMenu */

var modclickcount = 0;
function modclick(obj, tableid) {
    var modcount = $('#modcount');
    var modlayer = $('#modlayer');
    if (obj.checked == true) {
        modclickcount++;
    }
    else {
        modclickcount--;
    }
    modcount.html(modclickcount);

    if (modclickcount > 0) {
        var top_offset = obj.offsetTop;

        while ((obj = obj.offsetParent).id != tableid) {
            top_offset += obj.offsetTop;
        }

        modlayer.css("top", top_offset + 20);
        modlayer.show();
    }
    else {
        modlayer.hide();
    }



    if (modclickcount > 1) {
        $(".export").hide();
    }
    else {
        $(".export").show();
    }

}





function checkall(obj) {
    var num = 0;
    var chks = $("#thetable input[name='listitem']");

    if ($(obj).is(':checked')) {
        chks.attr("checked", true);
        num = chks.length;
    }
    else {
        chks.attr("checked", false);
        num = 0;
    }

    modclickcount = num;

    $('#modcount').html(num);
    if (num <= 0) {
        $('#modlayer').hide();
    }
    else {
        $('#modlayer').show();
    }



    if (num > 1) {
        $(".export").hide();
    }
    else {
        $(".export").show();
    }

}







function op(action, url, popTitle, returnUrl, showIFrame) {


    var checked = 0;
    var allvalue = '';
    var chks = $("#thetable input[name='listitem']");

    chks.each(
     function () {
         if ($(this).is(":checked")) {
             checked++;
             if (checked > 1) {
                 allvalue += ',' + $(this).val();
             }
             else {
                 allvalue = $(this).val();
             }
         }
     }
    );





    $("#hf_ids").val(allvalue);




    if (!checked) {
        alert('请选择需要操作的记录');
    }
    else {

        if (action == "get") {
            return;
        }

        if (action == "delete") {
            return;
        }



        if (showIFrame) {
            ShowIframeNoScroll(url + "&ids=" + allvalue + "&returnUrl=" + returnUrl, "500", "350", popTitle);
        }
        else {
            location.href = url + "&ids=" + allvalue;
        }
    }

}



function Pop(_src, _width, _height, _title) {


    layer.open({
        type: 2,
        title: _title,
        shadeClose: true,
        shade: 0.8,
        area: [_width + 'px', _height + 'px'],
        content: _src
    });

}

function ShowIframeNoScroll(_src, _width, _height, _title) {

    layer.open({
        type: 2,
        title: _title,
        shadeClose: true,
        shade: 0.8,
        area: [_width + 'px', _height + 'px'],
        content: _src
    });

}



function ept(url) {
    // window.open(url, null, 'left=200,top=200,width=450,height=350')
    // return false;
    Pop(url, 450, 350, "导出/导入数据");

}