/*
Argonauts
oBu
navparams_processor.js
generates arrays from the data in navigation_params.js
created 06-03-2003
last edited 22-04-2005 dg

added option for full path links

redeveloped for science in the box: multi-language-capable
extended for 6th level
*/

// part two: logic

var error="";			// contains error string
var depth=6;			// contains navigation depth. must be >0!
var primElements=0;		// contains number of primary navigation elements
var mpt=new Array();	// menupoint
var mnpt=new Array();	// metanavigationpoint
var fpt=new Array();	// footernavigationpoint


//*********************************************************************************
// add full path prefix here, if necessary, otherwise use empty assignment
// for CW environment
var fullpath="";
// for diss
// var fullpath="http://www.dash.de/de_DE"
//*********************************************************************************

mncounter=0;
fncounter=0;

var elementNumber=17;		// number of elements per entry ######
var dA;						// contains data Array


// call check functions
var debug=1;

		// check for urls or function calls

dA=writeToArray();
writeCleanArray();
		
if (debug==1) {
	// check number of elements. 
	// the last element is an empty string. ignore.
	checkValue=(dA.length-1)/elementNumber;
	if (checkValue==parseInt(checkValue)) {
		// all is fine
	} else {
		error+="checksum failure: corrupt file 'navigation_params.js'\n";
		error+="number of elements: "+dA.length+"\n";
	}

	for (i=0; i<dA.length; i++) {
		// depth=checkDepth();
		// legal=checkForEmpty();
	}
	
	
	if (error!="") {
		alert (error);
	}
}

// writes the content of navigation_params.js into an Array
// strips leading and trailing whitespace
function writeToArray() {
	dA=data.split(",");
	for (i=0; i<dA.length; i++) {
		if (dA[i].indexOf(" ")==0){
			dA[i]=dA[i].slice(1);
		}
		if (dA[i].indexOf(" ")==dA[i].length-1) {
			start=0;
			end=dA[i].length-1;
			dA[i]=dA[i].slice(start, end);
		}
	}
	return dA;
}

function writeCleanArray() {
	nL=new Array;
	for (i=1; i<=depth; i++) {
		nL[i]=new Array();
	}
	pec=0;
	
	
	for (i=0; i<dA.length-1; i+=elementNumber) {
		if (dA[i]==1) {
			pec++;
			mpt[pec]=new Array();
			for (j=2; j<=depth; j++) {
				nL[j]=0;
			}
			nL[2]=0;
			tester=dA[i+1].split("://");
			if (tester.length>1) {
				mpt[pec]['lnk']=dA[i+1];
			} else {
				mpt[pec]['lnk']=fullpath+dA[i+1];
			}
			
			mpt[pec]['exen']=dA[i+2];
			mpt[pec]['exes']=dA[i+3];
			mpt[pec]['exfr']=dA[i+4];
			mpt[pec]['exit']=dA[i+5];
			mpt[pec]['exde']=dA[i+6];
			mpt[pec]['nmeen']=dA[i+7];
			mpt[pec]['nmees']=dA[i+8];
			mpt[pec]['nmefr']=dA[i+9];
			mpt[pec]['nmeit']=dA[i+10];
			mpt[pec]['nmede']=dA[i+11];

			mpt[pec]['tgt']=dA[i+12];
			mpt[pec]['iin']=dA[i+13];
		}
		if (dA[i]==2){
			nL[3]=0;
			for (j=(3); j<=depth; j++) {
				nL[j]=0;
			}
			nL[2]++;
			mpt[pec][nL[2]]=new Array();
			
			tester=dA[i+1].split("://");
			if (tester.length>1) {
				mpt[pec][nL[2]]['lnk']=dA[i+1];
			} else {
				mpt[pec][nL[2]]['lnk']=fullpath+dA[i+1];
			}
			mpt[pec][nL[2]]['exen']=dA[i+2];
			mpt[pec][nL[2]]['exes']=dA[i+3];
			mpt[pec][nL[2]]['exfr']=dA[i+4];
			mpt[pec][nL[2]]['exit']=dA[i+5];
			mpt[pec][nL[2]]['exde']=dA[i+6];
			mpt[pec][nL[2]]['nmeen']=dA[i+7];
			mpt[pec][nL[2]]['nmees']=dA[i+8];
			mpt[pec][nL[2]]['nmefr']=dA[i+9];
			mpt[pec][nL[2]]['nmeit']=dA[i+10];
			mpt[pec][nL[2]]['nmede']=dA[i+11];
			
			mpt[pec][nL[2]]['tgt']=dA[i+12];
			mpt[pec][nL[2]]['iin']=dA[i+13];
		}
		if (dA[i]==3){
			for (j=4; j<=depth; j++) {
				nL[j]=0;
			}
			nL[3]++;
			mpt[pec][nL[2]][nL[3]]=new Array();
			tester=dA[i+1].split("://");
			if (tester.length>1) {
				mpt[pec][nL[2]][nL[3]]['lnk']=dA[i+1];
			} else {
				mpt[pec][nL[2]][nL[3]]['lnk']=fullpath+dA[i+1];
			}
			mpt[pec][nL[2]][nL[3]]['exen']=dA[i+2];
			mpt[pec][nL[2]][nL[3]]['exes']=dA[i+3];
			mpt[pec][nL[2]][nL[3]]['exfr']=dA[i+4];
			mpt[pec][nL[2]][nL[3]]['exit']=dA[i+5];
			mpt[pec][nL[2]][nL[3]]['exde']=dA[i+6];
			mpt[pec][nL[2]][nL[3]]['nmeen']=dA[i+7];
			mpt[pec][nL[2]][nL[3]]['nmees']=dA[i+8];
			mpt[pec][nL[2]][nL[3]]['nmefr']=dA[i+9];
			mpt[pec][nL[2]][nL[3]]['nmeit']=dA[i+10];
			mpt[pec][nL[2]][nL[3]]['nmede']=dA[i+11];
			
			mpt[pec][nL[2]][nL[3]]['tgt']=dA[i+12];
			mpt[pec][nL[2]][nL[3]]['iin']=dA[i+13];
		}
		if (dA[i]==4){
			for (j=(5); j<=depth; j++) {
				nL[j]=0;
			}
			nL[4]++;
			mpt[pec][nL[2]][nL[3]][nL[4]]=new Array();
			tester=dA[i+1].split("://");
			if (tester.length>1) {
				mpt[pec][nL[2]][nL[3]][nL[4]]['lnk']=dA[i+1];
			} else {
				mpt[pec][nL[2]][nL[3]][nL[4]]['lnk']=fullpath+dA[i+1];
			}
			mpt[pec][nL[2]][nL[3]][nL[4]]['exen']=dA[i+2];
			mpt[pec][nL[2]][nL[3]][nL[4]]['exes']=dA[i+3];
			mpt[pec][nL[2]][nL[3]][nL[4]]['exfr']=dA[i+4];
			mpt[pec][nL[2]][nL[3]][nL[4]]['exit']=dA[i+5];
			mpt[pec][nL[2]][nL[3]][nL[4]]['exde']=dA[i+6];
			mpt[pec][nL[2]][nL[3]][nL[4]]['nmeen']=dA[i+7];
			mpt[pec][nL[2]][nL[3]][nL[4]]['nmees']=dA[i+8];
			mpt[pec][nL[2]][nL[3]][nL[4]]['nmefr']=dA[i+9];
			mpt[pec][nL[2]][nL[3]][nL[4]]['nmeit']=dA[i+10];
			mpt[pec][nL[2]][nL[3]][nL[4]]['nmede']=dA[i+11];
			
			mpt[pec][nL[2]][nL[3]][nL[4]]['tgt']=dA[i+12];
			mpt[pec][nL[2]][nL[3]][nL[4]]['iin']=dA[i+13];
		}
		if (dA[i]==5){
			for (j=(dA[i]+1); j<=depth; j++) {
				nL[j]=0;
			}
			nL[5]++;
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]=new Array();
			tester=dA[i+1].split("://");
			if (tester.length>1) {
				mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['lnk']=dA[i+1];
			} else {
				mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['lnk']=fullpath+dA[i+1];
			}
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['exen']=dA[i+2];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['exes']=dA[i+3];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['exfr']=dA[i+4];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['exit']=dA[i+5];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['exde']=dA[i+6];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['nmeen']=dA[i+7];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['nmees']=dA[i+8];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['nmefr']=dA[i+9];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['nmeit']=dA[i+10];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['nmede']=dA[i+11];
			
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['tgt']=dA[i+12];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]]['iin']=dA[i+13];
		}
		if (dA[i]==6){
			for (j=(dA[i]+1); j<=depth; j++) {
				nL[j]=0;
			}
			nL[6]++;
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]=new Array();
			tester=dA[i+1].split("://");
			if (tester.length>1) {
				mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['lnk']=dA[i+1];
			} else {
				mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['lnk']=fullpath+dA[i+1];
			}
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['exen']=dA[i+2];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['exes']=dA[i+3];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['exfr']=dA[i+4];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['exit']=dA[i+5];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['exde']=dA[i+6];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['nmeen']=dA[i+6];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['nmees']=dA[i+7];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['nmefr']=dA[i+8];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['nmeit']=dA[i+9];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['nmeit']=dA[i+10];
			
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['tgt']=dA[i+11];
			mpt[pec][nL[2]][nL[3]][nL[4]][nL[5]][nL[6]]['iin']=dA[i+12];
		}
	}
}



function checkDepth() {
	if ((i==0) || (i/elementNumber == parseInt(i/elementNumber))) {
		el=dA[i];
		if (el==parseInt(el)) {
			el=parseInt(el);
			if (i>(elementNumber-1)) {
				lastEl=parseInt(dA[i-(elementNumber-1)]);
			}
			if (el==1 && dA[i+(elementNumber-1)]=="yes") {
				primElements++;
			}
			if (el==(depth+1)) {
				depth=el;
			} else if (el>depth+2 || (i>(elementNumber-1) && el>lastEl+1)) {
				error+="illegal depth indicator in element "+(i/elementNumber)+"\n";
			}
		} else {
			error+="depth indicator in element "+(i/elementNumber)+" is not a number\n";
			error+="depth indicator: '"+el+"'\n";
		}
	}
	return depth;
}

function checkForEmpty() {
	if (dA[i]=="" || dA[i]==" ") {
		error+="element "+i+" is empty\n";
	}
}




