jQuery.fn.fadeIn = function (speed, callback) {
	//	if(typeof console!="undefined") console.log("fadein");
	return this.animate({ opacity: 'show' }, speed, function () {
		if (jQuery.browser.msie)
			this.style.removeAttribute('filter');
		if (jQuery.isFunction(callback))
			callback();
	});
};


var addEvent = function (obj, type, fn) {
	if (obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent)
		obj.attachEvent('on' + type, function () { return fn.apply(obj, new Array(window.event)); });
}

var website = function () {
	{
		var checkInputField, getQueryVariable;
		var initOnLoad;
		var initLoginBox;
		var initFormValidation;
		var toonDatumVanVandaag = function (sId) {
			if (!document.getElementById(sId))
				return;
			var now = new Date();
			var date = ((now.getDate() < 10) ? "0" : "") + now.getDate();
			var month = now.getMonth() + 1;
			function fourdigits(number) {
				return (number < 1000) ? number + 1900 : number;
			}
			today = date + "-" + ((month < 10) ? "0" : "") + month + "-" + (fourdigits(now.getYear()));
			document.getElementById(sId).innerHTML = today.toString();
		}
		
		
		checkInputField = function (id, value) {
			if (!document.getElementById(id))
				return;
			var el = document.getElementById(id).getElementsByTagName("input")[0];
			if (el.value == '') el.value = value;

			addEvent(el, "focus", function () {
				if (this.value == value) {
					this.value = '';
					this.className = "active";
				}
			});
			addEvent(el, "blur", function () {
				if (this.value == '') {
					this.value = value;
					this.className = "";
				}
			});
		}
		getQueryVariable = function (variable) {
			var query = window.location.search.substring(1);
			var vars = query.split("&");
			for (var i = 0; i < vars.length; i++) {
				var pair = vars[i].split("=");
				if (pair[0] == variable) {
					return pair[1];
				}
			}
			return;
		}
		initNieuwsHover = function (element, color) {
			if (!document.getElementById(element))
				return false;
			var nieuwsTabel = document.getElementById(element);
			var nieuwsItems = nieuwsTabel.getElementsByTagName('div');
			for (var i = 0, j = nieuwsItems.length; i < j; i++) {
				addEvent(nieuwsItems[i], "click", function (e) {
					if (!e) e = window.event;
					var url = this.getElementsByTagName('a')[0];
					window.location.href = url;
				});
				addEvent(nieuwsItems[i], "mouseenter", function (e) {
					if (!e) e = window.event;
					this.style.backgroundColor = color;
					this.style.cursor = 'hand';
				});
				addEvent(nieuwsItems[i], "mouseleave", function (e) {
					if (!e) e = window.event;
					this.style.backgroundColor = "";
					this.style.cursor = "";
				});
			}
		}
		showGotoMyProfile = function (id) {
			if (!document.getElementById(id))
				return;
			var el = document.getElementById(id);
			el.innerHTML = '<a id="text_loggedin_vervanging" href="\/cms\/showpage.aspx?id=333">Naar het Ledennet</a>';
			el.style.visibility = "visible";
		}
		initOnLoad = function () {
			showGotoMyProfile('text_loggedin');
			checkInputField("input_container_username", "Gebruikersnaam");
			checkInputField("input_container_password", "WACHTWOORD");
			initNieuwsHover('nieuwsOverzicht', '#e2eaf5');
			toonDatumVanVandaag('DatumButton');
		}
	}
	{	// Public functions
		return ({
			onLoad: function () {
				addEvent(window, "load", initOnLoad);
			}
			,
			submitFormToSendmail: function (fn) {
				var submitFormHasErrors = false;

				if (typeof fn == 'function') {
					submitFormHasErrors = fn();
				}
				if (submitFormHasErrors == false) {

				}
			}
		});
	}
} ();
website.onLoad();

function getElementbyContainerId(element) {
	if (!document.getElementById(element)) return;
	return document.getElementById(element).getElementsByTagName('input')[0];
}

$(function () {
	$("#Attentieblok h2:empty").remove();
	$("#Attentieblok .binnen:empty").parent().remove();
	$("span.lijst:empty").prev().remove();
	$("span.lijst:empty").remove();
});

var standardSearchValidation = function (formId, errorId) {
	// dus maar 1 tekst-input per zoekformulier:
	var veld = $("#" + formId).find("input:text");
	// de foutmelding:		
	var error = $("#" + errorId);
	// opdat een erover heen getoonde melding geen last heeft van de tekst-cursor verwijderen we de focus:
	veld.blur();
	// foutmelding tonen:
	$(error).fadeIn();
	// als muis of toetsenbord klik of scroll, verwijder de boodschap:
	$(document).one('mousedown keydown scroll', function (event) {
		$(error).fadeOut();
		event.stopPropagation();
		// focus terugzetten
		veld.focus();
	});
}
function contentLoader(id, data) {
	$("#" + id).hide();
	$("#" + id + "_Loader").removeClass("throbber");
	$("#" + id + "_Loader").css("display", "none");
	$("#" + id).html(data);
	$("#" + id).fadeIn(400);
}
