﻿$(document).ready(function(){
    $(".ajaxLoad")
        .css({opacity:0}).show()
        .ajaxStart(function(){$(this).fadeTo('fast',1.0);})
        .ajaxStop(function(){$(this).fadeTo('fast',0.0);})
        .ajaxError(function(){$(this).fadeTo('fast',0.0);
    });
});

try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {};

(function($) {
    jQuery.fn.serializeForm = function(removeSufix){
        var obj = new Object();
        var json = $(this).find("select, :input, textarea").each(function(){
            if($(this).attr("name")==""){
                $(this).attr("name",this.id);
            }
        });
        var jsonArray = $(this).find("select, input, textarea").serializeArray();
        jQuery.each(jsonArray, function(){
            obj[this.name.replace(new RegExp("^"+removeSufix),"")] = this.value;
        });
        return obj;
    }
})(jQuery);

function ajaxRequestJson(jsonString, pageName, webMethodFunc, func){
    $.ajax({type: "POST",
        data: jsonString,
        contentType: "application/json; charset=utf-8",dataType: "json",
        url: pageName+"/"+webMethodFunc,
        dataFilter: function(data) {
        try{
            var msg = JSON.parse(data);
        }
        catch(e){
            ajaxAlert("Não foi possível ler o JSON retornado de '"+webMethodFunc+"'.");
            return {sucess:false};
        }
        if (msg.hasOwnProperty('d'))
          return msg.d;
        else
          return msg;
        },
        success: function(d){
            func.call(this.constructor, d);
        },
        error: function(){ajaxAlert("Erro na chamada assíncrona '"+webMethodFunc+"'. AjaxError.")}
    });
}

        
        
    
