﻿
var ADT = {
    checkFlag: true,
    startTime: null,
    intervalId: null, 
    maximumPollTimeout: 30 * 60 * 1000, // check for half hour, otherwise stop polling

    oldload: window.onload,

    init: function() {
        if (ADT.oldload) ADT.oldload();
        ADT.startTime = new Date();
        ADT.checkFlag = true;
        ADT.checkForMessages();
    },

    checkForMessages: function() {
        try {
            clearInterval(ADT.intervalId);
            var testDate = new Date();
            if ((testDate.getTime() - ADT.startTime.getTime()) >= ADT.maximumPollTimeout) { return; } // stop

            if (location.hash != "") { 
              
                var iframeEl = document.getElementById ? document.getElementById('ADT_IFRAME') : document.all ? document.all['ADT_IFRAME'] : null;
                iframeEl.style.height = "auto";
                var newHeight = parseInt(location.hash.substr(1), 10);
                iframeEl.style.height = newHeight + "px";
                //history.back(-1); // clean history
            }

            if (ADT.checkFlag == true) {
                ADT.intervalId = setInterval(ADT.checkForMessages, 500);
            }

        } catch (e) {
            clearInterval(ADT.intervalId);
            ADT.checkFlag = false;
        }
    }
};

window.onload = function() { 
    ADT.init(); 
} 


