// //
// Copyright 2005 SurveySite. All rights reserved.

// Page: Danmark-3388mt
// Date: 2007-01-31


// Multiple script protection.
if (!window.SiteRecruit_Globals) {

// Create the configuration, globals, and constants namespaces.
var SiteRecruit_Config = new Object();
var SiteRecruit_Globals = new Object();
var SiteRecruit_Constants = new Object();

// Validation variables.
SiteRecruit_Globals.parseFlag = false;
SiteRecruit_Globals.empty = false;

// Browser information.
SiteRecruit_Constants.browser = new Object();
SiteRecruit_Constants.browser.internetExplorer = 'Microsoft Internet Explorer';
SiteRecruit_Constants.browser.mozilla = 'Netscape';

// Check browser information.
SiteRecruit_Globals.browserName = navigator.appName; 
SiteRecruit_Globals.browserVersion = parseInt(navigator.appVersion);

// Initialize browser flags.
SiteRecruit_Globals.isInternetExplorer = false;
SiteRecruit_Globals.isMozilla = false;
SiteRecruit_Globals.isInternetExplorer7 = false;

// Check for Internet Explorer based browsers.
if (SiteRecruit_Globals.browserName == SiteRecruit_Constants.browser.internetExplorer)
{
    if (SiteRecruit_Globals.browserVersion > 3)
    {
        // Only 5.5 and above.
        var a = navigator.userAgent.toLowerCase();
        if (a.indexOf("msie 5.0") == -1 && a.indexOf("msie 5.0") == -1)
        {
            SiteRecruit_Globals.isInternetExplorer = true;
        }
        
        // Check for 7.
        if (a.indexOf("msie 7") != -1)
        {
            SiteRecruit_Globals.isInternetExplorer7 = true;
        }
    }
}

// Check for Mozilla based browsers.
if (SiteRecruit_Globals.browserName == SiteRecruit_Constants.browser.mozilla)
{
    if (SiteRecruit_Globals.browserVersion > 4)
    {
        SiteRecruit_Globals.isMozilla = true;
    }
}

// Cookie lifetime.
SiteRecruit_Constants.cookieLifetimeType = new Object();
SiteRecruit_Constants.cookieLifetimeType.duration = 1;
SiteRecruit_Constants.cookieLifetimeType.expireDate = 2;
    
// Invitation type.
SiteRecruit_Constants.invitationType = new Object();
SiteRecruit_Constants.invitationType.standard = 0;
SiteRecruit_Constants.invitationType.email = 1;
SiteRecruit_Constants.invitationType.domainDeparture = 2;
    
// Cookie type flags.
SiteRecruit_Constants.cookieType = new Object();
SiteRecruit_Constants.cookieType.alreadyAsked = 1;
SiteRecruit_Constants.cookieType.inProgress = 2;

// Alignment types.
SiteRecruit_Constants.horizontalAlignment = new Object();
SiteRecruit_Constants.horizontalAlignment.left = 0;
SiteRecruit_Constants.horizontalAlignment.middle = 1;
SiteRecruit_Constants.horizontalAlignment.right = 2;
SiteRecruit_Constants.verticalAlignment = new Object();
SiteRecruit_Constants.verticalAlignment.top = 0;
SiteRecruit_Constants.verticalAlignment.middle = 1;
SiteRecruit_Constants.verticalAlignment.bottom = 2;

// Survey cookie configuration.
SiteRecruit_Config.cookieName = 'msresearch';
SiteRecruit_Config.cookieDomain = '.microsoft.com';
SiteRecruit_Config.cookiePath = '/';

// Cookie element join character.
SiteRecruit_Constants.cookieJoinChar = ':';

// Settings for cookie lifetime.
SiteRecruit_Config.cookieLifetimeType = 1;

    // Duration of the cookie in days.
    SiteRecruit_Config.cookieDuration = 90;

// Duration of the rapid cookie.
SiteRecruit_Config.rapidCookieDuration = 0;
// //
// Copyright 2005 SurveySite. All rights reserved.

// Class to read and write cookies.
function SiteRecruit_CookieUtilities()
{
    // Cookie duration factor, set to days.
    this.cookieDurationFactor = 1000 * 60 * 60 * 24;
    
    // Cookie removal date.
    this.cookieRemovalDate = 'Fri, 02-Jan-1970 00:00:00 GMT';

    // Attach methods.
    this.setSurveyCookie = CookieUtilities_setSurveyCookie;
    this.setSurveyCookieX = CookieUtilities_setSurveyCookieX;
    this.getSurveyCookie = CookieUtilities_getSurveyCookie;
    this.removeSurveyCookie = CookieUtilities_removeSurveyCookie;
    this.surveyCookieExists = CookieUtilities_surveyCookieExists;

    // Set the cookie to the standard cookie string.
    function CookieUtilities_setSurveyCookie(cookieType)
    {
        this.setSurveyCookieX(cookieType, false);
    }

    // New cookie method to optionally support rapid cookies.
    function CookieUtilities_setSurveyCookieX(cookieType, useRapidCookie)
    {
        var currentDate = new Date();  
        var expireDate = new Date();
        
        var duration = SiteRecruit_Config.cookieDuration;
        if (useRapidCookie)
        {
            duration = SiteRecruit_Config.rapidCookieDuration;
        }
        
        if (SiteRecruit_Config.cookieLifetimeType == SiteRecruit_Constants.cookieLifetimeType.duration)
        {
            expireDate.setTime(currentDate.getTime()
                + (duration * this.cookieDurationFactor));
        }
        else
        {
            expireDate.setTime(Date.parse(SiteRecruit_Config.cookieExpireDate));
        }        
        
        var c = '=' + cookieType;
        
        if (cookieType == SiteRecruit_Constants.cookieType.inProgress)
        {
            var j = SiteRecruit_Constants.cookieJoinChar;
            c += j + escape(document.location)
                + j + currentDate.getTime()
                + j + '0';
        }
        
        c += '; path=' + SiteRecruit_Config.cookiePath;

        if (cookieType == SiteRecruit_Constants.cookieType.alreadyAsked)
        {
            c += '; expires=' + expireDate.toGMTString();
        }
            
        if (SiteRecruit_Config.cookieDomain != '')
        {
            c += '; domain=' + SiteRecruit_Config.cookieDomain;
        }

        document.cookie = SiteRecruit_Config.cookieName + c;
        
        return true;
    }
    
    // Grabs the value of the survey cookie.
    function CookieUtilities_getSurveyCookie()
    {
        var c = '';
        
        c = document.cookie.toString();

        var index = c.indexOf(SiteRecruit_Config.cookieName);
        var endc = c.length;
        c = c.substring(index, endc);

        var ind1 = c.indexOf(';');
        if (ind1 != -1)
        {   
            c = c.substring(0, ind1);
        }

        var ind2 = c.indexOf('=');
        c = c.substring(ind2 + 1);

        if (index == -1) return null;
        
        return c;
    }
        
    // Removes the cookie by setting to an expired date.
    function CookieUtilities_removeSurveyCookie()
    {
        var c = SiteRecruit_Config.cookieName + '='
            + '; path=' + SiteRecruit_Config.cookiePath
            + '; expires=' + this.cookieRemovalDate;

        if (SiteRecruit_Config.cookieDomain != '')
        {
            c += '; domain=' + SiteRecruit_Config.cookieDomain;
        }

        document.cookie = c;
    }

    // Returns true if a survey cookie exists. Call optionally with a type.
    function CookieUtilities_surveyCookieExists(cookieType)
    {
        var t = '';
        if (cookieType)
        {
            t = cookieType;
        }
        
        return (document.cookie.indexOf(SiteRecruit_Config.cookieName + '=' + t) != -1)
    }
}

// Create an instance of the utils.
SiteRecruit_Globals.cookieUtils = new SiteRecruit_CookieUtilities();
// //
// Copyright 2005 SurveySite. All rights reserved.

// Frequency of the popup.
SiteRecruit_Config.frequency = 0;

// Skips the cookie test. Use for debugging.
SiteRecruit_Config.useCookie = true;

// Invitation constructor - sets necessary defaults.
function SiteRecruit_InvitationConfiguration()
{
    this.otherCookies = new Array();
    this.otherVariables = new Array();    
}

// The array of survey configurations.
SiteRecruit_Config.invitations = new Array();

// Iterate through the survey configurations.

    
            
        SiteRecruit_Config.invitations[0] = new SiteRecruit_InvitationConfiguration();
        SiteRecruit_Config.invitations[0].weight = 100;
    
        SiteRecruit_Config.invitations[0].projectId = 'Danmark-3388mt';
        SiteRecruit_Config.invitations[0].invitationType = 2;
        
        SiteRecruit_Config.invitations[0].acceptUrl = 'http://survey2.surveysite.com/wix/p12030529.aspx';
        SiteRecruit_Config.invitations[0].viewUrl = 'http://web.survey-poll.com/tc/CreateLog.aspx';
        SiteRecruit_Config.invitations[0].acceptParams = 'wave=1&site=115';
        SiteRecruit_Config.invitations[0].viewParams = 'log=comscore/view/p12030529-view.log&site=115';
        
        SiteRecruit_Config.invitations[0].invitationContent = '<table width="360" cellpadding="3" cellspacing="0" border="0" bgcolor="#FFFFFF"><tr><td> <table width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor="#999999"><tr><td> <table width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#FFFFFF"><tr valign="top"><td> <img src="http://www.microsoft.com/library/svy/logo-stripe.gif" /><a href="Close" onclick="@declineHandler"><img border="0" src="http://www.microsoft.com/library/svy/close.gif" /></a><br /> <img src="http://www.microsoft.com/library/svy/top-stripe.gif" /> <table width="100%" cellpadding="5"><tr><td>  <div style="font-family: Verdana, Arial, Helvetica, sans-serif;	font-size: 11px; color: #000000; margin: 0 0 15px 0;">Microsoft udfører en onlineundersøgelse for at forstå brugen af websiten www.microsoft.com/danmark. Vi vil gerne vide, hvilke sider du besøger i dag, og derefter bede dig om at udfylde en undersøgelse, når du forlader websiten www.microsoft.com/danmark.  Vil du deltage?</div>  <div align="center" style="margin: 0; padding: 0"> <form id="SiteRecruit_invitationForm" onsubmit="@acceptHandler" style="margin: 0; padding: 0"> <input style="margin: 0; padding: 0" type="submit" value="  Ja  " />&nbsp;&nbsp; <input style="margin: 0; padding: 0"  type="button" value=" Nej " onclick="@declineHandler" /> </form> </div>  <div style="font-family: Verdana, Arial, Helvetica, sans-serif;	font-size: 11px; color: #000000; margin: 15px 0 2px 0;"><a href="http://survey2.surveysite.com/wi/p12030529/PrivacyStatementDenmarkp12030529.html" target="_blank">Erklæring om beskyttelse af personlige oplysninger</a></div>  </td></tr></table> <img src="http://www.microsoft.com/library/svy/bottom-stripe.gif" /></td></tr></table> </td></tr></table> </td></tr></table>   '; 

        SiteRecruit_Config.invitations[0].invitationHeight = 210;
        SiteRecruit_Config.invitations[0].invitationWidth = 390;
        SiteRecruit_Config.invitations[0].revealDelay = 1000;
        SiteRecruit_Config.invitations[0].horizontalAlignment = 1;
        SiteRecruit_Config.invitations[0].verticalAlignment = 0;
        SiteRecruit_Config.invitations[0].horizontalMargin = 0;
        SiteRecruit_Config.invitations[0].verticalMargin = 0;
        SiteRecruit_Config.invitations[0].hideBlockingElements = true;
        SiteRecruit_Config.invitations[0].autoCentering = true;
    
            
            
                    SiteRecruit_Config.invitations[0].trackerUrl = 'http://www.microsoft.com/h/da-DK/s/SiteRecruit_Tracker_Danmark-3388mt.htm';
                
        SiteRecruit_Config.invitations[0].useRapidCookie = false;
        
                
    
// //
// Copyright 2005 SurveySite. All rights reserved.

// Class to test for frequencies and eligibility and start surveys.
function SiteRecruit_Primer()
{
    // Attach methods.
    this.isEligible = Primer_isEligible;
    this.srandom = Primer_srandom;

    // Custom random number generator.
    function Primer_srandom()
    {
        var n = 1000000000;
        
        function ugen(old, a, q, r, m)
        {
            var t = Math.floor(old / q);
            t = a * (old - (t * q)) - (t * r);
            return Math.round((t < 0) ? (t + m) : t);
        }
        
        var m1 = 2147483563;
        var m2 = 2147483399;
        var a1 = 40014;
        var a2 = 40692;
        var q1 = 53668;
        var q2 = 52774;
        var r1 = 12211;
        var r2 = 3791;
        var x = 67108862;
        var shuffle = new Array(32);
        var g1 = (Math.round(((new Date()).getTime() % 100000)) & 0x7FFFFFFF);
        var g2 = g1;
        var i = 0;
        
        for (; i < 19; i++)
        {
            g1 = ugen(g1, a1, q1, r1, m1);
        }
        for (i = 0; i < 32; i++)
        {
            g1 = ugen(g1, a1, q1, r1, m1);
            shuffle[31 - i] = g1;
        }
        g1 = ugen(g1, a1, q1, r1, m1);
        g2 = ugen(g2, a2, q2, r2, m2);
        var s = Math.round((shuffle[Math.floor(shuffle[0] / x)] + g2) % m1);
    
        return Math.floor(s / (m1 / (n + 1))) / n;
    }

    // Decide whether to hit the user with the invitation.
    function Primer_isEligible()
    {
        if (!SiteRecruit_Config.useCookie || !SiteRecruit_Globals.cookieUtils.surveyCookieExists())
        {
            // Roll the dice, and inject the survey scripts if the user is chosen.
            if (SiteRecruit_Config.frequency > Math.random())
            {
                return true;
            }
        }
        
        return false;
    }
}

// Run the builder only if it qualifies below.
SiteRecruit_Globals.startBuilder = false;

// Only kick things off if it's a known browser.
if (SiteRecruit_Globals.isInternetExplorer || SiteRecruit_Globals.isMozilla)
{
    // Create a primer and try to run a survey.
    SiteRecruit_Globals.primer = new SiteRecruit_Primer();
    if (SiteRecruit_Globals.primer.isEligible())
    {  
        SiteRecruit_Globals.startBuilder = true;
        
            }
}// //
// Copyright 2005 SurveySite. All rights reserved.

// Class to intercept users and take them to invitations.
function SiteRecruit_InvitationBuilder()
{
    // Other cookie and variables join and equality character.
    this.othersJoinChar = ';';
    this.othersEqualityChar = ':';
    
    // Name of invitation layer and form.
    this.invitationLayerName = 'SiteRecruit_invitationLayer';
    this.invitationFormName = 'SiteRecruit_invitationForm';
    
    // Substitution tags.
    this.acceptHandlerTag = '\\@acceptHandler';
    this.declineHandlerTag = '\\@declineHandler';
    
    // Handler function calls.
    this.acceptHandlerCode = 'return SiteRecruit_Globals.builder.onAccept(this)';
    this.declineHandlerCode = 'SiteRecruit_Globals.builder.onDecline(this); return false';
    
    // The time to wait before hiding the invitation.
    this.acceptHideTimeout = 1500;
    this.declineHideTimeout = 20;
    
    // The code to call to hide the invite.
    this.hideInvitationCode = 'SiteRecruit_Globals.builder.hideInvitation()';
    
    // URL parameter names.
    this.versionParamName = 'version';
    this.frequencyParamName = 'frequency';
    this.weightParamName = 'weight';
    this.locationParamName = 'location';
    this.referrerParamName = 'referrer';
    this.otherCookiesParamName = 'otherCookies';
    this.otherVariablesParamName = 'otherVariables';
    this.browserWidthParamName = 'browserWidth';
    this.browserHeightParamName = 'browserHeight';

    // The created invitation runtime.
    this.runtime = null;
    
    // Saved blocking objects.
    this.blockingElements = new Array();

    // Attach utility methods.
    this.getCookieValue = InvitationBuilder_getCookieValue;
    this.getVariableValue = InvitationBuilder_getVariableValue;
    this.submitViaImage = InvitationBuilder_submitViaImage;
    this.validateEmailAddress = InvitationBuilder_validateEmailAddress;

    // Attach core methods.
    this.start = InvitationBuilder_start;
    this.chooseInvitation = InvitationBuilder_chooseInvitation;

    // Attach invitation methods.
    this.injectInvitation = InvitationBuilder_injectInvitation;
    this.getPageLeftOffset = InvitationBuilder_getPageLeftOffset;
    this.getPageTopOffset = InvitationBuilder_getPageTopOffset;
    this.getPageWidth = InvitationBuilder_getPageWidth;
    this.getPageHeight = InvitationBuilder_getPageHeight;
    this.setInvitationPosition = InvitationBuilder_setInvitationPosition;
    this.showInvitation = InvitationBuilder_showInvitation;
    this.hideInvitation = InvitationBuilder_hideInvitation;
    this.hideBlockingElements = InvitationBuilder_hideBlockingElements;
    this.showBlockingElements = InvitationBuilder_showBlockingElements;
    this.onAccept = InvitationBuilder_onAccept;
    this.onDecline = InvitationBuilder_onDecline;
    this.addParam = InvitationBuilder_addParam;

    // Grabs the value of a specified client cookie.
    function InvitationBuilder_getCookieValue(cookieName)
    {
        var c = '';
        
        c = document.cookie.toString();

        var index = c.indexOf(cookieName);
        var endc = c.length;
        c = c.substring(index, endc);

        var ind1 = c.indexOf(';');
        if (ind1 != -1)
        {   
            c = c.substring(0, ind1);
        }

        var ind2 = c.indexOf('=');
        c = c.substring(ind2 + 1);

        if (index == -1) return null;
        
        return c;
    }
    
    // Safely attempts to grab a form variable.
    function InvitationBuilder_getVariableValue(expression)
    {
        var r = '';
        
        // Split the expression into form and variable name.
        var values = expression.split('.');
        if (values.length == 2)
        {
            formName = values[0];
            variableName = values[1];
            
            var f = document.forms[formName];
            if (f)
            {
                v = document.forms[formName].elements[variableName];
                if (v)
                {
                    r = v.value;
                }
            }
        }
        
        return r;
    }
    
    // Submits a request via an image link.
    function InvitationBuilder_submitViaImage(url)
    {
        var i = new Image();
        i.src = url + '&' + Math.random();
        
        // Random number is so that browsers will not cache the image.
    }
       
    // Returns true if an email address is valid.
    function InvitationBuilder_validateEmailAddress(address)
    {
        return (address.indexOf('.') > 2) && (address.indexOf('@') > 0);
    }
    
    // Start a survey invitation.
    function InvitationBuilder_start()
    {
        var invitations = SiteRecruit_Config.invitations;
        
        if (invitations.length > 0)
        {
            // Determine which survey to run.
            var invitation = this.chooseInvitation(invitations);
            
            // Store the chosen invitation in the globals.
            SiteRecruit_Globals.chosenInvitation = invitation;

            if (SiteRecruit_Config.useCookie)
            {
                // Mark their tracks.
                SiteRecruit_Globals.cookieUtils.setSurveyCookieX(SiteRecruit_Constants.cookieType.alreadyAsked,
                    invitation.useRapidCookie);
                
                // Bail if the cookie doesn't set properly.
                if (!SiteRecruit_Globals.cookieUtils.surveyCookieExists(SiteRecruit_Constants.cookieType.alreadyAsked))
                {
                    return;
                }
            }
                     
            this.runtime = new SiteRecruit_InvitationRuntime();
            this.injectInvitation(invitation);
            
            if (invitation.revealDelay > 0)
            {
                setTimeout('SiteRecruit_Globals.builder.showInvitation()', invitation.revealDelay);
            }
            else
            {
                this.showInvitation();
            }
        }
    }
    
    // Chooses an invitation to run based on the configured weightings.
    function InvitationBuilder_chooseInvitation(invitations)
    {
        var invitation = null;
        
        var f = invitations[0].weight;
        
        var totalWeight = 0;
        var realWeightInvitations = new Array();
        
        // Find the spot.
        for (var s = 0; s < invitations.length; s++)
        {
            if (invitations[s].weight >= 1)
            {
                totalWeight += invitations[s].weight;
                realWeightInvitations[realWeightInvitations.length] = s;
            }
        }
        
        // Only choose an invitation if the weight is sensible.
        if (totalWeight >= 1)
        {
            var r = Math.floor(Math.random() * totalWeight) + 1;
            
            var currentSum = 0;
            for (var s = 0; s < realWeightInvitations.length; s++)
            {
                var newInvitationNum = realWeightInvitations[s];
                currentSum += invitations[newInvitationNum].weight;
            
                if (r <= currentSum)
                {
                    invitation = invitations[newInvitationNum];
                    break;
                } 
            }
        }
        else
        {
            // Remove cookie, as this person didn't get hit.
            this.removeCookie();
        }
        
        return invitation;
    }
        
    // Injects the survey invitation layer.
    function InvitationBuilder_injectInvitation(invitation)
    {
        // First register the view.
        this.submitViaImage(invitation.viewUrl + '?' + invitation.viewParams);

        // Replace all of the template vars.
        var ar = new RegExp(this.acceptHandlerTag, 'g');
        var dr = new RegExp(this.declineHandlerTag, 'g');

        var content = invitation.invitationContent.replace(ar, this.acceptHandlerCode);
        content = content.replace(dr, this.declineHandlerCode);

        // Write the layer and the content.
        document.write('<div id="' + this.invitationLayerName
            + '" style="position:absolute'
            + '; left:0'
            + '; top:0'
            + '; z-index:11'
            + '; visibility: hidden">');
        document.write(content);
        document.write('</div>');
    }
    
    // Returns the left offset of the page.
    function InvitationBuilder_getPageLeftOffset()
    {
        var x = 0;
        var d = document;
        
        if (typeof(window.pageYOffset) == 'number')
        {
            x = window.pageXOffset;
        }
        else if (d.body && (d.body.scrollLeft || d.body.scrollTop))
        {
            x = d.body.scrollLeft;
        }
        else if (d.documentElement && (d.documentElement.scrollLeft || d.documentElement.scrollTop))
        {
            x = d.documentElement.scrollLeft;
        }
        
        return x;
    }
    
    // Returns the top offset of the page.
    function InvitationBuilder_getPageTopOffset()
    {
        var y = 0;
        var d = document;
        
        if (typeof(window.pageYOffset) == 'number')
        {
            y = window.pageYOffset;
        }
        else if (d.body && (d.body.scrollLeft || d.body.scrollTop))
        {
            y = d.body.scrollTop;
        }
        else if (d.documentElement && (d.documentElement.scrollLeft || d.documentElement.scrollTop))
        {
            y = d.documentElement.scrollTop;
        }
        
        return y;
    }

    // Returns the window width.
    function InvitationBuilder_getPageWidth()
    {
        var w = 0;
        var d = document;
        
        if (typeof(window.innerWidth) == 'number')
        {
            w = window.innerWidth;
        }
        else if (d.documentElement && (d.documentElement.clientWidth || d.documentElement.clientHeight))
        {
            w = d.documentElement.clientWidth;
        }
        else if (d.body && (d.body.clientWidth || d.body.clientHeight))
        {
            w = d.body.clientWidth;
        }
        
        return w;
    }
    
    // Returns the window height.
    function InvitationBuilder_getPageHeight()
    {
        var h = 0;
        var d = document;
        
        if (typeof(window.innerWidth) == 'number')
        {
            h = window.innerHeight;
        }
        else if (d.documentElement && (d.documentElement.clientWidth || d.documentElement.clientHeight))
        {
            h = d.documentElement.clientHeight;
        }
        else if (d.body && (d.body.clientWidth || d.body.clientHeight))
        {
            h = d.body.clientHeight;
        }
        
        return h;
    }
    
    // Moves the invitation around.
    function InvitationBuilder_setInvitationPosition(x, y)
    {    
        document.getElementById(this.invitationLayerName).style.left = x + 'px';
        document.getElementById(this.invitationLayerName).style.top = y + 'px';
    }

    // Shows the invitation layer.
    function InvitationBuilder_showInvitation()
    {
        var invitation = SiteRecruit_Globals.chosenInvitation;
        
        var x = 0;
        var y = 0;

        var h = invitation.horizontalAlignment;
        var v = invitation.verticalAlignment;

        if (h == SiteRecruit_Constants.horizontalAlignment.left)
        {
            x = invitation.horizontalMargin;
        }
        else if (h == SiteRecruit_Constants.horizontalAlignment.middle)
        {
            x = (this.getPageWidth() - invitation.invitationWidth) / 2;
        }
        else if (h == SiteRecruit_Constants.horizontalAlignment.right)
        {
            x = this.getPageWidth() - invitation.invitationWidth - invitation.horizontalMargin;
        }
        
        if (v == SiteRecruit_Constants.verticalAlignment.top)
        {
            y = invitation.verticalMargin;
        }
        else if (v == SiteRecruit_Constants.verticalAlignment.middle)
        {
            y = (this.getPageHeight() - invitation.invitationHeight) / 2;
        }
        else if (v == SiteRecruit_Constants.verticalAlignment.bottom)
        {
            y = this.getPageHeight() - invitation.invitationHeight - invitation.verticalMargin;
        }

        this.setInvitationPosition(x, y);

        if (invitation.hideBlockingElements)
        {
            // Collect the visible blocking elements.
            var objects = document.getElementsByTagName('OBJECT');
            for (var i = 0; i < objects.length; i++)
            {
                if (objects.item(i).style.visibility != 'hidden')
                {
                    this.blockingElements.push(objects.item(i));
                }
            }

            var selects = document.getElementsByTagName('SELECT');
            for (var i = 0; i < selects.length; i++)
            {
                if (selects.item(i).style.visibility != 'hidden')
                {
                    this.blockingElements.push(selects.item(i));
                }
            }

            this.hideBlockingElements();
        }

        // Shows the invite.
        document.getElementById(this.invitationLayerName).style.visibility = 'visible';
        
        this.runtime.init(x, y);
    }   
    
    // Hides the invitation layer.
    function InvitationBuilder_hideInvitation()
    {
        document.getElementById(this.invitationLayerName).style.visibility = 'hidden';
    }
        
    // Makes blocking elements visible.
    function InvitationBuilder_showBlockingElements()
    {
        for (var i = 0; i < this.blockingElements.length; i++)
        {
            this.blockingElements[i].style.visibility = 'visible';
        }
    }
    
    // Hides blocking elements.
    function InvitationBuilder_hideBlockingElements()
    {
        for (var i = 0; i < this.blockingElements.length; i++)
        {
            this.blockingElements[i].style.visibility = 'hidden';
        }
    }
        
    // Event handler for an accept.
    function InvitationBuilder_onAccept(el)
    {
        var invitation = SiteRecruit_Globals.chosenInvitation;

        // Grab the frequency.
        var frequencyString = SiteRecruit_Config.frequency.toString();
        var weightString = invitation.weight.toString();
        
        // And the version, filtering stuff out.
        var versionString = '';
        var version = '$Name$';
        var re = /\$Name\:\s*(.*)\s*\$/;
        var matches = version.match(re);
        if (matches && matches[1])
        {
            versionString = matches[1];
        }
        else
        {
            versionString = '0';
        }

        // Grab sniffer items.
        var locationString = escape(window.location.toString());
        var referrerString = escape(document.referrer);
        
        // Grab the other cookies.
        var otherCookiesString = '';
        var otherCookies = invitation.otherCookies;
        for (var i = 0; i < otherCookies.length; i++)
        {
            var c = this.getCookieValue(otherCookies[i]);
            if (!c)
            {
                c = '';
            }
            otherCookiesString += otherCookies[i] + this.othersEqualityChar
                + escape(c) + this.othersJoinChar;
        }
        otherCookiesString = escape(otherCookiesString);
    
        // Grab the other variables.
        var otherVariablesString = '';
        var otherVariables = invitation.otherVariables;
        for (var i = 0; i < otherVariables.length; i++)
        {
            var v = this.getVariableValue(otherVariables[i]);
            if (!v)
            {
                v = '';
            }
            otherVariablesString += otherVariables[i] + this.othersEqualityChar
                + escape(v) + this.othersJoinChar;
        }
        otherVariablesString = escape(otherVariablesString);
        
        var browserWidthString = this.getPageWidth().toString();
        var browserHeightString = this.getPageHeight().toString();
        
        var values = [];

        // Pop in all of the regular params.
        values.push({'n': this.versionParamName, 'v': versionString});
        values.push({'n': this.frequencyParamName, 'v': frequencyString});
        values.push({'n': this.weightParamName, 'v': weightString});
        values.push({'n': this.locationParamName, 'v': locationString});
        values.push({'n': this.referrerParamName, 'v': referrerString});
        values.push({'n': this.otherCookiesParamName, 'v': otherCookiesString});
        values.push({'n': this.otherVariablesParamName, 'v': otherVariablesString});
        values.push({'n': this.browserWidthParamName, 'v': browserWidthString});
        values.push({'n': this.browserHeightParamName, 'v': browserHeightString});

        // Add any extra params.
        var p = invitation.acceptParams;
        if (p)
        {
            // Split by &'s.
            var pairs = p.split(/&/);
            
            for (var i = 0; i < pairs.length; i++)
            {
                // Split by ='s.
                var nv = pairs[i].split(/=/);
                
                // Pull out the name and value.
                var name = nv[0];
                var value = nv[1];
                
                if (name != '')
                {
                    values.push({'n': name, 'v': value});
                }
            }
        }

        // Stop the centering, show hidden elements, and hide the layer.
        clearInterval(this.runtime.savedIntervalId);
        setTimeout(this.hideInvitationCode, this.acceptHideTimeout);
        if (invitation.hideBlockingElements)
        {
            this.showBlockingElements();
        }
        
        var url = invitation.acceptUrl;
        
        // Set some shortcut flags to make the code below more palatable.
        var isEmail = invitation.invitationType == SiteRecruit_Constants.invitationType.email;
        var isDomainDeparture = invitation.invitationType == SiteRecruit_Constants.invitationType.domainDeparture;
        var isYahooHack = isDomainDeparture && SiteRecruit_Globals.isInternetExplorer7;
        
        // Set the appropriate URL.
        if (isDomainDeparture)
        {
            url = invitation.trackerUrl;
        }

        if (isEmail || isYahooHack)
        {
            // Create query string from values.
            url += '?';
            var len = values.length;
            for (var i = 0; i < len; i++)
            {
                url += values[i]['n'] + '=' + values[i]['v'] + '&';
            }
            
            if (isEmail)
            {
                this.submitViaImage(url);
            }
            else
            {
                // Use the window object.
                window.open(url, '', 'location=1,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=1');
            }
            
            // Suppress the submit.
            return false;
        }
        else
        {
            // Create the form.
            var body = document.getElementsByTagName('body')[0];
            var invitationForm = document.getElementById(this.invitationFormName);
            invitationForm.setAttribute('method', 'get');
            invitationForm.setAttribute('action', url);
            invitationForm.setAttribute('target', '_blank');
    
            // Fill it with the params.
            var len = values.length;
            for (var i = 0; i < len; i++)
            {
                var input = document.createElement('input');
                input.setAttribute('type', 'hidden');
                input.setAttribute('name', values[i]['n']);
                input.setAttribute('value', values[i]['v']);
                invitationForm.appendChild(input);
            }            
        }
        
        // Complete the submit.
        return true;
    }

    // Event handler for a decline.
    function InvitationBuilder_onDecline(el)
    {
        var invitation = SiteRecruit_Globals.chosenInvitation;

        // Stop the centering, show hidden elements, and hide the layer.
        clearInterval(this.runtime.savedIntervalId);
        setTimeout(this.hideInvitationCode, this.declineHideTimeout);
        
        if (invitation.hideBlockingElements)
        {
            this.showBlockingElements();
        }
    }   
    
    // Helper function to add extra accept parameters.
    function InvitationBuilder_addParam(name, value)
    {
        var invitation = SiteRecruit_Globals.chosenInvitation;
        invitation.acceptParams += '&' + name + '=' + escape(value);
    }
}

// Class to control invitation behaviour at runtime.
function SiteRecruit_InvitationRuntime()
{
    this.delay = 5;
    
    this.i = null;
    this.b = null;
    this.w = this.h = 0;
    this.lastX = this.lastY = 0;
    this.marginX = this.marginY = 0;
    this.savedIntervalId = 0;

    this.init = InvitationRuntime_init;
    this.adjust = InvitationRuntime_adjust;

    // Initializes the invitation event handlers and centering.
    function InvitationRuntime_init(x, y)
    {
        this.i = SiteRecruit_Globals.chosenInvitation;
        this.b = SiteRecruit_Globals.builder;
        this.w = this.i.invitationWidth;
        this.h = this.i.invitationHeight;

        if (this.i.autoCentering)
        {
            this.lastX = x;
            this.lastY = y;
            this.savedIntervalId = setInterval('SiteRecruit_Globals.builder.runtime.adjust()', this.delay);
        }
    }
    
    // Polled to center the invitation.
    function InvitationRuntime_adjust()
    {
        this.marginX = Math.round(this.b.getPageWidth() / 2) - Math.round(this.w / 2);
        this.marginY = Math.round(this.b.getPageHeight() / 2) - Math.round(this.h / 2);

        var t = this.delay;
        
        var x = this.lastX;
        var y = this.lastY;

        var dx = Math.abs(this.b.getPageLeftOffset() + this.marginX - x);
        var dy = Math.abs(this.b.getPageTopOffset() + this.marginY - y);
        var d = Math.sqrt(dx * dx + dy * dy);
        var c = Math.round(d / 50);
       
        if (this.b.getPageLeftOffset() + this.marginX > x) { x = x + t + c; }
        if (this.b.getPageLeftOffset() + this.marginX < x) { x = x - t - c; }
        if (this.b.getPageTopOffset() + this.marginY > y) { y = y + t + c; }
        if (this.b.getPageTopOffset() + this.marginY < y) { y = y - t - c; }
        
        // Repeat for stubborn elements.
        if (this.i.hideBlockingElements)
        {
            this.b.hideBlockingElements();
        }
        
        this.b.setInvitationPosition(x, y);

        this.lastX = x;
        this.lastY = y;       
    }
}

if (SiteRecruit_Globals.startBuilder)
{
    // Start the manager and runtime going.
    SiteRecruit_Globals.builder = new SiteRecruit_InvitationBuilder();
    SiteRecruit_Globals.builder.start();
}

// Multiple script protection.
}
