﻿// JScript File
function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) {
        oWindow = window.radWindow;
    }
    else if (window.frameElement.radWindow) {
        oWindow = window.frameElement.radWindow;
    }
    return oWindow;
}

function EditWindowReturn(EditType, Result, ItemID) {
    GetRadWindow().Close();
    GetRadWindow().BrowserWindow.EditWindowReturn(EditType, Result, ItemID);
    return false;
}

function EditWindowReturnA(EditType, Result, ItemID) {
    GetRadWindow().Close();
    GetRadWindow().BrowserWindow.EditWindowReturnA(EditType, Result, ItemID);
    return false;
}

function CancelEdit() {
    window.close();
    GetRadWindow().Close();
}

function CancelEdit1() {
    window.close();
    GetRadWindow().Close();
}

function refreshWindow() {
    GetRadWindow().Close();
    GetRadWindow().BrowserWindow.refreshWindow();
    return false;
}

function refreshTree(arg, RowIndex) {
    GetRadWindow().Close();
    GetRadWindow().BrowserWindow.refreshTree(arg, RowIndex);
    return false;
}

function CloseAndRebind(arg, RowIndex) {
    GetRadWindow().Close();
    GetRadWindow().BrowserWindow.refreshGrid(arg, RowIndex);
    return false;
}

function SessionClose() {
    GetRadWindow().Close();
    GetRadWindow().BrowserWindow.BackLogin();
    return false;
}

window.onload = function() {
    var btnCancel = document.getElementById("btnCancel");
    if (btnCancel != null) btnCancel.onclick = CancelEdit;
}

var LoadPageURL = "/Loading.aspx"
function OpenWindow(Purl, Ptitle, PwinWidth, PwinHeight, pWinName) {
    var oWindow = window.radopen(Purl + "&rdn=" + Math.random(), pWinName);
    oWindow.SetSize(PwinWidth, PwinHeight);
    oWindow.SetTitle(Ptitle);
    oWindow.set_modal(true);
    oWindow.Center();
    oWindow.add_close(OnWindowClientClose);
}

function OnWindowClientClose(sender, eventArgs) {
    sender.SetUrl(LoadPageURL);
}

function AddLoadHandler(pFunc) {
    if (typeof (window.onload) != 'function')
        window.onload = pFunc;
    else {
        var oldFunc = window.onload;
        window.onload = function() {
            oldFunc();
            pFunc();
        }
    }
}

function BackLogin() {
    window.location = '';
}

function SessionEnd() {
    GetRadWindow().Close();
    GetRadWindow().BrowserWindow.GotoLogin();
    return false;
}

function GotoLogin() {
    window.location.href = "SignIn.aspx";
}

function AddClickHandler(btnID, addFunc) {
    var btnSure = document.getElementById(btnID);
    if (btnSure == null)
        return false;
    var oldFunc = btnSure.onclick;
    if (typeof oldFunc == 'function') {
        btnSure.onclick = function() {
            var result = oldFunc();
            for (var validator in Page_Validators) {

                var isValidated = Page_Validators[validator].style.display;
                if (isValidated == "inline" || isValidated == "") {
                    return false;
                }

            }
            return addFunc();

        }
    }
    else {
        btnSure.onclick = function() {
            return addFunc();
        };
    }
}

function PromptFunction() {
    return confirm("你确定要执行此项操作吗?");
}

//AddLoadHandler(function()
//{
//    AddClickHandler("btnSure",PromptFunction);
//});

String.prototype.trim = function() {
    return this.replace(/(^\s+)|\s+$/g, "");
}

if (typeof (HTMLElement) != "undefined")   //给firefox定义contains()方法，ie下不起作用
{
    HTMLElement.prototype.contains = function(obj) {
        while (obj != null && typeof (obj.tagName) != "undefind") { //通过循环对比来判断是不是obj的父元素
            if (obj == this) return true;
            obj = obj.parentNode;
        }
        return false;
    };
}

function checkLen(editorID, len) {
    if (Page_ClientValidate()) {
        if (editorID != "" && $find(editorID) != null) {
            if ($find(editorID).get_html().length > len) {
                alert("您输入的字符长度太长，请按字符要求输入！");
                return false;
            }
            else return true;
        } else return false;
    }
    else {
        return false;
    }
}

function checkTxtLen(txtBoxID, len) {
    if (Page_ClientValidate()) {
        if (txtBoxID != "" && $find(txtBoxID) != null) {
            if ($find(txtBoxID).get_value().trim().length > len) {
                alert("您输入的字符长度太长，请按字符要求输入！");
                return false;
            }
            else return true;
        }
        else return false;
    }
    else {
        return false;
    }
}

var SysType = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/msie ([\d.]+)/)) ? SysType.ie = s[1] :
        (s = ua.match(/firefox\/([\d.]+)/)) ? SysType.firefox = s[1] :
        (s = ua.match(/chrome\/([\d.]+)/)) ? SysType.chrome = s[1] :
        (s = ua.match(/opera.([\d.]+)/)) ? SysType.opera = s[1] :
        (s = ua.match(/version\/([\d.]+).*safari/)) ? SysType.safari = s[1] : 0;

function showShareList(e, btShare) {
    if (SysType.ie) {
        btShare.nextSibling.style.display = "block";
        btShare.style.backgroundImage = "url(../images/share2.jpg)";
    }
    else {
        btShare.nextSibling.nextSibling.style.display = "block";
        btShare.style.backgroundImage = "url(../images/share2.jpg)";
    }

}
function hideShare(e, OutDiv) {
    if (SysType.ie) {
        if (OutDiv.contains(e.toElement)) {
            return;
        }
        else {
            OutDiv.childNodes[0].style.backgroundImage = "url(../images/share1.jpg)";
            OutDiv.childNodes[1].style.display = "none";
        }
    }
    else {
        if (OutDiv.contains(e.relatedTarget)) {
            return;
        }
        else {
            OutDiv.childNodes[1].style.backgroundImage = "url(../images/share1.jpg)";
            OutDiv.childNodes[3].style.display = "none";
        }
    }
}
           


