// global variables
var curObj			= null;
var wasAnyReportLoaded = false;

//
// ---------------------------------------------------------------------------------------------------
//

function expand_collapseNode(theObj)
{
	var Identifier					= theObj.id;
    var Table                       = document.getElementsByTagName("tr");
    var startExpand					= false;
    var startDepth;
    
    for (var i = 0; i < Table.length; i++)
    {
            if (Table[i].id == Identifier)
            {
				startExpand = true;
				startDepth	= parseInt(Table[i].getAttribute("depth"));
			}
			else if (startExpand)
			{
				if (parseInt(Table[i].getAttribute("depth")) <= startDepth )
					break;
				if (parseInt(Table[i].getAttribute("depth")) == startDepth + 1 &&
					Table[i].style.display == "none")
					Table[i].style.display = "";
				else if (Table[i].style.display == "")
					Table[i].style.display = "none";
            }
    }
    return;
}

//
// ---------------------------------------------------------------------------------------------------
//

function enterTableRow( theObj )
{
	lastObj = theObj;
	if ( theObj != curObj )
		theObj.style.color="darkblue"; 
	else
		theObj.style.color="darkred";
	theObj.style.fontWeight="bold";
}

//
// ---------------------------------------------------------------------------------------------------
//

function leaveTableRow( theObj )
{
	if ( theObj != curObj )
		theObj.style.color="black"
	else
		theObj.style.color="darkred";
	theObj.style.fontWeight="normal";
}

//
// ---------------------------------------------------------------------------------------------------
//

//empty.aspx:
function doRestart()
{
	try
	{
        // HoW, 19.02.2008: Write Back Improvements
	    var haveToCheck = false;
	    try {
	        haveToCheck = this.parent.reportFrame.checkWriteBack();
	    } catch ( ex ) {}
	    
        if (haveToCheck) {
            // set parameter
            theCurrentUserAction = "Restart";
            
            // ask for write back
            this.parent.reportFrame.askForWriteBack();
            
        } else {
            // everything is ok, just execute "restart"
		    if (this.parent.frames.length == 0)
			    return;
			    
		    if (this.parent.reportFrame != null) { 
		        this.parent.location.replace("default.aspx");
		    }
		    
        }
	}
	catch(e)
	{}
}

function continueRestart()
{
    if (this.parent.frames.length == 0) {
        // do nothing
	} else {
	    if (this.parent.reportFrame != null)
	    {
		    // rka: SessionTimeout: refresh whole frameset
		    this.parent.location.replace(getURL_Root()+"default.aspx");
	    }
    }
    
    resetMessageBoxDialogVariables();
}

//
// ---------------------------------------------------------------------------------------------------
//

//titlebar.aspx:
// HoW, 08.04.08: [GBUR-7DGJ67] runtime error when clicking "export to excel" while pdf doc is open
// and [RKAG-7DGHZ4] Back - Button in Titlebar has wrong link!
function disableButtons() {
                    
    disableButton("WRITE");
    disableButton("REFRESH");
    disableButton("ADHOC");
    disableButton("EXCEL");
    disableButton("PDF");
    disableButton("FOLDERPRINT");
    disableButton("SETTINGS");
    disableButton("SETTINGSWITHMENU");
}

function enableButtons()
{
    // enabling report independent buttons
	if ( blnCanEnableFolderPrintButton ) {
	    enableButton("FOLDERPRINT");
	}
    enableButton("SETTINGSWITHMENU");
    enableButton("SETTINGS");
    
    if ( this.parent.reportFrame != null ) {
        if ( !this.parent.reportFrame.g_ReportGuid || this.parent.reportFrame.g_ReportGuid == null || this.parent.reportFrame.g_ReportGuid.length == 0 ) {
            disableButton("WRITE");
            disableButton("EXCEL");
            disableButton("PDF");
        }
    }
    
}
	
//
// ---------------------------------------------------------------------------------------------------
//

function disableButton(ctrlName) {
    // get the button object
    var button = document.getElementById("IB_" + ctrlName);
    if (button) {
        // change the image
        button.src = getDisabledSrcName(ctrlName);
        if ( (ctrlName == "PDF" && !blnCanEnablePDFButton) || (ctrlName == "FOLDERPRINT" && !blnCanEnableFolderPrintButton) ) {
        } else {
            button.title = "";
        }
        
        button.disabled = true;
		if (navigator.userAgent.indexOf("MSIE") > -1 && navigator.userAgent.indexOf("5.5") > -1)
			button.style.setAttribute("cursor", "default");
		else
			button.style.cursor = "default";
        
        // enable the hyperlink
        var hyperlink = document.getElementById("HY_" + ctrlName);
        if (hyperlink) {
            hyperlink.disabled = true;
			hyperlink.title = button.title;
			hyperlink.className = "hyperlinksDisabled";
			
		    if (navigator.userAgent.indexOf("MSIE") > -1 && navigator.userAgent.indexOf("5.5") > -1)
			    hyperlink.style.setAttribute("cursor", "default");
		    else
			    hyperlink.style.cursor = "default";
        }
        
        var dummybutton = document.getElementById("DB_" + ctrlName);
        if (dummybutton) {
            dummybutton.disabled = true;
			dummybutton.title = button.title;
			dummybutton.className = "hyperlinksDisabled";
			
		    if (navigator.userAgent.indexOf("MSIE") > -1 && navigator.userAgent.indexOf("5.5") > -1)
			    dummybutton.style.setAttribute("cursor", "default");
		    else
			    dummybutton.style.cursor = "default";
        }
        
        /*
        // set the onmouseover and onmouseout event of the corresponding table row
        var table = button;
        while ( table.tagName.toLowerCase() != "table" )
        {
            table = table.parentNode;
        }
        table.onmouseover = "this.className='tableRowNormal';";
        table.onmouseout = "this.className='tableRowNormal';";
        */
    }
}

function getDisabledSrcName(ctrlName) {
    if (ctrlName.toLowerCase() == "back")
        return getURL_Root()+"img/btn_back16x16_disabled.gif";
    
    if (ctrlName.toLowerCase() == "refresh")
        return getURL_Root()+"img/btn_refresh16x16_disabled.gif";
    
    if (ctrlName.toLowerCase() == "write")
        return getURL_Root()+"img/btn_save16x16_disabled.gif";
    
    if (ctrlName.toLowerCase() == "excel")
        return getURL_Root()+"img/btn_export_excel16x16_disabled.gif";
    
    if (ctrlName.toLowerCase() == "pdf")
        return getURL_Root()+"img/btn_export_pdf16x16_disabled.gif";
    
    // HoW, 08.04.08: [GBUR-7DGJ67] runtime error when clicking "export to excel" while pdf doc is open
    // and [RKAG-7DGHZ4] Back - Button in Titlebar has wrong link!
    if (ctrlName.toLowerCase() == "folderprint")
        return getURL_Root()+"img/btn_print16x16_disabled.gif";
    
    if (ctrlName.toLowerCase() == "settingswithmenu")
        return getURL_Root()+"img/btn_settingswithmenu28x16_disabled.gif";
    
    if (ctrlName.toLowerCase() == "settings")
        return getURL_Root()+"img/btn_settings16x16_disabled.gif";
}

/*
function setMouseOverEvent(row){
	try {
	    row.style.backgroundColor="#9EB1BE";
	    row.style.color="#555555";
	} catch (ex) {}
}

function setMouseOutEvent(row){
	try {
	    row.style.backgroundColor="Transparent";
	    row.style.color="Black";
	} catch (ex) {}
}
*/

//
// ---------------------------------------------------------------------------------------------------
//

function enableButton(ctrlName) {
    // get the button object
    var button = document.getElementById("IB_" + ctrlName);
    if (button) {
        // change the image
        button.src = getEnabledSrcName(ctrlName);
        button.title = button.getAttribute("CustomToolTip");
        
        button.disabled = false;
		if (navigator.userAgent.indexOf("MSIE") > -1 && navigator.userAgent.indexOf("5.5") > -1)
			button.style.setAttribute("cursor", "hand");
		else
			button.style.cursor = "pointer";
        
        // enable the hyperlink
        var hyperlink = document.getElementById("HY_" + ctrlName);
        if (hyperlink) {
            hyperlink.disabled = false;
			hyperlink.title = button.title;
			hyperlink.className = "hyperlinks";
		    
		    if (navigator.userAgent.indexOf("MSIE") > -1 && navigator.userAgent.indexOf("5.5") > -1)
			    hyperlink.style.setAttribute("cursor", "hand");
		    else
			    hyperlink.style.cursor = "pointer";
			    
			button.onclick = hyperlink.onclick;
        }
        
        var dummybutton = document.getElementById("DB_" + ctrlName);
        if (dummybutton) {
            dummybutton.disabled = false;
			dummybutton.title = button.title;
			dummybutton.className = "hyperlinks";
		    
		    if (navigator.userAgent.indexOf("MSIE") > -1 && navigator.userAgent.indexOf("5.5") > -1)
			    dummybutton.style.setAttribute("cursor", "hand");
		    else
			    dummybutton.style.cursor = "pointer";
			    
			dummybutton.onclick = hyperlink.onclick;
        }
        
        /*
        // set the onmouseover and onmouseout event of the corresponding table row
        var table = button;
        while ( table.tagName.toLowerCase() != "table" )
        {
            table = table.parentNode;
        }
        table.onmouseover = "this.className='tableRowHighlight';";
        table.onmouseout = "this.className='tableRowNormal';";
        */
    }
}

function getEnabledSrcName(ctrlName) {
    if (ctrlName.toLowerCase() == "back")
        return getURL_Root()+"img/btn_back16x16_enabled.gif";
    
    if (ctrlName.toLowerCase() == "refresh")
        return getURL_Root()+"img/btn_refresh16x16_enabled.gif";
    
    if (ctrlName.toLowerCase() == "write")
        return getURL_Root()+"img/btn_save16x16_enabled.gif";
    
    if (ctrlName.toLowerCase() == "excel")
        return getURL_Root()+"img/btn_export_excel16x16_enabled.gif";
    
    if (ctrlName.toLowerCase() == "pdf")
        return getURL_Root()+"img/btn_export_pdf16x16_enabled.gif";
    
    if (ctrlName.toLowerCase() == "folderprint")
        return getURL_Root()+"img/btn_print16x16.gif";
    
    if (ctrlName.toLowerCase() == "settingswithmenu")
        return getURL_Root()+"img/btn_settingswithmenu28x16.gif";
    
    if (ctrlName.toLowerCase() == "settings")
        return getURL_Root()+"img/btn_settings16x16.gif";
}

function getOnClickFunctionName(ctrlName) {
    if (ctrlName.toLowerCase() == "back")
        return "goBack();";
    
    if (ctrlName.toLowerCase() == "refresh")
        return "updateSelections();";
    
    if (ctrlName.toLowerCase() == "write")
        return "doWriteBack();";
    
    if (ctrlName.toLowerCase() == "excel")
        return "exportToExcel();";
    
    if (ctrlName.toLowerCase() == "pdf")
        return "loadPDF();";
    
    // HoW, 16.04.08: [WSCS-7DKJTW] Batch Print Improvements: Print folder action always opens the select folder dialogue
    // HoW, 24.04.08: [WSCS-7DYFKY] Batch Print Improvements: No pdf file is created when action is set to "Don't show print settings"
    if (ctrlName.toLowerCase() == "folderprint")
        return "printFolder(null, true);";
}

//
// ---------------------------------------------------------------------------------------------------
//

function isReportLoaded()
{
	try {
		if (this.parent.reportFrame != null &&
			this.parent.reportFrame.document.URL.indexOf("report.html") != -1) {
			
			return true;
		
		} else {

			return false;
		}
	}
	catch ( ex ) {
		return false;
	}
}

//
// ---------------------------------------------------------------------------------------------------
//

function isPasswordChangeControlLoaded()
{

	if (this.parent.reportFrame != null ) {
		if ( this.parent.reportFrame.document.URL.indexOf("empty.aspx?changePassword") != -1 ||
			 this.parent.reportFrame.document.URL.indexOf("empty.aspx?changeAliasPasswords") != -1 ) {
		
			return true;
	
		} else {

			return !isReportLoaded();
		}
	} else {
	
		return false;
	}
}

//
// ---------------------------------------------------------------------------------------------------
//

function doWriteBack()
{
	//debugger;
	// -- testing writeback behavior-- please enable in testcases!
	/*if ( !theObj ) { var tmpString2 = ""; var coll = document.all.tags("TEXTAREA");
		if (coll!=null)	{ for (ii=0; ii<coll.length; ii++) { if ( coll[ii].name ) { if ( coll[ii].name.indexOf("e_grd_") > -1 ) {
						tmpString2 += coll[ii].name + " : " + coll[ii].value + " ;\n";	}}}}	alert ( tmpString2 );	return;	}
	*/

    hideMenus();
	try {
		this.parent.reportFrame.enableConfirmExit = false;
	
        var button = document.getElementById("IB_WRITE");
        if (button) {
            if (button.src.indexOf("btn_save16x16_enabled") > -1 && this.parent.reportFrame != null) {
            	saveScrollPosition();
    			this.parent.reportFrame.submitForm();
            }
        }
	} catch (ex) {}

}
function doWriteBackHidden(theObj)
{
	//debugger;
	// -- testing writeback behavior-- please enable in testcases!
	/*if ( !theObj ) { var tmpString2 = ""; var coll = document.all.tags("TEXTAREA");
		if (coll!=null)	{ for (ii=0; ii<coll.length; ii++) { if ( coll[ii].name ) { if ( coll[ii].name.indexOf("e_grd_") > -1 ) {
						tmpString2 += coll[ii].name + " : " + coll[ii].value + " ;\n";	}}}}	alert ( tmpString2 );	return;	}
	*/

	try {
		this.parent.reportFrame.enableConfirmExit = false;
		
        var button = document.getElementById("IB_WRITE");
        if (button) {
            if (button.src.indexOf("btn_save16x16_enabled") > -1 && this.parent.reportFrame != null) {
                saveScrollPosition();

                this.parent.reportFrame.document.forms[0].target = "historyFrame";
                this.parent.reportFrame.submitForm(); 
            }
        }
		return; 
	
	} catch (ex) {}

}

// TRAH-77SFCK  When using the writeback via html the scroll position is lost
function saveScrollPosition()
{
		if ( this.parent.reportFrame != null) {
            	// rka keepScrollPosition, only in drilldown
    	        this.parent.crScrollTop = this.parent.reportFrame.document.getElementById('report').scrollTop;
	            this.parent.crScrollLeft = this.parent.reportFrame.document.getElementById('report').scrollLeft;
	            this.parent.crReportGuid = this.parent.reportFrame.g_ReportGuid;
        }
}
//
// ---------------------------------------------------------------------------------------------------
//

function updateSelections()
{
    hideMenus();
    var button = document.getElementById("IB_REFRESH");
    if (button) {
        if (button.src.indexOf("btn_refresh16x16_enabled") > -1 && this.parent.reportFrame != null) {
		    this.parent.reportFrame.update();
        }
    }
}

//
// ---------------------------------------------------------------------------------------------------
//

function exportToExcel()
{
    // wrapper
    hideMenus();
    
    // HoW, 08.04.08: [GBUR-7DGJ67] runtime error when clicking "export to excel" while pdf doc is open
    // and [RKAG-7DGHZ4] Back - Button in Titlebar has wrong link!
    var button = document.getElementById("IB_EXCEL");
    if (button) {
        if (button.src.indexOf("btn_export_excel16x16_enabled") > -1 && this.parent.reportFrame != null) {
            if (  this.parent.reportFrame.location.href.indexOf("/temp/") > -1)
	            this.parent.reportFrame.exportToExcel();
        }
    }
}

//
// ---------------------------------------------------------------------------------------------------
//

// HoW, 16.04.08: [WSCS-7DKJTW] Batch Print Improvements: Print folder action always opens the select folder dialogue
// HoW, 24.04.08: [WSCS-7DYFKY] Batch Print Improvements: No pdf file is created when action is set to "Don't show print settings"
function printFolder(folderId, showWizard)
{
    hideMenus();
    var button = document.getElementById("IB_FOLDERPRINT");
    if (button) {
        // HoW, 08.04.08: [GBUR-7DGJ67] runtime error when clicking "export to excel" while pdf doc is open
        // and [RKAG-7DGHZ4] Back - Button in Titlebar has wrong link!
        if (button.src.indexOf("btn_print16x16_disabled") == -1 && this.parent.reportFrame != null) {
        
            // HoW, 16.04.08: [WSCS-7DKJTW] Batch Print Improvements: Print folder action always opens the select folder dialogue
            if (folderId == null || folderId == '') { 
                var QueryString = encodeURI(getURL_Root()+"Forms/BatchPrintingDialog.aspx?NoFolderGuid=true");
            } else {
                // HoW, 24.04.08: [WSCS-7DYFKY] Batch Print Improvements: No pdf file is created when action is set to "Don't show print settings"
                if (showWizard) {
                    var QueryString = encodeURI(getURL_Root()+"Forms/BatchPrintingDialog.aspx?FolderGuid=") + folderId + "&ShowWizard=true";
                } else {
                    var QueryString = encodeURI(getURL_Root()+"Forms/BatchPrintingDialog.aspx?FolderGuid=") + folderId + "&ShowWizard=false";
                }
            }
            
            //// HoW, 24.06.08: [MART-7F5BR8] selectmember<->membercname: disabling report tree
            //this.parent.reportFrame.showContainer();
            
            var sCaption = "Folder Print Wizard";
            if ( window.showModalDialog )
            {
                if ( navigator.appVersion.indexOf("MSIE 6.0") > 0 || navigator.appVersion.indexOf("MSIE 5.5") > 0) {
                    // HoW, altered dialogHeight + 20, because of [VLAA-72NFXT]
                    var Settings = "dialogWidth:606px;dialogHeight:466px;center:yes;status:no;resizable:no;help:no";
                } else {
                    // HoW, because of [YHAD-6YVM9Z] dialogWidth in IE7 can be reduced again
                    var Settings = "dialogWidth:606px;dialogHeight:440px;center:yes;status:no;resizable:no;help:no";
                }
    		    
	            var ret = window.showModalDialog(QueryString, sCaption, Settings );
	            
                //// HoW, 24.06.08: [MART-7F5BR8] selectmember<->membercname: disabling report tree
                //this.parent.reportFrame.hideContainer();
	            
    		    //ret =0:  ok
    		    //ret =-1: already opened dialog
    		    //ret =1:  timeout, error;
	            // The status of the folderprint must be reset
	            if ( ret >= 0 )
	                ovAjaxRequest(getURL_Root()+"forms/BatchPrintingDialog.aspx?doTidy=true&timestamp=" + getTimeStamp());    		    
    		    
	            if (ret  == 3 ) {
		            // session timeout: do logout!
		            //debugger;
		            doLogout();
		            return;
	            }
    		    
            }
            else
            {
		        var posLeft = window.screenX + ((window.outerWidth - 600) / 2);
		        var posTop = window.screenY + 150; //(screen.availHeight - 446) / 2;
                if (posTop > window.screenY + 446) posTop = window.screenY;

    	        winModalWindow = window.open( QueryString, sCaption,
						"dependent=yes,modal=yes,width=600,height=446,left=" + posLeft + ",top=" + posTop + ",status=no,resizable=no,help=no" );
                
	            winModalWindow.focus();
	            setTimeout("_doPostBackPrintFolderFF();", 100);
            }
        }
    }    
}

function printFolderFromReport(folderId, showWizard)
{
    hideMenus();
        
    // HoW, 16.04.08: [WSCS-7DKJTW] Batch Print Improvements: Print folder action always opens the select folder dialogue
    if (folderId == null || folderId == '') { 
        var QueryString = encodeURI(getURL_Root()+"Forms/BatchPrintingDialog.aspx?NoFolderGuid=true");
    } else {
        // HoW, 24.04.08: [WSCS-7DYFKY] Batch Print Improvements: No pdf file is created when action is set to "Don't show print settings"
        if (showWizard) {
            var QueryString = encodeURI(getURL_Root()+"Forms/BatchPrintingDialog.aspx?FolderGuid=") + folderId + "&ShowWizard=true";
        } else {
            var QueryString = encodeURI(getURL_Root()+"Forms/BatchPrintingDialog.aspx?FolderGuid=") + folderId + "&ShowWizard=false";
        }
    }
            
    var sCaption = "Folder Print Wizard";
    if ( window.showModalDialog )
    {
        if ( navigator.appVersion.indexOf("MSIE 6.0") > 0 || navigator.appVersion.indexOf("MSIE 5.5") > 0) {
            // HoW, altered dialogHeight + 20, because of [VLAA-72NFXT]
            var Settings = "dialogWidth:606px;dialogHeight:466px;center:yes;status:no;resizable:no;help:no";
        } else {
            // HoW, because of [YHAD-6YVM9Z] dialogWidth in IE7 can be reduced again
            var Settings = "dialogWidth:606px;dialogHeight:440px;center:yes;status:no;resizable:no;help:no";
        }
	    
        var ret = window.showModalDialog(QueryString, sCaption, Settings );

	    //ret =0:  ok
	    //ret =-1: already opened dialog
	    //ret =1:  timeout, error;
        // The status of the folderprint must be reset
        if ( ret >= 0 )
            ovAjaxRequest(getURL_Root()+"forms/BatchPrintingDialog.aspx?doTidy=true&timestamp=" + getTimeStamp());    		    
	    
	    // HoW, 28.01.09: [HWAR-7NQCUJ] Clicking Cancel button while FolderPrint is interpreted as session timeout
        if ( ret == 3 ) {
            // session timeout: do logout!
            doLogout();
            return;
        }
	    
    }
    else
    {
        var posLeft = window.screenX + ((window.outerWidth - 600) / 2);
        var posTop = window.screenY + 150; //(screen.availHeight - 446) / 2;
        if (posTop > window.screenY + 446) posTop = window.screenY;

        winModalWindow = window.open( QueryString, sCaption,
				"dependent=yes,modal=yes,width=600,height=446,left=" + posLeft + ",top=" + posTop + ",status=no,resizable=no,help=no" );
        
        winModalWindow.focus();
        setTimeout("_doPostBackPrintFolderFF();", 100);
    }
}

function _doPostBackPrintFolderFF()
{
    // only netscape, ff
    if ( winModalWindow.name == null ){
        //// HoW, 24.06.08: [MART-7F5BR8] selectmember<->membercname: disabling report tree
        //this.parent.reportFrame.hideContainer();
        ovAjaxRequest("./forms/BatchPrintingDialog.aspx?doTidy=true&timestamp=" + getTimeStamp()); 
    } else {
        // wait again
        setTimeout("_doPostBackPrintFolderFF();", 250);
    }
}

//
// ---------------------------------------------------------------------------------------------------
//

function loadPDF()
{
	try {
	
        hideMenus();
	    var g_Inst = "&InstanceId=1";
	    if ( parent.g_InstanceId )
            g_Inst = "&InstanceId="+parent.g_InstanceId;
        var g_ReportGUID = "&ReportGUID=" + this.parent.reportFrame.g_ReportGuid;
	
        var button = document.getElementById("IB_PDF");
        if (button) {
            if (button.src.indexOf("btn_export_pdf16x16_enabled") > -1 && this.parent.reportFrame != null) {

                // HoW, 18.02.2008: Write Back Improvements
                if (this.parent.reportFrame.checkWriteBack()) {
                    this.parent.reportFrame.enableConfirmExit = false;
                    
                    // set parameter
                    theCurrentUserAction = "LoadPDF";
                    
                    // ask for write back
                    this.parent.reportFrame.askForWriteBack();
                } else {
                    // everything is ok, just execute "loadPDF"
                    location.replace("titlebar.aspx?loadPDF=true" + g_Inst + g_ReportGUID);
                }
            }
		}
	} catch (ex) {}

}		

function loadPDFFromReport()
{
	try {
	
        hideMenus();
	
        if (this.parent.reportFrame != null) {
            
            var g_Inst = "&InstanceId=1";
            if ( parent.g_InstanceId )
                g_Inst = "&InstanceId="+parent.g_InstanceId;
            var g_ReportGUID = "&ReportGUID=" + this.parent.reportFrame.g_ReportGuid;

            // HoW, 18.02.2008: Write Back Improvements
            if (this.parent.reportFrame.checkWriteBack()) {
                this.parent.reportFrame.enableConfirmExit = false;
                
                // set parameter
                theCurrentUserAction = "LoadPDF";
                
                // ask for write back
                this.parent.reportFrame.askForWriteBack();
            } else {
                // everything is ok, just execute "loadPDF"
                location.replace(getURL_Root() + "titlebar.aspx?loadPDF=true" + g_Inst + g_ReportGUID);
            }
        }
        
	} catch (ex) {}

}		

function continueLoadPDF()
{
    var g_Inst = "&InstanceId=1";
    if ( parent.g_InstanceId )
        g_Inst = "&InstanceId="+parent.g_InstanceId;
    var g_ReportGUID = "&ReportGUID=" + this.parent.reportFrame.g_ReportGuid;

    location.replace(getURL_Root()+"titlebar.aspx?loadPDF=true" + g_Inst + g_ReportGUID);
    resetMessageBoxDialogVariables();
}

//
// ---------------------------------------------------------------------------------------------------
//

function changePW(menuClicked)
{
    hideMenus();
    
    var button = document.getElementById("IB_SETTINGS");
    var button2 = document.getElementById("IB_SETTINGSWITHMENU");
    
    if (button || button2) {
        var flag = true;
        try {
            if ( button.src.indexOf("btn_settings16x16_disabled.gif") > -1 || menuClicked )
                flag = false;
        } catch ( ex ) {}
        
        if ( flag && this.parent.reportFrame != null) {
            this.parent.reportFrame.enableConfirmExit = false;
            // necessary if this is called when the change alias passwords dialog is currently shown
            var haveToCheck = false;
            try {
                haveToCheck = this.parent.reportFrame.checkWriteBack();
            } catch ( ex ) {}
            	
            // HoW, 19.02.2008: Write Back Improvements
            if (haveToCheck) {
                // set parameter
                theCurrentUserAction = "ChangePassword";
                
                // ask for write back
                this.parent.reportFrame.askForWriteBack();
            } else {
                // everything is ok, just execute "changePassword"
                this.parent.reportFrame.location.href = getURL_Root()+"empty.aspx?changePassword=true";
                
                if (wasAnyReportLoaded) {
                    enableButton("BACK");
                }
                
                // HoW, 12.10.06: [KUJI-6UEB7F] Remove Adhoc services
                enableButton("ADHOC");
        		
                disableButton("PDF");
                disableButton("EXCEL");
                disableButton("WRITE");
                disableButton("REFRESH");
            }
        }
    }
}

function continueChangePassword()
{
    this.parent.reportFrame.location.href = getURL_Root()+"empty.aspx?changePassword=true";
    enableButton("BACK");
    
    // HoW, 12.10.06: [KUJI-6UEB7F] Remove Adhoc services
    enableButton("ADHOC");
	
    disableButton("PDF");
    disableButton("EXCEL");
    disableButton("WRITE");
    disableButton("REFRESH");
    
    resetMessageBoxDialogVariables();
}

//
// ---------------------------------------------------------------------------------------------------
//

var count = 0;
function changeAliasPasswords(menuClicked)
{
    hideMenus();
    
    var button = document.getElementById("IB_SETTINGS");
    var button2 = document.getElementById("IB_SETTINGSWITHMENU");
    
    if (button || button2) {
        var flag = true;
        try {
            if ( button.src.indexOf("btn_settings16x16_disabled.gif") > -1 || menuClicked )
                flag = false;
        } catch ( ex ) {}
        
        if ( flag && this.parent.reportFrame != null) {
	        this.parent.reportFrame.enableConfirmExit = false;
	        // necessary if this is called when the change password dialog is currently shown
	        var haveToCheck = false;
	        try {
	            haveToCheck = this.parent.reportFrame.checkWriteBack();
	        } catch ( ex ) {}
            	
            // HoW, 19.02.2008: Write Back Improvements
            if (haveToCheck) {
                // set parameter
                theCurrentUserAction = "ChangeAliasPasswords";
                
                // ask for write back
                this.parent.reportFrame.askForWriteBack();
            } else {
                // everything is ok, just execute "changeAliasPasswords"
                count++;
                this.parent.reportFrame.location.href = getURL_Root()+"empty.aspx?changeAliasPasswords=" + count;

                if (wasAnyReportLoaded) {
	                enableButton("BACK");
	            }
                
                // HoW, 12.10.06: [KUJI-6UEB7F] Remove Adhoc services
	            enableButton("ADHOC");
        		
	            disableButton("PDF");
	            disableButton("EXCEL");
	            disableButton("WRITE");
	            disableButton("REFRESH");
            }
        }
    }
}

function continueChangeAliasPasswords()
{
    count++;
    this.parent.reportFrame.location.href = getURL_Root()+"empty.aspx?changeAliasPasswords=" + count;
    enableButton("BACK");
    
    // HoW, 12.10.06: [KUJI-6UEB7F] Remove Adhoc services
    enableButton("ADHOC");
	
    disableButton("PDF");
    disableButton("EXCEL");
    disableButton("WRITE");
    disableButton("REFRESH");
    
    resetMessageBoxDialogVariables();
}

//
// ---------------------------------------------------------------------------------------------------
//

// HoW, 12.10.06: [KUJI-6UEB7F] Remove Adhoc services
function loadAdhocBrowser()
{
	if (adhocBrowserURL != null && adhocBrowserURL != '' &&
		targetWindow != null)
	{
		targetWindow = targetWindow.toLowerCase();
		if (targetWindow.indexOf(this.parent.reportFrame.name.toLowerCase()) == 0 &&
			this.parent.reportFrame.name.toLowerCase().indexOf(targetWindow) == 0)
		{
            // HoW, 19.02.2008: Write Back Improvements
            if (haveToCheck) {
                // set parameter
                theCurrentUserAction = "LoadAdhocBrowser";
                
                // ask for write back
                this.parent.reportFrame.askForWriteBack();
            } else {
			    this.parent.reportFrame.location.href = adhocBrowserURL;
		        enableButton("BACK");
		        disableButton("PDF");
		        //disableButton("folderprintenabled");
                disableButton("EXCEL");
		        disableButton("WRITE");
		        disableButton("REFRESH");
		        disableButton("adhoc");
            }
		
		}
		else
		{		
		    //rka: new 'Own' Window, set focus..
		    ret = window.open(adhocBrowserURL, targetWindow);
			ret.focus();
		
		}
		
	}
}

function continueLoadAdhocBrowser()
{
    this.parent.reportFrame.location.href = adhocBrowserURL;
    enableButton("BACK");
    disableButton("PDF");
    disableButton("EXCEL");
    disableButton("WRITE");
    disableButton("REFRESH");
    disableButton("adhoc");
}


//
// ---------------------------------------------------------------------------------------------------
//

function goBack()
{
    hideMenus();
    var button = document.getElementById("IB_BACK");
    if (button) {
        if (button.src.indexOf("btn_back16x16_enabled") > -1 ) {
		    if ( this.parent.curReportHref ) {
			    if ( isReportLoaded() == false ) {
				    this.parent.reportFrame.location.replace( this.parent.curReportHref );
				    // HoW, 24.06.08: [FAHD-7FSK3S] Cancel button in Change Password and Database Alias pages
				    try {
				        hideContainerBackground();
				    } catch (ex) {}
				}
		    }

		    disableButton("WRITE");
		    disableButton("REFRESH");
        }
    }
}

//
// ---------------------------------------------------------------------------------------------------
//

function doLogout()
{
	try
	{
        // HoW, 19.02.2008: Write Back Improvements
        hideMenus();
        if (this.parent.reportFrame.location.href.indexOf('?showEmpty')<0 && this.parent.reportFrame.checkWriteBack()) {
            this.parent.reportFrame.enableConfirmExit = false;
            // set parameter
            theCurrentUserAction = "LogOut";
            
            // ask for write back
            this.parent.reportFrame.askForWriteBack();
            return;
        } 
	}
	catch(e)
	{}

	try
	{
        // everything is ok, just execute "logout"
	    if (this.parent.frames.length == 0)
		    return;
		    
	    // get the abs. directory for this applicatiaon  
	    var pathName = ".";
	    if ( this.location.pathname ) {
	        var idx = this.location.pathname.lastIndexOf("/");
	        pathName = this.location.pathname.substr(0, idx);
	    }
	    
	    ovAjaxRequest(pathName+"/empty.aspx?doLogout=true&timestamp=" + getTimeStamp());
	    this.parent.location.href = pathName+"/default.aspx";
	}
	catch(e)
	{}

}

function continueLogout()
{
    if (this.parent.frames.length == 0) {
		// do nothing
	} else {
	    // call logout with 
	    ovAjaxRequest(getURL_Root()+"empty.aspx?doLogout=true&timestamp=" + getTimeStamp());
	    // HoW, 09.06.08: [JSCL-7FCHMS] log off without writeback of changed data 
	    // when using IE6
        this.parent.location.href = getURL_Root()+"default.aspx"
    }
    
    resetMessageBoxDialogVariables();
}

//
// ---------------------------------------------------------------------------------------------------
//
//Ajax Call: -->TKUZ-6UGCKK
function makeHTTPRequest () {
    
    var http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
            // See note below about this line
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        isHttpRequestError = 1;
        //alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    return http_request;
}

//
// ---------------------------------------------------------------------------------------------------
//
function ovAjaxRequest(urlCheckFile) {
    // checks the current Progress
    
    var http_request = makeHTTPRequest();
    if (!http_request) return;
   
    http_request.onreadystatechange = function() { 
        //alertContents(http_request); 
        if(http_request.readyState  == 4)
         {
              if(http_request.status  == 200) 
                  //document.ajax.dyn="Received:"  + xhr.responseText; 
				{}  
              else 
                 //document.ajax.dyn="Error code " + xhr.status;
				{}
         }

    }
     
     //alert ( http_request ); 
    http_request.open('GET', urlCheckFile, false);
    // in ff, the last parameter should be true, because of a synchonized workflow!
    http_request.send( null );

}

//
// ---------------------------------------------------------------------------------------------------
//
function alertContents(http_request) 
{
    // closed!
}

//
// ---------------------------------------------------------------------------------------------------
//
function getTimeStamp(){
   var d, s = "";
   var c = ":";
   d = new Date();
   s += d.getHours() + c;
   s += d.getMinutes() + c;
   s += d.getSeconds() + c;
   s += d.getMilliseconds();
   return ( s );
}

//
// ---------------------------------------------------------------------------------------------------
//
function jswait(millis)
{
        var date = new Date();
        var curDate = null;
        do { curDate  = new Date(); }
        while(curDate-date < millis);
} 			


//
// ---------------------------------------------------------------------------------------------------
//

function closeBrowserWindow()
{
    // check writeback!
    try {
        if (this.parent.reportFrame.saveWriteBack()) return;
    } catch ( ex ){}

    top.close();
}


//
// ---------------------------------------------------------------------------------------------------
//

var interval;
var isBusy = false;
function startAnimation()
{
	if (isBusy)
		return;
	isBusy = true;
	if ( this.name == "topFrame" ) {
        //deleted animation
	    return;
    }
     else 
    {
        //debugger;
        disableContainer();
	}
}


function disableContainer()
{
    showContainerBackground();
    try {
        parent.frames['leftFrame'].showContainerBackground();
    } catch (ex) {}
    try {
        parent.frames['topFrame'].showContainerBackground();
    } catch (ex) {}
}

function showContainerBackground() {
    if ( document.getElementById("ovBackMask") ) 
    {
		document.getElementById("ovBackMask").style.visibility = "visible";
		try {
		    document.getElementById("ovBackLoading").style.visibility = "visible";
		} catch (ex) {}
    }
    else {
        var oDivCol = document.createElement("div");
        oDivCol.style.top             = "0";	
        oDivCol.style.width           = "100%";
        oDivCol.style.height          = "2000px"; 
        oDivCol.style.visibility      = "visible";
        oDivCol.className             = "x-dlg-mask";
        oDivCol.setAttribute("id", "ovBackMask");
        document.body.appendChild(oDivCol)
	}
}

function hideContainerBackground()
{
    document.getElementById("ovBackMask").style.visibility = "hidden";
	
	try {
	    document.getElementById("ovBackLoading").style.visibility = "hidden";
	} catch (ex) {}
	
	try {
        parent.frames['leftFrame'].document.getElementById("ovBackMask").style.visibility = "hidden";
        parent.frames['topFrame'].document.getElementById("ovBackMask").style.visibility = "hidden";
	} catch (ex) {}
}

//
// ---------------------------------------------------------------------------------------------------
//

function setHourglass() {
    document.body.style.cursor = 'wait';
}

//
// ---------------------------------------------------------------------------------------------------
//

function initLogin()
{
	try
	{
	    document.body.style.cursor='default';
		hideContainerBackground();
	    
		if (document.getElementById("LoginControl1_B_Submit") != null)
		{
			if (this.parent.topFrame != null)
				this.parent.topFrame.document.getElementById("P_Buttons").style.visibility = "hidden";
		}
		
		document.getElementById("LoginControl1_B_Submit").focus();
		
		
	}
	catch (e)
	{}
}

//
// ---------------------------------------------------------------------------------------------------
//

function disableComboBoxes() { 
	var theComboBoxes = document.getElementsByTagName("select"); 
	if (theComboBoxes == null) 
        return; 
	for (var i = 0; i < theComboBoxes.length; i++) { 
		theComboBoxes[i].disabled = "true";
	} 
}

//
// ---------------------------------------------------------------------------------------------------
//

// type: 0 or empty: call from inside a report
// type: 1: call from outside:  a report
function hiddenWriteBack(sHref, itype)
{
    var ii = 0;
	//do a submit ( writeback ) and check after the last state!
    this.parent.reportFrame.submitForm();
    
    // readyState = 'complete' abwarten
    return hiddenWriteBack2(sHref,1, itype);
    
}

//
// ---------------------------------------------------------------------------------------------------
//

function hiddenWriteBack2(sHref, iiCount, itype)
{
    if ( this.parent.reportFrame.document.readyState == 'complete' ) 
	{
		if ( itype == 1 )
			return this.parent.reportFrame.GoLink(sHref);
		else
			return this.parent.reportFrame.GoLinkHidden(sHref);
		
    }
	else 
	{
		iiCount++;
        this.setTimeout("hiddenWriteBack2('" + sHref + "'," + iiCount + "," + itype + ")", 100);
	}
}

//
// ---------------------------------------------------------------------------------------------------
//

// rka: new Function for debugging!
function getOVCurrentTime(){
   var d, s = "";
   var c = ":";
   d = new Date();
   s += d.getHours() + c;
   s += d.getMinutes() + c;
   s += d.getSeconds() + c;
   s += d.getMilliseconds();
   return ( s );
}

//
// ---------------------------------------------------------------------------------------------------
//

function setHiddenTextBox4ScrollPosition(tbName, tbValue) 
{
    try {
        var hiddenTB = document.getElementById(tbName);
        
        if (hiddenTB == null || typeof hiddenTB == 'undefined') {
            return false;
        }
        
        hiddenTB.value = tbValue;
        return true;
        
	}
    catch(oException) {
        return false;
    }
}

function createHiddenTextBox4ScrollPosition(tbName, tbValue) 
{
    try {
        // create new hidden textbox
        var hiddenTB = document.createElement('INPUT');
        
        hiddenTB.type = 'hidden';
        hiddenTB.id = tbName;
        hiddenTB.name = "hiddenScrollPosition";
        hiddenTB.style.width = "5px";
        hiddenTB.style.height = "5px";
        hiddenTB.value = tbValue;
        document.body.appendChild(hiddenTB);
	}
    catch(oException)
    {}
}

function getHiddenTextBoxes4ScrollPosition()
{
    try {
        var objects = document.getElementsByTagName("INPUT");
        return objects;
    }
    catch(oException)
    {
        return null;
    }
}

//
// ---------------------------------------------------------------------------------------------------
//  Write Back Improvements 2008

var theCurrentUserAction = "";
var theCurrentUserActionParameter = null;
var theCurrentUserActionParameter2 = null;
var theCurrentUserActionParameter3 = null;
var executedWriteBackViaMessageBox = false;

var canceledObjectName = null;
var canceledObjectIndex = null;
var canceledObjectNewIndex = null;
var canceledObjectValue = null;
var canceledObjectType = null;

function resetMessageBoxDialogVariables() {
    theCurrentUserAction = "";
    theCurrentUserActionParameter = null;
    theCurrentUserActionParameter2 = null;
    theCurrentUserActionParameter3 = null;
}


//
// ---------------------------------------------------------------------------------------------------
//  CLEAR UX Look and Feel March 2008

function showSettings() {
    // HoW, 08.04.08: [GBUR-7DGJ67] runtime error when clicking "export to excel" while pdf doc is open
    // and [RKAG-7DGHZ4] Back - Button in Titlebar has wrong link!
    var button = document.getElementById("IB_SETTINGSWITHMENU");
    if (button) {
        if (button.src.indexOf("btn_settingswithmenu28x16_disabled.gif") == -1 && this.parent.reportFrame != null) {
            // if the div is already visible, then hide the div
            var menu = this.parent.reportFrame.document.getElementById("SettingsMenuLayer");
            if (menu) {
                if (menu.style.visibility == "visible") {
                    menu.style.visibility = "hidden";
                    setSettingsFontWeight();
                    return;
                }
            }

            var obj = document.getElementById("HY_SETTINGSWITHMENU");
            if (obj) {
            
                //obj.className = "hyperlinksSelected";
                obj.className = "hyperlinks";
            }

            var tmpNode = obj;
            var itmp  = 0;
            while ( tmpNode.tagName.toLowerCase() != "body" )
            {
                itmp += tmpNode.offsetLeft;
                tmpNode = tmpNode.parentNode;
            }

            var rpos = parent.document.body.offsetWidth - obj.parentNode.offsetWidth - itmp;
            showSettingsMenuHelper(rpos);
        }
    }
}

function hideMenus() {
    hideSettingsMenu();
}

function setSettingsFontWeight() {
    var obj = this.parent.topFrame.document.getElementById("HY_SETTINGSWITHMENU");
    if (obj) {
        obj.className = "hyperlinks";
    }
}

function hideSettingsMenu() {
    try {
        var menu = this.parent.reportFrame.document.getElementById("SettingsMenuLayer");
    } catch(ex) {} 
    
    if (menu) {
        menu.style.visibility = "hidden";
        setSettingsFontWeight();
    }
}

function showSettingsMenuHelper(rightPos) {
    // check if the menu is already there
    var menu = this.parent.reportFrame.document.getElementById("SettingsMenuLayer");
    
    if (menu) {
        menu.parentNode.removeChild(menu);
    }
    
    if ( isPasswordChangeControlLoaded() ) {
        rightPos = 0;
    }
    
    // build div element
    var divMenu = this.parent.reportFrame.document.createElement("div");
    
    divMenu.className = "SettingsMenuLayer";
    divMenu.setAttribute("id", "SettingsMenuLayer");
    divMenu.setAttribute("name", "SettingsMenuLayer");
    divMenu.style.zIndex = 10001;
    divMenu.style.visibility = "visible";
    divMenu.style.right = rightPos;
    
    var innerHtml = buildInnerHtml();
    divMenu.innerHTML = innerHtml;
    
    // GB: [MMAK-7RBGBU]            
    // it seems that IE8 on Win2k8 can't pass the eventhandler properly
    // when the html code is assigned via <obj>.innerHTML = <text>
    // when inspecting the eventhandler they are present as String objects rather than
    // function objects
    // thus, we override them here as explicite functions
	var TRs = divMenu.getElementsByTagName("tr");
	if ( TRs && TRs != null && TRs.length > 0)
	{
		for(var i=0; i<TRs.length; i++)
		{
			var tr = TRs[i];
			tr.onmouseover = function(){this.className='tableRowHighlight';}
			tr.onmouseout = function(){this.className='tableRowNormal';}
		}
	}
	var As = divMenu.getElementsByTagName("A");
 	if ( As && As != null && As.length > 0)
	{
		for(var i=0; i<As.length; i++)
		{
			var a = As[i];
			if (a && a.id && a.id != null)
			{
				if (a.id == "H_Password")
				{
					a.onclick = function(){parent.topFrame.changePW(true);}
				}
				else if (a.id == "H_Aliases")
				{
					a.onclick = function(){parent.topFrame.changeAliasPasswords(true);}
				}
			}
		}
	}

    this.parent.reportFrame.document.body.appendChild(divMenu);
}

function resizeSettingsMenu(leftPos) {
    try {
        var menu = this.parent.reportFrame.document.getElementById("SettingsMenuLayer");
    } catch(ex) {} 

    if (menu) {
        menu.style.left = leftPos;
    }
}

function buildInnerHtml() {
    // first caption
    //var pwHref = " onclick=\"javascript:changePW();\" href=\"#\"";
    var pwHref = " onclick=\"parent.topFrame.changePW(true);\" href=\"#\"";
    var passwordInnerHtml = "<a id=\"H_Password\" class=\"H_MenuItem\">" + this.parent.topFrame.sLABEL_PASSWORD + "</a>";
    var row1 = buildTrTag(buildTdTag("<div class=\"divMenuItem\"" + pwHref + ">" + passwordInnerHtml + "</div>", pwHref), this.parent.topFrame.sTOOLTIP_CHANGE_PASSWORD);
    
    // second caption
    //var aliasesHref = " onclick=\"javascript:changeAliasPasswords();\" href=\"#\"";
    var aliasesHref = " onclick=\"parent.topFrame.changeAliasPasswords(true);\" href=\"#\"";
    var aliasesInnerHtml = "<a id=\"H_Aliases\" class=\"H_MenuItem\">" + this.parent.topFrame.sLABEL_ALIASES + "</a>";
    var row2 = buildTrTag(buildTdTag("<div class=\"divMenuItem\""+ aliasesHref + ">" + aliasesInnerHtml + "</div>", aliasesHref), this.parent.topFrame.sTOOLTIP_CHANGE_ALIAS_PASSWORDS);
    
    var rows = row1 + row2;
    return buildTableTag(rows);
}

function buildTableTag(sInput) {
    return "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">" + sInput + "</table>";
}

function buildTrTag(sInput, sToolTip) {
    return "<tr title=\"" + sToolTip + "\" onMouseOver=\"this.className='tableRowHighlight';\" onMouseOut=\"this.className='tableRowNormal';\">" + sInput + "</tr>";
}

function buildTdTag(sInput, hRef) {
    var spacer = "<a class=\"H_MenuItem\">&nbsp;&nbsp;</a>";
    spacer = "<div class=\"divMenuItemSpacer\"" + hRef + ">" + spacer + "</div>";
    
    var td = "<td style=\"border:0;width:16px;height:16px;\">" + spacer + "</td>";
    
    var td_center = "<td>" + sInput + "</td>";
    
    return td + td_center + td;
}

//rka: wrapper function for reading the current application path from the default.aspx file (frameset)
function getURL_Root()
{
    try {
        return this.parent.g_URL_Root;
    } catch (ex) {
        return "../";
    }
}

