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 checkInputField, getQueryVariable;
        var initOnLoad;
        var initSearchBox, searchSubmit, 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();
        }

        initSearchBox = function()
        {
            if (!document.getElementById('zoekTekst')) 
                 return;
            var el = document.getElementById('zoekTekst');
            addEvent(el, "keydown", function(e)
            {
                if (!e) e = window.event;
                if (e.keyCode == 13)
                {
                    searchSubmit();
                }
            });
            var el = document.getElementById('btnContentSearch');
            addEvent(el, "click", searchSubmit);

        }

        /* -- */
        searchSubmit = function()
        {
			if (!document.getElementById('zoekTekst'))
				return;
            searchTerm = encodeURIComponent(document.getElementById('zoekTekst').value);
            var currentLocation = window.location.href;
            if (searchTerm.length > 1)
            {

                document.forms[0].onsubmit = function() { return false }
                var searchUrl = document.getElementById('zoekUrl').value ;


                searchUrl += searchTerm;
                window.location.href = searchUrl;
				return false;

            } else
            {
                alert('Voer een zoekterm van minstens twee tekens in');       
				return false;
            }
          
        }

        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');
			initSearchBox();
            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();
});




