﻿// JScript 文件
function writeLeave(A,B,C,D)
{
    var E=getStringLen(A.value,1);
    if(E==0){try{B.value=maxl;}catch(e){}try{B.innerHTML=C;}catch(e){}try{D.disabled=true;}catch(e){}}
    else if(E>C){A.value=cutString(A.value,C,1);try{B.value=0;}catch(e){};try{B.innerHTML=0;}catch(e){};try{D.disabled=false;}catch(e){};}
    else{try{B.value=C-E;}catch(e){};try{B.innerHTML=C-E;}catch(e){};try{D.disabled=false;}catch(e){};}
};
function inputtext(A,C)
{
    if(getStringLen(A.value,2)>C)
    {
        var value=A.value;
        for(var i=C;getStringLen(value,2)>C;i--)
        {
            value=cutString(value,i,1);
        };
        A.value=value;
    };
};
function cutString(str,cutLentth,gbkLen){return str.substring(0,cutLentth);};
function getStringLen(str,gbkLen){str=ltrim(str);if(2==gbkLen){str=str.replace(/[^\x00-\xff]/g,"**");}return str.length;};
function trim(str){return str.replace(/(^\s*)|(\s*$)/g,"");};
function ltrim(str){return str.replace(/(^\s*)/g,"");};
function rtrim(str){return str.replace(/(\s*$)/g,"");};
function emailreg(str){var test=/^[\w-]+(\.[\w-]+)*@(\w)+(\.[\w-]+)+$/;return test.test(str)};
function datereg(str){var test=/^(\d{4}|\d{3})-((0?[1-9])|(1[0-2]))-((0?[1-9])|([12][0-9])|(3[01]))$/;return test.test(str);};
function urlreg(str){var test=/^[a-zA-z]+\:\/\/(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$/;return test.test(str);};

function tdover(obj){obj.style.backgroundColor="#ffffff";};
function tdout(obj){obj.style.backgroundColor="#FFEFB6";};

function _selectadd(A,B,C){var D=document.createElement("option");D.appendChild(document.createTextNode(B));if(arguments.length==3){D.setAttribute("value",C);};A.appendChild(D);}

function OffsetTop(A){var thetop=A.offsetTop;while(A.offsetParent.tagName.toUpperCase()!="BODY"){A=A.offsetParent;thetop+=A.offsetTop;}return thetop;}
function OffsetLeft(A){var theleft=A.offsetLeft;while(A.offsetParent.tagName.toUpperCase()!="BODY"){A=A.offsetParent;theleft+=A.offsetLeft;}return theleft;}
function iframeAutoFit()
{
try{
    if(window!=parent)
    {
        var A=parent.document.getElementsByTagName("IFRAME");
        for(var i=0,l=A.length;i<l;i++)
        {
            if(A[i].contentWindow==window)
            {
                var H=ScrollHeight();
                if ( isIE ) { H += 4; } else if ( isOpera ) { H += 1; };
                A[i].style.height = H + "px";
                continue;
            };
        };
    };
}catch(ex){alert("脚本无法跨域操作！");}
};

function ClientWidth(){var theWidth = 0;if(window.innerWidth){theWidth = window.innerWidth }else if (document.documentElement && document.documentElement.clientWidth){ theWidth = document.documentElement.clientWidth } else if (document.body){theWidth = document.body.clientWidth }return theWidth;};
function ClientHeight(){var theHeight = 0;if (window.innerHeight) { theHeight = window.innerHeight;}else if (document.documentElement && document.documentElement.clientHeight) { theHeight = document.documentElement.clientHeight }else if (document.body) { theHeight = document.body.clientHeight }return theHeight;};
function ScrollTop()
{
    var theSTop = 0;
    if(document.documentElement&&document.documentElement.scrollTop){theSTop = document.documentElement.scrollTop;}
    else if (document.body && isIE) {theSTop = document.body.scrollTop;};
    return theSTop;
};
function ScrollHeight()
{
    var theSHeight = 0;
    if(document.documentElement&&document.documentElement.scrollHeight){theSHeight = document.documentElement.scrollHeight;}
    else if (document.body && isIE) {theSHeight = document.body.scrollHeight;};
    return theSHeight;
};
function ScrollLeft()
{
    var theSLeft = 0;
    if(document.documentElement&&document.documentElement.scrollLeft){theSLeft = document.documentElement.scrollLeft;}
    else if (document.body && isIE) {theSLeft = document.body.scrollLeft;};
    return theSLeft;
};
function ScrollWidth()
{
    var theSWidth = 0;
    if(document.documentElement&&document.documentElement.scrollWidth){theSWidth = document.documentElement.scrollWidth;}
    else if (document.body && isIE) {theSWidth = document.body.scrollWidth;};
    return theSWidth;
};

function isEmail(A){return /^[\w-]+(\.[\w-]+)*@(\w)+(\.[\w-]+)+$/.test(A);};
function isDateTime(A)
{
    if(A==''){return true;}
    else if(!/^\d{8}$/.test(A)){return false;}
    else
    {
        var Y=A.substring(0,4),M=A.substring(4,6),D=A.substring(6,8),datetime=new Date(Number(Y),Number(M)-1,Number(D));
        if (isNaN(datetime)){return false;};
        else
        {
            var newY=String(datetime.getFullYear()),newM=String(datetime.getMonth()+1),newD=String(datetime.getDate()),B=newY+(newM.length==2?newM:"0"+newM)+(newD.length==2?newD:"0"+newD);
            if(A==B){return true;}else{return false;};
         };
    };
};
function isyyyyMMdd(A)
{
    if(!/^\d{8}$/.test(A)) { return false; }
    else
    {
        var Y = A.substring(0,4),M = A.substring(4,6),D = A.substring(6,8);
        var datetime = new Date(Number(Y),Number(M)-1,Number(D));
        if (isNaN(datetime)){ return false;};
        else
        {
            var newY = String(datetime.getFullYear()),newM=String(datetime.getMonth()+1),newD=String(datetime.getDate());
            while (newY.length < 4){ newY = "0" + newY;};while (newM.length < 2){ newM = "0" + newM;};while (newD.length < 2){ newD = "0" + newD;};
            if( Y == newY && M == newM && D == newD){ return true;} else { return false;};
         };
    };
};
function isyyyy_MM_dd(A)
{
    if(!/^\d{4}-\d{2}-\d{2}$/.test(A)) { return false; }
    else
    {
        var Y = A.substring(0,4),M = A.substring(5,7),D = A.substring(8,10);
        var datetime = new Date(Number(Y),Number(M)-1,Number(D));
        if (isNaN(datetime)){ return false;};
        else
        {
            var newY = String(datetime.getFullYear()),newM=String(datetime.getMonth()+1),newD=String(datetime.getDate());
            while (newY.length < 4){ newY = "0" + newY;};while (newM.length < 2){ newM = "0" + newM;};while (newD.length < 2){ newD = "0" + newD;};
            if( Y == newY && M == newM && D == newD){ return true;} else { return false;};
         };
    };
};
function isurl(A){return /^[a-zA-z]+\:\/\/(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$/.test(A);};
function isnum(A){return /^\d*$/.test(A);};
function isNum(A,kong){if(kong){return /^\d*$/.test(A);}else{return /^\d+$/.test(A);};};
function isYear(A,kong){if(isNum(A,kong)&&Number(A)<2100&&Number(A)>1900){return true;}else{return false;}};
var sUserAgent=navigator.userAgent;
var fAppVersion=parseFloat(navigator.appVersion);
var isOpera=sUserAgent.indexOf("Opera")>-1;
var isKHTML=sUserAgent.indexOf("KHTML")>-1||(sUserAgent.indexOf("Konqueror")>-1)||(sUserAgent.indexOf("AppleWebKit")>-1);
var isIE=sUserAgent.indexOf("compatible")>-1&&sUserAgent.indexOf("MSIE")>-1&&!isOpera;
var isMoz=sUserAgent.indexOf("Gecko")>-1&&!isKHTML;
var isNS4=!isIE&&!isOpera&&!isMoz&&!isKHTML&&(sUserAgent.indexOf("Mozilla")==0)&&(navigator.appName=="Netscape")&&(fAppVersion>=4.0&&fAppVersion<5.0);
var isWin=(navigator.platform=="Win32")||(navigator.platform=="Windows");
var isMac=(navigator.platform=="Mac68k")||(navigator.platform=="MacPPC")||(navigator.platform=="Macintosh");
var isUnix=(navigator.platform=="X11")&&!isWin&&!isMac;
var EventUtil = new Object;
EventUtil.addEventHandler=function(oTarget,sEventType,fnHandler){if(oTarget.addEventListener){oTarget.addEventListener(sEventType,fnHandler,false);}else if(oTarget.attachEvent){oTarget.attachEvent("on"+sEventType,fnHandler);}else{oTarget["on"+sEventType]=fnHandler;}};
EventUtil.removeEventHandler=function(oTarget,sEventType,fnHandler){if(oTarget.removeEventListener){oTarget.removeEventListener(sEventType,fnHandler,false);}else if(oTarget.detachEvent){oTarget.detachEvent("on"+sEventType,fnHandler);}else {oTarget["on"+sEventType]=null;}};
EventUtil.formatEvent=function(oEvent){if(isIE && isWin){oEvent.charCode=(oEvent.type=="keypress")?oEvent.keyCode:0;oEvent.eventPhase=2;oEvent.isChar=(oEvent.charCode>0);oEvent.pageX=oEvent.clientX+document.body.scrollLeft;oEvent.pageY=oEvent.clientY+document.body.scrollTop;oEvent.preventDefault=function(){this.returnValue=false;};if (oEvent.type=="mouseout"){oEvent.relatedTarget=oEvent.toElement;}else if(oEvent.type=="mouseover"){oEvent.relatedTarget = oEvent.fromElement;}oEvent.stopPropagation=function(){this.cancelBubble=true;};oEvent.target=oEvent.srcElement;oEvent.time=(new Date).getTime();}return oEvent;};
EventUtil.getEvent=function(){if (window.event){return this.formatEvent(window.event);}else{return EventUtil.getEvent.caller.arguments[0];}};
function CookieEnable(){if(navigator.cookiesEnabled){return true;}document.cookie="testcookie=yes;";var A=document.cookie;var B=new Date();B.setTime(B.getTime()-10000);document.cookie="testcookie=yes;expires="+B.toGMTString();if (A.indexOf("testcookie=yes")>-1){return true;}else{return false;}}
function CreateElement(tagname,cssText,id,value){var obj=document.createElement(tagname);obj.style.cssText=cssText;if ( id != "" && id != null ) { obj.id = id; };if ( value != null && value != "" ) { obj.innerHTML = value; };return obj;};
function newimage(img,iwidth,iheght)
{
    var image=new Image();
    image.src=img.src;
    width=iwidth||400;
    height=iheght||300;
    if(image.width>width||image.height>height){var w=image.width/width,h=image.height/height;if(w>h){img.width=width;img.height=image.height/w;}else{img.height=height;img.width=image.width/h;};};
};
function Imagechange(obj,iwidth,iheight)
{
    var width=obj.width+2,height=obj.height+2;
    if(width<iwidth&&height<iheight)
    {
        obj.height=height;
        obj.width=width;
        setTimeout(function(){Imagechange(obj,iwidth,iheight);},10);
    }
    else{obj.height=iheight;obj.width=iwidth;}
};
function G_id(idname){return document.getElementById(idname);};
/**AJAX**/
function createXmlDom()
{
    if(window.ActiveXObject)
    {
        var A = ["MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument","Microsoft.XmlDom"];
        for(var i = 0;i<A.length;i++)
        {
            try
            {
                var B = new ActiveXObject(A[i]);
                return B;
            }
            catch(e){}
        };
        throw new Error("MSXML is not installed on your system.");
    }
    else if(document.implementation && document.implementation.createDocument)
    {
        var A = document.implementation.createDocument("","",null);
        A.parseError = {valueOf:function(){return this.errorCode;},toString:function(){return this.errorCode.toString()}};
        A.__initError__();
        A.addEventListener("load",function(){this.__checkForError__();this.__changeReadyState__(4);},false);
        return A;
    }
    else{throw new Error("你的浏览器不支持 XML Dom Object。");}
    if(isMoz)
    {
        Document.prototype.readyState = 0;
        Dodument.prototype.onreadystatechange = null;
        Document.prototype.__changeReadyState__ = function(A){this.readyState = A;if(typeof this.onreadystatechange == "function"){this.onreadystatechange();}};
        Document.prototype.__initError__ = function(){this.parseError.errorCode = 0;this.parseError.filepos = -1;this.parseError.line = -1;this.parseError.linepos = -1;this.parseError.reason = null;this.parseError.srcText = null;this.parseError.url = null;};
        Document.prototype.__checkForErrors__ = function(){if(this.documentElement.tagName == "parseerror"){var A = />([\s\S]*?)Location:([\s\S]*?)Line Number (\d+),Column(\d+):<sourcetext>([\s\S]*?)(?:\-*\^)/;A.test(this.xml);this.parseError.errorCode = -999999;this.parseError.reason = RegExp.$1;this.parseError.url = RegExp.$2;this.parseError.line = parseInt(RegExp.$3);this.parseError.linepos = parseInt(RegExp.$4);this.parseError.srcText = RegExp.$5;}};
        Document.prototype.loadXML = function(sXml){this.__initError__();this.__changeReadyState__(1);var A = new DomParser();var B = A.parseFromString(sXml,"text/xml");while(this.firstChild){this.removeChild(this.firstChild);}for(var i = 0;i<B.childNodes.length;i++){var C = this.importNode(B.childNodes[i],true);this.appendChild(C);}this.__checkForError__();this.__changeReadyState__(4);};
        Document.prototype.__load__ = Document.prototype.load;
        Document.prototyoe.load = function(A){this.__initError__();this.__changeReadyState__(1);this.__load__(A);};
        Node.prototype.__defineGetter__("xml",function(){var A = new XMLSerializer();return A.serializeToString(this,"text/xml");});
    };
};
function createXMLHTTP()
{
    var A =["MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
    for(var i=0;i<A.length;i++)
    {
    try{var B=new ActiveXObject(A[i]);return B;}catch(e){}
    };
    throw new Error("MSXML is not installed on your system.");
};
var bXmlHttpSupport=(typeof XMLHttpRequest=="object"||window.ActionXObject);
var Http=new Object;
Http.getf=function(sURL,fnCallback)
{
    if(bXmlHttpSupport)
    {
        var oRequest=createXMLHTTP();
        oRequest.open("get",encodeURI(sURL),true);
        oRequest.onreadystatechange=function()
        {
            if(oRequest.readyState==4){fnCallback(oRequest.responseText);};
        };
        oRequest.send(null);
    }
    else if(navigator.javaEnabled()&&typeof java !="undefined"&&typeof java.net!="undefined")
    {
        setTimeout(function(){fnCallback(httpGet(sURL));},10);
    }
    else {alert("你的浏览器不支持 HTTP requests.");};
};
Http.post=function (sURL,sParams,fnCallback)
{
    if(bXmlHttpSupport)
    {
        var oRequest=createXMLHTTP();
        oRequest.open("post",encodeURI(sURL),true);
        oRequest.serRequestHeader("Content-Type","application/x-www-form-urlencoded");
        oRequest.onreadystatechange=function()
        {
            if(oRequest.readyState==4){fnCallback(oRequest.responseText);};
        };
        oRequest.send(sParams);
    }
    else if(navigator.javaEnabled()&&typeof java !="undefined"&&typeof java.net!="undefined")
    {
        setTimeout(function(){fnCallback(httpPost(sURL,sParams));},10);
    }
    else {alert("你的浏览器不支持 HTTP requests.");};
};
function httpGet(sURL)
{
    var oURL=new java.net.URL(sURL);
    var oStream=oURL.openStream();
    var oReader=new java.io.BufferedReader(new java.io.InputStreamReader(oStream));
    var sResponseText="";
    var sLine=oReader.readLine();
    while(sLine!=null)
    {
        sResponseText+=sLine+"\n";
        sLine=oReader.readLine();
    };
    oReader.close();
    return sResponseText;
};
function httpPost(sURL,sParams)
{
    var oURL=new java.net.URL(sURL);
    var oConnection = oURL.openConnection();
    oConnection.setDoInput(true);
    oConnection.setDoOutput(true);
    oConnection.setUseCaches(false);
    oConnection.setRequestProperty("Content-Type","application/x-www-form-urlencodeed");
    var oOutput=new java.io.DataOutputStream(oConnection.getOutputStream());
    oOutput.writeBytes(sParams);
    oOutput.flush();
    oOutput.close();
    var sLine="",sResponseText="";
    var oInput =new java.io.DataInputStream(oConnection.getInputStream());
    sLine=oInput.readLine();
    while(sLine!=null)
    {
        sResponseText+=sLine+"\n";
        sLine=oInput.readLine();
    };
    oInput.close();
    return sResponseText;
};
function addPostParam(A,B,C){if(A.length>0)A+="&";return A+encodeURIComponent("<#"+B+">")+"="+encodeURIComponent(C.replace("&",""));};