// DEPRECATED
// No habría que usarlo mas, solo se mantiene por compatibilidad

/**
 * Manejo de comentarios, denuncias, votacin y paginacin
 * @author Daniela Rodrguez <dcareri@gmail.com>
 * @requires jQuery
 *  
 */
var mono = {};

mono.CFG = {}


// Constantes de idioma --------------------------------------------------------------------
var mono = {};

mono.CFG = {}

mono.CFG.DEBUG = true;
mono.CFG.COMENTARIOS_MAX_CAPS = 70; // mï¿½ximo porcentaje de caracteres en mayï¿½sculas tolerables en un comentario
mono.CFG.URL_BASE = "/";
mono.CFG.URL_COMENTARIO_ENVIAR = mono.CFG.URL_BASE + "comentario/crear";
mono.CFG.URL_COMENTARIO_DENUNCIAR = mono.CFG.URL_BASE + "comentario/denunciar";
mono.CFG.URL_COMENTARIO_VOTAR = mono.CFG.URL_BASE + "comentario/votar";
mono.CFG.URL_PAGINA_SOLICITAR = mono.CFG.URL_BASE + "comentario/paginador/";



// Constantes de idioma --------------------------------------------------------------------

mono.msg = {

        ERROR_500 : "Ha ocurrido un error en el servidor. Por favor, vuelva a intentar en unos minutos.",
        ERROR_403_COMENTARIO : "Para dejar un comentario debe iniciar sesi&oacute;n.",
        ERROR_403_DENUNCIA : "Para denunciar un comentario, debe iniciar sesion.",
        ERROR_403_VOTAR : "Para poder votar, debe iniciar sesion.",
        ERROR_400_COMENTARIO : "Antes de enviar, escriba el comentario.",
        CONFIRMA_DENUNCIA : "Confirme por favor que este comentario viola los Terminos y Condiciones de Monografias.com",
        DENUNCIA_ENVIADA : "&nbsp;|&nbsp; <strong>Comentario denunciado</strong>",
        NO_VOTAR_DOBLE : "No puede votar el mismo comentario dos veces"

}

// Utilidades --------------------------------------------------------------------
mono.util = {

        getCookie : function(nombre) {
                var results = document.cookie.match ( '(^|;) ?' + nombre + '=([^;]*)(;|$)' );
                if (results) {
                        return (unescape(results[2]));
                } else {
                        return null;
                }
        },

        setCookie : function(nombre, value, neverexpires) {
                var cookie_string = nombre + "=" + escape(value) + "; path=/";
                if (neverexpires) {
                        var cookie_date = new Date();
                        cookie_date.setDate (cookie_date.getDate() + 365 );
                        cookie_string += "; expires=" + cookie_date.toGMTString();
                }
                document.cookie = cookie_string;
        },   

        deleteCookie : function(nombre) {
                var cookie_date = new Date();
                cookie_date.setTime (cookie_date.getTime() - 1 );
                document.cookie = nombre += "=; expires=" + cookie_date.toGMTString();
        },

        sanearTexto : function(t) {
                var mayus = t.match(/[A-Z]/g);
                if (mayus) {
                        var cantMayus = mayus.length;
                        var total = t.length;
                        if ( ((cantMayus/total)*100) > mono.CFG.COMENTARIOS_MAX_CAPS ) {
                                t = t.charAt(0).toUpperCase() + t.substr(1).toLowerCase(); // HOLA --> Hola
                        }
	        }
                t = t.replace(/([A-Za-z0-9,\.!\?\$\-])\1{5,}/g, "$1"+"$1"+"$1"+"$1"); // Holaaaaaaaaaaaaaa --> Holaaaa
                return t;
        }

}


// Utilidades --------------------------------------------------------------------
mono.followbox = {
	followMeBox : function(){
                // Mostrar el form de comentarios solo a los logueados.
                if (mono.CFG.usuario_logueado) {
                        $("#js-followme-logged").show();
                } else {
                        $("#js-followme-error").show();

		}

	}
	
}

// Extender jQuery con funciones utiles --------------------------------------------------------------------

jQuery.fn.extend ({

        // Desactivar form
        desactivar: function() {
                $(':input[readonly!="readonly"]:not(.desactivado)', this).each(function() {
                        var $el = $(this);
                        $el.attr('readonly', 'readonly').addClass('desactivado js-dis'); // Ojo, seteamos radonly, no disabled
                        if ($el.hasClass('submit'))     {
                                $el.addClass('busy');
                                $el.attr('disabled', 'disabled').attr('oldValue', $.trim($(this).html()));
                                $el.html("Enviando...");
                                $el.blur();
                        }
                })
                return this;
        },

        // Reactivar form
        activar: function() {
                return $('.desactivado.js-dis', this).each(function() {
                        $(this).removeAttr('readonly').removeClass('desactivado js-dis');
                        if ($(this).attr('oldValue')) {
                                $(this).removeClass('busy');
                                $(this).html($(this).attr('oldValue'));
                                $(this).removeAttr('disabled').removeAttr('oldValue');
                        }
                });
        }

});
// Main ------------------------------------------------------

$(document).bind("ready", function() {
        if (mono.util.getCookie("monoauth_session_hash")) {
                mono.CFG.usuario_logueado = true;
        } else {
                mono.CFG.usuario_logueado = false;         
        }
	mono.followbox.followMeBox();
});

