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);
}


var $j = jQuery.noConflict()

$j(document).ready(function(){
	$j(".addComment").click(function() {
		$j("#commentsPopup").css("display", "inline");
		$j("#tx-comments-comment-form").slideDown("slow");
		
		
	});
	
	$j("#comments-cancel-button").click(function() {
		$j("#tx-comments-comment-form").slideUp("slow");
		$j("#commentsPopup").css("display", "none");
	});
	

	
	// Formular validieren
	$j("#comments-form").submit(function() {
		var validate = true;

		if($j("#tx_comments_pi1_lastname").val() == ""){
			$j("#tx_comments_pi1_lastname").after("<div class='comments_error'>Dies ist ein Pflichtfeld!</div>");
			validate = false;
		}
		
		if($j("#tx_comments_pi1_email").val() == ""){
			$j("#tx_comments_pi1_email").after("<div class='comments_error'>Dies ist ein Pflichtfeld!</div>");
			validate = false;
		}
		
		if($j("#tx_comments_pi1_content").val() == ""){
			$j("#tx_comments_pi1_content").after("<div class='comments_error'>Dies ist ein Pflichtfeld!</div>");
			validate = false;
		}

		if (($j("#tx_comments_pi1_email").val() != "") && (!isValidEmailAddress($j("#tx_comments_pi1_email").val()))){
			$j("#tx_comments_pi1_email").after("<div class='comments_error'>Bitte geben Sie eine richtige E-Mail-Adresse ein</div>");
			validate = false;
		}
    
    if($j(".tx-comments-comment-input-captcha").val() == ""){
			$j(".tx-comments-comment-input-captcha").after("<div class='comments_error'>Dies ist ein Pflichtfeld!</div>");
			validate = false;
		}
	
		$j(".comments_error").fadeOut(3500);

		return validate;
	});
	
	
	/* Weiterempfehlen */
	$j(".recommend").click(function() {
		$j("#commentes_recommend").slideDown("slow");
		$j("#commentsPopup").css("display", "inline");
	});
	
	$j("#recommend_button").click(function() {
		$j("#commentes_recommend").slideUp("slow");
		$j("#commentsPopup").css("display", "none");
	});
	
	$j("#recommend-form").submit(function() {
		//return false;
	});


  });