var headerSearchDefaultCaption = "Zoek hier op trefwoord";

window.addEvent("domready",function(){

	// Zoek input
	$("header_search_input").addEvent("click",function(){
		if( this.value == headerSearchDefaultCaption )
		{
			this.value = "";
		}
	});
	$("header_search_input").addEvent("blur",function(){
		if( this.value == "" )
		{
			this.value = headerSearchDefaultCaption;
		}
	});

	$("header_search_input").value = headerSearchDefaultCaption;

	// Top menu
	suckerfishMenu("topmenu");

	var openIndex = -1;

	// Submenu actief? Betreffende parentleaf openen
	var item = $$("div.right dl.accbody dd.active");
	if( item.get("tag") == "dd" )
	{
		openIndex = item.get("itemindex");
	}
	

	// Accordeons
	var accordion = new Accordion($$(".accheader"), $$(".accbody"), {
		display: openIndex
	});

	// Accordion FAQ
	var accordion = new Accordion($$("div#content div.left dl dt"), $$("div#content div.left dl dd"), {
		display: false,
	    alwaysHide: true,
	    onActive: function(toggler, element) {
			if( toggler != null )
			{
				toggler.addClass("open");
			}
	    },
	    onBackground: function(toggler, element) {
			if( toggler != null )
			{
				toggler.removeClass("open");
			}
	    }
	});
	
	setTimeout(updateFooterPosition,300);
});

window.addEvent("resize",function(){
	updateFooterPosition();
});

function suckerfishMenu(id)
{
	if( document.all && document.getElementById )
	{
		var navRoot = document.getElementById(id);
		for( var i = 0; i < navRoot.childNodes.length; i++ )
		{
			var node = navRoot.childNodes[i];
			if( node.nodeName == "LI" )
			{
				node.onmouseover = function(){
					this.className += " over";
				}
				node.onmouseout = function(){
					this.className = this.className.replace(" over", "");
				}
			}
		}
	}
}

var footerTop = null;

function updateFooterPosition()
{
	if( $("footer").initialTop == null )
	{
		$("footer").initialTop = $("footer").getTop();
	}

	var marginTop = (window.getHeight()-$("footer").initialTop-$("footer").getHeight());
	if( marginTop < 0 )
	{
		marginTop = 0;
	}
	$("footer").setStyle("margin-top",marginTop + "px");
}

function submitContactForm()
{
	$("name_error").setStyle("display","none");
	$("email_error").setStyle("display","none");
	$("message_error").setStyle("display","none");
	
	if( ($("name").value = $("name").value.trim()).length < 2 )
	{
		$("name_error").innerHTML = "Vul aub je naam in";
		$("name_error").setStyle("display","block");
		$("name").focus();
		return false;
	}

	$("company").value = $("company").value.trim();

	if(
		( $("email").value.length < 5 ) ||
		( $("email").value.indexOf("@") == -1 ) ||
		( $("email").value.indexOf(".") == -1 )
	)
	{
		$("email_error").innerHTML = "Vul aub een geldig emailadres in";
		$("email_error").setStyle("display","block");
		$("email").focus();
		return false;
	}

	if( ($("message").value = $("message").value.trim()).length < 4 )
	{
		$("message_error").innerHTML = "Vul aub je aanvraag in";
		$("message_error").setStyle("display","block");
		$("message").focus();
		return false;
	}

	$("contactsubmit").disabled = true;
	$("send").value = "True";
	return true;
}

function doHeaderSearch()
{
	location.href = '/zoeken/?q=' + $('header_search_input').value;
}
