// NOTE: Do not initialize variables here! Do var initialization in initAll().

// the current menu id
var currentMenuID;
// the current document and menu language id
var currentLanguageID;
// the current user interface language id - currently not used
var currentUILanguageID;
// holds the Window object reference to the cont frame
var contFrame;
// holds the Window object reference to the top frame (frameset!)
var topFrame;
// holds the Window object reference to the top index frame
var topiFrame;
// holds the Window object reference to the navi frame
var naviFrame;
// helper for document's cookies
var mycookie;
// current navigation mode
var navMode;
// tree state
var treeState;

// boolean indicating, that Netscape Navigator 4 is being used
var ns4;
// boolean indicating, that Microsoft Internet Exporer 4 is being used
var ie4;


// that string prefixes all dynamic navigation HTML code
var ns4_navi_prefix;
// that string postfixes all dynamic navigation HTML code
var ns4_navi_postfix;
// holds a reference to the open admin center window
var adminCenter;



/**
 * Sets the current navigation settings. Must be called after each modification to the navigation state.
 */
function saveNavState() {
    mycookie = document.cookie = "pbNavState1=" + escape(navMode+";"+treeState)
}
/**
 * Returns a string, that contains the current navigation settings.
 */
function restoreNavState() {
    if (mycookie==null)
        return "";
    var label = "pbNavState1="
    var labelLen = label.length
    var cLen = mycookie.length
    var i = 0
    var currState="stdNav;";
    while (i < cLen) {
        var j = i + labelLen
        if (mycookie.substring(i,j) == label) {
            var cEnd = mycookie.indexOf(";",j)
            if (cEnd == -1) {
                cEnd = mycookie.length
            }
            currState=unescape(mycookie.substring(j,cEnd))
        }
        i++
    }
    i=currState.indexOf(";");
    if (i==-1)
        return;
    navMode=currState.substring(0,i);
    treeState=currState.substring(i+1);
}



/**
 * returns the URL for a button image
 */
/* 
// THIS FUNCTION HAS BEEN OUTSOURCED TO THE FRAMESET TEMPLATES
// BECAUSE THE CURRENTUILANGUAGEID HAS TO BE DETERMINED BY JSP	
function getButtonURL(type,subtype,active) {
    if (active)
        return "/portal_tabs/"+type+"_but_"+subtype+"_active_"+currentUILanguageID+".gif";
    else
        return "/portal_tabs/"+type+"_but_"+subtype+"_inactive_"+currentUILanguageID+".gif";
}
*/


/**
 * Called to change the current menu layer in the top frame
 */
function clickMenu(doc,type) {
    if (type=="workspace") {
        doc.images.imgWorkspace.src=getButtonURL("main","wkspc",true);
        doc.images.imgSearchFind.src=getButtonURL("main","srch",false);
        doc.images.imgPageEdit.src=getButtonURL("main","edtpg",false);
        doc.images.imgPageInfo.src=getButtonURL("main","pgdet",false);
        if (ie4) {
            doc.all.menu_workspace.style.visibility="visible";
            doc.all.menu_searchFind.style.visibility="hidden";
            doc.all.menu_pageEdit.style.visibility="hidden";
            doc.all.menu_pageInfo.style.visibility="hidden";
        }
        if (ns4) {
            doc.menu_workspace.visibility="show";
            doc.menu_searchFind.visibility="hide";
            doc.menu_pageEdit.visibility="hide";
            doc.menu_pageInfo.visibility="hide";
        }
    }
    if (type=="searchFind") {
        doc.images.imgWorkspace.src=getButtonURL("main","wkspc",false);
        doc.images.imgSearchFind.src=getButtonURL("main","srch",true);
        doc.images.imgPageEdit.src=getButtonURL("main","edtpg",false);
        doc.images.imgPageInfo.src=getButtonURL("main","pgdet",false);
        if (ie4) {
            doc.all.menu_workspace.style.visibility="hidden";
            doc.all.menu_searchFind.style.visibility="visible";
            doc.all.menu_pageEdit.style.visibility="hidden";
            doc.all.menu_pageInfo.style.visibility="hidden";
        }
        if (ns4) {
            doc.menu_workspace.visibility="hide";
            doc.menu_searchFind.visibility="show";
            doc.menu_pageEdit.visibility="hide";
            doc.menu_pageInfo.visibility="hide";
        }
    }
    if (type=="pageEdit") {
        doc.images.imgWorkspace.src=getButtonURL("main","wkspc",false);
        doc.images.imgSearchFind.src=getButtonURL("main","srch",false);
        doc.images.imgPageEdit.src=getButtonURL("main","edtpg",true);
        doc.images.imgPageInfo.src=getButtonURL("main","pgdet",false);
        if (ie4) {
            doc.all.menu_workspace.style.visibility="hidden";
            doc.all.menu_searchFind.style.visibility="hidden";
            doc.all.menu_pageEdit.style.visibility="visible";
            doc.all.menu_pageInfo.style.visibility="hidden";
        }
        if (ns4) {
            doc.menu_workspace.visibility="hide";
            doc.menu_searchFind.visibility="hide";
            doc.menu_pageEdit.visibility="show";
            doc.menu_pageInfo.visibility="hide";
        }
    }
    if (type=="pageInfo") {
        doc.images.imgWorkspace.src=getButtonURL("main","wkspc",false);
        doc.images.imgSearchFind.src=getButtonURL("main","srch",false);
        doc.images.imgPageEdit.src=getButtonURL("main","edtpg",false);
        doc.images.imgPageInfo.src=getButtonURL("main","pgdet",true);
        if (ie4) {
            doc.all.menu_workspace.style.visibility="hidden";
            doc.all.menu_searchFind.style.visibility="hidden";
            doc.all.menu_pageEdit.style.visibility="hidden";
            doc.all.menu_pageInfo.style.visibility="visible";
        }
        if (ns4) {
            doc.menu_workspace.visibility="hide";
            doc.menu_searchFind.visibility="hide";
            doc.menu_pageEdit.visibility="hide";
            doc.menu_pageInfo.visibility="show";
        }
    }
}



/**
 * Called to change the current navigation mode image
 */
function clickNav(type,doc,img) {
    topiFrame.document.images.imgStdNav.src=getButtonURL("navi","stand",false);
    topiFrame.document.images.imgCatNav.src=getButtonURL("navi","cattree",false);
    topiFrame.document.images.imgCatIdx.src=getButtonURL("navi","catindx",false);
    img.src=getButtonURL("navi",type,true);
}



/**
 * Called to change the text in the browser's status bar
 */
function chStatus(statusText) {
    window.top.status=statusText;
    return true;
}



/**
 * Called to change an image and the text in the browser's status bar
 */
function chImg(img,src,statusText) {
    img.src=src;
    return chStatus(statusText);
}



/**
 * Builds a relative pirobase link based upon HTTP command name, page part and optional special parameters for the command
 */
function buildPbLink(cmd,pagePart,special) {
    url="../../"+cmd+"/"+currentMenuID+"_l"+currentLanguageID;
    if (pagePart!=null)
        url+="_p"+pagePart;
    if (special!=null)
        url+=special;
    url += "/index.html";
    return url;
}



/**
 * Builds a relative pirobase link based upon HTTP command name, page part and optional special parameters for the command
 * and changes the location of the content frame.
 */
function changePbContFrame(cmd,pagePart,special) {
    url=buildPbLink(cmd,pagePart,special);
    contFrame.location=url;
}



/**
 * Builds a relative pirobase link based upon HTTP command name, page part and optional special parameters for the command
 * and changes the location of the top frame.
 */
function changePbTopFrame(cmd,pagePart,special) {
    url=buildPbLink(cmd,pagePart,special);
    topFrame.location=url;
}



/**
 * Builds a relative pirobase link based upon HTTP command name, page part and optional special parameters for the command
 * and opens a new window.
 */
function openPbWin(cmd,pagePart,winWidth,winHeight,title,prop) {
    url=buildPbLink(cmd,pagePart);
    if (prop==null)
        prop='toolbar=no,directories=no,status=no,scrollbars=yes,menubar=yes,resizable=yes';
    if (winWidth!=0)
        prop+=',width='+winWidth;
    if (winHeight!=0)
        prop+=',height='+winHeight;
    winHandle=window.open(url,title,prop);
    if(navigator.appVersion.indexOf("MSIE 3",0)==-1) {
        id = setTimeout('winHandle.focus()',1000);
    }
}

/**
 * Builds a relative pirobase link based upon HTTP command name, page part and optional special parameters for the command
 * and opens a new window.
 */
function openPbWinType(cmd,pageType,pagePart,winWidth,winHeight,title,prop) {
    url=buildPbLink(cmd,pagePart,pageType);
    if (prop==null)
        prop='toolbar=no,directories=no,status=no,scrollbars=yes,menubar=yes,resizable=yes';
    if (winWidth!=0)
        prop+=',width='+winWidth;
    if (winHeight!=0)
        prop+=',height='+winHeight;
    winHandle=window.open(url,title,prop);
    if(navigator.appVersion.indexOf("MSIE 3",0)==-1) {
        id = setTimeout('winHandle.focus()',1000);
    }
}


/**
 * Gets a relative pirobase link and optional special parameters and opens a new window.
 * Also includes caring for getting always a new page from the server, not a cached copy.
 */
function openSpecialWin(url,winWidth,winHeight,title,prop,cacheok) {
    if (prop==null)
        prop='toolbar=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=yes';
    if (winWidth!=0)
        prop+=',width='+winWidth;
    if (winHeight!=0)
        prop+=',height='+winHeight;

		if(cacheok != "true"){
	 	  var dt = new Date(); //this is needed for making the browser use non-cached pages
			var dothtml = "-" + dt.getTime() + ".html";		
			url = url.replace(/.html/, dothtml);
    }
    if(title=="AdminCenter") {
    	if(adminCenter != null){
    		if(adminCenter.closed) {
    			winHandle=window.open(url,title,prop);
    			adminCenter = winHandle;
    		}
    		else {
    			adminCenter.focus();
    		}
    	}
    	else {
    		winHandle=window.open(url,title,prop);
    		adminCenter = winHandle;
    	}
    }
    else
       winHandle=window.open(url,title,prop);
    if(navigator.appVersion.indexOf("MSIE 3",0)==-1) {
        id = setTimeout('winHandle.focus()',1000);
    }
}


/**
 * returns the HTML code to display the standard navigation
 */
function getStdNavHTML() {
    var s="";
    if (ns4)
        s+=ns4_navi_prefix;
    s+="stdNav "+new Date().toString();
    if (ns4)
        s+=ns4_navi_postfix;
    return s;
}
/**
 * returns the HTML code to display the catalog navigation
 */
function getCatNavHTML() {
    var s="";
    if (ns4)
        s+=ns4_navi_prefix;
    s+="catNav "+new Date().toString();
    if (ns4)
        s+=ns4_navi_postfix;
    return s;
}
/**
 * returns the HTML code to display the catalog index
 */
function getCatIdxHTML() {
    var s="";
    if (ns4)
        s+=ns4_navi_prefix;
    s+="catIdx "+new Date().toString();
    if (ns4)
        s+=ns4_navi_postfix;
    return s;
}



/**
 * Changes to the standard navigation.
 */
function chStdNav() {
    navMode="stdNav";
    saveNavState();
}
/**
 * Changes to the catalog navigation.
 */
function chCatNav() {
    navMode="catNav";
    saveNavState();
}
/**
 * Changes to the catalog index.
 */
function chCatIdx() {
    navMode="catIdx";
    saveNavState();
}



/**
 * Initializes the navigation mode
 */
function initNavMode() {
    if (navMode=="stdNav") {
    		parent.topi.clickStdNav();
    }
    if (navMode=="catNav") {
    		parent.topi.clickCatTree();
    }
    if (navMode=="catIdx") {
    		parent.topi.clickCatIndex();
    }
}

/**
 *
 */
function initAll() {
    ns4=(document.layers)? true:false;
    ie4=(document.all)? true:false;

    ns4_navi_prefix="<HTML><HEAD>\n"+
        "<!--\n"+
        "<STYLE TYPE=\"text/css\">\n"+
        "BODY,P,TD,TH,LI,UL,OL,A,BLOCKQUOTE,DIV { font-family:\"Arial\",\"Helvetica\"; color:black; }\n"+
        "BODY,P,TD { font-size: 9pt; }\n"+
        "A         { font-size: 10pt; color:#000000; text-decoration: underline; }\n"+
        "A:link    { font-size: 10pt; color:#000000; }\n"+
        "A:visited { font-size: 10pt; color:#000000; }\n"+
        "A:active  { font-size: 10pt; color:#000000; }\n"+
        "//--></STYLE></HEAD><BODY>";
    ns4_navi_postfix='</BODY></HTML>';

    currentMenuID=-1;
    currentLanguageID=1;
    currentUILanguageID=1;

    mycookie = document.cookie;

    navMode="stdNav";
    treeState="";

    restoreNavState();

    initNavMode();
}

