﻿// Init js object
var FPPopper = new Object();
FPPopper.sc1 = null;
FPPopper.scpopper = null;
FPPopper.ifr = null;
FPPopper.hasData = false;
FPPopper.url = 'http://www.futurespress.net/popper/Render.aspx?id=';
//FPPopper.url = 'http://localhost/FPCorporateSite/popper/Render.aspx?id=';

FPPopper.openUrl = '';
FPPopper.imageUrl = '';
FPPopper.width = '';
FPPopper.height = '';
FPPopper.loadJQueryInteralId = 0;

FPPopper.call = function(ws) {
    // Remove tag script scriptData
    if (this.sc1)
        this.sc1.parentNode.removeChild(this.sc1);   
    this.sc1 = document.createElement('SCRIPT');
    this.sc1.id = 'sc1';
    this.sc1.type = 'text/javascript';
    this.sc1.src = ws;   
    var styleBasic = document.createElement('LINK');
    styleBasic.type = 'text/css';
    styleBasic.rel = 'stylesheet';
    styleBasic.href = 'http://www.futurespress.net/popper/basic.css';
    //styleBasic.href = 'http://localhost/FPCorporateSite/popper/basic.css';

    // Append script tag
    try {
        document.getElementsByTagName('head')[0].appendChild(this.sc1);
        document.getElementsByTagName('head')[0].appendChild(styleBasic);
    }
    catch (ex) {
        document.body.appendChild(this.sc1);
        document.body.appendChild(styleBasic);
    }
}
FPPopper.runScript = function() {
    this.loadJQueryInteralId = setInterval("FPPopper.includeScript()", 200);
}
FPPopper.includeScript = function() {
    if (typeof jQuery == "undefined") {
        var jqueryScript = document.createElement('SCRIPT');
        jqueryScript.type = 'text/javascript';
        jqueryScript.src = 'http://www.futurespress.net/popper/jquery-1.3.2.min.js';
        //jqueryScript.src = 'http://localhost/FPCorporateSite/popper/jquery-1.3.2.min.js';
        try {
            document.getElementsByTagName('head')[0].appendChild(jqueryScript);
        }
        catch (ex) {
            document.body.appendChild(jqueryScript);
        }
    }
    else {
        clearInterval(this.loadJQueryInteralId);
        jQuery.getScript('http://www.futurespress.net/popper/popup.modal.js', function() {
            var ctr = document.createElement('DIV');
            if (ctr) {
                ctr.className = 'fp_popper_div';
                ctr.style.display = 'none';
                ctr.style.margin = '5px';
				ctr.style.width = FPPopper.width +'px';
				ctr.style.height = FPPopper.height +'px';
                var html = '<a class=\"simplemodal-close\" id=\"fp_link\" onclick=\"FPPopper.openLink();\" target=\"_blank\" href=\"\">' +
                            '<img border=\"0\" src=\"' + FPPopper.imageUrl + '\" style=\"width:' + FPPopper.width + 'px; height:' + FPPopper.height + 'px;\"/></a>';
                ctr.innerHTML = html;
                document.body.appendChild(ctr);
                FPPopper.hasData = true;
                if (FPPopper.ifr)
                    FPPopper.ifr.src = 'about:blank';
                jQuery('.fp_popper_div').modal();
            }
        });
    }
}

FPPopper.execute = function() {
    // On Loading...
    var ws = this.url + FP_Popper_Id + '&rand=' + Math.random();
    if (typeof FP_Popper_AffCode != 'undefined')
        ws += '&AffCode=' + FP_Popper_AffCode;
    this.call(ws);
}
FPPopper.callBack = function() {
    FPPopper.runScript();
}
FPPopper.openLink = function() {
    window.open(this.openUrl, '');
}
window.setTimeout("FPPopper.execute()", 100);

