$(document).ready(function() {   



//insert new comment
    $('.newcomment').click(function() {
        var msg = "";
        var id = this.name;

        if ($('#from_name' + id).val() == '')
            msg += ' - Please enter a name<br>';
        if ($('#comment' + id).val() == '')
            msg += ' - Please enter a comment<br>';

        if (msg != '') {
           $.facebox(msg);
            return;
        }


        $("#loading1").show();
        $.post("/comments_post.php", {
            cFromName: $('#from_name' + id).val(),
            cFromCompany: $('#company' + id).val(),
            cComment: $('#comment' + id).val(),
            cRecommendationId: $('#recommendation' + id).val(),
            Flag:'foradd',
            submit: 'submit'
        },

		    function(data) {
		        $('#loading1').hide();
		        eval("data =" + data);
		        if (data.response != "OK")
		              $.facebox(data.response);
		        else {
		            
		            $('#labelcnt' + id).html(data.cnt);
		            $('#from_name' + id).val("");
		            $('#company' + id).val("");
		            $('#comment' + id).val("");
		            
		            $.facebox("Comment submitted!");
		                   
		                   if($('.divcomments'+id).css("display") == 'block')
		                   {  $.post("/comments_post.php", {
            
                              cRecommendationId: $('#recommendation' + id).val(),
                              Flag:'forshow',
                              submit: 'submit'
                              },

		                       function(data) {
		                       eval("data =" + data);
		 
		                       if (data.response != "OK")
		           
		                      $.facebox(data.response);
		                       else
		                       { 
		         
		                        $('.divcomments' + id).html(data.html);		             
		                        $('.divcomments'+id).slideDown("slow");       
		           
		                        }
		                      
		                    });
		                   
		                   
		                   }
		        
		                      
		                      $('#'+id+'2').slideUp("slow");
		                      $('#'+id+'1').css("display","");
		        
		        
		        
		        
		            }
		    });
    });

$('.more_reviews').click(function(){

		var id = this.rel;
		$('.more_reviews_display' +id).css("display","");
		$('.more_reviews_points' +id).css("display","none");			
	});

//view comments
    
   
    $('.comment').click(function() {
        
        var id = this.rel;

        if($('.divcomments'+id).css("display") == 'none')
			
	{		
        
        
         $.post("/comments_post.php", {
            
            cRecommendationId: $('#recommendation' + id).val(),
            Flag:'forshow',
            submit: 'submit'
        },

		    function(data) {
		       eval("data =" + data);
		 
		        if (data.response != "OK")
		           
		            $.facebox(data.response);
		           else
		           { 
		         
		             $('.divcomments' + id).html(data.html);		             
		             $('.divcomments'+id).slideDown("slow");       
		           
		           }
		       
		            
		        
		    });
   
   }
   
   else
   $('.divcomments'+id).slideUp("slow");
   
    
    
    
    });




});