<!--
// @@@
// @@ Author: Bas van Dorst
// @@ Date: 2007-02-27
// @@ Last change: 2007-02-27
// @@ Version: 1
// @@ Revision: 0
// @@ Copyright: Ecommany B.V.
// @@ Description: JS: zoek trefwoorden
// @@$

// dit bestand bevat code die alleen gebruikt wordt voor het snelselectie lijstje van de aanwezige 
// trefwoorden in het formulier van de wie wat waar
var jsShowDiv = '';
var bTest = 0;

// onderstaande functie heeft dezelfde naam als een reeds aanwezige functie. Wordt onderstaande nog
// wel gebruikt (kan nergens een aanroep vinden?!) -> hernoemd naar swapImg2
function swapImg2(jsId,jsImg) {
	document.images[jsId].src = jsImg;
}

function getLeft(jsObj) {
	var posX = 0;
	var scrollObj = jsObj;
	if (jsObj.offsetParent) {
		while (jsObj.offsetParent) {
			posX+= jsObj.offsetLeft;
			jsObj = jsObj.offsetParent;
		} // while
		while (scrollObj.tagName!='DIV' && scrollObj.offsetParent) 
			scrollObj = scrollObj.offsetParent;
		if (scrollObj.tagName=='DIV') 
			posX-=scrollObj.scrollLeft;
	} else if (jsObj.x)
		posX = jsObj.x;
	return posX;
} // function getLeft

function getTop(jsObj) {
	var posY = 0;
	var scrollObj = jsObj;
	if (jsObj.offsetParent) {
		while (jsObj.offsetParent) {
			posY+= jsObj.offsetTop;
			jsObj = jsObj.offsetParent;
		} // while
		while (scrollObj.tagName!='DIV' && scrollObj.offsetParent) 
			scrollObj = scrollObj.offsetParent;
		if (scrollObj.tagName=='DIV') 
			posY-=scrollObj.scrollTop;
	} else if (jsObj.y)
		posY = jsObj.y;
	return posY;
} // function getTop

function getHeight(jsObj) {
	h=0;
	if (jsObj.clip) 
		h=jsObj.clip.height;
	else if(jsObj.style.pixelHeight) 
		h=jsObj.style.pixelHeight;
	else 
		h=jsObj.offsetHeight;
	return h;
} // function getHeight

function getWidth(jsObj) {
	h=0;
	if (jsObj.clip) 
		h=jsObj.clip.width;
	else if(jsObj.style.pixelWidth) 
		h=jsObj.style.pixelWidth;
	else 
		h=jsObj.offsetWidth;
	return h;
} // function getWidth

function setLeft(jsObj,x) {
	if (jsObj.clip) 
		jsObj.clip.left=x;
	else if(jsObj.style.pixelLeft) 
		jsObj.style.pixelLeft=x;
	else 
		jsObj.style.left=x+'px';
} // function setLeft

function setTop(jsObj,y) {
	if (jsObj.clip) 
		jsObj.clip.top=y;
	else if(jsObj.style.pixelTop) 
		jsObj.style.pixelTop=y;
	else 
		jsObj.style.top=y+'px';
} // function setTop

function setHeight(jsObj,h) {
	if (jsObj.clip) 
		jsObj.clip.height=h;
	else if(jsObj.style.pixelHeight) 
		jsObj.style.pixelHeight=h;
	else 
		jsObj.style.height=h+'px';
} // function setHeight

function setWidth(jsObj,w) {
	if (jsObj.clip) 
		jsObj.clip.width=w;
	else if(jsObj.style.pixelWidth) 
		jsObj.style.pixelWidth=w;
	else 
		jsObj.style.width=w+'px';
} // function setWidth

function hideDiv(jsObj) {
	if (jsObj.style) 
		jsObj.style.visibility='hidden';
	else 
		jsObj.visibility='hide';
	
	if (jsShowDiv!='' && jsShowDiv==jsObj.id) {
		document.getElementById('hideForm').style.display = "none";
		jsShowDiv = '';
	} // if
} // function hideDiv

function showDiv(jsObj) {
	if (jsShowDiv!='' && jsObj.id!=jsShowDiv && jsShowDiv.substr(0,5)!='kaart' || (jsShowDiv.substr(0,5)=='kaart' && jsObj.id.substr(0,5)=='kaart')) 
		hideDiv(document.getElementById(jsShowDiv))
	jsShowDiv = jsObj.id;
	
	if (jsObj.id.substr(0,5)!='kaart') {
		IfrRef = document.getElementById('hideForm');
		setWidth(IfrRef,getWidth(jsObj));
		if (jsObj.className=='smartselect') 
			setHeight(IfrRef,getHeight(jsObj)+2);
		else 
			setHeight(IfrRef,getHeight(jsObj));

		if (jsObj.scrollTop!= null && jsObj.scrollTop!= 0) 
			setTop(IfrRef,getTop(jsObj)+jsObj.scrollTop);
		else 
			setTop(IfrRef,getTop(jsObj));
			
		if (jsObj.scrollLeft!= null && jsObj.scrollLeft!= 0) 
			setLeft(IfrRef,getLeft(jsObj)+jsObj.scrollLeft);
		else setLeft(IfrRef,getLeft(jsObj));
			IfrRef.style.display = "block";
	}
	
	if (jsObj.style) 
		jsObj.style.visibility='visible';
	else 
		jsObj.visibility='show';
} // function showDiv


function selectZoek(jsVeldNaam) {
	this.aAllOptions = new Array();
	this.aShowOptions = new Array();
	this.jsVeldNaam= jsVeldNaam;
	this.index = -1;
	this.bKeyAction = false;
	this.timerId = null;
	this.extra = null;

	this.readOptions = function() {
		frmObj = eval('document.frmOpties.'+this.jsVeldNaam);
		frmId = frmObj.value
		
		jsHtml = document.getElementById('div_'+this.jsVeldNaam).innerHTML;
		re = /<br[ \/]*>\s*/gi;
		aLinks = jsHtml.split(re);
		iMax = aLinks.length;
		//iMax = 100;
		re = /selectOption\(([^\)]*)\)">([^<]*)/i;
		for (i=0;i<iMax;i++) {
			if (re.test(aLinks[i])) {
				myArray = re.exec(aLinks[i]);
				this.aAllOptions[i] = new Array();
				this.aAllOptions[i][0] = myArray[1];
				this.aAllOptions[i][1] = myArray[2];
				this.aShowOptions[i] = this.aAllOptions[i];
				if (myArray[1]==frmId) this.index = i;
			} // if
		} // for
	} // function

	this.showList = function(jsObj,divH,divW) {
		setLeft(document.getElementById('div_'+this.jsVeldNaam),getLeft(jsObj));
		setTop(document.getElementById('div_'+this.jsVeldNaam),getTop(jsObj)+20);
		setHeight(document.getElementById('div_'+this.jsVeldNaam),divH);
		setWidth(document.getElementById('div_'+this.jsVeldNaam),divW);
		showDiv(document.getElementById('div_'+this.jsVeldNaam));
	}

	this.hideList = function() {
		frmObj = eval('document.frmOpties.'+this.jsVeldNaam);
		if (this.index==-1) {
//			frmObj.value='';
//			frmObj = eval('document.frmOpties.txt_'+this.jsVeldNaam);
//			frmObj.value='';
		} else {
//			frmObj.value=this.aShowOptions[this.index][0];
//			frmObj = eval('document.frmOpties.txt_'+this.jsVeldNaam);
//			frmObj.value=this.aShowOptions[this.index][1];
		} // if
		frmObj.blur();
		if (this.extra!=null) 
			this.extra();
		jsStr = 'hideDiv(document.getElementById(\'div_'+this.jsVeldNaam+'\'))';
		this.timerId = setTimeout(jsStr,200);
	}

	this.clearTimer = function() {
		if (this.timerId!=null) 
			clearTimeout(this.timerId);
	}

	this.setOption = function() {
		if (!this.bKeyAction) {
			re = /(\(|\)|\[|\]|\*|\+|\?|\^|\$|\||\\|\.|\/)/g;
		
			frmObj = eval('document.frmOpties.txt_'+this.jsVeldNaam);
			txt = frmObj.value;
			if (txt=='maak uw keuze') {
				frmObj.value = '';
				txt='';
			} // if
			txt_length = txt.length;
		
			txt = txt.replace(re,"\\$1");
			sRegExp = '^'+txt+'.*';
			re= new RegExp(sRegExp,'i');
		
			this.aShowOptions = new Array();
			jsHtml = '';
			this.index = -1;
			iMax = this.aAllOptions.length;
			j=0;
			for (i=0;i<iMax;i++) {
				if (re.test(this.aAllOptions[i][1])) {
//					jsHtml+= '<a href="javascript:js_'+this.jsVeldNaam+'.selectOption('+this.aAllOptions[i][0]+')">';
					jsHtml+= '<a href="javascript:js_'+this.jsVeldNaam+'.selectOption(\''+this.aAllOptions[i][1]+'\')">';
					if (j==0 && txt_length>0) {
						 jsHtml+= '<span id="selOptie_'+this.jsVeldNaam+'" class="selectedOption">';
						 this.index=0;
					} // if
					jsHtml+= this.aAllOptions[i][1];
					if (j==0 && txt_length>0) 
						jsHtml+= '</span>';
					jsHtml+= '</a>';
					if (j!=0 || txt_length==0) 
						jsHtml+= '<br />';
					this.aShowOptions[j] = this.aAllOptions[i]
					j++;
				} // if
			} // for
			document.getElementById('div_'+this.jsVeldNaam).innerHTML = jsHtml;
			if (txt_length>0 && jsHtml!='') 
				// document.getElementById('selOptie_'+this.jsVeldNaam).scrollIntoView(true);
				document.getElementById('selOptie_'+this.jsVeldNaam).scrollIntoView(false);
		} else 
			this.bKeyAction=false;
	} // function

	this.setDiv = function(aNewOptions) {
		iMax = aNewOptions.length;
		frmObj = eval('document.frmOpties.'+this.jsVeldNaam);
		this.index=-1;
		for (i=0;i<iMax;i++) 
			if (aNewOptions[i][0]==frmObj.value) this.index=i;
		if (this.index==-1) {
			frmObj.value='';
			frmObj = eval('document.frmOpties.txt_'+this.jsVeldNaam);
			frmObj.value='maak uw keuze';
		} // if
		this.aAllOptions = aNewOptions;
		this.setOption();
	} // function

	this.selectOption = function(jsId) {
		if (this.timerId!=null) 
			clearTimeout(this.timerId);
		
		iMax = this.aShowOptions.length;
		this.index=-1;
		for (i=0;i<iMax;i++) 
			if (this.aShowOptions[i][0]==jsId) 
				this.index=i;

		this.hideList();
		// smerig stukje wat de waarde van de input box in de hidden input gooit
		document.getElementById('vulbox_vis').value=jsId;
		document.getElementById('vulbox').value=document.getElementById('vulbox_vis').value;

	
	} // function

	this.keyUp = function() {
		iMax = this.aShowOptions.length;
		if (this.index>0) {
			this.index--;
			jsHtml = '';
			for (i=0;i<iMax;i++) {
				jsHtml+= '<a href="javascript:js_'+this.jsVeldNaam+'.selectOption('+this.aShowOptions[i][0]+')">';
				if (i==this.index) 
					jsHtml+= '<span id="selOptie_'+this.jsVeldNaam+'" class="selectedOption">';
				jsHtml+= this.aShowOptions[i][1];
				if (i==this.index) 
					jsHtml+= '</span>';
				jsHtml+= '</a>';
				if (i!=this.index) 
					jsHtml+= '<br />';
			} // for
			frmObj = eval('document.frmOpties.'+this.jsVeldNaam);
			frmObj.value=this.aShowOptions[this.index][0];
			frmObj = eval('document.frmOpties.txt_'+this.jsVeldNaam);
			frmObj.value=this.aShowOptions[this.index][1];
			document.getElementById('div_'+this.jsVeldNaam).innerHTML = jsHtml;
			// document.getElementById('selOptie_'+this.jsVeldNaam).scrollIntoView(true);
			document.getElementById('selOptie_'+this.jsVeldNaam).scrollIntoView(false);
		} // if
		this.bKeyAction = true;
	} // function

	this.keyDown = function() {
		iMax = this.aShowOptions.length;
		if (this.index<iMax-1) {
			this.index++;
			jsHtml = '';
			for (i=0;i<iMax;i++) {
				jsHtml+= '<a href="javascript:js_'+this.jsVeldNaam+'.selectOption('+this.aShowOptions[i][0]+')">';
				if (i==this.index) 
					jsHtml+= '<span id="selOptie_'+this.jsVeldNaam+'" class="selectedOption">';
				jsHtml+= this.aShowOptions[i][1];
				if (i==this.index) 
					jsHtml+= '</span>';
				jsHtml+= '</a>';
				if (i!=this.index) 
					jsHtml+= '<br />';
			} // for
			frmObj = eval('document.frmOpties.'+this.jsVeldNaam);
			frmObj.value=this.aShowOptions[this.index][0];
			frmObj = eval('document.frmOpties.txt_'+this.jsVeldNaam);
			frmObj.value=this.aShowOptions[this.index][1];
			document.getElementById('div_'+this.jsVeldNaam).innerHTML = jsHtml;
			document.getElementById('selOptie_'+this.jsVeldNaam).scrollIntoView(false);
		} // if
		this.bKeyAction = true;
	} // function

	this.keyEnter = function() {
		this.hideList();
	} // function

	this.keyEvent = function(e) {
		if (window.event!=null) 
			nKey = window.event.keyCode;
		else 
			nKey = e.which;
		if (nKey==13) this.keyEnter();
		if (nKey==38) this.keyUp();
		if (nKey==40) this.keyDown();
	} // function

	this.readOptions();
} // function selectZoek
//-->