//**
//Register Namespace
Type.registerNamespace("envention.idbp.web.portal");

//**
//Constructor
envention.idbp.web.portal.KeepAliveComponent = function envention$idbp$web$portal$KeepAliveComponent(){
    this._refreshInterval = 300000;
    this._timeoutHandle = null;
    this._keepAliveServiceSucceededCallbackDelegate = null;
    this._keepAliveServiceFailedCallbackDelegate = null;
}

//**
//Properties

function envention$idbp$web$portal$KeepAliveComponent$set_refreshInterval(value){
    var e = Function._validateParams(arguments, [{name: "value", type: Number}]);
    if (e){ throw e };
    
    this._refreshInterval = value;
}

function envention$idbp$web$portal$KeepAliveComponent$get_refreshInterval(){
    if(arguments.length !== 0){ throw Error.parameterCount(); }
    return this._refreshInterval;
}

//**
//Overrides

function envention$idbp$web$portal$KeepAliveComponent$initialize(){
    
    this._keepAliveServiceSucceededCallbackDelegate = Function.createDelegate(this,this._keepAliveServiceSucceededCallback);
    this._keepAliveServiceFailedCallbackDelegate = Function.createDelegate(this,this._keepAliveServiceFailedCallback);
    
    Sys.Application.add_unload(Function.createDelegate(this, this._stopTimeout));
    
    this._startTimeout();
    
    envention.idbp.web.portal.KeepAliveComponent.callBaseMethod(this, "initialize"); 
}

function envention$idbp$web$portal$KeepAliveComponent$dispose(){

    if(this._keepAliveServiceSucceededCallbackDelegate !== null){
        delete this._keepAliveServiceSucceededCallbackDelegate;
    }

    if(this._keepAliveServiceFailedCallbackDelegate !== null){
        delete this._keepAliveServiceFailedCallbackDelegate;
    }
    
    envention.idbp.web.portal.KeepAliveComponent.callBaseMethod(this, "dispose");
}

//**
//Private Methods

function envention$idbp$web$portal$KeepAliveComponent$_keepAliveServiceSucceededCallback(result,userContext,methodName){
    userContext._startTimeout();
}

function envention$idbp$web$portal$KeepAliveComponent$_keepAliveServiceFailedCallback(webServiceError,userContext,methodName){
    
}

function envention$idbp$web$portal$KeepAliveComponent$_startTimeout(){
    this._timeoutHandle = window.setTimeout(Function.createDelegate(this,this._timeoutElapsed),this.get_refreshInterval());
}

function envention$idbp$web$portal$KeepAliveComponent$_stopTimeout(){
        
    //Cancel Timeout
    if(this._timeoutHandle !== null){
        window.clearTimeout(this._timeoutHandle);
        this._timeoutHandle = null;
    } 
    
}

function envention$idbp$web$portal$KeepAliveComponent$_timeoutElapsed(){
    this._timeoutHandle = null;
    envention.idbp.web.portal.KeepAliveService.Request(this._keepAliveServiceSucceededCallback, this._keepAliveServiceFailedCallback,this);
}

//**
//Prototype
envention.idbp.web.portal.KeepAliveComponent.prototype = {
    set_refreshInterval: envention$idbp$web$portal$KeepAliveComponent$set_refreshInterval,
    get_refreshInterval: envention$idbp$web$portal$KeepAliveComponent$get_refreshInterval,
    initialize: envention$idbp$web$portal$KeepAliveComponent$initialize,
    dispose: envention$idbp$web$portal$KeepAliveComponent$dispose,
    _keepAliveServiceSucceededCallback: envention$idbp$web$portal$KeepAliveComponent$_keepAliveServiceSucceededCallback,
    _keepAliveServiceFailedCallback: envention$idbp$web$portal$KeepAliveComponent$_keepAliveServiceFailedCallback,
    _startTimeout: envention$idbp$web$portal$KeepAliveComponent$_startTimeout,
    _stopTimeout: envention$idbp$web$portal$KeepAliveComponent$_stopTimeout,
    _timeoutElapsed: envention$idbp$web$portal$KeepAliveComponent$_timeoutElapsed
    
}

//**
//Register Class
envention.idbp.web.portal.KeepAliveComponent.registerClass("envention.idbp.web.portal.KeepAliveComponent", Sys.Component);

//Notify Script Loaded
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

