String.prototype.Trim = function() { 
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function() {
    return this.replace(/(^\s*)/g, "");
}
String.prototype.RTrim = function() {
    return this.replace(/(\s*$)/g, "");
} 
// 获得下一个元素对象(nodeType=1)
function $NE(e) {
    e = e.nextSibling;
    while (e && e.nodeType != 1) { e = e.nextSibling; }
    return e;
}
// 获得上一个元素对象(nodeType=1)
function $PE(e) {
    e = e.previousSibling;
    while (e && e.nodeType != 1) { e = e.previousSibling; }
    return e;
}
// 获得第一个元素对象(nodeType=1)
function $FE(e) {
    e = e.firstChild;
    while (e && e.nodeType != 1) { e = e.firstChild; }
    return e;
}
// 获得最后一个元素对象(nodeType=1)
function $LE(e) {
    e = e.lastChild;
    while (e && e.nodeType != 1) { e = e.lastChild; }
    return e;
}
function CancelBubble(eventTag)
{
    var e = eventTag ? eventTag : window.event;
    if (e && e.stopPropagation) {
        e.stopPropagation();
    }
    else {
        window.event.cancelBubble = true;
    }
    return false;
}
function click(f) {
    f.className = "mover";
    //写入Cookies
    SetCookie("lastclick", f.id);
}
function GetCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie(name, value) {
    var expdate = new Date();
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    if (expires != null) expdate.setTime(expdate.getTime() + (expires * 1000));
    document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + expdate.toGMTString()))
		+ ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain))
		+ ((secure == true) ? "; secure" : "");
}
function DelCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = GetCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
function GetCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return GetCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}
function addEventHandler(oTarget, sEventType, fnHandler) {
    if (oTarget.addEventListener) {
        oTarget.addEventListener(sEventType, fnHandler, false);
    } else if (oTarget.attachEvent) {
        oTarget.attachEvent("on" + sEventType, fnHandler);
    }
}
function delEventHandler(oTarget, sEventType, fnHandler) {
    if (oTarget.removeEventListener) {
        oTarget.removeEventListener(sEventType, fnHandler, false);
    } else if (oTarget.attachEvent) {
        oTarget.detachEvent("on" + sEventType, fnHandler);
    } 
}
var windowname = "cyz";
function blackbg() {
    var bgdiv = document.createElement("div");
    bgdiv.id = windowname + "_blackbgdiv";
    bgdiv.name = windowname + "$blackbgdiv";

    bgdiv.style.backgroundColor = "black";
    bgdiv.style.width = "100%";
    bgdiv.style.height = "100%";
    bgdiv.style.filter = "Alpha(opacity=60)";
    bgdiv.style.opacity="0.60";
    bgdiv.style.position = "absolute";
    bgdiv.style.top = document.documentElement.scrollTop + "px";
    bgdiv.style.left = "0";
    bgdiv.style.zIndex = "0";
    document.body.appendChild(bgdiv);

    //绑定滚动事件
    addEventHandler(window, "scroll", changebg);
}
function changebg() {
    var bgdiv = document.getElementById(windowname + "_blackbgdiv");
    if (bgdiv != null) {
        bgdiv.style.top = Math.floor(document.documentElement.scrollTop) + "px";
        bgdiv.style.left = Math.floor(document.documentElement.scrollLeft) + "px";
    }
}
function clearbg() {
    //卸载滚动事件
    delEventHandler(window, "scroll", changebg);
    var bgdiv = document.getElementById(windowname + "_blackbgdiv");
    if (bgdiv != null)
        document.body.removeChild(bgdiv);
}
function InsertFlash(elm, url, w, h) {
    if (!document.getElementById(elm)) return;
    var o = '';
    o += '<object width="' + w + '" height="' + h + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
    o += '<param name="wmode" value="transparent">';
    o += '<param name="menu" value="false">';
    o += '<param name="quality" value="best">';
    o += '<param name="movie" value="' + url + '">';
    o += '<embed width="' + w + '" height="' + h + '" src="' + url + '" quality="best" wmode="opaque" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>';
    o += '</object>';
    document.getElementById(elm).innerHTML = o;
}

function divwindow(divtitle, url) {
    //增加操作窗口
    var SearchWindow = document.createElement("div");
    SearchWindow.id = windowname + "_searchwindow";
    SearchWindow.name = windowname + "$searchwindow";
    SearchWindow.style.top = Math.floor((document.documentElement.clientHeight - 300) / 2 + document.documentElement.scrollTop) + "px";
    SearchWindow.style.left = Math.floor((document.documentElement.clientWidth - 400) / 2 + document.documentElement.scrollLeft) + "px";
    SearchWindow.className = "DialogWindow";

    //窗口标题
    var topdiv = document.createElement("div");
    topdiv.id = windowname + "_top";
    topdiv.name = windowname + "_top";
    topdiv.className = "top";
    //标题
    var title = document.createElement("div");
    title.innerHTML = divtitle;
    title.className = "title";
    topdiv.appendChild(title);
    //关闭按钮
    var closebutton = document.createElement("input");
    closebutton.id = windowname + "_closebutton";
    closebutton.name = windowname + "_closebutton";
    closebutton.type = "button";
    closebutton.value = "";
    closebutton.className = "closebtn";
    addEventHandler(closebutton, "click", closewindow);
    topdiv.appendChild(closebutton);
    SearchWindow.appendChild(topdiv);
    //插入一个iframe
    iframe = document.createElement("iframe");
    iframe.id = windowname + "_iframe";
    iframe.name = windowname + "_iframe";
    iframe.className = "iframe";
    iframe.frameBorder = "none";
    if (url.indexOf("?")>-1) {
        url += "&r=" + Math.random();
    }
    else {
        url += "?r=" + Math.random();
    }
    iframe.src = url;
    
    SearchWindow.appendChild(iframe);

    //生成用户操作栏
    tooldiv = document.createElement("div");
    tooldiv.id = windowname + "_tool";
    tooldiv.name = windowname + "_tool";
    tooldiv.className = "tooldiv";
    SearchWindow.appendChild(tooldiv);

    //关闭按钮
    var closetool = document.createElement("input");
    closetool.id = windowname + "_closetool";
    closetool.name = windowname + "_closetool";
    closetool.type = "button";
    closetool.value = "关闭";
    closetool.className = "closetool";
    addEventHandler(closetool, "click", closewindow);
    tooldiv.appendChild(closetool);
    
    document.body.appendChild(SearchWindow);
    //加载事件
    addEventHandler(window, "resize", resizediv);
    addEventHandler(window, "scroll", resizediv);
}
function resizediv() {
    var div = document.getElementById(windowname + "_searchwindow");
    if (div != null) {
        div.style.top = Math.floor((document.documentElement.clientHeight - 300) / 2 + document.documentElement.scrollTop) + "px";
        div.style.left = Math.floor((document.documentElement.clientWidth - 400) / 2 + document.documentElement.scrollLeft) + "px";
    } 
}
function closewindow() {
    //卸载事件
    delEventHandler(window, "resize", resizediv);
    delEventHandler(window, "scroll", resizediv);
    var div = document.getElementById(windowname + "_searchwindow");
    if (div != null)
        document.body.removeChild(div);
    clearbg();
    if (arguments[0]==1) {
        //刷新
        location.reload();
    }
}
function request(vname) {
    var href = location.href;
    var querystring = href.substr(href.indexOf("?") + 1);
    if (querystring != href) {
        var qarr = querystring.split("&");
        for (var i = 0; i < qarr.length; i++) {
            var sarr = qarr[i].split("=");
            if (sarr[0] == vname) {
                return sarr[1];
            }
        }
    }
    return "";
}
/*菜单*/
function leftnavclick(li) {
    var hiddenli = $NE(li);
    if (hiddenli != null) {
        if (hiddenli.className != "hiddenlist") {
            hiddenli.className = "hiddenlist";
        }
        else {
            hiddenli.className = "displaylist";
        }
        //记录
        var ul = hiddenli.parentNode;
        var recordlist = "";
        for (var i = 0; i < ul.childNodes.length; i++) {
            var templi;
            while (typeof (ul.childNodes[i]) != "undefined" && (ul.childNodes[i].nodeType != 1 || ul.childNodes[i].onclick != undefined || ul.childNodes[i].id == "bottomdiv")) {
                i++;
            }
            if (typeof(ul.childNodes[i]) != "undefined") {
                templi = ul.childNodes[i];
                if (templi.className == "hiddenlist")
                    recordlist += "1";
                else
                    recordlist += "0";
                recordlist += ",";
            } 
        }
        if (recordlist.length > 1)
            recordlist = recordlist.substr(0, recordlist.length - 1);
        //写入Cookies
        SetCookie("leftnav", recordlist);
    }
    else {
        alert("未找到内容块");
    }
}
function AddBalance() {
    //加载黑色背景
    blackbg();
    //显示对话框
    if(arguments[0]==null)
        divwindow("用户预存款处理", "UserBalanceAdd.aspx?username=");
    else
        divwindow("用户预存款处理", "UserBalanceAdd.aspx?username="+arguments[0]);

}
