$(document).ready(function() { 
	loading = new Image(16,16);
	loading.src = "assets/load.gif";
	
	function checkEmailAddress(emailaddress) {
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(emailaddress)) {
			return false;
		}
		return true;
	}
	
	$('#plaatscomment').click(function() { 	
		var errors = '';
		var addcomments = $('#addcomments');
		var naam = $('#commentnaam').val();
		var type = $('#commenttype').val();
		var team_id = $('#team_id').val();
		var code = $('#validator').val();
		var email = $('#commentemail').val();
		var nieuws_id = $('#commentnieuws_id').val();
		var bericht = $('#commentbericht').val();
		if (!checkEmailAddress(email)) {
			errors += 'E-mail is niet goed opgegeven.\n';
		}
		if (naam=='') {
			errors += 'Naam is verplicht.\n';
		}
		if (bericht=='') {
			errors += 'Bericht is verplicht.\n';
		}
		if (errors=='') {
			if (confirm('Uw bericht plaatsen?')) {
				addcomments.html('<img src="assets/load.gif"/>');	
				$.ajax( {
				   type: "POST",
				   url: "modules/addcomments.php",
				   data: { c_naam: naam, c_email: email, c_nieuws_id: nieuws_id, c_bericht: bericht, c_type: type, c_team_id: team_id, validator: code },
		
				   success: function(msg) {
						addcomments.html(msg);
						$('#commentnaam').val("");
					    $('#validator').val("");
					    $('#commentemail').val("");
					    $('#commentbericht').val("");
						$.get(type + "/comments.php?load=1&nieuws_id=" + nieuws_id, function(data) {
    						$("#listcomments").html(data);
    
  						});
				   }				   
				});
			}
		} else {
			alert(errors);	
		}
	});
});


