$.fn.duplicate = function(count, cloneEvents) {
	var tmp = [];
	for ( var i = 0; i < count; i++ ) {
		$.merge( tmp, this.clone( cloneEvents ).get() );
	}
	return this.pushStack( tmp );
};

function buOv(id)
{
	document.getElementById(id).className = 'menuBuOv';
}

function buOut(id)
{
	document.getElementById(id).className = 'menuBu';
}

function bu2Ov(id)
{
	document.getElementById(id).className = 'menuBubOv';
}

function bu2Out(id)
{
	document.getElementById(id).className = 'menuBub';
}

function clearDefault(id)
{
  if(id.defaultValue == id.value)
  {
  	id.value = "";
  }
}
var counter = 1;
var counter2 = 1;

function addPerson() 
{
 	counter++;
	$('.persoon:first').duplicate(1, true).insertAfter('.persoon:last');
	
	$(".persoon:last input").each(function()
	{
		$(this).attr("value", "");
	});
	
	$(".persoon:last select").each(function()
	{
		$(this).attr("value", "");
	});

	$(".persoon:last").attr("class", "persoon persoonExtra");
	return false;
}
function setDefault(id)
{
  if(id.value == "")
  {
  	id.value = id.defaultValue;
  }
}

function addChild() 
{
 	counter++;
	$('.kind:first').duplicate(1, true).insertAfter('.kind:last');
	
	$(".kind:last input").each(function()
	{
		$(this).attr("value", "");
	});
	
	$(".kind:last select").each(function()
	{
		$(this).attr("value", "");
	});

	$(".kind:last").attr("class", "kind kindExtra");
	return false;
}
function setDefault(id)
{
  if(id.value == "")
  {
  	id.value = id.defaultValue;
  }
}

$(document).ready(function(){
	$('.cultuurCycle').hover(function(){$(this).prev().addClass("cultuurActiveHover");}, function(){$(this).prev().removeClass("cultuurActiveHover");});
	
	$('.curecareCycle').hover(function(){$(this).prev().addClass("curecareActiveHover");}, function(){$(this).prev().removeClass("curecareActiveHover");});
	
	$('.gezinCycle').hover(function(){$(this).prev().addClass("gezinActiveHover");}, function(){$(this).prev().removeClass("gezinActiveHover");});
	
	$('.kunstCycle').hover(function(){$(this).prev().addClass("kunstActiveHover");}, function(){$(this).prev().removeClass("kunstActiveHover");});
	
	$('.muziekCycle').hover(function(){$(this).prev().addClass("muziekActiveHover");}, function(){$(this).prev().removeClass("muziekActiveHover");});
	
	$("#form1").validate({
   		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'U heeft een veld niet juist ingevuld. Controleer het gemarkeerde veld.'
					: 'U heeft ' + errors + ' velden niet juist ingevuld. Controleer de gemarkeerde velden.';
				$("div.errorMsg span").html(message);
				$("div.errorMsg").show();
			} else {
				$("div.errorMsg").hide();
			}
		}
	});

	
	$('.submit').click(function()
	{
		$('#form1').submit();
		if($(".errorMsg span").text() == "")
		{
			return false;
		}
		
	});
	
	$('.reset').click(function()
	{
		$('#form1')[0].reset()
		$('.kindExtra').each(function(){
		$(this).remove();
		});
		$('.persoonExtra').each(function(){
		$(this).remove();
		});
		
		return false;
	});
	
});

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

