$(function() {

	if (window.initGallery) { initGallery() }
	$(".formbuilder_formpanel input:radio").addClass("noBorder");
	$(".formbuilder_formpanel input:checkbox").addClass("noBorder");
	$("h3:empty").remove();
	$("h2:empty").remove();
	$(".afbeelding:empty").remove();
	$(".tekst:empty").remove();
	$("div.bericht:empty").remove();
	$("div.bg_if_text:empty").remove();
	$("div#onderkant:empty").remove();
	$(".banner:empty").remove();
	$("#CCIPlaceHolder_Content .ledenlijst .item a").click(function(){
		$(this).next().toggleClass("zichtbaar");
	});

	
	/*$("#overzicht_leden .item").hover(function(){
		$(this).addClass("mouseover");
	}, function() {
		$(this).removeClass("mouseover");
	});*/
	
	$(".tekst:empty").remove();
	
	$(".pulldown select").change(function() {

		var selected = $(".pulldown option:selected");
		if (selected.val() != 0) {
			window.location = selected.val();
		}
	});
/* Zoekformulier */
$('.zoekknop').click(function() {
	searchSubmit($(this));
	return false;
});
var searchSubmit = function(sNode) {
	var theForm = $(sNode).parent();
	var searchInputText = $(theForm).find('input:text');
	var searchInputHidden = $(theForm).find('input:hidden');
	searchTerm = encodeURIComponent(searchInputText.val());
	if (searchTerm.length > 1) {
		$("form").submit(function() { return false });
		var searchUrl = searchInputHidden.val();
		searchUrl += searchTerm;
		window.location = searchUrl;
	} else {
		alert('Vul minstens twee tekens in om te zoeken.');
		return false;
	}
}
$("#zoek input:text").each(function() {
	$(this).keydown(
			function(e) {
				if (e.keyCode == 13) {
					searchSubmit($(this));
					return false;
				}
			}
		);
	$(this).focus(
			function() {
				this.value = '';
				//				this.className = 'zoekveld';
			}
		);
	$(this).blur(
			function() {
				if (this.value == '') {
					this.value = '';
					//					this.className = 'zoekveld';
				}
			}
		)
}
	)

	
});


Date.prototype.setISO8601 = function (string) {
    var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
        "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" +
        "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
    var d = string.match(new RegExp(regexp));

    var offset = 0;
    var date = new Date(d[1], 0, 1);

    if (d[3]) { date.setMonth(d[3] - 1); }
    if (d[5]) { date.setDate(d[5]); }
    if (d[7]) { date.setHours(d[7]); }
    if (d[8]) { date.setMinutes(d[8]); }
    if (d[10]) { date.setSeconds(d[10]); }
    if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
    if (d[14]) {
        offset = (Number(d[16]) * 60) + Number(d[17]);
        offset *= ((d[15] == '-') ? 1 : -1);
    }

    // offset -= date.getTimezoneOffset();
    time = (Number(date) + (offset * 60 * 1000));
    this.setTime(Number(time));
}

Date.prototype.showStart = function(endDate){
	var d = this;
	
	var monthArray = ['Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sept','Okt','Nov','Dec'];
	var y = this.getYear();

	var t = "";
	t += this.getDate() + " ";
	t += monthArray[this.getMonth()] + "  ";
	t += y > 1900 ? y : (y + 1900);
	t += ", ";
	var hours = this.getHours();
	if (hours < 10) {
		t += "0";
	}
	t += hours + ":";
	var minutes = this.getMinutes();
	if (minutes < 10) {
		t += "0";
	}
	t += minutes;
	return t;
}
Date.prototype.showEnd = function(endDate){
	var d = this;
	var t = " tot ";

	var hours = this.getHours();
	if (hours < 10) {
		t += "0";
	}
	t += hours + ":";
	var minutes = this.getMinutes();
	if (minutes < 10) {
		t += "0";
	}
	t += minutes;
	t += " uur";
	return t;
}


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() {
	{	// Private functions
		var initOnLoad;

		showGotoMyProfile = function(id) {
			if (!document.getElementById(id))
				return;
			var el = document.getElementById(id);
			el.innerHTML = '<a id="text_loggedin_vervanging" href="\/ledennet">Ga naar het ledennet</a>';
			el.style.visibility = "visible";
		}

		initOnLoad = function() {
			showGotoMyProfile('text_loggedin');
		}
	}
	{	// 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();