function search()
{
	this.search_data=new Array();
	this.kenmerk_afkorting=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
	this.query=new Array();
	this.result=new Array();
	this.groep_data=new Array();
	this.groep_data[0]="";
	this.groep="";
	this.kenmerken=new Array();
	this.nivgroep="";
	this.numg=false;


	this.empty_query = function()
	{
		this.query=null;
		this.query=new Array();
		this.result=null;
		this.result=new Array();
		this.groep="";
		this.kenmerken=new Array();
	}

	this.add_query_element = function(kenmerk, waarde)
	{
		this.query[this.query.length]=[kenmerk, waarde];
	//	alert((kenmerk+1)+', '+waarde);
	//	this.kenmerken[kenmerk+1]=waarde;
	}


	this.find_first = function(str, ind)
	{
		var planten=top.tblPlanten;	
		this.empty_query();
		var str=str.toLowerCase();
		for(var tlr=0; tlr<planten.length; tlr++)
		{
			// var num = planten[tlr][1];
			if( (String(planten[tlr][ind]).toLowerCase()).indexOf(str)==0 ) {
				this.result[this.result.length]=tlr;
			}
		}
		this.numg=true;
	}

	this.find_in = function(str, ind)
	{
		var planten=top.tblPlanten;	
		this.empty_query();
		var str=str.toLowerCase();
		for(var tlr=0; tlr<planten.length; tlr++)
		{
			// var num = planten[tlr][1];
			if((String(planten[tlr][ind]).toLowerCase()).indexOf(str)>=0) this.result[this.result.length]=tlr;
		}
		this.numg=true;
	}

	this.do_query = function()
	{
		this.result=null;
		this.result=new Array();
		//	this.result vullen: array met nummertjes
		if(this.query.length > 0){
			if(this.query.length == 1){
				// dit gaat alleen goed als de bijbehorende indextabel ook bestaat.

				eval('this.result = this.get_index(idx' + search_config[0][this.query[0][0]] + ', ' + this.query[0][1] + ')');
			}else{
				//alert('this.result = this.doorsnede(this.get_index(idx' + search_config[0][this.query[0][0]] + ','+ this.query[0][1] +'), this.get_index(idx' + search_config[0][this.query[1][0]] + ','+ this.query[1][1] +'));');
				eval('this.result = this.doorsnede(this.get_index(idx' + search_config[0][this.query[0][0]] + ','+ this.query[0][1] +'), this.get_index(idx' + search_config[0][this.query[1][0]] + ','+ this.query[1][1] +'));');
				for(i=2; i<this.query.length; i++){
					eval('this.result = this.doorsnede(this.result, this.get_index(idx' + search_config[0][this.query[i][0]] + ','+ this.query[i][1] +'));');
				}
			}
		}
		this.numg=false;
	}
	
	this.doorsnede = function(array1, array2){
		/*
			code by INFI bv
			http://www.infi.nl
			
			05:37:52 PM April 28, 2004 
			Ernst Jan R. Vesseur
			
			Berekent de doorsnede tussen twee arrays. Er wordt niet gecheckt of de aangeleverde variabele een valide array is. 
			Een lege array is goed, maar bij een ander datatype krijg je een error.
			Indien de twee aangeleverde arrays geen dubbele waarden bevatten, zal het resultaat dat ook niet doen.
		*/	
		var array3 = new Array();
		
		for(var i=0; i<array1.length; i++){
			for(var j=0; j<array2.length; j++){
				if(array1[i]==array2[j]) array3[array3.length]=array1[i];
			}
		}
		return array3;
	}				
	
	this.geheel = function(array1, array2){		
		var array3 = new Array();
		
		for(var i=0; i<array2.length; i++){
			array3[array3.length] = array2[i];
		}

		for(var i=0; i<array1.length; i++){			
			var exist = false;
			for(var j=0; j<array2.length; j++){
				if(array1[i]==array2[j]) exist=true;
			}
			if(!exist) {
				array3[array3.length]=array1[i]
			}
		}
		return array3;
	}		
	
	this.get_index = function(array, index){
		/*
			code by INFI bv
			http://www.infi.nl
			
			11:10:33 AM May 11, 2004 
			Ernst Jan R. Vesseur
			
			Deze functie gebruik je om met de gebrekkige arrays om te gaan die de dbconversie van Roy oplevert :-)
			Hij wordt aangeroepen door do_query hierboven.		
				
		*/
		if(array.length > index) return array[index];
		else return [];
	}			
		
/*
		OUDE ZUT

		for(var tl=0; tl<this.search_data.length; tl++)
		{
			var obj=this.search_data[tl];
			var match=true;
			// check alle eigenschappen..

			for(var tl2=0; tl2<this.query.length; tl2++)
			{
				if(obj[1].indexOf(this.query[tl2])<0) match=false;
			//	alert(obj[1]+', '+this.query[tl2]+', '+match);
			}
			if(match==true) this.result[this.result.length]=obj[0];
		}
		this.numg=false;

*/		

	this.select_all = function()
	{
		this.result=null;
		this.result=new Array();
		for(var tl=0; tl<top.tblPlanten.length; tl++) {
			this.result[tl]=tl;
		}
		
		this.numg=false;
	}
	

	this.empty_query();
	this.select_all();
}

