//<![CDATA[	
$(document).ready(function() {
	
	$("#comentarios").validate({
		rules: {
			name_str: {
				required: true
			},
			email_str:{
				required:true,
				email:true
			},
			comment_str: {
				required: true
			}
			
		},			
		messages: {
			name_str: {
				required: ""
			},
			email_str:{
				required:"",
				email:""
			},
			comment_str: {
				required: ""
			}
		},
		submitHandler: function(form) {
				$("#comentarios #load").ajaxStart(function(){
					$(this).show();
				});
				$.ajax({
					   type: "POST",
					   url: url+"application/models/AjaxFunctions.php",
					   data: $('#comentarios').serialize()+"&function=saveComments",
					   success: function(response){
							$("#load").hide();
							if( response == 'OK')
							{	
								$(":input").attr('value','');
								$("#load").hide();
								$("#response").fadeIn('slow');
								setTimeout(function() {
								 	$('#response').fadeOut('slow');
								 }, 10000); 
						 	}
							else
							{ 
								
								$("#response").html('Ops! Ocorreu um erro!');
								$("#response").fadeIn('slow');
								
							}
						}
				});	
 			}	

		});
		
	$('#ratings').rater(null,url+"remote-functions/"); 
		
	
		
});

function saveRating(num)
{
	$("#ratings").ajaxStart(function(){
		$("#ratings").show();	
	});
	$.ajax({
		   type: "POST",
		   url: url+"application/models/AjaxFunctions.php",
		   data: $('#comentarios').serialize()+"&function=saveRatings&rate="+num,
		   success: function(response){
				$("#load").hide();
				if( response != 'error')
				{	
					$('#value-ratings').html(response)
			 	}
			}
	});	
}
