// start info
if(typeof jsReport != 'undefined'){
	jsVersion = new Array(
	/*Name			=*/ 'Content.INI brain-file',
	/*Version 		=*/ '1.3a',
	/*Date 			=*/ 20020218,
	/*Author		=*/ 'Maurice van Creij',
	/*ProjectCode	=*/ 'l1_contentini',
	/*Summary		=*/ 'Store properties of a site\'s documents in a central XML brain-file, for reference by navigational functions.',
	/*Dependencies	=*/ new Array('content_filter.js','content_ini.js','content_ini.xml','content_ini.xsl','content_js2xml.htm','content_xml2js.htm','content_xml2js.asp','xml2htm.asp'),
	/*Browsers		=*/ new Array('NS','MO','IE','OP'),
	/*Changes		=*/ new Array(
						'1.3a: modified to check urls for multiple languages at the same time',
						'1.3: added "guessDocID()" for finding the ID for a given URL',
						'1.2: "DBarray=validateDBarray(DBdisarray,booVerbose)" was added to rescue mallformed, but otherwise correct, DBarrays',
						'1.11: Added isInArrayOrCSV() function for quick checks',
					  	'1.1: Support XML generation of the array',
					  	'1.0: Common document information is stored in a central file'
					  	),
	/*Usage			=*/ new Array(
						'<script language="JavaScript" src="/~wmittens/includes/content_filter.js" type="text/javascript"></script>',
						'<script language="JavaScript" type="text/javascript">',
						'<!'+'--',
						'DBarray = new Array(0,',
						'// 0,   1,       2,    3,     4,       5,     6,     7,    8,     9,     10,          11,           12',
						'//ID,childoff,"name","url","target","icon","xpos","ypos",order,"type","long name","description","terminator"',
						'new Array(1,0,"games","/~wmittens/content/games/index.htm","content","fold",0,0,-1,"folder","Games","Homepage for the games.",0),',
						'new Array(2,0,"gear","/~wmittens/content/gear/index.htm","content","fold",0,0,-1,"folder","Gear","Homepage for the merchandise.",0),',
						'new Array(3,0,"graphics","/~wmittens/content/graphics/gallery.htm?ID=3","content","fold",0,0,-1,"folder","Graphics","Homepage for the picture-galleries.",0),',
						'new Array(4,0,"documents","/~wmittens/content/documents/index.htm","content","fold",0,0,-1,"folder","Articles","Homepage for the tutorial documents.",0),',
						'new Array(5,0,"info","/~wmittens/content/info/index.htm","content","help",0,0,-1,"folder","Info","Homepage for the support and info pages.",0),',
						'new Array(6,5,"about","/~wmittens/content/info/about.htm","content","help",75,72,-1,"support","About","Help for problems with this site.",0),',
						'new Array(7,5,"contact","/~wmittens/content/info/contact.htm","content","help",0,0,-1,"support","Contact","Useful links to other sites.",0),',
						'new Array(8,5,"search","/~wmittens/content/info/search.htm","content","help",0,0,-1,"support","Search","Search this site.",0),',
						'new Array(9,5,"links","/~wmittens/content/info/links.htm","content","help",0,0,-1,"support","Links","Useful links to other sites.",0),',
						'new Array(10,5,"help","/~wmittens/content/info/help.htm","content","help",0,0,-1,"support","Help","Help for problems with this site.",0),',
						'new Array(11,5,"home","/~wmittens/content/index.htm","content","help",0,0,-1,"support","Home","Return to the homepage.",0),',
						'new Array(0)',
						');DBarray[0]=DBarray.length-1;DBarray.length=DBarray[0]',
						'',
						'arrayofNames = FilterContent(1,0,10)',
						'arrayofUrls = SearchContent(11,\'tutorial\',3)',
						'arrayofPeerindexes = peersOf(36)',
						'//'+'-->',
						'</script>'
					  	)
	)
}else{
// end info


	// ----------------------- content_ini.js filter ------------------------------------
	function FilterContent(fieldnr,string,getfieldnr){ // sort through the content_ini for a complete string in a particular field and return the value from the field specified in (getfieldnr)
	aID = new Array(0);
	tellerB = 0;
		for (var tellerA = 1;tellerA<DBarray.length;tellerA++){
			if (DBarray[tellerA][fieldnr]==string){
				aID[tellerB] = DBarray[tellerA][getfieldnr]
				tellerB++
			}
		}
	return aID
	}
		
	function SearchContent(fieldnr,string,getfieldnr){ // sort through the content_ini for part of a string in a particular field and return the value from the field specified in (getfieldnr)
	aID = new Array();
	var tellerZ = 0;
		for (var tellerA = 1;tellerA<DBarray.length;tellerA++){
			dbString = DBarray[tellerA][fieldnr].toLowerCase()
			compString = string.toLowerCase()
			if (dbString.indexOf(compString) != -1){
				aID[tellerZ] = DBarray[tellerA][getfieldnr]
				tellerZ=tellerZ+1
			}
		}
		if(aID.length==0){
			for (var tellerA = 1;tellerA<DBarray.length;tellerA++){
				dbString = DBarray[tellerA][fieldnr].toLowerCase()
				compString = string.toLowerCase()
				if (compString.indexOf(dbString) != -1){
					aID[tellerZ] = DBarray[tellerA][getfieldnr]
					tellerZ=tellerZ+1
				}
			}		
		}
	return aID
	}
	
		function sortNumbers(a,b){return a-b}
		function reverseSort(a,b){if(a>b){return -1};if(a<b){return 1};return 0}
		function sortFirstSubArrayElement(a,b){
			if(typeof a[0]!='undefined'){y=a[0]}else{y=a};
			if(typeof b[0]!='undefined'){z=b[0]}else{z=b};
			return y-z;
		} 
	
	function OrderContent(sortArray,sortMatrix){ // re-orders the filtered content if an array with an order-matrix is supplied
		aID = new Array()
		bID = new Array()
		
		if(sortMatrix[0]!=-1 && sortArray.length==sortMatrix.length){
			// compile sort array
			for(var intA=0; intA<sortArray.length; intA++){
				aID[intA] = new Array(sortMatrix[intA],sortArray[intA])
			}
			// invoke bubble-sort
			aID = aID.sort(sortFirstSubArrayElement)
			// compile return array
			for(var intA=0; intA<sortArray.length; intA++){
				bID[intA] = aID[intA][1]
			}
		}else{
			bID = sortArray; //function proxy
		}
	return bID
	}
		
	function TraceBranch(zID){ // trace a path back across the parent items
	aID = new Array(0);
	rID = new Array(0);
	var tellerA = 0;
	var tellerB = 0;
	
		rID[tellerA]=zID;
		do{ // store all parents of the item zID in an array
			if(zID != 0){parentz = DBarray[zID][1]}else{parentz = 0}
			tellerA = tellerA + 1
			rID[tellerA] = parentz
			zID = parentz
		}while(parentz>0 && tellerA < 10)
		for (tellerB=0 ; tellerB<rID.length ; tellerB++){ // reverse the array for further use
			aID[tellerB] = rID[tellerA]
			tellerA = tellerA - 1
		}
	return aID
	}
	
	function hasChild(cID){
		arrChilds = FilterContent(1,cID,0)
		gotChild = arrChilds.length
	return gotChild
	}
	
	function parentOf(child){
		var parentz = DBarray[child][1]
		return parentz
	}
	
	function peersOf(item){
		var parentz = DBarray[item][1]
		peerIndex = FilterContent(1,parentz,0)
		return peerIndex
	}
	
	function tagStrip(inString){
		tagStart = inString.indexOf("<")	
		tagEnd = inString.indexOf(">")
		
		beforeString = inString.substring(0,tagStart)
		afterString = inString.substring((tagEnd+1),inString.length)
		outString = beforeString + " " +afterString
	return outString
	}
	
	function cleanString(inString,replaceString,replaceByString){
		// make lowercase
		outString = inString.toLowerCase()
		
		// replace spaces
		tellerC=0
		while(outString.indexOf(replaceString)>-1 && tellerC<25){
			replacePos = outString.indexOf(replaceString)
			startString = outString.substring(0,replacePos)
			endString = outString.substring(replacePos+replaceString.length,outString.length)
			outString = startString + replaceByString + endString
			tellerC=tellerC+1
		}
	return outString
	}
	
	function makeNumber(strIn) {
	    var tellerB, strIn
		var isNumber = true
		
	    for (tellerB = 0; tellerB < strIn.length; tellerB++) {
	        // Check if the current character is a number.
	        var strTest = strIn.charAt(tellerB);
	        if (!( (strTest>="0")&&(strTest<="9")||(strTest=="-") )){isNumber = false}
	    }
		
		if(isNumber){
			return strIn*1;
		}else{
			return strIn;
		}
	}
	
	function isElementOfArray(sItem,sArray){
		// returns the index of an item in an array
		var tellerB=0
		var booFoundSelfInList = false
		while(!booFoundSelfInList && tellerB<=sArray.length){
			if(sItem==sArray[tellerB]) booFoundSelfInList=true
			tellerB=tellerB+1
		}
		if(tellerB>sArray.length) tellerB=0
	return tellerB-1
	}
	
	function isInArrayOrCSV(sItem,sArray){
		sString = ','+sArray+','
		sItem = ','+sItem+','
		if(sString.indexOf(sItem)>-1){return true}else{return false}
	}
	
	function removeFromCSV(csvIn, strRemove){
		csvIn = ','+csvIn+','
		strRemove = ','+strRemove+','
		//remove specified items
		csvOut = cleanString(csvIn,strRemove,',')
		// remove the trailing and leading commas
		csvOut = csvOut.substring(1,csvOut.length-1)
	return csvOut
	}
	
	function csv2array(csvIn){
		arrOut = csvIn.split(',')
	return arrOut
	}
	
	function array2csv(arrIn){
		csvOut = 'X'+arrIn
		csvOut = csvOut.substring(1,csvOut.length)
	return csvOut
	}
	
	
	// -------------------- document related functions --------------
	
	// document-url identification
		var intIDcache = -1;
		function guessDocID(strUrlIn,intDBfield){ // useage rating: 5
			arrFoundIds = new Array();

			// use the document's URL to determine the ID
				arrFoundIds = SearchContent(3,strUrlIn,0);
				
				// clean the domain from the string
				if(strUrlIn.indexOf('file:')>-1){
					strippedURL = Pathstrip(strUrlIn);
				}else if(strUrlIn.indexOf('http:')>-1){
					strippedURL = URLstrip(strUrlIn);
				}else{
					strippedURL = strUrlIn;
				}

				// first attempt: finding the  fragment-URL in the content_ini-URLs
				if(arrFoundIds.length==0) arrFoundIds=SearchContent(intDBfield,strippedURL,0);

				// remove unique features from the end of the url, for more search hits
				arrSnipPoints = new Array('#','&','?');

				// attempts: finding the shortened fragment-URL in the content_ini-URLs
				for(var intA=0; intA<arrSnipPoints.length; intA++){
					if(arrFoundIds.length==0){
						snipPoint=strippedURL.indexOf(arrSnipPoints[intA]);
						if(snipPoint>-1){
							snippedURL = strippedURL.substring(0,snipPoint);
							arrFoundIds = SearchContent(intDBfield,snippedURL,0);
						}
					}
				}
			
			// use the last know good ID as a desperate measure	
			if(arrFoundIds.length==0) arrFoundIds[0]=intIDcache;
			
			// store new last know good ID
			intIDcache = arrFoundIds[0];
			
			// pass the result back			
			return arrFoundIds[0];
		}

	
	
	// -------------------- DBarray modifiers -------------------
	function autoTerminateBranches(){
		// turn off all unwanted termination
		for(var tellerZ=0; tellerZ<DBarray.length; tellerZ++){
			DBarray[tellerZ][12] = 0
		}
		// turn on termination on all branch ends
		for(var tellerA=0; tellerA<DBarray.length; tellerA++){
			if (hasChild(tellerA)>0){
				aID = FilterContent(1,tellerA,0)
				lastItem = aID[aID.length-1]
				DBarray[lastItem][12] = -1
			}
		}
	}

	function validateDBarray(DBdisarray,booVerbose){
		// resetting reserved field 0
		DBdisarray[0] = 0
		
		// invoke bubble-sort
		DBdisarray = DBdisarray.sort(sortFirstSubArrayElement)
	
		// for each item in the array
		for(var intA=1; intA<DBdisarray.length; intA++){
			// remember the old id
			intOldId = DBdisarray[intA][0]
			// number it correctly
			DBdisarray[intA][0] = intA
			// for each parent-id
			for(var intB=1; intB<DBdisarray.length; intB++){
				// find the old id
				if(DBdisarray[intB][1]==intOldId){
					// replace it with the new one
					DBdisarray[intB][1] = intA
				}
			}
		}
		
		// restoring reserved field 0
		DBdisarray[0] = DBdisarray.length
	
		// write DBarray out verbose
		if(booVerbose){
			strWrite = ''
						+'// version : 1.1<br>'
						+'// release : 31/05/2001<br>'
						+'// author : Maurice van Creij<br>'
						+'// changes<br>'
						+'// 1.0 - 1.1 : support XML generation of the array<br>'
						+'<br>'
						+'DBarray = new Array(0,<br>'
						+'// 0,1,2,3,4,5,6,7,8,9,10,11,12<br>'
						+'//ID,childoff,"name","url","target","icon","xpos","ypos",order,"type","long name","description","terminator"<br><br>'
			
			for(var intA=1; intA<DBdisarray.length; intA++){
				if(typeof DBdisarray[intA][0]!='undefined'){
					strWrite = strWrite + 'new Array('+DBdisarray[intA][0]+','+DBdisarray[intA][1]+',"'+DBdisarray[intA][2]+'","'+DBdisarray[intA][3]+'","'+DBdisarray[intA][4]+'","'+DBdisarray[intA][5]+'",'+DBdisarray[intA][6]+','+DBdisarray[intA][7]+','+DBdisarray[intA][8]+',"'+DBdisarray[intA][9]+'","'+DBdisarray[intA][10]+'","'+DBdisarray[intA][11]+'",'+DBdisarray[intA][12]+'),<br>'
				}else{
					strWrite = strWrite + DBdisarray[intA] + '<br>'
				}
			}			
			
			strWrite = strWrite + '<br>'
						+'new Array(0)<br>'
						+');DBarray[0]=DBarray.length-1;DBarray.length=DBarray[0]<br>'
		
			document.writeln(strWrite)
		}
		
	// return the fixed DBarray
	return DBdisarray
	}

	
	
}
