//panoramio
function ycs(id,val,cv) {
	var go = true;
	if (cv) { if (val==null || val=='') { go = false; } }
	if (go) { var myCookie = Cookie.write(id,val,{domain:".dagjeweg.nl"}); }
};
function doG(e) { return document.getElementById(e); }
function initFrontpage(e) {
	iSI(['dq','dqw'],['wat','waar']);
};
function ldScript(fn){
	var script = document.createElement("script");
	script.src = document.location.protocol + fn;
	script.type = "text/javascript";
	document.getElementsByTagName("head")[0].appendChild(script);
};
function gaNaar(urll) { top.location.href = urll; };
function PrintVersion(urll) { var pup=window.open(urll,"Print","toolbar=0,location=0,directories=1,status=1,menubar=1,scrollbars=1,resizable=1,width=690,height=550,left=50,top=50"); pup.focus; };
function switchTab(tabID) {
	if (doG(tabID).style.display == 'none') {
		doG(tabID).style.display = 'block';
	} else {
		doG(tabID).style.display = 'none';
	}
};
function eOpen(elmntId) {
	if (doG(elmntId) != null) {
		doG(elmntId).style.display = 'block';
	}
	return false; 
};
function eClose(elmntId) {
	if (doG(elmntId) != null) {
		doG(elmntId).style.display = 'none';
	}
	return false; 
};
function trim(value) { return value.replace(/^\s+/,'').replace(/\s+$/,''); };
function stdFocus(targetId,stdText,stdColor) {
	var e = targetId;
	if (e.value == stdText) { e.value = ''; }
	e.style.color = stdColor; 
};
function stdLostFocus(targetId,stdText,stdColor) {
	var e = targetId;
	if (trim(e.value) == '' || trim(e.value) == stdText) {
		e.value = stdText;
		e.style.color = stdColor;
	} 
};
function stdSubmit(targetIds,targetValues) {
	var e;
	var stdVal;
	for (i=0; i < targetIds.length; i++) {
		e = doG(targetIds[i]);
		stdVal = targetValues[i];
		if (trim(e.value) == stdVal || trim(e.value) == e.stdValue) {
			e.value = '';
		}
	} 
};
function iSI(idArray,valArray) {
	for (var i = 0; i < idArray.length; i++) {
		e = doG(idArray[i]);	

		if (e != null) {
			e.stdValue = valArray[i];
			e.onfocus = function() { stdFocus(this,this.stdValue,'#000'); };
			e.onblur = function() { stdLostFocus(this,this.stdValue,'#E1E1E1'); };
		}
	}
};
function iSS(idSubmit,valArray,stdArray) {
	e = doG(idSubmit);	
	if (e != null) {
		e.valArray = valArray;
		e.stdArray = stdArray;
		e.onsubmit = function() {
			stdSubmit(this.valArray,this.stdArray);
		};
	};
};
function customizeCalendar(calId) {
	if (calId != null) {
		calId.cfg.setProperty("DATE_FIELD_DELIMITER",".");  

		calId.cfg.setProperty("MDY_DAY_POSITION",1);  
		calId.cfg.setProperty("MDY_MONTH_POSITION",2);  
		calId.cfg.setProperty("MDY_YEAR_POSITION",3);  

		calId.cfg.setProperty("MD_DAY_POSITION",1);  
		calId.cfg.setProperty("MD_MONTH_POSITION",2);  

		calId.cfg.setProperty("MONTHS_SHORT",  ["Jan","Feb","Mar","Apr","Mei","Jun","Jul","Aug","Sep","Okt","Nov","Dec"]);  
		calId.cfg.setProperty("MONTHS_LONG",	["Januari","Februari","Maart","April","Mei","Juni","Juli","Augustus","September","Oktober","November","December"]);  
		calId.cfg.setProperty("WEEKDAYS_1CHAR",["Z","M","D","W","D","V","Z"]);  
		calId.cfg.setProperty("WEEKDAYS_SHORT",["Zo","Ma","Di","Wo","Do","Vr","Za"]);  
		calId.cfg.setProperty("WEEKDAYS_MEDIUM",["Zon","Maa","Din","Woe","Don","Vri","Zat"]);  
		calId.cfg.setProperty("WEEKDAYS_LONG", ["Zondag","Maandag","Dinsdag","Woensdag","Donderdag","Vrijdag","Zaterdag"]);  
	}
	return;
};
function initTabUI(tabs,bgcolor1,bgcolor2,bgcolor3) {
	var tmp;
	var e;

	if (bgcolor1 == null) { bgcolor1 = '#27bdee'; }
	if (bgcolor2 == null) { bgcolor2 = '#fff'; }
	if (bgcolor3 == null) { bgcolor3 = '#000'; }

	for (var j = 0; j < tabs.length; j++) {
		e = doG(tabs[j]);	
		if (e != null) {
			e.tabs = tabs;
	
			e.onmouseover = function () {
				var initFilter = Cookie.read("if");
				if (initFilter == null) {
					for (var j = 0; j < this.tabs.length; j++) {
						e = doG(this.tabs[j]);	
						if (e != null) {
							e.style.backgroundColor = bgcolor2;
							e.style.color = bgcolor3;
							e.style.textDecoration = 'none';
							
							f = doG(e.id+'C');	
							f.style.display = 'none';
						};
					}
	
					this.style.backgroundColor = bgcolor1;
					this.style.color = bgcolor2;
					this.style.textDecoration = 'underline';
	
					e = doG(this.id+'C');	
					if (e != null) {
						ycs("if",this.id);
						e.style.display = 'block';
					}
				} else {
					for (var j = 0; j < this.tabs.length; j++) {
						e = doG(this.tabs[j]);	
						if (e != null) {
							e.style.textDecoration = 'none';
						}
					};
					if (this.style.backgroundColor != bgcolor1) {
						this.style.textDecoration = 'underline';
					}
				}
			};
			
			e.onmouseout = function() {
				this.style.textDecoration = 'none';
			};
	
			e.onclick = function () {
				ycs("if",this.id);
	
				for (var j = 0; j < this.tabs.length; j++) {
					e = doG(this.tabs[j]);	
					if (e != null) {
						e.style.backgroundColor = bgcolor2;
						e.style.color = bgcolor1;
						e.style.textDecoration = 'none';
	
						f = doG(e.id+'C');	
						f.style.display = 'none';
					}
				}
	
				this.style.backgroundColor = bgcolor1;
				this.style.color = bgcolor2;
				this.style.textDecoration = 'none';
	
				e = doG(this.id+'C');	
				if (e != null) {
					e.style.display = 'block';
				}
			};
		}
	}
};
function initTabContentUI(container,tabs,bgcolor1,bgcolor2,bgcolor3) {
	if (bgcolor1 == '') { bgcolor1 = '#27bdee'; }
	if (bgcolor2 == '') { bgcolor2 = '#fff'; }
	if (bgcolor3 == '') { bgcolor2 = '#000'; }

	e = doG(container);	
	if (e != null) {
		e.tabs = tabs;
	
		e.onmouseout = function() {
			var initFilter = Cookie.read("if");
			if (initFilter == null) {
				for (var j = 0; j < this.tabs.length; j++) {
					e = doG(this.tabs[j]);	
					if (e != null) {
						e.style.backgroundColor = bgcolor2;
						e.style.color = bgcolor3;
	
						f = doG(e.id+'C');	
						f.style.display = 'none';
					}
				}
			}
		};
	
		var initFilter = Cookie.read("if");
		e2 = doG(initFilter);
		if (e2 != null) {
			e2.style.backgroundColor = bgcolor1;
			e2.style.color = bgcolor2;
			e2.style.textDecoration = 'none';
	
			f = doG(e2.id+'C');	
			f.style.display = 'block';
		} else {
			Cookie.dispose("if",{domain:".dagjeweg.nl"});
		}
	}
};
function initFaceBook() {
	window.fbAsyncInit = function() {
    	FB.init({
		appId  : '148345218567613',
		status : false,
		cookie : true,
		xfbml  : true,
		channelUrl	: 'http://www.dagjeweg.nl/channel.html'
		});
	};

	(function() {
		var e = document.createElement('script');
		e.async = true;
		e.src = document.location.protocol + '//connect.facebook.net/nl_NL/all.js';
		var fbr = document.getElementById('fb-root');
		if (fbr!=null) {
			fbr.appendChild(e);
		}
	}());
};
function initZoek(e) {
	iSI(['dq','dqw'],['wat','waar']);
	iSS('dagjeuitzoeken',['dq','dqw'],['wat','waar']);
};
function xGetElementsByTagName(t,p){var list=null;t=t||'*';p=p||document;if(typeof p.getElementsByTagName!='undefined'){list=p.getElementsByTagName(t);if(t=='*'&&(!list||!list.length))list=p.all;}else{if(t=='*')list=p.all;else if(p.all&&p.all.tags)list=p.all.tags(t);}return list||new Array();};
function xGetElementsByClassName(c,p,t,f){var r=new Array();var re=new RegExp("(^|\\s)"+c+"(\\s|$)");var e=xGetElementsByTagName(t,p);for(var i=0;i<e.length;++i){if(re.test(e[i].className)){r[r.length]=e[i];if(f)f(e[i]);}}return r;};

function initZFLogicals(logicals,submitId,toelId) {
	var e;
	var zfl;

	for (var j = 0; j < logicals.length; j++) {
		zfl = logicals[j];
		e = doG(zfl);	
		if (e != null) {
			e.zfch = zfl.substr(2);
			e.submitId = submitId;
			e.toelId = toelId;
			e.onclick = function () {
				e = doG(this.zfch);	
				f = doG(this.submitId);
				g = doG(this.toelId);
				if (e != null) { e.checked = false; e.onclick(); this.style.color = '#FFF'; }
				if (f != null) { f.style.display = 'block'; }
				if (g != null) { g.style.display = 'none'; }
			}
		}
	}
};
function initZFNumValues(nums,submitId,toelId) {
	var e;
	var zfn;

	for (var j = 0; j < nums.length; j++) {
		zfn = nums[j];
		e = doG(nums[j]);	
		if (e != null) {
			e.zfch = zfn.substr(2);
			e.submitId = submitId;
			e.toelId = toelId;
			e.onclick = function () {
				e = doG(this.zfch);	
				f = doG(this.submitId);
				g = doG(this.toelId);
				if (e != null) { e.value = ''; e.onchange(); this.style.color = '#FFF'; }
				if (f != null) { f.style.display = 'block'; }
				if (g != null) { g.style.display = 'none'; }
			}
		}
	}
};
function initImitate(targetA,sourceA) {
	for (var j = 0; j < sourceA.length; j++) {
		var s = doG(sourceA[j]);
		var t = doG(targetA[j]);

		if (s != null && t != null) {
			s.imiTarget = targetA[j];
			s.imiSource = sourceA[j];
			s.onchange = function() {
				e = doG(this.imiTarget);
				if (e != null) {
					e.value = this.value;
					f = doG(this.imiTarget+'h');
					g = doG(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++) {
		var s = doG(sourceA[j]);
		var t = doG(targetA[j]);
		var u = doG(klikA[j]);
		var s2 = doG(sourceB[j]);
		var t2 = doG(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 = doG(this.imiTarget);
				f = doG(this.imiSource);
				if (e != null && f != null) {
					if (e.href != null) { e.href = f.innerHTML;
					} else { e.innerHTML = f.innerHTML;
					}
				}
				e = doG(this.imiTarget2);
				f = doG(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 = doG(texts[j]);	

		if (e != null) {
			e.onclick = function () {
				e = doG('clearFilter');	
				if (e != null) { e.style.display = 'inline-block'; }
				e = doG('zfRefresh');	
				if (e != null) { e.style.display = 'inline-block'; }
			}
		}
	}
};
function initNumValues(nums) {
	var tmp;
	var e;

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

			e.onchange = function () {
				Cookie.dispose(this.id,{domain:".dagjeweg.nl"});
				ycs(this.id,this.value,true);
				e = doG('clearFilter');	
				if (e != null) { e.style.display = 'inline-block'; }
				e = doG('zfRefresh');	
				if (e != null) { e.style.display = 'inline-block'; }
			}
		}
	}
};
function initLogicalValues(logicals) {
	var tmp;
	var e;

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

		if (e != null) {
			e.onclick = function () {
				if (this.checked) {
					ycs(this.id,this.value);
					e = doG('clearFilter');	
					if (e != null) { e.style.display = 'inline-block'; }
				} else {
					Cookie.dispose(this.id,{domain:".dagjeweg.nl"});
				}
				e = doG('zfRefresh');	
				if (e != null) { e.style.display = 'inline-block'; }
			}
		}
	}
};
function initClearFilter(resetFilterId,logicals,nums,tabs,texts,filterBox,submitId,verversId,zfToelId) {
	var initFilter = Cookie.read("if");
	var e = doG(resetFilterId);
	var g = doG(filterBox);
	var h = doG(submitId);

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

		e.logicals = logicals;
		e.nums = nums;
		e.tabs = tabs;
		e.texts = texts;
		e.verversId = verversId;
		e.zfToelId = zfToelId;
	
		e.onclick = function() {
			Cookie.dispose("if",{domain:".dagjeweg.nl"});
	
			for (var j = 0; j < this.logicals.length; j++) {
				e = doG(this.logicals[j]);	
				if (e != null) { 
					e.checked = null;
				}
				Cookie.dispose(this.logicals[j],{domain:".dagjeweg.nl"});
			}
	
			for (j = 0; j < this.nums.length; j++) {
				e = doG(this.nums[j]);	
				if (e != null) { 
					e.value = '';
					Cookie.dispose(this.nums[j],{domain:".dagjeweg.nl"});
				}
			}
	
			document.location.reload(true);
		}
	}
};
function initFilterOnOff(onOffId,filterId,submitId) {
	var e = doG(onOffId);

	if (e != null) {
		e.filterId = filterId;
		e.submitId = submitId;
		e.onclick = function() {
			var f = doG(this.filterId);
			var g = doG(this.submitId);
			if (f != null) {
				if (f.style.display != 'block') {
					f.style.display = 'block';
					if (g != null) { 
						//g.style.display = 'none'; 
						if (_gaq != null) {
							_gaq.push(['_trackEvent','Zoekfilter','Aan']);
						}
					}
				} else {
					f.style.display = 'none';
					if (g != null) { 
						g.style.display = 'block';
						if (_gaq != null) {
							_gaq.push(['_trackEvent','Zoekfilter','Uit']);
						}
					}
				}
			}
		}
	} 
};
function initRefreshPage(zfRefreshId) {
	var e = doG(zfRefreshId);

	if (e != null) {
		e.onclick = function() {
			if (_gaq != null) {
				_gaq.push(['_trackEvent','Zoekfilter','RefreshPage']);
			}
			document.location.reload(true);
		}
	}
};
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','chGZA','chLJO','chLKI','chLKL','chLVO','chLGE','chHA','chHAR','chHAG','chHAB','chRO','chRG','chKDE','chKDL'];
	var nums = ['maxbedrag','aantalvolw','aantalkind','kdg','kmd','kjr'];
	var texts = ['dqwg','dqg'];
	var zfLogicals = ['zfchWO','zfchWGO','zfchWB','zfchGR','zfchFR','zfchDR','zfchOV','zfchGE','zfchUT','zfchFL','zfchNH','zfchZH','zfchZE','zfchNO','zfchLI','zfchGKI','zfchGFA','zfchGVR','zfchGVF','zfchGBE','zfchGZA','zfchLJO','zfchLKI','zfchLKL','zfchLVO','zfchLGE','zfchHA','zfchHAR','zfchHAG','zfchHAB','zfchRO','zfchRG'];
	var zfNums = ['zfmaxbedrag','zfaantalvolw','zfaantalkind'];

	initNumValues(nums);
	initLogicalValues(logicals);
	initTextsValues(texts);
	initImitate(['dqw','dq'],texts);
	initTabUI(tabs);
	initTabContentUI('ft',tabs);
	initClearFilter('clearFilter',logicals,nums,tabs,texts,'filter','zoekBtn','zfRefresh','zfToe');
	initRefreshPage('zfRefresh');
	initFilterOnOff('filterOnOff','filter','zoekBtn');
	initZFLogicals(zfLogicals,'zfRefresh','zfToe');
	initZFNumValues(zfNums,'zfRefresh','zfToe');

	// dwleftbar.js
	initK();
};
function changeUIRowA(e) { e.oldColor = e.style.color; };
function restoreUIRowA(e) { e.style.color = e.oldColor; };
function changeUIRow(e) {
    e.onmouseover = function () {
        e.oldBgColor = e.style.backgroundColor;
        e.oldColor = e.style.color;
        e.style.backgroundColor = "#C9E6EE";//EFFBFF";
        var aArray = xGetElementsByClassName('zqRef', e, 'a', changeUIRowA);
    }
    e.onmouseout = function () {
        e.style.backgroundColor = e.oldBgColor;
        e.style.color = e.oldColor;
        //e.style.backgroundImage = "url()";
        var aArray = xGetElementsByClassName('zqRef', e, '', restoreUIRowA);
    }
};
function initZoeken(e) {
    var rowArray = xGetElementsByClassName('zqRow', '', '', changeUIRow);
    rowArray = xGetElementsByClassName('zqRowOdd', '', '', changeUIRow);
};
function loadLatLng() {
	var ipServer = "http://www.dagjeweg.nl/ajax/getGeoIP.php";

	var successHandler = function(rJSON, rText) {
		var j = rText;
		try {
			var i = rJSON;

			var lat = doG('lat');
			var lng = doG('lng');

			if (!lat) {
				lat = document.createElement("span");
				lat.id = 'lat';
				document.body.appendChild(lat);

				lng = document.createElement("span");
				lng.id = 'lng';
				document.body.appendChild(lng);
			}
			lat.title = i.Results.latitude;
			lng.title = i.Results.longitude;
		} catch(e) {}
	}
	var jsonRequest = new Request.JSON({url:ipServer, onSuccess:successHandler}).get();
};
function initCarrousel() {
	if (doG("example_6_content")) {
    	var ex6Carousel = new iCarousel("example_6_content", {  
        	idPrevious: "example_6_previous",  
        	idNext: "example_6_next",  
        	idToggle: "undefined",  
        	item: {  
            	klass: "example_6_item",  
            	size: 686
        	},  
        	animation: {  
            	type: "scroll",  
            	duration: 1500,  
            	amount: 1,
				rotate: {
					type: "auto",
					interval: 4000
				},
        	}  
    	});  
 	 
		for (var i = 0; i<30; i++) {
			var a = 'thumb'+i;
  			if (doG(a)) {
    			$(a).addEvent("click", function(event){
					var i = this.getProperty('title');
					new Event(event).stop();
					ex6Carousel.goTo(i);
				});  
			}
		}
	}
	return;
};
function initK() {
	if (doG('kd')) {
		var td = new Date();
		var minDate = td.getDate()+"."+(td.getMonth()+1)+"."+td.getFullYear();
		var cal1 = new YAHOO.widget.Calendar('kd');
		customizeCalendar(cal1);
		cal1.selectEvent.subscribe(function(p_sType, p_aArgs) {
			var aDate;
			if (p_aArgs) {
				aDate = p_aArgs[0][0];
				var t = doG('kdg'); if (t) { t.value = aDate[2]; ycs('kdg',t.value); }
				var u = doG('kmd'); if (u) { u.value = aDate[1]; ycs('kmd',u.value); }
				var v = doG('kjr'); if (v) { v.value = aDate[0]; ycs('kjr',v.value); }
			}
		});
		cal1.cfg.setProperty("mindate", minDate);
		var y = Cookie.read('kjr');
		var m = Cookie.read('kmd');
		var d = Cookie.read('kdg');
		if (!isNaN(y) && !isNaN(m) && !isNaN(d) && y>10 && y<99 && m>0 && m<13 && d>0 && d<32) {
			var sd = d+"."+m+".20"+y;
			cal1.select(sd);
			cal1.cfg.setProperty("pagedate", m+".20"+y);
		}
		cal1.render();
	}
};
window.addEvent('domready', function() {
	initZoek();
	initOpties();
	initZoeken();
	initCarrousel();
	initFaceBook();
	loadLatLng();
});

