function Sapphire(){
    this.api_desc = 'Sapphire API Core JavaScript object.';

    var sTransStartToken = '{{';
    var sTransEndToken = '}}';
    var sShowTransToken = '@';
    var sFunctionErrorMsg2 = 'Could not locate function.\nYou may be missing an include or an object.';
    var sFunctionErrorMsg1 = sTransStartToken + 'Could not execute function' + sTransEndToken + '\n'
    var sFailAjaxailMsg1 = sTransStartToken + 'Ajax Ping Failure' + sTransEndToken + ' ';
    var sFailAjaxailMsg2 = sTransStartToken + 'Ajax failed' + sTransEndToken + ': ';
    var sFailAjaxailMsg3 = 'Ajax class failed.';
    var sFailAjaxailMsg4 = sTransStartToken + 'Onload is not defined!\n Received response' + sTransEndToken + ':';
    var sFailAjaxailMsg5 = 'Encountered Server Response Error.';
    var sFailAjaxailMsg6 = 'Ajax Connection Reset.';
    var sFailAjaxailMsg7 = 'Ajax Could Not Communicate With Server.';
    var sFailAjaxailMsg8 = 'Ajax Connection Aborted or Timed Out.';
    var sTimerMsg1 = 'Timer not stoped.';
    var sTimerMsg2 = 'Timer not started.';
    var sNavMsg = sTransStartToken + 'Navigating to' + sTransEndToken + ' ';

    this.custom = {
        api_desc: 'Place holder for custom scripts.'
    }

    this.call = function( oFunction, oaArguments, oObject ){
        if (typeof(oFunction) != 'undefined' ){
            if (typeof(oFunction) == 'string' ){
                try{
                    oFunction = eval(oFunction);
                }
                catch(e2){
                    oFunction = undefined;
                }
            }
            if ( typeof( oObject ) == 'undefined' ){
                    oObject = this;
            }
            if (typeof(oFunction) != 'undefined'){
                try{
                    return oFunction.apply( oObject, oaArguments );
                }
                catch(e1){
                    sapphire.alert( sFunctionErrorMsg1 + e1.message );
                }
            }
            else{
                sapphire.alert( sFunctionErrorMsg2 );
            }
            return void(0);
        }
    }

    var msgTO = null;
    this.statusMsg = function( sMsg, iShowTime, lAppend, lTranslate ){
        if ( typeof(status) != 'undefined' ){
            if ( typeof(iShowTime) == 'undefined' ){
                iShowTime = 3000;
            }
            if ( msgTO != null ){
                clearTimeout( msgTO );
                msgTO = null;
            }
            if (lAppend){
                status += ((typeof(lTranslate) == 'undefined' || lTranslate)?sMsg.translate():sMsg);
            }
            else{
                status = ((typeof(lTranslate) == 'undefined' || lTranslate)?sMsg.translate():sMsg);
            }
            if ( iShowTime > -1 ){
                msgTO = setTimeout( function(){ status=''}, iShowTime );
            }
        }
    }

    this.alert = function(sMsg, lTranslate){
        if ( typeof(sapphire.ui) != 'undefined' ){
            return sapphire.ui.dialog.alert( '' + sMsg, lTranslate );
        }
        else{
            alert( (lTranslate?sMsg.translate():sMsg) );
            return null;
        }
    }


    this.translate = function ( textid ) {
        if ( typeof( translations ) != 'undefined' || textid.length == 0 ){
            if ( showtranslations ) {
                return sShowTransToken + textid;
            }
            else{
                var sT = translations[textid];
                if (sT == null){
                    if ( typeof(textidsForAutoFillTransMasterTemp) != 'undefined') {
                        textidsForAutoFillTransMasterTemp += (sTransStartToken + textid);
                    }
                    return textid;
                }
                else {
                    return ((typeof(sT) !='undefined' || sT !='undefined')?sT:textid);
                }
            }
        }
        else{
            return textid;
        }
    }

    this.translatePartial = function( textid ) {
        if (textid.length > 0 && textid.indexOf(sTransStartToken) > -1 && textid.indexOf(sTransEndToken) > -1){
            var sSU = this.util.string;
            var tokens = sSU.getTokens(textid, sTransStartToken, sTransEndToken);
            for (var i = 0; i < tokens.length; i++) {
                var sTk = sTransStartToken + tokens[i] + sTransEndToken;
                var sTrans = this.translate(tokens[i]);
                textid = sSU.replaceAll(textid, sTk, sTrans);
            }
            return textid;
        }
        else {
            return textid;
        }
    }

    this.jsdebug = false;

    this.connection = {
        api_desc: 'Sapphire API for managing the connection.',
        applicationRoot: '',
        rsetid: '',
        pingRsetFrqcy: 60,
        pingConnectionFrqcy: 60,
        connectionTimeout: 3600,
        connectionDate: '',
        timeToTimeout: 0,
        connectionId: '',
        databaseId: '',
        sysUserId: '',
        sysUserDesc: '',
        sysUserRoleList: '',
        sysUserModuleList: '',
        decimalSeparator: '.',
        groupingSeparator: ',',
        groupingInterval: 3,
        isDevMode: false,
        timeOutDialog: null,
        rsetTimerHandle: null,
        connectionTimerHandle: null,
        pingRset: function( rsetid ){
            sapphire.ajax.callClass( 'com.labvantage.sapphire.ajax.operations.PingRset', 'sapphire.connection.pingRsetHandler',
                      { 'rsetid': rsetid },
                      true, false, 'sapphire.connection.pingError' );
        },
        pingRsetHandler: function( rsetid ){
            if ( typeof( rsetid ) != 'undefined' && rsetid != null ){
                this.rsetid = rsetid;
                this.rsetTimerHandle = window.setTimeout( 'sapphire.connection.pingRset("' + rsetid + '")', 1000 * this.pingRsetFrqcy );
            }
        },
        checkConnection: function( ){
            if ( this != sapphire.connection ){
                sapphire.connection.checkConnection();
            }
            else{
                if ( this.connectionId.length > 0 ){
                    sapphire.ajax.callClass( 'com.labvantage.sapphire.ajax.operations.PingConnection', 'sapphire.connection.pingOrCheckConnectionHandler',
                              { 'connectionId': this.connectionId,
                                  'keepalive': false,
                                  'forceTimeout': false,
                                  'connectionTimeout': this.connectionTimeout },
                              true, false, 'sapphire.connection.pingError' );
                }
            }
        },
        pingConnection: function( lForceTimeout ){
            if ( this != sapphire.connection ){
                sapphire.connection.pingConnection();
            }
            else{
                var lKeepAlive = true;
                if ( typeof(lForceTimeout) == 'undefined'){
                    lForceTimeout = false;
                }
                if ( lForceTimeout ){
                    lKeepAlive = false;
                }
                if ( this.connectionTimerHandle != null ){
                    window.clearTimeout(this.connectionTimerHandle);
                    this.connectionTimerHandle = null;
                }
                if ( this.connectionId.length > 0 ){
                    sapphire.ajax.callClass( 'com.labvantage.sapphire.ajax.operations.PingConnection', 'sapphire.connection.pingOrCheckConnectionHandler',
                            { 'connectionId': this.connectionId,
                              'keepalive': lKeepAlive,
                              'forceTimeout': lForceTimeout,
                              'connectionTimeout': this.connectionTimeout },
                              true, false, 'sapphire.connection.pingError' );
                }
            }
        },
        pingError: function(sMsg){
            sapphire.statusMsg( sFailAjaxailMsg1 + sMsg, -1 );
        },
        logOff: function( ){
            if ( this.connectionTimerHandle != null ){
                window.clearTimeout(this.connectionTimerHandle);
                this.connectionTimerHandle = null;
            }
            if ( this.rsetTimerHandle != null ){
                window.clearTimeout(this.rsetTimerHandle);
                this.rsetTimerHandle = null;
            }
            if ( this.timeOutDialog != null ){
                var oT = document.getElementById('timeoutTime');
                if (oT != null ){
                    oT.innerText = 0;
                    oT.style.color = 'red';
                }
                var oBtn = sapphire.ui.dialog.getDialogButton( this.timeOutDialog.dialogNumber, 0 );
                oBtn.disabled = true;
                oBtn = sapphire.ui.dialog.getDialogButton( this.timeOutDialog.dialogNumber, 1 );
                oBtn.disabled = true;
                var oClose = document.getElementById( 'dlgClose' + this.timeOutDialog.dialogNumber );
                if ( oClose != null ){
                    oClose.onclick = null;
                }
            }
            window.document.location.href = 'rc?command=logoff';
        },
        pingOrCheckConnectionHandler: function( keepalive, interval, timeToTimeout ){
            if ( typeof( keepalive ) != 'undefined' && typeof( interval ) != 'undefined' && typeof( timeToTimeout ) != 'undefined' &&
                 keepalive != null && interval != null && timeToTimeout != null ){

                if ( timeToTimeout < 1 ){
                    this.logOff();
                }
                else{
                    this.pingConnectionFrqcy = interval;
                    this.timeToTimeout = timeToTimeout;
                    if ( !keepalive ){ // not a ping
                        if ( timeToTimeout <= 120 ){
                            if ( this.timeOutDialog == null ){
                                window.focus();
                                this.timeOutDialog = sapphire.ui.dialog.create( 400,200, sapphire.translate('LabVantage Timeout'),
                                        '<div style="padding: 10 10 10 10;">' + sapphire.translate('Your connection to LabVantage will timeout in ') +
                                        '<span id=timeoutTime style="font-weight:bold;">' + timeToTimeout + '</span> ' + sapphire.translate('seconds') + '.<br><br>' +
                                        sapphire.translate('Click "Continue" to continue using LabVantage or click "Log off" to exit LabVantage.' ) + '</div>',
                                        { "Continue": "sapphire.connection.pingConnection(false)", "Log off": "sapphire.connection.pingConnection(true)" } ,
                                        false, true, true, 10, 'sapphire.connection.pingConnection(false)'
                                        );
                            }
                            else{
                                var oT = document.getElementById('timeoutTime');
                                if (oT != null ){
                                    oT.innerText = timeToTimeout;
                                    if ( timeToTimeout <= 30 ){
                                        oT.style.color = 'red';
                                    }
                                }
                            }
                        }
                        else{
                            if ( this.timeOutDialog != null ){
                                sapphire.ui.dialog.close( this.timeOutDialog.dialogNumber );
                                this.timeOutDialog = null;
                            }
                        }

                    }
                    else{
                        if ( this.timeOutDialog != null ){
                            sapphire.ui.dialog.close( this.timeOutDialog.dialogNumber );
                            this.timeOutDialog = null;
                        }
                    }
                    this.connectionTimerHandle = window.setTimeout( 'sapphire.connection.checkConnection()', interval * 1000 );
                }
            }
        },
        dsCall: function( sSDCId, sKeyId1, sOperation, sAccessType, sFailureScript, oFunction, oaArguments ){
            if ( sKeyId1.length > 0 ){
                this.__ds_failurescript = sFailureScript;
                this.__ds_function = oFunction;
                this.__ds_arguments = oaArguments;
                if ( typeof( sAccessType ) != 'undefined' && sAccessType != null && sAccessType.length > 0 ){
                    if ( sAccessType.toLowerCase() == 'world' ){
                        sapphire.call( oFunction, oaArguments );
                    }
                    else if ( sAccessType.toLowerCase() == 'none' ){
                        this.dsCallHandler( sOperation, sKeyId1, '' );
                    }
                    else{
                        sapphire.ajax.callClass( 'com.labvantage.sapphire.ajax.operations.DepartmentalSecurityCheck', 'sapphire.connection.dsCallHandler',
                                { 'sdcid': sSDCId,
                                  'operation': sOperation,
                                  'accesstype': sAccessType,
                                  'keyid1': sKeyId1 },
                                  true, true );
                    }
                }
                else{
                    sapphire.ajax.callClass( 'com.labvantage.sapphire.ajax.operations.DepartmentalSecurityCheck', 'sapphire.connection.dsCallHandler',
                            { 'sdcid': sSDCId,
                              'operation': sOperation,
                              'accesstype': '',
                              'keyid1': sKeyId1 },
                              true, true );
                }
            }
            else{
                sapphire.alert( top.selectAtleastOneItemMsg, false );
            }
        },
        dsCallHandler: function( sOperation, sFailedSDIs, sPassedSDIs ){
            var ds_failurescript = this.__ds_failurescript;
            this.__ds_failurescript = null;
            var ds_function = this.__ds_function;
            this.__ds_function = null;
            var ds_arguments = this.__ds_arguments;
            this.__ds_arguments = null;

            if ( sFailedSDIs.length == 0 ){
                sapphire.call( ds_function, ds_arguments );
            }
            else{
                if ( typeof( ds_failurescript) != 'undefined' && ds_failurescript != null && ds_failurescript.length > 0 ){
                    function call(){
                        this.failedsdis = sFailedSDIs;
                        this.passedsdis = sPassedSDIs;
                        eval(ds_failurescript);
                    }
                    call();
                }
                else{
                    var sMsg = top.dueToDeptSec[0] + sOperation + top.dueToDeptSec[1] +
                                sFailedSDIs;
                    sapphire.alert( sMsg, false  );
                }
            }
        },
        releaseLock: function ( sReleaseLockFlag ){
            if( sReleaseLockFlag != 'N' ) {
                var sRsetlist = this.getRSetId();
                if ( sRsetlist != null ){
                    this.setCookieRSetList( sRsetlist );
                }
            }
            else {
                this.setCookieRSetList( '' );
            }
        },
        setCookieRSetList: function( sRsetlist ){
            if ( typeof( sRsetlist ) != 'undefined' &&  sRsetlist != null ) {
                if ( sRsetlist == '' ) {
                    sapphire.cookie.setCookieCrumb( 'rsetlist', '' );
                }
                else{
                    var sCookieValue = sapphire.cookie.getCookieCrumb( 'rsetlist' );
                    if ( sCookieValue.length == 0 || sCookieValue == 'null' || sCookieValue == '(null)' || sCookieValue == null ) {
                        sapphire.cookie.setCookieCrumb( 'rsetlist', sRsetlist );
                    }
                    else{
                        sapphire.cookie.setCookieCrumb( 'rsetlist', sRsetlist + '|' + sCookieValue );
                    }
                }
            }

        },
        getRSetId: function( ) {
            var saRsetFrames = [ 'maint_iframe', 'sourceframe_iframe', 'rightframe', 'iframe_dataentry' ]; // add more here as required
            // first check to see if there is an __rsetlist variable in current context
            if( typeof( __rsetlist ) != 'undefined' && __rsetlist != null ) {
                this.rsetid = __rsetlist;
                return __rsetlist;
            }
            else {
                // now if we are at the top frame
                for ( var iIndex = 0; iIndex < saRsetFrames.length; iIndex++ ){
                    var oFrame = window.frames[saRsetFrames[iIndex]];
                    if ( typeof( oFrame ) != 'undefined' && typeof( oFrame.sapphire ) != 'undefined' ){
                        var sRset = oFrame.sapphire.connection.getRSetId();
                        if ( sRset != null ){
                            return sRset;
                        }
                    }
                }
                return null;
            }
        }

    }

    this.browser = {
        api_desc: 'Sapphire API for determining the client browser.',
        determine: function(){
            //deprecated - this is now rendered from server
        },
        id: '',
        name: '',
        osId: '',
        compat: '',
        compatMode: false,
        compatVersion: 0,
        version: 0,
        mozillaVersion:0,
        webkitVersion:0,
        mozilla: false,
        webkit: false,
        firefox: false,
        chrome: false,
        android: false,
        skyfire: false,
        safari: false,
        blackberry: false,
        opera: false,
        ie: false,
        mobile: false,
        supported: false,
        gc: false
    }

    this.events = {
        api_desc: 'Sapphire API for adding custom events and listeners.',
        oaLoadListeners: new Array(),
        registerLoadListener: function ( vFunction, lInsertBefore, iTimeout ){
            this.registerListner( vFunction, this.oaLoadListeners, lInsertBefore, iTimeout );
        },
        registerListner: function ( vFunction, oaArray, lInsertBefore, iTimeout ){
            var oaHolder;
            oaHolder    = new Array(2);
            oaHolder[0] = vFunction;
            if ( typeof( iTimeout ) == 'undefined' ){
                oaHolder[1] = 0;
            }
            else{
                oaHolder[1] = iTimeout;
            }
            if ( !lInsertBefore ){
                oaArray.push( oaHolder );
            }
            else{
                oaArray.unshift( oaHolder );
            }
        },
        _to: new Array(),
        callListeners_to: function(iIndex){
            if ( this != sapphire.events ){
                sapphire.events.callListeners_to(iIndex);
            }
            else{
                if ( this._to.length > 0 && iIndex < this._to.length && this._to[iIndex] != null ){
                    sapphire.call(this._to[iIndex].call,this._to[iIndex].att,this._to[iIndex].ref);
                    this._to[iIndex] = null;
                }
            }
        },
        callListeners: function( oaArray, oAtt ){
            if ( oaArray != null ){
                if ( typeof(oAtt) == 'undefined' || oAtt == null ){
                    oAtt = new Array();
                }

                var iLength = oaArray.length;
                var iCurrent = -1;
                for ( var iIndex = 0; iIndex < iLength; iIndex++ ){
                    try{
                        var oItem = oaArray[iIndex];
                        var oOne = oItem[0];
                        try{
                            var oTwo = oItem[1];
                            try{
                                if ( oTwo > 0 ){
                                    oItem[3] = oAtt;
                                    oItem[4] = this;
                                    sapphire.events._to.push({call:oOne,att:oAtt,ref:this});
                                    setTimeout( new Function('sapphire.events.callListeners_to(' + (sapphire.events._to.length - 1) + ');' ), oTwo );
                                }
                                else{
                                    sapphire.call(oOne, oAtt, this);
                                }
                            }
                            finally{
                                oTwo = null;
                            }
                        }
                        finally{
                            oItem = null;
                            oOne = null;
                        }
                    }
                    catch( e ){
                    }
                }
            }
        },
        callLoadListeners: function ( ){
            if ( this != sapphire.events ){
                sapphire.events.callLoadListeners( );
            }
            else{
                sapphire.events.callListeners( this.oaLoadListeners );
            }
        },
        attachEvent: function( oElement, sTriggerName, vFunction ){
            if ( sTriggerName.indexOf('on') == 0 ){
                sTriggerName = sTriggerName.substr( 2 );
            }
            if ( oElement.attachEvent ){
                oElement.attachEvent( 'on' + sTriggerName, vFunction );
            }
            else{
                oElement.addEventListener( sTriggerName, vFunction, false );
            }
        },
        detachEvent: function(oElement,sTriggerName,vFunction){
            if ( sTriggerName.indexOf('on') == 0 ){
                sTriggerName = sTriggerName.substr( 2 );
            }
            if ( oElement.detachEvent ){
                oElement.detachEvent( 'on' + sTriggerName, vFunction );
            }
            else{
                oElement.removeEventListener( sTriggerName, vFunction, false );
            }
        },
        fireEvent: function(oElement, sTriggerName){
            if (sapphire.browser.ie){
                if(sTriggerName.indexOf('on') != 0){
                    sTriggerName = 'on' + sTriggerName;
                }
                oElement.fireEvent(sTriggerName);
            }
            else{
                sTriggerName = sTriggerName.toLowerCase();
                if(sTriggerName.indexOf('on') == 0){
                    sTriggerName = sTriggerName.substr(2);
                }
                var e;
                e = document.createEvent('Event');
                e.initEvent(sTriggerName, true, true);
                oElement.dispatchEvent(e);
            }
        }
    }

    this.cookie = {
        api_desc: 'Sapphire API for handling cookies.',
        getCookieCrumb: function( sCrumbId ){
            var sReturn = '';
            var aCookie = document.cookie.split('; ');
            var iLength = aCookie.length;
            for ( var i = 0; i < iLength; i++ ){
                var aCrumb = aCookie[i].split( '=' );
                if ( sCrumbId == aCrumb[0] ){
                    if ( aCrumb.length == 1 ){
                        sReturn = '';
                    }
                    else{
                        sReturn = unescape( aCrumb[1] );
                    }
                    break;
                }
            }
            return sReturn;
        },
        setCookieCrumb: function( sCrumbId, sValue ){
            sCrumbId = sCrumbId.replace(/ /g,"_");
            if ( sValue.length > 0 ) {
                document.cookie = sCrumbId + '=' + encodeURI(sValue);
            }
            else {
                document.cookie = sCrumbId + '=(null)';
            }
        }
    }

    this.userConfig = {
        api_desc: 'Sapphire API for manipulating the user configuration cookies.',
        set: function ( sPropertyId, sValue ){
			if ( sPropertyId.indexOf( 'userconfig_' ) == -1 ){
                sPropertyId = 'userconfig_' + sPropertyId;
            }
            sapphire.cookie.setCookieCrumb( sPropertyId, sValue );
        },
        get: function ( sPropertyId ){
            // user config can only be read from server side.
            return '';
        }
    }

    this.style = {
        api_desc: 'Sapphire API for manipulating the style classes and CSS.',
        getStyleSheet: function( sTheId, oDoc ){
            if ( typeof( oDoc ) == 'undefined' ){
                oDoc = document;
            }
            try{
                return oDoc.styleSheets.item( sTheId );
            }
            catch( e){
                return null;
            }
        },
        createStyleSheet: function( sTheId, oDoc ){
            if ( typeof( oDoc ) == 'undefined' ){
                oDoc = document;
            }
            var oStyleSheet = oDoc.getElementById( sTheId );
            if ( oStyleSheet == null || typeof(oStyleSheet) == 'undefined'  ){
                oStyleSheet = oDoc.createElement('STYLE');
                oStyleSheet.id = sTheId;
                oDoc.documentElement.firstChild.appendChild(oStyleSheet);
                oStyleSheet = this.getStyleSheet( sTheId, oDoc );
            }
            return oStyleSheet;
        },
        addRule: function( sTheId, sTheRule, sStyle, oDoc ){
            if ( typeof( oDoc ) == 'undefined' ){
                oDoc = document;
            }
            var oStyleSheet = this.getStyleSheet(sTheId,oDoc);
            if ( oStyleSheet != null && typeof( oStyleSheet ) != 'undefined' ){
                oStyleSheet.addRule( sTheRule, sStyle );
                return ( sapphire.browser.ie ? oStyleSheet.rules.length : oStyleSheet.cssRules.length ) - 1;
            }
            else{
                return -1;
            }
        },
        getRuleIndex: function( sTheId, sTheRule, oDoc ){
            if ( typeof( oDoc ) == 'undefined' ){
                oDoc = document;
            }
            var oRule;
            var iRule = -1;
            var oStyleSheet = this.getStyleSheet(sTheId,oDoc);
            if ( oStyleSheet != null && typeof( oStyleSheet ) != 'undefined' ){
                var oRules = sapphire.browser.ie ? oStyleSheet.rules : oStyleSheet.cssRules;
                var iLength = oRules.length;
                var iIndex;
                for ( iIndex = 0; iIndex < iLength; iIndex++ ){
                    oRule = oRules.item( iIndex );
                    if ( oRule.selectorText == sTheRule ){
                        iRule = iIndex;
                        break;
                    }
                }
            }
            return iRule;
        },
        removeRule: function( sTheId, sTheRule, oDoc ){
            if ( typeof( oDoc ) == 'undefined' ){
                oDoc = document;
            }
            var oStyleSheet = this.getStyleSheet(sTheId,oDoc);
            if ( oStyleSheet != null && typeof( oStyleSheet ) != 'undefined' ){
                var iRule = this.getRuleIndex( sTheId, sTheRule, oDoc );
                if ( iRule > -1 ){
                    oStyleSheet.removeRule( iRule );
                }
            }
        },
        setClassElement: function ( sTheId, sTheRule, sTheElement, sTheValue, oDoc ){
            // Sets any css class rule in a style sheet
            if (typeof(oDoc) == 'undefined'){
                oDoc = document;
            }
            var oStyleSheet;
            var oRule;
            oStyleSheet = oDoc.styleSheets.item( sTheId );
            if ( oStyleSheet != null && typeof( oStyleSheet ) != 'undefined' ){
                var oRules = sapphire.browser.ie ? oStyleSheet.rules : oStyleSheet.cssRules;
                var iLength = oRules.length;
                var iIndex;
                sTheRule = sTheRule.toLowerCase();
                for ( iIndex = 0; iIndex < iLength; iIndex++ ){
                    oRule = oRules.item( iIndex );
                    if ( oRule.selectorText.toLowerCase() == sTheRule ){
                        eval( 'oRule.style.' + sTheElement + ' = ' + '"' + sTheValue + '"'  );
                    }
                }
            }
            else{
            }
        },
        getClassElement: function ( sTheId, sTheRule, sTheElement, oDoc ){
            // Gets any css class rule in a style sheet
            if (typeof(oDoc) == 'undefined'){
                oDoc = document;
            }
            var oStyleSheet;
            var iPri = 0;
            var oSS = oDoc.styleSheets;
            var iDLen = sTheId.length;
            if ( iDLen > 0 ){
                try{
                    oStyleSheet = oSS.item( sTheId );
                }
                catch(e){
                    return '';
                }
            }
            else{
                oStyleSheet = oSS.item( iPri );
            }
            var sReturn     = '';
            var iLen = oSS.length;
            sTheRule = sTheRule.toLowerCase();
            while ( oStyleSheet != null && typeof( oStyleSheet ) != 'undefined' ){
                var oRules = sapphire.browser.ie ? oStyleSheet.rules : oStyleSheet.cssRules;
                var iLength = oRules.length;
                for ( var iIndex = 0; iIndex < iLength; iIndex++ ){
                    var oRule = oRules.item( iIndex );
                    if ( oRule.selectorText.toLowerCase() == sTheRule ){
                        sReturn = eval( 'oRule.style.' + sTheElement );
                    }
                }
                if ( iDLen > 0 || iPri == iLen - 1 ){
                    break;
                }
                else{
                    iPri ++;
                    oStyleSheet = oSS.item( iPri );
                }
            }
            return sReturn;
        }
    }


    this.ajax = {
        api_desc: 'Sapphire API for creating AJAX requests and handling AJAX responses.',
        defaultToPOST: true,
        callClass: function( classname, callback, callproperties, post, synchronous, errorCallback ) {
            //Sapphire API for making AJAX Request (use post = true for char above 255).
            this.callCommand( 'command=ajax&ajaxclass=' + classname, callback, callproperties, post, synchronous, errorCallback );
        },
        callService: function( service, callback, callproperties, post, synchronous, errorCallback ) {
            this.callCommand( 'command=ajax&ajaxservice=' + service, callback, callproperties, post, synchronous, errorCallback )
        },
        callCommand: function( command, callback, callproperties, post, synchronous, errorCallback ) {
            if ( typeof( post ) == 'undefined' ) {
                post = this.defaultToPOST;
            }
            if ( typeof(synchronous) == 'undefined' || synchronous == null ){
                synchronous = false;
            }
            if ( document.readyState == 'complete' ){
                var method = 'GET';
                if ( post ){
                    method = 'POST';
                }
                var oInputs = new Array();
                if ( typeof(callproperties) == 'undefined' || callproperties == null ){
                    callproperties = { 'timestamp': this.util.getTimeStamp() };
                    oInputs.push( {name:'callproperties',id:'callproperties', value: objectToJSONString( callproperties ) } );
                }
                else if ( typeof(callproperties) == 'object' ){
                    callproperties['timestamp'] = this.util.getTimeStamp();
                    oInputs.push( {name:'callproperties',id:'callproperties', value: objectToJSONString( callproperties ) } );
                }
                else if ( typeof( callproperties ) == 'string' ) {
                    oInputs.push( {name:'timestamp',id:'timestamp', value: this.util.getTimeStamp() } );
                    oInputs.push( {name:'callproperties',id:'callproperties', value: callproperties} );
                }
                oInputs.push( {name:'rnd',id:'rnd', value: this.util.getRandomString(5) } );
                oInputs.push( {name:'callback', id:'callback', value:callback} );

                if ( typeof(errorCallback) == 'undefined' ){
                    errorCallback = 'errorAlert';
                }
                oInputs.push( {name:'errorcallback', id:'errorcallback', value:errorCallback} );
                var oForm = this.util.createForm( 'rc?' + command, post,
                        oInputs, null, true );

                this.io.send( '', method,
                        function( type, data, evt ) {
                            eval( 'sapphire.ajax.callServiceHandler( type, data, evt )' );
                        },
                        function( ) {
                            eval( 'sapphire.ajax.callServiceError()' );
                        },
                        oForm,
                        synchronous );

                sapphire.garbage.add( oForm );
                oForm = null;
            }
            else{
                sapphire.events.attachEvent( window, 'load',
                        new Function( 'sapphire.ajax.callCommand(' +
                               '\'' + command + '\',' +
                               '\'' + callback + '\',' +
                               objectToJSONString( callproperties ) + ',' +
                               post + ',' +
                               synchronous +
                               ')' ) );
            }

        },
        callServiceError: function() {
            sapphire.alert( 'Error calling AJAX class - check logs for details.' );
        },
        callServiceHandler: function( type, data, evt  ) {
            function errorAlert( sMsg ){
                sapphire.alert( sMsg );
            }
            if ( typeof(data) == 'object' ){
                try{
                    var errorcallback = data.errorcallback;
                    try{
                        var error = data.error;
                        if ( typeof(error) == 'undefined' ) {
                            var callback = data.callback;
                            var args = data.callbackArgs.split( ',' );
                            var callbackArgs = '';
                            var iLength = args.length;
                            for ( var i = 0; i < iLength; i++ ) {
                                callbackArgs += ',data.' + args[i].replace( /^\s+|\s+$/g, '' ); // RegEx to trim a string
                            }
                            eval( callback + '( ' + callbackArgs.substring( 1 ) + ' )' );
                        }
                        else {
                            throw new Error( error );
                        }
                    }
                    catch(e2){
                        if ( typeof(errorcallback) == 'undefined' || errorcallback.length == 0 ){
                            errorcallback = 'errorAlert';
                        }
                        var oFunc = eval( errorcallback );
                        oFunc( e2.message, data );
                    }

                }
                catch (e){
                    errorAlert( sFailAjaxailMsg2 + e.message );
                }
            }
            else {
                errorAlert( sFailAjaxailMsg3 );
            }
        },
        request: function ( requesturl, loadhandler, params, formid, onerror ) {
            var onload = 'sapphire.ajax.handleResponse';
            if ( typeof( onerror ) == 'undefined' ) {
                onerror = 'sapphire.ajax.handleError';
            }
            if ( typeof( requesturl ) == 'undefined' || requesturl.length == 0 ) {
                sapphire.alert( 'Request url is not defined.' );
                return;
            }
            if ( typeof( loadhandler ) != 'undefined' ) {
                onload = loadhandler;
            }
            var sMethod = 'GET';
            if ( this.defaultToPOST ){
                sMethod = 'POST';
            }

            var lCForm = false;
            var oForm = null;
            if (typeof(formid) != 'undefined' && formid != null && formid.length > 0){
                oForm = document.getElementById( formid );
                if (oForm != null){
                    oForm = oForm.cloneNode(true);
                    lCForm = true;
                }
            }

            try{
                this.io.send( requesturl, sMethod,
                        function( type, data, evt ) {
                            eval( onload + '( type, data, evt, params )' );
                        },
                        function( ) {
                            eval( onerror );
                        },
                        oForm,
                        false );
            }
            finally{
                if (lCForm){
                    sapphire.garbage.add( oForm );
                    oForm = null;
                }
            }
        },
        requestDelayed: function ( delayms, requesturl, loadhandler, params, formid, onerror ) {
            // for mouseover events
        },
        handleResponse: function ( type, data, evt, params  ) {
            //Sapphire Default Response Handler
            sapphire.alert( sFailAjaxailMsg4 +'\n' + (sTransStartToken + 'Type' + sTransEndToken) + ': ' + type + '\n ' + (sTransStartToken +  'Data' + ': ' + sTransEndToken) + data, false );
        },
        handleError: function() {
            // Sapphire Default Error Handler
            sapphire.alert( sFailAjaxailMsg5 );
        },
        io:{
            timeout: 60000,
            getXMLHttpRequest: function(){
                var oXmlReq = null;
                if(window.XMLHttpRequest){
                    oXmlReq = new XMLHttpRequest();
                }
                else if(window.ActiveXObject){
                    try{
                        oXmlReq = new ActiveXObject('MSXML2.XMLHTTP.6.0');
                    }
                    catch(e1){
                        try{
                            oXmlReq = new ActiveXObject('MSXML2.XMLHTTP.3.0');
                        }
                        catch(e2){
                            try{
                                oXmlReq = new ActiveXObject('MSXML2.XMLHTTP');
                            }
                            catch(e3){
                                try{
                                    oXmlReq = new ActiveXObject('Microsoft.XMLHTTP');
                                }
                                catch(e4){
                                    oXmlReq = null;
                                }
                            }
                        }
                    }
                }
                return oXmlReq;
            },
            send: function( sUrl, sMethod, fOnLoad, fOnError, oForm, lSync ){
                function doEscape( sText ){
                    return encodeURIComponent(sText);
                }
                function getData( oForm){
                    var oData;
                    oData = '';
                    var oaInputs = oForm.childNodes;
                    var iL = oaInputs.length;
                    for ( var iIndex = 0; iIndex < iL; iIndex++ ){
                        var oI = oaInputs[iIndex];
                        if ( oI.tagName == 'SELECT' || oI.tagName == 'INPUT' || oI.tagName == 'TEXTAREA' ){
                            var sVal = oI.value;
                            var sName = oI.name;
                            if ( typeof(sName) == 'undefined' || sName.length == 0 ){
                                sName = oI.id;
                            }
                            if ( oData.length > 0 ){
                                oData += '&';
                            }
                            oData += doEscape(sName) + '=' + doEscape(sVal);
                        }
                    }
                    return oData;
                }
                if ( typeof(sUrl) == 'undefined' ){
                    sUrl = '';
                }
                var oTimeOut = null;
                var oXmlReq = this.getXMLHttpRequest();
                if(oXmlReq!=null){
                    oXmlReq.onreadystatechange = function(){
                        switch(oXmlReq.readyState){
                            case 0:
                                break;
                            case 1:
                                break;
                            case 2:
                                break;
                            case 3:
                                break;
                            case 4:
                                if ( oTimeOut != null ){
                                    clearTimeout( oTimeOut );
                                    oTimeOut = null;
                                }
                                if ( oXmlReq.status == 200 ){
                                    try{
                                        if ( oXmlReq.responseText != null ){
                                            var sText = oXmlReq.responseText;
                                            var oOb = null;
                                            if ( sText.indexOf("{") == 0 && sText.indexOf("}", sText.length-1) == sText.length -1){
                                                oOb = eval("(" + sText + ")");
                                            }
                                            else{
                                                oOb = sText;
                                            }
                                            fOnLoad( 'load', oOb, oXmlReq );
                                        }
                                        else{
                                            fOnLoad( 'load', null, oXmlReq );
                                        }
                                    }
                                    catch(e){
                                        fOnError( );
                                    }
                                }
                                else if ( oXmlReq.status == 12031 ){
                                        sapphire.statusMsg(sFailAjaxailMsg6, -1);
                                }
                                else if ( oXmlReq.status == 12029 ){
                                        sapphire.statusMsg(sFailAjaxailMsg7, -1);
                                }
                                else if ( oXmlReq.status == 0 ){
                                        sapphire.statusMsg(sFailAjaxailMsg8, -1);
                                }
                                else{
                                    fOnError( );
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
                var oData = null;
                if ( typeof(sMethod) != 'undefined' && sMethod == 'POST' ){
                    sMethod = 'POST';
                    if ( typeof(oForm) != 'undefined' && oForm != null ){
                        if (sUrl.length == 0){
                            if ( typeof(oForm.action) != 'undefined' && oForm.action.length > 0 ){
                                sUrl = oForm.action;
                            }
                        }
                        sapphire.util.url.addToForm(sUrl, oForm);
                        // Firefox now send utf-8 on end of formdata for ajax requests made with xmlhttprequrest. Jaguar cannot parse formdata from this.
                        // Therefore when firefox is used we use a JSON request where the json data in in the body of the content rather than as form variables.
                        if (sapphire.browser.id == 'FF'){
                            oData = sapphire.util.propertyList.create(oForm).toJSONString();
                        }
                        else{
                            oData = getData(oForm);
                        }
                    }
                }
                else{
                    sMethod = 'GET';
                    if ( typeof(oForm) != 'undefined' && oForm != null ){
                        if (sUrl.length == 0){
                            if ( typeof(oForm.action) != 'undefined' && oForm.action.length > 0 ){
                                sUrl = oForm.action;
                            }
                        }
                        sUrl = sapphire.util.url.encode(sUrl);
                        var sExtra = getData(oForm);
                        if ( sExtra.length > 0 ){
                            if ( sUrl.indexOf('?') > -1){
                                sUrl += '&' + sExtra;
                            }
                            else{
                                sUrl += '?' + sExtra;
                            }
                        }
                    }
                }
                if ( typeof(lSync) == 'undefined'  ){
                    lSync = false;
                }
                oXmlReq.open(sMethod, sUrl, !lSync);
                if ( sMethod == 'POST' && sapphire.browser.id != 'FF' ){
                    oXmlReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                }
                else{
                    oXmlReq.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');
                }
                oXmlReq.send (oData);

                oTimeOut = setTimeout( function(){
                            oTimeOut = null;
                            oXmlReq.abort();
                        },
                        this.timeout );

            }
        },
        util: {
            api_desc: 'Sapphire Ajax utility methods.',
            getTimeStamp: function(){
                return new Date().getTime();
            },
            getRandomString: function( iLength ){
                var sChars;
                var sRandomString;
                var iIndex;
                var nRand;
                sChars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
                sRandomString = '';
                for ( iIndex = 0; iIndex < iLength; iIndex++ ){
                    nRand = Math.floor(Math.random() * sChars.length );
                    sRandomString += sChars.substring(nRand, nRand + 1 );
                }
                return sRandomString;
            },
            setInnerHTML: function( oContainer, sHtml ){
                sHtml = sHtml.replace( /<script/g, '<div ajaxscript=Y style="visibility:hidden;" ' );
                sHtml = sHtml.replace( /<\/script/g, '</div' );
                oContainer.innerHTML = sHtml;
                var oDoc = document;
                var oHead = oDoc.getElementsByTagName('head')[0];
                if ( oHead != null ){
                    var oaScripts = oContainer.getElementsByTagName( 'div' );
                    if ( typeof(oaScripts) != 'undefined' && oaScripts != null && oaScripts.length > 0 ){
                        var oaToRemove = [];
                        var iLength = oaScripts.length;
                        for ( var iS = 0; iS < iLength; iS++ ){
                            var oScript = oaScripts[iS];
                            if ( typeof(oScript.ajaxscript) != 'undefined' && oScript.ajaxscript == 'Y' ){

                                var oScriptEl = oDoc.createElement('script');
                                if ( typeof(oScript.src) != 'undefined' ){
                                    oScriptEl.src = oScript.src;
                                }
                                if ( typeof(oScript.defer) != 'undefined' ){
                                    oScriptEl.defer = oScript.defer;
                                }
                                if ( typeof(oScript.type) != 'undefined' ){
                                    oScriptEl.type = oScript.type;
                                }
                                if ( typeof(oScript.id) != 'undefined' ){
                                    oScriptEl.id = oScript.id;
                                }
                                oScriptEl.text = oScript.innerText;
                                oaToRemove.push( oScript );
                                oHead.appendChild(oScriptEl);
                            }
                            else{
                            }
                        }
                        if ( oaToRemove.length > 0 ){
                            sapphire.garbage.add( oaToRemove );
                        }
                    }
                }

            },
            createForm: function( sURL, lPost, oInputs, oParent, lHidden ){
                var oForm = document.createElement('form');
                oForm.action = sURL;
                if ( typeof(lHidden) != 'undefined' && lHidden ){
                    oForm.style.position = 'absolute';
                    oForm.style.display = 'none';
                }
                if ( lPost ) {
                    oForm.method = 'POST';
                }
                else{
                    oForm.method = 'GET';
                }
                if ( typeof( oInputs) != 'undefined' && oInputs != null ){
                    var sHtml = '';
                    var iLength = oInputs.length;
                    for ( var iIndex = 0; iIndex < iLength; iIndex++ ){
                        var oInput = oInputs[iIndex];
                        var oAnInput;
                        var sName = '';
                        if ( typeof (oInput.name) != 'undefined' ){
                            sName = oInput.name;
                        }
                        else{
                            sName = 'input' + iIndex;
                        }

                        if (sapphire.browser.ie){
                            oAnInput = document.createElement( '<input name="' + sName + '">' );
                        }
                        else{
                            oAnInput = document.createElement( 'input' );
                            oAnInput.name = sName;
                        }
                        if ( typeof (oInput.id) != 'undefined' ){
                            oAnInput.id = oInput.id;
                        }
                        if ( typeof (oInput.value) != 'undefined' ){
                            oAnInput.value = '' + oInput.value;
                        }
                        else{
                            oAnInput.value = '';
                        }
                        if ( typeof (oInput.type) != 'undefined' ){
                            oAnInput.type = oInput.type;
                        }
                        else{
                            oAnInput.type = 'hidden';
                        }
                        try{
                            oForm.appendChild(oAnInput);
                        }
                        catch(e){
                            sHtml += sapphire.util.dom.getOuterHTML(oAnInput);
                        }
                        oAnInput = null;
                        oInput = null;
                    }
                    if (sHtml.length > 0){
                        oForm.innerHTML += sHtml;
                    }
                }
                if ( typeof( oParent ) != 'undefined' && oParent != null ){
                    oParent.appendChild( oForm );
                }
                try{
                    return oForm;
                }
                finally{
                    oForm = null;
                }
            }
        }
    }

    this.util = {
        api_desc: 'Sapphire utility methods and classes.',
        number:{
            parseFraction: function(sNumber){
                var saTemp = sNumber.split('/' );
                if (saTemp.length == 2 ){
                    var sT = saTemp[1].trim();
                    if (sT.indexOf(' ') == -1 ){
                        var iZ;
                        try{
                            iZ = parseFloat(sT);
                        }
                        catch( e ){
                            return NaN;
                        }
                    }
                    else{
                        return NaN;
                    }

                    var iX;
                    saTemp = saTemp[0].trim().split(' ');
                    if ( saTemp.length > 1 ){
                        try{
                            iX = parseFloat(saTemp[0].trim());
                        }
                        catch( e ){
                            return NaN;
                        }
                    }
                    else{
                        iX = 0;
                    }
                    var iY;
                    try{
                        iY = parseFloat(saTemp[saTemp.length-1].trim());
                    }
                    catch( e ){
                        return NaN;
                    }
                    if ( iZ > 0 && iY != 0 ){
                        if ( iX >= 0 ){
                            return ( iY / iZ ) + iX;
                        }
                        else{
                            return iX - ( iY / iZ );
                        }
                    }
                    else{
                        return NaN;
                    }

                }
                else{
                    return NaN;
                }
            },
            isNumber: function( sNumber, lAllowFraction ){
                var lReturn = false;
                var iI = sNumber.indexOf( '/' );
                if ( lAllowFraction && iI > -1 ){
                    var nNum = this.parseFraction(sNumber);
                    lReturn = !isNaN(nNum);
                }
                else{
                    var oC = sapphire.connection;
                    var iFound = sNumber.indexOf(oC.groupingSeparator);
                    if ( iFound != 0 && iFound != sNumber.length - 1){
                        var oU = sapphire.util.string;
                        var oRE1 = new RegExp(oU.escapeRegExp(oC.decimalSeparator));
                        var oRE2 = new RegExp(oU.escapeRegExp(oC.groupingSeparator),'g');
                        lReturn = !isNaN(sNumber.replace(oRE1,'.').replace(oRE2,''));
                    }
                }
                return lReturn;
            }
        },
        array:{
            findInArray: function( saArray, sValue, lIgnoreCase ){
                var iFound = -1;
                var iL = saArray.length;
                if (lIgnoreCase){
                    sValue = sValue.toLowerCase();
                }
                for ( var iIndex = 0; iIndex < iL; iIndex++ ){
                    var sItem = saArray[iIndex];
                    if (lIgnoreCase){
                        sItem = sItem.toLowerCase();
                    }
                    if ( sItem == sValue ){
                        iFound = iIndex;
                        break;
                    }
                }
                return iFound;
            },
            toString: function(saArray, sDelim){
                var sReturn = '';
                if ( typeof(sDelim) == 'undefined'){
                    sDelim = ';';
                }
                else if ( sDelim == ','){
                    return saArray.toString();
                }
                var iL = saArray.length;
                for ( var iIndex = 0; iIndex < iL; iIndex++ ){
                    if ( iIndex > 0 ){
                        sReturn += sDelim;
                    }
                    sReturn += saArray[iIndex];
                }
                return sReturn;
            }
        },
        url:{
            defaultExcludes: {'page':true,'command':true,'file':true,'sdcid':true},
            href: function(sUrl, lEncode, oQueryExcludes, fQueryProcess, lSimple) {
                this.url = sUrl;
                this.address='';
                this.protocol='';
                this.server='';
                this.port=-1;
                this.page='';
                this.queryString='';
                this.query={};
                this.queryExclude='';
                var lHasQuery = false;
                var lQuick = (lSimple==true);

                this.get = function(lFull, lDecode){
                    function queryEx(sQueryEx){
                        var sT = '';
                        if (sQueryEx.length > 0){
                            sT += '?' + sQueryEx;
                            if (lHasQuery && lFull){
                                sT += '&';
                            }
                        }
                        else{
                            if (lHasQuery && lFull){
                                sT += '?';
                            }
                        }
                        return sT;
                    }
                    var sOut = '';
                    if (lQuick){
						sOut += this.address + queryEx(this.queryExclude);
                    }
                    else{
                        if (this.protocol.length > 0){
                            sOut += this.protocol + '://';
                        }
                        if (this.server.length > 0){
                            sOut += this.server;
                            if (!isNaN(this.port) && this.port > -1){
                                sOut += ':' + this.port;
                            }
                        }
                        if (this.page.length > 0){
                            if (sOut.length >0){
                                sOut += '/';
                            }
                            sOut += this.page + queryEx(this.queryExclude);
                        }
                        else if (lHasQuery > 0 && lFull){
                            sOut += '/?';
                        }
                    }
                    var sQS = '';
                    if (lFull){
                        for (var sParam in this.query){
                            if (sQS.length > 0){
                                sQS += '&'
                            }
                            var sValue = this.query[sParam];
                            if (lDecode && sValue.indexOf('%') > -1){
                                try{
                                    sValue = decodeURIComponent(sValue);
                                }catch(e){}
                            }
                            sQS += sParam + '=' + sValue;
                        }
                    }
                    return sOut + sQS;
                }
                var iS = sUrl.indexOf('?');
                if (iS > -1){
                    this.address = sUrl.substr(0, iS);
                    this.queryString = sUrl.substr(iS + 1);
                }
                else{
                    iS = sUrl.indexOf('&');
                    if (iS > -1){
                        this.address = sUrl.substr(0, iS);
                        this.queryString = sUrl.substr(iS + 1);
                    }
                    else{
                        this.address = sUrl;
                    }
                }
                if (!lQuick){
                    var sAddress = this.address;

                    iS = sUrl.indexOf(':')
                    if (iS > -1){
                        this.protocol = sAddress.substr(0,iS);
                        sAddress = sAddress.substr(iS + 3);
                        iS = sAddress.indexOf(':')
                        if (iS > -1){
                            this.server = sAddress.substr(0,iS);
                            sAddress = sAddress.substr(iS + 1);
                            iS = sAddress.indexOf('/');
                            if (iS > -1){
                                this.port = parseInt(sAddress.substr(0, iS));
                                this.page = sAddress.substr(iS + 1);
                            }
                            else{
                                this.port = parseInt(sAddress.substr(0));
                                this.page = '';
                            }
                        }
                        else{
                            iS = sAddress.indexOf('/');
                            if (iS > -1){
                                this.server = sAddress.substr(0, iS);
                                this.page = sAddress.substr(iS + 1);
                            }
                            else{
                                this.server = sAddress;
                                this.page = '';
                            }
                        }
                    }
                    else{
                        this.page = sAddress;
                    }
                }

				if (this.queryString.length > 0){
                    var saParts = this.queryString.split('&');
                    var iL = saParts.length;
                    for (var iIndex = 0; iIndex < iL; iIndex++){
                        var sItem = saParts[iIndex];
                        var iEq = sItem.indexOf('=');
                        if (iEq > -1){
                            var sParam = sItem.substr(0, iEq);
                            var sValue = '';
                            if (iEq < sItem.length - 1){
                                sValue = sItem.substr(iEq+1);
                            }
                            if (lEncode){
                                if (sValue.indexOf('%') > -1){
                                    try{
                                        sValue = decodeURIComponent(sValue);
                                    }catch(e){}
                                }
                                sValue = encodeURIComponent(sValue);
                            }
                            if(typeof(oQueryExcludes) == 'undefined' || oQueryExcludes == null || typeof(oQueryExcludes[sParam]) == 'undefined'){
								this.query[sParam] = sValue;
                                if (!lHasQuery){
                                    lHasQuery = true;
                                }
                                if(typeof(fQueryProcess) != 'undefined' && fQueryProcess != null){
                                    sapphire.call(fQueryProcess, new Array(sParam, sValue), this);
                                }
                            }
                            else{
                                if (this.queryExclude.length > 0){
                                    this.queryExclude += '&';
                                }
                                this.queryExclude += sParam + '=' + sValue;
                            }
                        }
                    }
                }
            },
            encode: function(sUrl){
                var oHref = new this.href(sUrl,true, null, null, true);
                return oHref.get(true, false);
            },
            decode: function(sUrl){
                var oHref = new this.href(sUrl,false, null, null, true);
                return oHref.get(true, true);
            },
            addToForm: function(sUrl, oForm, oExcludes){
                if (typeof(oForm) == 'undefined' || oForm == null){
                    oForm = sapphire.ajax.util.createForm('',true)
                }
                var oHref = new this.href(sUrl,false,oExcludes,function(sParam, sValue){
                    sapphire.util.dom.setFormField(oForm, sParam, sValue, 'hidden', sParam );
                }, true);
                oForm.action = oHref.get(false, false);
                return oForm;
            },
            getFromForm: function(oForm){
                var oInputs = oForm.elements;
                var iL = oInputs.length;
                var sUrl = '';
                for (var iIndex = 0; iIndex < iL; iIndex++){
                    var sName = typeof(oInputs[iIndex].name) != 'undefined'?oInputs[iIndex].name:'';
                    if (sName.length == 0){
                        sName = typeof(oInputs[iIndex].id) != 'undefined'?oInputs[iIndex].id:'';
                    }
                    if (sName.length > 0 && typeof(oInput[iIndex].value) != 'undefined'){
                        if (sUrl.length > 0){
                            sUrl += '&';
                        }
                        sUrl += sName + '=' + oInput[iIndex].value;
                    }
                }
                if (oForm.action.length > 0){
                    var iQ = oForm.action.indexOf('?');
                    if (iQ == -1){
                        sUrl = oForm.action + '?' + sUrl;
                    }
                    else if (iQ == oForm.action.length - 1){
                        sUrl = oForm.action + sUrl;
                    }
                    else{
                        sUrl = oForm.action + '&' + sUrl;
                    }
                }
                return sUrl;
            }
        },
        string:{
            escapeRegExp: function(sStr){
              if (typeof(this.oRE) == 'undefined') {
                var saSpecials = [
                  '/', '.', '*', '+', '?', '|',
                  '(', ')', '[', ']', '{', '}', '\\'
                ];
                this.oRE = new RegExp(
                  '(\\' + saSpecials.join('|\\') + ')', 'g'
                );
              }
              return sStr.replace(this.oRE, '\\$1');
            },
            trim: function(sString, sChars) {
                return this.leftTrim(this.rightTrim(sString, sChars), sChars);
            },
            leftTrim: function(sString, sChars) {
                sChars = sChars || '\\s';
                return sString.replace(new RegExp('^[' + sChars + ']+', 'g'), '');
            },
            rightTrim: function(sString, sChars) {
                sChars = sChars || '\\s';
                return sString.replace(new RegExp('[' + sChars + ']+$', 'g'), '');
            },
            getTokens: function( sInput, sStartToken, sEndToken ) {
                var saTokenlist = new Array();
                var iStartoffset = sStartToken.length;
                if (typeof(sInput) != 'undefined' && sInput.length > 0) {
                    var iSearchfrom = 0;
                    do {
                        var iPos1 = sInput.indexOf(sStartToken, iSearchfrom);
                        if ( iPos1 >= 0 ) {
                            // Search for the end token
                            var iPos2 = sInput.indexOf(sEndToken, iPos1 + 1);
                            if ( iPos2 > 0 ) {
                                iSearchfrom = iPos2 + 1;
                                var sNewvalue = sInput.substring(iPos1 + iStartoffset, iPos2);
                                if ( saTokenlist.find(sNewvalue, true) == -1 ) {
                                    saTokenlist.push(sNewvalue);
                                }
                            }
                            else{
                                break;
                            }
                        }
                        else{
                            break;
                        }
                    } while ( true );
                }
                return saTokenlist;
            },
            replaceAll: function ( sStr, sOld, sNew, lIgnoreCase, lUseRegExp ) {
                if ( typeof(lUseRegExp) == 'undefined' || lUseRegExp ){
                    var sP = 'g';
                    if (lIgnoreCase){
                        sP += 'i';
                    }
                    sStr = sStr.replace(new RegExp(sapphire.util.string.escapeRegExp(sOld),sP), sNew);
                }
                else{
                    var sSearch = lIgnoreCase?sStr.toLowerCase():sStr;
                    var sFind = lIgnoreCase?sOld.toLowerCase():sOld;
                    var iIndex = sSearch.indexOf(sFind);
                    while ( iIndex != -1 ) {
                        sStr = sStr.substr(0,iIndex) + sNew + sStr.substr(iIndex + sOld.length);
                        sSearch = lIgnoreCase?sStr.toLowerCase():sStr;
                        iIndex = sSearch.indexOf(sFind);
                    }
                }
                return sStr;
            },
            startsWith: function( sStr, sPrefix ) {
                var sRetValue = false;
                if ( typeof( sPrefix ) == 'string' && sStr.indexOf(sPrefix) == 0 ) {
                    sRetValue = true;
                }
                return sRetValue;
            },
            endsWith: function( sStr, sPostfix ) {
                var sRetValue = false;
                if ( typeof( sPostfix ) == 'string' && sStr.indexOf(sPostfix) == sStr.length - sPostfix.length) {
                    sRetValue = true;
                }
                return sRetValue;
            }
        },
        timer:{
            iaTimes: new Array(),
            iaNames: new Array(),
            start: function(){
                this.reset();
                this.iaTimes.push(new Date().getTime());
                this.iaNames.push('Start');
            },
            lap: function(sName){
                if ( typeof(sName) == 'undefined'){
                    sName = 'Lap ' + (this.iaTimes.length - 1);
                }
                this.iaTimes.push(new Date().getTime());
                this.iaNames.push(sName);
            },
            getElapsed: function(lFromStart){
                if (this.iaTimes.length > 0){
                    if (lFromStart){
                        return ((new Date().getTime()) - this.iaTimes[0])
                    }
                    else{
                        return ((new Date().getTime()) - this.iaTimes[this.iaTimes.length-1])
                    }
                }
                else{
                    return 0;
                }
            },
            stop: function(){
                this.iaTimes.push(new Date().getTime());
                this.iaNames.push('Stop');
                this.report();
            },
            report: function(){
                var iL = this.iaTimes.length;
                if (iL > 0){
                    if (iL > 1){
                        var sMsg = '';
                        if ( iL > 2 ){
                            for ( var i = 1; i < iL; i++ ){
                                sMsg += this.iaNames[i] + ' = ' + ((this.iaTimes[i] - this.iaTimes[i-1]) / 1000)  + ' sec\n'
                            }
                            sMsg += (sTransStartToken + 'Overall' + sTransEndToken) + ' = ' + ((this.iaTimes[iL-1] - this.iaTimes[0]) / 1000)  + ' sec'

                        }
                        else{
                            sMsg += (sTransStartToken + 'Time' + sTransEndToken) + ' = ' + ((this.iaTimes[1] - this.iaTimes[0]) / 1000)  + ' sec'
                        }
                        sapphire.alert(sMsg, false);

                    }
                    else{
                        sapphire.alert(sTimerMsg1);
                    }
                }
                else{
                    sapphire.alert(sTimerMsg2);
                }
            },
            reset: function(){
                this.iaTimes = new Array();
                this.iaNames = new Array();
            }
        },
        propertyList: {
            api_desc: 'Sapphire API for handling client side propertylists (JSON Rendered)',
            create: function( oPropertyList ){
                function propertylist(){
                }
                if ( typeof(oPropertyList) == 'undefined' ){
                    oPropertyList = new propertylist;
                }
                else if ( typeof(oPropertyList) == 'string' ){
                    if(typeof(JSON) != 'undefined'){
                        oPropertyList = JSON.parse(oPropertyList);
                    }
                    else{
                        oPropertyList = eval('(' + oPropertyList + ')');
                    }
                }
                else if ( typeof(oPropertyList) == 'object' && typeof(oPropertyList.tagName) != 'undefined' && oPropertyList.tagName == 'FORM' ){
                    var oForm = oPropertyList;
                    oPropertyList = new propertylist;
                    var iL = oForm.children.length;
                    for ( var iIndex = 0; iIndex < iL; iIndex++){
                        var oCN = oForm.children[iIndex];
                        var sPropName = '';
                        if ( typeof(oCN.name) != 'undefined' && oCN.name.length > 0 ){
                            sPropName = oCN.name;
                        }
                        else if ( typeof(oCN.id) != 'undefined' && oCN.id.length > 0 ){
                            sPropName = oCN.id;
                        }
                        if ( sPropName.length > 0 && typeof(oCN.value) != 'undefined' ){
                            sapphire.util.propertyList.set( oPropertyList, sPropName, oCN.value );
                        }
                    }
                }
                oPropertyList.set = function( sPropertyId, oValue ){
                    sapphire.util.propertyList.set( this, sPropertyId, oValue );
                }
                oPropertyList.add = function( sPropertyId, oValue ){
                    sapphire.util.propertyList.add( this, sPropertyId, oValue );
                }
                oPropertyList.get = function( sPropertyId, sDefault ){
                    return sapphire.util.propertyList.get( this, sPropertyId, sDefault );
                }
                oPropertyList.getPropertyList = function( sPropertyId ){
                    return sapphire.util.propertyList.getPropertyList( this, sPropertyId );
                }
                oPropertyList.getCollection = function( sPropertyId ){
                    return sapphire.util.propertyList.getCollection( this, sPropertyId );
                }
                oPropertyList.remove = function( sPropertyId ){
                    sapphire.util.propertyList.get( this, sPropertyId );
                }
                oPropertyList.getId = function( ){
                    return sapphire.util.propertyList.getId( this );
                }
                oPropertyList.setId = function( sId ){
                    sapphire.util.propertyList.getId( this, sId );
                }
                oPropertyList.setId = function( sId ){
                    sapphire.util.propertyList.setId( this, sId );
                }
                oPropertyList.setSequence = function( vSequence ){
                    sapphire.util.propertyList.setSequence( this, vSequence );
                }
                oPropertyList.getSequence = function( ){
                    return sapphire.util.propertyList.setSequence( this );
                }
                oPropertyList.toForm = function( ){
                    return sapphire.util.propertyList.toForm( this );
                }
                oPropertyList.toJSONString = function( ){
                    return sapphire.util.propertyList.toJSONString( this );
                }
                oPropertyList.clone = function( ){
                    return sapphire.util.propertyList.clone( this );
                }
                return oPropertyList;
            },
            set: function( oPropertyList, sPropertyId, oValue ){
                oPropertyList[sPropertyId] = oValue;
            },
            add: function( oPropertyList, sPropertyId, oValue ){
                this.set( oPropertyList, sPropertyId, oValue );
            },
            get: function( oPropertyList, sPropertyId, sDefault ){
                if ( typeof( oPropertyList[sPropertyId] ) == 'undefined ' || oPropertyList[sPropertyId] == null ){
                    if ( typeof(sDefault) != 'undefined' ){
                        return sDefault;
                    }
                    else{
                        return null;
                    }
                }
                else{
                    return oPropertyList[sPropertyId];
                }
            },
            getId: function( oPropertyList ){
                return this.get( oPropertyList, '__propertylistid', '' );
            },
            setId: function( oPropertyList, sId ){
                this.set( oPropertyList, '__propertylistid', sId );
            },
            getSequence: function( oPropertyList ){
                return this.get( oPropertyList, '__propertylistsequence', '' );
            },
            setSequence: function( oPropertyList, vSequence ){
                this.set( oPropertyList, '__propertylistsequence', vSequence );
            },
            remove: function( oPropertyList, sPropertyId ){
                if ( tyepeof (oPropertyList[sPropertyId]) != 'undefined' ){
                    delete oPropertyList[sPropertyId];
                }
            },
            getCollection: function( oPropertyList, sPropertyId ){
                return sapphire.util.propertyListCollection.create( this.get( oPropertyList, sPropertyId, sapphire.util.propertyListCollection.create() ) );
            },
            getPropertyList: function( oPropertyList, sPropertyId ){
                return sapphire.util.propertyList.create( this.get( oPropertyList, sPropertyId, sapphire.util.propertyList.create() ) );
            },
            toForm: function( oPropertyList ){
                var oForm = document.createElement( 'form' );
                var sHtml = '';
                for ( var o in oPropertyList ){
                    if ( typeof(oPropertyList[o]) != 'object' && typeof(oPropertyList[o]) != 'function' && (o + '').length > 0){
                        var oInput;
                        if (sapphire.browser.ie){
                            oInput = document.createElement( '<input type="hidden" name="' + o + '">' );
                        }
                        else{
                            oInput = document.createElement( 'input' );
                            oInput.type = 'hidden';
                            oInput.name = '' + o;
                        }
                        oInput.value = '' + oPropertyList[o];
                        try{
                            oForm.appendChild(oInput);
                        }
                        catch(e){
                            sHtml += sapphire.util.dom.getOuterHTML(oInput);
                        }
                    }
                }
                if (sHtml.length > 0){
                    oForm.innerHTML += sHtml;
                }
                return oForm;
            },
            toJSONString: function( oPropertyList ){
                if ( typeof(JSON) != 'undefined'){
                    return JSON.stringify( oPropertyList );
                }
                else{
                    return '';
                }
            },
            clone: function( oPropertyList ){
                return this.create(oPropertyList.toJSONString());
            }
        },
        propertyListCollection: {
            api_desc: 'Sapphire API for handling client side propertylistcollection (JSON Rendered)',
            create: function( oCollection ){
                if ( typeof(oCollection) == 'undefined' ){
                    oCollection = new Array();
                }
                else if ( typeof(oCollection) == 'string' ){
                    if(typeof(JSON) != 'undefined'){
                        oCollection = JSON.parse(oCollection);
                    }
                    else{
                        oCollection = eval('(' + oCollection + ')');
                    }
                }
                else if ( typeof(oCollection.length) == 'undefined'){
                    var oNew = new Array();
                    for (var oKey in oCollection){
                        oNew[oKey] = oCollection[oKey];
                    }
                    oCollection = oNew;
                }
                oCollection.add = function( oPropertyList, vKeyOrIndex ){
                    sapphire.util.propertyListCollection.add( this, oPropertyList, vKeyOrIndex );
                }
                oCollection.get = function( vKeyOrIndex ){
                    return sapphire.util.propertyListCollection.get( this, vKeyOrIndex );
                }
                oCollection.remove = function( iIndex ){
                    sapphire.util.propertyListCollection.remove( this, iIndex );
                }
                oCollection.find = function( sPropertyId, sValue ){
                    return sapphire.util.propertyListCollection.find( this, sPropertyId, sValue );
                }
                oCollection.findIndex = function( sPropertyId, sValue ){
                    return sapphire.util.propertyListCollection.findIndex( this, sPropertyId, sValue );
                }
                oCollection.move = function( iIndex, iDelta ){
                    return sapphire.util.propertyListCollection.move( this, iIndex, iDelta );
                }
                oCollection.copy = function( iIndex, iCopies ){
                    return sapphire.util.propertyListCollection.copy( this, iIndex, iCopies );
                }
                oCollection.clone = function( ){
                    return sapphire.util.propertyListCollection.clone( this );
                }
                oCollection.clear = function( ){
                    sapphire.util.propertyListCollection.clear( this );
                }
                oCollection.toJSONString = function( ){
                    return sapphire.util.propertyListCollection.toJSONString( this );
                }
                return oCollection;
            },
            get: function( oPropertyListCollection, vKeyOrIndex ){
                return sapphire.util.propertyList.create( oPropertyListCollection['' + vKeyOrIndex] );
            },
            add: function( oPropertyListCollection, oPropertyList, vKeyOrIndex ){
                if ( typeof( vKeyOrIndex ) == 'undefined' ){
                    var iMax = -1;
                    for ( var sKey in oPropertyListCollection ){
                        var iKey = parseInt(sKey);
                        if ( !isNaN(iKey) ){
                            if ( iKey > iMax ){
                                iMax = iKey;
                            }
                        }
                    }
                    if ( iMax == -1 ){
                        vKeyOrIndex = 0;
                    }
                    else{
                        vKeyOrIndex = iMax + 1;
                    }
                    oPropertyListCollection['' + vKeyOrIndex] = oPropertyList;
                }
                else{
                    oPropertyListCollection['' + vKeyOrIndex] = oPropertyList;
                }
            },
            remove: function( oPropertyListCollection, iIndex ){
                oPropertyListCollection.splice( iIndex, 1);
            },
            findIndex: function( oPropertyListCollection, sPropertyId, sValue ){
                var iFound = -1;
                var iL = oPropertyListCollection.length;
                for ( var iIndex = 0; iIndex < iL; iIndex++ ){
                    var oItem = oPropertyListCollection[iIndex];
                    if ( typeof( oItem[sPropertyId] ) != 'undefined' && oItem[sPropertyId] == sValue ){
                        iFound = iIndex;
                        break;
                    }
                }
                return iFound;
            },
            find: function( oPropertyListCollection, sPropertyId, sValue ){
                var iFound = this.findIndex( oPropertyListCollection, sPropertyId, sValue );
                var oFound = oPropertyListCollection[iFound];
                if ( oFound == null ){
                    return null;
                }
                else{
                    return sapphire.util.propertyList.create( oFound );
                }
            },
            move: function( oPropertyListCollection, iIndex, iDelta) {
              if ( iIndex < 0 || iIndex >= oPropertyListCollection.length) {
                return -1;
              }
              var iTarIndex = iIndex + iDelta;
              if (iTarIndex < 0 || iTarIndex >= oPropertyListCollection.length || iTarIndex == iIndex) {
                return -1;
              }
              var oTemp = oPropertyListCollection[iTarIndex];
              oPropertyListCollection[iTarIndex] = oPropertyListCollection[iIndex];
              oPropertyListCollection[iIndex] = oTemp;
              return iTarIndex;
            },
            copy: function( oPropertyListCollection, iIndex, iCopies) {
              if ( typeof (iCopies ) == 'undefined' || iCopies < 1 ){
                  iCopies = 1;
              }
              if ( iIndex < 0 || iIndex >= oPropertyListCollection.length) {
                return -1;
              }
              var oTemp = oPropertyListCollection[iIndex];
              if ( oTemp != null ){
                  var sTemp = objectToJSONString( oTemp );
                  for ( var iI = 0; iI < iCopies; iI++ ){
                      var oNew = eval( '(' + sTemp + ')' );
                      if ( oNew != null ){
                          this.add( oPropertyListCollection, oNew );
                      }
                  }
              }

              return oPropertyListCollection.length - 1;
            },
            clear: function( oPropertyListCollection ){
                var iL = oPropertyListCollection.length;
                for ( var iIndex = iL - 1; iIndex > -1; iIndex-- ){
                    this.remove(oPropertyListCollection, iIndex);
                }
            },
            clone: function( oPropertyListCollection ){
                //return this.create(oPropertyListCollection);
                return this.create(oPropertyListCollection.toJSONString());
            },
            toJSONString: function( oPropertyListCollection ){
                if ( typeof(JSON) != 'undefined'){
                    return JSON.stringify( oPropertyListCollection );
                }
                else{
                    return '';
                }
            }
        },
        getAll: function( oElement ){
            return this.dom.getAll(oElement);
        },
        evaluateExpression: function(sString){
            var saToks = sString.getTokens('[',']');
            var iL = saToks.length;
            for ( var iIndex = 0; iIndex < iL; iIndex++){
                var sTok = saToks[iIndex].toLowerCase();
                var sVal = '';
                if ( sTok.indexOf('javascript:') == 0 ){
                    try{
                        sVal = eval(saToks[iIndex]);
                    }
                    catch(e){
                    }
                }
                else{
                    if (sTok.indexOf('columnid:') == 0){
                        sTok = sTok.substr(9);
                    }
                    else if (sTok.indexOf('fieldid:') == 0){
                        sTok = sTok.substr(8);
                    }
                    if ( sTok == 'keyid1' ){
                        sVal = sapphire.page.getKeyId1(true);
                    }
                    else if ( sTok == 'sdcid' ){
                        sVal = sapphire.page.getSDCId();
                    }
                    else{
                        if ( sTok.indexOf('.') > -1 ){
                            var saTok = sTok.split('.');
                            sVal = sapphire.page.getSelected(saTok[1],saTok[0]);
                        }
                        else{
                            sVal = sapphire.page.getSelected(sTok);
                        }
                    }
                }
                //sString = sString.replace(new RegExp('\\[' + this.string.escapeRegExp(saToks[iIndex]) + '\\]','gi'), sVal);
                sString = sString.replaceAll('[' + saToks[iIndex] + ']', sVal, true);
            }
            return sString;
        },
        script:{
            createProxyFunction: function(vOldFunc){
                if (typeof(vOldFunc) == 'string'){
                    vOldFunc = eval(vOldFunc);
                }
                var sFunc = '' + vOldFunc;
                sFunc = sFunc.substr(sFunc.indexOf('{'));
                return new Function(sFunc);
            },
            eval: function(sScript, oaWindows){
                var oReturn;
                if ( typeof(oaWindows) == 'undefined' || oaWindows.length == 0){
                    oaWindows = [window];
                }
                var iL = oaWindows.length;
                var oErr = null;
                for (var iIndex = 0; iIndex < iL; iIndex++){
                    if (oaWindows[iIndex] != null){
                        try{
                            oReturn = oaWindows[iIndex].eval(sScript);
                            oErr = null;
                            break;
                        }
                        catch(e2){
                            oErr = e2;
                            if ( e2.name != 'TypeError' && e2.description.toLowerCase() != 'object expected' ){
                                throw e2;
                            }
                        }
                    }
                }
                if (oErr != null){
                    throw oErr;
                }
                else{
                    return oReturn;
                }
            },
            execScript: function(sScript, oThis, oaWindows){
                var oReturn;
                var oFunc;
                if ( typeof(oThis) != 'object' || oThis == null ){
                    oThis = this;
                }
                if ( typeof(oaWindows) == 'undefined' || oaWindows.length == 0){
                    oaWindows = [window];
                }
                var iL = oaWindows.length;
                var oErr = null;
                for (var iIndex = 0; iIndex < iL; iIndex++){
                    if (oaWindows[iIndex] != null){
                        try{
                            oFunc = oaWindows[iIndex].Function(sScript);
                            oReturn = oFunc.apply(oThis,[]);
                            oErr = null;
                            break;
                        }
                        catch(e2){
                            oErr = e2;
                            if ( e2.name != 'TypeError' && e2.description.toLowerCase() != 'object expected' ){
                                throw e2;
                            }
                        }
                    }
                }
                if (oErr != null){
                    throw oErr;
                }
                else{
                    return oReturn;
                }
            }
        },
        dom:{
            getElementByName: function(sName, oDoc){
                if (typeof(oDoc) == 'undefined'){
                    oDoc = document;    
                }
                var oEl = null;
                if (sapphire.browser.ie){
                    oEl = oDoc.getElementById(sName);
                }
                else{
                    var oEls = oDoc.getElementsByName(sName);
                    if (oEls != null && oEls.length > 0){
                        oEl = oEls[0]
                    }
                }
                return oEl;
            },
            getAttribute: function(vEl, sAttribute){
                if (typeof(vEl) == 'string'){
                    vEl = document.getElementById(vEl);
                }
                if (sapphire.browser.ie){
                    return vEl[sAttribute];
                }
                else{
                    return vEl.getAttribute(sAttribute);
                }
            },
            setAttribute: function(vEl, sAttribute, vValue){
                if (typeof(vEl) == 'string'){
                    vEl = document.getElementById(vEl);
                }
                if (sapphire.browser.ie){
                    vEl[sAttribute] = vValue
                }
                else{
                    vEl.setAttribute(sAttribute,vValue);
                }
            },
            containsNode: function(oParent, oChild){
                if (oParent.contains){
                    return oParent.contains(oChild);
                }
                else{
                    function contains(oParent, oChild){
                        var lFound = false;
                        if (oParent.childNodes){
                            var iL = oParent.childNodes.length;
                            for (var iIndex = 0; iIndex < iL; iIndex++){
                                var oNode = oParent.childNodes[iIndex];
                                if (oNode == oChild){
                                    lFound = true;
                                }
                                else if (oNode.hasChildNodes && oNode.hasChildNodes()){
                                    lFound = contains(oNode, oChild);
                                }
                                if (lFound){
                                    break;
                                }
                            }
                        }
                        return lFound;
                    }
                    return contains(oParent, oChild);
                }

            },
            getAll: function(oElement){
                function doAll(oParent, oArray){
                    for ( var iIndex = 0; iIndex < oParent.childNodes.length; iIndex++ ){
                        var oNode = oParent.childNodes[iIndex];
                        if ( typeof(oNode.name) != 'undefined' && oNode.name.length > 0){

                            if ( typeof(oArray[oNode.name]) != 'undefined' ){
                                var oVal = oArray[oNode.name];
                                if ( typeof(oVal.splice) == 'undefined' && typeof(oVal.push) == 'undefined' ){
                                    var oOld = oVal;
                                    oVal = new Array();
                                    oVal.push(oOld);
                                }
                                oVal.push(oNode);
                                oArray[oNode.name] = oVal;
                            }
                            else{
                                oArray[oNode.name] = oNode;
                            }
                        }
                        else{
                            oArray.push( oNode );
                        }
                        if ( oNode.hasChildNodes() ){
                            doAll( oNode, oArray );
                        }
                    }
                }
                if ( oElement.all ){
                    return oElement.all;
                }
                else{
                    var oaAll = new Array();
                    doAll( oElement, oaAll );
                    return oaAll;
                }

            },
            setFormField: function(vForm, sName, sValue, sType, sId){
                if (typeof(vForm) == 'string'){
                    vForm = document.getElementById(vForm);
                }
                if (vForm != null){
                    if (typeof(sName) != 'undefined' && typeof(sValue) != 'undefined'){
                        if ( sValue.indexOf('%') > -1 ) {
							try {
								sValue = decodeURIComponent(sValue);
							}
							catch( e ) {
							}
						}
                        var oInput = vForm[sName];
                        if (typeof(oInput) == 'undefined' || oInput == null){
                            if (sapphire.browser.ie){
                                oInput = document.createElement( '<input name="' + sName + '">' );
                            }
                            else{
                                oInput = document.createElement( 'input' );
                                oInput.name = sName;
                            }
                            if (typeof(sId) != 'undefined'){
                                oInput.id = sId;
                            }
                            else{
                                oInput.id = sName;
                            }
                            if (typeof(sType) != 'undefined'){
                                oInput.type = sType;
                            }
                            else{
                                oInput.type = 'hidden';
                            }
                            oInput.value = sValue;
                            try{
                                vForm.appendChild(oInput);
                            }
                            catch(e){
                                vForm.innerHTML += sapphire.util.dom.getOuterHTML(oInput);
                            }
                        }
                        else{
                            oInput.value = sValue;
                        }

                    }
                }
            },
            getOuterHTML: function(oEl){
                if (typeof(oEl.outerHTML) != 'undefined'){
                    return oEl.outerHTML;
                }
                else{
                    var oDiv = document.createElement('div');
                    var oClone = oEl.cloneNode(true);
                    oDiv.appendChild(oClone);
                    return oDiv.innerHTML
                }
            }
        },
        date:{
            MILLISECONDS: 1,
            SECONDS: 1000,
            MINUTES: (1000 * 60),
            HOURS: (1000 * 60 * 60),
            DAYS: (1000 * 60 * 60 * 24),
            WEEKS: (1000 * 60 * 60 * 24 * 7),
            MONTHS: ((1000 * 60 * 60 * 24 * 7 * 52) / 12),
            YEARS: (1000 * 60 * 60 * 24 * 7 * 52),
            compare: function(dDate1,dDate2){
                var iMil1 = dDate1.getTime();
                var iMil2 = dDate2.getTime();
                if (iMil2 > iMil1){
                    return 1;
                }
                else if (iMil2 < iMil1){
                    return -1;
                }
                else{
                    return 0;
                }
            },
            compareTime: function(dDate1, dDate2, iTimeType){
                if (typeof(iTimeType) == 'undefined'){
                    iTimeType = this.DAYS;
                }
                var iT1 = dDate1.getTime();
                var iT2 = dDate2.getTime();
                var iDiff = iT2 - iT1;
                return Math.floor(iDiff / iTimeType);
            }
        }
    }

    String.prototype.getTokens =  function( sStartToken, sEndToken ){
        return sapphire.util.string.getTokens( this, sStartToken, sEndToken );
    }
    String.prototype.trim =  function( sChar ){
        return sapphire.util.string.trim( this, sChar );
    }
    String.prototype.leftTrim =  function( sChar ){
        return sapphire.util.string.leftTrim( this, sChar );
    }
    String.prototype.rightTrim =  function( sChar ){
        return sapphire.util.string.rightTrim( this, sChar );
    }
    String.prototype.replaceAll =  function( sOld, sNew, lIgnore, lRegExp ){
        return sapphire.util.string.replaceAll( this, sOld, sNew, lIgnore, lRegExp );
    }
    String.prototype.startsWith =  function( sPrefix ){
        return sapphire.util.string.startsWith( this, sPrefix );
    }
    String.prototype.endsWith =  function( sPostfix ){
        return sapphire.util.string.endsWith( this, sPostfix );
    }
    String.prototype.translate =  function(lPartial){
        if ( this.length > 0 ){
            if (typeof(lPartial) != 'undefined' && lPartial){
                return sapphire.translatePartial( this );
            }
            else if (typeof(lPartial) != 'undefined'){
                return sapphire.translate( this );
            }
            else{
                if ( this.indexOf(sTransStartToken) > -1 && this.indexOf(sTransEndToken) > -1){
                    return sapphire.translatePartial( this );
                }
                else{
                    return sapphire.translate( this );
                }
            }
        }
        else{
            return this;
        }
    }
    Array.prototype.find =  function( sValue, lIgnoreCase ){
        return sapphire.util.array.findInArray( this, sValue, lIgnoreCase );
    }
    Array.prototype.toDelimitedString =  function( sDelim ){
        return sapphire.util.array.toString( this, sDelim );
    }
    Date.prototype.compare = function( dDate2 ){
        return sapphire.util.date.compare( this, dDate2 );
    }
    Date.prototype.compareDays = function( dDate2 ){
        return sapphire.util.date.compareTime( this, dDate2, sapphire.util.date.DAYS );
    }
    Date.prototype.compareMonths = function( dDate2 ){
        return sapphire.util.date.compareTime( this, dDate2, sapphire.util.date.MONTHS );
    }
    Date.prototype.compareYears = function( dDate2 ){
        return sapphire.util.date.compareTime( this, dDate2, sapphire.util.date.YEARS );
    }

    var lTopBarAlt = false;
    var lSideBarAlt = false;

    this.page = {
        api_desc: 'Sapphire API for storing page level data and methods.',
        iLIST:0,
        iMAINT:1,
        iDATAENTRY:2,
        iOTHER:3,
        getPageType: function(){
            if ( this.pageType == -1 && typeof(this.data) != 'undefined' && typeof(this.data.propertytreeid) != 'undefined'){
                var sPtree = this.data.propertytreeid;
                if ( sPtree == 'MaintenanceList' ){
                    this.pageType = this.iLIST;
                }
                else if ( sPtree == 'MaintenanceForm' ){
                    this.pageType = this.iMAINT;
                }
                else if ( sPtree == 'DataEntry' || sPtree == 'DataEntryByQuery' ){
                    this.pageType = this.iDATAENTRY;
                }
                else{
                    this.pageType = this.iOTHER;
                }
            }
            return this.pageType;
        },
        pageType: -1,
        name: '',
        data: null,
        maximizeLayout: function(){
            if (typeof(top.__topBarToggle) != 'undefined' && top.__topBarToggle.visible){
                top.__topBarToggle.toggle(false, true, false);
                lTopBarAlt = true;
            }
            if (typeof(top.sideBarVisible) !='undefined' && top.sideBarVisible){
                top.simpleHideSideBar();
                lSideBarAlt = true;
            }
        },
        minimizeLayout: function(){
            if (lTopBarAlt && typeof(top.__topBarToggle) != 'undefined' && !top.__topBarToggle.visible){
                top.__topBarToggle.toggle(true, false, false);
                lTopBarAlt = false;
            }
            if (lSideBarAlt && typeof(top.sideBarVisible) !='undefined' && !top.sideBarVisible){
                top.simpleShowSideBar();
                lSideBarAlt = false;
            }
        },
        toggleLoading: function(lShow){
            if ( typeof(showProcessingDiv) != 'undefined' && typeof(hideProcessingDiv) != 'undefined' ){
                if ( lShow ){
                    showProcessingDiv();
                }
                else{
                    hideProcessingDiv();
                }
            }
        },
        navigate: function( sUrl, sRleaseLockFlag, sTarget, oForm, lAddToForm ){
            sapphire.statusMsg(sNavMsg + sUrl + '...',-1);
            if (typeof(lAddToForm) == 'undefined'){
                lAddToForm = true;
            }
            this.toggleLoading(true);
            var lDispose = false;
            if ( sUrl.indexOf( 'rc?' ) == -1 && sUrl.indexOf('http://') == -1 && sUrl.indexOf('/') == -1 ) {
                sUrl = 'rc?command=page&page=' + sUrl;
            }
            if ( typeof( oForm ) == 'undefined' || oForm == null ){
                oForm = sapphire.ajax.util.createForm( '', true, null, document.body, true );
                oForm.style.display = 'none';
                lDispose = true;
            }
            else{
                if ( (sapphire.browser.ie && oForm.parentElement == null) || oForm.parentNode == null ){
                    document.body.appendChild( oForm );
                    lDispose = true;
                }
                oForm.method = 'POST';
            }
            if (lAddToForm){
                sapphire.util.url.addToForm(sUrl,oForm,sapphire.util.url.defaultExcludes);
            }
            else{
                sUrl = sapphire.util.url.encode(sUrl);
                oForm.action = sUrl;
            }
            if ( typeof(sTarget) != 'undefined' ){
                oForm.target = sTarget;
            }
            if ( typeof( sRleaseLockFlag ) != 'undefined' ){
                sapphire.connection.releaseLock( sRleaseLockFlag );
            }
            try{
                oForm.submit();
            }
            finally{
                if (lDispose){
                    sapphire.garbage.add(oForm);
                }
            }
        },
        getKeyId: function (iNum, lFullSelection ){
            // will get keyid1 on any list, maint or dataentry page
            var sKeys = '';
            switch( this.getPageType() ){
                case this.iLIST:
                    sKeys = eval('this.list.getSelectedKeyId' + iNum + '()');
                    break;
                case this.iMAINT:
                    if (lFullSelection){
                        sKeys = eval('this.maint.getSelectedKeyId' + iNum + '()');
                    }
                    else{
                        sKeys = eval('this.maint.getKeyId' + iNum + '()');
                    }
                    break;
                case this.iDATAENTRY:
                    sKeys = eval('this.dataentry.getSelectedKeyId' + iNum + '()');
                    break;
                default:
                    sKeys = '';
                    break;
            }
            return sKeys.replace(/%3B/g,';');
        },
        getKeyId1: function( lFullSelection ){
            return this.getKeyId(1, lFullSelection);
        },
        getKeyId2: function( lFullSelection ){
            return this.getKeyId(2, lFullSelection);
        },
        getKeyId3: function( lFullSelection ){
            return this.getKeyId(3, lFullSelection);
        },
        getSelected: function( sColumn, sElementId ){
            var sSel = '';
            if ( typeof(sColumn) != 'undefined' && sColumn.length > 0 ){
                switch( this.getPageType() ){
                    case this.iLIST:
                        sSel = this.list.getSelectedValue(sColumn,'').replace(/%3B/g,';');
                        break;
                    case this.iMAINT:
                        if ( typeof(sElementId) == 'undefined' || sElementId.length == 0 || sElementId == 'maint'){
                            sSel = this.maint.getSelectedColumnValue(sColumn,';','|');
                        }
                        else{
                            if (this.elements.sdcLinkMaint.isSDCLinkMaint(sElementId)){
                                sSel = this.elements.sdcLinkMaint.getSelected(sElementId,sColumn).replace(/\|/g,';');
                            }
                            else{
                                sSel = '';
                            }
                        }
                        break;
                    case this.iDATAENTRY:
                        sSel = this.dataentry.getQuerySelectedKeys(sColumn).replace(/%3B/g,';');
                        break;
                    default:
                        sSel = '';
                        break;
                }
            }
            return sSel;
        },
        getSDCId: function(){
            switch( this.getPageType() ){
                case this.iLIST:
                    return typeof(document.submitdata)!='undefined'?document.submitdata['sdcid'].value:'';
                case this.iMAINT:
                    return typeof(document.submitdata)!='undefined'?document.submitdata['sdcid'].value:'';
                case this.iDATAENTRY:
                    return typeof(document.submitdata)!='undefined'?document.submitdata['sdcid'].value:'';
                default:
                    return '';
            }
        }
    }

    this.garbage = {
        api_desc: 'Sapphire API for managing DOM and JavaScript memory leaks.',
        bin: null,
        limit: 10,
        size: 0,
        toAdd: new Array(),
        collect: function( ){
            // cause an update to collect document object garbage
            if ( this.bin != null ){
                this.bin.innerHTML = '';
                this.size = 0;
            }
            // collect JS object garbage
            if (sapphire.browser.id == 'FF'){
                try{
                    window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils).garbageCollect();
                }
                catch(e){
                    //
                }
            }
            else{
                var oDoc = document;
                oDoc.innerHTML += ' ';
                oDoc.innerHTML -= ' ';
                if ( typeof(CollectGarbage) != 'undefined' ){
                    CollectGarbage();
                }
            }
        },
        add: function( vElement ){
            var oDoc = document;
            var oaElements = new Array();;
            if ( typeof(vElement) == 'string' ){
                var oElement = oDoc.getElementById( vElement );
                if ( oElement != null ){
                    oaElements.push( oElement );
                }
            }
            else if ( typeof(vElement.pop) != 'undefined' ){
                oaElements = vElement;
            }
            else{
                oaElements.push( vElement );
            }
            if (sapphire.browser.gc){
                oaElements = oaElements.concat(this.toAdd);
                var iLen = oaElements.length;

                if ( oDoc.readyState == 'complete' ){
                    this.toAdd = new Array();

                    if ( this.bin == null ){
                        this.bin = oDoc.createElement('DIV');
                        this.bin.id = 'SapphireGarbageBin';
                        this.bin.style.display = 'none';
                        oDoc.body.appendChild(this.bin);
                    }
                    for ( var iIndex = 0; iIndex < iLen; iIndex++ ){
                        var oEl = oaElements[iIndex];
                        var lFrag = false;
                        if ( oEl.parentNode != null ){
                            lFrag = (oEl.parentNode.nodeName == '#document-fragment');
                            oEl.parentNode.removeChild(oEl);
                        }
                        if (!lFrag){
                            oEl.id = '__gc_' + this.size;
                            var oaA = sapphire.util.getAll( oEl );//oEl.all;
                            var iL = oaA.length;
                            for ( var iS = 0; iS < iL; iS++ ){
                                var oSib = oaA[iS];
                                if ( typeof(oSib.id) != 'undefined' && oSib.id.length > 0 ){
                                    oSib.id = null;
                                }
                            }
                            this.bin.appendChild(oEl);
                            this.size++;
                        }
                        else if (typeof(oEl.innerHTML) != 'undefined'){
                                oEl.innerHTML = '';
                        }
                        oEl = null;
                        oaElements[iIndex] = null;
                    }
                    if ( this.size > this.limit ){
                        this.collect();
                    }
                }
                else{
                    // cannot completely remove, therefore cache
                    for ( var iIndex = 0; iIndex < iLen; iIndex++ ){
                        var oEl = oaElements[iIndex];
                        oEl.id = '';
                        oEl.name = '';
                        if ( oEl.parentNode != null ){
                            oEl.parentNode.removeChild(oEl);
                        }
                    }
                }
            }
            else{
                var iLen = oaElements.length;
                for ( var iIndex = 0; iIndex < iLen; iIndex++ ){
                    var oEl = oaElements[iIndex];
                    if ( oEl.parentNode != null ){
                        oEl.parentNode.removeChild(oEl);
                    }
                }
            }
        }
    }

    function Debug () {
        this.api_desc = 'Sapphire API for debugging JavaScript.';
        var sJSINFOPAGE = 'rc?command=file&file=WEB-CORE/utils/javascript/jsinfo.jsp';
        var oJSDialog = null;
        function  showJSInfo(){
            if ( oJSDialog == null  ){
                oJSDialog = sapphire.ui.dialog.open( 'JavaScript Tool', sJSINFOPAGE, false, 680, 350 );
            }
            else{
                if ( !top.window.document.body.contains( oJSDialog ) ){
                    oJSDialog = sapphire.ui.dialog.open( 'JavaScript Tool', sJSINFOPAGE, false, 680, 350 );
                }
                else{
                }
            }
        }
        this.show = function(){
            if ( sapphire.jsdebug ){
                showJSInfo();
            }
        }

        this.executeFunction = function(sFrameName, sFunctionText){
            var sRun;
            if (sFrameName == ''){
                sRun = sFunctionText;
            }
            else{
                sRun = 'top.' + sFrameName + '.' + sFunctionText;
            }
            try{
               execScript(sRun, 'javascript');
            }
            catch(error){
            }
        }
    }
    this.debug = new Debug();

    // Set check on connection to occur in one min
    if ( window == top ){
        this.events.attachEvent( window, 'load', new Function( 'window.setTimeout(\'sapphire.connection.checkConnection()\', ' + ( this.connection.pingConnectionFrqcy * 1000) + ' )' ) );
    }
    this.events.attachEvent( window, 'load', this.events.callLoadListeners );
}




