﻿/*
 * Object for keeping the session alive by doing an ajax request before the
 * session times out.
 */
SessionKeepAlive =
{
    delay: 10000,
    url: undefined,

    run: function()
    {
        if (this.url)
        {
            //alert("calling: " + this.url);
            $.get(this.url + "?d=" + escape(new Date().getTime()));
            setTimeout("SessionKeepAlive.run()", this.delay);
        }
    },

    // Starts the session keep alive
    // @delay = Number of minutes to wait between calls to the url
    // @url = The url to call to refresh the session
    start: function(delay, url)
    {
        // Set ajax timeout to 10 seconds
        $.ajaxSetup({
            timeout: 10000
            //,error: function() { alert("Error pinging server"); }
        });
        
        // Convert delay to millis
        this.delay = parseInt(delay) * 60000;
        this.url = url;
        setTimeout("SessionKeepAlive.run()", this.delay);
    }
};
