function SapphireUI(){
    api_desc: 'Sapphire API for dialogs, panels, anumation, drag-drop and linking.';

    this.button = {
        mouseover: function(oEl){
            if (sapphire.browser.ie){
                oEl.mouseover='Y';
                oEl.className='button_' + oEl.appearance + '_highlight';
            }
            else{
                oEl.setAttribute('mouseover','Y');
                oEl.className='button_' + oEl.getAttribute('appearance') + '_highlight';
            }
        },
        mouseout: function(oEl){
            if (sapphire.browser.ie){
                oEl.mouseover='N';
                oEl.className='button_' + oEl.appearance;
            }
            else{
                oEl.setAttribute('mouseover','N');
                oEl.className='button_' + oEl.getAttribute('appearance');
            }

        },
        preClick: function(oEl){
            if (oEl.nodeName == 'TABLE'){
                if (sapphire.browser.ie){
                    oEl.className='button_' + oEl.appearance;
                }
                else{
                    oEl.className='button_' + oEl.getAttribute('appearance');
                }
            }

            return !sapphire.ui.button.getDisabled(oEl);
        },
        refresh: function(oEl){
            sapphire.util.dom.setAttribute(oEl,'refresh','Y');
            if (!sapphire.browser.ie){
                this.propertyChange(oEl);
            }
        },
        setText: function(oEl, sText){
            sapphire.util.dom.setAttribute(oEl,'text',sText);
            this.refresh(oEl);
        },
        setAppearance: function(oEl, sApp){
            sapphire.util.dom.setAttribute(oEl,'appearance',sApp);
            this.refresh(oEl);
        },
        setImage: function(oEl, sImg){
            sapphire.util.dom.setAttribute(oEl,'img',sImg);
            this.refresh(oEl);
        },
        setDisabled: function(oEl, lDisabled){
            if (sapphire.browser.ie){
                oEl.disabled = lDisabled;
            }
            else{
                if (lDisabled){
                    oEl.setAttribute('disabled', true);
                }
                else{
                    oEl.removeAttribute('disabled');
                }
            }
            this.refresh(oEl);
        },
        getText: function(oEl){
            return sapphire.util.dom.getAttribute(oEl,'text');
        },
        getImage: function(oEl){
            return sapphire.util.dom.getAttribute(oEl,'img');
        },
        getDisabled: function(oEl){
            var lDis = sapphire.util.dom.getAttribute(oEl,'disabled');
            if (typeof(lDis) == 'undefined' || lDis == null || lDis.length == 0 ){
                lDis = false;
            }
            else if(lDis == true || lDis == 'true' || lDis == 'disabled'){
                lDis = true;
            }
            else{
                lDis = false;
            }
            return lDis;
        },
        propertyChange: function(oEl){
            var lImage = (sapphire.util.dom.getAttribute(oEl,'hasimg') == 'Y');
            var lText = (sapphire.util.dom.getAttribute(oEl,'hastext') == 'Y');
            if ( sapphire.util.dom.getAttribute(oEl,'refresh') == 'Y' ) {
                if(sapphire.browser.ie){
                    oEl.refresh = 'N';
                }
                else{
                    oEl.setAttribute('refresh','N');
                }
        		if ( oEl.nodeName == 'TABLE' ) {
                    if ( lImage ) {
                        if (sapphire.browser.ie){
                            oEl.rows[0].cells[0].childNodes[0].rows[0].cells[0].childNodes[0].src = oEl.img;
                        }
                        else{
                            oEl.rows[0].cells[0].childNodes[0].rows[0].cells[0].childNodes[0].src = oEl.getAttribute('img');
                        }
                    }
                    if ( lText ) {
                        if (sapphire.browser.ie){
                            oEl.rows[0].cells[0].childNodes[0].rows[0].cells[ (lImage ? '2' : '0' ) ].innerText = oEl.text;
                        }
                        else{
                            oEl.rows[0].cells[0].childNodes[0].rows[0].cells[ (lImage ? '2' : '0' ) ].textContent = oEl.getAttribute('text');
                        }
                    }
                    if (sapphire.util.dom.getAttribute(oEl,'mouseover') == 'N' || sapphire.util.dom.getAttribute(oEl,'disabled')) {
                        oEl.className= 'button_' + sapphire.util.dom.getAttribute(oEl,'appearance');
                    }
                    if (!sapphire.browser.ie){
                        oEl.rows[0].cells[0].childNodes[0].rows[0].cells[ (lImage ? '2' : '0' ) ].style.color = sapphire.ui.button.getDisabled(oEl)?'lightgray':'';
                    }
                }
                else {
                    if ( lImage ) {
                        if (sapphire.browser.ie){
                            oEl.childNodes[0].rows[0].cells[0].childNodes[0].src = oEl.img;
                        }
                        else{
                            oEl.childNodes[0].rows[0].cells[0].childNodes[0].src = oEl.getAttribute('img');
                        }
                    }
                    if ( lText ) {
                        if (sapphire.browser.ie){
                            oEl.childNodes[0].rows[0].cells[(lImage?'2':'0')].innerText = oEl.text;
                        }
                        else{
                            oEl.childNodes[0].rows[0].cells[(lImage?'2':'0')].textContent = oEl.getAttribute('text');
                        }
                    }
                }
            }
        }
    }


    this.selectBlocker = {
        api_desc: 'Sapphire API for blocking select elements in IE6.',
        show: function( sId, oParent, iX, iY, iWidth, iHeight ){
            function set( oSetFrame, iX, iY, iWidth, iHeight  ){
                oSetFrame.style.top = iY;
                oSetFrame.style.left = iX;
                oSetFrame.style.width = iWidth;
                oSetFrame.style.height = iHeight;
            }
            var oFrame = document.getElementById( sId );
            if ( oFrame == null ){
                oFrame = document.createElement( 'iframe' );
                oFrame.id = sId;
                oFrame.name = sId + 'name';
                oFrame.style.filter = 'alpha(opacity=0)';
                oFrame.style.position = 'absolute';
                oFrame.style.zIndex = 200;
                set( oFrame, iX, iY, iWidth, iHeight );
                oParent.appendChild( oFrame );
            }
            else{
                set( oFrame, iX, iY, iWidth, iHeight );
            }
            try{
                return oFrame;
            }
            finally{
                oFrame = null;
                oParent = null;
            }
        },
        hide: function( sId ){
            var oFrame = document.getElementById( sId );
            if ( oFrame != null ){
                sapphire.garbage.add( oFrame );
            }
        }
    }

    this.modalCover = {
        api_desc: 'Sapphire API for showing a modal cover over the page.',
        create: function( sId, oParent, iOpacity ){
            var oDoc = document;
            var oModal =oDoc.getElementById( sId );
            if ( oModal == null ){
                oModal = document.createElement('div');
                oModal.style.backgroundColor = 'black';
                oModal.style.position = 'absolute';
                if (sapphire.browser.mozilla){
                    oModal.style.opacity = iOpacity / 100;
                }
                else{
                    oModal.style.filter = 'alpha(opacity=' + iOpacity + ');';
                }
                oModal.id = sId;
                var iSWidth = document.body.scrollWidth;
                var iSHeight = document.body.scrollHeight;
                if ( document.body.clientHeight > iSHeight){
                    iSHeight = document.body.clientHeight;
                }
                if ( sapphire.browser.id == 'IE6' ){
                    oModal.blocker = sapphire.ui.selectBlocker.show( sId + '_blocker', oParent, 0, 0, iSWidth, iSHeight );
                }
                oModal.style.height = iSHeight;
                oModal.style.width = iSWidth;
                oModal.style.top = 0;
                oModal.style.left = 0;
                oModal.style.display = 'none';
                oModal.style.zIndex = 200;
                var oFunc = new Function( 'sapphire.ui.modalCover.resize( ' + sId + ' )' );
                oModal.resizeFunction = oFunc;
                sapphire.events.attachEvent( window, 'resize', oFunc );
                oParent.appendChild( oModal );
            }
            try{
                return oModal;
            }
            finally{
                oFunc = null;
                oModal = null;
            }
        },
        show: function( oModal ){
            if ( oModal != null ){
                oModal.style.display = 'block';
            }
        },
        hide: function( oModal ){
            if ( oModal != null ){
                oModal.style.display = 'none';
            }
        },
        resize: function( oModal ){
            if (oModal != null ){
                var oBody = document.body;
                var iSWidth = oBody.scrollWidth;
                var iSHeight = oBody.scrollHeight;
                if ( sapphire.browser.id == 'IE6' ){
                    sapphire.ui.selectBlocker.show( sId + '_blocker', oModal.parentElement, 0, 0, iSWidth, iSHeight );
                }
                oModal.style.height = iSHeight;
                oModal.style.width = iSWidth;
                oModal.style.top = 0;
                oModal.style.left = 0;
            }
        },
        remove: function( sId, oParent ){
            var oModal = document.getElementById( sId );
            if ( oModal != null ){
                this.hide( oModal );
                sapphire.events.detachEvent( window, 'onresize', oModal.resizeFunction );
                oModal.resizeFunction = null;
                if ( typeof( oModal.blocker ) != 'undefined' ){
                    sapphire.garbage.add( [oModal.blocker, oModal] );
                    oModal.blocker = null;                    
                }
                else{
                    sapphire.garbage.add( oModal );
                }
                oModal = null;
            }
        }
    }

    this.dialog = {
        api_desc: 'Sapphire API for showing dialogs and pop-ups.',
        dialogCount: 0,
        dialogs: new Array(),
        focusedNumber: -1,
        started: false,
        alert: function( sContent, lTranslate ){
            var oDialog = this.show('', sContent, true, null, lTranslate );
            try{
                return oDialog;
            }
            finally{
                oDialog = null;
            }
        },
        show: function( sTitle, sContent, lModal, sURL, lTranslate ){
            if ( window != top ){
                var oNewDialog = top.sapphire.ui.dialog.show( sTitle, sContent, lModal, sURL, lTranslate );
                oNewDialog.opener = window;
                try{
                    return oNewDialog;
                }
                finally{
                    oNewDialog = null;
                }
            }
            else{
                var oReturn = null;
                if ( typeof(sURL)!='undefined' && sURL != null && sURL.length > 0 ){
                    this.open( sTitle, sURL, lModal, 0, 0, null, null, true, lTranslate )
                }
                else if ( typeof(sContent)!='undefined' && sContent != null ){
                    if( sContent.length == 0 ){
                        sContent = '&nbsp;';
                    }
                    else{
                        if (typeof(lTranslate) == 'undefined' || lTranslate){
                            sContent = sContent.translate();
                        }
                        var iFound = sContent.indexOf('\n');
                        while ( iFound > -1 ){
                            sContent = sContent.replace( '\n', '<br>' );
                            iFound = sContent.indexOf('\n');
                        }
                    }
                    if (typeof(lModal) == 'undefined'){
                        lModal = true;
                    }
                    oReturn = this.create( 300, 200, sTitle, sContent, null, false, true, lModal, 10, '', lTranslate );
                    oReturn.dialogType = 'alert';
                }
                try{
                    return oReturn;
                }
                finally{
                    oReturn = null;
                }

            }
        },
        open: function ( sTitle, sURL, lModal, iWidth, iHeight, oBtns, oForm, lResizable, lTranslate ){
            if ( window != top ){
                var oNewDialog = top.sapphire.ui.dialog.open( sTitle, sURL, lModal, iWidth, iHeight, oBtns, oForm, lResizable, lTranslate );
                oNewDialog.opener = window;
                try{
                    return oNewDialog;
                }
                finally{
                    oNewDialog = null;
                }
            }
            else{
                var oReturn = null;
                if ( typeof(lResizable) == 'undefined' ){
                    lResizable = true;
                }
                if ( typeof(iWidth) == 'undefined' || iWidth == 0 ){
                    iWidth = 600;
                }
                if ( typeof(iHeight) == 'undefined' || iHeight == 0 ){
                    iHeight = 400;
                }
                var lShowInner = false;
                if ( typeof(oBtns) != 'undefined' && oBtns != null ){
                    lShowInner = true;
                }

                if ( sURL.indexOf( 'rc?' ) == -1 && sURL.indexOf('http://') == -1 && sURL.indexOf('/') == -1 ) {
                    sURL = 'rc?command=page&page=' + sURL;
                }
                var sOrgAction = '';
                var sOrgMethod = '';
                var sOrgTarget = '';
                if ( typeof(oForm) != 'undefined' && oForm != null ){
                    sOrgAction = oForm.action;
                    sOrgMethod = oForm.method;
                    sOrgTarget = oForm.target;
                    sapphire.util.url.addToForm(sURL,oForm,sapphire.util.url.defaultExcludes);
                    oForm.method = 'post';
                    oForm.target = 'dlg_frame' + this.dialogCount;
                    sURL = 'about:blank';
                    if ( !sapphire.util.dom.containsNode(oForm.ownerDocument.body,oForm) ){
                        oForm.style.display = 'none';
                        oForm.ownerDocument.body.appendChild( oForm );
                    }
                }
                else{
                    sURL = sapphire.util.url.encode(sURL);
                }
                oReturn = this.create( iWidth, iHeight, sTitle, '<iframe name="dlg_frame' + this.dialogCount +
                                                                '" id="dlg_frame' + this.dialogCount + '" dialogNumber="' + this.dialogCount +
                                                                '" src="' + sURL + '" frameborder=0 width="100%" height="100%" style="' +
                                                                ' width:100%;height:100%;"></iframe>',
                        oBtns, lResizable, lShowInner, lModal, 0, '', lTranslate );
                if ( typeof(oForm) != 'undefined' && oForm != null ){
                    oForm.submit();
                    oForm.action = sOrgAction;
                    oForm.method = sOrgMethod;
                    oForm.target = sOrgTarget;
                }
                oReturn.frame = window.frames[ 'dlg_frame' + oReturn.dialogNumber ];
                oReturn.dialogType = 'url';
                try{
                    return oReturn;
                }
                finally{
                    oReturn = null;
                }
            }
        },
        prompt: function ( sTitle, sPrompt, sDefault, sReturnFunction, lTranslate ){
            if ( window != top ){
                var oNewDialog = top.sapphire.ui.dialog.prompt( sTitle, sPrompt, sDefault, sReturnFunction, lTranslate );
                oNewDialog.opener = window;
                try{
                    return oNewDialog;
                }
                finally{
                    oNewDialog = null;
                }

            }
            else{
                var oReturn = null;
                if (typeof(sReturnFunction) == 'undefined' || sReturnFunction == null){
                    sReturnFunction = '';
                }
                if ( typeof(sDefault) == 'undefined' || sDefault == null ){
                    sDefault = '';
                }
                if ( typeof(sPrompt) == 'undefined' || sPrompt.length == 0 ){
                    sPrompt =  'Please enter';
                }
                if (typeof(lTranslate) == 'undefined' || lTranslate){
                    sPrompt = sPrompt.translate();
                }
                oReturn = this.create( 300, 150, sTitle, sPrompt + ':<br><input name="dlgReturn' + this.dialogCount + '" id="dlgReturn' + this.dialogCount + '" value="' + sDefault + '" style="width:250;">',
                          {'OK': 'sapphire.ui.dialog.callbackPrompt( sapphireDialog' + this.dialogCount + ',\'' + sReturnFunction + '\');', 'Cancel': 'sapphire.ui.dialog.close(' + this.dialogCount + ');'}, false, true, true, 10, '', lTranslate );
                oReturn.dialogType = 'prompt';
                oReturn.promptFields = [ document.getElementById('dlgReturn' + oReturn.dialogNumber) ];
                try{
                    return oReturn;
                }
                finally{
                    oReturn = null;
                }
            }
        },
        multiPrompt: function ( sTitle, saPromptArray, saDefaultArray, sReturnFunction, lTranslate ){
            if ( window != top ){
                var oNewDialog = top.sapphire.ui.dialog.multiPrompt( sTitle, saPromptArray, saDefaultArray, sReturnFunction );
                oNewDialog.opener = window;
                try{
                    return oNewDialog;
                }
                finally{
                    oNewDialog = null;
                }
            }
            else{
                var oReturn = null;
                if (typeof(sReturnFunction) == 'undefined' || sReturnFunction == null){
                    sReturnFunction = '';
                }
                if ( typeof(saDefaultArray) == 'undefined' || saDefaultArray == null ){
                    saDefaultArray = [''];
                }
                var sDefaultPrompt = 'Please enter:';
                if ( typeof(saPromptArray) == 'undefined' || saPromptArray.length == 0 ){
                    saPromptArray = [sDefaultPrompt];
                }
                if ( typeof(lTranslate) == 'undefined' || lTranslate ){
                    lTranslate = true;
                }

                var sHTML = '';
                var iHeight = 100;
                for ( var iIndex = 0; iIndex < saPromptArray.length; iIndex++ ){
                    var sPrompt = saPromptArray[iIndex];
                    if ( sPrompt.length == 0 ){
                        sPrompt = sDefaultPrompt;
                    }
                    if (lTranslate){
                        sPrompt = sPrompt.translate();
                    }
                    var sDefault = '';
                    if ( iIndex < saDefaultArray.length ){
                        sDefault = saDefaultArray[iIndex];
                    }
                    iHeight += 50;
                    if ( iIndex == 0 ){
                        sHTML = sPrompt + ':<br><input name="dlgMReturn' + this.dialogCount + '_' + iIndex + '" id="dlgMReturn' + this.dialogCount + '_' + iIndex + '" value="' + sDefault + '" style="width:250;">';
                    }
                    else{
                        sHTML += '<br><br>' + sPrompt + ':<br><input name="dlgMReturn' + this.dialogCount + '_' + iIndex + '" id="dlgMReturn' + this.dialogCount + '_' + iIndex + '" value="' + sDefault + '" style="width:250;">';
                    }
                }
                oReturn = this.create( 300, iHeight, sTitle, sHTML,
                          {'OK': 'sapphire.ui.dialog.callbackMultiPrompt( sapphireDialog' + this.dialogCount + ',\'' + sReturnFunction + '\');', 'Cancel' : 'sapphire.ui.dialog.close(' + this.dialogCount + ');'}, false, true, true, 10, '', lTranslate );
                oReturn.dialogType = 'multiprompt';

                var oaPF = [];
                var oDoc = document;
                for ( var iIndex = 0; iIndex < saPromptArray.length; iIndex++ ){
                    oaPF.push( oDoc.getElementById( 'dlgMReturn' + oReturn.dialogNumber + '_' + iIndex ) );
                }
                oReturn.promptFields = oaPF;

                try{
                    return oReturn;
                }
                finally{
                    oReturn = null;
                }
            }
        },
        confirm: function ( sTitle, sPrompt, sReturnFunction, lTranslate ){
            if ( window != top ){
                var oNewDialog = top.sapphire.ui.dialog.confirm( sTitle, sPrompt, sReturnFunction );
                oNewDialog.opener = window;
                try{
                    return oNewDialog;
                }
                finally{
                    oNewDialog = null;
                }
            }
            else{
                var oReturn = null;
                if (typeof(sReturnFunction) == 'undefined' || sReturnFunction == null){
                    sReturnFunction = '';
                }
                if ( typeof(sPrompt) == 'undefined' || sPrompt.length == 0 ){
                    sPrompt = ((typeof(lTranslate) == 'undefined' || lTranslate)?sapphire.translate('Please confirm'):'Please confirm') + ':';
                }
                else{
                    if (typeof(lTranslate) == 'undefined' || lTranslate){
                        sPrompt = sPrompt.translate();
                    }
                    var iFound = sPrompt.indexOf('\n');
                    while ( iFound > -1 ){
                        sPrompt = sPrompt.replace( '\n', '<br>' );
                        iFound = sPrompt.indexOf('\n');
                    }
                }

                oReturn = this.create( 300, 150, sTitle, sPrompt,
                          {'Yes': 'sapphire.ui.dialog.callbackConfirm( sapphireDialog' + this.dialogCount + ',\'' + sReturnFunction + '\', true);', 'No': 'sapphire.ui.dialog.callbackConfirm( sapphireDialog' + this.dialogCount + ',\'' + sReturnFunction + '\', false);', 'Cancel' : 'sapphire.ui.dialog.callbackConfirm( sapphireDialog' + this.dialogCount + ', \'\', null);'},
                        false, true, true, 10, 'sapphire.ui.dialog.callbackConfirm( sapphireDialog' + this.dialogCount + ', \'\', null)', lTranslate );
                oReturn.dialogType = 'confirm';
                try{
                    return oReturn;
                }
                finally{
                    oReturn = null;    
                }
            }
        },
        callbackPrompt: function( oDialog, sReturnFunction ){
            function emptyReturn( oDialog, sValue ){
                sapphire.ui.dialog.show('Prompt result', 'Dialog ' + oDialog.dialogNumber + ' returned ' + sValue, false, '', false );
            }
            var oInput = oDialog.promptFields[0];
            if ( oInput != null ){
                var sVal = oInput.value;
                var oFunc;
                if ( sReturnFunction.length > 0 ){
                    oFunc = sapphire.util.script.eval(sReturnFunction, [window,oDialog.opener,oDialog.frame]);
                }
                else{
                    oFunc = emptyReturn;
                }
                if ( typeof(oFunc) != 'undefined' && oFunc != null ){
                    var vReturn = oFunc( oDialog, sVal );
                    if ( vReturn != false ){
                        this.close(oDialog.dialogNumber);
                    }
                }
            }
        },
        callbackMultiPrompt: function( oDialog, sReturnFunction ){
            function emptyReturn( oDialog, saValues ){
                sapphire.ui.dialog.show('Prompt result', 'Dialog ' + oDialog.dialogNumber + ' returned ' + saValues.length + ' values.', false, '', false );
            }
            var saValues = new Array();
            var iIndex = 0;
            var oaPF = oDialog.promptFields;
            for ( var iIndex = 0; iIndex < oaPF.length; iIndex++ ){
                var oInput = oaPF[iIndex];
                if ( oInput != null ){
                    saValues.push( oInput.value );
                }
            }
            var oFunc;
            if ( sReturnFunction.length > 0 ){
                oFunc = sapphire.util.script.eval(sReturnFunction, [window,oDialog.opener,oDialog.frame]);
            }
            else{
                oFunc = emptyReturn;
            }
            if ( typeof(oFunc) != 'undefined' && oFunc != null ){
                var vReturn = oFunc( oDialog, saValues );
                if ( vReturn != false ){
                    this.close(oDialog.dialogNumber);
                }
            }
        },
        postConfirm: function( oDialog, lValue ){
            if ( lValue == null ){
                if ( typeof(oDialog.cancelscript) != 'undefined' ){
                    eval( oDialog.cancelscript );
                }
                if ( typeof(oDialog.cancelcallback) != 'undefined' ){
                    if ( typeof(oDialog.cancelcallbackarguments) != 'undefined'){
                        oDialog.cancelcallback.apply( this, oDialog.cancelcallbackarguments );
                    }
                    else{
                        oDialog.cancelcallback.apply( this );
                    }
                }
            }
            else if ( lValue ){
                if ( typeof(oDialog.yesscript) != 'undefined' ){
                    eval( oDialog.yesscript );
                }
                if ( typeof(oDialog.yescallback) != 'undefined' ){
                    if ( typeof(oDialog.yescallbackarguments) != 'undefined'){
                        oDialog.yescallback.apply( this, oDialog.yescallbackarguments );
                    }
                    else{
                        oDialog.yescallback.apply( this );
                    }
                }
            }
            else{
                if ( typeof(oDialog.noscript) != 'undefined' ){
                    eval( oDialog.noscript );
                }
                if ( typeof(oDialog.nocallback) != 'undefined' ){
                    if ( typeof(oDialog.nocallbackarguments) != 'undefined'){
                        oDialog.nocallback.apply( this, oDialog.nocallbackarguments );
                    }
                    else{
                        oDialog.nocallback.apply( this );
                    }
                }
            }
        },
        callbackConfirm: function( oDialog, sReturnFunction, lResult ){
            function emptyReturn( oDialog, lValue ){
                if (typeof(oDialog.yesscript) != 'undefined' || typeof(oDialog.yescallback) != 'undefined' ||
                      typeof(oDialog.noscript) != 'undefined' || typeof(oDialog.nocallback) != 'undefined' ||
                        typeof(oDialog.cancelscript) != 'undefined' || typeof(oDialog.cancelcallback) != 'undefined'){
                    sapphire.ui.dialog.postConfirm(oDialog, lValue);
                }
                else{
                    if ( lResult != null ){
                        sapphire.ui.dialog.show('Confirm result', 'Dialog ' + oDialog.dialogNumber + ' returned ' + lValue, false, '', false );
                    }
                }
            }
            var oFunc;
            if ( sReturnFunction.length > 0){
                oFunc = sapphire.util.script.eval(sReturnFunction, [window,oDialog.opener,oDialog.frame]);
            }
            else{
                oFunc = emptyReturn;
            }
            if ( typeof(oFunc) != 'undefined' && oFunc != null ){
                oFunc( oDialog, lResult );
            }
            this.close(oDialog.dialogNumber);
        },
        getButtonsHtml: function(oBtns, iDialogNumber, lTranslate){
            var i = 0;
            var sReturn = '';
            for ( var oKey in oBtns ){
                var iSize = 75;
                if (oKey.length > 11){
                    iSize = 120;
                }
                sReturn += '<button id="dlgBtn' + iDialogNumber + '_' + i + '" onclick="sapphire.ui.dialog.callButton( ' + iDialogNumber + ', ' + i + ', \'' + oKey + '\' )" class="dialog_contents_btn" style="width:' + iSize + ';">';
                var sTemp;
                if ( oKey == 'Yes' && i == 0 ){
                    sTemp = (typeof(lTranslate) == 'undefined' || lTranslate)?sapphire.translate('Yes'):'Yes';
                    sReturn += '<u>' + sTemp.substr(0,1) + '</u>' + sTemp.substr(1) + '</button>';
                }
                else if ( oKey == 'No' && i == 1 ){
                    sTemp = (typeof(lTranslate) == 'undefined' || lTranslate)?sapphire.translate('No'):'No';
                    sReturn += '<u>' + sTemp.substr(0,1) + '</u>' + sTemp.substr(1) + '</button>';
                }
                else{
                    sReturn += ((typeof(lTranslate) == 'undefined' || lTranslate)?sapphire.translate('' + oKey):oKey) + '</button>';
                }

                i++;
            }
            return sReturn;
        },
        addButtons: function(vDialog, oBtns, lTranslate){
            if (typeof(vDialog) == 'number'){
                vDialog = this.getDialogObject(vDialog);
            }
            var sHtml = this.getButtonsHtml(oBtns, vDialog.dialogNumber,lTranslate);
            if (sHtml.length > 0){
                var oDoc = top.document;
                var oCell = oDoc.getElementById('dlg_btns' + vDialog.dialogNumber);
                if (oCell != null){
                    oCell.innerHTML = sHtml;
                    vDialog.buttons = oBtns;
                }
                else{
                    oCell = oDoc.getElementById('dlg_content' + vDialog.dialogNumber);
                    if (oCell != null){
                        var oTable = oCell.parentElement.parentElement.parentElement;
                        var oRow = oTable.insertRow();
                        oRow.height = '25px';                        
                        oCell = oRow.insertCell();
                        oCell.align = 'right';
                        oCell.id = 'dlg_btns' + vDialog.dialogNumber;
                        oCell.className = 'dialog_contents_body_btn';
                        oCell.innerHTML += sHtml;
                        vDialog.buttons = oBtns;
                    }
                }
            }
        },
        create: function( iWidth, iHeight, sTitle, sHTML, oBtns, lResizable, lShowInnerContainer, lModal, iInnerPadding, sCloseFunction, lTranslate ){
            //private
            function getHtml( sTitle, sHTML, lShowInnerContainer, oBtns, lResize, iInnerPadding, sCloseFunction, iDialogCount, lTranslate ){
                var sReturn = '';
                if (typeof(iDialogCount) == 'undefined'){
                    iDialogCount = 0;
                }
                var sFollowString;
                if ( sapphire.browser.id == 'IE6' ){
                    sFollowString = '[sapphireDialogShadow' + iDialogCount + ',sapphireDialogBlocker' + iDialogCount + ']';
                }
                else{
                    sFollowString = '[sapphireDialogShadow' + iDialogCount + ']';
                }
                sReturn += '<table id="dlg_main' + iDialogCount + '" width="100%" height="100%" cellpadding=0 cellspacing=0 border=0 style="table-layout:fixed;">';
                sReturn += '<tr>';
                sReturn += '<td class="dialog_contents_headl">';
                if ( lResize ){
                    sReturn += '<table width="100%" height="100%" cellpadding=0 cellspacing=0 border=0>' +
                            '<tr height=5><td width=5 style="cursor:nw-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'nw\')"></td><td style="cursor:n-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'n\')"></td></tr>' +
                            '<tr><td width=5 style="cursor:w-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'w\')"></td><td></td></tr>' +
                            '</table>';
                }
                sReturn += '</td>';
                if ( lResize ){
                    sReturn += '<td class="dialog_contents_head dialog_contents_title">';
                    sReturn += '<table width="100%" height="100%" cellpadding=0 cellspacing=0 border=0>' +
                            '<tr height=5><td style="cursor:n-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'n\')"></td></tr>' +
                            '<tr><td id="dlg_head' + iDialogCount + '" class="dialog_contents_title">' +
                            sTitle +
                            '</td></tr>' +
                            '<tr height=5><td></td></tr>' +
                            '</table>';
                }
                else{
                    sReturn += '<td id="dlg_head' + iDialogCount + '" class="dialog_contents_head dialog_contents_title">';
                    sReturn +=  sTitle ;
                }
                sReturn += '</td>';
                sReturn += '<td class="dialog_contents_headr" align=right>';

                var sClose = 'sapphire.ui.dialog.close(' + iDialogCount + ')';
                if (typeof(sCloseFunction)!='undefined' && sCloseFunction.length > 0 ){
                    sClose = sCloseFunction;
                }
                if ( lResize ){
                    sReturn += '<table width="100%" height="100%" cellpadding=0 cellspacing=0 border=0>' +
                            '<tr height=5><td colspan=2 style="cursor:n-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'n\')"></td><td width=5 style="cursor:ne-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'ne\')"></td></tr>' +
                            '<tr><td valign=top align=right>' +
                            '<input type=image width=14 id="dlgMax' + iDialogCount + '" class=dialog_contents_headbtn src="WEB-CORE/images/dlgmax.jpg" onclick="sapphire.ui.dialog.maximize(' + iDialogCount + ',event);" onmouseover="this.className=\'dialog_contents_headbtn_over\';"  onmouseout="this.className=\'dialog_contents_headbtn\';" style="cursor:hand;">'  +
                            '</td><td valign=top align=right>' +
                            '<input type=image width=14 id="dlgClose' + iDialogCount + '" class=dialog_contents_headbtn src="WEB-CORE/images/dlgclose.jpg" onclick="' + sClose + '" onmouseover="this.className=\'dialog_contents_headbtn_over\';"  onmouseout="this.className=\'dialog_contents_headbtn\';" style="cursor:hand;">' +
                            '</td><td width=5 style="cursor:e-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'e\')"></td></tr>' +
                            '</table>';
                }
                else{
                    sReturn += '<input type=image width=14 id="dlgClose' + iDialogCount + '" class=dialog_contents_headbtn src="WEB-CORE/images/dlgclose.jpg" onclick="' + sClose + '" onmouseover="this.className=\'dialog_contents_headbtn_over\';"  onmouseout="this.className=\'dialog_contents_headbtn\';" style="cursor:hand;"><img height="1" src="WEB-CORE/images/blank.gif" width="5">';
                }
                sReturn += '</td>';
                sReturn += '</tr>';
                sReturn += '<tr>';
                sReturn += '<td colspan=3 id="dlg_body' + iDialogCount + '" class="dialog_contents_body">';
                sReturn += '<table cellpadding=0 cellspacing=0 width="100%" height="100%" border=0>';
                if ( lResize ){
                    sReturn += '<tr height=5><td width=5 style="cursor:w-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'w\')"></td><td></td><td width=5 style="cursor:e-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'e\')"></td></tr>';
                    sReturn += '<tr><td width=5 style="cursor:w-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'w\')"></td><td>';
                }
                else{
                    sReturn += '<tr height=5><td width=5></td><td></td><td width=5></td></tr>';
                    sReturn += '<tr><td width=5></td><td>';
                }
                sReturn += '<table cellpadding=0 cellspacing=5 width="100%" height="100%" style="table-layout:fixed;" border=0>';
                sReturn += '<tr>';

                if ( lShowInnerContainer ){
                    var iPad = 0;
                    if ( typeof( iInnerPadding ) != 'undefined' ){
                        iPad = iInnerPadding;
                    }
                    sReturn += '<td id="dlg_content' + iDialogCount + '" class="dialog_contents_body_msg" valign=top align=left style="padding: ' + iPad + ' ' + iPad + ' ' + iPad + ' ' + iPad + ';">';


                    sReturn += sHTML;
                    sReturn += '</td>';
                    sReturn += '</tr>';
                    sReturn += '<tr height="25">';
                    sReturn += '<td align=right id="dlg_btns' + iDialogCount + '" class="dialog_contents_body_btn">';

                    sReturn += sapphire.ui.dialog.getButtonsHtml(oBtns, iDialogCount, lTranslate);

                    sReturn += '</td>';
                }
                else{
                    sReturn += '<td id="dlg_content' + iDialogCount + '" class="dialog_contents_body_html" valign=top align=left>';
                    sReturn += sHTML;
                    sReturn += '</td>';
                }
                sReturn += '</tr>';
                sReturn += '</table>';
                if ( lResize ){
                    sReturn += '</td><td width=5 style="cursor:e-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'e\')"></td></tr>';
                    sReturn += '<tr height=5><td width=5 style="cursor:sw-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'sw\')"></td><td style="cursor:s-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'s\')"></td><td width=5 style="cursor:se-resize;" onmousedown="sapphire.ui.resize.start(sapphireDialog' + iDialogCount + ',' + sFollowString + ', \'se\')"></td></tr>';
                }
                else{
                    sReturn += '</td><td width=5></td></tr>';
                    sReturn += '<tr height=5><td width=5></td><td></td><td width=5></td></tr>';
                }
                sReturn += '</table>';
                sReturn += '</td>';
                sReturn += '</tr>';
                sReturn += '</table>';
                return sReturn;
            }
            var oDoc = document;
            var oBody = oDoc.body;
            if (window != top){
                var oNewDialog = top.sapphire.ui.dialog.create( iWidth, iHeight, sTitle, sHTML, oBtns, lResizable, lShowInnerContainer, lModal, iInnerPadding, sCloseFunction )
                oNewDialog.opener = window;
                try{
                    return oNewDialog;
                }
                finally{
                    oNewDialog = null;
                }
            }
            else{
                if ( typeof(lTranslate) == 'undefined'){
                    lTranslate = true;
                }
                if ( typeof(sTitle) == 'undefined' || sTitle.length == 0 ){
                    sTitle = 'LabVantage';
                }
                if (lTranslate){
                    sTitle = sapphire.translate(sTitle);
                }
                var oDlgFocus = oDoc.getElementById( 'dlg_inputfocus' ); // fix ms ie bug
                if ( oDlgFocus == null ){
                    oDlgFocus = oDoc.createElement( 'input' );
                    oDlgFocus.id = 'dlg_inputfocus';
                    oDlgFocus.style.width = 0;
                    oDlgFocus.style.height = 0;
                    oDlgFocus.style.position = 'absolute';
                    oDlgFocus.type = 'text';
                    oBody.appendChild( oDlgFocus );
                }
                var oCont = oDoc.createElement('div');
                var oModal = null;
                var oDlgBlocker = null;
                var oDiv = oDoc.createElement('div');
                var oShadow = oDoc.createElement('div');
                oCont.id = 'sapphireDialogContainer' + this.dialogCount;
                oDiv.id = 'sapphireDialog' + this.dialogCount;
                oDiv.dialogNumber = this.dialogCount;
                oShadow.id = 'sapphireDialogShadow' + this.dialogCount;
                oCont.className = 'dialog_container';
                oDiv.className = 'dialog_sapphire';
                oShadow.className = 'dialog_shadow';
                var iTop = 0;
                var iLeft = 0;
                var iScrollTop = oBody.scrollTop;
                if ( iScrollTop < 1 ){
                    iTop = ( oBody.clientHeight / 2 ) - ( iHeight / 2 );
                }
                else{
                    iTop = ( ( oBody.clientHeight / 2 ) - ( iHeight / 2 ) ) + iScrollTop;
                }
                var iScrollLeft = oBody.scrollLeft;
                if ( iScrollLeft < 1 ){
                    iLeft = ( oBody.clientWidth / 2 ) - ( iWidth / 2 );
                }
                else{
                    iLeft = ( ( oBody.clientWidth / 2 ) - ( iWidth / 2 )) + iScrollLeft;
                }
                oDiv.style.height = iHeight;
                oDiv.style.width = iWidth;
                oDiv.style.top = iTop;
                oDiv.style.left = iLeft;
                oDiv.style.zIndex = 200;
                oShadow.style.height = iHeight;
                oShadow.style.width = iWidth;
                oShadow.style.top = iTop + 2;
                oShadow.style.left = iLeft + 2;
                oShadow.style.zIndex = 200;
                if ( lModal ){
                    oModal = sapphire.ui.modalCover.create( 'sapphireDialogModal' + this.dialogCount, oCont, 40 );
                }
                if ( sapphire.browser.id == 'IE6' ){
                    oDlgBlocker = sapphire.ui.selectBlocker.show( 'sapphireDialogBlocker' + this.dialogCount, oCont, iLeft, iTop, iWidth + 2, iHeight + 2 );
                }
                if ( typeof(oBtns) == 'undefined' || oBtns == null ){
                    oBtns = { 'Close': 'sapphire.ui.dialog.close(' + this.dialogCount + ')' };
                }
                oDiv.innerHTML = getHtml( sTitle, sHTML, lShowInnerContainer, oBtns, lResizable, iInnerPadding, sCloseFunction, this.dialogCount, lTranslate );
                oDiv.style.display = 'none';
                oShadow.style.display = 'none';
                oCont.appendChild( oShadow );
                oCont.appendChild( oDiv );
                oBody.appendChild( oCont );
                var oDlgHead = oDoc.getElementById('dlg_head' + this.dialogCount );

                if (oDlgHead != null ){
                    sapphire.ui.dragdrop.registerDragObject( oDlgHead, oDiv, false)
                    if ( oDlgBlocker != null ){
                        sapphire.ui.dragdrop.setFollowElements( oDlgHead, [ oShadow, oDlgBlocker ] );
                    }
                    else{
                        sapphire.ui.dragdrop.setFollowElements( oDlgHead, [ oShadow ] );
                    }
                }

                var oaOrder;
                if ( lModal && oModal != null ){
                    if ( oDlgBlocker ){
                        if ( typeof( oModal.blocker) != 'undefined'){
                            oaOrder = [oModal.blocker, oModal, oShadow, oDlgBlocker];
                        }
                        else{
                            oaOrder = [oModal, oShadow, oDlgBlocker];
                        }
                    }
                    else{
                        oaOrder = [oModal, oShadow];
                    }
                }
                else{
                    if ( oDlgBlocker != null ){
                        oaOrder = [oShadow, oDlgBlocker];
                    }
                    else{
                        oaOrder = [oShadow];
                    }
                }
                sapphire.ui.order.register( oDiv, oaOrder );
                sapphire.events.attachEvent( oDiv, 'click', new Function('sapphire.ui.dialog.focus( ' + this.dialogCount + ' )') );

                this.focus(this.dialogCount);
                oDiv.buttons = oBtns;
                oDiv.frame = null;
                oDiv.opener = window;
                oDiv.modal = lModal;
                oDiv.onshowlisteners = [];
                oDiv.onhidelisteners = [];
                oDiv.dialogType = 'custom';

                if ( lModal && oModal != null ){
                    if(sapphire.ui.animation.fadeInOutEnabled && oDoc.readyState == 'complete'){
                        sapphire.ui.animation.fadeIn( 'sapphireDialogModal' + this.dialogCount, 25, 5, 1, 30, 'sapphire.ui.dialog.showEnd(' + this.dialogCount + ')' );
                    }
                   else{
                        sapphire.ui.modalCover.show( oModal );
                        this.showEnd( this.dialogCount );
                   }
                }
                else{
                    if(sapphire.ui.animation.fadeInOutEnabled && oDoc.readyState == 'complete'){
                        sapphire.ui.animation.fadeIn( 'sapphireDialog' + this.dialogCount, 25, 10, 1, 100, 'sapphire.ui.dialog.showEnd(' + this.dialogCount + ')' );
                    }
                    else{
                        this.showEnd( this.dialogCount );
                    }
                }
                if (!this.started){
                    this.started = true;
                    sapphire.events.attachEvent( oDoc, 'keydown', this.keyDown );
                    sapphire.events.attachEvent( oDoc, 'focusin', this.docFocus );
                }

                this.dialogs.push(this.dialogCount);
                this.dialogCount = this.dialogCount + 1;

                try{
                    return oDiv;
                }
                finally{
                    oDiv = null;
                    oShadow = null;
                    oCont = null;
                    oBody = null;
                    oDlgHead = null;
                    oDlgFocus = null;
                    oModal = null;
                    oDlgBlocker = null;
                }
            }
        },
        attachOnShowEvent: function( iDialogNumber, vFunction ){
            if ( window != top ){
                top.sapphire.ui.dialog.attachOnShowEvent( iDialogNumber, vFunction );
            }
            else{
                var oDiv = document.getElementById( 'sapphireDialog' + iDialogNumber );
                if ( oDiv != null ){
                    sapphire.events.registerListner( vFunction, oDiv.onshowlisteners, false, 0 );
                }
            }
        },
        attachOnHideEvent: function( iDialogNumber, vFunction  ){
            if ( window != top ){
                top.sapphire.ui.dialog.attachOnHideEvent( iDialogNumber, vFunction );
            }
            else{
                var oDiv = document.getElementById( 'sapphireDialog' + iDialogNumber );
                if ( oDiv != null ){
                    sapphire.events.registerListner( vFunction, oDiv.onhidelisteners, false, 0 );
                }
            }
        },
        docFocus: function(){
            if ( this != sapphire.ui.dialog ){
                sapphire.ui.dialog.docFocus();
            }
            else{
                if ( this.focusedNumber > -1 && this.dialogs.length > 0 ){

                    var oDialog = this.getDialogObject(this.focusedNumber);
                    if ( oDialog != null && oDialog.modal ){
                        if ( !sapphire.util.dom.containsNode( oDialog, document.activeElement ) ){
                            try{
                                oDialog.focus();
                            }
                            catch(e){
                                //
                            }
                        }
                    }
                }
            }
        },
        keyDown: function(e){
            function findAndCallBtn( iDialogNumber, sBtnText ){
                var lOut = false;
                var iBtn = 0;
                var oBtn = sapphire.ui.dialog.getDialogButton( iDialogNumber, iBtn );
                while ( oBtn != null ){
                    if ( oBtn.innerText == sBtnText ){
                        sapphire.ui.dialog.callButton( iDialogNumber, iBtn, sBtnText );
                        lOut = true;
                        break;
                    }
                    iBtn ++;
                    oBtn = sapphire.ui.dialog.getDialogButton( iDialogNumber, iBtn );
                }
                return lOut;
            }

            if ( this != sapphire.ui.dialog ){
                sapphire.ui.dialog.keyDown(e);
            }
            else{
                if (typeof(e)=='undefined'){
                    e = event;
                }
                if ( this.focusedNumber > -1 && this.dialogs.length > 0 ){
                    if ( e.keyCode == 9 ){ // tab
                    }
                    else if ( e.keyCode == 27){ // escape
                        var oDialogCls = document.getElementById( 'dlgClose' + this.focusedNumber);
                        if ( oDialogCls != null ){
                            oDialogCls.click();
                            sapphire.ui.util.cancelEvent(e);
                        }
                    }
                    else if ( e.keyCode == 13 ){ // return
                        var oDialog = sapphire.ui.dialog.getDialogObject( this.focusedNumber );
                        if ( oDialog != null ){
                            var sType = oDialog.dialogType;
                            if ( sType == 'alert' ){
                                if ( findAndCallBtn( this.focusedNumber, 'Close' ) ){
                                    sapphire.ui.util.cancelEvent(e);
                                }
                            }
                            else if ( sType == 'prompt' || sType == 'multiprompt' ){
                                if  ( findAndCallBtn( this.focusedNumber, 'OK' ) ){
                                    sapphire.ui.util.cancelEvent(e);
                                }
                            }
                        }
                    }
                    else{
                        var sChar = String.fromCharCode(e.keyCode).toLowerCase();
                        if ( sChar == 'y'){
                            findAndCallBtn( this.focusedNumber, 'Yes' );
                        }
                        else if ( sChar == 'n' ){
                            findAndCallBtn( this.focusedNumber, 'No' );
                        }
                    }

                }
            }
        },
        showEnd: function( iDialogNumber ){
            function selectFirstBtn( iDialogNumber ){
                var oFirstBtn = document.getElementById('dlgBtn' + iDialogNumber + '_0');
                if ( oFirstBtn != null ){
                    oFirstBtn.focus();
                }
            }
            var oShadow = document.getElementById( 'sapphireDialogShadow'  + iDialogNumber );
            var oDiv = document.getElementById( 'sapphireDialog' + iDialogNumber );
            if ( oShadow != null && oDiv != null ){
                oShadow.style.display = 'block';
                oDiv.style.display = 'block';
                try{
                    var oPromptInput = document.getElementById( 'dlgReturn' + iDialogNumber );
                    if ( oPromptInput == null ){
                        oPromptInput = document.getElementById( 'dlgMReturn' + iDialogNumber + '_0' );
                        if ( oPromptInput == null ){
                            if (sapphire.browser.ie){
                                var oInput = document.getElementById( 'dlg_inputfocus' );  // fix ms ie bug
                                if ( oInput != null ){
                                    oInput.focus();
                                }
                            }
                            selectFirstBtn( iDialogNumber );
                        }
                        else{
                            oPromptInput.focus();
                            oPromptInput.select();
                        }
                    }
                    else{
                        oPromptInput.focus();
                        oPromptInput.select();
                    }
                    this.focus(iDialogNumber);
                }
                catch( e__1 ){
                    //
                }
                sapphire.events.callListeners( oDiv.onshowlisteners );
            }
        },
        close: function( iDialogNumber ){
            if ( window != top ){
                top.sapphire.ui.dialog.close( iDialogNumber );
            }
            else{
                var oDoc = document;
                this.clearFocus();
                var oDiv = oDoc.getElementById('sapphireDialog' + iDialogNumber );
                if ( oDiv != null ){
                    var oModal = oDoc.getElementById('sapphireDialogModal' + iDialogNumber);
                    if ( oModal != null && oDiv != null ){
                        if(sapphire.ui.animation.fadeInOutEnabled && oDoc.readyState == 'complete'){
                            sapphire.ui.animation.fadeOut( 'sapphireDialogModal' + iDialogNumber, 25, 5, 1, 30, 'sapphire.ui.dialog.closeEnd(' + iDialogNumber + ')' );
                        }
                        else{
                            sapphire.ui.modalCover.hide( oModal );
                            this.closeEnd( iDialogNumber );
                        }
                    }
                    else if ( oDiv != null ){
                        var oShadow = oDoc.getElementById('sapphireDialogShadow' + iDialogNumber );
                        if ( oShadow != null ){
                            oShadow.style.display = 'none';
                        }
                        if(sapphire.ui.animation.fadeInOutEnabled  && oDoc.readyState == 'complete'){
                            sapphire.ui.animation.fadeOut( 'sapphireDialog' + iDialogNumber, 25, 10, 1, 100, 'sapphire.ui.dialog.closeEnd(' + iDialogNumber + ')' );
                        }
                        else{
                            this.closeEnd( iDialogNumber );
                        }
                    }
                }
            }

        },
        callButton: function ( iDialogNumber, iButton, sButton ){
            var oDiv = document.getElementById('sapphireDialog' + iDialogNumber);
            if ( oDiv != null ){
                var oBtns = oDiv.buttons;
                var sFunc = oBtns[sButton];
                if ( typeof( sFunc ) != 'undefined' && sFunc != null && sFunc.length > 0 ){
                    function Call(){
                        this.dialogNumber = iDialogNumber;
                        this.buttonNumber = iButton;
                        this.dialog = oDiv;
                        this.button = sapphire.ui.dialog.getDialogButton( iDialogNumber, iButton );
                        this.close = new Function('sapphire.ui.dialog.close(' + iDialogNumber + ')');
                        this.maximize = new Function('sapphire.ui.dialog.maximize(' + iDialogNumber + ',arguments[0])');
                        this.restore = new Function('sapphire.ui.dialog.restore(' + iDialogNumber + ',arguments[0])');
                        this.frame = oDiv.frame;
                        this.opener = oDiv.opener;

                        var oaWindows = [window,oDiv.opener,oDiv.frame];
                        var iL = oaWindows.length;
                        var oErr = null;
                        for (var iIndex = 0; iIndex < iL; iIndex++){
                            if (oaWindows[iIndex] != null){
                                try{
                                    if (oaWindows[iIndex] == top){
                                        oaWindows[iIndex].eval(sFunc);
                                    }
                                    else{
                                        oaWindows[iIndex].Function(sFunc).apply(this,[]);
                                    }
                                    oErr = null;
                                    break;
                                }
                                catch(e2){
                                    oErr = e2;
                                    if ( e2.name != 'TypeError' && e2.description.toLowerCase() != 'object expected' ){
                                        break;
                                    }
                                }
                            }
                        }
                        if( oErr != null ){
                            sapphire.ui.dialog.alert('{{Could not execute button.}}\n' + e2.message);
                        }
                        this.dialog = null;
                        this.button = null;
                        this.close = null;
                        this.maximize = null;
                        this.restore = null;
                        this.frame = null;
                        this.opener = null;
                    }

                    var oCall = new Call();
                }
            }
        },
        maximize: function( iDialogNumber, e ){
            if ( window != top ){
                top.sapphire.ui.dialog.maximize( iDialogNumber, e );
            }
            else{
                if (typeof(e)=='undefined'){
                    e = window.event;
                }                
                var oDiv = document.getElementById('sapphireDialog' + iDialogNumber);
                if ( oDiv != null ){
                    sapphire.ui.resize.maximize( oDiv );
                    var oSrc = (typeof(e.srcElement) != 'undefined') ? e.srcElement : e.target;
                    oSrc.src = 'WEB-CORE/images/dlgnorm.jpg';
                    oSrc.onclick = new Function('sapphire.ui.dialog.restore(' + iDialogNumber + ',arguments[0])' );
                }
            }
        },
        restore: function( iDialogNumber, e ){
            if ( window != top ){
                top.sapphire.ui.dialog.restore( iDialogNumber, e );
            }
            else{
                if (typeof(e)=='undefined'){
                    e = window.event;
                }
                var oDiv = document.getElementById('sapphireDialog' + iDialogNumber);
                if ( oDiv != null ){
                    sapphire.ui.resize.restore( oDiv );
                    var oSrc = (typeof(e.srcElement) != 'undefined') ? e.srcElement : e.target;
                    oSrc.src = 'WEB-CORE/images/dlgmax.jpg';
                    oSrc.onclick = new Function('sapphire.ui.dialog.maximize(' + iDialogNumber + ',arguments[0])' );
                }
            }
        },
        closeEnd: function( iDialogNumber ){
            var oDoc = document;
            var oCont = oDoc.getElementById( 'sapphireDialogContainer' + iDialogNumber );
            if ( oCont != null ){
                var oDiv = oDoc.getElementById('sapphireDialog' + iDialogNumber );
                if ( oDiv != null ){
                    if ( typeof(oDiv.frame) != 'undefined' && oDiv.frame != null && sapphire.browser.id != 'IE8' ){
                        try{
                            oDiv.frame.window.location = 'about:blank';
                        }
                        catch(_e){}
                    }
                    sapphire.ui.dragdrop.unregisterDragObject( oDoc.getElementById('dlg_head' + iDialogNumber ) );
                    sapphire.ui.order.unregister( oDiv );
                    sapphire.ui.modalCover.remove( 'sapphireDialogModal' + iDialogNumber );

                    var oHL = oDiv.onhidelisteners;
                    oDiv.onhidelisteners = null;
                    oDiv.buttons = null;
                    oDiv.frame = null;
                    var oOpener = oDiv.opener;
                    oDiv.opener = null;
                    oDiv.onshowlisteners = null;
                    oDiv.onhidelisteners = null;
                    oDiv.promptFields = null;
                    oDiv = null;
                    sapphire.garbage.add( oCont );
                    oCont = null;
                    if ( sapphire.browser.ie ){
                        var oInput = document.getElementById( 'dlg_inputfocus' );  // fix ms ie bug
                        if ( oInput != null ){
                            oInput.focus();
                        }
                    }
                    try{
                        sapphire.events.callListeners( oHL );
                    }
                    finally{
                        oHL = null;
                    }
                    var iL = this.dialogs.length;
                    for ( var iIndex = 0; iIndex < iL; iIndex++ ){
                        if ( this.dialogs[iIndex] == iDialogNumber ){
                            this.dialogs.splice( iIndex, 1 );
                            break;
                        }
                    }
                    try{
                        if (oOpener != top){
                            oOpener.focus();
                        }
                    }
                    catch(e){
                        //
                    }
                    finally{
                        oOpener = null;
                    }
                    oDiv = null;
                    oCont = null;
                    sapphire.garbage.collect();
                }
            }

        },
        clearFocus: function( iDialogNumber ){
            if ( window != top ){
                top.sapphire.ui.dialog.clearFocus( iDialogNumber );
            }
            else{
                this.focusedNumber = -1;
                sapphire.ui.order.unregister( document.getElementById( 'sapphireDialog' + iDialogNumber) );
            }
        },
        focus: function( iDialogNumber ){
            if ( window != top ){
                top.sapphire.ui.dialog.focus( iDialogNumber );
            }
            else{
                this.focusedNumber = iDialogNumber;
                sapphire.ui.order.bringToFront( document.getElementById( 'sapphireDialog' + iDialogNumber ) );
            }
        },
        getDialogNumber: function( oWindow ){
            if ( window != top ){
                return top.sapphire.ui.dialog.getDialogNumber( oWindow );
            }
            else{
                if ( (typeof(oWindow) != 'undefined' && oWindow != null) &&
                     (typeof(oWindow.frameElement) != 'undefined' && oWindow.frameElement != null )){
                    var oParent = oWindow;
                    while ( oParent != top ){
                        var oFrameEl = oParent.frameElement;
                        if ( typeof(oFrameEl) != 'undefined' && oFrameEl != null &&
                             typeof(oFrameEl.id) !='undefined' && oFrameEl.id.indexOf('dlg_frame') == 0 ){
                            break;
                        }
                        oParent = oParent.parent;
                    }
                    var iNum = NaN;
                    if (oParent.frameElement != null){
                        iNum = parseInt(oParent.frameElement.dialogNumber);
                    }
                    if ( !isNaN(iNum)){
                        return iNum;
                    }
                    else{
                        return this.focusedNumber;
                    }
                }
                else{
                    return this.focusedNumber;
                }
            }
        },
        getDialogButton: function( iDialogNumber, iButtonNumber ){
            if ( window != top ){
                return top.sapphire.ui.dialog.getDialogButton( iDialogNumber, iButtonNumber );
            }
            else{
                return document.getElementById( 'dlgBtn' + iDialogNumber + '_' + iButtonNumber );
            }
        },
        getDialogObject: function( iDialogNumber ){
            if ( window != top ){
                return top.sapphire.ui.dialog.getDialogObject( iDialogNumber );
            }
            else{
                return document.getElementById( 'sapphireDialog' + iDialogNumber );
            }
        },
        setContent: function( iDialogNumber, sHTML ){
            var oDialogContent = document.getElementById( 'dlg_content' + iDialogNumber );
            if ( oDialogContent != null ){
                oDialogContent.innerHTML = '';
                oDialogContent.innerHTML = sHTML;
                oDialogContent = null;
            }

        }
    };

    this.panel = {
        api_desc: 'Sapphire API for managing Panels.',
        panels: [],
        register: function( sPanelId, lDragDrop, sResizeEvent, sDropEvent ){
            if (typeof(lDragDrop) == 'undefined' ){
                lDragDrop = false;
            }
            var oResizeEvent;
            if (typeof(sResizeEvent) == 'undefined' || sResizeEvent == null ){
                oResizeEvent = null;
            }
            else{
                oResizeEvent = eval( sResizeEvent );
            }
            var oDropEvent;
            if (typeof(sDropEvent) == 'undefined' || sDropEvent == null ){
                oDropEvent = null;
            }
            else{
                oDropEvent = eval( sDropEvent );
            }
            var lFound = false;
            var iLength = this.panels.length;
            for ( var iIndex = 0; iIndex < iLength; iIndex++ ){
                if ( this.panels[iIndex].panelId == sPanelId ){
                    lFound = true;
                    break;
                }
            }
            if (!lFound){
                this.panels.push( {
                    panelId: sPanelId,
                    dragdrop: lDragDrop,
                    resizeEvent: oResizeEvent,
                    dropEvent: oDropEvent
                    } );
            }
        },
        load: function(){
            if ( this != sapphire.ui.panel ){
                sapphire.ui.panel.load();
            }
            else{
                var iLength = this.panels.length;
                var oDD = sapphire.ui.dragdrop;
                var oOrder = sapphire.ui.order;
                var oResize = sapphire.ui.resize;
                var oDoc = document;
                for ( var iIndex = 0; iIndex < iLength; iIndex++ ){
                    var sPanelId = this.panels[iIndex].panelId;
                    var oPanel = oDoc.getElementById( 'sapphirePanel_' + sPanelId);
                    var oHandle = oDoc.getElementById( 'pnl_head_' + sPanelId);
                    var lDragDrop = this.panels[iIndex].dragdrop;
                    if ( oPanel != null ){
                        if ( lDragDrop ){
                            oDD.registerDragObject( oHandle, oPanel, false );
                            oDD.setDropOffTargetEvent( oHandle, this.panels[iIndex].dropEvent );
                        }
                        oOrder.register( oPanel );
                        oResize.setResizeEvent( oPanel, this.panels[iIndex].resizeEvent );
                    }
                }
                oOrder.restore( false );
            }
        },
        focus: function( sPanelId ){
            var oElement = null;
            if ( typeof( sPanelId ) == 'string'  ){
                oElement = document.getElementById( 'sapphirePanel_' + sPanelId);
            }
            else if ( typeof( sPanelId ) == 'object' ){
                oElement = sPanelId;
            }
            sapphire.ui.order.bringToFront( document.getElementById( 'sapphirePanel_' + sPanelId ) );
        },
        close: function( sPanelId ){
            var oElement = null;
            if ( typeof( sPanelId ) == 'string'  ){
                oElement = document.getElementById( 'sapphirePanel_' + sPanelId);
            }
            else if ( typeof( sPanelId ) == 'object' ){
                oElement = sPanelId;
                sPanelId = oElement.panelId;
            }
            if ( oElement != null ){
                for ( var iIndex = 0; iIndex < this.panels.length; iIndex++ ){
                    if ( this.panels[iIndex].panelId == sPanelId  ){
                        if ( this.panels[iIndex].dragdrop ){
                            var oHandle = document.getElementById( 'pnl_head_' + sPanelId);
                            if ( oHandle != null ){
                                sapphire.ui.dragdrop.unregisterDragObject( oHandle );
                            }
                        }
                        this.panels.splice[iIndex, 1];
                        break;
                    }
                }
                sapphire.ui.order.unregister( oElement );
                sapphire.garbage.add( oElement );
                oElement = null;
            }
        }
    }

    this.order = {
        api_desc: 'Sapphire API for managing z-index.',
        zOrder: [],
        register: function( oElement, oaFollowElements ){
            if ( typeof(oaFollowElements) == 'undefined' || oaFollowElements == null){
                oaFollowElements = [];
            }
            if ( oElement != null ){
                if ( this.zOrder.length == 0 ){
                    this.zOrder.push( {
                        element: oElement,
                        zIndex: oElement.style.zIndex,
                        followElements: oaFollowElements
                    } );
                }
                else{
                    var lFound = false;
                    var iLength = this.zOrder.length;
                    for ( var iIndex = 0; iIndex < iLength; iIndex++ ){
                        var oCurr = this.zOrder[iIndex].element;
                        if ( oCurr == oElement ){
                            lFound = true;
                            break;
                        }
                    }
                    if ( !lFound ){
                        this.zOrder.push( {
                            element: oElement,
                            zIndex: oElement.style.zIndex,
                            followElements: oaFollowElements
                        } );
                    }
                }
            }
        },
        unregister: function ( oElement ){
            for ( var iIndex = 0; iIndex < this.zOrder.length; iIndex++ ){
                var oCurr = this.zOrder[iIndex].element;
                if ( oCurr == oElement ){
                    this.zOrder.splice( iIndex, 1 );
                    break;
                }
            }
        },
        restore: function( lTriggerEvent ){
            var oaNewOrder = [];
            var iLength = this.zOrder.length;
            for ( var iIndex = 0; iIndex < this.zOrder.length; iIndex++ ){
                var iHigh = -1;
                var oHighElement = null;
                var iHighIndex = -1;
                for ( var iArrayIndex = 0; iArrayIndex < this.zOrder.length; iArrayIndex++ ){
                    var iCurr = this.zOrder[iArrayIndex].zIndex;
                    if (iCurr == 0){
                        // not set yet
                        iCurr = this.zOrder[iArrayIndex].element.style.zIndex;
                    }
                    if ( iCurr > iHigh ){
                        iHigh = iCurr;
                        oHighElement = this.zOrder[iArrayIndex].element;
                        iHighIndex = iArrayIndex;
                    }
                }
                if ( iHigh > -1 && oHighElement != null && iHighIndex > -1 ){
                    var oaFollowEl = this.zOrder[iHighIndex].followElements;
                    this.zOrder.splice( iHighIndex, 1 );
                    iIndex --;
                    var iNewZ = (iLength - oaNewOrder.length);
                    oaNewOrder.push( {
                        element: oHighElement,
                        zIndex: iNewZ,
                        followElements: oaFollowEl
                    } );
                    oHighElement = null;
                    iHigh = -1;
                }
            }
            var iNewLength = oaNewOrder.length;
            for ( var iArrayIndex = 0; iArrayIndex < iNewLength; iArrayIndex++ ){
                var oElement = oaNewOrder[iArrayIndex].element;
                var oaFollowEl = oaNewOrder[iArrayIndex].followElements;
                var iZ = oaNewOrder[iArrayIndex].zIndex;
                if ( oElement != null && oaFollowEl != null ){
                    var iFolLength = oaFollowEl.length;
                    for ( var iFolIndex = 0; iFolIndex < iFolLength; iFolIndex++){
                        if ( oaFollowEl[iFolIndex] != null ){
                            oaFollowEl[iFolIndex].style.zIndex = iZ;
                        }
                    }
                    oElement.style.zIndex = iZ;
                    if ( typeof(lTriggerEvent) != 'undefined' && lTriggerEvent ) {
                        if ( typeof(oElement.zindexchanged) != 'undefined' && oElement.zindexchanged != null ){
                            if ( typeof(oElement.zindexchanged) == 'string' ){
                                eval(oElement.zindexchanged)( oElement );
                            }
                            else{
                                oElement.zindexchanged( oElement );
                            }
                        }
                    }
                }
            }
            this.zOrder = oaNewOrder;
        },
        bringToFront: function( oElement ){
            var iLength = this.zOrder.length;
            for ( var iIndex = 0; iIndex < iLength; iIndex++ ){
                var oCurr = this.zOrder[iIndex].element;
                if ( oCurr == oElement){
                    this.zOrder[iIndex].zIndex = 200;
                    break;
                }
            }
            this.restore( true );
        },
        setZIndexChangedEvent: function( oElement, oChangedEvent ){
            oElement.zindexchanged = oChangedEvent;
        }
    }

    this.animation = {
        api_desc: 'Sapphire API for fade-in/out and transition-in/out animations.',
        menuEnabled: true,
        fadeInOutEnabled: true,
        resizeInOutEnabled: true,
        flash: function(sId){
            var oEl = document.getElementById(sId);
            if (oEl != null){
                var sOldBorder = oEl.style.borderStyle + ' ' + oEl.style.borderColor + ' ' + oEl.style.borderWidth;
                oEl.style.border = 'solid orange 2px';
                window.setTimeout('document.getElementById("' + sId + '").style.border = "solid yellow 1px"', 100);
                window.setTimeout('document.getElementById("' + sId + '").style.border = "' + sOldBorder + '"', 200);
            }

        },
        fadeIn: function( id, millisec, inc, startOpacity, endOpacity, animationOnEnd  ){
            var speed;
            var timer;
            var opStart;
            var opEnd;
            var object;
            var i;

            speed = millisec;
            if ( typeof(startOpacity) != 'undefined' && typeof(endOpacity) != 'undefined' ){
                if ( startOpacity < endOpacity ){
                    opStart = startOpacity;
                }
                else{
                    opStart = endOpacity;
                }
            }
            else{
                opStart = 1;
            }
            timer = 1;
            object = document.getElementById( id );
            if ( object != null ){
                i = opStart;
                if ( typeof(endOpacity) != 'undefined' && typeof(startOpacity) != 'undefined' ){
                    if ( endOpacity > startOpacity ){
                        opEnd = endOpacity;
                    }
                    else{
                        opEnd = startOpacity;
                    }
                }
                else{
                    opEnd = 100;
                }
                if ( !this.fadeInOutEnabled ){
                    sapphire.ui.animation.changeObjectFade( id, opEnd, true, false );
                }
                else{
                    sapphire.ui.animation.changeObjectFade( id, i, true, false );
                    i = i + inc;
                    while( i < opEnd + 1 ) {
                        setTimeout( 'sapphire.ui.animation.changeObjectFade("' + id + '", ' + i + ', false, false )', ( timer * speed ) );
                        i = i + inc;
                        timer++;
                    }
                    setTimeout( 'sapphire.ui.animation.changeObjectFade("' + id + '", ' + i + ', false, false )', ( timer  * speed ) );
                    if ( typeof(animationOnEnd) != 'undefined' && animationOnEnd != null  ){
                        if ( typeof( animationOnEnd ) == 'string'){
                            if ( animationOnEnd.length > 0 ){
                                setTimeout( animationOnEnd, (timer + 1)  * speed  );
                            }
                        }
                        else{
                            setTimeout( animationOnEnd, (timer + 1)  * speed  );
                        }
                    }

                }
            }
        },
        fadeOut: function( id, millisec, dec, startOpacity, endOpacity, animationOnEnd ){
            var speed;
            var timer;
            var opStart;
            var opEnd;
            var i;
            var object;
            speed = millisec;
            timer = 1;
            if ( typeof(endOpacity) != 'undefined' && typeof(startOpacity) != 'undefined' ){
                if ( endOpacity < startOpacity ){
                    opEnd = endOpacity;
                }
                else{
                    opEnd = startOpacity;
                }
            }
            else{
                opEnd = 1;
            }
            object = document.getElementById(id);

            if ( object != null ){
                if ( !this.fadeInOutEnabled ){
                    sapphire.ui.animation.changeObjectFade( id, opEnd, false, true );
                }
                else{
                    if ( typeof(startOpacity) != 'undefined' && typeof(endOpacity) != 'undefined'  ){
                        if ( startOpacity > endOpacity ){
                            opStart = startOpacity;
                        }
                        else{
                            opStart = endOpacity;
                        }
                    }
                    else{
                        opStart = 100;
                    }
                    i = opStart;
                    sapphire.ui.animation.changeObjectFade( id,  i, false, false );
                    i = i - dec;
                    while( i > opEnd - 1 ) {
                        setTimeout( 'sapphire.ui.animation.changeObjectFade("' + id + '", ' + i + ',  false, false )', ( timer * speed ) );
                        i = i - dec;
                        timer++;
                    }
                    setTimeout( 'sapphire.ui.animation.changeObjectFade("' + id + '", ' + i + ', false, true )', ( timer * speed ) );
                    if ( typeof(animationOnEnd) != 'undefined' && animationOnEnd != null  ){
                        if ( typeof( animationOnEnd ) == 'string'){
                            if ( animationOnEnd.length > 0 ){
                                setTimeout( animationOnEnd, (timer + 1)  * speed  );
                            }
                        }
                        else{
                            setTimeout( animationOnEnd, (timer + 1)  * speed  );
                        }
                    }
                }
            }
        },
        changeObjectFade: function( id, opacity, show, hide ) {
            var object = document.getElementById(id);
            if ( object != null ){
                if ( opacity > 0 ){
                    if ( show ){
                        object.style.display = 'block';
                    }
                    if (sapphire.browser.mozilla){
                        object.style.opacity = opacity / 100;
                    }
                    else{
                        object.style.filter = "alpha(opacity=" + opacity + ")";
                    }
                    if ( hide ){
                        object.style.display = 'none';
                    }
                }
                else{
                    if ( show){
                        object.style.display = 'block';
                    }
                    if (sapphire.browser.mozilla){
                        object.style.opacity = 0.1;
                    }
                    else{
                        object.style.filter = "alpha(opacity=" + 1 + ")";
                    }

                    if ( hide ){
                        object.style.display = 'none';
                    }
                }
            }
        },
        showObjectVertical: function( id, millisec, inc, animationOnEnd ){
            var speed;
            var timer;
            var heightStart;
            var heightEnd;
//            var orgHeight;
            var object;
            var i;
            speed = millisec;
            heightStart = 1;
            timer = 1;
            object = document.getElementById( id );
            if ( object != null ){
                i = heightStart;
                object.style.display='block';
//                orgHeight = '' + object.height;
                heightEnd = object.offsetHeight;
                object.style.display='none';
                if ( !this.resizeInOutEnabled || heightEnd > 800 ){
                    sapphire.ui.animation.changeObjectVertical( id, heightEnd, 2 );
                }
                else{
                    sapphire.ui.animation.changeObjectVertical( id, i, 1 );
                    i = i + inc;
                    while( i < heightEnd + 1 ) {
                        setTimeout( 'sapphire.ui.animation.changeObjectVertical("' + id + '", ' + i + ', 0)', ( timer * speed ) );
                        i = i + inc;
                        timer++;
                    }
                    setTimeout( 'sapphire.ui.animation.changeObjectVertical("' + id + '", ' + i + ', 2)', ( timer  * speed ) );
//                    if ( orgHeight.length > 0 ){
//                        alert(orgHeight);
//                        setTimeout( 'document.getElementById(\'' + id + '\' ).height = \'' + orgHeight + '\';', ( timer + 1 )  * speed );
//                    }
                    if ( typeof(animationOnEnd) != 'undefined' && animationOnEnd != null  ){
                        if ( typeof( animationOnEnd ) == 'string'){
                            if ( animationOnEnd.length > 0 ){
                                setTimeout( animationOnEnd, (timer + 1)  * speed  );
                            }
                        }
                        else{
                            setTimeout( animationOnEnd, (timer + 1)  * speed  );
                        }
                    }
                }
            }
        },
        showObjectHorizontal: function( id, millisec, inc, animationOnEnd ){
            var speed;
            var timer;
            var widthStart;
            var widthEnd;
            var object;
            var i;
            speed = millisec;
            widthStart = 1;
            timer = 1;
            object = document.getElementById( id );
            if ( object != null ){
                i = widthStart;
                object.style.display = 'block';
                var oParent = null;
                if ( typeof(object.parentElement) != 'undefined' ){
                    oParent = object.parentElement;
                }
                else{
                    oParent = object.parentNode;
                }
                if ( oParent != null && oParent.nodeName == 'TD' ){
                    oParent.style.display = 'block';
                }
                widthEnd = object.offsetWidth;
                object.style.display='none';

                if ( object.parentElement != null && object.parentElement.tagName == 'TD' ){
                    object.parentElement.style.display = 'none';
                }
                if ( !this.resizeInOutEnabled || widthEnd > 1000 ){
                    sapphire.ui.animation.changeObjectHorizontal( id, widthEnd, 2 );
                }
                else{
                    sapphire.ui.animation.changeObjectHorizontal( id, i, 1 );
                    i = i + inc;
                    while( i < widthEnd + 1 ) {
                        setTimeout( 'sapphire.ui.animation.changeObjectHorizontal("' + id + '", ' + i + ', 0)', ( timer * speed ) );
                        i = i + inc;
                        timer++;
                    }
                    setTimeout( 'sapphire.ui.animation.changeObjectHorizontal("' + id + '", ' + i + ', 2)', ( timer  * speed ) );
                    if ( typeof(animationOnEnd) != 'undefined' && animationOnEnd != null  ){
                        if ( typeof( animationOnEnd ) == 'string'){
                            if ( animationOnEnd.length > 0 ){
                                setTimeout( animationOnEnd, (timer + 1)  * speed  );
                            }
                        }
                        else{
                            setTimeout( animationOnEnd, (timer + 1)  * speed  );
                        }
                    }
                }
            }
        },
        hideObjectVertical: function( id, millisec, dec, animationOnEnd ){
            var speed;
            var timer;
            var heightEnd;
//            var orgHeight;
            var heightStart;
            var i;
            var object;
            speed = millisec;
            timer = 1;
            heightEnd = 1;
            object = document.getElementById(id);
            if ( object != null ){
//                orgHeight = '' + object.height;
                heightStart = object.offsetHeight;
                if ( !this.resizeInOutEnabled || heightStart > 800 ){
                    sapphire.ui.animation.changeObjectVertical( id, heightEnd, 4 );
                }
                else{
                    i = heightStart;
                    sapphire.ui.animation.changeObjectVertical( id,  i , 3 );
                    i = i - dec;
                    while( i > heightEnd - 1 ) {
                        setTimeout( 'sapphire.ui.animation.changeObjectVertical("' + id + '", ' + i + ', 0)', ( timer * speed ) );
                        i = i - dec;
                        timer++;
                    }
                    setTimeout( 'sapphire.ui.animation.changeObjectVertical("' + id + '", ' + i + ', 4)', ( timer * speed ) );
//                    if ( orgHeight.length > 0 ){
//                        alert(orgHeight);
//                        setTimeout( 'document.getElementById(\'' + id + '\' ).height = \'' + orgHeight + '\';', ( timer + 1 )  * speed );
//                    }
                    if ( typeof(animationOnEnd) != 'undefined' && animationOnEnd != null  ){
                        if ( typeof( animationOnEnd ) == 'string'){
                            if ( animationOnEnd.length > 0 ){
                                setTimeout( animationOnEnd, (timer + 1)  * speed  );
                            }
                        }
                        else{
                            setTimeout( animationOnEnd, (timer + 1)  * speed  );
                        }
                    }
                }
            }
        },
        hideObjectHorizontal: function( id, millisec, dec, animationOnEnd ){
            var speed;
            var timer;
            var widthEnd;
            var widthStart;
            var i;
            var object;
            speed = millisec;
            timer = 1;
            widthEnd = 1;
            object = document.getElementById(id);
            if ( object != null ){
                widthStart = object.offsetWidth;
                if ( !this.resizeInOutEnabled || widthStart > 1000 ){
                    sapphire.ui.animation.changeObjectHorizontal( id, widthEnd, 4 );
                }
                else{
                    i = widthStart;
                    sapphire.ui.animation.changeObjectHorizontal( id, i, 3 );
                    i = i - dec;
                    while( i > widthEnd - 1 ) {
                        setTimeout( 'sapphire.ui.animation.changeObjectHorizontal("' + id + '", ' + i + ', 0)', ( timer * speed ) );
                        i = i - dec;
                        timer++;
                    }
                    setTimeout( 'sapphire.ui.animation.changeObjectHorizontal("' + id + '", ' + i + ', 4)', ( timer  * speed ) );
                    if ( typeof(animationOnEnd) != 'undefined' && animationOnEnd != null  ){
                        if ( typeof( animationOnEnd ) == 'string'){
                            if ( animationOnEnd.length > 0 ){
                                setTimeout( animationOnEnd, (timer + 1)  * speed  );
                            }
                        }
                        else{
                            setTimeout( animationOnEnd, (timer + 1)  * speed  );
                        }
                    }                
                }
            }
        },
        changeObjectVertical: function( id, height, action ) {
            var object = document.getElementById(id);
            if ( object != null ){
                if ( action == 0 ){
                    if ( height > 0 ){
                        object.style.height = height;
                    }
                    else{
                        object.style.height = 1;
                    }
                }
                else if ( action == 1 ){
                    object.style.height = 1;
                    object.style.display = 'block';
                    object.style.overflowY = 'hidden';
                    object.u_height = object.height;
                    if ( height > 0 ){
                        object.style.height = height;
                    }
                    else{
                        object.style.height = 1;
                    }
                }
                else if ( action == 2 ){
                    object.style.display = 'block';
                    object.style.overflowY = '';
                    object.style.height = 'auto';
                    object.height = '';
                }
                else if ( action == 3 ){
                    object.u_height = object.offsetHeight;
                    object.style.overflowY = 'hidden';
                    if ( height > 0 ){
                        object.style.height = height;
                    }
                    else{
                        object.style.height = 1;
                    }
                }
                else if ( action == 4 ){
                    object.style.display = 'none';
                    object.style.overflowY = '';
                    if ( typeof(object.u_height) != 'undefined' ){
                        object.style.height = object.u_height;
                        object.height = object.u_height;
                    }
                }
            }
        },
        changeObjectHorizontal: function( id, width, action ) {
            var object = document.getElementById(id);
            if ( object != null ){
                if ( action == 0 ){
                    if ( width > 0 ){
                        object.style.width = width;
                        if ( object.parentElement != null && object.parentElement.tagName == 'TD' ){
                            object.parentElement.width = width;
                        }
                    }
                    else{
                        object.style.width = 1;
                    }
                }
                else if ( action == 1 ){
                    if ( object.parentElement != null && object.parentElement.tagName == 'TD' ){
                        object.parentElement.style.display = 'block';
                    }
                    object.style.display = 'block';
                    object.style.overflowX = 'hidden';
                    object.u_width = object.offsetWidth;
                    if ( width > 0 ){
                        object.style.width = width;
                        if ( object.parentElement != null && object.parentElement.tagName == 'TD' ){
                            object.parentElement.style.width = width;
                        }
                    }
                    else{
                        object.style.width = 1;
                        if ( object.parentElement != null && object.parentElement.tagName == 'TD' ){
                            object.parentElement.style.width = 1;
                        }

                    }
                }
                else if ( action == 2 ){
                    if ( object.parentElement != null && object.parentElement.tagName == 'TD' ){
                        object.parentElement.style.display = 'block';
                    }
                    object.style.display = 'block';
                    object.style.overflowX = '';
                    if ( typeof( object.u_width ) != 'undefined' ){
                        object.style.width = object.u_width;
                        object.width = object.u_width;
                    }
                    object.style.display = 'none'; // fixes css bug in ie6
                    object.style.display = 'block';
                }
                else if ( action == 3 ){
                    object.u_width = object.offsetWidth;
                    object.style.overflowX = 'hidden';
                    if ( width > 0 ){
                        object.style.width = width;
                    }
                    else{
                        object.style.width = 1;
                    }
                }
                else if ( action == 4 ){
                    object.style.display = 'none';
                    object.style.overflowX = '';
                    if ( typeof( object.u_width ) != 'undefined' ){
                        object.style.width = object.u_width;
                        object.width = object.u_width;
                    }
                    if ( object.parentElement != null && object.parentElement.tagName == 'TD' ){
                        object.parentElement.style.display = 'none';
                    }
                }
            }
        }
    };

    this.progress = {
        api_desc: 'Sapphire API for showing a progress bar dialog.',
        oProgressControl: null,
        show: function( sTitle, sText1, sText2, iInitalTime, sTimeUnit, sImageFrom, sImageTo, sCancelFunction, lTranslate ){
            var oaData;
            if ( this.oProgressControl == null ){
                if (typeof(lTranslate) == 'undefined' && lTranslate){
                    if (sTitle.length > 0){
                        sTitle = sapphire.translate(sTitle);
                    }
                    if (sText1.length > 0){
                        sText1 = sText1.translate();
                    }
                    if (sText2.length > 0){
                        sText2 = sText2.translate();
                    }
                }
                oaData = new Array(7);
                oaData[0] = sTitle;
                oaData[1] = sText1;
                oaData[2] = sText2;
                if ( typeof( iInitalTime ) != 'undefined' ){
                    oaData[3] = iInitalTime;
                }
                else{
                    oaData[3] = 0;
                }
                if ( typeof( sTimeUnit ) != 'undefined' ){
                    oaData[4] = sTimeUnit;
                }
                else{
                    oaData[4] = '';
                }
                if ( typeof( sImageFrom ) != 'undefined' ){
                    oaData[5] = sImageFrom;
                }
                else{
                    oaData[5] = '';
                }
                if ( typeof( sImageTo ) != 'undefined' ){
                    oaData[6] = sImageTo;
                }
                else{
                    oaData[6] = '';
                }
                var sUrl = 'rc?command=file&file=WEB-CORE/utils/javascript/progress.jsp';
                if ( typeof( sCancelFunction ) != 'undefined' ){
                    oaData[7] = sCancelFunction;
                    sUrl += '&cancel=Y';
                }
                else{
                    oaData[7] = '';
                }
                oaData[8] = window;
                top.window.focus();
                top.sapphire.ui.modalCover.show( top.sapphire.ui.modalCover.create( 'sapphireProgressModal', top.document.body, 40 ) );
                try{
                    this.oProgressControl = window.showModelessDialog( sUrl,
                            oaData,
                            'dialogWidth:400px;dialogHeight:170px;resizable:no;help:no;scroll:no;status:no;center:yes;' );
                }
                catch(e){
                    if ( top.sapphire.ui.animation.fadeInOutEnabled ){
                        top.sapphire.ui.animation.fadeOut( 'sapphireDialogModal', 25, 2, 1, 30, this.hideEnd );
                    }
                    else{
                        this.hideEnd();
                    }
                    this.oProgressControl = null;
                    sapphire.ui.dialog.alert('Popup blocked therefore progress dialog cannot show.');
                }
                var iWait = 0;
                while (this.oProgressControl.document.readyState == 'loading' || iWait > 99999){
                    iWait ++;    
                }
            }
        },
        hide: function( ){
            if ( this.oProgressControl != null ){
                top.sapphire.ui.modalCover.remove('sapphireProgressModal');
                this.oProgressControl.window.closing = true;
                this.oProgressControl.window.close();                
                this.hideEnd();
            }
        },
        hideEnd: function(){
            this.oProgressControl = null;
        },
        update: function( sText1, sText2, iTotalItems, iItemNumber, nTimePerItem ){
            if ( this.oProgressControl != null ){
                if (sText1.length > 0){
                    sText1 = sText1.translate();
                }
                if (sText2.length > 0){
                    sText2 = sText2.translate();
                }
                try{
                    this.oProgressControl.progress.doUpdateProgress( sText1, sText2, iTotalItems, iItemNumber, nTimePerItem, 'Second', 'Seconds' );
                }
                catch( e ){
                    ///
                }
            }
        }
    }

    this.resize = {
        api_desc: 'Sapphire API for applying dynamic resize to any HTML element.',
        xcorr: 0,
        ycorr: 0,
        offsetX: 0,
        offsetY: 0,
        bounds: {
            minX: 0,
            maxX: 0,
            minY: 0,
            maxY: 0
        },
        resizing: false,
        direction: '',
        orgbodycursor: 'default',
        resizeObject: null,
        resizableObject: null,
        start: function ( oResizableObject, oaFollowObjects, sDirection ){
            if ( !sapphire.ui.dragdrop.dragging ){
                if ( typeof(oResizableObject) != 'undefined' && oResizableObject != null &&
                       typeof(sDirection) != 'undefined' && sDirection.length > 0 ){
                    if (typeof(oResizableObject.maximized) == 'undefined' || !oResizableObject.maximized ){
                        var oDoc = document;
                        var oDiv = oDoc.createElement('div');
                        try{
                            oDiv.id = 'sapphireResize';
                            oDiv.className = 'resize_div';
                            oDiv.style.position = 'absolute';
                            oDiv.style.zIndex = 200;
                            var iaPos = sapphire.ui.util.findElementPos( oResizableObject.offsetParent );
                            this.offsetX = iaPos[0];
                            this.offsetY = iaPos[1];
                            if ( this.bounds.maxX == 0 && this.bounds.maxY == 0 &&
                                 this.bounds.minX == 0 && this.bounds.minY == 0 ){
                                var oParent = oResizableObject.offsetParent;
                                if ( oParent.scrollWidth > oParent.clientWidth ){
                                    this.bounds.maxX = oParent.scrollWidth - 2;
                                }
                                else{
                                    this.bounds.maxX = oParent.clientWidth - 2;
                                }
                                if ( oParent.scrollHeight > oParent.clientHeight ){
                                    this.bounds.maxY = oParent.scrollHeight - 2;
                                }
                                else{
                                    this.bounds.maxY = oParent.clientHeight - 2;
                                }
                                this.bounds.minX = 2;
                                this.bounds.minY = 2;
                            }
                            var oR;
                            if (oResizableObject.tagName=='TR'){
                                if (sapphire.browser.ie){
                                    oR = oResizableObject.parentElement.parentElement.getBoundingClientRect();
                                }
                                else{
                                    oR = oResizableObject.parentNode.parentNode.getBoundingClientRect();
                                }
                                oDiv.style.width = oR.right - oR.left;
                            }
                            else{
                                oDiv.style.width = oResizableObject.style.width;
                            }
                            if (oResizableObject.tagName=='TD'){
                                oR = oResizableObject.getBoundingClientRect();
                                oDiv.style.height = oR.bottom - oR.top;
                            }
                            else{
                                oDiv.style.height = oResizableObject.style.height;
                            }

                            var iPT = sapphire.browser.ie ? oResizableObject.style.pixelTop : parseInt(oResizableObject.style.top);
                            var iPL = sapphire.browser.ie ? oResizableObject.style.pixelLeft : parseInt(oResizableObject.style.left);

                            oDiv.style.top = iPT  + this.offsetY;
                            oDiv.style.left = iPL + this.offsetX;
                            oDoc.body.appendChild( oDiv );
                            this.orgbodycursor = oDoc.body.style.cursor;
                            this.direction = sDirection.toLowerCase();
                            oDoc.body.style.cursor = this.direction + '-resize';
                            if (typeof(oaFollowObjects) != 'undefined' && oaFollowObjects != null){
                                oResizableObject.resizefollowelements = oaFollowObjects;
                            }
                            else{
                                oResizableObject.resizefollowelements = null;
                            }
                            this.resizableObject = oResizableObject;
                            this.resizeObject = oDiv;

                            sapphire.ui.util.addCover( this.resizeObject.parentElement?this.resizeObject.parentElement:this.resizeObject.parentNode,
                                    this.bounds.minX, this.bounds.minY, this.bounds.maxX, this.bounds.maxY );

                            sapphire.events.attachEvent( oDoc, 'mousemove', this.doResizeMM );
                            sapphire.events.attachEvent( oDoc, 'mouseup', this.doResizeEnd );

                            this.resizing = true;
                        }
                        finally{
                            oDiv = null;
                        }
                    }
                }
            }
        },
        doMMFrame: function( sFrameId, e ){
            if ( typeof(sapphire.ui.resize) != 'undefined' && sapphire.ui.resize.resizing ){
                var oFrame=window.frames[sFrameId];
                if ( oFrame != null ){
                    if (typeof(e) == 'undefined'){
                        e = oFrame.window.event;
                    }
                    var iX = e.x;
                    var iY = e.y;
                    var iaFrameCoords = sapphire.ui.util.findElementPos( oFrame.frameElement );
                    iX += iaFrameCoords[0];
                    iY += iaFrameCoords[1];
                    sapphire.ui.resize.doResize( iX, iY );
                    if (sapphire.browser.mozilla){
                        e.preventDefault();
                    }
                    else{
                        e.returnValue = false;
                    }
                }
            }
        },
        doMUFrame: function( sFrameId, e ){
            if ( typeof(sapphire.ui.resize) != 'undefined' && sapphire.ui.resize.resizing ){
                sapphire.ui.resize.doResizeEnd();
            }
        },
        doResizeMM: function( e ){
            if ( this != sapphire.ui.resize ){
                sapphire.ui.resize.doResizeMM(e);
            }
            else
            {
                if ( this.resizing ){
                    //this.doResize(e.x, e.y);
                    this.doResize(e.clientX, e.clientY);
                    sapphire.ui.util.cancelEvent(e);
                }
            }
        },
        doResize: function( iX, iY ){
            if ( this.resizeObject != null && this.resizableObject != null ){
                var iDiffX;
                var iDiffY;
                var iPT = sapphire.browser.ie ? this.resizeObject.style.pixelTop : parseInt(this.resizeObject.style.top);
                var iPL = sapphire.browser.ie ? this.resizeObject.style.pixelLeft : parseInt(this.resizeObject.style.left);
                var iPW = sapphire.browser.ie ? this.resizeObject.style.pixelWidth : parseInt(this.resizeObject.style.width);
                var iPH = sapphire.browser.ie ? this.resizeObject.style.pixelHeight : parseInt(this.resizeObject.style.height);

                if ( this.direction == 'e' || this.direction == 'se' || this.direction == 'ne' ){
                    iDiffX = (iPL + iPW) - ((iX - this.xcorr) + document.body.scrollLeft);
                    if ( (iPW - iDiffX) + (iPL - this.offsetX) <= this.bounds.maxX ){
                        this.resizeObject.style.width = iPW - iDiffX;
                    }
                }
                else if (this.direction == 'w' || this.direction == 'sw' || this.direction == 'nw' ){
                    iDiffX = iPL - ((iX - this.xcorr) + document.body.scrollLeft);
                    if ( ((iPL - this.offsetX) - iDiffX) >= this.bounds.minX ){
                        this.resizeObject.style.left = iPL - iDiffX;
                        this.resizeObject.style.width = iPW + iDiffX;
                    }
                }
                if ( this.direction == 's' || this.direction == 'se' || this.direction == 'sw' ){
                    iDiffY = (iPT + iPH) - ((iY - this.ycorr) + document.body.scrollTop);
                    if ( (iPH - iDiffY) + (iPT - this.offsetY) <= this.bounds.maxY ){
                        this.resizeObject.style.height = iPH - iDiffY;
                    }
                }
                else if (this.direction == 'n' || this.direction == 'ne' || this.direction == 'nw' ){
                    iDiffY = iPT - ((iY - this.ycorr) + document.body.scrollTop);
                    if ( ((iPT - this.offsetY) - iDiffY) >= this.bounds.minY ){
                        this.resizeObject.style.top = iPT - iDiffY;
                        this.resizeObject.style.height = iPH + iDiffY;
                    }
                }
            }
        },
        doResizeEnd: function(){
            if ( this != sapphire.ui.resize ){
                sapphire.ui.resize.doResizeEnd();
            }
            else
            {
                if ( this.resizing ){
                    if ( this.resizeObject != null && this.resizableObject != null ){
                        this.resizing = false;
                        var oDoc = document;
                        sapphire.events.detachEvent( oDoc, 'mousemove', this.doResizeMM );
                        sapphire.events.detachEvent( oDoc, 'mouseup', this.doResizeEnd );

                        var iPT1 = sapphire.browser.ie ? this.resizableObject.style.pixelTop : parseInt(this.resizableObject.style.top);
                        var iPT2 = sapphire.browser.ie ? this.resizeObject.style.pixelTop : parseInt(this.resizeObject.style.top);
                        var iPL1 = sapphire.browser.ie ? this.resizableObject.style.pixelLeft : parseInt(this.resizableObject.style.left);
                        var iPL2 = sapphire.browser.ie ? this.resizeObject.style.pixelLeft : parseInt(this.resizeObject.style.left);
                        var iPW1 = sapphire.browser.ie ? this.resizableObject.style.pixelWidth : parseInt(this.resizableObject.style.width);
                        var iPW2 = sapphire.browser.ie ? this.resizeObject.style.pixelWidth : parseInt(this.resizeObject.style.width);
                        var iPH1 = sapphire.browser.ie ? this.resizableObject.style.pixelHeight : parseInt(this.resizableObject.style.height);
                        var iPH2 = sapphire.browser.ie ? this.resizeObject.style.pixelHeight : parseInt(this.resizeObject.style.height);

                        var iDifX = iPT1 - iPT2;
                        var iDifY = iPL1 - iPL2;
                        var iDifW = iPW1 - iPW2;
                        var iDifH = iPH1 - iPH2;
                        this.resizableObject.style.top = iPT2 - this.offsetY;
                        this.resizableObject.style.left = iPL2 - this.offsetX;
                        this.resizableObject.style.width = iPW2;
                        this.resizableObject.style.height = iPH2;
                        if ( this.resizableObject.resizefollowelements != null ){
                            var oEls = this.resizableObject.resizefollowelements;
                            var iFolLength = oEls.length;
                            for (var iIndex = 0; iIndex < iFolLength; iIndex++){
                                var oEl;
                                if (typeof (oEls[iIndex].frameElement)  != 'undefined' ){
                                    oEl = oEls[iIndex].frameElement;
                                }
                                else{
                                    oEl = oEls[iIndex];
                                }
                                oEl.style.top = (sapphire.browser.ie ? oEl.style.pixelTop : parseInt(oEl.style.top)) - iDifX;
                                oEl.style.left = (sapphire.browser.ie ? oEl.style.pixelLeft : parseInt(oEl.style.left)) - iDifY;
                                oEl.style.width = (sapphire.browser.ie ? oEl.style.pixelWidth : parseInt(oEl.style.width)) - iDifW;
                                oEl.style.height = (sapphire.browser.ie ? oEl.style.pixelHeight : parseInt(oEl.style.height)) - iDifH;
                            }
                            oEls = null;
                        }
                        this.direction = '';
                        oDoc.body.style.cursor = this.orgbodycursor;

                        sapphire.garbage.add( this.resizeObject );
                        sapphire.ui.util.removeCover();

                        if( this.resizableObject.linked ){
                            sapphire.ui.link.updateAll( this.resizableObject );
                        }
                        if ( typeof( this.resizableObject.onresizeend )!='undefined' && this.resizableObject.onresizeend != null ){
                            if ( typeof(this.resizableObject.onresizeend) == 'string'){
                                eval(this.resizableObject.onresizeend)( this.resizableObject );
                            }
                            else{
                                this.resizableObject.onresizeend( this.resizableObject );
                            }
                        }
                        this.resizableObject = null;
                        this.resizeObject = null;
                    }
                }
            }
        },
        maximize: function( oResizableObject ){
            if (typeof(oResizableObject) != 'undefined' && oResizableObject != null){
                if (typeof(oResizableObject.maximized) == 'undefined' || !oResizableObject.maximized ){
                    oResizableObject.orgx = (sapphire.browser.ie ? oResizableObject.style.pixelLeft : parseInt(oResizableObject.style.left));
                    oResizableObject.orgy = (sapphire.browser.ie ? oResizableObject.style.pixelTop : parseInt(oResizableObject.style.top));
                    oResizableObject.orgwidth = (sapphire.browser.ie ? oResizableObject.style.pixelWidth : parseInt(oResizableObject.style.width));
                    oResizableObject.orgheight = (sapphire.browser.ie ? oResizableObject.style.pixelHeight : parseInt(oResizableObject.style.height));
                    oResizableObject.maximized = true;
                    //if( typeof(oResizableObject.links) != 'undefined' && oResizableObject.links != null ){
                    if( oResizableObject.linked ){
                        sapphire.ui.link.hideAll( oResizableObject );
                    }
                    oResizableObject.style.left = 0;
                    oResizableObject.style.top = 0;
                    if ( document.body.scrollWidth > document.body.clientWidth ){
                        oResizableObject.style.width = document.body.scrollWidth;
                    }
                    else{
                        oResizableObject.style.width = document.body.clientWidth;
                    }
                    if ( oResizableObject.offsetParent.scrollHeight > document.body.clientHeight ){
                        oResizableObject.style.height = document.body.scrollHeight;
                    }
                    else{
                        oResizableObject.style.height = document.body.clientHeight;
                    }
                }
            }
        },
        restore: function (oResizableObject){
            if (typeof(oResizableObject) != 'undefined' && oResizableObject != null){
                if (typeof(oResizableObject.maximized) != 'undefined' && oResizableObject.maximized ){
                    oResizableObject.maximized = false;
                    oResizableObject.style.left = oResizableObject.orgx;
                    oResizableObject.style.top = oResizableObject.orgy;
                    oResizableObject.style.width = oResizableObject.orgwidth;
                    oResizableObject.style.height = oResizableObject.orgheight;
                    //if( typeof(oResizableObject.links) != 'undefined' && oResizableObject.links != null ){
                    if( oResizableObject.linked ){
                        sapphire.ui.link.updateAll( oResizableObject );
                    }
                }
            }
        },
        setResizeEvent: function( oResizableObject, oOnResize ){
            if ( typeof(oResizableObject)!= 'undefined' && oResizableObject != null &&
                   typeof(oOnResize)!= 'undefined' && oOnResize != null ){
                oResizableObject.onresizeend = oOnResize;
            }
            else{
                oResizableObject.onresizeend = null;
            }
        }
    }

    this.dragdrop = {
        api_desc: 'Sapphire API for applying drag and drop to any HTML element.',
        xcorr: 0,
        ycorr: 0,
        yoffset: 0,
        xoffset: 0,
        startLeft: 0,
        startTop: 0,
        dragObject: null,
        dropTarget: null,
        targets: new Array(),
        cursor: 'move',
        dragging: false,
        mouseDown: false,
        MOVEPOSITVE: 1,
        MOVENEGATIVE: -1,
        MOVENONE: 0,
        MOVENORMAL: -99,
        setMoveX: function ( oDragPointElement, iMovement ){
            if ( typeof(oDragPointElement)!= 'undefined' && oDragPointElement != null &&
                   typeof(oDragPointElement.dragElement)!= 'undefined' && oDragPointElement.dragElement != null  ){
                oDragPointElement.dragElement.movex = iMovement;
            }
        },
        setMoveY: function ( oDragPointElement, iMovement ){
            if ( typeof(oDragPointElement)!= 'undefined' && oDragPointElement != null &&
                   typeof(oDragPointElement.dragElement)!= 'undefined' && oDragPointElement.dragElement != null  ){
                oDragPointElement.dragElement.movey = iMovement;
            }
        },
        setFollowElements: function ( oDragPointElement, oaFollowElements ){
            if ( typeof(oDragPointElement)!= 'undefined' && oDragPointElement != null &&
                   typeof(oaFollowElements)!= 'undefined' && oaFollowElements != null &&
                   typeof(oDragPointElement.dragElement)!= 'undefined' && oDragPointElement.dragElement != null  ){
                if ( typeof(oaFollowElements)!= 'undefined' && oaFollowElements != null ){
                    oDragPointElement.dragElement.followElements = oaFollowElements;
                }
                else{
                    oDragPointElement.dragElement.followElements = null;
                }
            }
        },
        setDropOnTargetEvent: function( oDragPointElement, oOnDropOnTarget ){
            if ( typeof(oDragPointElement)!= 'undefined' && oDragPointElement != null &&
                   typeof(oOnDropOnTarget)!= 'undefined' && oOnDropOnTarget != null &&
                   typeof(oDragPointElement.dragElement)!= 'undefined' && oDragPointElement.dragElement != null  ){
                oDragPointElement.dragElement.ondropontarget = oOnDropOnTarget;
            }
            else{
                oDragPointElement.dragElement.ondropontarget = null;
            }

        },
        setDropOffTargetEvent: function( oDragPointElement, oOnDropOffTarget ){
            if ( typeof(oDragPointElement)!= 'undefined' && oDragPointElement != null &&
                   typeof(oOnDropOffTarget)!= 'undefined' && oOnDropOffTarget != null &&
                   typeof(oDragPointElement.dragElement)!= 'undefined' && oDragPointElement.dragElement != null  ){
                oDragPointElement.dragElement.ondropofftarget = oOnDropOffTarget;
            }
            else{
                oDragPointElement.dragElement.ondropofftarget = null;
            }

        },
        defaultBounds: function ( oDragElement ){
            function Bounds( iMinX, iMaxX, iMinY, iMaxY ) {
                this.minX= iMinX;
                this.maxX= iMaxX;
                this.minY= iMinY;
                this.maxY= iMaxY;
            }
            var bounds = new Bounds( 0,0,0,0 );
            if ( typeof( oDragElement ) != 'undefined' && oDragElement != null ){
                var oParent = oDragElement.offsetParent;
                if ( oParent.scrollWidth > 0 || oParent.clientWidth > 0 ){
                    if ( oParent.scrollWidth > oParent.clientWidth ){
                        bounds.maxX = oParent.scrollWidth - 2;
                    }
                    else{
                        bounds.maxX = oParent.clientWidth - 2;
                    }
                    bounds.minX = 2;
                }
                if ( oParent.scrollHeight > 0 || oParent.clientHeight > 0 ){
                    if ( oParent.scrollHeight > oParent.clientHeight ){
                        bounds.maxY = oParent.scrollHeight - 2;
                    }
                    else{
                        bounds.maxY = oParent.clientHeight - 2;
                    }
                    bounds.minY = 2;
                }
            }
            return bounds;
        },
        registerDragObject: function( oDragPointElement, oDragElement, lReset , iaBounds ){
            if ( typeof(oDragPointElement)!= 'undefined' && oDragPointElement != null ){
                if ( typeof(oDragElement)!= 'undefined' && oDragElement != null ){
                    oDragPointElement.dragable = true;
                    oDragPointElement.dragElement = oDragElement;

                    if ( typeof(lReset)== 'undefined' || lReset ){
                        oDragPointElement.dragElement.reset = true;
                    }
                    else{
                        oDragPointElement.dragElement.reset = false;
                    }

                    oDragPointElement.dragElement.followElements = null;
                    oDragPointElement.dragElement.ondropontarget = null;
                    oDragPointElement.dragElement.ondropofftarget = null;
                    oDragPointElement.dragElement.movex = this.MOVENORMAL;
                    oDragPointElement.dragElement.movey = this.MOVENORMAL;
                    if ( typeof( iaBounds ) != 'undefined' && iaBounds != null && iaBounds.length == 4 ){
                        oDragPointElement.dragElement.bounds = this.defaultBounds( null );
                        oDragPointElement.dragElement.bounds.minX = iaBounds[0];
                        oDragPointElement.dragElement.bounds.maxX = iaBounds[1];
                        oDragPointElement.dragElement.bounds.minY = iaBounds[2];
                        oDragPointElement.dragElement.bounds.maxY = iaBounds[3];
                    }
                    else{
                        oDragPointElement.dragElement.bounds = null;
                    }
                }
                else{
                    oDragPointElement.dragElement = null;
                }
            }
        },
        unregisterDragObject: function( oDragPointElement ){
            if ( oDragPointElement != null ){
                var oDragElement = oDragPointElement.dragElement;
                if ( typeof(oDragElement)!= 'undefined' && oDragElement != null ){
                    oDragElement.bounds = null;
                    oDragElement.followElements = null;
                    oDragElement.ondropontarget = null;
                    oDragElement.ondropofftarget = null;
                    oDragElement.movex = null;
                    oDragElement.movey = null;
                    oDragElement.reset = null;
                    oDragElement.followElements = null;
                    oDragElement.ondropontarget = null;
                    oDragElement.ondropofftarget = null;
                }
                oDragPointElement.dragElement = null;
                oDragPointElement.dragable = null;
            }
        },
        registerDropTarget: function( oHTMLElement ){
            if ( typeof(oHTMLElement)!= 'undefined' && oHTMLElement != null ){
                oHTMLElement.droptarget = true;
                this.targets.push(oHTMLElement);
            }
        },
        doMDown: function(e){
            sapphire.ui.dragdrop.mousedown = true;
        },
        doMUp: function(e){
            sapphire.ui.dragdrop.mousedown = false;
        },
        doMMFrame: function( sFrameId, e ){
            if ( typeof(sapphire.ui.dragdrop) != 'undefined' && sapphire.ui.dragdrop.dragging ){
                var oFrame=window.frames[sFrameId];
                if ( oFrame != null ){
                    var iX;
                    var iY;
                    if ( sapphire.mozilla ){
                        iX = e.x;
                        iY = e.y;
                    }
                    else{
                        iX = oFrame.window.event.x;
                        iY = oFrame.window.event.y;
                    }
                    var iaFrameCoords = sapphire.ui.util.findElementPos( oFrame.frameElement );
                    iX += iaFrameCoords[0];
                    iY += iaFrameCoords[1];
                    sapphire.ui.dragdrop.doDrag( iX, iY );
                    if (sapphire.browser.mozilla){
                        e.preventDefault();
                    }
                    else{
                        oFrame.window.event.returnValue = false;
                    }
                }
            }
        },
        doMUFrame: function( sFrameId, e ){
            if ( typeof(sapphire.ui.dragdrop) != 'undefined' && sapphire.ui.dragdrop.dragging ){
                sapphire.ui.dragdrop.doDragEnd();
            }
        },
        doDragMM: function( e ){
            if ( this != sapphire.ui.dragdrop  ){
                sapphire.ui.dragdrop.doDragMM( e );
            }
            else if (typeof(e) != 'undefined' && e != null) {
                if ( e.button == 1 || this.mousedown ){
                    if ( !this.dragging ){
                        var oSrc = (typeof(e.srcElement) != 'undefined') ? e.srcElement : e.target;
                        if (oSrc.dragable){
                            if ( !sapphire.ui.resize.resizing ){
                                if (typeof(oSrc.dragElement.maximized) == 'undefined' || !oSrc.dragElement.maximized ){
                                    this.dragObject = oSrc.dragElement;
                                    if ( this.dragObject.bounds == null ){
                                        this.dragObject.bounds = this.defaultBounds( this.dragObject );
                                    }
                                    this.startLeft = sapphire.browser.ie ? this.dragObject.style.pixelLeft : parseInt(this.dragObject.style.left);
                                    this.startTop = sapphire.browser.ie ? this.dragObject.style.pixelTop : parseInt(this.dragObject.style.top);
                                    this.dragObject.oldposition = this.dragObject.style.position;
                                    var iaPos1 = sapphire.ui.util.findElementPos( this.dragObject.offsetParent );
                                    var iaPos2 = sapphire.ui.util.findElementPos( oSrc );
                                    var iaPos3 = sapphire.ui.util.findElementPos( this.dragObject );
                                    var iaPos4 = [ iaPos3[0] - iaPos2[0], iaPos3[1] - iaPos2[1] ];
                                    this.xoffset = (sapphire.browser.ie ? e.offsetX : e.layerX) + iaPos1[0] - iaPos4[0];
                                    this.yoffset = (sapphire.browser.ie ? e.offsetY : e.layerY) + iaPos1[1] - iaPos4[1];

                                    var oCover = sapphire.ui.util.addCover( (sapphire.browser.ie ? this.dragObject.parentElement : this.dragObject.parentNode),
                                            this.dragObject.bounds.minX, this.dragObject.bounds.minY, this.dragObject.bounds.maxX, this.dragObject.bounds.maxY );
                                    oCover.style.cursor = 'move';

                                    if ( typeof(this.dragObject.ondragstart) != 'undefined' && this.dragObject.ondragstart != null ){
                                        this.dragObject.ondragstart();
                                    }
                                    this.dragging = true;
                                    sapphire.ui.util.cancelEvent(e);
                                }
                            }
                        }
                    }
                    else{
                        this.doDrag( e.clientX, e.clientY );
                        sapphire.ui.util.cancelEvent();
                    }

                }
            }
        },
        doDrag: function( iX, iY ){
            if ( this != sapphire.ui.dragdrop ){
                sapphire.ui.dragdrop.doDrag( iX, iY );
            }
            else{
                var oDragObject = this.dragObject;
                if ( oDragObject.style.cursor != this.cursor){
                    oDragObject.orgcursor = oDragObject.style.cursor;
                    oDragObject.style.cursor = this.cursor;
                }
                var iPixLeft = (sapphire.browser.ie ? oDragObject.style.pixelLeft : parseInt(oDragObject.style.left));
                var iPixTop = (sapphire.browser.ie ? oDragObject.style.pixelTop : parseInt(oDragObject.style.top));
                var iPixHeight = (sapphire.browser.ie ? oDragObject.style.pixelHeight : parseInt(oDragObject.style.height));
                var iPixWidth = (sapphire.browser.ie ? oDragObject.style.pixelWidth : parseInt(oDragObject.style.width));
                var iDiffX = iPixLeft - (((iX - this.xcorr) -  this.xoffset) + document.body.scrollLeft);
                var iDiffY = iPixTop - (((iY - this.ycorr)- this.yoffset)  + document.body.scrollTop);
                if ( oDragObject.movex == this.MOVENONE || (iDiffX > 0 && oDragObject.movex == this.MOVEPOSITVE) || ( iDiffX < 0 && oDragObject.movex == this.MOVENEGATIVE ) ){
                    iDiffX = 0;
                }
                if ( oDragObject.movey == this.MOVENONE || (iDiffY > 0 && oDragObject.movey == this.MOVEPOSITVE) || ( iDiffY < 0 && oDragObject.movey == this.MOVENEGATIVE ) ){
                    iDiffY = 0;
                }
                if ( (iPixLeft - iDiffX) <= oDragObject.bounds.minX ){
                    iDiffX = iPixLeft - oDragObject.bounds.minX;
                }
                else if (((iPixLeft - iDiffX)  + iPixWidth) >= oDragObject.bounds.maxX ){
                    iDiffX = (iPixLeft + iPixWidth)  - oDragObject.bounds.maxX;
                }
                if ((iPixTop - iDiffY) <= oDragObject.bounds.minY ){
                    iDiffY = iPixTop - oDragObject.bounds.minY;
                }
                else if (((iPixTop - iDiffY) + iPixHeight)  >= oDragObject.bounds.maxY ){
                    iDiffY = (iPixTop + iPixHeight)  - oDragObject.bounds.maxY;
                }
                if ( iDiffX != 0 ){
                    oDragObject.style.left = iPixLeft - iDiffX;
                }
                if ( iDiffY != 0 ){
                    oDragObject.style.top = iPixTop - iDiffY;
                }
                if ( typeof(oDragObject.followElements) != 'undefined' && oDragObject.followElements != null ){
                    var iLength = oDragObject.followElements.length;
                    for ( var iIndex = 0; iIndex < iLength; iIndex++ ){
                        var oItem = this.dragObject.followElements[iIndex];
                        if ( iDiffX != 0 ){
                            oItem.style.left = (sapphire.browser.ie ? oItem.style.pixelLeft : parseInt(oItem.style.left)) - iDiffX;
                        }
                        if ( iDiffY != 0 ){
                            oItem.style.top = (sapphire.browser.ie ? oItem.style.pixelTop : parseInt(oItem.style.top)) - iDiffY;
                        }
                    }
                }
                if( oDragObject.linked ){
                    sapphire.ui.link.updateAll( this.dragObject );
                }
                var iMinX = iPixLeft;
                var iMinY = iPixTop;
                var iMaxX = iMinX + iPixWidth;
                var iMaxY = iMinY + iPixHeight;
                var iTarLength = this.targets.length;
                for ( var iIndex = 0; iIndex < iTarLength; iIndex++ ){
                    var oItem = this.targets[iIndex];
                    var iBMinX = (sapphire.browser.ie ? oItem.style.pixelLeft : parseInt(oItem.style.left));
                    var iBMinY = (sapphire.browser.ie ? oItem.style.pixelTop : parseInt(oItem.style.top));
                    var iBMaxX = iBMinX + (sapphire.browser.ie ? oItem.style.pixelWidth : parseInt(oItem.style.width));
                    var iBMaxY = iBMinY + (sapphire.browser.ie ? oItem.style.pixelHeight : parseInt(oItem.style.height));
                    if ( (iMinX > iBMinX && iMinY > iBMinY ) && ( iMinX < iBMaxX && iMinY < iBMaxY )){
                        if ( oItem != this.dropTarget ){
                            this.doDragEnter( oItem );
                        }
                    }
                    else{
                        if ( oItem == this.dropTarget ){
                            this.doDragLeave( );
                        }
                    }
                }
            }
        },
        doDragEnter: function( oElement ){
            if ( this != sapphire.ui.dragdrop ){
                sapphire.ui.dragdrop.doDragEnter( oElement );
            }
            else{
                if ( this.dragging ){
                    if (this.dragObject != null && this.dropTarget == null){
                        this.dropTarget = oElement;
                        this.dropTarget.orgborder = this.dropTarget.style.border;
                        this.dropTarget.style.border = 'red solid 4';
                        sapphire.ui.util.cancelEvent();
                    }
                }
            }
        },
        doDragLeave: function(){
            if ( this != sapphire.ui.dragdrop ){
                sapphire.ui.dragdrop.doDragLeave();
            }
            else{
                if ( this.dragging ){
                    if (this.dropTarget != null && this.dropTarget != null){
                        this.dropTarget.style.border = this.dropTarget.orgborder;
                        this.dropTarget = null;
                        sapphire.ui.util.cancelEvent();
                    }
                }
            }
        },
        doDragEnd: function(){
            if ( this != sapphire.ui.dragdrop ){
                sapphire.ui.dragdrop.doDragEnd();
            }
            else
            {
                if ( this.dragging ){
                    this.dragging = false;
                    var oTheDragOb;
                    var oTheDropTar;
                    oTheDragOb  = this.dragObject;
                    oTheDropTar = this.dropTarget;
                    if ( oTheDragOb.reset ){
                        this.dragObject.style.left     = this.startLeft;
                        this.dragObject.style.top      = this.startTop;
                    }
                    this.dragObject.style.cursor = this.dragObject.orgcursor;
                    this.dropTarget = null;
                    this.dragObject = null;
                    if( oTheDragOb.linked ){
                        sapphire.ui.link.updateAll( oTheDragOb );
                    }
                    sapphire.ui.util.removeCover();
                    if (oTheDragOb != null && oTheDropTar != null){
                        oTheDropTar.style.border = oTheDropTar.orgborder;
                        if ( typeof(oTheDropTar.ondropontarget) != 'undefined' && oTheDropTar.ondropontarget != null ){
                            oTheDropTar.ondropontarget( oTheDragOb, oTheDropTar );
                        }
                    }
                    else if ( oTheDragOb != null){
                        if ( typeof(oTheDragOb.ondropofftarget) != 'undefined' && oTheDragOb.ondropofftarget != null ){
                            oTheDragOb.ondropofftarget( oTheDragOb );
                        }
                    }
                    oTheDragOb = null;
                    oTheDropTar = null;
                    sapphire.garbage.collect();
                }
            }
        }
    }

    this.link = {
        api_desc: 'Sapphire API for drawing a graphical link between any two HTML elements.',
        count: 0,
        offset: 0,
        tocorrection:[0,0],
        fromcorrection:[0,0],
        links: [],
        attachEvent: function ( oLink, sEventName, oFunction ){
            if ( typeof(oLink) != 'undefined' ){
                if ( typeof(oLink.linkobject1) != 'undefined' && oLink.linkobject1 != null ){
                    var oFunc = function(){
                        oFunction( oLink );
                    }
                    sapphire.events.attachEvent( oLink.linkobject1, sEventName, oFunc );
                    sapphire.events.attachEvent( oLink.linkobject2, sEventName, oFunc );
                    sapphire.events.attachEvent( oLink.linkobject3, sEventName, oFunc );
                    sapphire.events.attachEvent( oLink.linkobject4, sEventName, oFunc );
                    sapphire.events.attachEvent( oLink.linkobject5, sEventName, oFunc );
                    sapphire.events.attachEvent( oLink.startnode, sEventName, oFunc );
                    sapphire.events.attachEvent( oLink.endnode, sEventName, oFunc );
                    sapphire.events.attachEvent( oLink.descriptionnode, sEventName, oFunc );
                }
            }
        },
        detachEvent: function ( oLink, sEventname, oFunction ){
            if ( typeof(oFromObject) != 'undefined' && typeof(oToObject) != 'undefined' && oFromObject != null && oToObject != null ){
                if ( typeof(oLink.linkobject1) != 'undefined' && oLink.linkobject1 != null ){
                    var oFunc = function(){
                        oFunction( oLink );
                    }
                    oLink.linkobject1.detachEvent(sEventName, oFunc);
                    oLink.linkobject2.detachEvent(sEventName, oFunc);
                    oLink.linkobject3.detachEvent(sEventName, oFunc);
                    oLink.linkobject4.detachEvent(sEventName, oFunc);
                    oLink.linkobject5.detachEvent(sEventName, oFunc);
                    oLink.startnode.detachEvent(sEventName, oFunc);
                    oLink.endnode.detachEvent(sEventName, oFunc);
                    oLink.centernode.detachEvent(sEventName, oFunc);
                    oLink.descriptionnode.detachEvent(sEventName, oFunc);
                }
            }
        },
        register: function ( oFromObject, oToObject, sLinkColor, iLinkWidth, sStartNodeSrc, sCenterNodeSrc, sEndNodeSrc, sDescription ){
            if ( typeof(oFromObject) != 'undefined' && typeof(oToObject) != 'undefined' && oFromObject != null && oToObject != null ){
                if ( typeof(sLinkColor) == 'undefined' || sLinkColor.length == 0 ){
                    sLinkColor = '#000000'
                }
                if ( typeof(iLinkWidth) == 'undefined' || iLinkWidth == 0 ){
                    iLinkWidth = 2;
                }
                if ( typeof(sStartNodeSrc) == 'undefined' ){
                    sStartNodeSrc = '';
                }
                if ( typeof(sCenterNodeSrc) == 'undefined' ){
                    sCenterNodeSrc = '';
                }
                if ( typeof(sEndNodeSrc) == 'undefined' ){
                    sEndNodeSrc = '';
                }
                if ( typeof(sDescription) == 'undefined' ){
                    sDescription = '';
                }
                var oLink = {
                    fromobject: oFromObject,
                    toobject: oToObject,
                    linkcolor: sLinkColor,
                    linkwidth: iLinkWidth,
                    startnodesrc: sStartNodeSrc,
                    centernodesrc: sCenterNodeSrc,
                    endnodesrc: sEndNodeSrc,
                    description: sDescription,
                    linkobject1: null,
                    linkobject2: null,
                    linkobject3: null,
                    linkobject4: null,
                    linkobject5: null,
                    startnode: null,
                    centernode: null,
                    endnode: null,
                    descriptionnode: null
                }
                oFromObject.linked = true;
                oToObject.linked = true;
                this.links.push( oLink );
                try{
                    return oLink;
                }
                finally{
                    oLink = null;
                }
                
            }
            return null;
        },
        unregister: function( oLinkedObject ){
            this.removeAll( oLinkedObject );
        },
        updateAll: function( oLinkedObject ){
            if ( typeof(oLinkedObject) != 'undefined' && oLinkedObject != null ){
                var iLength = this.links.length;
                for (var iIndex = 0; iIndex < iLength; iIndex++){
                    var oLink = this.links[iIndex];
                    if ( oLink.toobject == oLinkedObject || oLink.fromobject == oLinkedObject ){
                        this.add( oLink );
                    }
                }
            }
            else{
                var iL = this.links.length;
                for (var iI = 0; iI < iL; iI++){
                    this.add( this.links[iI] );
                }
            }
        },
        removeAll: function( oLinkedObject ){
            if ( typeof(oLinkedObject) != 'undefined' && oLinkedObject != null ){
                var oaToRem = [];
                for (var iIndex = 0; iIndex < this.links.length; iIndex++){
                    var oLink = this.links[iIndex];
                    if ( oLink.toobject == oLinkedObject || oLink.fromobject == oLinkedObject ){
                        oaToRem.push(oLink);
                    }
                }
                var iLength = oaToRem.length;
                for (var iSecIndex = 0; iSecIndex < iLength; iSecIndex++){
                    this.remove( oaToRem[iSecIndex] );
                }
                oaToRem = null;
            }
            else{
                var oaToRem2 = [];
                var iL = this.links.length;
                for (var iI = 0; iI < iL; iI++){
                    oaToRem2.push(this.links[iI]);
                }
                var iL2 = oaToRem2.length;
                for (var iI2 = 0; iI2 < iL2; iI2++){
                    this.remove( oaToRem2[iI2] );
                }
                oaToRem2 = null;
            }
        },
        hideAll: function( oLinkedObject ){
            if ( typeof(oLinkedObject) != 'undefined' && oLinkedObject != null ){
                var iLength = this.links.length;
                for (var iIndex = 0; iIndex < iLength; iIndex++){
                    var oLink = this.links[iIndex];
                    if ( oLink.toobject == oLinkedObject || oLink.fromobject == oLinkedObject ){
                        this.hide( oLink );
                    }
                }
            }
            else{
                var iL = this.links.length;
                for (var iI = 0; iI < iL; iI++){
                    this.hide( this.links[iI] );
                }
            }
        },
        change: function(oLink){
            this.add(oLink);
        },
        add: function ( oLink ){
            if ( typeof(oLink) != 'undefined' && oLink != null ){
                var oLink1;
                var oLink2;
                var oLink3;
                var oLink4;
                var oLink5;
                var oSNode;
                var oCNode;
                var oENode;
                var oDesc;
                if ( typeof(oLink.linkobject1) != 'undefined' && oLink.linkobject1 != null){
                    oLink1 = oLink.linkobject1;
                    oLink2 = oLink.linkobject2;
                    oLink3 = oLink.linkobject3;
                    oLink4 = oLink.linkobject4;
                    oLink5 = oLink.linkobject5;
                    oSNode = oLink.startnode;
                    oCNode = oLink.centernode;
                    oENode = oLink.endnode;
                    oDesc = oLink.descriptionnode
                }
                else{
                    oLink1 = document.createElement('img');
                    oLink2 = document.createElement('img');
                    oLink3 = document.createElement('img');
                    oLink4 = document.createElement('img');
                    oLink5 = document.createElement('img');
                    oSNode = document.createElement('img');
                    oCNode = document.createElement('img');
                    oENode = document.createElement('img');
                    oDesc = document.createElement('div');
                    oLink1.id = 'uilink_1_' + this.count;
                    oLink2.id = 'uilink_2_' + this.count;
                    oLink3.id = 'uilink_3_' + this.count;
                    oLink4.id = 'uilink_4_' + this.count;
                    oLink5.id = 'uilink_5_' + this.count;
                    oSNode.id = 'uilink_s_' + this.count;
                    oCNode.id = 'uilink_c_' + this.count;
                    oENode.id = 'uilink_e_' + this.count;
                    oDesc.id = 'uilink_d_' + this.count;
                    oLink1.style.position = 'absolute';
                    oLink2.style.position = 'absolute';
                    oLink3.style.position = 'absolute';
                    oLink4.style.position = 'absolute';
                    oLink5.style.position = 'absolute';
                    oSNode.style.position = 'absolute';
                    oCNode.style.position = 'absolute';
                    oENode.style.position = 'absolute';
                    oDesc.className = 'linkDescription';
                    oDesc.align = 'center';
                    oDesc.style.position = 'absolute';
                    oDesc.style.width = 75;
                    oDesc.style.height = 25;
                    oLink1.border = 0;
                    oLink2.border = 0;
                    oLink3.border = 0;
                    oLink4.border = 0;
                    oLink5.border = 0;
                    oSNode.border = 0;
                    oCNode.border = 0;
                    oENode.border = 0;
                    this.count++;
                    document.body.appendChild(oLink1);
                    document.body.appendChild(oLink2);
                    document.body.appendChild(oLink3);
                    document.body.appendChild(oLink4);
                    document.body.appendChild(oLink5);
                    document.body.appendChild(oSNode);
                    document.body.appendChild(oCNode);
                    document.body.appendChild(oENode);
                    document.body.appendChild(oDesc);
                    oLink.linkobject1 = oLink1;
                    oLink.linkobject2 = oLink2;
                    oLink.linkobject3 = oLink3;
                    oLink.linkobject4 = oLink4;
                    oLink.linkobject5 = oLink5;
                    oLink.startnode = oSNode;
                    oLink.centernode = oCNode;
                    oLink.endnode = oENode;
                    oLink.descriptionnode = oDesc;
                }
                if ( oLink.startnodesrc.length > 0 ){
                    oSNode.src = oLink.startnodesrc;
                }
                if ( oLink.centernodesrc.length > 0 ){
                    oCNode.src = oLink.centernodesrc;
                }
                if ( oLink.endnodesrc.length > 0 ){
                    oENode.src = oLink.endnodesrc;
                }
                if ( oLink.description.length > 0 ){
                    oDesc.innerHTML = oLink.description;
                }
                oSNode.style.display = 'none';
                oCNode.style.display = 'none';
                oENode.style.display = 'none';
                oDesc.style.display = 'none';
                oLink1.style.backgroundColor = oLink.linkcolor;
                oLink1.style.display = 'none';
                oLink2.style.backgroundColor = oLink.linkcolor;
                oLink2.style.display = 'none';
                oLink3.style.backgroundColor = oLink.linkcolor;
                oLink3.style.display = 'none';
                oLink4.style.backgroundColor = oLink.linkcolor;
                oLink4.style.display = 'none';
                oLink5.style.backgroundColor = oLink.linkcolor;
                oLink5.style.display = 'none';
                // get fromobjects coordinates
                var iaCoordFrom = sapphire.ui.util.findElementPos( oLink.fromobject, true );
                iaCoordFrom[0] += this.fromcorrection[0];
                iaCoordFrom[1] += this.fromcorrection[1];
                var oFromWin = oLink.fromobject.document.parentWindow;
                while ( typeof( oFromWin.frameElement ) != 'undefined' && oFromWin.frameElement != null ){
                    var iaC2 = oFromWin.parent.sapphire.ui.util.findElementPos( oFromWin.frameElement );
                    iaCoordFrom[0] += iaC2[0];
                    iaCoordFrom[1] += iaC2[1];
                    oFromWin = oFromWin.parent;
                }

                var iFill = 15;
                // now ajust from object so that it goes from end
                if ( oLink.fromobject.tagName == 'INPUT' ){
                    iaCoordFrom[0] = iaCoordFrom[0] + oLink.fromobject.clientWidth;
                }
                else{
                    iaCoordFrom[0] = iaCoordFrom[0] + oLink.fromobject.style.pixelWidth;
                }
                var iLinks = this.links.length;//oLink.fromobject.links.length;
                if ( iLinks > 1 ){
                    var iTheY;
                    if ( oLink.fromobject.tagName == 'INPUT' ){
                        iTheY = ( oLink.fromobject.clientHeight / 2 ) - ((iLinks * this.offset) / 2);
                    }
                    else{
                        iTheY = ( oLink.fromobject.style.pixelHeight / 2 ) - ((iLinks * this.offset) / 2);
                    }
                    var iCount;
                    for (iCount = 0; iCount<iLinks; iCount++){
                        //if ( oLink.fromobject.links[iCount] == oLink ){
                        if ( this.links[iCount] == oLink ){
                            break;
                        }
                    }
                    var iOffSet = iCount * this.offset;
                    iFill = 15 + iOffSet;
                    iaCoordFrom[1] = iaCoordFrom[1] + iTheY + iOffSet;
                }
                else{
                    // now adjust from object so that it goes from half way down
                    if ( oLink.fromobject.tagName == 'INPUT' ){
                        iaCoordFrom[1] = iaCoordFrom[1] + ( oLink.fromobject.clientHeight / 2 );
                    }
                    else{
                        iaCoordFrom[1] = iaCoordFrom[1] + ( oLink.fromobject.style.pixelHeight / 2 );
                    }
                }

                // get toobject coord
                iLinks = this.links.length;
                var iaCoordTo = sapphire.ui.util.findElementPos( oLink.toobject );
                iaCoordTo[0] += this.tocorrection[0];
                iaCoordTo[1] += this.tocorrection[1];                
                var oToWin = oLink.toobject.document.parentWindow;
                while ( typeof( oToWin.frameElement ) != 'undefined' && oToWin.frameElement != null ){
                    var iaC2 = oToWin.parent.sapphire.ui.util.findElementPos( oToWin.frameElement );
                    iaCoordTo[0] += iaC2[0];
                    iaCoordTo[1] += iaC2[1];
                    oToWin = oToWin.parent;
                }

                if ( iLinks > 1 ){
                    var iTheY;
                    if ( oLink.fromobject.tagName == 'INPUT' ){
                        iTheY = ( oLink.toobject.clientHeight / 2 ) - ((iLinks * this.offset) / 2);
                    }
                    else{
                        iTheY = ( oLink.toobject.style.pixelHeight / 2 ) - ((iLinks * this.offset) / 2);
                    }
                    var iCount;
                    for (iCount = 0; iCount<iLinks; iCount++){
                        if ( this.links[iCount] == oLink ){
                            break;
                        }
                    }
                    var iOffSet = iCount * this.offset;
                    iFill = 15 + iOffSet;
                    iaCoordTo[1] = iaCoordTo[1] + iTheY + iOffSet;
                }
                else{
                    // now adjust from object so that it goes from half way down
                    if ( oLink.fromobject.tagName == 'INPUT' ){
                        iaCoordTo[1] = iaCoordTo[1] + ( oLink.toobject.clientHeight / 2 );
                    }
                    else{
                        iaCoordTo[1] = iaCoordTo[1] + ( oLink.toobject.style.pixelHeight / 2 );
                    }
                }

                if ( oLink.startnodesrc.length == 0){
                    oSNode = null;
                }
                if ( oLink.centernodesrc.length == 0){
                    oCNode = null;
                }
                if ( oLink.endnodesrc.length == 0){
                    oENode = null;
                }
                if ( oLink.description.length == 0){
                    oDesc = null;
                }
                this.draw( iaCoordFrom, iaCoordTo, parseInt(oLink.linkwidth), oLink1, oLink2, oLink3, oLink4, oLink5, oSNode, oCNode, oENode, oDesc, iFill );
            }
        },
        draw: function( iaCoordFrom, iaCoordTo, iLinkSize, oLinkObject1,  oLinkObject2,  oLinkObject3, oLinkObject4, oLinkObject5, oStart, oCenter, oEnd, oDescription, iFill ){
            var iCalc = 0;
            if (typeof(iFill)=='undefined'){
                iFill = 15;
            }
            if ( oStart != null ){
                oStart.style.display = 'block';
                oStart.style.left = iaCoordFrom[0];
                oStart.style.top = iaCoordFrom[1] - (oStart.height / 2) + ( iLinkSize / 2 );
            }
            if (iaCoordFrom[0] < iaCoordTo[0]){ // from infront of to
                // calc finishing x for line1 and start x for line2
                iCalc = Math.round((iaCoordFrom[0] - iaCoordTo[0]) / 2) + iaCoordTo[0];
                this.drawLine(iaCoordFrom[0], iaCoordFrom[1], iCalc, iaCoordFrom[1], iLinkSize, oLinkObject1); // draw fist horizontal line
                this.drawLine(iCalc, iaCoordTo[1], iaCoordTo[0], iaCoordTo[1], iLinkSize, oLinkObject3); // draw final horizontal line
                // draw vertical line
                if (iaCoordFrom[1] < iaCoordTo[1]){ // from is above to
                    this.drawLine(iCalc, iaCoordFrom[1], iCalc, iaCoordTo[1] + iLinkSize, iLinkSize, oLinkObject2);
                    if ( oCenter != null ){
                        oCenter.style.display = 'block';
                        oCenter.style.left = iCalc - (oCenter.width / 2) + ( iLinkSize / 2 );
                        oCenter.style.top = (((iaCoordTo[1] - iaCoordFrom[1]) / 2) + iaCoordFrom[1]) - (oCenter.height / 2);
                    }
                    if ( oDescription != null ){
                        oDescription.style.display = 'block';
                        oDescription.style.left = iCalc - (oDescription.style.pixelWidth / 2) + ( iLinkSize / 2 );
                        oDescription.style.top = (((iaCoordTo[1] - iaCoordFrom[1]) / 2) + iaCoordFrom[1]) - (oDescription.style.pixelHeight / 2);
                    }
                }
                else{ // from below to
                    this.drawLine(iCalc, iaCoordTo[1], iCalc, iaCoordFrom[1] + iLinkSize, iLinkSize, oLinkObject2);
                    if ( oCenter != null ){
                        oCenter.style.display = 'block';
                        oCenter.style.left = iCalc - (oCenter.width / 2) + ( iLinkSize / 2 );
                        oCenter.style.top = (((iaCoordFrom[1] - iaCoordTo[1]) / 2) + iaCoordTo[1]) - (oCenter.height / 2);
                    }
                    if ( oDescription != null ){
                        oDescription.style.display = 'block';
                        oDescription.style.left = iCalc - (oDescription.style.pixelWidth / 2) + ( iLinkSize / 2 );
                        oDescription.style.top = (((iaCoordFrom[1] - iaCoordTo[1]) / 2) + iaCoordTo[1]) - (oDescription.style.pixelHeight / 2);
                    }
                }
            }
            else{ // from behind to
                iCalc = Math.round((iaCoordTo[1] - iaCoordFrom[1]) / 2) + iaCoordFrom[1];
                this.drawLine(iaCoordFrom[0], iaCoordFrom[1] , iaCoordFrom[0] + iFill, iaCoordFrom[1], iLinkSize, oLinkObject1); // draw first horizontal line out
                // draw first vertical line
                if (iaCoordFrom[1] < iaCoordTo[1]){ // from is above to
                    this.drawLine(iaCoordFrom[0] + iFill, iaCoordFrom[1], iaCoordFrom[0] + iFill, iCalc + iLinkSize, iLinkSize, oLinkObject2);
                }
                else{ // from below to
                    this.drawLine(iaCoordFrom[0] + iFill, iCalc, iaCoordFrom[0] + iFill, iaCoordFrom[1] + iLinkSize, iLinkSize, oLinkObject2);
                }
                this.drawLine(iaCoordTo[0] - iFill, iCalc, iaCoordFrom[0] + iFill, iCalc, iLinkSize, oLinkObject3); // draw middle horizontal line
                if ( oCenter != null ){
                    oCenter.style.display = 'block';
                    oCenter.style.left = ((((iaCoordFrom[0] + iFill) - (iaCoordTo[0] - iFill)) / 2) + (iaCoordTo[0] - iFill)) - (oCenter.width / 2);
                    oCenter.style.top = iCalc - (oCenter.height / 2)  + ( iLinkSize / 2 );
                }
                if ( oDescription != null ){
                    oDescription.style.display = 'block';
                    oDescription.style.left = ((((iaCoordFrom[0] + iFill) - (iaCoordTo[0] - iFill)) / 2) + (iaCoordTo[0] - iFill)) - (oDescription.style.pixelWidth / 2);
                    oDescription.style.top = iCalc - (oDescription.style.pixelHeight / 2)  + ( iLinkSize / 2 );
                }
                // draw second vertical line
                if (iaCoordFrom[1] < iaCoordTo[1]){ // from is above to
                    this.drawLine(iaCoordTo[0] - iFill, iCalc, iaCoordTo[0] - iFill, iaCoordTo[1] + iLinkSize, iLinkSize, oLinkObject4);
                }
                else{ // from below to
                    this.drawLine(iaCoordTo[0] - iFill, iaCoordTo[1], iaCoordTo[0] - iFill, iCalc, iLinkSize, oLinkObject4);
                }
                this.drawLine(iaCoordTo[0] - iFill, iaCoordTo[1], iaCoordTo[0], iaCoordTo[1], iLinkSize, oLinkObject5); // draw last horizontal line in
            }
            if ( oEnd != null ){
                oEnd.style.display = 'block';
                oEnd.style.left = iaCoordTo[0] - oEnd.width;
                oEnd.style.top = iaCoordTo[1] - (oEnd.height / 2)  + ( iLinkSize / 2 );
            }
        },
        drawLine: function(iStartX, iStartY, iEndX, iEndY, iSize, oLinkObject ){
            var iLeft, iTop, iWidth, iHeight;
            if (iStartX > iEndX || iStartY > iEndY){
                return;
            }
            iLeft = iStartX;
            iTop = iStartY;
            iWidth = iEndX - iStartX;
            iHeight = iEndY - iStartY;
            if (iWidth <= 0){
                iWidth = iSize;
            }
            if (iHeight <= 0) {
                iHeight = iSize;
            }
            oLinkObject.style.left = iLeft;
            oLinkObject.style.top = iTop;
            oLinkObject.style.height = iHeight;
            oLinkObject.style.width = iWidth;
            oLinkObject.style.display = 'block';
        },
        hide: function( oLink ){
            if ( typeof(oLink) != 'undefined' && oLink != null ){
                if ( typeof(oLink.linkobject1) != 'undefined' && oLink.linkobject1 != null ){
                    oLink.linkobject1.style.display = 'none';
                    oLink.linkobject2.style.display = 'none';
                    oLink.linkobject3.style.display = 'none';
                    oLink.linkobject4.style.display = 'none';
                    oLink.linkobject5.style.display = 'none';
                    oLink.startnode.style.display = 'none';
                    oLink.centernode.style.display = 'none';
                    oLink.endnode.style.display = 'none';
                    oLink.descriptionnode.style.display = 'none';
                }
            }
        },
        remove: function( oLink ){
            if ( typeof(oLink) != 'undefined' && oLink != null ){
                for (var iIndex = 0; iIndex < this.links.length; iIndex++){
                    if ( this.links[iIndex] == oLink ){
                        this.links.splice( iIndex, 1 );
                        break;
                    }
                }
                var iLen = this.links.length
                var lFoundTo = false;
                var lFoundFrom = false;
                for (var iIndex = 0; iIndex < iLen; iIndex++){
                    var oCLink = this.links[iIndex];
                    var oTo = oCLink.toobject;
                    var oFrom = oCLink.fromobject;
                    if ( oTo == oLink.toobject ){
                        lFoundTo = true;
                    }
                    if ( oFrom == oLink.fromobject ){
                        lFoundFrom = true;
                    }
                }
                if ( !lFoundTo ){
                    oLink.toobject.linked = null;
                }
                if ( !lFoundFrom ){
                    oLink.fromobject.linked = null;        
                }

                sapphire.garbage.add( [oLink.linkobject1,oLink.linkobject2,
                    oLink.linkobject3,oLink.linkobject4,oLink.linkobject5,
                    oLink.startnode,oLink.centernode,oLink.endnode,oLink.descriptionnode] );
                oLink.fromobject = null;
                oLink.toobject = null;
                oLink.linkobject1 = null;
                oLink.linkobject2 = null;
                oLink.linkobject3 = null;
                oLink.linkobject4 = null;
                oLink.linkobject5 = null;
                oLink.startnode = null;
                oLink.centernode = null;
                oLink.endnode = null;
                oLink.descriptionnode = null;
            }
        }
    }

    this.util = {
        api_desc: 'Sapphire API for user interface utility methods.',
        getFramePath: function(oWin, lAddTop, lAddPeriod){
            var sFrame = '';
            while(oWin.frameElement != null){
                if (sFrame.length > 0){
                    sFrame = oWin.frameElement.id + '.' + sFrame;
                }
                else{
                    sFrame = oWin.frameElement.id.length > 0?oWin.frameElement.id:oWin.frameElement.name;
                }
                oWin = oWin.parent;
            }
            if (sFrame.length > 0 && lAddPeriod){
                sFrame += '.';
            }
            if (lAddTop){
                sFrame = 'top.' + sFrame;
            }
            return sFrame;
        },
        findElementPos: function( oOrgElement, lUseRect ) {
            if ( typeof( lUseRect ) == 'undefined' ){
                lUseRect = false;
            }
            var iCurtop = 0;
            var iCurleft = 0;
            if ( !lUseRect ){
                var oElement = oOrgElement;
                if (oElement.offsetParent) {
                    iCurleft = oElement.offsetLeft;
                    iCurtop = oElement.offsetTop;
                    oElement = oElement.offsetParent;
                    while ( oElement ) {
                        iCurleft += oElement.offsetLeft;
                        iCurtop += oElement.offsetTop;

                        oElement = oElement.offsetParent;
                    }
                }
            }
            else{
                var oRect = oOrgElement.getBoundingClientRect();
                iCurtop = oRect.top;
                iCurleft = oRect.left;
                var oDoc = oOrgElement.ownerDocument;
                if ( typeof( oDoc ) != 'undefined' || oDoc != null ){
                    iCurtop += oDoc.body.scrollTop;
                    iCurleft += oDoc.body.scrollLeft;
                }
                oRect = null;
            }
            return [iCurleft,iCurtop];
        },
        setCaretPos: function( oElement, iCaretPos ){
            if ( sapphire.browser.id != 'FF' ){
                oElement.focus();
                var oRange = oElement.createTextRange();
                oRange.collapse(true);
                if ( oElement.tagName.toLowerCase() == 'textarea' ){
                    var sText = oElement.innerText.substr(0, iCaretPos);
                    var iCor = 0;
                    for ( var iIndex = 0; iIndex < sText.length; iIndex++){
                        if ( sText.charCodeAt(iIndex) == 13 ){
                            iCor++;
                        }
                    }
                    iCaretPos = iCaretPos - iCor;
                }
                oRange.moveEnd('character', iCaretPos);
                oRange.moveStart('character', iCaretPos);
                oRange.select();
            }
            else{
                oElement.selectionStart = iCaretPos;
                oElement.selectionEnd = iCaretPos;
                oElement.focus();
            }
        },
        getCaretPos: function( oElement ){
            var iCaretPos = 0;
            if ( sapphire.browser.id != 'FF' ){
                oElement.focus();
                var oCurrentRange = document.selection.createRange();
                var oWorkRange = oCurrentRange.duplicate();
                if ( oElement.tagName.toLowerCase() == 'textarea' ){
                     var sInsert = '\001';
                     var iLength = 0;
                     oWorkRange.moveToElementText(oElement);
                     oCurrentRange.text	= sInsert;
                     iLength = oElement.innerText.indexOf( sInsert );
                     oCurrentRange.moveStart('character',-1);
                     oCurrentRange.text	= "";
                     iCaretPos = iLength;
                }
                else{
                    oElement.select();
                    var oAllRange = document.selection.createRange();
                    var iLength = 0;
                    while( oWorkRange.compareEndPoints( 'StartToStart', oAllRange) > 0 ) {
                        oWorkRange.moveStart( 'character', -1 );
                        iLength++;
                    }
                    oCurrentRange.select()
                    iCaretPos = iLength;
                }
            }
            else{
                iCaretPos = oElement.selectionStart;
            }
            return iCaretPos;
        },
        findCaretCoord: function (oElement){
            var iPos = this.getCaretPos( oElement );
            if ( iPos == 0 ){
                return this.findElementPos( oElement );
            }
            else{
                var oRange = oElement.createTextRange();
                var iLines = 0;
                if ( oRange.text.length != oElement.value.length && iPos > oRange.text.length ){
                    iLines = oElement.value.length - oRange.text.length;
                }
                while ( oRange.text.length > iPos ){
                    if ( oRange.moveEnd( 'character', -1 ) == 0 ){
                        break;
                    }
                }
                while ( oRange.text.length > 1 ){
                    if ( oRange.moveStart( 'character', 1 ) == 0 ){
                        break;
                    }
                }
                var iLeft;
                var iTop;
                if ( iLines > 0 ){
                    iLeft = this.findElementPos( oElement )[0];
                    iTop = oRange.offsetTop + ( 12 * (iLines / 2) );
                }
                else{
                    iLeft = oRange.offsetLeft;
                    iTop = oRange.offsetTop;
                }
                if (oElement.innerText.charCodeAt(iPos-1) == 10){
                    iTop += 12;
                }
                return [ iLeft, iTop];
            }
        },
        addCover: function( oElement, minX, minY, maxX, maxY ){
            // creates a transparent cover over element using bounds so that drag and resize work over frames
            var oCover = document.createElement('div');
            oCover.style.position = 'absolute';
            oCover.style.left = minX;
            oCover.style.top = minY;
            oCover.style.width = maxX;
            oCover.style.height = maxY;
            oCover.style.backgroundColor = '#FFFFFF';
            if (sapphire.browser.ie){
                oCover.style.filter = 'alpha(opacity=1)';
            }
            else{
                oCover.style.opacity = 0.01;
            }
            this.cover = oCover;
            oCover.id = '__uicover_' + sapphire.ajax.util.getRandomString(3);
            oCover.style.zIndex = 300;
            oElement.appendChild(oCover);
            this.cover = oCover;

            try{
                return oCover;
            }
            finally{
                oCover = null;
            }
        },
        removeCover: function(  ){
            var oCov = this.cover;
            this.cover =  null;
            sapphire.garbage.add( oCov );
        },
        cancelEvent: function(e){
            if ( this != sapphire.ui.util ){
                sapphire.ui.util.cancelEvent(e);
            }
            else{
                if ( typeof(e) == 'undefined' && typeof(event) != 'undefined'){
                    e = event;
                }
                if (typeof(e) != 'undefined'){
                    if (sapphire.browser.ie){
                        e.returnValue = false;
                    }
                    else{
                        e.preventDefault();
                    }
                }

            }
        },
        prepareFragment: function( oElement, oDoc ){
            var oFragment={
                element: null,
                docFrag: null,
                parent: null,
                bookmark: null
            }
            if (typeof(oDoc) == 'undefined'){
                oDoc = document;
            }
            oFragment.element = oElement;
            oFragment.documentFragment = oDoc.createDocumentFragment();
            oFragment.parent = oElement.parentElement;
            if ( oFragment.parent != null ){
                oFragment.bookmark = oDoc.createElement('span');
                oFragment.parent.insertBefore( oFragment.bookmark, oElement );
                oFragment.parent.removeChild(oElement);
                oFragment.documentFragment.appendChild(oElement);
            }
            return oFragment;
        },
        restoreFragment: function( oFragment ){
            oFragment.parent.insertBefore(oFragment.documentFragment,oFragment.bookmark);
            sapphire.garbage.add(oFragment.bookmark);
        }
    }

    this.tab = {
        getIndex: function(sName,sElementId){
            var lGroup = false;
            if ( typeof(maint_iframe) != 'undefined'){
                oDoc = maint_iframe.document;
            }
            else{
                oDoc = document;
            }
            if (typeof(sElementId) =='undefined'){
                sElementId = 'maintform';
            }
            var iIndex = 0;
            var oTab;
            if ( sElementId != 'maintform' ){
                oTab = oDoc.getElementById('tab_' + sElementId + '__tab');
                if ( oTab == null || typeof(oTab.currentTab) != 'undefined'){
                    oTab = oDoc.getElementById('tab_' + sElementId + '__tab' + iIndex);
                    if ( oTab == null ){
                        sElementId+='1';
                        oTab = oDoc.getElementById('tab_' + sElementId + '__tab');
                    }
                    else{
                        lGroup = true;
                    }
                }
            }
            else{
                oTab = oDoc.getElementById('tab_' + sElementId + '__tab');
            }
            while (oTab != null ){
                var sContent = oTab.innerText;
                if ( sContent == sName ){
                    return iIndex;
                }
                iIndex++;
                if (lGroup){
                    oTab = oDoc.getElementById('tab_' + sElementId + '__tab' + iIndex);
                }
                else{
                    oTab = oDoc.getElementById('tab_' + sElementId + iIndex + '__tab');
                }
            }
            return  -1;
        },
        getTab: function(iIndex, sElementId){
            if ( iIndex > -1 ){
                if ( typeof(maint_iframe) != 'undefined'){
                    oDoc = maint_iframe.document;
                }
                else{
                    oDoc = document;
                }
                if (typeof(sElementId) =='undefined'){
                    sElementId = 'maintform';
                }
                var oTab;
                if ( sElementId != 'maintform' ){
                    if ( iIndex == 0 ){
                        oTab = oDoc.getElementById('tab_' + sElementId + '__tab');
                    }
                    else{
                        oTab = oDoc.getElementById('tab_' + sElementId + iIndex + '__tab');
                    }
                    if ( oTab == null || typeof(oTab.currentTab) != 'undefined' ){
                        oTab = oDoc.getElementById('tab_' + sElementId + '__tab' + iIndex);
                        if ( oTab == null ){
                            sElementId+='1';
                            if ( iIndex == 0 ){
                                oTab = oDoc.getElementById('tab_' + sElementId + '__tab');
                            }
                            else{
                                oTab = oDoc.getElementById('tab_' + sElementId + iIndex + '__tab');
                            }
                        }
                    }
                }
                else{
                    if ( iIndex == 0 ){
                        oTab = oDoc.getElementById('tab_' + sElementId + '__tab');
                    }
                    else{
                        oTab = oDoc.getElementById('tab_' + sElementId + iIndex + '__tab');
                    }
                }
            }
            else{
                oTab = null;
            }
            return oTab;
        },
        hide: function(iIndex, sElementId){
            var oTab = this.getTab(iIndex,sElementId);
            if ( oTab != null ){
                var oTable = oTab.parentElement.parentElement.parentElement;
                var oCell = oTable.parentElement;
                oTable.style.display='none';
                oCell.style.width = '0px';
            }
        },
        show: function(iIndex,sElementId){
            var oTab = this.getTab(iIndex,sElementId);
            if ( oTab != null ){
                var oTable = oTab.parentElement.parentElement.parentElement;
                var oCell = oTable.parentElement;
                oTable.style.display='block';
                oCell.style.width = '';
            }
        },
        click: function(iIndex,sElementId){
            var oTab = this.getTab(iIndex,sElementId);
            if ( oTab != null ){
                oTab.click();
            }
        }
    }

    
    var oDoc = window.document;
    // register required events
    if ( top.window == window ){
        sapphire.events.attachEvent( oDoc, 'mousemove', this.dragdrop.doDragMM );
        sapphire.events.attachEvent( oDoc, 'mouseup', this.dragdrop.doDragEnd );
        if (sapphire.browser.mozilla){
            sapphire.events.attachEvent( oDoc, 'mouseup', this.dragdrop.doMUp );
            sapphire.events.attachEvent( oDoc, 'mousedown', this.dragdrop.doMDown );
        }
    }
    else if (typeof(window.frameElement.id) != 'undefined' ){
        // To use drag drop or resize over a non-sapphire frame the frame will either need to include sapphireui.js or
        // instantiate the events below:
		if ( top.sapphire != null ) {
            sapphire.events.attachEvent( oDoc, 'mousemove', new Function('top.sapphire.ui.dragdrop.doMMFrame( \'' + window.frameElement.id + '\', arguments[0] )') );
            sapphire.events.attachEvent( oDoc, 'mouseup', new Function('top.sapphire.ui.dragdrop.doMUFrame( \'' + window.frameElement.id + '\', arguments[0] )') );
		}
	}
    oDoc = null;


}

