$(document).ready(function() {
 
   $("#comment_submit_button").click(function() {

		var	name = $('#name').val();
		var	email = $('#email').val();
		var	kommentar = $('#comment').val();
		var	code = $('#sicherheitscode').val();		
		var error = '';
		if(name=='') error = 'Bitte Name eingeben.';
		else if(name=='') error = 'Bitte Name eingeben.';
		else if(!checkEmail(email)) error = 'Bitte korrekte E-Mail eingeben.';
		else if(kommentar=='') error = 'Bitte Kommentar eingeben.';
		else if(code=='') error = 'Bitte Ergebnis der Rechenaufgabe eingeben.';
		
		if(error!='') {
			alert(error);
		} else {
			$.post('http://www.treffpunkt-riesa.de/comment.php?action=captcha',
				   	$('#form').serialize(),
					function(data) {
						
							alert(data.message);

						
					},'json');
		
		}
	});
   
   $("#commentlink").click(function() {
		$('#commentlink').hide();
		$('#commentbox').show();
	});
});

function pop(url,breite,hoehe)    {
      var pop = null;
      pop =  window.open(url,'popwin','width='+breite+',height='+hoehe+',resizable=no,status=no,scrollbars=yes,menubar=no,toolbar=no,directories=no')
      if (pop) {
         pop.moveTo(screen.width/2-breite/2,screen.height/2-hoehe/2);
         pop.window.focus();
      }
}

function checkEmail(s) {
	var a = false;
	var res = false;
	if (typeof(RegExp) == 'function') {
		var b = new RegExp('abc');
		if (b.test('abc') == true) {
			a = true;
		}
	}

	if (a == true) {
		reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'
				+ '(\\@)([a-zA-Z0-9\\-\\.]+)' + '(\\.)([a-zA-Z]{2,4})$');
		res = (reg.test(s));
	} else {
		res = (s.search('@') >= 1 && s.lastIndexOf('.') > s.search('@') && s
				.lastIndexOf('.') >= s.length - 5)
	}
	return (res);
}
