// timer voor opties
YAHOO.util.Event.addListener(window, 'load', initOpties);

function initImitate(targetA, sourceA) {
	for (var j = 0; j < sourceA.length; j++) {
		s = xGetElementById(sourceA[j]);
		t = xGetElementById(targetA[j]);

		if (s != null && t != null) {
			s.imiTarget = targetA[j];
			s.imiSource = sourceA[j];
			s.onchange = function() {
				e = xGetElementById(this.imiTarget);
				if (e != null) {
					e.value = this.value;
					f = xGetElementById(this.imiTarget+'h');
					g = xGetElementById(this.imiSource+'h');
					if (f != null && g != null) {
						f.value = this.value; // als "<imiTarget>h" gevuld, gebruik die waarde voor zoeken
						g.value = ''; // maak "<imiSource>h" leeg
					}
				}
			}
		}
	}
}

function initCopy(targetA, sourceA, targetB, sourceB, klikA) {
    for (var j = 0; j < sourceA.length; j++) {
        s = xGetElementById(sourceA[j]);
        t = xGetElementById(targetA[j]);
        u = xGetElementById(klikA[j]);
        s2 = xGetElementById(sourceB[j]);
        t2 = xGetElementById(targetB[j]);

        if (s != null && t != null && u != null) {
            u.imiTarget = targetA[j];
            u.imiSource = sourceA[j];
            u.imiTarget2 = targetB[j];
            u.imiSource2 = sourceB[j];
            u.onclick = function() {
                e = xGetElementById(this.imiTarget);
                f = xGetElementById(this.imiSource);
                if (e != null && f != null) {
                    if (e.href != null) { e.href = f.innerHTML;
                    } else { e.innerHTML = f.innerHTML;
                    }
                }
                e = xGetElementById(this.imiTarget2);
                f = xGetElementById(this.imiSource2);
                if (e != null && f != null) {
                    if (e.href != null) { e.href = f.innerHTML;
                    } else { e.innerHTML = f.innerHTML;
                    }
                }
            }
        }
    }
}

function initTextsValues(texts) {
	var tmp;
	var e;

	for (var j = 0; j < texts.length; j++) {
		e = xGetElementById(texts[j]);	

		if (e != null) {
			e.onclick = function () {
				e = xGetElementById('clearFilter');	
				if (e != null) { e.style.display = 'inline'; }
				e = xGetElementById('submitBtn');	
				if (e != null) { e.style.display = 'block'; }
			}
		}
	}
}

function initNumValues(nums) {
	var tmp;
	var e;

	for (var j = 0; j < nums.length; j++) {
		tmp = YAHOO.util.Cookie.get(nums[j]);
		e = xGetElementById(nums[j]);	
		if (e != null) {
			e.value = ( (tmp != null && tmp != nums[j]) ? tmp : '');

			e.onchange = function () {
				YAHOO.util.Cookie.remove(this.id, { path: "/", domain: ".daysout.nl" } );
				YAHOO.util.Cookie.set(this.id, this.value, { path: "/", domain: ".daysout.nl" } );
				e = xGetElementById('clearFilter');	
				if (e != null) { e.style.display = 'inline'; }
				e = xGetElementById('submitBtn');	
				if (e != null) { e.style.display = 'block'; }
			}
		}
	}
}

function initLogicalValues(logicals) {
	var tmp;
	var e;

	for (var j = 0; j < logicals.length; j++) {
		tmp = YAHOO.util.Cookie.get(logicals[j]);
		e = xGetElementById(logicals[j]);	
		if (tmp != null) { if (e != null) { e.checked = 'checked'; } }

		if (e != null) {
			e.onclick = function () {
				if (this.checked) {
					YAHOO.util.Cookie.set(this.id, this.value, { path: "/", domain: ".daysout.nl" } );
					e = xGetElementById('clearFilter');	
					if (e != null) { e.style.display = 'inline'; }
				} else {
					YAHOO.util.Cookie.remove(this.id, { path: "/", domain: ".daysout.nl" } );
				}
				e = xGetElementById('submitBtn');	
				if (e != null) { e.style.display = 'block'; }
			}
		}
	}
}

function initClearFilter(resetFilterId, logicals, nums, tabs, texts, filterBox) {
	var initFilter = YAHOO.util.Cookie.get("if");
	var e = xGetElementById(resetFilterId);	
	var g = xGetElementById(filterBox);	

	if (e != null) { 
		for (var j = 0; j < logicals.length; j++) {
			f = xGetElementById(logicals[j]);	
			if (f != null) {
				if (f.checked) { 
					e.style.display = 'block';
				}
			}
		}
	
		for (var j = 0; j < nums.length; j++) {
			f = xGetElementById(nums[j]);	
			if (f != null && f.value != null && f.value != '') { 
				e.style.display = 'block';
			}
		}
	
		if (e.style.display == 'block' && g != null) {
			g.style.display = 'block';
		}

		e.logicals = logicals;
		e.nums = nums;
		e.tabs = tabs;
		e.texts = texts;
	
		e.onclick = function() {
			YAHOO.util.Cookie.remove("if", { path: "/", domain: ".daysout.nl" } );
	
			for (var j = 0; j < this.logicals.length; j++) {
				e = xGetElementById(this.logicals[j]);	
				if (e != null) { 
					e.checked = null;
					YAHOO.util.Cookie.remove(e.id, { path: "/", domain: ".daysout.nl" } );
				}
			}
	
			for (j = 0; j < this.nums.length; j++) {
				e = xGetElementById(this.nums[j]);	
				if (e != null) { 
					e.value = '';
					YAHOO.util.Cookie.remove(e.id, { path: "/", domain: ".daysout.nl" } );
				}
			}
	
			for (j = 0; j < this.texts.length; j++) {
				e = xGetElementById(this.texts[j]);	
				if (e != null && e.id != 'dqg' && e.id != 'dqwg') { e.value = ''; }
			}
	
			for (j = 0; j < this.tabs.length; j++) {
				e = xGetElementById(this.tabs[j]);	
				if (e != null) {
					e.style.backgroundColor = '#fff';
					e.style.color = '#000';
					e.style.textDecoration = 'none';
	
					f = xGetElementById(e.id+'C');	
					f.style.display = 'none';
				}
			}
	
			f = xGetElementById('submitBtn');	
			if (f != null) { f.style.display = 'block'; }
	
			this.style.display = 'none';
		}
	}
}

function initFilterOnOff(onOffId, filterId) {
	var e = xGetElementById(onOffId);

	if (e != null) {
		e.filterId = filterId;
		e.onclick = function() {
			var f = xGetElementById(this.filterId);
			if (f != null) {
				if (f.style.display != 'block') {
					f.style.display = 'block';
				} else {
					f.style.display = 'none';
				}
			}
		}
	}
}

function initGZ() {
/* 1.4.2009 loze functie? */
	var e = xGetElementById('gz');	

	if (e != null) {
		e.onclick = function() {
			var e = xGetElementById('eropuit-filter');	
			if (e != null) {
				if (e.style.display == 'none') {
					e.style.display = 'block';
				} else {
					e.style.display = 'none';
				}
			}
		}
	}
}

function initOpties(e) {
	var tabs = ['tabWeer','tabGeo','tabGroepen','tabDoelg','tabHandicap','tabRubriek'];
	var logicals = ['chWO','chWGO','chWB','chGR','chFR','chDR','chOV','chGE','chUT','chFL','chNH','chZH','chZE','chNO','chLI','chGKI','chGFA','chGVR','chGVF','chGBE','chLJO','chLKI','chLKL','chLVO','chLGE','chHA','chHAR','chHAG','chHAB','chRO'];
	var nums = ['maxbedrag','aantalvolw','aantalkind'];
	var texts = ['dqwg','dqg'];

	initNumValues(nums);
	initLogicalValues(logicals);
	initTextsValues(texts);
	initImitate(['dqw','dq'], texts);
	initTabUI(tabs);
	initTabContentUI('filtertab', tabs);
	initClearFilter('clearFilter', logicals, nums, tabs, texts, 'filter');
	initFilterOnOff('filterOnOff', 'filter');
	initGZ();

	// dwleftbar.js
	initStdInput(['dqg','dqwg'],['what','where']);
	initStdSubmit('geavanceerdzoeken',['dqg','dqwg'],['what','where']);
}
