// //
// Copyright 2005 SurveySite. All rights reserved.

// Page: PageConfiguration_2695us_Page
// Date: 2006-12-18


// 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;

// Check for Internet Explorer based browsers.
if (SiteRecruit_Globals.browserName == SiteRecruit_Constants.browser.internetExplorer)
{
    if (SiteRecruit_Globals.browserVersion > 3)
    {
        SiteRecruit_Globals.isInternetExplorer = 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 = 'uspsresearch';
SiteRecruit_Config.cookieDomain = '.usps.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;
// //
// 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.getSurveyCookie = CookieUtilities_getSurveyCookie;
    this.removeSurveyCookie = CookieUtilities_removeSurveyCookie;
    this.surveyCookieExists = CookieUtilities_surveyCookieExists;

    // Set the cookie to the standard cookie string.
    function CookieUtilities_setSurveyCookie(cookieType)
    {
        var currentDate = new Date();  
        var expireDate = new Date();
        
        if (SiteRecruit_Config.cookieLifetimeType == SiteRecruit_Constants.cookieLifetimeType.duration)
        {
            expireDate.setTime(currentDate.getTime()
                + (SiteRecruit_Config.cookieDuration * 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.0013;

// Skips the cookie test. Use for debugging.
SiteRecruit_Config.useCookie = true;

// Invitation constructor. Sets defaults.
function SiteRecruit_InvitationConfiguration()
{
    this.weight = 0;
    
    this.projectId = '';    
    this.invitationType = SiteRecruit_Constants.invitationType.standard;
    
    this.acceptUrl = '';
    this.viewUrl = '';
    this.acceptParams = '';
    this.viewParams = '';

    this.invitationContent = '';

    this.invitationHeight = 0;
    this.invitationWidth = 0;
    this.revealDelay = 0;
    this.horizontalAlignment = SiteRecruit_Constants.horizontalAlignment.middle;
    this.verticalAlignment = SiteRecruit_Constants.verticalAlignment.middle;
    this.horizontalMargin = 0;
    this.verticalMargin = 0;
    this.hideBlockingElements = false;
    this.autoCentering = true;

    this.otherCookies = new Array();
    this.otherVariables = new Array();    

    this.trackerUrl = '';    
}

// 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 = '2695us';
        SiteRecruit_Config.invitations[0].invitationType = 0;
        
        SiteRecruit_Config.invitations[0].acceptUrl = 'http://survey2.surveysite.com/wix/p10208136.aspx';
        SiteRecruit_Config.invitations[0].viewUrl = 'http://web.survey-poll.com/tc/CreateLog.aspx';
        SiteRecruit_Config.invitations[0].acceptParams = 'site=01';
        SiteRecruit_Config.invitations[0].viewParams = 'log=comscore/view/p10208136-view.log&site=01';
        
        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="/survey/header01.gif" /><a href="Close" onclick="@declineHandler"><img border="0" src="/survey/close.gif" align="top" /></a><br /> <img src="/survey/header_left.gif" /><img src="/survey/header_bg.gif" /> <table width="100%" cellpadding="5"><tr><td>  <!-- Intro text. --> <p><div style="font-family: Verdana, Arial, Helvetica, sans-serif;	font-size: 11px; color: #000000;">We are conducting a survey to find out what visitors think about USPS.com. Your answers will help us serve you better. Would you like to participate?</div></p>  <!-- Invite form. --> <div align="center" style="margin-bottom: 15px"> <input type="button" value="  Yes  " onclick="@acceptHandler" />&nbsp;&nbsp; <input type="button" value=" No " onclick="@declineHandler" />  <!-- Register the view. --> <img src="@viewUrlAndParams" width="0" height="0" style="margin: 0; padding: 0;" />  </div>  <!-- Footer text. --> <div style="font-family: Verdana, Arial, Helvetica, sans-serif;	font-size: 11px; color: #000000; margin-top: 0px;">Review the <a href="http://www.usps.com/common/docs/privpol.htm/" target="_blank">Privacy Statement</a> for this survey.</div>  </td></tr></table> <img src="/survey/footer.gif" width="380" height="20" /></td></tr></table> </td></tr></table> </td></tr></table>   '; 

        SiteRecruit_Config.invitations[0].invitationHeight = 210;
        SiteRecruit_Config.invitations[0].invitationWidth = 360;
        SiteRecruit_Config.invitations[0].revealDelay = 0;
        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;
    
            
            
                
        
                
    
// //
// 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;

    // 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 = 'invitationLayer';
    
    // Substitution tags.
    this.acceptHandlerTag = '\\@acceptHandler';
    this.declineHandlerTag = '\\@declineHandler';
    this.viewUrlAndParamsTag = '\\@viewUrlAndParams';
    
    // Handler function calls.
    this.acceptHandlerCode = 'SiteRecruit_Globals.builder.onAccept(this); return false';
    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;

    // 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;

    // 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)
        {
            if (SiteRecruit_Config.useCookie)
            {
                // Mark their tracks.
                SiteRecruit_Globals.cookieUtils.setSurveyCookie(SiteRecruit_Constants.cookieType.alreadyAsked);
                
                // Bail if the cookie doesn't set properly.
                if (!SiteRecruit_Globals.cookieUtils.surveyCookieExists(SiteRecruit_Constants.cookieType.alreadyAsked))
                {
                    return;
                }
            }
          
            // Determine which survey to run.
            var invitation = this.chooseInvitation(invitations);
            
            // Store the chosen invitation in the globals.
            SiteRecruit_Globals.chosenInvitation = invitation;
            
            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)
    {
        // Replace all of the template vars.
        var ar = new RegExp(this.acceptHandlerTag, 'g');
        var dr = new RegExp(this.declineHandlerTag, 'g');
        var vr = new RegExp(this.viewUrlAndParamsTag);

        var content = invitation.invitationContent.replace(ar, this.acceptHandlerCode);
        content = content.replace(dr, this.declineHandlerCode);
        content = content.replace(vr, invitation.viewUrl + '?' + invitation.viewParams);

        // 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()
    {
        if (SiteRecruit_Globals.isInternetExplorer)
        {
            return document.body.scrollLeft;
        }
        if (SiteRecruit_Globals.isMozilla)
        {
            return window.pageXOffset;
        }
    }
    
    // Returns the top offset of the page.
    function InvitationBuilder_getPageTopOffset()
    {
        if (SiteRecruit_Globals.isInternetExplorer)
        {
            return document.body.scrollTop;
        }
        if (SiteRecruit_Globals.isMozilla)
        {
            return window.pageYOffset;
        }
    }
    
    // Returns the window width.
    function InvitationBuilder_getPageWidth()
    {
        if (SiteRecruit_Globals.isInternetExplorer)
        {
            // Note: -20 is for the scrollbar.
            return document.body.offsetWidth - 20;
        }
        if (SiteRecruit_Globals.isMozilla)
        {
            return window.innerWidth;
        }
    }
    
    // Returns the window height.
    function InvitationBuilder_getPageHeight()
    {
        if (SiteRecruit_Globals.isInternetExplorer)
        {
            return document.body.offsetHeight;
        }
        if (SiteRecruit_Globals.isMozilla)
        {
            return window.innerHeight;
        }
    }
    
    // Moves the invitation around.
    function InvitationBuilder_setInvitationPosition(x, y)
    {    
        if (SiteRecruit_Globals.isInternetExplorer)
        {
            document.all[this.invitationLayerName].style.posLeft = x;
            document.all[this.invitationLayerName].style.posTop = y;
        }
        if (SiteRecruit_Globals.isMozilla)
        {
            document.getElementById(this.invitationLayerName).style.left = x;
            document.getElementById(this.invitationLayerName).style.top = y;
        }
    }

    // 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)
        {
            this.hideBlockingElements();
        }

        // Shows the invite.
        if (SiteRecruit_Globals.isInternetExplorer)
        {
            document.all[this.invitationLayerName].style.visibility = 'visible';
        }
        else if (SiteRecruit_Globals.isMozilla)
        {
            document.getElementById(this.invitationLayerName).style.visibility = 'visible';
        }
        
        this.runtime.init(x, y);
    }   
    
    // Hides the invitation layer.
    function InvitationBuilder_hideInvitation()
    {
        if (SiteRecruit_Globals.isInternetExplorer)
        {
            document.all[this.invitationLayerName].style.visibility = 'hidden';
        }
        if (SiteRecruit_Globals.isMozilla)
        {
            document.getElementById(this.invitationLayerName).style.visibility = 'hidden';
        }
    }
    
    // Makes blocking elements visible.
    function InvitationBuilder_showBlockingElements()
    {
        var objectElements = document.getElementsByTagName('OBJECT');
        for (var i = 0; i < objectElements.length; i++)
        {
            var el = objectElements.item(i);
            el.style.visibility = 'visible';
        }
        var selectElements = document.getElementsByTagName('SELECT');
        for (var i = 0; i < selectElements.length; i++)
        {
            var el = selectElements.item(i);
            el.style.visibility = 'visible';
        }
    }
    
    // Hides blocking elements.
    function InvitationBuilder_hideBlockingElements()
    {
        var objectElements = document.getElementsByTagName('OBJECT');
        for (var i = 0; i < objectElements.length; i++)
        {
            var el = objectElements.item(i);
            el.style.visibility = 'hidden';
        }
        var selectElements = document.getElementsByTagName('SELECT');
        for (var i = 0; i < selectElements.length; i++)
        {
            var el = selectElements.item(i);
            el.style.visibility = 'hidden';
        }
    }
        
    // Event handler for an accept.
    function InvitationBuilder_onAccept(el)
    {
        var invitation = SiteRecruit_Globals.chosenInvitation;

        // Build the URL.
        var a = '&';
        var e = '=';
        var q = '?';
        var u = '';
        
        // Decide whether to use the tracker or the accept URL.
        if (invitation.invitationType == SiteRecruit_Constants.invitationType.domainDeparture)
        {
            u = invitation.trackerUrl;
        }
        else
        {
            u = invitation.acceptUrl;
        }

        // 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: release-2-3-1 $';
        var re = /\$Name\:\s*(.*)\s*\$/;
        var matches = version.match(re);
        if (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();
        
        // Pop in all of the regular params.
        u += q + this.versionParamName + e + versionString;
        u += a + this.frequencyParamName + e + frequencyString;
        u += a + this.weightParamName + e + weightString;
        u += a + this.locationParamName + e + locationString;
        u += a + this.referrerParamName + e + referrerString;
        u += a + this.otherCookiesParamName+ e + otherCookiesString;
        u += a + this.otherVariablesParamName + e + otherVariablesString;
        u += a + this.browserWidthParamName + e + browserWidthString;
        u += a + this.browserHeightParamName + e + browserHeightString;

        // Write out 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 != '')
                {
                    u += a + name + e + 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();
        }
        
        // Open the survey window.
        window.open(u);
    }

    // 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();
        }
    }   
}

// 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;
    this.resize = InvitationRuntime_resize;

    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.resize();
            window.onresize = new Function('SiteRecruit_Globals.builder.runtime.resize()');
            this.savedIntervalId = setInterval('SiteRecruit_Globals.builder.runtime.adjust()', this.delay);
        }
    }
    
    function InvitationRuntime_adjust()
    {
        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; }
 
        this.b.setInvitationPosition(x, y);

        this.lastX = x;
        this.lastY = y;       
    }
    
    function InvitationRuntime_resize()
    {
        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);
    }    
}

if (SiteRecruit_Globals.startBuilder)
{
    // Start the manager and runtime going.
    SiteRecruit_Globals.builder = new SiteRecruit_InvitationBuilder();
    SiteRecruit_Globals.builder.start();
}

// Multiple script protection.
}
