// JavaScript Document
function addOption(value, text, id)
{
	var thisValue = value;
	var thisText  = text;
	var thisOpt   = document.createElement('option');
	thisOpt.value = thisValue;
	thisOpt.appendChild(document.createTextNode(thisText));
	$("#" + id).append(thisOpt);
}

function showAddress(map,geocoder,address,html, postalcode, i) {
	geocoder.getLatLng(
	address,
	function(point) {
		if (!point && i < 1) {
			showAddress(map, geocoder, postalcode, html, postalcode, 1);
		} else {
			map.setCenter(point, 15);
			var marker = new GMarker(point);
		
			map.addOverlay(marker);
			map.addControl(new GMapTypeControl());
			map.addControl(new GLargeMapControl());
		}
	});
}

function switchStylestyle(styleName)
{
  jQuery('link[@rel*=style][title]').each(function(i)
  {
     this.disabled = true;
     if (this.getAttribute('title') == styleName) this.disabled = false;
  });
  createCookie('style', styleName, 365);
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function mainmenu(){
    /** / $("#nav ul").css({display: "none"}); // Opera Fix /**/
    $("#nav li").mouseover(function()
    {
    	$(this).find('ul:first').css({visibility: "visible",display: "visible"}).show();
    });
    $("#nav li").mouseout(function()
    {
		$(this).find('ul:first').css({visibility: "hidden"});
    });
}

$(document).ready(function()
{
		mainmenu();
});

$(document).ready(function()
{
	$('.datepicker').datepicker();
	
	var arrowcolor = 'Blue';
	$("#faq > dt").click(function()
	{
		$(this).next().slideToggle();
		var $img = jQuery(this).children('img'); 
		var $siteColor = jQuery(this).children('input').val();
		if ($img.attr('src') == 'images/arrowUp' + arrowcolor + '.jpg')
		{
			$img.attr('src', 'images/arrowDown' + arrowcolor + '.jpg');
		}
		else
		{
			$img.attr('src', 'images/arrowUp' + arrowcolor + '.jpg');
		}
	});

	$('ul#headerimg').innerfade({ 
		speed: 1000,
		timeout: 10000,
		type: 'sequence',
		containerheight: '300px'
	});
	
	//$("a[rel='lightbox']").colorbox(); 
	
	$('a').focus(function()
	{
		if(this.blur)this.blur();
	});
	
	$('.styleswitch').click(function()
	{
		switchStylestyle(this.getAttribute("rel"));
		$(".styleswitch").css({"color" : "#006EAB"});
		$(this).css({"color" : "#006EAB"});
		
		return false;
	});
	
	var c = readCookie('style');
	
	if (c) 
	{
		$(".styleswitch").css({"color" : "#006EAB"});
		$('#stylesBox > ul > li > a#' + c + 'Letters').css({"color" : "#006EAB"});
		switchStylestyle(c);
	}
	
	$('#verzorger').click(function()
	{
		$('#machtigingsdiv').css('visibility','visible');
		$('#machtigingsbedrag').html('27,50');
	});

	$('#patient').click(function()
	{
		$('#machtigingsdiv').css('visibility','visible');
		$('#machtigingsbedrag').html('27,50');
	});

	$('#donateur').click(function()
	{
		$('#machtigingsdiv').css('visibility','visible');
		$('#machtigingsbedrag').html('15,00');
	});
	
	$('#vrijwilliger').click(function()
	{
		document.getElementById('machtiging_donateur').checked = false;
		$('#machtigingsdiv').css('visibility','hidden');
	});
	
	
});


/** formvalidation **/

function evalLength(objectId,length,nextObjectId){
	if(document.getElementById(objectId).value.length >= length){
		document.getElementById(nextObjectId).focus();
	}
}

function in_array(the_needle, the_haystack){
	var the_hay = the_haystack.toString();
	if(the_hay == ''){
		return false;
	}
	var the_pattern = new RegExp(the_needle, 'g');
	var matched = the_pattern.test(the_haystack);
	return matched;
}

function upperCase(input){
	input.value = input.value.toUpperCase();
}


function printFormElements(){
	alert(message);
}

function showFormElements(form){
	if (message !== 'Het formulier bevat de volgende elementen: \r\n\r\n') message = 'Het formulier bevat de volgende elementen: \r\n\r\n';
	var form = document.getElementById(form);
	var len = form.length;
	var elm = form.elements;
	for (i=0; i < len; i++){
	  addFormElm(i, 'elmId = ' + elm[i].id + ', elmName = ' + elm[i].name + ', elmType = ' + elm[i].type + ', elmValue = ' + elm[i].value);
	}
	printFormElements();
}
// end debugging

