﻿/// <reference path="../../js/jquery/jquery126.js" />
/// <reference path="../../js/jquery/JQuery.Intellisense.js" />
window.checklogin = true;
if ($.cookie && window.checklogin) {
    window.setInterval(function() {
        if ($.cookie("UserID") == null) {
            alert("请登陆后再操作！");
            window.top.document.location.href = "/manage/login.shtml";
        }
        else if ($.cookie("IsAdmin") == null) {
            if (document.location.href.indexOf("index.html") == -1) {
                alert("您没有操作的权限！");
                document.location.href = "about:blank";
            }
        }
    }, 100);
}

Function.prototype.json = function(jsonurl, data) {
    var callback = this;
    var args = arguments;
    var method = "GET";
    var postPras = "";
    var arrPras = jsonurl.split("/");
    if (jsonurl.indexOf("/") > -1) {
        if (arrPras.length < 2) {
            alert("参数格式错误！");
            return;
        }
        postPras = "mod=" + arrPras[0] + "&action=" + arrPras[1];
        for (var i = 2; i < arrPras.length; i++) postPras += "&" + arrPras[i];
    }
    if (data && data != null && data != "") method = "POST";

    $.ajax({
        url: "../api/?" + postPras,
        type: method,
        data: data,
        dataType: 'json',
        error: function(xhr) { },
        success: function(json) {
            var args2 = new Array();
            args2[0] = json;
            for (var i = 2; i < args.length; i++) args2[i - 1] = args[i];
            callback.apply(this, args2);
        }
    });
};


function checkall(selector, name) {
    $(selector).click(function() {
        if ($(this).attr("checked") == true) { // 全选
            $("input[@name='" + name + "']").each(function() {
                $(this).attr("checked", true);
            });
        } else { // 取消全选
            $("input[@name='" + name + "']").each(function() {
                $(this).attr("checked", false);
            });
        }
    });
}

function getTableCheckValues(selector) {
    var ids = "";
    $(selector).each(function() {
        if (this.checked) {
            ids += this.value + ",";
        }
    });
    if (ids != "") ids = ids.substring(0, ids.length - 1);
    return ids;
}

// 获取元素的纵坐标
function getTop(e) {
    var offset = e.offsetTop;
    if (e.offsetParent != null)
        offset += getTop(e.offsetParent);
    return offset;
}

// 获取元素的横坐标
function getLeft(e) {
    var offset = e.offsetLeft;
    if (e.offsetParent != null)
        offset += getLeft(e.offsetParent);
    return offset;
}

