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 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;
}
function adjustIFrameSize(iframeWindow)
{
	var iExtraPixels = 5;
	var iframeElement = parent.document.getElementById(iframeWindow.name);
	iframeElement.style.height = iframeWindow.document.body.scrollHeight + iExtraPixels + 'px';
	document.body.style.border = "0";
}

function getElementbyContainerId(element)
{
	if (!document.getElementById(element)) return;

	return document.getElementById(element).getElementsByTagName('input')[0];
}

$(function()
{
       initSearchBox = function()
        {

            var el = document.getElementById('zoekTekst');
            addEvent(el, "keydown", function(e)
            {
                if (!e) e = window.event;
                if (e.keyCode == 13)
                {
                    searchSubmit();
                }
            });
            var el = document.getElementById('zoekSubmit');
            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('zoek_url').value ;


                searchUrl += searchTerm;
//alert(searchUrl);
                window.location.href = searchUrl;
				return false;

            } else
            {

                alert('Voer een zoekterm van minstens twee tekens in');
        
				return false;
            }
          
        }
	showGotoMyProfile = function(id)
	{
		if (!document.getElementById(id))
			return;
		var el = document.getElementById(id);
		// id vervangen....???
		el.innerHTML = '<a id="text_loggedin_vervanging" href="\/cms\/showpage.aspx?id=109">Naar mijn profiel</a>';
		el.style.visibility = "visible";

	}
	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 = "";
			}
		});
	}
	$("#menu").insertAfter("h1");
	$("#hoofdnavigatie .Kring a").attr("href", $("#hoofdnavigatie .Kring a").attr("href") + "&" + $("#kring_url").text());
	$("#hoofdnavigatie .Groep a").attr("href", $("#hoofdnavigatie .Groep a").attr("href") + "&" + $("#groep_url").text());
	showGotoMyProfile('text_loggedin');
	initSearchBox();
	checkInputField("input_container_username", "NAAM");
	checkInputField("input_container_password", "WACHTWOORD");
});