jQuery.fn.log = function (msg)
{
  console.log("%s: %o", msg, this);
  return this;
};



function ajaxLoadingBUI()
{
	$.blockUI({ 
		message: '<div class="ajaxLoader">Aguarde un momento por favor...</div>',
		onUnblock: null,
		css: { 
			border: 'none', 
			padding: '15px', 
			backgroundColor: '#000', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px', 
			opacity: '1', 
			color: '#fff'
		}		
	});	
}


function bindBtnCloseBUI()
{
	$('.btnCloseBUI').click(function(){
		$.unblockUI();
		$(this).unbind('click');
	});
}


function loadModulo(obj, idContainer)
{
	$('li.active', $(obj).parent().parent()).removeClass('active');
	$(obj).addClass('active');
	loadModuloFNC($(obj).attr('data-Modulo'), idContainer);
}


function loadModuloFNC(modulo, idContainer)
{
	ajaxLoadingBUI();
	$.get( modulo,
		  {  },
		  function(data){
			$('#' + idContainer).html(data);
			$.unblockUI();
	});
}


function ajaxError(idContainer)
{
	$('#' + idContainer).ajaxError(function(event, request, settings)
	{
		$.get('/includes/ajaxError.php',
			  {
			   url: settings.url
			  },
			  function(data){
				  $('#' + idContainer).html(data);
		});

	});
	$.unblockUI();
}


function bloquearPantalla(mensaje, autoClose)
{
	
	if(!autoClose)
		mensaje = mensaje + '<br /><input type="button" class="btnCloseBUI" value="Cerrar" />';
	
    $.blockUI({
        message: mensaje,
        onUnblock: null,
        css: {
            border: 'none',
            padding: '15px',
            backgroundColor: '#000',
            '-webkit-border-radius': '10px',
            '-moz-border-radius': '10px',
            opacity: '1',
            color: '#fff'
        }
    });
	
	if(!autoClose)
		bindBtnCloseBUI();
}



function habilitarPantalla()
{
    var pos = $("#wrapper").offset();
    $("html").animate(
    {
        scrollTop: pos.top + "px"
    },

    {
        duration: 1000
    }, setTimeout($.unblockUI, 1100)
        );
	
}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}




function loadCatalogo(url)
{
    window.location = url;
}


function jqGridFixWidth()
{
    $('div.GridHeader').width('100%');
    $('div.userdata').width('100%');
    $('div.grid_hdiv').width('100%');
    $('div.grid_bdiv').width('100%');
    $('div[id^=tbl].scroll').width('100%');
}


function jqRowSelected(jqGridID)
{
    var s;
    s = $('#' + jqGridID).getGridParam('selrow');
    return s;
}

function jqGridUniqueRow(jqGridID)
{
    var s;
    s = $('#' + jqGridID).getGridParam('selarrrow');
    if($(s).length != 1)
    {
        bloquearPantalla('<div align="right" class="buiError"><h1>Seleccione un &uacute;nico registro</h1></div>', false);
        return false;
    }

    return true;
}

function jqGridSelected(jqGridID)
{
    var s;
    s = $('#' + jqGridID).getGridParam('selarrrow');
    if($(s).length <= 0)
    {
        bloquearPantalla('<div align="right" class="buiError"><h1>Seleccione registros</h1></div>', false);
        return false;
    }

    return true;
}
