/*Html*/
Html=function(){
	this.uitvoeren=function(obj,str){
		var u ="",param
		if(str){
		var arr=str.match(/\$\w+/g)
			if(arr){
				for(var i=0;i<arr.length;i++){
					param=arr[i].substr(1)
					try{
					str = str.replace(eval("/\\\$"+param+"/g"),obj(param))
					} catch(e){}
				}
			}
		return str
		}
	return ""
	}
	this.repeat=function(o,str,max){
		var length=(o.count||o.recordcount||o.length)
		max=(!max||max>length)?length:max
		var output=""
		if(o.count){for(var i=0;i<max;i++){output += this.uitvoeren(o,str)}}
		else if(o.recordcount){if(o.eof){return ""};for(var i=0;i<max;i++){output += this.uitvoeren(o,str);o.movenext()}}
		else if(o.length){for(var i=0;i<max;i++){output+=this.uitvoeren(o,str)}}
		return output
	}
	this.tag=function(id,a){
		var str = "<"+id+(a[0]?" "+a[0]:"")+">"
		if(!id.match(/^img|br|input$/))str+=(a[1]||"")+"<"+"/"+id+">"
		return str
	}
	this.param=[]
	this.addparam=function(a,ispreset){
		a=ispreset?a.replace(/(=)([^ ]+)?/gi,'$1"$2"'):a.replace(/(=)(.+)/gi,'$1"$2"')
		this.param[this.param.length]=a
	}
	this.getparam=function(){var a=this.param.join(" ");this.param=[];return a}
	this.read=function(args,presets){
		var temp,content="",key,naam,size,quot="'"
		var re=/^\w+\s*=\s*[^<>=]+|^nowrap/
		for(var i=0;i<args.length;i++){
			args[i]=String(args[i]).replace(/\s*=\s*/g,"=")//.replace(eval("/"+quot+"/g"),"\\'")// ruimtes bij issen weg
			if(args[i].match(re)){/*het is een parameter*/
				temp=args[i].split(/&/)// was ;|&
				inner:for(var j=0;j<temp.length;j++){
					if(presets){
						if(presets.indexOf(naam=temp[j].match(/^\w+=/))!=-1){
							presets=presets.replace(eval("/"+naam+"\\w+/"),temp[j])
							continue inner
						}
					}
					this.addparam(temp[j])
				}
			}
			else {content+=args[i]}
		}
		if(presets){this.addparam(presets,true)}
		return [this.getparam(),content]
	}
	var lijst=[["a"],["b"],["i"],["u"],["br"],["img","border=0"],["table","border=0 cellpadding=0 cellspacing=0"],["td"],["tr"],["span"],["div"],["p"],["form"],["option"],["select"],["input"],["button"],["textarea"],["li"],["ol"],["ul"],["dl"],["dd"],["dt"],["sub"],["sup"],["script","language=javascript"],["xmp"],["link"],["style","type=text/css"],["frame"],["frameset"],["iframe"],["body"],["html"],["head"],["title"]]
	for(var i=0;i<lijst.length;i++){var a=lijst[i]
		this[a[0]]=Function("return this.tag('"+a[0]+"',this.read(arguments,'"+(a[1]||"")+"'))")
	}	
}
/*EINDE HTML*/
/*onloadhandler*/
addonload=function(anonymusfunc){
	var c = /(^\s*function\s*\w*\s*\([^\)]*\)\s*\{)|(\s*}\s*$)/g
	var f 	= String(anonymusfunc).replace(c,"")
	var o 	= String(window.onload).replace(c,"")
	window.onload = Function (o+";\n"+f)
}

/*
voor het gebruik van een tooltip bij de infoknop kan geen onload worden gebruikt om de 
opties weg te schrijven: gebruik hiervoor een document.write.
voeg toe onder in de pagina...
language="JavaScript" src="scripts/wz_tooltip.js"
zo bouw je een element op : 
element([elementid],elementtype,text_titel,text_info,text_reset)).inlezen([optielijst])
- tooltipdefinitie=text_info
	"onmouseover=return escape(str)"
	str is hier een aparte string met daarin tekst of html (zie beschrijving bij tooltipscript)
- elementtype kan zijn: select of tekst
VOLGENDE STIJLELEMENTEN WORDEN GEBRUIKT...
	select.waarde{}
	span.waarde{}
	span.titel{}
	td.titel,td.info,td.waarde,td.reset{}
	span.info, a.info{}
	a.reset{}
	a.waarde{}
VOLGENDE METHODEN KUNNEN WORDEN GEBRUIKT
	inlezen(LIJST)
	setfilter(LIJST)
	filteropheffen()
	tonen(BOOLEAN)
	selecteer
VOLGENDE FUNCTIE IS TE GEBRUIKEN VOOR INTERACTIE
	selectaction

*/

/*ElementClass*/
var ElementClass=function(id,type,text_titel,text_info,text_reset){
	this.id=id
	this.ingelezenlijst	=[]
	this.filter			=[]
	this.img_info		="images/info.gif"
	this.text_selectie	=""
	this.waarde=""
	this.text_titel		=text_titel||id
	this.text_info		=text_info||""
	this.text_reset		=text_reset||"reset"
	this.style_elmid	="waarde"
	this.style_reset	="reset"
	this.style_titel	="titel"
	this.style_info		="info"
	this.elementtype=type||"select"
	this.statusleeg		=false
	this.options=[]
	this.inlezen=function(lijst){
		this.ingelezenlijst=lijst
		this.filter=[]
	}
	// filter op tekstwaarden
	this.setfilter=function(lijst){
		
		this.filter=[]
		for(var i=0;i<lijst.length;i++){
        	this.filter[lijst[i]]=true
        }
		str=""
		//for (var i in this.filter){str += i+" "};alert(str)
	}
	// zet het filter uit voor dit element
	this.filteropheffen=function(){this.filter=[]}
	this.reset=function(){
		this.text_selectie = ""
		this.waarde = ""
	}
	// toon dit element wel of niet
	this.tonen=function(type,schrijven){
		var elm=document.getElementById("element_"+this.id)
		if(elm){
			if(type==false&&elm.style.display!="none"){
				elm.style.display="none"
			}
			else if(type==true){
				elm.style.display=""
				if(schrijven)this.writeelement()
			}
		}
	}
	this.getelementhtml=function(){
		var outputstr="",optionstr="",o,s
		var elmstyle="class="+this.style_elmid
		var t=this.elementtype,waarde,str,strinfo,teller=0
		this.statusleeg=false
		with(new Html()){
			if(this.text_info){
				strinfo=a("class="+this.style_info,
				"href=javascript:void(0)",
				this.text_info,img("src="+this.img_info))
			}
			else{
				strinfo=span("class="+this.style_info,"&nbsp;")
			}
			if(!this.text_selectie){
					switch(t){ 
		        	case "select" :
						optionstr=[]
						for(var i=0;i<this.ingelezenlijst.length;i++){
							if(this.filter[this.ingelezenlijst[i]]){continue}
							waarde=this.ingelezenlijst[i]
		                  optionstr[optionstr.length]=[option(waarde)]
		                }
						if(!optionstr.length){
							str = span(elmstyle,"niet van toepassing")
							this.statusleeg=true
						}
						else{str = select(elmstyle,
							"id=select_"+this.id,
							"onchange=element('"+this.id+"').selecteer()",
							option()+optionstr.join(""))}
		        	break
					case "tekst" :
						optionstr=[]
						for(var i=0;i<this.ingelezenlijst.length;i++){
							if(this.filter[this.ingelezenlijst[i]]){continue}
							waarde=this.ingelezenlijst[i]
							optionstr[optionstr.length]=a(elmstyle,waarde,"href=javascript:element('"+
							this.id+"').selecteer('"+waarde+"')")
		                }
						if(!optionstr.length){
							str = span(elmstyle,"niet van toepassing")
							this.statusleeg=true
						}
						else{str = optionstr.join("&nbsp;/&nbsp;")}
		        	break
		        }//switch
			// maak element zonder reset
				if(optionstr.length==1){
					this.waarde=waarde
					str = tr(
					td("class="+this.style_titel,span("class="+this.style_titel,this.text_titel)),
					td("class=info",strinfo),
					td("class="+this.style_elmid,span("class="+this.style_elmid,waarde)),
					td("class="+this.style_reset,span("class="+this.style_reset))
					)
				}else{
					str = tr(
					td("class="+this.style_titel,span("class="+this.style_titel,this.text_titel)),
					td("class=info",strinfo),
					td("class="+this.style_elmid,span("class="+this.style_elmid,str)),
					td("class="+this.style_reset,span("class="+this.style_reset))
					)
				}
			}
			// maak element mèt reset
			else{
				str = tr(
				td("class="+this.style_titel,span("class="+this.style_titel,this.text_titel)),
				td("class=info",strinfo),
				td("class="+this.style_elmid,span("class="+this.style_elmid,this.text_selectie)),
				td("class="+this.style_reset,a("href=javascript:element('"+
							this.id+"').selecteer()","class="+this.style_reset,this.text_reset))
				)
			}
		return table(str)
		}//html
	}
	// selecteeractie bij aanklikken van gebruikerselement
	this.selecteer=function(str,hold){
		var elm,waarde
		if(!this.text_selectie){
			if(this.elementtype=="select"){
				elm = document.getElementById("select_"+this.id)
				waarde=elm[elm.selectedIndex].text
			}else{waarde=str}
			this.text_selectie = waarde
			this.waarde = waarde
		}
		else{this.text_selectie="";this.waarde=""}
		this.writeelement()
		if(typeof tt_Init!="undefined"){tt_Init(true)}
		if(hold==true){return}
		this.selectaction()
	}
	// schrijf element weg in de pagina
	this.writeelement=function(ret){
		var elm=document.getElementById("element_"+this.id)
		if(elm)elm.innerHTML=this.getelementhtml()
	}
}
ElementClass.prototype.selectaction=function(){}
var element=function(id,type,text_titel,text_info,text_reset){
	if(typeof _elementobjecten=="undefined"){_elementobjecten=[]}
	if(!_elementobjecten[id]){
	_elementobjecten[id] = new ElementClass(id,type,text_titel,text_info,text_reset)
	addonload("element('"+id+"').writeelement()")
	}
	return _elementobjecten[id]
}
