var $j = jQuery.noConflict();
$j(document).ready(function() {
   $j(".error").hide();//hide the errors block	
   $j('div#share_popup').hide();
   $j('div#email_popup').hide();
   $j('div#comment_popup').hide();
   
   $j('a#share_btn').click(function() {
	   $j('div#email_popup').slideUp('slow'); 
	   $j('div#comment_popup').slideUp('slow');
	   $j("#comment_notice").html('');
	   $j('#share_popup').slideToggle(400);
	   return false;
   });
   $j('a#email_btn').click(function() {
	   $j('div#share_popup').slideUp('slow');     
	   $j('div#comment_popup').slideUp('slow');
	   $j("#comment_notice").html('');
	   $j('#email_popup').slideToggle(400);
	   return false;
   });
   $j('a#comment_btn').click(function() {
	   $j('div#share_popup').slideUp('slow');
	   $j('div#email_popup').slideUp('slow');      
	   $j('#comment_popup').slideToggle(400);
	   return false;
   });
   $j("#comment_submit").click(function(){					   				   
		$j("#com_err").hide();
		var hasError = false;
		var messageVal = $j("#com_ent_comment").val();
		if(messageVal == '') {
			$j("#com_err").html('You forgot to enter a comment.');
			$j("#com_err").show();
			hasError = true;
		}
		if(hasError == false) {
			$j(this).hide();
			$j('#cloading').show();
			$j.post("/typo3conf/ext/sbs_news_comments/submit_comment.php",$j("form#add_comment").serialize(),
  					function(data){
						$j("#comment_popup").slideUp("normal", function() {				   
							$j('#cloading').hide();
							$j("#comment_submit").show();
							$j("#comment_notice").html(data);
							$j("#com_ent_name").val('');
							$j("#com_ent_city").val('');
							$j("#com_ent_comment").val('');
						});
  					}
				 ); 
			return false;
		};
		return false;
	});
   $j("#email_submit").click(function(){					   				   
		$j("#email_err").hide();
		var hasError = false;
		var messageVal = $j("#em_recieve_message").val();
		if(messageVal == '') {
			$j("#com_err").html('You forgot to enter a comment.');
			$j("#com_err").show();
			hasError = true;
		}
		if(hasError == false) {
			$j(this).hide();
			$j('#cloading').show();
			$j.post("/typo3conf/ext/sbs_news_comments/send_email.php",$j("form#email_form").serialize(),
 					function(data){
						$j("#email_form").slideUp("normal", function() {				   
							$j('#cloading').hide();
							$j("#email_notice").show();
							$j("#email_notice").html(data);
							$j("#em_email_name").val('');
							$j("#em_send_address").val('');
							$j("#em_recieve_address").val('');
							$j("#em_recieve_message").val('');
							
						});
 					}
				 ); 
			return false;
		};
		return false;
	});
   $j("#rate_btn").click(function(){					   				   
		$j(this).hide();
		$j.post("/typo3conf/ext/sbs_news_comments/submit_rating.php",$j("form#rate_form").serialize(),
				function(data){
					$j('#article_rating').html(data);
				}
			 ); 
	return false;
	});   
   
});
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}
