function alertMe(type,text,redirect)
{
    if( type == 'confirm')  confirmMe(text,redirect);
    if( type == 'advice' )  adviceMe(text,redirect);
}

function confirmMe(text, redirect)
{
    alert("confirm, text: "+text+" redirect: "+redirect);
}

function adviceMe(text, redirect)
{
    $('body').append('<div id="overlay" />');
    $('#overlay').fadeIn(300, function() 
    {
        $('body').append('<div id="alertModalOuter"><div id="alertModal"></div></div>');
        
        var advice = '<p>'+text+'</p><br><p><a href="#" class="alertButton" id="yes"><span>Aceptar</span></a></p>';
        $('body').append('<div id="alert">'+advice+'</div>');
        
        var outer = $('#alertModalOuter');
        var modal = $('#alertModal');
        var defWidth = outer.outerWidth();
        var defHeight = outer.outerHeight();
        
        modal.html(function() 
        {
            var alertBoxContent = $('#alert');
            var alertWidth = alertBoxContent.outerWidth();
            var alertHeight = alertBoxContent.outerHeight();

            var widthCombine = -((defWidth + alertWidth) / 2);
            var heightCombine = -((defHeight + alertHeight) / 2);

            modal.animate({width: alertWidth}, 200);
            outer.animate({marginLeft: widthCombine, marginTop: heightCombine}, 200, function() 
            {
                $('#yes').click(function(e) 
                {
                    e.preventDefault();
                    $('#overlay, #alertModalOuter').fadeOut(400, function() 
                    {
                        if( redirect != null)
                            window.location.href = redirect; 
                        
                        $('#overlay').remove();
                        $('#alertModalOuter').remove();
                        $('#alert').remove();
                        $(this).remove();
                    });
                });
            });
            
            return advice;

        });
        
        document.location="#alertTop";
    });
}

function confirmMe(text, redirect)
{
    $('body').append('<div id="overlay" />');
    $('#overlay').fadeIn(300, function() 
    {
        $('body').append('<div id="alertModalOuter"><div id="alertModal"></div></div>');
        
        var advice = '<p>'+text+'</p><br><p><a href="#" class="alertButton" id="yes"><span>Ok</span></a><a href="#" class="alertButton" id="no"><span>Cancelar</span></a></p>';
        $('body').append('<div id="alert">'+advice+'</div>');
        
        var outer = $('#alertModalOuter');
        var modal = $('#alertModal');
        var defWidth = outer.outerWidth();
        var defHeight = outer.outerHeight();
        
        modal.html(function() 
        {
            var alertBoxContent = $('#alert');
            var alertWidth = alertBoxContent.outerWidth();
            var alertHeight = alertBoxContent.outerHeight();

            var widthCombine = -((defWidth + alertWidth) / 2);
            var heightCombine = -((defHeight + alertHeight) / 2);

            modal.animate({width: alertWidth}, 200);
            outer.animate({marginLeft: widthCombine, marginTop: heightCombine}, 200, function() 
            {
                $('#yes').click(function(e) 
                {
                    e.preventDefault();
                    $('#overlay, #alertModalOuter').fadeOut(400, function() 
                    {
                        if( redirect != null)
                            window.location.href = redirect; 
                        
                        $('#overlay').remove();
                        $('#alertModalOuter').remove();
                        $('#alert').remove();
                        $(this).remove();
                    });
                });
                
                $('#no').click(function(e) 
                {
                    e.preventDefault();
                    $('#overlay, #alertModalOuter').fadeOut(400, function() 
                    {                       
                        $('#overlay').remove();
                        $('#alertModalOuter').remove();
                        $('#alert').remove();
                        $(this).remove();
                    });
                });
            });
            
            return advice;

        });
    });
}
