﻿/* Dit bestand heet custom.js en niet global.js omdat visual studio mij om één of andere reden geen global.js liet maken in deze map */
function OpenPics(url, iwidth, iheight) {
    window.open(url, "afbeelding", "width=" + iwidth + ",height=" + iheight + ",left=125,top=100");
}
$(function(){
	// Als de breedte van het submenu kleiner is dan zijn parent-listitem, dan moet de breedte ingesteld worden, anders niet.
	$("#mainmenu ul ul").each(function(){
	    var w = $(this).parent().width();
	    $("a", this).css({width: w});
		if($(this).width() < $(this).parent().width()) {
			$(this).width($(this).parent().width());
		}
	});
	
	// Dropdowns:
	$("#mainmenu li").hover(function(){
		// mouseOver					
		$("ul", this).show();
	}, function(){
		// mouseOut
		$("ul", this).hide();
	});
	
	// Kijken of alle verplichte velden ingevuld zijn
	$("form").each(function(){
	    $(this).submit(function(){
	        var ok = true;
	        var m  = 'Niet alle verplichte velden zijn ingevuld!';
	        $(".required", this).each(function(){
	            if($(this).val()=='') { ok = false; }
	        });
	        $(".requiredMail", this).each(function(){
                if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($(this).val()) == false) {
                    m = 'Het ingevoerde e-mail adres is onjuist!';
                    return false;
                } 
	        });
	        if(ok) { 
    	        return true;
	        } else {
    	        alert(m);
    	        return false;
	        }
	    });
	});
	
	$("form.poll").submit(function(){
	    var ok = false;
	    $("input[type=radio]", this).each(function(){
	        if($(this).attr("checked")!=false) {
	            ok = true;
	        }
	    });
        if(ok) { 
	        return true;
        } else {
	        alert('U dient een keuze te maken voor de poll!');
	        return false;
        }
	});
	
	// Links openenen in een extern venster, de xhtml-strict manier:
	$("a[rel=external]").click(function() { 
	    window.open($(this).attr('href')); 
	    return false; 
    });
});