﻿//whilst testing set test = 1 otherwise set test = 0
var test = 0;


if (test == 1) {
    //document.write("test=1");
    addLoadEvent(runTESTPopup);
}
else{
    //document.write("test=0");
        addLoadEvent(randPopup);
};

function runTESTPopup() {

    var loadScript = document.createElement('script')
    loadScript.setAttribute("type", "text/javascript")
    loadScript.setAttribute("src", "Includes/TESTCBIMainSurveyPopup.js")
    loadScript.setAttribute("wmode", "transparent");
    document.getElementsByTagName("body")[0].appendChild(loadScript);
}

function randPopup() {
    //probability of showing popup ie if <= 7 then 70% chance
    //change for different probabilities to a number between 1 and 10

    if (Math.floor(Math.random() * 11) <= 5) {

        var loadScript = document.createElement('script')
        loadScript.setAttribute("type", "text/javascript")
        loadScript.setAttribute("src", "Includes/CBIMainSurveyPopup.js")
        loadScript.setAttribute("wmode", "transparent");
        document.getElementsByTagName("body")[0].appendChild(loadScript);
    }
}


//closure function to add new onload events after pre-existing ones
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

