$(document).ready(function(){
	
	// transparent pngfix for IE6
	$("div.banner img[@src$=.png]").ifixpng();
	
	// insert layer as shadow for pull down menu
	if($.browser.msie && parseInt($.browser.version) <= 6 ){
		$("#menu").prepend("<iframe id='menuShadow' src='shadowDummy.htm' frameborder='0'></iframe>");
	} else {
		$("#menu").prepend("<div id='menuShadow'></div>");
	}
	
	// pull down menu's
	var oldMenu;
	var menuTimer;
	$(".nav>li:has(a)").hover(function(){
		clearTimeout(menuTimer);
		// if this menu != oldMenu then hide oldMenu
		if(oldMenu && ($(this).children().eq(0).attr('class') != $(oldMenu).children().eq(0).attr('class'))){
			$(oldMenu).removeClass('hover');
		}
		if($(this).find("ul").length>0){
			$(this).find("ul").css("display","none");
			var w = ($(this).width() > 160)? $(this).width()+20 : 160;
			var h = $(this).find("ul").height();
			var l = this.offsetLeft - 1;
			var t = this.offsetTop + 26;
			$(this).addClass("hover").find("ul li").width(w);
			$("#menuShadow").width(w+4).height(h).css("left",l+"px").css("top",t+"px");
			$(this).find("ul").show();
			$("#menuShadow").show();
		} else {
			$('#menuShadow').hide();	
		}
		oldMenu = $(this);
	}, function(){
		menuTimer = setTimeout(function(){
			$(oldMenu).removeClass('hover');
			$('#menuShadow').hide();
			oldMenu = null;
			},500);
	});
	
	// tag menu items without pulldown
	$(".nav li:has(a[@class])").not(":has(ul)").addClass("noChildren");
	
	// print icon
	$("a.print").click(function(){
		this.blur();
		window.print();							
	});
	
	// reageer button
	$("div.reageer").not(".rounded").not(".verzonden").hide();
	$("td.forth").click(function(){
		this.blur();
		$("div.reageer").not(".rounded").toggle();
		$(this).toggleClass("forth").toggleClass("forthactive");
	});
	
	// zoek inputfield
	$("div.zoeken input").focus(function(){
		if($(this).val() == $(this).attr("title")) $(this).val("");
	}).blur(function(){
		if($(this).val().length < 1) $(this).val($(this).attr("title"));
	});
	
	
	
});


//form validatie

function findObj(id) {
	return ((document.getElementById) ? document.getElementById(id) : document.all[id]);
}
var optSelected = '';
function validateForm(obj,required,msg){
	var errorFields = '';
	var firstField = '';
	var message = '';
	var requiredFields = required.split (/\s*,\s*/);
	var emailfilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	for(var i=0;i<requiredFields.length;i++){
		var frmObj = findObj(obj);
		var fldObj = eval('frmObj.' + requiredFields[i]);
			if ((fldObj.value == '' || fldObj.value.indexOf("< ") != -1 || fldObj.value.indexOf("-- ") != -1) || ( ((fldObj.id == "email")||(fldObj.id == "Email")) && !(emailfilter.test(fldObj.value)))    ) {
				if (firstField == '')firstField = fldObj;
				if (fldObj.title != ''){
					if (fldObj.title == "< DD >") { errorFields += '- Datum dag\n'; }
					else if (fldObj.title == "< MM >") { errorFields += '- Datum maand\n'; }
					else if (fldObj.title == "< JJJJ >") { errorFields += '- Datum jaar\n'; }
					else { errorFields += '- ' + fldObj.title + '\n'; }
				}else{
					errorFields += '- ' + fldObj.id + '\n';
				}
				fldObj.style.backgroundColor = '#FFD4D4';
			}
	}
	
	//custom voor contact formulier checkboxen
	if(optSelected != ''){
		fldObj =document.getElementById(optSelected);
		if(fldObj.value == ''){
			errorFields +=  '- ' + fldObj.title + '\n';
			fldObj.style.backgroundColor = '#FFD4D4';
		}
	}
	//custom end
	
	if(errorFields != ''){
		alert(msg + '\n\n' + errorFields);
		return false;
	}
	return true;
}

function changed(obj, fldname){
	fldObj = findObj('hiddenNr');	
	if(obj.value == '' || obj.value == 'Anders'){
		fldObj.style.display = 'none';
		fldObj2 =document.getElementById(fldname);
		fldObj2.value = '';
		optSelected = '';
	}else{
		fldObj.style.display = 'block';
		optSelected = fldname;
	}
}
