function zeroPad(num,count) {
	var numZeropad = num + '';
	while(numZeropad.length < count) {
		numZeropad = "0" + numZeropad;
	}
	return numZeropad;
}

function getFlashMovie(movieName) {   
	var isIE = navigator.appName.indexOf("Microsoft") != -1;   
	return (isIE) ? window[movieName] : document[movieName]; 
}

function checkForm(form,type) {
	if (form=='newsletter') {
		if ($('#nwsl-email').val()=='Uw e-mailadres'&&type=='click') $('#nwsl-email').val('');
		if ($('#nwsl-email').val()==''&&type=='blur') $('#nwsl-email').val('Uw e-mailadres');
	} else if (form=='ask') {
		if ($('#ask').val()=='Vul hier uw vraag in.'&&type=='click') $('#ask').val('');
		if ($('#ask').val()==''&&type=='blur') $('#ask').val('Vul hier uw vraag in.');
	}
}

function saveNewsletterAddress(type) {
	var val = $('#nwsl-email').val();
	
	if (val==''||val=='Uw e-mailadres') alert('Vul een e-mailadres in!');
	else {
		if (isValidEmailAddress(val)) {
		$.ajax({ 
			type	: "POST", 
			url		: "/services/saveNewsletterAddress.php", 
			data	: "val="+val+"&type="+type,
			success	: function(html){
				if (html=='email_added') {
					alert('Uw adres is toegevoegd aan de database. Vanaf de volgende nieuwsbrief zult u hem ook ontvangen.');
					$('#nwsl-email').val('Uw e-mailadres');
				} else if (html=='email_exists') {
					alert('Het ingevulde e-mailadres komt al voor in onze database en ontvangt dus al de nieuwsbrief.');
				} else if (html=='email_removed') {
					alert('Uw e-mailadres is verwijderd uit de database. Vanaf nu zal u de nieuwsbrief niet meer ontvangen.');
					$('#nwsl-email').val('Uw e-mailadres');
				} else if (html=='email_not_exists') alert('Het ingevulde e-mailadres komt niet voor in onze database.');
				else if (html=='wrong') alert('Er is iets niet goed gegaan!');
			}
		});
		} else alert('Vul een juist e-mailadres in!');
	}
}

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function loadCSS(type) {
	$.ajax({ 
		type	: "POST", 
		url		: "/services/setCookie.php", 
		data	: "type="+type,
		success	: function(){
			window.location.reload();
		}
	});
}

function saveAnswer(val) {
	$.ajax({ 
		type	: "POST", 
		url		: "/services/saveAnswer.php", 
		data	: "val="+val,
		success	: function(){
			window.location.reload();
		}
	});
}

jQuery.fn.ForceNumericOnly = function() {
	return this.each(function() {
		$(this).keydown(function(e) {
			var key = e.charCode || e.keyCode || 0;
			// allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
			return (key == 8 || key == 9 || key == 46 || (key >= 37 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105));
        })
    })
};

