/**
 * @author user
 */
	
	$(document).ready(function(){
		
		$('#commentform').validate({
			errorLabelContainer: $('#commentform div.error'),
			rules: {
				article_comment: {
					required: true
				}
			},
			messages: {
				article_comment: 'Debe ingresar su comentario.'
			}
		});
		
		$('#articlebody a[balloon=true]').click(function(){
			$(this).blur();
			return false;
		});
		
		$('#articlebody a[balloon=true]').bt({
			trigger: 'click',
			ajaxPath: ["$(this).attr('href')"],
			width:396,
			margin:0,
			padding:0,
			fill:'rgba(0,0,0,.0)',
			strokeWidth: 0
		});
		
	})
	
	$.validator.setDefaults({
		submitHandler: function() {

			$.ajax({
				type:'POST',
				dataType:'json',
				url: $('#commentform').attr('action'),
				data: 'comment=' + $('#article_comment').val(),
				beforeSend: function(){
					$('#article_comment').attr('disabled', true)
					.css('background-color', '#CCC');
					
					$('#commentmessage', $('#commentform')).val('Enviando su solicitud...');
				},
				success: function(data){
					if(data.result == 'true'){
						$('#article_comment').val('');
						$('#commentmessage', $('#commentform')).html('Su comentario fue enviado con éxito.');
					} else {
						$('#commentmessage', $('#commentform')).html('Ocurrió un error al enviar su comentario.');
					}
					
					$('#article_comment').attr('disabled', false)
					.css('background-color', '#FFF');
				}
			});
		
			return false;
		}
	});

