// data-filter for content_ini.js
	// sort through the content_ini for a complete string in a particular field and return the value from the field specified in (getfieldnr)
	function FilterContent(fieldnr,string,getfieldnr){ // useage rating: 18
		var aID = new Array(0);
		var tellerB = 0;
		for (var tellerA = 1;tellerA<DBarray.length;tellerA++){
			if (DBarray[tellerA][fieldnr]==string){
				aID[tellerB] = DBarray[tellerA][getfieldnr];
				tellerB++;
			}
		}
		return aID;
	}
	
	// sort through the content_ini for part of a string in a particular field and return the value from the field specified in (getfieldnr)
	function SearchContent(fieldnr,string,getfieldnr){ // useage rating: 5
		var 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;
	}
	
	// check all fields for the searched string fragment
	function FindContent(fieldnr,string,getfieldnr){
		var aID = new Array();
		var bID = new Array();
		var fltComparison = 0;
		var fltHighest = 0;
		var strSearchLine = '';

		// prepare the search-word
		var strSearchWord = string.toLowerCase();

		// for all searchable lines
		for (var tellerA=DBarray.length-1;tellerA>=0;tellerA--){
			// prepare the search-line
			if(fieldnr>=0){
				strSearchLine = (DBarray[tellerA][fieldnr]+'').toLowerCase();
			}else{
				strSearchLine = (DBarray[tellerA]+'').toLowerCase();
			}
			// get compare score
			fltComparison = compareString(strSearchWord,strSearchLine,new Array(' ',',','/','?','#'));
			// store
			bID[bID.length] = new Array(fltComparison,tellerA);
		}
		
		// sort the scores
		bID = bID.sort(sortFirstSubArrayElement);
		bID = bID.reverse();
				
		// compile the requested data
		for(var tellerA=0;tellerA<bID.length;tellerA++){
			intFoundId = bID[tellerA][1];
			fltFoundScore = bID[tellerA][0];
			aID[tellerA] = new Array(DBarray[intFoundId][getfieldnr],fltFoundScore);
		}

		return aID
	}
	

// hierarchy determination/manipulation
	// trace a path back across the parent items
	function TraceBranch(zID,booPure){
	aID = new Array();
	rID = new Array();
	var tellerA = 0;
	var tellerB = 0;
		// pure mode
		if(typeof booPure == 'undefined') booPure = false;
	
		// for valid instances of zID
		if(zID>-1 && zID<DBarray.length){
			rID[tellerA]=zID;
			// store all parents of the item zID in an array
			do{
				if(zID!=0){parentz = DBarray[zID][1]}else{parentz = 0}
				tellerA = tellerA + 1;
				rID[tellerA] = parentz;
				zID = parentz;
			}while(parentz>0 && tellerA<10);
			// reverse the array for further use
			aID = rID.reverse();
		}else{
			aID = new Array(0,0);
		}
		
		// fix the array for 'pure' mode
		if(booPure){
			if(aID[1]==0) aID.length=1;
		};
		
	return aID;
	}
	
	function hasChild(cID){
		arrChilds = FilterContent(1,cID,0);
		gotChild = arrChilds.length;
		return gotChild;
	}
	
	function IsFirstLevel( cID ){
		isFirstLevel = false;
		arrMain = FilterContent(1,0,0);
		for(var intA=0; intA<arrMain.length; intA++){
			if ( arrMain[intA] == cID ) {
				isFirstLevel = true;
			}
		}
		return isFirstLevel;
	}

	function childrenOf(parent){
		var children = FilterContent(1,parent,0);
		return children;
	}
	
	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;
	}
	
		// custom sort sub-functions	
		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;
		} 
	
	// sorting arrays using an order-matrix
	function OrderContent(arrMatrix,arrOrder){
		aID = new Array();
		bID = new Array();
		
		if(arrOrder[0]!=-1 && arrMatrix.length==arrOrder.length){
			// compile sort array
			for(var intA=0; intA<arrMatrix.length; intA++){
				aID[intA] = new Array(arrOrder[intA],arrMatrix[intA]);
			}
			// invoke bubble-sort
				aID = aID.sort(sortFirstSubArrayElement);
			// compile return array
			for(var intA=0; intA<arrMatrix.length; intA++){
				bID[intA] = aID[intA][1];
			}
		}else{
			//if it didn't work out
			bID = arrMatrix; 
		}
	return bID;
	}

	function isInArrayOrCSV(sItem,sArray){
		sString = ','+sArray+',';
		sItem = ','+sItem+',';
		if(sString.indexOf(sItem)>-1){return true}else{return false}
	}
	
	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;
	}
	
	// compare all fields for the searched strong fragment
	function compareString(strFragment,strCompare,arrDelimiters){
		var intScore = 0;
		var fltCompare = 0;
		// prepare both strings
		strFragment = strFragment.toLowerCase();
		strCompare = strCompare.toLowerCase();
		
		// default delimiter
		if(typeof arrDelimiters == 'undefined') arrDelimiters = new Array(' ');
		
		// split the fragment up in units according to the given delimiters
		csvFragment = strFragment;
		for(var intA=0; intA<arrDelimiters.length; intA++){
			csvFragment = (csvFragment+'').split(arrDelimiters[intA]);
		}
		arrFragment = (csvFragment+'').split(',');
		
		// check the existence of each fragment-unit in the compare-string keep score based on occurance and fragment-unit length
		for(var intA=0; intA<arrFragment.length; intA++){
			if(strCompare.indexOf(arrFragment[intA])>-1) intScore += arrFragment[intA].length;
		}
		
		// calculate the fraction of similar fragment-units in the compare-string
		fltCompare = intScore / strFragment.length;
		
		return fltCompare;
	}	
	
	if(typeof DBarray == 'undefined') DBarray = parent.DBarray;