// JavaScript Document
function btnOver (elem) {
	var anchorElement = elem.getElementsByTagName("a")[0];
	if (anchorElement) {
		var imgElement = anchorElement.getElementsByTagName("img")[0];
		if (imgElement) {
			var filename = imgElement.src.replace(/(_over)?\.(gif|jpe?g|png|php)$/i,"_over.$2");
			imgElement.setAttribute("src",filename);
		}
	}
}

function btnOut (elem) {
	var anchorElement = elem.getElementsByTagName("a")[0];
	if (anchorElement) {
		var imgElement = anchorElement.getElementsByTagName("img")[0];
		if (imgElement) {
			imgElement.setAttribute("src",imgElement.getAttribute("src").replace(/_over/i,""));
		}
	}
}

function sfHover() {
	var sfEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() { this.className+=" ie_does_hover"; }
		sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" ie_does_hover\\b"), ""); }
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function toggleShowroomDropdown () {
	var ddContainer = document.getElementById("showroomDropdown");
	if (ddContainer.style.left != '0px')
		ddContainer.style.left = '0px'
	else
		ddContainer.style.left = '-999px';
}
function selectShowroomDropdown(id) {
	var ddSelectBox = document.getElementById("selectbox");
	var ddContainer = document.getElementById("showroomDropdown");
	var ddVestiging = document.getElementById("vestiging_"+id);
	var ddInput     = document.getElementById("plaats_start");
	ddSelectBox.value = ddVestiging.innerHTML;
	ddInput.value     = ddVestiging.innerHTML;
	ddContainer.style.left = '-999px';
}


function showMeerInformatie () {
	if (document.getElementById("meerInformatieBlok").className == "meerInformatieBlok hide") {
		document.getElementById("meerInformatieBlok").className = "meerInformatieBlok show"
		document.getElementById("meerInformatieBtn").src = "/siteimg/meer_informatie_dicht.gif"
	} else {
		document.getElementById("meerInformatieBlok").className = "meerInformatieBlok hide"
		document.getElementById("meerInformatieBtn").src = "/siteimg/meer_informatie.gif"
	}
}

function showInloggen () {
	if (document.getElementById("inloggen").className == "hide") {
		document.getElementById("inloggen").className = "show";
		document.getElementById("registreren").className = "hide";
		document.getElementById("inloggenBtn").style.color = "#102b72";
		document.getElementById("registrerenBtn").style.color = "#FFF";
	}
}

function showRegistreren () {
	if (document.getElementById("registreren").className == "hide") {
		document.getElementById("registreren").className = "show";
		document.getElementById("inloggen").className = "hide";
		document.getElementById("inloggenBtn").style.color = "#FFF";
		document.getElementById("registrerenBtn").style.color = "#102b72";
	}
}

function getProductBladerPagina(gid, pag) {
	var url = '/ajax_productbladeren.php?groepid=' + gid + '&pagina=' + pag + "&referer=" + encodeURIComponent(window.location.href);
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
		$('productBladeren').innerHTML = transport.responseText;
		}
	});
}
function getProductBladerPaginaTijdelijk(pag) {
	var url = '/ajax_productbladerentijdelijk.php?pagina=' + pag + "&referer=" + encodeURIComponent(window.location.href);
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
		$('productBladeren').innerHTML = transport.responseText;
		}
	});
}

function voegFavorietToe(id, type) {
	var url = '/ajax_addfavo.php?pid=' + id + '&type=' + type + '&referer=' + window.location.href;
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
			location.reload();
		}
	});
}

function deleteFavoriet(id, type) {
	var url = '/ajax_delfavo.php?pid=' + id + '&type=' + type + '&referer=' + window.location.href;
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
			location.reload();
		}
	});
}

function addNieuwsbrief(email) {
	var url = '/ajax_addnieuwsbrief.php?email=' + encodeURIComponent(email);
	
	if (!email.match(/^[a-z0-9_\-]+(\.[_a-z0-9\-]+)*@([_a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel)$/i)) {
		alert("U dient een geldig e-mail adres in te vullen");
	} else {
		new Ajax.Request(url, {
			method: 'get',
			onSuccess: function(transport) {
				alert("U bent aangemeld voor de nieuwsbrief.");
			}
		});
	}
	return false;
}


function submitRegistreerForm () {
	data = $('registrerenForm').serialize(true);
	new Ajax.Request($('registrerenForm').action, {
		method: 'get',
		parameters: data,
		onSuccess: function(transport) {
			if(transport.responseText.match(/error/)){
				error = transport.responseText.split("||");
				alert(error[1]);
			} else {
				alert("Uw registratie is gelukt. U krijgt binnen enkele ogenblikken uw wachtwoord per email.");
				window.location.reload();
			}
		}
	});
}


function submitLoginForm () {
	data = $('loginForm').serialize(true);
	new Ajax.Request($('loginForm').action, {
		method: 'get',
		parameters: data,
		onSuccess: function(transport) {
			if(transport.responseText.match(/error/)){
				error = transport.responseText.split("||");
				alert(error[1]);
			} else location.reload()
		}
	});
}

function checkPersoonlijkVerleider() {
	if (document.persoonlijkverleider.persoonlijk_naam.value.match(/[0-9\s]/)) {
		alert("U mag enkel letters gebruiken.");
		return false;
	} else {
		return true;
	}
}

function uitloggen() {
	var url = '/ajax_persoonlijk_uitloggen.php';
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
			alert("U bent uitgelogd.");
			window.location.href="/Persoonlijk";
		}
	});
	return false;
}

/* KALENDER */

function bindAsEventListener(func,object,args) {
	return function(event) { return func.apply(object, [event].concat(args)); }
}
function AjaxCalendar(container) {
	this.date  = new Date();
	this.year  = this.date.getFullYear();
	this.month = this.date.getMonth()+1;
	this.day   = this.date.getDate();
	this.dow   = this.date.getDay();
	this.container = container;
	this.setCalendar();
	this.getOverviewDate(this.day);
}
AjaxCalendar.prototype.setCalendar = function() {
	new Ajax.Request("/ajax_calendar_set.php", {
		method: 'post',
		parameters: "month="+this.month+"&year="+this.year,
		onSuccess: bindAsEventListener(function(transport){this.container.innerHTML=transport.responseText;},this,[])
	});
}
AjaxCalendar.prototype.prevMonth = function() {
	this.date.setMonth(this.month-2);
	this.year  = this.date.getFullYear();
	this.month = this.date.getMonth()+1;
	this.day   = this.date.getDate();
	this.dow   = this.date.getDay();
	this.setCalendar();
}
AjaxCalendar.prototype.nextMonth = function() {
	this.date.setMonth(this.month);
	this.year  = this.date.getFullYear();
	this.month = this.date.getMonth()+1;
	this.day   = this.date.getDate();
	this.dow   = this.date.getDay();
	this.setCalendar();
}
AjaxCalendar.prototype.getOverviewDate = function(day) {
	new Ajax.Request("/ajax_calendar_getkzbydate.php", {
		method: 'post',
		parameters: "day="+day+"&month="+this.month+"&year="+this.year,
		onSuccess: bindAsEventListener(function(transport){document.getElementById("bydate").innerHTML=transport.responseText;},this,[])
	});
}
AjaxCalendar.prototype.getOverviewLoc = function(vid) {
	new Ajax.Request("/ajax_calendar_getkzbylocation.php", {
		method: 'post',
		parameters: "vid="+vid,
		onSuccess: bindAsEventListener(function(transport){document.getElementById("bylocation").innerHTML=transport.responseText;},this,[])
	});
}



