﻿//通用脚本程序

function jso(v)
{
    return  document.getElementById(v);
}
/*function jso(v)
{
    return document.getElementById("<%=ClientID%>_" + v);
}
*/
function e__gotoPage()
{
    __doPostBack('pager','Page$'+jso("e__pageIndex").value);
}
function _adjust(mainContainer) {

    var mc = document.getElementById(mainContainer);
    var ch = mc.childNodes[1].clientHeight;
    
    mc.firstChild.style.height = ch;
    mc.style.height = ch+10;
}
function myCorners(settings, obj) {
    if (settings["autoAdjust"] == undefined || settings["autoAdjust"] == false || typeof(obj)!="object" ) {
        curvyCorners(settings, obj);
        return;
    }
    curvyCorners(settings, obj);
    setInterval("_adjust('"+obj.id+"')", 50);
}

//打开对话框.
//默认打开不可调整大小的模式对话框
function openDialog(url,argument, width, height, resizeable, modal)
{
    if (modal == undefined || modal == null)
        modal = true;
    if (resizeable == undefined || resizeable == null)
        resizeable = false;
    if (argument == undefined || argument == null)
        argument = "";
    var isIE = false;
    if (navigator.userAgent.indexOf("MSIE") >= 0)
        isIE = true;
        
    var iTop = (window.screen.availHeight - 30 - height) / 2;       //获得窗口的垂直位置;
    var iLeft = (window.screen.availWidth - 10 - width) / 2;           //获得窗口的水平位置;
  /*  if (url.indexOf("?") > 0)
    {
        url += "&_tmr=" + new Date().getMilliseconds();
    }
    else
    {
        url += "?_tmr=" + new Date().getMilliseconds();
    }
*/
    if (isIE)
    {
        if (modal)
            return window.showModalDialog(url, argument, 'dialogHeight:' + height + 'px;dialogWidth:' + width + 'px;resizable:' + (resizeable ? 'yes' : 'no') + ';center:yes;');
        else
            return window.showModelessDialog(url, argument, 'dialogHeight:' + height + 'px;dialogWidth:' + width + 'px;resizable:' + (resizeable ? 'yes' : 'no') + ';center:yes;');
    }
    else
    {
        if (modal)
            window.open(url, argument, 'modal=yes,height=' + height + ',innerHeight=' + height + ',width=' + width + ',innerWidth=' + width + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=' + (resizeable ? 'yes' : 'no') + ',location=no,status=yes');
        else
            window.open(url, argument, 'modal=no,height=' + height + ',innerHeight=' + height + ',width=' + width + ',innerWidth=' + width + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=' + (resizeable ? 'yes' : 'no') + ',location=no,status=yes');
    }
}

function openWindow(url,name, width, height) {
    var iTop = (window.screen.availHeight - 30 - height) / 2;       //获得窗口的垂直位置;
    var iLeft = (window.screen.availWidth - 10 - width) / 2;           //获得窗口的水平位置;
    var resizeable = true;

    try {
        window.open(url, name, 'height=' + height + ',innerHeight=' + height + ',width=' + width + ',innerWidth=' + width + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=' + (resizeable ? 'yes' : 'no') + ',location=no,status=yes');
    }
    catch (e) {
        openDialog(url,null, width, height, true, false);
    }
    return false;
}


var WebRoot = window.location.href;
WebRoot = WebRoot.substr(7); //去掉http://
var __loc = WebRoot.indexOf("/");
WebRoot = WebRoot.substr(__loc+1); //去掉主机
__loc = WebRoot.indexOf("/"); //找到文件名前面的/
if (__loc < 0)
    WebRoot = "/"; //未找到
else
{
    WebRoot = WebRoot.substr(0, __loc);//去掉文件
    if (WebRoot.toLowerCase() == "admin")
        WebRoot = "/";
    else
        WebRoot = "/" + WebRoot.substr(0, __loc) + "/";
}
function showEndowDetail(eid)
{
    var url = WebRoot + "EndowDetail.aspx?type=1&id=" + eid + "&isDialog=1";
    openWindow(url,"endowDetail"+eid , 750, 500);
    
    return false;
}
function showDonorInfo(did)
{
    var url = WebRoot + 'Admin/DonorInfo.aspx?did=' + did + "&isDialog=1";
    //openDialog(url, null, 600, 360, true, false);
    openWindow(url,"donorInfo"+did, 600, 360);
    return false;
}
function showSchoolInfo(schid)
{
    var url = WebRoot + "SchoolInfo.aspx?schid=" + schid + "&isDialog=1";
    openDialog(url, null, 600, 400, true, false);
    return false;
}
function showStudentInfo(sid)
{
    var url = WebRoot + "StudentInfo.aspx?sid=" + sid + "&isDialog=1";
    openDialog(url, null, 600, 360, true, false);

    return false;
}
function showEndowBatchInfo(eid)
{
    var url = WebRoot + "EndowBatchInfo.aspx?batid=" + eid + "&isDialog=1";
    openDialog(url, null, 700, 380, true, false);
    return false;
}

function openDonorEditor(did)
{
    if (did == undefined)
        did = "";
    var url= WebRoot+"DonorEditor.aspx?did="+did+"&isDialog=1";
    openDialog(url,null,650,550);
    return false;
}


function resetDialogHeight()
{
    var ua = navigator.userAgent;
    var height = document.body.offsetHeight;
    if (ua.lastIndexOf("MSIE 6.0") != -1)
    {
        if (ua.lastIndexOf("Windows NT 5.1") != -1)
        {
            //alert("xp.ie6.0"); 
            var height = document.body.offsetHeight;
            window.dialogHeight = (height + 90) + "px";
        }
        else if (ua.lastIndexOf("Windows NT 5.0") != -1)
        {
            //alert("w2k.ie6.0"); 
            var height = document.body.offsetHeight;
            window.dialogHeight = (height + 49) + "px";
        }
    }
}


/**
*   注册窗口调整函数
*/
function RegisterResetDialog()
{
    resetDialogHeight();
}


var infoTrCssClass = "";
function setInfoTable()
{

}


function FilterOnOff()
{
    if (jso("dvFilter").style.display == "none")
        jso("dvFilter").style.display = "block";
    else
        jso("dvFilter").style.display = "none";
}
function HtmlEncode(str)
{
    var s = "";
    if (str.length == 0) return "";
    for (var i = 0; i < str.length; i++)
    {
        switch (str.substr(i, 1))
        {
            case "<": s += "&lt;"; break;
            case ">": s += "&gt;"; break;
            case "&": s += "&amp;"; break;
            case "   ": s += "&nbsp;"; break;
            case "\"": s += "&quot;"; break;
            case "\n": s += "<br>"; break;
            default: s += str.substr(i, 1); break;
        }
    }
    return s;
}

function loadJs(src) {
    var oHead = document.getElementsByTagName('head').item(0);

    var oScript = document.createElement("script");

    oScript.type = "text/javascript";

    oScript.src = src;

    oHead.appendChild(oScript);
}

function loadCss(src) {
    var oHead = document.getElementsByTagName('head').item(0);

    var oCss = document.createElement("link");

    oCss.type = "text/css";

    oCss.rel = "Stylesheet";
    oCss.href = src;

    oHead.appendChild(oCss);
}

function showProfileViewer(dvUserName) {
    var url = WebRoot + "Admin/ProfileViewer.aspx?DvUserName=" + encodeURIComponent(dvUserName) + "&isDialog=1";
    openDialog(url, null, 600, 280);
    return false;   
}
