	
/////////////////////////////////////////////////////////////////////////////////
//FUNCTION WRITELESSONINFOTOPAGE()
/* Revision-history
29-7-2003 New File by PG
23-03-2004 *modified* removed show cover (=double with startuplesson()) and added sending of access-status to startuplesson
*/
function writelessoninfotopage(arr_lsn_info,writeinID) //
    {
    //init   
	var string="<ul>"
	var i
	
	for(var i=0;i<arr_lsn_info.length;i++)
		{//lesson-name
		string+="<li><a href='#' "
	string+="onclick='startuplesson(\\\""+arr_lsn_info[i][0]+"\\\",\\\""+arr_lsn_info[i][1]+"\\\",\\\""+arr_lsn_info[i][4]+"\\\")'"
	string+="onmouseover='event.srcElement.style.backgroundColor=\\\"#FF0033\\\"' "
	string+="onmouseout='event.srcElement.style.backgroundColor=\\\"transparent\\\"' "
		string+="title='"+arr_lsn_info[i][5]+"'>"
		string+="<span class='css_lsn_name'>"+arr_lsn_info[i][1]+"</span></a><br />"
		string+="<span class='css_trg_grp'>("+arr_lsn_info[i][2]+") </span>"
		string+="<span class='css_tech_req'>["+arr_lsn_info[i][3]+"] </span>"
		string+="<span class='css_access'>["+arr_lsn_info[i][4]+"] </span>"
		string+="</li>"
		}
	
	string+="</ul>"

	ih(writeinID,string)
    }	//end func writelessoninfotopage()


/////////////////////////////////////////////////////////////////////////////////
//FUNCTION WRITEPAGEINFOTOPAGE()
/* Revision-history
9-3-2004 New File by PG
21-5-2006 *temp fixed* commented out MESH stuff as this didn't work well
21-5-2006 *fixed* added 2 <br /> to end of page list, to show complete list + some space below
*/
function writepageinfotopage(arr_pg_info,writeinID) //
    {
	/*
	arr_pg_info[i][0]=rtURL
	arr_pg_info[i][1]=pagetitle
	arr_pg_info[i][2]=MESHcode
	arr_pg_info[i][3]=MESHphrase
	*/
    //init 
	var i
	var string=""
	var lastMESHcode=""
	
	for(i=0;i<arr_pg_info.length;i++)
		{//21-5-2006: MESH headings not working well, cut out so long
		
		//new header (new MESH-group)
		/*if(lastMESHcode!=arr_pg_info[i][2])
			{string+="<br /><span style='text-decoration:underline;font-size:110%'>"+arr_pg_info[i][2]+" "+arr_pg_info[i][3]+"</span><br />"
			lastMESHcode=arr_pg_info[i][2]
			}
		*/	
		
		//adding a page to the list	
		pageURL=convert_rtURL_to_URL(arr_pg_info[i][0])
		string+="<a href='"+pageURL+"' onclick='setassinglepage()'>"+arr_pg_info[i][1]+"</a><br />"
		//alert(string)
		}

	//21-5-2006 cut out 2 lines below: 1st line because now cutting off essential parts end line 2 because MESH stuff not yet working well
	//string=string.slice(9) //for some reason starts with word 'undefined' can't find quickly so temp cut it off
	//string="<i>(MESH - MEdical Subject Headings)</i><br />"+string //all a bit temporarily 9-3-2004

	string+="<br /><br />"
	ih(writeinID,string)
    }	//end func writelessoninfotopage()

	
	
	
//////////////////////////////////////////////////////////////////
//FUNCTION SETASSINGLEPAGE
/*sets boolean in navbar to identify we are looking at a single page
neccessary for hiding forw nav arw, that is neccessary in case a lessonlist is still in navabar from a previously loaded lesson, navarw_forw would send to 1st page of lesson after home
*/
/* Revision-history
2004 New file by PG
13-10-2004 *fixed* present_page["ordernr"] ..> ["ordernr"] was missing
*/

function setassinglepage()
    {if(top.nav)
		{top.nav.cask_in_single_page_mode=true}
			
		/*sets ordernr in lessonlist (=presentpage) to the homepages nr by default)
		This will cause getnextandprevpage to identify prevpage as the homepage
		(NB: a bit double up with the safety setting in identify page, which if it cannot 
		identify a page, as is the case with a single page also default sets presentpage 
		to 1= homepage
		*/	
	if(typeof top.nav.present_page!="undefined")
		{top.nav.present_page["ordernr"]=1}
    }	


	
/////////////////////////////////////////////////////////////////////////////////
//FUNCTION STARTUPLESSON()
/* Revision-history
29-7-2003 Started building file by PG
14-10-2003 built further: simplified call to getcontentsofalesson (instead of exploretree),added lsnID specifying
??-10-2003 *modified* broke into 2 functions with startuplesson calling reallystart
28-10-2003 finished: added push array to navbar, get lessonname, get startpage and load it
10-11-2003 *modified* push lessonID to navbar instead of lessontitle 
24-11-2003 *modified* in STEP2 used return_container2 instead of reusing return_container (for clarity)
*/
/*
Needs arr_lsn_info defined globally to this function
*/	
	
function startuplesson(lsnID,lsn_name,access) //
    {//init
	var passlsnID=lsnID
	var x
	var y
	var tStart
	var pass_lsn_name=lsn_name
	
	//replace other languages equiv. 'accessible' by English
	//Dutch
	access=access.replace(/niet *toegankelijk/i,"closed")
	access=access.replace(/toegankelijk/i,"accessible")

	//don't pass if lesson is not set to "accessible"
	if((access.search(/accessible/i)==-1))
		{msg_restricted(passlsnID,pass_lsn_name)
		return
		}
		
	//show message 'loading lesson' and set transparent cover
	//to prevent simultaneus activation of another lesson
	s("message,cover")
	//for some or other reason there had to be a timeout before starting the 
	//reading of the XML-files, otherwise the s("message,cover") is not executed
	//till after the reading of the XML is completed
	tStart=setTimeout("reallystart('"+passlsnID+"')",10)
	}
	

function reallystart(lsnID) //
    {
	//init
	//info: hierpreparray is a coded lesson contents description in an assocarray,
	//to be used for the drop-down menu
	//lsn_pagelist is a differently coded lesson contents description
	//to be used for the pagelist in navbar for nextpage and prevpage
	//it is made in func getcontentsofalesson()
	var return_container
	var return_container2
	var hierpreparray
	var lsn_pagelist
	var passlsnID=lsnID
	var hierarraysstring
	var lsn_name
	var lsnsp_pageID
	var page_rtURL
	var pageURL
	
	//STEP 1: read the contents of this lesson
	return_container=getcontentsofalesson(passlsnID)
	hierpreparray=return_container[1]
	lsn_pagelist=return_container[2]
	//\\//alert("Reallystart() step 1.\nGoing to show returncontainer(1) and (2)as just returned from getcontentsofalesson")
	//\\//alertassocarray(lsn_pagelist)
	//\\//alertassocarray(hierpreparray)
	/*Info: return_container contains:
	return_container[1]=hierpreparray (=assoc array), e.g.:
		r_c[1]["root"]="pageID,pageID,CHPname,pageID"
		r_c[1]["chapter 1"]="pageID,pageID"
	return_container[2]=lsn_pagelist (=nested regular array)
		r_c[2][1]=info regarding 1st page in lesson, with:
			r_c[2][1][0]=pageID
			r_c[2][1][1]=!!!to be added in this func still!!!=rtURL of page	
			r_c[2][1][2]=chapterpath in which this page sits
	*/

	//STEP 2: transform hierpreparray into a hierarraysstring and 
	//complete the lsn_pagelist with the rtURL's
	return_container2=construct_lsnarrays(hierpreparray,lsn_pagelist)
	hierarraysstring=return_container2[0] 
	lsn_pagelist=return_container2[1]
	h("message,cover")
	//\\//alert("Reallystart() step 2.\nhierarraystring="+hierarraysstring)

	
	//STEP 3: send the arrays to the navbar to be used
	//3a. send the hierarraysstring to navbar, ready to construct a hiermenu from it!
	if(top.nav && top.nav.hierarraysstring_store)
		{top.nav.hierarraysstring_store=hierarraysstring}
	/*
	Info: as a new page loads in the mainframe that page's autoexec_onstartload will:
	1. replace the ROOTs in the URLs with the glb_pathtoroot of that page
	2. eval the string so the arrays are really formed
	*/
	//3b. send the lsn_pagelist to navbar, to use for prevpage and nextpage and chpname
	if(top.nav && top.nav.lsn_pagelist)
		{
		//\\//aaa("INFO=pagelist from startup before sending it to navbar","lsn_pagelist",lsn_pagelist)
		top.nav.lsn_pagelist=lsn_pagelist
		//\\//alert("Reallystart() step 3.\nGoing to show lsn_pagelist")
		//alertassocarray(lsn_pagelist)
		}
	
	//STEP 4. get the lesson_name & send it to the navbar to store
	//for all lessons...
	get_lsn_name:
	for(var i=0;i<arr_lsn_info.length;i++)
		{//if this one has the lsnID of the now started lesson
		//\\//alert("Sought lsnID= "+lsnID+", arr_lsn_info[i][0]="+arr_lsn_info[i][0])
		if(arr_lsn_info[i][0]==lsnID)
			{//then get the lsnname
			lsn_name=arr_lsn_info[i][1]
			//\\//alert("Found lsn_name= "+lsn_name)
			//push lesson name to navbar to keep during run of lesson
			if(top.nav)
			// For some reason addition:&& top.nav.glb_lessontitle doesn't work
				{top.nav.glb_lessonID=lsnID

				//10-11-2003:ready to del: push of lessontitle/name (then also doesn't need to be read here anymore
				top.nav.glb_lessontitle=lsn_name
				//\\//alert("Sent to top.nav= "+top.nav.glb_lessontitle)
				}
			break get_lsn_name
			}
		}
	
	
	//STEP 5: get the pageID of the lesson_startpage
	lsnsp_pageID=extract_lsn_startpage_ID(hierpreparray)
	//get the rtURL of this page
	page_rtURL=getpage_rtURL(lsnsp_pageID)
	//convert to the real page URL
	pageURL=convert_rtURL_to_URL(page_rtURL)
	//safety
	if (pageURL==null) 
		{alert("Message for developer: Error in function reallystart, pageURL of lessonstartpage is undefined");
		return
		}
	
	//STEP 6. (something different inbetween, also neccessary)
	/*sets boolean in navbar to identify we are not looking at a single page but at a page in a lesson. This boolean determines the hiding of the forw navarw in case of a single page
	*/
	if(top.nav)
   		{top.nav.cask_in_single_page_mode=false}	
	
	//STEP 7. load this page!
	window.location=pageURL

		
    }// end of func startuplesson()
	

/////////////////////////////////////////////////////////////////////////////////
//FUNCTION CONSTRUCT_LSNARRAYS()
/* Revision-history
20-10-2003 New File by  PG
4-6-2005 *fixed* to correct error on some computers that appeared unable to handle RegExp.lastParen replaced this search method by indexOf and substring
*/
/*
1. Constructs the hierArrays for the contents dropdown from a hierpreparray array
2. Completes array lsn_pagelist (used for determining chpname and next and prevpage)
*/


function construct_lsnarrays(hierpreparray,lsn_pagelist) //
    {//init
	var arr_entries_on_line= new Array()
	var arMenucode= new Array()
	arMenucode["root"]="1" //the entry connected to the first array to be built
	var now_menucode  //determines the number connected to the arMenu, startnr
	var entry
	var pageID
	var page_rtURL
	var pageURL //with page.htm at the end
	var contentsxmlURL //with contents.xml at the end
	var pagetitles
	var short_pagetitle
	var arr_pt=new Array()
	var chpname
	var hierarraysstring=""
	var return_container=new Array() 
	var srchstartpos
	var srchendpos
	
	//build up the hierarraystring: every line will be translated in one hierarray
    for(var line in hierpreparray)
		{
		//\\//alert("Now reading line"+line+" with entries:"+hierpreparray[line])
		//STEP 1. FIND THE arMenu CODE FOR THE ARRAY WE ARE GOING TO BUILD NOW
		//loop through the stored nrs
		findmenucode:
		for(var chap_name in arMenucode)
			{//if found the entry in arMenunr corresponding with
			//the line we are reading now
			if(chap_name==line)
				{//get the nrcode of the arMenu to build
				now_menucode=arMenucode[chap_name]
				//open a new Array with this nrcode
				hierarraysstring+="arMenu"+now_menucode+" = new Array("
				break findmenucode
				}
			}

		//STEP 2. ONLY if this is the FIRST menu, start with putting in the initvars 
		//(declared in declaration_glb_variables)
		if(now_menucode=="1")
			{hierarraysstring+=hierarraysstring_initvars}
			
		//STEP 3. NOW GOING TO THE LEVEL OF INDIVIDUAL ENTRIES
		arr_entries_on_line=hierpreparray[line].split(",")

		//for every entry (a page or a chapter) on the line extend 
		//the hierarraysstring with it
		addentrytohierarraysstring:
		for(var i=0;i<arr_entries_on_line.length;i++)
			{//for easy reading
			entry=arr_entries_on_line[i]
			//\\//alert("for loop doing all entries, i="+i+", entry= "+entry)			
			
			//skip the empty entries behind the "," at the end of a line
			if(entry=="") 
				{continue addentrytohierarraysstring}
			
			
			//STEP 4a. EXTRACT THE PAGEID (IF THE ENTRY IS -any kind of- PAGEID)
			if(entry.search("PAGEID_")!=-1 || entry.search("LSNspID_")!=-1 || entry.search("CHPfpID_")!=-1)
				{

				//if its a normal page's pageID...
				if(entry.search("PAGEID_")!=-1)
					{//get the pageID inbetween PAGEID_..._PAGEID
//\\//alert("Identified PAGEID_ in search, with search="+entry.search)
					//entry.search(/PAGEID_(.*)_PAGEID/)
srchstartpos=entry.indexOf("PAGEID_")
srchendpos=entry.indexOf("_PAGEID")
pageID=entry.substring(srchstartpos+7,srchendpos)
//\\//alert("startpos="+srchstartpos+", endpos="+srchendpos+", pageID="+pageID)
					//pageID=RegExp.lastParen
					}					
								
				//if it is a lesson startpage's pageID..
				if(entry.search("LSNspID_")!=-1)
					{//get the pageID inbetween LSNspID_..._LSNspID
					//entry.search(/LSNspID_(.*)_LSNspID/)
					//pageID=RegExp.lastParen
srchstartpos=entry.indexOf("LSNspID_")
srchendpos=entry.indexOf("_LSNspID")
pageID=entry.substring(srchstartpos+8,srchendpos)
					}

				//if it is a chapter frontpage's pageID..
				if(entry.search("CHPfpID_")!=-1)
					{//get the pageID inbetween CHPfp_..._CHPfp
					//entry.search(/CHPfpID_(.*)_CHPfpID/)
					//pageID=RegExp.lastParen
srchstartpos=entry.indexOf("CHPfpID_")
srchendpos=entry.indexOf("_CHPfpID")
pageID=entry.substring(srchstartpos+8,srchendpos)
					}
				
//alert("found pageID="+pageID)
									
				//STEP 4b. (with the pageID:) GET THE rtURL
				page_rtURL=getpage_rtURL(pageID)
				//alert("Func constructhierarrays: page_rtURL="+page_rtURL)
				//convert rtURL to the real page URL
				pageURL=convert_rtURL_to_URL(page_rtURL)
				//safety
				if (pageURL==null) 
					{alert("Message for developer: Error in function constructlsnarrays, pageURL is undefined");
					return
					}
				//convert pageURL to contentsxmlURL
				contentsxmlURL=convert_page_to_contentsURL(pageURL) 
				
				//STEP 4c. GET THE PAGETITLES
				pagetitles=getpagetitles(contentsxmlURL)
				if(pagetitles==null)
					{alert("Message for developer' Error in function constructlsnarrays. Pagetitles is undefined.")
					return	
					}
				//alert("Pagetitles="+pagetitles)				
				//split long and short title
				arr_pt=pagetitles.split(",")
				//get the short title (i=1), if not available take the long one (i=0)
				if (arr_pt[1]!=null && arr_pt[1]!="") //
					{short_pagetitle=arr_pt[1]}
				else
					{short_pagetitle=arr_pt[0]}
				//alert("short pagetitle="+short_pagetitle+", page_rtURL= "+page_rtURL)
				
				//STEP 4d. CONSTRUCT AN ENTRY IN THE HIERARRAY
				//add a line for this page to the hierarrays
				hierarraysstring+='"'+short_pagetitle+'","'+page_rtURL+'",0,'
		
				//STEP 4e. COMPLETE THE LSN_PAGELIST WITH THE rtURL OF THIS PAGE
				find_rtURL:
				for(var y=1;y<lsn_pagelist.length;y++)				
					{//\\//alert("y="+y+", pageID sought= "+pageID+", present pageID in lsn_pagelist= "+lsn_pagelist[y][0])
					if(lsn_pagelist[y][0]==pageID)
						{lsn_pagelist[y][1]=page_rtURL
						//\\//alert("added rtURL "+page_rtURL+" of pageID "+pageID+" to lsn_pagelist["+y+"]")  
//NB: don't put a 'break find_rtURL here because in case of 2 times a same page in a lesson, it will not have the URL inserted at the further than 1st entry
						} 
					} //end for
				} //end if entry == pageID of some kind
				

			//STEP 5a. IF THE ENTRY IS A CHAPTER ANNOUNCEMENT...
			if(entry.search("CHP_")!=-1)
				{//a more precise search: get the stuff inbetween CHP_..._CHP
				//entry.search(/CHP_(.*)_CHP/)
				//chpname=RegExp.lastParen
srchstartpos=entry.indexOf("CHP_")
srchendpos=entry.indexOf("_CHP")
chpname=entry.substring(srchstartpos+4,srchendpos)
				//STEP 5b. CONSTRUCT AN ENTRY IN THE HIERARRAY
				//add a line for this chapter to the hierarrayssstring
				hierarraysstring+='"'+chpname+'","",1,'

				//STEP 5c. keep some administration to later determine the arMenu number
				//use i+1 because i starts at 0 and arMenu codes start from 1
				arMenucode[chpname]=now_menucode+"_"+(i+1).toString()
				}
			
			//REPEAT THE SAME FOR ALL ENTRIES ON A LINE OF HIERPREPARRAY		
			}// end for entries on line
		
		//STEP 6. CLOSE THIS arMenu
		//cut off last ","
		hierarraysstring=hierarraysstring.slice(0,-1)
		//add closing parenthesis and new lines
		hierarraysstring+=")\n\n"
		
		}//end for: reading lines in the assoc array hierpreparray
	
	//STEP 7. END THE WHOLE HIERARRAYS
	//add the hierarraysendstring
	hierarraysstring+=hierarraysstring_endstring
	

	//STEP 8. PUT THE HIERARRAYSSTRING AND THE LSN_PAGELIST TOGETHER 
	//IN A RETURN_CONTAINER AND RETURN		
	return_container[0]=hierarraysstring
	return_container[1]=lsn_pagelist
	//\\//alert("Now going to get aaa from constructlsnarrays at end just before returning lsn_pagelist")
	//\\//alertassocarray(lsn_pagelist)
	//\\//alert(hierarraysstring)
	return return_container
	
    }//end of func constructlsnarrays()"")
	
	
/////////////////////////////////////////////////////////////////////
//FUNCTION EXTRACT_LSN_STARTPAGE_ID()
/* Revision-history
28-10-2003 New File by 
4-6-2005 *fixed* to correct error on some computers that appeared unable to handle RegExp.lastParen replaced this search method by indexOf and substring

*/


function extract_lsn_startpage_ID(hierpreparray) //
    {//init
	var arr_entries_on_line
	var entry
	var pageID
	var srchstartpos
	var srchendpos
	var i
		
	//for every line in the assoc array hierpreparray...	
	for(var line in hierpreparray)
		{//get this line and split it to its individual entries (pages or CHP)
		arr_entries_on_line=hierpreparray[line].split(",")
		
		//for each entry in the line...
		for(i=0;i<arr_entries_on_line.length;i++)
			{//for easy reading
			entry=arr_entries_on_line[i]

			//if it is a lesson startpage's pageID..
			if(entry.search("LSNspID_")!=-1)
				{//get the pageID inbetween LSNspID_..._LSNspID
				//entry.search(/LSNspID_(.*)_LSNspID/)
				//pageID=RegExp.lastParen
srchstartpos=entry.indexOf("LSNspID_")
srchendpos=entry.indexOf("_LSNspID")
pageID=entry.substring(srchstartpos+8,srchendpos)

				//and return the found pageID and exit function
				return pageID
				}// end if lesson startpage found			
			}//end for: reading entries on one line
    	}//end for: reading lines in the assoc array hierpreparray

    } //end func extract_lsn_startpageID()

	

