
 $(document).ready(function(){
	init_rate_form();
 });
 
 function comment_form_send(pid){
	var title=$('#commentTitle').val();
	var content=$('#commentContent').val();
	var sig=$('#commentSignature').val();
	var rate=$('#commentRate').val();
	
	var form_data= harvestData('commentForm');
		form_data=form_data+'&pid='+pid;
		
		ajax.callMethod('CommentComponent','addComment', null,form_data, null, function(http,bb) {
			var root = http.getResponseJSON(showErrorMessage);
		
			if(!root) return;
			
			if (root['validateError']=='true') {
				$('#messageLabel').html(root['html']).slideDown('slow');
				
				//refresh_captcha('commentFormCaptcha');
			} else {
				showMessage(root['html']);
				if(!root.only_rating){
					$('#comments_add_link').remove();
					$('#comments_send_notice').show();
				}
					
					
				if(root['rating_form']){
						$('#customers_rating').html(root['rating_form']);
						init_rate_form();
				}
			}
		}.bindResponse(this));
}

 function init_rate_form(){
	$('#customers_rating').mouseenter(function(){
		if($('#own_rating').css( 'display')=='none' ){
		
		//	$(this).children().not('#own_rating').hide();
			//$('#own_rating').stop().slideDown("slow");
		}
	})
	
	$('#own_rating').mouseleave(function(){
		if($('#own_rating:animated').length==0){
			//$(this).stop().slideUp('slow');
		//	$('#customers_rating').children().not('#own_rating').show();
		}
	});
	
	$('.rating_star').mouseleave(function(){
		$('.rating_star').removeClass('star_on');
		$('.rate_star_on').removeClass('star_off');
		$('.rate_star_on').addClass('star_on');
		$('#yours_rate_label').hide();
		$('#customers_rate_label').show();
	});
	$('.rating_star').mouseover(function(){
		$(this).addClass('star_on').prevAll('.rating_star').addClass('star_on');
		$(this).nextAll('.rating_star').removeClass('star_on');
		$('.rate_star_on').addClass('star_off');
		$('.rate_star_on').removeClass('star_on');
		$('#yours_rate_label').show();
		$('#customers_rate_label').hide();
	});
 }
 
 function addRate(products_id, rate)
 {

		if(products_id && rate)
		{
				var paramsPost = 'pid='+products_id+'&rate='+rate;

				ajax.callMethod('CommentComponent','addRate',paramsPost,paramsPost,null,
					function(http,bb) {		
						var root = http.getResponseJSON(showMessage);
						
						if (root) {
							if(root.loginError){
								showMessage(root.errorMessage, 'logowanie.php','error');
								return;
							}
						

							if(root['rating_form']){
								$('#customers_rating').html(root['rating_form']);
								init_rate_form();
							}
							$('#comments_add_link').html(dict('!#commentComponent_js#Dodaj opinię do swojej oceny'));
							var params=new Array();
							params['yesFunction'] = "comment_form("+products_id+")";
							params['content']=root['html'];
							LightBox.showFromTemplate('KomunikatInformacja',params);
						}
				}.bindResponse(this));
		}
 }

 function getComments(pid, page){
 
		form_data='&pid='+pid+'&page='+(parseInt(page));
		
		ajax.callMethod('CommentComponent','getCommentsAjax', null,form_data, null, function(http,bb) {
			var root = http.getResponseJSON(showErrorMessage);
		
			if(!root) return;

			$('#products_comments_container').html(root['html']);

		}.bindResponse(this));
}

function comment_form(pid){
		
		form_data='pid='+pid;
		
		ajax.callMethod('CommentComponent','getFormParams', null,form_data, null, function(http,bb) {
			var root = http.getResponseJSON(showErrorMessage);
		
			if(!root) return;

			if(root.loginError){
				showErrorMessage(root.errorMessage);
				
				showMessage(root.errorMessage, 'logowanie.php','error');
				return;
			}
		
			if(root.hascomment && root.hascomment==1){
				showErrorMessage(dict("!#commentComponent#Już dodałeś swoją recenzję"));
				return;
			}
			root['okFunction'] = "comment_form_send("+pid+")";
			LightBox.showFromTemplate('KomunikatKomentarzForm',root);
			
		}.bindResponse(this));
		
			
}
 
	

