// version 	: 1.0
// release 	: 09/05/2001
// author 	: Maurice van Creij

// ----------------------- 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[0];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(0);
tellerB = 0;
	for (var tellerA = 1;tellerA<DBarray[0];tellerA++){
		dbString = DBarray[tellerA][fieldnr].toLowerCase()
		compString = string.toLowerCase()
		if (dbString.indexOf(compString) != -1){
			aID[tellerB] = DBarray[tellerA][getfieldnr]
			tellerB++
		}
	}
return aID
}

function OrderContent(sortArray,sortMatrix){ // re-orders the filtered content if an array with an order-matrix is supplied
aID = new Array(0);
	if(sortMatrix[0]!=-1 && sortArray.length==sortMatrix.length){
		for(tellerA=0; tellerA<sortArray.length; tellerA++){
			aID[sortMatrix[tellerA]]=sortArray[tellerA]
		}
	}else{
		aID = sortArray; //function proxy
	}
return aID
}
	
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){
var gotChild = 0;
	for (var teller = 1;teller<DBarray[0];teller++){
		if (DBarray[teller][1]==cID){
			gotChild = 1
		}
	}
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
}


// -------------------- DBarray modifiers -------------------
function autoTerminateBranches(){
	for(tellerA=0; tellerA<DBarray.length; tellerA++){
		if (hasChild(tellerA)==1){
			aID = FilterContent(1,tellerA,0)
			lastItem = aID[aID.length-1]
			DBarray[lastItem][12] = -1
		}
	}
}

rLevels = new Array(0,0,0,0,0,0,0,0,0,0);
function aproximateMenuPos(startPos,rLevel,menuWidth,menuHeight){
	if(rLevel>0){rLevels[rLevel] = 0}
	for (var tellerA = 1 ; tellerA < DBarray[0] ; tellerA++){
		if (DBarray[tellerA][1]==startPos){
			if(rLevel>0){
				parentZ = DBarray[tellerA][1]
				
				// place the Xpos of the menu blocks
				offSetX = DBarray[parentZ][6]
				if(DBarray[tellerA][6]==0){DBarray[tellerA][6] = offSetX + menuWidth + menuPosX}

				// place the Ypos of the menu-bocks in line-heigh steps
				offSetY = DBarray[parentZ][7]
				if(DBarray[parentZ][8]==-1){ // if the parents of the items have no order override (-1)
					if(DBarray[tellerA][7]==0){DBarray[tellerA][7] = (rLevels[rLevel-1] * menuHeight) + offSetY - menuHeight + subMenuShift + menuPosY}
				}else{	// if the parents items have an order override, use that instead of the recursion level
					if(DBarray[tellerA][7]==0){DBarray[tellerA][7] = ((DBarray[parentZ][8]+1) * menuHeight) + offSetY - menuHeight + subMenuShift + menuPosY}
				}
			}
			rLevels[rLevel] = rLevels[rLevel] + 1
			aproximateMenuPos(tellerA,rLevel+1,menuWidth,menuHeight)
		}
	}
}



