/*******************************************************************************
							!!! ATTENTION !!!
	ALL FILES OF THE LIGHT PUBLICATION MUST BE SAVED AS UNICODE (UTF-16).
*******************************************************************************/
var refToTop = window;

window.onload=handle_onload;

var browser=navigator.appName+" "+navigator.appVersion;
var ms=false;
if (browser.substring(0,9)=="Microsoft"){ms=true;}
var ISGECKO = window.navigator.userAgent.indexOf("Gecko") != -1 ? true : false;
var LEFT = 0;
var RIGHT = 1;
var DOC = 2;
var TABS = 3;
var POPUP = 4;

//' global system var
var objSystem=new System();

// popup Array, reference to all opened popup window objects
var arrPopups = [];

// variables used when loading a frameset inside a newly loaded frame
// these are set to 0 again, when the menu/menu_item/document/paragraph has been loaded
var intRequestedDocumentID = 0;
var intRequestedMenuItemID = 0;
var intRequestedMenuRightID = 0;
var intRequestedParagraphID = 0;

var isEnvironment = true;    //RR: used to determine if this is the top window
var intHighlightDocument = 0; // used to determine if a document should highlight search results

// this variable contains the desired menuitem id, for instance the one used in a link
var intReferencedMenuItemID = 0;

var objTabHierarchy = new TabHierarchy();
var objButtonCreator = new ButtonCreator();
var objMenuContainer = new MenuContainer();

function handle_onload() {
	
	function getArg(argName){
		//retrieves an Argument passed in the url.
		var url = unescape(document.location.href);
		if(!argName | argName.length == 0 | url.indexOf("?") <0 ){
			return -1;
		}
		var strArgs = url.substr(url.indexOf("?"), url.length);
		strArgs.indexOf('?' + argName) >= 0 ? (argName = '?' + argName) : (argName = '&' + argName); 
		if(strArgs.indexOf(argName) <0){
			return -1;
		}
		return strArgs.substr(strArgs.indexOf("=", strArgs.indexOf(argName)) + 1, strArgs.indexOf("&", strArgs.indexOf(argName) +1 ) >=0 ? strArgs.indexOf("&", strArgs.indexOf(argName) + 1 ) - (strArgs.indexOf("=", strArgs.indexOf(argName)) + 1) : strArgs.length - (strArgs.indexOf("=", strArgs.indexOf(argName)) ) );
	}
	//' create the system object

	left.location.replace("iframes.htm");		//' loads the menu frames on the left
	right.location.replace("right.htm");			//' load the content on the right
	
	//' get the arguments	
	objSystem.start_document = getArg("do_id");
	objSystem.start_menuitem  = getArg("mi_id");
	
	//set the frameset bordercolor in the index file
	guiSetIndexFramesetBorderColor();
}

/*START functions for CSS related things*/
//get css by name (for example custom.css) 
//returns null if not found, returns stylesheet obj if it is found
function getCssByName(sName) {
	var blnFound = false;
	var intCount = document.styleSheets.length -1;
	var cStyleSheet;
	while((intCount >= 0) && (blnFound == false)) {
		cStyleSheet = document.styleSheets[intCount];
		var cName       = fixStyleSheetHref(cStyleSheet.href);
		if(cName == sName) {
			blnFound = true;
		} else {
			intCount--;
		}
	}
	
	if(blnFound == true) {
		return cStyleSheet;
	} else {
		return null;
	}
}

//get the rules of the css, depending by browser
function getRulesByCss(eStylesheet) {
	if (eStylesheet.cssRules) {
		var crossrule = eStylesheet.cssRules;
	} else {
		if (eStylesheet.rules) {
			crossrule = eStylesheet.rules;
		}
	}
	return crossrule;
}

//get the last part of the href: for example: custom.css
function fixStyleSheetHref(sRef) {
	var iIndexOfSlash = Math.max(sRef.lastIndexOf("/"), sRef.lastIndexOf("\\")) +1;
	sRef = sRef.substr(iIndexOfSlash);
	return sRef;
}

//search a class in the given css rules, return null if not found
function findCssClass(cRules, sClassName) {
	var blnFound = false;
	var intCount = cRules.length -1;
	var cRule;
	while((intCount >= 0) && (blnFound == false)) {
		cRule 		   = cRules[intCount];
		var cClassName = cRule.selectorText;
		if(cClassName == sClassName) {
			blnFound = true;
		} else {
			intCount--;
		}
	}
	
	if(blnFound == true) {
		return cRule;
	} else {
		return null;
	}
}

//set the frameset bordercolor in the index file. Is specified in the custom.css
//file, as ".frameBorderIndex". only works for IE!!!
function guiSetIndexFramesetBorderColor() {
	//part to set the color of the frameset border between menu right and document frame
	if(ISGECKO) {
	} else {
		var cStyleSheet = getCssByName("custom.css");
		var cRules = getRulesByCss(cStyleSheet);
		var cRule = findCssClass(cRules, ".frameBorderIndex");
		var cBackgroundColor = cRule.style.backgroundColor;
		var objIndexFrameset = document.getElementById("objIndexFrameset");
		objIndexFrameset.borderColor = cBackgroundColor;
	}
}
/*END functions for CSS related things*/

/*
	Function is called by QTI questions and Actionmodule:
	- document.js
	- actionModule.js
	
	Opens the document in the middle frame. The document is found in the menu 
	file at the left by the IDs given as parameters.
*/
function openLinkQtiActionModuleFromDocument(strDoId, strMiId, strMeId, strCoId) {
	//get the element from the left tree menu window
	var objElement = window.getTreeWindow().getObjectDocumentFromTree(strDoId, strMiId);	
	//get the text from the element (FF or IE)
	if (ISGECKO) {
		 var strDocuTitle = objElement.text;
	 }//if
	 else {
		 var strDocuTitle = objElement.innerText;
	}//else
	
	//init vars
	var strPopup_url = "";
	var strPopup_name = ""
	var strPopup_strFeats = "";
	//read out the popup_strFeatsType (undefined, null, knop_alinea, knop_document)
	strPopup_strFeats = objElement.getAttribute("popup_strFeatsType");
	
	try {
		//check if there is a popup_strFeatsType (either knop_document or knop_alinea
		if ((strPopup_strFeats != "undefined") && (strPopup_strFeats != null) && (strPopup_strFeats != "")) {
			if(strPopup_strFeats == "knop_alinea") {
				var boolFound = false;
				var boolMore = true;
				var count = 0;
				var strSelectedCoId;
				while((!boolFound) && (boolMore)) {
					//get (next) the knopalinea id
					strSelectedCoId = objElement.getAttribute("knopalinea_id" + count);
					if ((strSelectedCoId == "") || (strSelectedCoId == null) || (strSelectedCoId == "undefined")) {
						boolMore = false;
					}//if
					else {
						if(strSelectedCoId == strCoId){
							boolFound = true;
						}//if
						else{
							count++;
						}//else
					}//else
				}//while
				
				if(boolFound) {
					strPopup_name = objElement.getAttribute("knopalinea_name" + count);
					strPopup_url = objElement.getAttribute("knopalinea_url" + count);
				}//if
			}//if
			
			if(strPopup_strFeats == "knop_document") {
				strPopup_url = objElement.getAttribute("popup_url");
				strPopup_name = strDocuTitle;
				strDocuTitle = objElement.getAttribute("parent_do_name");
				
				//open parent, so adjust do_id etc.
				strDoId = objElement.getAttribute("parent_do_id"); 
				strMiId = objElement.getAttribute("parent_mi_id");
				strMeId = "0";
				strCoId = "0";
			}//if
		}//if
	}//try
	catch(e) {
		//no popup is needed
	}
	
	//open link and... (scripts/index.js)
	//,popup_url, popup_strFeatsType, popup_name
	window.openNewLink(strDoId
					  ,strMiId
					  ,strMeId
					  ,strCoId
					  ,strDocuTitle
					  ,strPopup_url
					  ,strPopup_strFeats
					  ,strPopup_name
					  );
}

function getButtonCreator() {
	return self.objButtonCreator;
}

function reportFrameUnloaded(frame) {
	if (frame == "menu_right") objSystem.menuRightLoaded = false;
	else if (frame == "main") {
		objSystem.mainLoaded = false;
		objSystem.setDocumentLoaded(0);
		objSystem.setMenuItemLoaded(0);
	}
}

// this function reports when the menu, main or filter frames are loaded. And 
// run the needed functions when so (to mark the doc as open is the menu,
// or filter it)
function reportFrameLoaded(frame){
	//alert(frame);
	if (frame == "popup") {
		// for now there isn't an action defined for this signal
		// don't go any further into this method, to prevent reloading of buttons and such
		if(objSystem.filterLoaded){
			refreshFilters(POPUP);
		}
		return;
	}	
	if (frame == "menu"){
		objSystem.menuLoaded = true;
	} else 	if (frame == "main"){
		objSystem.mainLoaded = false;
		if (intRequestedMenuRightID == 0 && intRequestedParagraphID != 0) {
			var strDocPath = new String(self.getContentWindow().location.href);
			self.getContentWindow().location.href = strDocPath+"#"+intRequestedParagraphID;
			intRequestedParagraphID = 0;
		}
		else{
			objSystem.mainLoaded = true;
		}
		
		// If there is a right menu, mark the right tree-item
		if (objSystem.menuRightLoaded){
	        var objRightWindow = self.getMenuRightWindow();
	        if (objRightWindow != null){
		        objRightWindow.markTreeById(objSystem.currentDocument, objSystem.currentMenuItem);			
	        }
	    }
	    
	    // Open the frame
	    this.getRightWindow().showFrame("content");
	    
        intHighlightDocument--;
        
        this.getPathWindow().setPathElement(0, objSystem.currentMenuItem);
	} else 	if (frame == "menu_right") {
		objSystem.menuRightLoaded = true;	
		try { refreshFilters(RIGHT); } catch (e) { }
		

    	if (objSystem.mainLoaded){
	        var objRightWindow = self.getMenuRightWindow();
	        if (objRightWindow != null){
		        objRightWindow.markTreeById(objSystem.currentDocument, objSystem.currentMenuItem);
	        }
	    }
	} else if (frame == "filter"){
		objSystem.filterLoaded = true;
	} else if (frame == "no_tabs_empty") {
		objSystem.mainLoaded = false;
		menuRightLoaded = false;
		openContainer(intRequestedDocumentID, intRequestedMenuItemID, intRequestedMenuRightID, false);
	}
	
	if (objSystem.menuLoaded && objSystem.mainLoaded && objSystem.start_document > 0) {
		//try to read in more arguments: if succeed it is a popup document
		//that needs to be popuped (if openend solo)
		try {
			var popup_url = getArg("popup_url");
			var popup_strFeatsType = getArg("popup_strFeatsType");
			var docName = getArg("parent_do_name");
			if(objSystem.start_document != -1){
				openNewLink(objSystem.start_document, objSystem.start_menuitem, -1, -1, docName, popup_url, popup_strFeatsType, "popup");
			}//if
		}//try
		catch(e) {	
			if(objSystem.start_document != -1) {
				openNewLink(objSystem.start_document, objSystem.start_menuitem, -1, -1, "doc");
				objSystem.start_document = 0;
				objSystem.start_menuitem = 0;
			}//if
		}//catch
	}
	
	if (objSystem.mainLoaded && objSystem.menuRightLoaded && intRequestedDocumentID != 0) {
		// use intDocumentID to load in the frame, as a result of simulated click in menu right, 
		// this should only occur if the requested document id != 0		
		objSystem.mainLoaded = false;
		var strDocPath = new String(self.getContentWindow().location.href);
		var arrPath = strDocPath.split("/");
		if (arrPath[arrPath.length -1].search(/\.htm/)!= -1) arrPath.pop();
		if (arrPath[arrPath.length -1].search(/documents/)!= -1) arrPath.pop();
		strDocPath = arrPath.join("/");
		//strDocPath += "/documents/do_"+intRequestedDocumentID+".htm";
		strDocPath += "/documents/mi_"+self.intReferencedMenuItemID+"_do_"+intRequestedDocumentID+".htm";
		//alert("in mainloaded and frame == menuright, doc id: "+intRequestedDocumentID);
		self.getContentWindow().location.href = strDocPath+(intRequestedParagraphID != 0 ? "#"+intRequestedParagraphID: "");
		var objRightWindow = self.getMenuRightWindow();	
		if (objRightWindow != null) {
			//alert("opening tree right at document id: "+intRequestedDocumentID+";menuitem id: "+intRequestedMenuRightID);
			objRightWindow.markTreeById(intRequestedDocumentID, intRequestedMenuRightID);			
		}
		intRequestedParagraphID = 0;
		intRequestedDocumentID = 0;
		intRequestedMenuRightID = 0;
	}

	// filter the doc once loaded.
	if(objSystem.filterLoaded && objSystem.mainLoaded){
		//alert("filter and main loaded");
		refreshFilters(DOC);
	}
	// every tab corresponds to a specific menu_item and document
	if (frame == "tabset" && intRequestedMenuItemID != 0) {
		objSystem.mainLoaded = false;
		objSystem.menuRightLoaded = false;
		//alert("activating tab: "+intRequestedMenuItemID + "_" + intRequestedDocumentID);
		// search for the correct tab -> match the first menu item id
		var arrTabs = self.frames["right"].frames["ce_main"].myTabSet.tabs;
		var strCustomId = "";
		for (var i=0; i < arrTabs.length; i++) {
			var intMenuItemID = arrTabs[i].getCustomId().split("_")[0]; 
			if(intMenuItemID == intRequestedMenuItemID) {
				strCustomId = arrTabs[i].getCustomId();
				break;
			}
		}
		//self.frames["right"].frames["ce_main"].myTabSet.activateTab(intRequestedMenuItemID + "_" + intRequestedDocumentID);
		self.frames["right"].frames["ce_main"].myTabSet.activateTab(strCustomId);
		intRequestedMenuItemID = 0;
	}
}

// refresh the filter only for the selected newly loaded part of the publication (document, leftMenu, rightMenu, etc)
function refreshFilters(frame){
	var filterWin = window.getFilterWindow();
	var filterFunc = null;
	switch(frame){
		case LEFT:
			filterFunc = filterWin.filterLeftMenu;
			break;
		case RIGHT:
			filterFunc = filterWin.filterRightMenu;
			break;
		case DOC:
			filterFunc = filterWin.filterDocument;
			break;
		case TABS:
			filterFunc = filterWin.filterTabs;
			break;
		case POPUP:
			filterFunc = filterWin.filterPopups;
			break;
		default:
			return false;
	}
	var filters = window.getFilterWindow().document.getElementsByTagName("input");
	for(var i=0; i<filters.length; i++){
		if(filters[i].getAttribute("type") == "checkbox"){
			var intCheckboxID = filters[i].getAttribute("id");
			var blnGreyed = filterWin.document.getElementById("greyd").checked;
			filterFunc(intCheckboxID, filters[i].value, filters[i].checked, blnGreyed);
		}
	}
}

function getParameter(str) {
	var _tmp=new String(document.location);
	var pos_st=_tmp.indexOf("?");
	var pos1=_tmp.indexOf(str,pos_st);
	if (pos1>=0) {
		//' string contains variable !!
		pos2=_tmp.indexOf("~",pos1);
		if (pos2>=0) {
			return _tmp.substring(pos1+str.length+1,pos2);
		} else {
			return _tmp.substr(pos1+str.length+1,_tmp.length);
		}
	} else return null;
}

function openTreeAt(intDocumentID, intMenuItemID, intMenuID) {
	//alert("document id: "+intDocumentID+";menuitem id: "+intMenuItemID+"; menu id: "+intMenuID);
	//alert("searching tree to mark");
	window.getTreeWindow().markTreeById(intDocumentID, intMenuItemID);
}

function openExternalLink(strUrl, strName, target){
    self.getPathWindow().setPathElement(0, 0, 0, 0, strName, strUrl, target);
}

function openNewLink(intDocumentID, intMenuItemID, intMenuID, intParagraphID, strName
                    ,popup_url, popup_strFeatsType, popup_name) {
	openTreeAt(intDocumentID, intMenuItemID, intMenuID);
	self.intReferencedMenuItemID = intMenuItemID;
	self.getPathWindow().setPathElement(intDocumentID, intMenuItemID, intMenuID, intParagraphID, strName);
	objSystem.mainLoaded = false;
	objSystem.menuRightLoaded = false;
	// get info whether the document is in a tabset
	// first check if the menuitem is referring to a tabset
	if (objTabHierarchy.isTabSet(intMenuItemID)) {
		openContainer(intDocumentID, intMenuItemID, 0, true);
		//RR: 07042006: added to stop loading anymore frames. 
		//is similair as openFromTree now
		self.intRequestedDocumentID = 0;
		self.intRequestedMenuItemID = 0;
		self.intRequestedMenuRightID = 0;
		self.intRequestedParagraphID = 0;	
	}
	else {
		// either the menu-item is not a tabset nor a descendant or it is a descendant
		var intTabSetID = objTabHierarchy.getTabSetFromTab(intMenuItemID);
		if (intTabSetID != -1) {
			openContainer(intDocumentID, intTabSetID, 0, true);
			// intMenuItemID is the id of the tab
			intRequestedMenuItemID = intMenuItemID;
			intRequestedParagraphID = intParagraphID;
		}
		else {			
			var intParentMenuItemID = objTabHierarchy.getTabSet(intMenuItemID);	
			if (intParentMenuItemID != -1) {
				openContainer(intDocumentID, intParentMenuItemID, 0, true);
				// this intRequestedMenuItemID is used when the frame reports that it has been loaded!
				// intRequestedMenuItemID is not the id of a tab, but of an item in the menu right
				var intTabID = objTabHierarchy.getTabFromChildren(intMenuItemID); 
				if (intTabID != -1) {
					intRequestedMenuItemID = intTabID;
					intRequestedMenuRightID = intMenuItemID;
				}
				intRequestedParagraphID = intParagraphID;				
			}
			else {
				// menuitem and document are not in a tabset
				if (objMenuContainer.isInRightMenu(intMenuItemID, intDocumentID)) {
					// first open the parent before trying the a child menu item
					var intParentMenuItemID = objMenuContainer.getAncestorMenuItem(intMenuItemID, intDocumentID);
					openContainer(intDocumentID, intParentMenuItemID, 0, false);
					// without this reference menuitem id, the right menu won't be loaded!
					intReferencedMenuItemID = intMenuItemID;
					intRequestedMenuRightID = intMenuItemID;
				}
				else {
					openContainer(intDocumentID, intMenuItemID, 0, false);
					intRequestedParagraphID = intParagraphID;
				}
				// if a paragraph has been entered, scroll to the paragraph
			}
		}
	}
	//see if a popup is needed (just try)
	try {
		//get the proper feats string, then show the popup document
		if (typeof(popup_url) != "undefined") {
			if((popup_url != "") && (popup_url != null)){
				var strFeats = getStrFeatsPopup(popup_strFeatsType);
				var objWindow = openPopupDoc(popup_url, popup_name, strFeats);				
				objWindow.focus();
			}//if
		}//if
	}
	catch(e) {
		//there is no popup to be opened
	}
}

/*
	Types can be: knop_document, knop_alinea
	(used for opening popups)
*/
function getStrFeatsPopup(strFeatsType) {
	if (strFeatsType == "knop_document") {
		return "height=800,width=1000,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes";
	}//if
	if (strFeatsType == "knop_alinea") {
		return "height=600,width=400,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes";
	}//if
}

// this function is called when a link is clicked in the menu right section, so a document needs to be loaded in the frame left
// of the menu right
// intMenuItemID and intMenuID are given for the sake of a link!
function openMenuRightToLeft(intDocumentID, intMenuItemID, intMenuID, strName) {   
	addToPath(intDocumentID, intMenuItemID, intMenuID, 0, strName);
	objSystem.mainLoaded = false;
	var strDocPath = new String(self.getContentWindow().location.href);
	var arrPath = strDocPath.split("/");
	if (arrPath[arrPath.length -1].search(/\.htm/)!= -1) arrPath.pop();
	if (arrPath[arrPath.length -1].search(/documents/)!= -1) arrPath.pop();
	strDocPath = arrPath.join("/");
	strDocPath += "/documents/mi_"+intMenuItemID+"_do_"+intDocumentID+".htm";
	objSystem.setDocumentLoaded(intDocumentID);
	objSystem.setMenuItemLoaded(intMenuItemID);
	//alert(strDocPath.replace(/\//g,"\n"));
	self.getContentWindow().location.href = strDocPath;
}

/*  OBSOLETE func
	Ramon Ribbe - 25-11-2005
	Returns a popup window of the given index.
	If the index is out of range, null is returned.
	First element in the array is: 0

function getPopupWindowByIndex(intIndex) {
	if((intIndex >= 0) && (intIndex < arrPopups.length)) {
		return arrPopups[intIndex];
	}
	else {
		return null;
	}
}
*/

/*
	Ramon Ribbe - 25-11-2005
	Searches through the array of popup-windows and returns the objWindow of the
	popup-window that has the same name. If there are or more popup-windows with 
	the same name, the last in the array will be returned.
	If none is found, null will be returned.
*/
function getLastPopupWindowByName(strName) {
	strName = strName.replace(/ /g, "_");
	var boolFound = false;
	var count = arrPopups.length -1;
	while ((!boolFound) && (count >= 0)) {
		//alert(count + " " + arrPopups[count].name + " " + strName);
		if(arrPopups[count].name == strName) {
			boolFound = true;
		}
		else {
			count--;
		}
	}
	if(boolFound) {
		return arrPopups[count];
	}
	else {
		return null;
	}
}

/*
	As a name, it must contain only letters, digits, and underscores, and
	must start with a letter (starting with an underscore is reserved for
	"_blank" etc.).
	See devguru for the meaning of /\W. in the Regexp below:
	http://www.devguru.com/Technologies/ecmaScript/quickref/regexp_special_characters.html
*/
function openPopupDoc(url ,name, strFeatures) {
	//add letters before the window name, XYZname should not be in the content... we hope
	name = "XYZname" + name;
	//replace spaces with underscores (spaces are not allowed inside a name of a window)
	name = name.replace(/ /g, "_");
	//replace all non digit, letters and underscores
	name=name.replace(/\W/g , "");

	var objWin = window.open(url, name, strFeatures);
	arrPopups.push(objWin);
	return objWin;
}

function closePopup(objWin){
	/*var objWinIndex = -1;
	for(var i=0; i< arrPopups.length; i++){
		if(arrPopups[i] == objWin){
			objWinIndex = i;
			break;
		}
	}
	for(var i= objWinIndex; i< arrPopups.length-1; i++){
		arrPopups[i] = arrPopups[i+1];
	}
	arrPopups.pop();*/
}

function getContentWindow() {
	if (window.frames["right"].frames["ce_main"].document.getElementById("container")) {
	    // Content in a no-tabs document
		return window.frames["right"].frames["ce_main"].document.getElementById("container").contentWindow.frames["doc_contents"];
	}
	else if (window.frames["right"].frames["ce_main"].document.getElementById("tabFrs")) {
	    // Content within a tabs document.
		var objTabSet = window.frames["right"].frames["ce_main"].myTabSet;
		return objTabSet.getActiveFrame().contentWindow.frames["doc_contents"];
	}
	else{
		return window.frames["right"].frames["ce_main"];
	}
}

function getRightWindow() {
	return window.frames["right"];
}

function getFramesWindow() {
	return window.frames["left"];
}

function getTreeWindow() {
	return getFramesWindow().getFrame("content").contentWindow;
}

function getFilterWindow() {
	return getFramesWindow().getFrame("filter").contentWindow;
}

function getSearchWindow() {
	return frames["header_pub"];
}

function getSearchResultWindow(){
    return window.frames["right"].frames["ce_results"];
}

function getMenuRightWindow() {
	if (window.frames["right"].frames["ce_main"].document.getElementById("container")) {
		return window.frames["right"].frames["ce_main"].document.getElementById("container").contentWindow.frames["menu_right"];
	}
	else if (window.frames["right"].frames["ce_main"].document.getElementById("tabFrs")) {
		// is this always the correct window??????
		var objTabSet = window.frames["right"].frames["ce_main"].myTabSet;
		return objTabSet.getActiveFrame().contentWindow.frames["menu_right"];
	}
	else return null;
}

function getPathWindow() {
	return window.frames["header_pub"];
}

function ShowHighlights(){
    intHighlightDocument = 3;
}

function openContainer(intRequestedDocumentID, intRequestedMenuItemID, intRequestedMenuRightID, blnTabs, strCustomID) {
	//alert("opening container: do:"+intRequestedDocumentID+"\nmi"+intRequestedMenuItemID+"\nmi right:"+intRequestedMenuRightID+"\ntabs:"+blnTabs);
	if (intRequestedDocumentID != 0 && intRequestedMenuItemID == 0 && intRequestedMenuRightID == 0) {
		// the document is relative to the container file, which is located in the "documents" folder
		objSystem.menuRightLoaded=false;
		objSystem.mainLoaded = false;
		var strUrl="mi_"+self.intReferencedMenuItemID+"_do_"+intRequestedDocumentID+".htm";
		if (self.frames["right"].frames["ce_main"].document.getElementById("container")) {
			self.frames["right"].frames["ce_main"].document.getElementById("container").contentWindow.frames["doc_contents"].location.href = strUrl;
		} else {
			//' 
			alert ("Invalid link");
		}
	}
	else if (intRequestedDocumentID != 0 && intRequestedMenuItemID != 0) {
		objSystem.menuRightLoaded=false;
		objSystem.mainLoaded = false;
		var strFile = (blnTabs ? "": "no_") + "tabs_mi_"+intRequestedMenuItemID + ".htm";
		
        // Open a particular tab
		if (blnTabs && strCustomID != null){
		    strFile+= '?tab='+strCustomID+'#'+strCustomID;
		}

		// get the correct path to the document from wherever this function is called
		var strFramePath = self.frames["right"].frames["ce_main"].location.href;
		var arrPath = strFramePath.split("/");
		if (arrPath[arrPath.length -1].search(/\.htm/)!= -1) arrPath.pop();
		if (arrPath[arrPath.length -1].search(/documents/)!= -1) arrPath.pop();
		strFramePath = arrPath.join("/");
		//alert("trying to open: "+strFile.replace(/\//g,"\n"));
		self.frames["right"].frames["ce_main"].location.href = strFramePath+ "/documents/"+strFile;
		self.intRequestedDocumentID = intRequestedDocumentID;
		self.intRequestedMenuRightID = intRequestedMenuRightID;
	}
	else { 
		//alert("not implemented yet");
	}
}

function openFromTree(intRequestedDocumentID, intRequestedMenuItemID, intRequestedMenuRightID, blnTabs, strName) {
	addToPath(intRequestedDocumentID, intRequestedMenuItemID, 0, 0, strName);
	
	objSystem.mainLoaded = false;
	objSystem.menuRightLoaded = false;
	
	self.intRequestedDocumentID = 0;
	self.intRequestedMenuItemID = 0;
	self.intRequestedMenuRightID = 0;
	self.intRequestedParagraphID = 0;
	//alert("openContainer( "+intRequestedDocumentID+","+intRequestedMenuItemID+","+intRequestedMenuRightID+","+blnTabs+")");
	self.intReferencedMenuItemID = intReferencedMenuItemID;
	self.openContainer(intRequestedDocumentID, intRequestedMenuItemID, intRequestedMenuRightID, blnTabs);
	self.intRequestedDocumentID = 0;
	self.intRequestedMenuItemID = 0;
	self.intRequestedMenuRightID = 0;
	self.intRequestedParagraphID = 0;	
}

function registerTabClicked(strCustomId, strName) {
	var intMenuItemID = strCustomId.split("_")[0];
	self.intReferencedMenuItemID = intMenuItemID;
	var intDocumentID = strCustomId.split("_")[1];
	// this action occurs only when a user has clicked on a tab, so we don't need intRequestedDocumentID 
	// make sure that intRequestedDocumentID = 0, to avoid the problem that the contentwindow is being redirected to intRequestedDocumentID 
	intRequestedDocumentID = 0;	
	objSystem.setDocumentLoaded(intDocumentID);
	objSystem.setMenuItemLoaded(intMenuItemID);
	//alert("menu_item id: "+intMenuItemID+"; document id: "+intDocumentID);
	self.getPathWindow().setPathElement(intDocumentID, intMenuItemID, 0, 0, strName);
}

function addToPath(intDocumentID, intMenuItemID, intMenuID, intParagraphID, strName) {
	self.getPathWindow().setPathElement(intDocumentID, intMenuItemID, intMenuID, intParagraphID, strName);
}

function isDocumentLoaded() {
	//' called from zoek.htm
	return objSystem.currentDocument != 0 && 
		objSystem.mainLoaded &&
		self.intRequestedMenuItemID == 0 && 
		self.intRequestedMenuRightID == 0 && 
		self.intRequestedParagraphID == 0;
}

function System() {
	// booleans used to "synchronize" page loading 
	this.menuLoaded = false;
	this.mainLoaded = false;
	this.filterLoaded = false;
	this.menuRightLoaded = false;

	this.currentDocument = 0;
	this.currentMenuItem = 0;
	
}
System.prototype.setDocumentLoaded=System_setDocumentLoaded;
System.prototype.setMenuItemLoaded=System_setMenuItemLoaded;

function System_setDocumentLoaded(intDocumentID) {
	//' called when a document is loaded
	objSystem.currentDocument = intDocumentID;
}
function System_setMenuItemLoaded(intMenuItemID) {
	//' called when a menuitem is loaded
	objSystem.currentMenuItem = intMenuItemID;
}


