/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function loadScript(source){
    $.ajaxSetup({async: false});
    $.getScript(source);
    $.ajaxSetup({async: true});
}
(function(a){
    a.log=function(){
        try{
            if(window.console&&window.console.log){
                console.log.apply(window.console,arguments)
            }
        }catch(error){}
    };        
    a.fn.log=function(){
        a.log(this);
        return this
    }
})(jQuery);



(function($) {
    $.sAjax=function(url,data,callback,callbackerror){
        //alert("refreshStatistics");
        $.ajax({
            type: "POST",
            url: url,
            dataType: "json",
            data: data,
            success: function(json) {
                if (json==null || json.error)
                {                    
                    if(json==null){                        
                        $.log("Sin respuesta");
                        alert("No se recibio respuesta");
                    }
                    else if (json.error==1){
                        alert("Lo sentimos, su sesión ha expirado.\nSi desea seguir usando la aplicación por favor vuelva a firmarse.");
                        parent.document.location.href="../index.jsp";
                        return;
                    }
                    
                    if(callbackerror instanceof Function)
                        callbackerror(json); 
                    else{                                                
                        alert(json.error);
                    } 
                   
                }
                else{ 
                    if(callback instanceof Function)
                        callback(json);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.log(textStatus)              
                if(callbackerror instanceof Function)
                    callbackerror(XMLHttpRequest); 
            },
            contentType:"application/x-www-form-urlencoded;charset=UTF-8",
            async:true
        });
    }
    
})(jQuery);

jQuery.fn.reset = function () {
    $(this).each (function() {
        this.reset();
    });
}
