function PingTimeOut(handler, timeout) {
    this.callBack = handler.timeoutCallBack;
    this.failcallback = handler.failcallback
    this.timeout_default = 6000;
    this.handler = handler;
    this.timeout = timeout || this.timeout_default;
    this.xhr = null;
}

PingTimeOut.prototype.Init = function () {
    var self = this;
    this.timeoutId = setTimeout(function () { self.verificaSituacao(self); }, this.timeout);
};

PingTimeOut.prototype.verificaSituacao = function (self) {
    if (self.xhr) {
        self.xhr.abort();
    }
    self.xhr = $.ajax({
        url: urlGlobal + "State/Ping",
        data: {},
        dataType: 'jsonp',
        beforeSend: function () { },
        error: function (jqXHR, textStatus, errorThrown) {
            if (jqXHR.status == 200) {
                if (self.callBack)
                    self.callBack(self.handler);

                clearTimeout(self.timeoutId);
                return;
            } else if (self.failcallback) {
                self.failcallback();
            }
            self.timeoutId = setTimeout(function () { self.verificaSituacao(self); }, self.timeout);
        },
        success: function (data) {
            if (self.callBack)
                self.callBack(self.handler);

            clearTimeout(self.timeoutId);
        }
    });
};