function Stub()
{
    this.survey = "qst/qst09008";
    this.rawUrl = "http://survey.questus.com/survey/qst/qst09008";
    this.chance = 0.0;  // percent chance that popup appears (e.g.: 0.1==10%)
    this.markup = '<div id="decipherInviteBox" style=\n    "display:none;border: 2px outset #335EAC; position: absolute; z-index:25000; top: 100px; left: 250px; height: 232px; width: 390px">\n\n\n<img style="border:0px" \n    src="http://survey.questus.com/survey/qst/qst09008/surveypop1.jpg"\n    usemap="#decipherInviteMap"/>\n<script language="javascript" type="text/javascript">\ndecipher = {\n    hide: function() {\n        document.getElementById(\'decipherInviteBox\').style.display=\'none\';\n    },\n    fadeLoop : function (o, opacity) {\n        decipher.setOpacity(o, opacity);\n        if (opacity < 100)\n        {\n            opacity += 4;\n            if (opacity > 100) opacity = 100;\n            window.setTimeout(\n               function () { decipher.fadeLoop(o, opacity) },\n                50);\n        }\n    },\n    setOpacity : function (o, opacity) {\n        o.style.filter = "alpha(style=0,opacity:" + opacity + ")";  // IE\n        o.style.KHTMLOpacity = opacity / 100; // Konqueror\n        o.style.MozOpacity = opacity / 100; // Mozilla (old)\n        o.style.opacity = opacity / 100; // Mozilla (new)\n    },\n    box: document.getElementById(\'decipherInviteBox\')\n}\nsetTimeout(function() {\ndecipher.setOpacity(decipher.box, 0);\ndecipher.box.style.display = \'\';\ndecipher.fadeLoop(decipher.box, 0);\n}, 10);\n</script>\n<map name=\'decipherInviteMap\'>\n    <!-- close button -->\n<area style="cursor:pointer" shape="rect" coords="195,184,309,213" onclick="decipher.hide()" />\n<area style="cursor:pointer" shape="rect" coords="195,144,309,173" href="__SURVEY_URL__" />\n</map>\n\n\n</div>\n';
    // cookie settings
    this.cookie = {
        name: "decipherinc_seen_popup",
        value: "set",
        path: "/",
        expire: ""
    };
}

Stub.prototype = {
    stealthWindow : function () 
    {
        var exiturl = "stealth.html";
        var win2 = window.open(exiturl,'stealth','height=1,width=300,scrollbars=yes,toolbars=no,location=no,resizable=yes, status=no');
        win2.screenX = screen.width;
        win2.screenY = screen.height;
    	if(win2.focus())
	    {
            win2.blur();
        }
        window.focus();
    },
    setCookie: function()
    {
        var c=this.cookie;
        var now=new Date();
        now.setTime(now.getTime()+1000*60*60*24*3);
        document.cookie=[c.name,"=",escape(c.value),"; expires=",c.expires ? c.expires : now.toGMTString(),c.path ? "; path=" + c.path : ''].join('');
    },
    getCookie: function(name)
    {
        var cookies = document.cookie;
        var startAt = cookies.indexOf(name + "=");
        if(startAt !== -1)
        {
            startAt = startAt + name.length + 1;
            var endAt = cookies.indexOf(";", startAt);
            if(endAt == -1) endAt = cookies.length;
            return unescape(cookies.substring(startAt, endAt));
        }
        return null;
    },
    getFakeArgs: function()
    {
        var rex = new RegExp('/survey/' + this.survey);
        var matchUrl = function (s) { 
            if (!s)
                return false;
            return s.search(rex) >= 0;
        }
        scripts = document.getElementsByTagName('script');
        for (var i=0; i<scripts.length; i++) {
            var sx = scripts[i];
            if (matchUrl(sx.getAttribute('src')))  break;
        }
        var gotUrl = sx.getAttribute('src');
        var qmIndex = gotUrl.indexOf('#');
        if (qmIndex < 0) return '';
        var ret = gotUrl.slice(qmIndex + 1);
        return ret;
    },
    mergeUrl: function(url, args) {
        if (args == "") return url;
        var qmIndex = url.indexOf('?');
        if (qmIndex < 0) return url + '?' + args;
        return url + '&' + args;
    },
    begin: function()
    {
        // cookie here keeps iframe from loading more than once
        if(this.getCookie(this.cookie.name) != "set")
        {
            this.setCookie(this.cookie);
            var r = Math.random();
            if (r >= (1.0 - this.chance))// chance is equal to 1-n
            {
                var fakeArgs = this.getFakeArgs();
                var surveyUrl = this.mergeUrl(this.rawUrl, fakeArgs);
                var markup = this.markup.replace('__SURVEY_URL__', surveyUrl);
                document.write(markup);
            }
        }
    }
}

Serve = new Stub();
Serve.begin();

// vim:set ft=javascript:
