﻿function toolTip(){
    this.message = null;
    this.raiseToolTipAjaxReLoad = function(idObject, urlAjax, objectToLoad, urlLoadAjax, permanent, width, heigth){
        this.message = $('#' + idObject);
        if (width != null)  
            this.message.width(width);
        if (heigth != null)
            this.message.height(heigth);
        this.initialRaiseAjax();
        this.message.animate({opacity: 0.8}, 800);
        $.ajax({
            url: urlAjax,
            success: function(response){
                this.message = $('#' + idObject);
                if (width != null)
                    this.message.width(width);
                if (heigth != null)
                     this.message.height(heigth);
                if (objectToLoad != null){
                    objectToLoad.load(urlLoadAjax, function() {
                        this.message = $('#' + idObject);
                        if (width != null)
                            this.message.width(width);
                        if (heigth != null)
                            this.message.height(heigth);
                        $('#loadingImg').css('display', 'none');
                        if (permanent)
                            this.message.animate({opacity: 0.8}, 800).animate({opacity: 0.8}, 1000);
                        else
                            this.message.animate({opacity: 0.8}, 800).animate({opacity: 0.8}, 1000).animate({opacity: 0}, 1000);
                        this.message.html(response);
                        this.message.click(function(){  
                            this.message = $('#' + idObject);
                            clearToolTip(this.message);
                        });
                    });
                }
            }
        });
    };
    this.raiseToolTipAjax = function(idObject, urlAjax, permanent, width, heigth){
        this.message = $('#' + idObject);
        if (width != null)  
            this.message.width(width);
        if (heigth != null)
            this.message.height(heigth);
        this.initialRaiseAjax();
        this.message.animate({opacity: 0.8}, 800);
        $.ajax({
            url: urlAjax,
            success: function(response){
                this.message = $('#' + idObject);
                if (width != null)
                    this.message.width(width);
                if (heigth != null)
                     this.message.height(heigth);
                $('#loadingImg').css('display', 'none');
                if (permanent)
                    this.message.animate({opacity: 0.8}, 800).animate({opacity: 0.8}, 1000);
                else
                    this.message.animate({opacity: 0.8}, 800).animate({opacity: 0.8}, 1000).animate({opacity: 0}, 1000);
                this.message.html(response);
                this.message.click(function(){
                    this.message = $('#' + idObject);
                    clearToolTip(this.message);
                });
             }
        });
    };
    this.raiseToolTip = function(idObject, text, permanent, width, heigth){
        this.message = $('#' + idObject);
        if (width != null)
            this.message.width(width);
        if (heigth != null)
            this.message.height(heigth);
        this.message.stop();
        this.message.css('display', 'block');
        if (permanent)
            this.message.animate({opacity: 0.8}, 800).animate({opacity: 0.8}, 1000);
        else
            this.message.animate({opacity: 0.8}, 800).animate({opacity: 0.8}, 1000).animate({opacity: 0}, 1000);
        this.message.html(text);
        this.message.click(function(){
            this.message = $('#' + idObject);
            clearToolTip(this.message);
        });
    };
    this.raiseToolTipEdicionCampo = function(idObject, title, idText, text, functionAceptar, width, heigth){
        this.message = $('#' + idObject);
        if (width != null)
            this.message.width(width);
        if (heigth != null)
            this.message.height(heigth);
        this.message.stop();
        this.message.css('display', 'block');
        this.message.animate({opacity: 1}, 800).animate({opacity: 1}, 1000);
        this.message.css('background-image', 'none');
        this.message.html(title + "<br/><br/><textarea rows='3' id='" + idText + "' style='resize:none; width:220px;' >" + text + "</textarea><div style='text-align:right;padding-right:10px;margin-top:3px;'><img src='/admin/img/check.png' onclick='" + functionAceptar + "; clearToolTip($(this).parent().parent());' border='0' alt='Aceptar' title='Aceptar'/>&nbsp;<img src='/admin/img/delete.png' border='0' alt='Cancelar' title='Cancelar' onclick='clearToolTip($(this).parent().parent())'/></div>");
    };
    this.initialRaiseAjax = function(){
        this.message.stop();
        this.message.css('display', 'none');
        this.message.html("<div id='loadingImg' style='width:31px; margin: auto;'><img src='/img/cargando.gif' style='margin-top:10px;'/></div>");
        this.message.css('display', 'block');
    }
}
function clearToolTip(message){
    message.stop();
    message.css('opacity', '0');
    message.css('display', 'none');
    message.html('');
}


