﻿/// <reference path="../../jQuery-vsdoc.js" />
function isie() {
    if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
        return true;
    }
    else {
        return false;
    }
}

function checkclick(msg,url){
    if(confirm(msg)){
        window.location.href=url;
    }
}
/*
function SeclectAll(flag,obj)
{
	var ak=document.getElementsByTagName("INPUT");
	if(obj && !obj.checked)
	{
		flag="0";
	}
	for (var i=0;i<ak.length;i++)
	{
		var e = ak[i];
		switch (flag)
		{
		case "0":
			e.checked = false;
			break;
		case "1":
			if (e.type=='checkbox'){
				e.checked = true;
			}
			break;
		case "2":
			if(e.type=='checkbox' && e.checked && e.name !='chkall')
			{
				e.checked=false;
			}
			else
			{
				e.checked=true;
			}
			if (e.type=='checkbox' && e.name =='chkall'){
				e.checked = false;
			}
			break;
		}
	}
}
*/
function SeclectAll(flag, obj) {
    if (!obj) {
        obj = ".STable";
    }
    switch (flag) {
        case "0":
            $(obj).unCheckCheckboxes();
            break;
        case "1":
            $(obj).checkCheckboxes();
            break;
        case "2":
            $(obj).toggleCheckboxes();
            break;
    }
}

/*是否显示搜索信息*/
function sw_search() {
    var searhide = $("#search_hidden");
    if (searhide.css("display") == "none") {
        $("#search_icon").innerHTML = "&nbsp;+&nbsp;显示快速搜索或说明";
        $("#search_content").hide();
        $("#search_hidden").show();
    }
    else {
        $("#search_icon").innerHTML = "&nbsp;-&nbsp;隐藏快速搜索或说明";
        $("#search_content").show();
        $("#search_hidden").hide();
    }
}

/*检查登录*/
function checklogin() {
    $("#tips").html("");
    if ($.trim($("#username").val()) == "") {
        $("#tips").html("用户名不能为空！");
        $("#username").focus();
        return;
    }
    if ($.trim($("#pwd").val()) == "") {
        $("#tips").html("密码不能为空！");
        $("#pwd").focus();
        return;
    }
    if ($.trim($("#checkcode").val()) == "") {
        $("#tips").html("验证码不能为空！");
        $("#checkcode").focus();
        return;
    }
    $("#tips").html("<img src=\"images/Loading.gif\" align=\"middle\" alt=\"\" /> 正在验证...");
    $.ajax({
        url: "../common/AjaxAdmin.aspx",
        type: "GET",
        cache: false,
        dataType: "text",
        data: { action: "chklogin", username: EncodeURL($.trim($("#username").val())), pwd: EncodeURL($.trim($("#pwd").val())), checkcode: EncodeURL($.trim($("#checkcode").val())) },
        success: function(transport) {
            if (transport == "Succeed") {
                $("#tips").html("<img src=\"images/Loading.gif\" align=\"middle\" alt=\"\" /> 登录成功，正在转入...");
                window.location.href = "admin_default.aspx";
            }
            else if (transport == "0") {
                $("#vcode").attr("src", "../common/ValidateCode.aspx?s=" + Math.random());
                $("#tips").html("验证码已过期或输入错误！");
            }
            else {
                $("#vcode").attr("src", "../common/ValidateCode.aspx?s=" + Math.random());
                $("#tips").html("用户名、密码或验证码错误！");
            }
        }
    });
}

function getposition(obj) {
    var r = new Array();
    r['x'] = obj.offsetLeft;
    r['y'] = obj.offsetTop;
    while (obj = obj.offsetParent) {
        r['x'] += obj.offsetLeft;
        r['y'] += obj.offsetTop;
    }
    return r;
}

//显示提示层
function showhintinfo(obj, objleftoffset, objtopoffset, title, info, objheight, showtype, objtopfirefoxoffset) {

    var p = getposition(obj);

    if ((showtype == null) || (showtype == "")) {
        showtype == "up";
    }
    //document.getElementById('hintiframe' + showtype).style.height = objheight + "px";
    document.getElementById("hintinfo" + showtype).innerHTML = info;
    document.getElementById("hintdiv" + showtype).style.display = "block";

    if (objtopfirefoxoffset != null && objtopfirefoxoffset != 0 && !isie()) {
        document.getElementById("hintdiv" + showtype).style.top = p["y"] + parseInt(objtopfirefoxoffset) + "px";
    }
    else {
        if (objtopoffset == 0) {
            if (showtype == "up") {
                document.getElementById("hintdiv" + showtype).style.top = p["y"] - document.getElementById("hintinfo" + showtype).offsetHeight - 35 + "px";
            }
            else {
                document.getElementById("hintdiv" + showtype).style.top = p["y"] + obj.offsetHeight + 5 + "px";
            }
        }
        else {
            document.getElementById("hintdiv" + showtype).style.top = p["y"] + (objtopoffset) + "px";
        }
    }
    document.getElementById("hintdiv" + showtype).style.left = p["x"] + (objleftoffset) + "px";
}

//隐藏提示层
function hidehintinfo() {
    document.getElementById("hintdivup").style.display = "none";
    document.getElementById("hintdivdown").style.display = "none";
}

//用于权限部分
function checkCheckboxes(obj) {
    var p1 = "0", p2 = "0";
    var curvale = obj.value;
    var curlen = curvale.length;
    if (curlen > 6 || curlen < 2) {
        alert("权限代码错误");
        return;
    } else {
        switch (curlen) {
            case 2:
            case 4:
                p1 = curvale.substring(0, 2);
                break;
            case 6:
                p1 = curvale.substring(0, 2);
                p2 = curvale.substring(0, 4);
                break;
        }
    }
    var cont = $(".edittable");
    var checked = $("input[type=checkbox]", cont);
    checked.each(function() {
        if (this.value.substring(0, curlen) == curvale) {
            this.checked = obj.checked;
        }
    });
    if (obj.checked == true) {
        checked.filter("[value='" + p1 + "']").each(function() { this.checked = true; });
        if (p2 != "0") {
            checked.filter("[value='" + p2 + "']").each(function() { this.checked = true; });
        }
    } else {

        if (p2 != "0") {
            var p2chk = checked.filter(function() {
                if (this.value.length == 6 && this.value.substring(0, 4) == p2) {
                    return this;
                }
            }).filter(":checked");
            if (p2chk.length == 0) {
                checked.filter("[value='" + p2 + "']").each(function() { this.checked = false; });
            }
        }

        if (p1 != "0") {
            var p1chk = checked.filter(function() {
                if (this.value.length == 4 && this.value.substring(0, 2) == p1) {
                    return this;
                }
            }).filter(":checked");
            if (p1chk.length == 0) {
                checked.filter("[value='" + p1 + "']").each(function() { this.checked = false; });
            }
        }
    }
}

