//
// var TARGET_URL_SHOUT2 = PATH_PREFIX_M + 'm_pshout2.php?dax=1&opt=a';
var TARGET_URL_SHOUT2 = 'modules/' + 'm_pshout2.php?dax=1&opt=a';
var TARGET_ID_SHOUT2 = 'shoutMessages';
var POLL_INTERVAL_SHOUT2 = 3;
var TIMEOUT_THRESHOLD_SHOUT2 = 10;

var Shout2 = new function() 
{
    this.targetURL = null;
    this.targetID = null;
    this.strValue = null;
    this.pollInterval = null;
    this.timeoutThreshold = null;
    this.ajax = new DAX();
    this.pollHand = null;
    this.timeoutHand = null;

    this.init = function()
    {
        var self = Shout2;
        self.targetURL = TARGET_URL_SHOUT2;
        self.targetID = TARGET_ID_SHOUT2;
        self.pollInterval = POLL_INTERVAL_SHOUT2;
        self.timeoutThreshold = TIMEOUT_THRESHOLD_SHOUT2;
        self.doPoll();
        //alert('2');
    };

    this.doPoll = function()
    {
        var self = Shout2;
        var url = self.targetURL;
        self.ajax.doGet(self.targetURL, self.showPoll);
        self.timeoutHand = setTimeout(self.handleTimeout, self.timeoutThreshold*1000);
    };

    this.showPoll = function(str)
    {
        var self = Shout2;
        self.strValue = str;
        clearTimeout(self.timeoutHand);
        self.printResult(self.strValue);
        self.doPollDelay();
    };

    this.doPollDelay = function()
    {
        var self = Shout2;
        self.pollHand = setTimeout(self.doPoll, self.pollInterval*1000);
    };

    this.stopPoll = function()
    {
        var self = Shout2;
        clearTimeout(self.pollHand);
		if (self.ajax) {
			self.ajax.abort();
		}
        clearTimeout(self.timeoutHand);
        return true;
    };

    this.handleTimeout = function()
    {
        //alert('handleTimout');
        var self = Shout2;
        self.printResult(self.strValue);
        self.doPollDelay();
    };

    this.printResult = function()
    {
        var self = Shout2;
        DAXPrintResult(self.targetID, self.strValue);
        DAXEval(self.strValue);
        //document.getElementById('div_info_a').innerHTML = self.pollHand;
        //alert('p2');
    };

}

