﻿
//获取对象 -------------------------------------------------------------------------
function $(objectID)
{
    return document.getElementById(objectID);
}
//检测浏览器 -------------------------------------------------------------------------
var sUserAgent = navigator.userAgent;
var fAppVersion = parseFloat(navigator.appVersion);

function compareVersions(sVersion1, sVersion2) {

    var aVersion1 = sVersion1.split(".");
    var aVersion2 = sVersion2.split(".");
    
    if (aVersion1.length > aVersion2.length) {
        for (var i=0; i < aVersion1.length - aVersion2.length; i++) {
            aVersion2.push("0");
        }
    } else if (aVersion1.length < aVersion2.length) {
        for (var i=0; i < aVersion2.length - aVersion1.length; i++) {
            aVersion1.push("0");
        }
    }
    
    for (var i=0; i < aVersion1.length; i++) {
 
        if (aVersion1[i] < aVersion2[i]) {
            return -1;
        } else if (aVersion1[i] > aVersion2[i]) {
            return 1;
        }
    }
    
    return 0;

}

var isOpera = sUserAgent.indexOf("Opera") > -1;
var isMinOpera4 = isMinOpera5 = isMinOpera6 = isMinOpera7 = isMinOpera7_5 = false;

if (isOpera) {
    var fOperaVersion;
    if(navigator.appName == "Opera") {
        fOperaVersion = fAppVersion;
    } else {
        var reOperaVersion = new RegExp("Opera (\\d+\\.\\d+)");
        reOperaVersion.test(sUserAgent);
        fOperaVersion = parseFloat(RegExp["$1"]);
    }

    isMinOpera4 = fOperaVersion >= 4;
    isMinOpera5 = fOperaVersion >= 5;
    isMinOpera6 = fOperaVersion >= 6;
    isMinOpera7 = fOperaVersion >= 7;
    isMinOpera7_5 = fOperaVersion >= 7.5;
}

var isKHTML = sUserAgent.indexOf("KHTML") > -1 
              || sUserAgent.indexOf("Konqueror") > -1 
              || sUserAgent.indexOf("AppleWebKit") > -1; 
              
var isMinSafari1 = isMinSafari1_2 = false;
var isMinKonq2_2 = isMinKonq3 = isMinKonq3_1 = isMinKonq3_2 = false;

if (isKHTML) {
    isSafari = sUserAgent.indexOf("AppleWebKit") > -1;
    isKonq = sUserAgent.indexOf("Konqueror") > -1;

    if (isSafari) {
        var reAppleWebKit = new RegExp("AppleWebKit\\/(\\d+(?:\\.\\d*)?)");
        reAppleWebKit.test(sUserAgent);
        var fAppleWebKitVersion = parseFloat(RegExp["$1"]);

        isMinSafari1 = fAppleWebKitVersion >= 85;
        isMinSafari1_2 = fAppleWebKitVersion >= 124;
    } else if (isKonq) {

        var reKonq = new RegExp("Konqueror\\/(\\d+(?:\\.\\d+(?:\\.\\d)?)?)");
        reKonq.test(sUserAgent);
        isMinKonq2_2 = compareVersions(RegExp["$1"], "2.2") >= 0;
        isMinKonq3 = compareVersions(RegExp["$1"], "3.0") >= 0;
        isMinKonq3_1 = compareVersions(RegExp["$1"], "3.1") >= 0;
        isMinKonq3_2 = compareVersions(RegExp["$1"], "3.2") >= 0;
    } 
    
}

var isIE = sUserAgent.indexOf("compatible") > -1 
           && sUserAgent.indexOf("MSIE") > -1
           && !isOpera;
           
var isMinIE4 = isMinIE5 = isMinIE5_5 = isMinIE6 = false;

if (isIE) {
    var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
    reIE.test(sUserAgent);
    var fIEVersion = parseFloat(RegExp["$1"]);

    isMinIE4 = fIEVersion >= 4;
    isMinIE5 = fIEVersion >= 5;
    isMinIE5_5 = fIEVersion >= 5.5;
    isMinIE6 = fIEVersion >= 6.0;
}

var isMoz = sUserAgent.indexOf("Gecko") > -1
            && !isKHTML;

var isMinMoz1 = sMinMoz1_4 = isMinMoz1_5 = false;

if (isMoz) {
    var reMoz = new RegExp("rv:(\\d+\\.\\d+(?:\\.\\d+)?)");
    reMoz.test(sUserAgent);
    isMinMoz1 = compareVersions(RegExp["$1"], "1.0") >= 0;
    isMinMoz1_4 = compareVersions(RegExp["$1"], "1.4") >= 0;
    isMinMoz1_5 = compareVersions(RegExp["$1"], "1.5") >= 0;
}

var isNS4 = !isIE && !isOpera && !isMoz && !isKHTML 
            && (sUserAgent.indexOf("Mozilla") == 0) 
            && (navigator.appName == "Netscape") 
            && (fAppVersion >= 4.0 && fAppVersion < 5.0);

var isMinNS4 = isMinNS4_5 = isMinNS4_7 = isMinNS4_8 = false;

if (isNS4) {
    isMinNS4 = true;
    isMinNS4_5 = fAppVersion >= 4.5;
    isMinNS4_7 = fAppVersion >= 4.7;
    isMinNS4_8 = fAppVersion >= 4.8;
}

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 isWin95 = isWin98 = isWinNT4 = isWin2K = isWinME = isWinXP = false;
var isMac68K = isMacPPC = false;
var isSunOS = isMinSunOS4 = isMinSunOS5 = isMinSunOS5_5 = false;

if (isWin) {
    isWin95 = sUserAgent.indexOf("Win95") > -1 
              || sUserAgent.indexOf("Windows 95") > -1;
    isWin98 = sUserAgent.indexOf("Win98") > -1 
              || sUserAgent.indexOf("Windows 98") > -1;
    isWinME = sUserAgent.indexOf("Win 9x 4.90") > -1 
              || sUserAgent.indexOf("Windows ME") > -1;
    isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 
              || sUserAgent.indexOf("Windows 2000") > -1;
    isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 
              || sUserAgent.indexOf("Windows XP") > -1;
    isWinNT4 = sUserAgent.indexOf("WinNT") > -1 
              || sUserAgent.indexOf("Windows NT") > -1 
              || sUserAgent.indexOf("WinNT4.0") > -1 
              || sUserAgent.indexOf("Windows NT 4.0") > -1 
              && (!isWinME && !isWin2K && !isWinXP);
} 

if (isMac) {
    isMac68K = sUserAgent.indexOf("Mac_68000") > -1 
               || sUserAgent.indexOf("68K") > -1;
    isMacPPC = sUserAgent.indexOf("Mac_PowerPC") > -1 
               || sUserAgent.indexOf("PPC") > -1;  
}

if (isUnix) {
    isSunOS = sUserAgent.indexOf("SunOS") > -1;

    if (isSunOS) {
        var reSunOS = new RegExp("SunOS (\\d+\\.\\d+(?:\\.\\d+)?)");
        reSunOS.test(sUserAgent);
        isMinSunOS4 = compareVersions(RegExp["$1"], "4.0") >= 0;
        isMinSunOS5 = compareVersions(RegExp["$1"], "5.0") >= 0;
        isMinSunOS5_5 = compareVersions(RegExp["$1"], "5.5") >= 0;
    }
}

//Cookie -------------------------------------------------------------------------
function Cookie(){
}
Cookie.prototype.set=function(name,value,days){
  var expires = "";
  if(days){
    var dt = new Date();
    dt.setTime(dt.getTime()+(days*24*60*60*1000));
    expires = "; expires="+dt.toGMTString();
  }
  document.cookie = name + "=" + value + expires + "; path=/";
}
Cookie.prototype.get=function(name){
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++){
        var c = ca[i];
        while (c.charAt(0)==' '){
          c = c.substring(1,c.length);
        }
        if (c.indexOf(nameEQ) == 0){
          return c.substring(nameEQ.length,c.length);
        }
  }
  return null;
}
Cookie.prototype.clear=function(name){
  this.set(name,"",-1);
}
function setCookie(sName, sValue, oExpires, sPath, sDomain, bSecure) {
    var sCookie = sName + "=" + encodeURIComponent(sValue);
    if (oExpires) {
        sCookie += "; expires=" + oExpires.toGMTString();
    }
    if (sPath) {
        sCookie += "; path=" + sPath;
    }
    if (sDomain) {
        sCookie += "; domain=" + sDomain;
    }
    if (bSecure) {
        sCookie += "; secure";
    }
    document.cookie = sCookie;
}
function getCookie(sName) {
    var sRE = "(?:; )?" + sName + "=([^;]*);?";
    var oRE = new RegExp(sRE);
    if (oRE.test(document.cookie)) {
        return decodeURIComponent(RegExp["$1"]);
    } else {
        return null;
    }
}                
function deleteCookie(sName, sPath, sDomain) {
    var sCookie = sName + "=; expires=" + (new Date(0)).toGMTString();
    if (sPath) {
        sCookie += "; path=" + sPath;
    }
    if (sDomain) {
        sCookie += "; domain=" + sDomain;
    }
    document.cookie = sCookie;
}

//xml -------------------------------------------------------------------------

function XmlDom() {
    if (window.ActiveXObject) {
        var arrSignatures = ["MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0",
                             "MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument",
                             "Microsoft.XmlDom"];
                         
        for (var i=0; i < arrSignatures.length; i++) {
            try {
        
                var oXmlDom = new ActiveXObject(arrSignatures[i]);
            
                return oXmlDom;
        
            } catch (oError) {
                //ignore
            }
        }

        throw new Error("您的浏览器不支持XML文档，请升级。"); 

    } else if (document.implementation && document.implementation.createDocument) {
        
        var oXmlDom = document.implementation.createDocument("","",null);

        oXmlDom.parseError = {
            valueOf: function () { return this.errorCode; },
            toString: function () { return this.errorCode.toString() }
        };
        
        oXmlDom.__initError__();
                
        oXmlDom.addEventListener("load", function () {
            this.__checkForErrors__();
            this.__changeReadyState__(4);
        }, false);

        return oXmlDom;        
        
    } else {
        throw new Error("您的浏览器不支持XML文档，请升级。");
    }
}

if (isMoz) {

    Document.prototype.readyState = 0;
    Document.prototype.onreadystatechange = null;

    Document.prototype.__changeReadyState__ = function (iReadyState) {
        this.readyState = iReadyState;

        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 == "parsererror") {

            var reError = />([\s\S]*?)Location:([\s\S]*?)Line Number (\d+), Column (\d+):<sourcetext>([\s\S]*?)(?:\-*\^)/;

            reError.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 oParser = new DOMParser();
        var oXmlDom = oParser.parseFromString(sXml, "text/xml");
 
        while (this.firstChild) {
            this.removeChild(this.firstChild);
        }

        for (var i=0; i < oXmlDom.childNodes.length; i++) {
            var oNewNode = this.importNode(oXmlDom.childNodes[i], true);
            this.appendChild(oNewNode);
        }
        
        this.__checkForErrors__();
        
        this.__changeReadyState__(4);

    };
    
    Document.prototype.__load__ = Document.prototype.load;

    Document.prototype.load = function (sURL) {
        this.__initError__();
        this.__changeReadyState__(1);
        this.__load__(sURL);
    };
    
    Node.prototype.__defineGetter__("xml", function () {
        var oSerializer = new XMLSerializer();
        return oSerializer.serializeToString(this, "text/xml");
    });

}

//Ajax -------------------------------------------------------------------------


var bXmlHttpSupport = (XMLHttpRequest || window.ActiveXObject);

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-urlencoded");                

    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(sParams, sParamName, sParamValue) {
    if (sParams.length > 0) {
        sParams += "&";
    }
    return sParams + encodeURIComponent(sParamName) + "=" 
                   + encodeURIComponent(sParamValue);
}

function addURLParam(sURL, sParamName, sParamValue) {
    sURL += (sURL.indexOf("?") == -1 ? "?" : "&");
    sURL += encodeURIComponent(sParamName) + "=" + encodeURIComponent(sParamValue);
    return sURL;   
}

function httpGet(sURL) {
    var sResponseText = "";
    var oURL = new java.net.URL(sURL);
    var oStream = oURL.openStream();
    var oReader = new java.io.BufferedReader(new java.io.InputStreamReader(oStream));
    
    var sLine = oReader.readLine();
    while (sLine != null) {
        sResponseText += sLine + "\n";
        sLine = oReader.readLine();
    }
    
    oReader.close();
    return sResponseText;
}

if (typeof XMLHttpRequest == "undefined" && window.ActiveXObject) {

    function XMLHttpRequest() {

        var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
                             "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
                             "Microsoft.XMLHTTP"];
                         
        for (var i=0; i < arrSignatures.length; i++) {
            try {
        
                var oRequest = new ActiveXObject(arrSignatures[i]);
            
                return oRequest;
        
            } catch (oError) {
                //ignore
            }
        }          

        throw new Error("MSXML is not installed on your system.");               
    }
}


var Http = new Object;

Http.get = function (sURL, fnCallback,errorCallback) {
    if (bXmlHttpSupport) {
        var oRequest = new XMLHttpRequest();
        oRequest.open("get", sURL, true);
        oRequest.onreadystatechange = function () {
            if (oRequest.readyState == 4) {
                if(oRequest.status == 200)
                {
                    if(fnCallback)fnCallback(oRequest.responseText);
                }
                else
                {
                    if(errorCallback)errorCallback();
                }
            }
        }
        oRequest.send(null);    
    
    } else if (navigator.javaEnabled() && typeof java != "undefined" 
            && typeof java.net != "undefined") {
            
        setTimeout(function () {
            fnCallback(httpGet(sURL));
        }, 10);
    } else {
        alert("Your browser doesn't support HTTP requests.");
    }

};

Http.post = function (sURL, sParams, fnCallback,errorCallback) {
 
    if (bXmlHttpSupport) {
   
        var oRequest = new XMLHttpRequest();
        oRequest.open("post", sURL, true);
        oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        oRequest.onreadystatechange = function () {
            if (oRequest.readyState == 4) {
                if(oRequest.status == 200)
                {
                    if(fnCallback)fnCallback(oRequest.responseText);
                }
                else
                {
                    if(errorCallback)errorCallback;
                }
            }
        }
        oRequest.send(sParams);    
    
    } else if (navigator.javaEnabled() && typeof java != "undefined" 
            && typeof java.net != "undefined") {
            
        setTimeout(function () {
            fnCallback(httpPost(sURL, sParams));
        }, 10);
    } else {
        alert("Your browser doesn't support HTTP requests.");
    }          

};

//event -------------------------------------------------------------------------
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.addEvent = 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.removeEvent = 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];
    }
};


//列表框 -------------------------------------------------------------------------
var ListUtil = new Object();

ListUtil.getSelectedIndexes = function (oListbox) {
    var arrIndexes = new Array;

    for (var i=0; i < oListbox.options.length; i++) {
        if (oListbox.options[i].selected) {
            arrIndexes.push(i);
        }
    }

    return arrIndexes;
};

ListUtil.add = function (oListbox, sName, sValue) {

    var oOption = document.createElement("option");
    oOption.appendChild(document.createTextNode(sName));

    if (arguments.length == 3) {
        oOption.setAttribute("value", sValue);
    }

    oListbox.appendChild(oOption);

}

ListUtil.remove = function (oListbox, iIndex) {
    oListbox.remove(iIndex);
};

ListUtil.clear = function (oListbox) {
    for (var i=oListbox.options.length-1; i >= 0; i--) {
        ListUtil.remove(oListbox, i);
    }
};

ListUtil.move = function (oListboxFrom, oListboxTo, iIndex) {
    var oOption = oListboxFrom.options[iIndex];

    if (oOption != null) {
        oListboxTo.appendChild(oOption);
    }
};

ListUtil.shiftUp = function (oListbox, iIndex) {
    if (iIndex > 0) {    
        var oOption = oListbox.options[iIndex];
        var oPrevOption = oListbox.options[iIndex-1];
        oListbox.insertBefore(oOption, oPrevOption);
    }    
};

ListUtil.shiftDown = function (oListbox, iIndex) {
    if (iIndex < oListbox.options.length - 1) {
        var oOption = oListbox.options[iIndex];
        var oNextOption = oListbox.options[iIndex+1];
        oListbox.insertBefore(oNextOption, oOption);
    }
};

//Form -------------------------------------------------------------------------

var FormUtil = new Object;

FormUtil.focusOnFirst = function () {
    if (document.forms.length > 0) {
        for (var i=0; i < document.forms[0].elements.length; i++) {
            var oField = document.forms[0].elements[i];
            if (oField.type != "hidden") {
                oField.focus();
                return;
            }
        }
    }
};

FormUtil.setTextboxes = function() {
    var colInputs = document.getElementsByTagName("input");
    var colTextAreas = document.getElementsByTagName("textarea");
        
    for (var i=0; i < colInputs.length; i++){
        if (colInputs[i].type == "text" || colInputs [i].type == "password") {
            colInputs[i].onfocus = function () { this.select(); };
        }
    }
        
    for (var i=0; i < colTextAreas.length; i++){
        colTextAreas[i].onfocus = function () { this.select(); };
    }
};

FormUtil.tabForward = function(oTextbox) {

    var oForm = oTextbox.form;

    //make sure the textbox is not the last field in the form
    if (oForm.elements[oForm.elements.length-1] != oTextbox 
        && oTextbox.value.length == oTextbox.maxLength) {
               
        for (var i=0; i < oForm.elements.length; i++) {
            if (oForm.elements[i] == oTextbox) {
                 for(var j=i+1; j < oForm.elements.length; j++) {
                     if (oForm.elements[j].type != "hidden") {
                         oForm.elements[j].focus();
                         return;
                     }
                 }
                 return;
            }
        }
    }
};



//Text -------------------------------------------------------------------------
var TextUtil = new Object;

TextUtil.isNotMax = function(oTextArea) {
    return oTextArea.value.length != oTextArea.getAttribute("maxlength");
};

TextUtil.blockChars = function (oTextbox, oEvent, bBlockPaste) {

    oEvent = EventUtil.formatEvent(oEvent);
         
    var sInvalidChars = oTextbox.getAttribute("invalidchars");
    var sChar = String.fromCharCode(oEvent.charCode);
    
    var bIsValidChar = sInvalidChars.indexOf(sChar) == -1;
       
    if (bBlockPaste) {
        return bIsValidChar && !(oEvent.ctrlKey && sChar == "v");
    } else {
        return bIsValidChar || oEvent.ctrlKey;
    }
};

TextUtil.allowChars = function (oTextbox, oEvent, bBlockPaste) {

    oEvent = EventUtil.formatEvent(oEvent);
         
    var sValidChars = oTextbox.getAttribute("validchars");
    var sChar = String.fromCharCode(oEvent.charCode);
    
    var bIsValidChar = sValidChars.indexOf(sChar) > -1;
    
    if (bBlockPaste) {
        return bIsValidChar && !(oEvent.ctrlKey && sChar == "v");
    } else {
        return bIsValidChar || oEvent.ctrlKey;
    }
};

TextUtil.blurBlock = function(oTextbox) {

    //get the invalid characters
    var sInvalidChars = oTextbox.getAttribute("invalidchars");

    //split the invalid characters into a character array
    var arrInvalidChars = sInvalidChars.split("");
    
    //iterate through the characters
    for (var i=0; i< arrInvalidChars.length; i++){
        if (oTextbox.value.indexOf(arrInvalidChars[i]) > -1) {
            alert("Character '" + arrInvalidChars[i] + "' not allowed.");
            oTextbox.focus();
            oTextbox.select();
            return;
        }
    }    
};


TextUtil.blurAllow = function(oTextbox) {
    //get the valid characters
    var sValidChars = oTextbox.getAttribute("validchars");
    
    //split the textbox value string into a character array
    var arrTextChars = oTextbox.value.split("");
   
    //iterate through the characters
    for (var i=0; i< arrTextChars.length; i++){
        if (sValidChars.indexOf(arrTextChars[i]) == -1) {
             alert("Character '" + arrTextChars[i] + "' not allowed.");
             oTextbox.focus();
             oTextbox.select();
             return;
        }
    }
};    

TextUtil.numericScroll = function (oTextbox, oEvent) {

    oEvent = EventUtil.formatEvent(oEvent);
    var iValue = oTextbox.value.length == 0 ? 0 :parseInt(oTextbox.value);
    
    var iMax = oTextbox.getAttribute("max");
    var iMin = oTextbox.getAttribute("min");

    if (oEvent.keyCode == 38) {
        if (iMax == null || iValue < iMax) {
            oTextbox.value = (iValue + 1);
        }
    } else if (oEvent.keyCode == 40){
        if (iMin == null || iValue > iMin) {
            oTextbox.value = (iValue - 1);
        }
    }
};

TextUtil.autosuggestMatch = function (sText, arrValues) {

    var arrResult = new Array;

    if (sText != "") {
        for (var i=0; i < arrValues.length; i++) {
            if (arrValues[i].indexOf(sText) == 0) {
                arrResult.push(arrValues[i]);
            }
        }
    }

   return arrResult;

};

TextUtil.autosuggest = function (oTextbox, arrValues, sListboxId) {
    
    var oListbox = document.getElementById(sListboxId);
    var arrMatches = TextUtil.autosuggestMatch(oTextbox.value, arrValues);
    
    ListUtil.clear(oListbox);
    
    for (var i=0; i < arrMatches.length; i++) {
        ListUtil.add(oListbox, arrMatches[i]);
    }
    
};

//StringBuffer -------------------------------------------------------------------------

function StringBuffer() {
    this.__strings__ = new Array;
}

StringBuffer.prototype.append = function (str) {
    this.__strings__.push(str);
};

StringBuffer.prototype.toString = function () {
    return this.__strings__.join("");
};


//----extend functions for string----start

String.prototype.leftTrim = function() 
{ 
    var str = this;
	var i; 
	for(i=0;i<str.length;i++) 
	{ 
	if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break; 
	} 
	str=str.substring(i,str.length); 
	return str; 
} 
String.prototype.rightTrim = function () 
{ 
    var str = this;
	var i; 
	for(i=str.length-1;i>=0;i--) 
	{ 
	if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break; 
	} 
	str=str.substring(0,i+1); 
	return str; 
} 
String.prototype.trim = function () 
{ 
    var str = this;
    str = str.rightTrim();
    str = str.leftTrim();
	return str; 
} 

String.prototype.getBytesCount =  function ()
{
    var bytesCount = 0;
    for(var i=0;i<this.length;i++)
    {
        if(this.charCodeAt(i)>256)
        {
            bytesCount+=2;
        }
        else
        {
            bytesCount+=1;
        }
    }
    return bytesCount;
};


String.prototype.left =  function (iOutLength, AppendString)
{
    var str = this;
    if (str == null) return "";
    str = str.trim();
    var strBytesCount = str.getBytesCount();
    if (strBytesCount < iOutLength) return str;
    var countLen = 0;
    var charCount = 0;
    for(var i=0;i<str.length;i++)
    {
        if(this.charCodeAt(i)>256)
        {
            countLen += 2;
        }
        else
        {
            countLen += 1;
        }
        if (countLen > iOutLength)
        {
            break;
        }
        charCount++;
    }
    return str.substr(0,charCount)+AppendString;
};

String.prototype.allReplace =  function (sourceStr, replaceText)
{
    var str = this;
    var myReg = new RegExp(sourceStr,"g");
    return str.replace(myReg, replaceText);
};

function StringIsNull(inputStr)
{
    var str = inputStr;
    if(typeof(str) == "undefined"||str == null||str == "")
    {
        return true;
    }
    else
    {
        return false;
    }
};

//设置图片大小
function ResetImageSize(ImgD,height,width)
{ 
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
        flag=true;
        if(image.width/image.height>= width/height){
            if(image.width>width){  
                ImgD.width=width;
                ImgD.height=(image.height*width)/image.width;
            }else{
                ImgD.width=image.width;  
                ImgD.height=image.height;
            }
        }else{
            if(image.height>height){  
                ImgD.height=height;
                ImgD.width=(image.width*height)/image.height;     
            }else{
                ImgD.width=image.width;  
                ImgD.height=image.height;
            }
        }
    }
}
//----extend functions for string----end

/*JSON----start*/
if(!this.JSON){JSON=function(){function f(n){return n<10?'0'+n:n;}
Date.prototype.toJSON=function(){return this.getUTCFullYear()+'-'+
f(this.getUTCMonth()+1)+'-'+
f(this.getUTCDate())+'T'+
f(this.getUTCHours())+':'+
f(this.getUTCMinutes())+':'+
f(this.getUTCSeconds())+'Z';};var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};function stringify(value,whitelist){var a,i,k,l,r=/["\\\x00-\x1f\x7f-\x9f]/g,v;switch(typeof value){case'string':return r.test(value)?'"'+value.replace(r,function(a){var c=m[a];if(c){return c;}
c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+
(c%16).toString(16);})+'"':'"'+value+'"';case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
if(typeof value.toJSON==='function'){return stringify(value.toJSON());}
a=[];if(typeof value.length==='number'&&!(value.propertyIsEnumerable('length'))){l=value.length;for(i=0;i<l;i+=1){a.push(stringify(value[i],whitelist)||'null');}
return'['+a.join(',')+']';}
if(whitelist){l=whitelist.length;for(i=0;i<l;i+=1){k=whitelist[i];if(typeof k==='string'){v=stringify(value[k],whitelist);if(v){a.push(stringify(k)+':'+v);}}}}else{for(k in value){if(typeof k==='string'){v=stringify(value[k],whitelist);if(v){a.push(stringify(k)+':'+v);}}}}
return'{'+a.join(',')+'}';}}
return{stringify:stringify,parse:function(text,filter){var j;function walk(k,v){var i,n;if(v&&typeof v==='object'){for(i in v){if(Object.prototype.hasOwnProperty.apply(v,[i])){n=walk(i,v[i]);if(n!==undefined){v[i]=n;}else{delete v[i];}}}}
return filter(k,v);}
if(/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof filter==='function'?walk('',j):j;}
throw new SyntaxError('parseJSON');}};}();}
/*JSON----end*/

/*跨浏览器设置innerHTML的方法*/
var setInnerHTML = function (el, htmlCode) { var ua = navigator.userAgent.toLowerCase(); if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) { htmlCode = '<div style="display:none">for IE</div>' + htmlCode; htmlCode = htmlCode.replace(/<script([^>]*)>/gi, '<script$1 defer>'); el.innerHTML = htmlCode; el.removeChild(el.firstChild); } else { var el_next = el.nextSibling; var el_parent = el.parentNode; el_parent.removeChild(el); el.innerHTML = htmlCode; if (el_next) { el_parent.insertBefore(el, el_next) } else { el_parent.appendChild(el); } } } 


/*插入Flash*/
function showflash(url, w, h, t) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+w+'" height="'+h+'">');
	document.write('<param name="movie" value="'+url+'">');
	document.write('<param name="quality" value="high">');
	if(t) document.write('<param name="wmode" value="transparent">');
	document.write('<param name="menu" value="false">');
	document.write('<embed src="'+url+'" width="'+w+'" height="'+h+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>');
	document.write('</object>');
}

function SelectAllChk(form,state) {
    for(var i=0; i<form.elements.length; i++) {
        if (form.elements[i].type=="checkbox") {
            form.elements[i].checked = state;
        }
    }
}

/// <summary>
/// 根据相册图片名取得相册图片地址
/// </summary>
/// <param name="sPicName"></param>
/// <param name="iType">(1-原图 ，2-小图)</param>
/// <returns></returns>
function GetAlbumPath(PicName,iType)
{
    var sPicName=String(PicName);
    if (sPicName.length > 17)
    {  
        if (iType == 1)
        {
            sPicName="http://imgwo.gouwo.com/WoAlbumPic/Formerly/" +
                sPicName.substring(0, 4) + "/" + sPicName.substring(4, 6) + "/" + sPicName.substring(6, 8) + "/" + sPicName.substring(8, 10) + "/" + sPicName.substring(10, 12) + "/" + sPicName;
        }
        else
        {
            sPicName="http://imgwo.gouwo.com/WoAlbumPic/Small/" +
                sPicName.substring(0, 4) + "/" + sPicName.substring(4, 6) + "/" + sPicName.substring(6, 8) + "/" + sPicName.substring(8, 10) + "/" + sPicName.substring(10, 12) + "/" + sPicName;
        }
    }
    return sPicName
}

//用于做自动切换相册的类
function DivChange(name,splittime,count,ismove,changed_callback)
{
    this.count = count;
    this.splittime = splittime;
    this.now = 0;
    this.name = name;
    this.timeid1;
    this.timeid2;
    this.ismove = ismove;
    this.changed_callback = changed_callback;
    this.next_button = document.getElementById(name+"_next_button");
    this.previous_button = document.getElementById(name+"_previous_button");
    this.isplay = true;
    var self = this;
    this.SetFocus = function() {
		if(self.now>=self.count) self.now=0;
		self.now = self.now+1;
        self.SelectLayer(self.now);
    };
	this.SelectLayer = function(i) {
      for(var j=1;j<=self.count;j++) {
        try
		    {
            if (j==i) {
                document.getElementById(name+"_panel_"+j).style.display="block";
                //document.getElementById(name+"__"+j).style.display="block";
            } else {
		        document.getElementById(name+"_panel_"+j).style.display="none";
		        //document.getElementById(name+"_panel_"+j).style.display="block";
            }
        }catch(e)
		    {}
      }
      try
      {
          if(typeof self.changed_callback == "function")
          {
            self.changed_callback(i);
          }
      }catch(e)
      {}
    };
    this.ChangeImg = function() {
        if(self.isplay)
        {
            self.timeid1 = setTimeout(self.SetFocus,self.splittime);
        }
        self.timeid2 = setTimeout(self.ChangeImg,self.splittime);
    };
	this.ChangeImg();
    
    this.Stop = function()
    {
        clearTimeout(this.timeid1);
        clearTimeout(this.timeid2);
    };
    this.Start = function()
    {
        this.ChangeImg();
    };
    this.Reset = function()
    {
        this.Stop();
        this.Start();
    };
    
	if(this.ismove!=1)
	{
        if(this.next_button)
        {
            this.next_button.onclick = function()
            {
			    self.Stop();
                if(self.now>=self.count)
                {
                    self.now = 0;
                }
                self.SelectLayer(self.now+1);
		        self.now = self.now+1;
			    self.Start();
            }
        }
        if(this.previous_button)
        {
            this.previous_button.onclick = function()
            {
			    self.Stop();
                if(self.now<=1)
                {
                    self.now = self.count+1;
                }
                self.SelectLayer(self.now-1);
			    self.now = self.now-1;
			    self.Start();
            }
        }
        for(var j=1;j<=count;j++)
        {
		    try
		    {
			    var now_button = document.getElementById(name+"_button_"+j);
			    if(now_button)
			    {
				    now_button.onclick = function()
				    {
					    self.Stop();
					    var num = parseInt(this.id.replace(name+"_button_",""));
					    self.SelectLayer(num);
					    self.now = num;
					    self.Start();
				    }
			    }
		    }catch(e)
		    {}
        }
    }
    else
    {
        if(this.next_button)
        {
            this.next_button.onmouseover = function()
            {
			    self.Stop();
                if(self.now>=self.count)
                {
                    self.now = 0;
                }
                self.SelectLayer(self.now+1);
		        self.now = self.now+1;
			    self.Start();
            }
        }
        if(this.previous_button)
        {
            this.previous_button.onmouseover = function()
            {
			    self.Stop();
                if(self.now<=1)
                {
                    self.now = self.count+1;
                }
                self.SelectLayer(self.now-1);
			    self.now = self.now-1;
			    self.Start();
            }
        }
        for(var j=1;j<=count;j++)
        {
		    try
		    {
			    var now_button = document.getElementById(name+"_button_"+j);
			    if(now_button)
			    {
				    now_button.onmouseover = function()
				    {
					    self.Stop();
					    var num = parseInt(this.id.replace(name+"_button_",""));
					    self.SelectLayer(num);
					    self.now = num;
				    }
				    now_button.onmouseout = function()
				    {
					    self.Start();
				    }
			    }
		    }catch(e)
		    {}
        }
    }
    for(var j=1;j<=count;j++)
    {
		try
		{
			var now_panel = document.getElementById(name+"_panel_"+j);
			if(now_panel)
			{
				now_panel.onmouseover = function()
				{
					self.Stop();
				}
				now_panel.onmousemove = function()
				{
					self.Stop();
				}
				now_panel.onmouseout = function()
				{
					self.Start();
				}
			}
		}catch(e)
		{}
    }
};

//用来读取Url里的参数
Request = {
 QueryString : function(item){
  var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
  return svalue ? svalue[1] : svalue;
 }
}

//拖放类

if(typeof addEvent!='function'){var addEvent=function(o,t,f,l){var d='addEventListener',n='on'+t,rO=o,rT=t,rF=f,rL=l;
if(o[d]&&!l)return o[d](t,f,false);
if(!o._evts)o._evts={};
if(!o._evts[t]){o._evts[t]=o[n]?{b:o[n]}:{};
o[n]=new Function('e','var r=true,o=this,a=o._evts["'+t+'"],i;for(i in a){o._f=a[i];r=o._f(e||window.event)!=false&&r;o._f=null}return r');
if(t!='unload')addEvent(window,'unload',function(){removeEvent(rO,rT,rF,rL)})}if(!f._i)f._i=addEvent._i++;
o._evts[t][f._i]=f};
addEvent._i=1;
var removeEvent=function(o,t,f,l){var d='removeEventListener';
if(o[d]&&!l)return o[d](t,f,false);
if(o._evts&&o._evts[t]&&f._i)delete o._evts[t][f._i]}}function cancelEvent(e,c){e.returnValue=false;
if(e.preventDefault)e.preventDefault();
if(c){e.cancelBubble=true;
if(e.stopPropagation)e.stopPropagation()}};

function MoveResize(myNewName,config)
{
	var props={myName:myNewName,enabled:true,handles:['tl','tm','tr','ml','mr','bl','bm','br'],element:null,handle:null,resizehandle:null,nowselected:null,minWidth:10,minHeight:10,minLeft:0,maxLeft:9999,minTop:0,maxTop:9999,minZIndex:1,maxZIndex:200,zIndex:0,mouseX:0,mouseY:0,lastMouseX:0,lastMouseY:0,mOffX:0,mOffY:0,elmX:0,elmY:0,elmW:0,elmH:0,allowBlur:true,ondragfocus:null,ondragstart:null,ondragmove:null,ondragend:null,ondragblur:null};
	this.objectlist = new Array();
	var obj = this;
	for(var p in props)this[p]=(typeof config[p]=='undefined')?props[p]:config[p];
	var mouseMoveFun =  function(e){obj.mouseMove(e)};
	var mouseUpFun =  function(e){obj.mouseUp(e)};
	this.AddObject = function(myDragConfig)
	{
		var dragConfig={canMove:true,canResize:true,element:null,handle:null,onMoveStart:null,onMoveEnd:null,onMove:null,onResizeStart:null,onResizeEnd:null,onResize:null};
		for(var p in myDragConfig)dragConfig[p]=myDragConfig[p];
		this.objectlist.push(dragConfig);
		addEvent(dragConfig.element,"mousedown",function(e){obj.mouseDown(e)});
	};
	this.ClearObjectList = function()
	{
	    this.objectlist.splice(0,this.objectlist.length);
	};
	this.AddMouseMove = function()
	{
		addEvent(document,"mousemove",mouseMoveFun);
	};
	this.AddMouseUp = function()
	{
		addEvent(document,"mouseup",mouseUpFun);
	};
	this.RemoveEvent = function()
	{
		removeEvent(document,"mousemove",mouseMoveFun);
		removeEvent(document,"mouseup",mouseUpFun);
	};
	this.GetObjectInfoByElement = function(mouveobj)
	{
		for(var i=0;i<this.objectlist.length;i++)
		{
			if(this.objectlist[i].element == mouveobj)
			{
				return this.objectlist[i];
			}
		}
		return null;
	};
	
	this.GetObjectInfoByHandle = function(mouveobj)
	{
		for(var i=0;i<this.objectlist.length;i++)
		{
			if(this.objectlist[i].handle == mouveobj)
			{
				return this.objectlist[i];
			}
		}
		return null;
	};
};

MoveResize.prototype.select=function(newElement,nowobjectinfo){
	with(this){
		if(!document.getElementById||!enabled)return;
		if(newElement&&(newElement!=element)&&enabled){
			nowselected = nowobjectinfo;
			element=newElement;
			this.resetZIndex();
			element.style.zIndex=zIndex+1;
			zIndex++;
			if(this.resizeHandleSet)this.resizeHandleSet(element,true);
			//if(isIE)
			//{
			//    elmX=kg.Page.getRealLeft(element)+kg.Page.getWindowScrollLeft();
			//    elmY=kg.Page.getRealTop(element)+kg.Page.getWindowScrollTop();
			//}
			//else
			//{
			//	elmX=kg.Page.getRealLeft(element);
			//    elmY=kg.Page.getRealTop(element);
			//}
			//elmW=kg.Page.getObjOffsetWidth(element);
			//elmH=kg.Page.getObjOffsetHeight(element);
			if(this.resizeHandleSet)this.resizeHandleSet(element,true);
			if(isIE)
			{
			    elmX=kg.Page.getRealLeft(element)+kg.Page.getWindowScrollLeft();
			    elmY=kg.Page.getRealTop(element)+kg.Page.getWindowScrollTop();
			}
			else
			{
				elmX=kg.Page.getRealLeft(element);
			    elmY=kg.Page.getRealTop(element);
			}
			if(element.style.width=="")
			{
			    elmW = kg.Page.getObjOffsetWidth(element);
			}
			else
			{
			    elmW = parseInt(element.style.width.toLowerCase().replace("px",""));
			}
			if(element.style.height=="")
			{
			    elmH = kg.Page.getObjOffsetHeight(element);
			}
			else
			{
			    elmH = parseInt(element.style.height.toLowerCase().replace("px",""));
			}
			if(ondragfocus)this.ondragfocus();
		}
	}
};
MoveResize.prototype.deselect=function(delHandles){
	with(this){
		if(!document.getElementById||!enabled)return;
		if(delHandles){
			if(ondragblur)this.ondragblur();
			if(this.resizeHandleSet)this.resizeHandleSet(element,false);
			element=null;
		}
		handle=null;
		resizehandle=null;
		//nowselected = null;
		mOffX=0;
		mOffY=0
	}
};
MoveResize.prototype.resizeHandleSet=function(elm,show){
	with(this){
	    if(elm)
	    {
		    if(!elm._handle_tr){
			    for(var h=0;h<handles.length;h++){
				    var hDiv=document.createElement('div');
				    hDiv.className=myName+' '+myName+'-'+handles[h];
				    elm['_handle_'+handles[h]]=elm.appendChild(hDiv);
			    }
		    }
    		
		    for(var h=0;h<handles.length;h++){
			    elm['_handle_'+handles[h]].style.visibility=show?'inherit':'hidden';
		    }
		}
	}
};
MoveResize.prototype.resizeHandleDrag=function(diffX,diffY){
	with(this){
		if(resizehandle==null)return false;
		//var hClass=handle&&handle.className&&handle.className.match(new RegExp(myName+'-([tmblr]{2})'))?RegExp.$1:'';
		var hClass = resizehandle.className.match(new RegExp(myName+'-([tmblr]{2})'))?RegExp.$1:'';
		var dY=diffY,dX=diffX,processed=false;
		if(hClass.indexOf('t')>=0){
			rs=1;
			if(elmH-dY<minHeight)mOffY=(dY-(diffY=elmH-minHeight));
			else if(elmY+dY<minTop)mOffY=(dY-(diffY=minTop-elmY));
			elmY+=diffY;
			elmH-=diffY;
			processed=true;
		}
		if(hClass.indexOf('b')>=0){
			rs=1;
			if(elmH+dY<minHeight)mOffY=(dY-(diffY=minHeight-elmH));
			else if(elmY+elmH+dY>maxTop)mOffY=(dY-(diffY=maxTop-elmY-elmH));
			elmH+=diffY;
			processed=true;
		}
		if(hClass.indexOf('l')>=0){
			rs=1;
			if(elmW-dX<minWidth)mOffX=(dX-(diffX=elmW-minWidth));
			else if(elmX+dX<minLeft)mOffX=(dX-(diffX=minLeft-elmX));
			elmX+=diffX;
			elmW-=diffX;
			processed=true;
		}
		if(hClass.indexOf('r')>=0){
			rs=1;
			if(elmW+dX<minWidth)mOffX=(dX-(diffX=minWidth-elmW));
			else if(elmX+elmW+dX>maxLeft)mOffX=(dX-(diffX=maxLeft-elmX-elmW));
			elmW+=diffX;
			processed=true;
		}
		return processed;
	}
};
MoveResize.prototype.mouseDown=function(e){
	with(this){
		if(!document.getElementById||!enabled)return true;
		var elm=e.target||e.srcElement;
		var objectInfo = GetObjectInfoByElement(elm);
		if(!objectInfo)
		{
			objectInfo = GetObjectInfoByHandle(elm);
		}
		if(objectInfo==null)
		{
			var hRE=new RegExp(myName+'-([trmbl]{2})','')
			if(hRE.test(elm.className))
			{
				mouseX=e.pageX||e.clientX+document.documentElement.scrollLeft;
				mouseY=e.pageY||e.clientY+document.documentElement.scrollTop;
				lastMouseX=mouseX;
				lastMouseY=mouseY;
				resizehandle=elm;
				if(resizehandle&&ondragstart)this.ondragstart(true);
				this.AddMouseMove();
				this.AddMouseUp();
			}
			return true;
		}
		if(nowselected&&(nowselected!=objectInfo)&&allowBlur)deselect(true);
		if(nowselected != objectInfo){
			//if(newHandle)cancelEvent(e);
			select(objectInfo.element,objectInfo);
		}
		if(elm==objectInfo.handle)
		{
				handle=objectInfo.handle;
				if(handle&&ondragstart)this.ondragstart(false);
				mouseX=e.pageX||e.clientX+document.documentElement.scrollLeft;
				mouseY=e.pageY||e.clientY+document.documentElement.scrollTop;
				lastMouseX=mouseX;
				lastMouseY=mouseY;
				this.AddMouseMove();
				this.AddMouseUp();
		}
	}
};
MoveResize.prototype.mouseMove=function(e){
	with(this){
		if(!document.getElementById||!enabled)return true;
		if(!nowselected.canMove&&handle!=null)return true;
		if(!nowselected.canResize&&resizehandle!=null)return true;
		var elm=e.target||e.srcElement;
		//var objectInfo = GetObjectInfoByHandle(handle);
		//if(objectInfo==null)return true;
		mouseX=e.pageX||e.clientX+document.documentElement.scrollLeft;
		mouseY=e.pageY||e.clientY+document.documentElement.scrollTop;
		var diffX=mouseX-lastMouseX+mOffX;
		var diffY=mouseY-lastMouseY+mOffY;
		mOffX=mOffY=0;
		lastMouseX=mouseX;
		lastMouseY=mouseY;
		//if(!handle)return true;
		var isResize=false;
		if(this.resizeHandleDrag&&this.resizeHandleDrag(diffX,diffY)){
			isResize=true;
		}else{
			var dX=diffX,dY=diffY;
			if(elmX+dX<minLeft)mOffX=(dX-(diffX=minLeft-elmX));
			else if(elmX+elmW+dX>maxLeft)mOffX=(dX-(diffX=maxLeft-elmX-elmW));
			if(elmY+dY<minTop)mOffY=(dY-(diffY=minTop-elmY));
			else if(elmY+elmH+dY>maxTop)mOffY=(dY-(diffY=maxTop-elmY-elmH));
			elmX+=diffX;
			elmY+=diffY;
		}
		with(element.style){
			left=elmX+'px';
			width=elmW+'px';
			top=elmY+'px';
			height=elmH+'px';
		}
		if(window.opera&&document.documentElement){
			var oDF=document.getElementById('op-drag-fix');
			if(!oDF){
				var oDF=document.createElement('input');
				oDF.id='op-drag-fix';
				oDF.style.display='none';
				document.body.appendChild(oDF)
			}
			oDF.focus();
		}
		if(ondragmove)this.ondragmove(isResize);
		cancelEvent(e);
	}
};
MoveResize.prototype.mouseUp=function(e){
	with(this){
		if(!document.getElementById||!enabled)return;
		//var elm=e.target||e.srcElement,hRE=new RegExp(myName+'-([trmbl]{2})','');
		this.RemoveEvent();
		if(nowselected.handle&&ondragend)this.ondragend(hRE.test(nowselected.handle.className));
		deselect(false);
	}
};
Array.prototype.swap = function(i, j) 
 { 
 var temp = this[i]; 
 this[i] = this[j]; 
 this[j] = temp; 
 };
 Array.prototype.bubbleSort = function(compare) 
 { 
 for (var i = this.length - 1; i > 0; --i) 
 { 
 for (var j = 0; j < i; ++j) 
 { 
 if (compare(this[j],this[j + 1])) this.swap(j, j + 1); 
 } 
 } 
};
MoveResize.prototype.zIndexCompare = function (value1,value2) { 
    if(parseInt(value1.element.style.zIndex)>parseInt(value2.element.style.zIndex))
    {
    	return true;
    }
    else
    {
    	return false;
    }
}; 
MoveResize.prototype.resetZIndex = function () { 

    if(this.zIndex==0||this.zIndex>=this.maxZIndex)
    {
    	this.objectlist.bubbleSort(this.zIndexCompare);
    	var nowZIndex = this.minZIndex;
    	for(var i=0;i<this.objectlist.length;i++)
    	{
    		this.objectlist[i].element.style.zIndex = nowZIndex;
    		nowZIndex++;
    	}
    	this.zIndex = nowZIndex;
    }
}; 