// //
// Copyright 2008 Premier Collection Ltd. All rights reserved.

// Name: PremierCollection-www
// Date: 2008-11-01


// 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';
SiteRecruit_Constants.browser.opera = 'Opera';

// 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;
    }
}

// Since Opera 9.02, they no longer use 'Mozilla' in the browser name
if (SiteRecruit_Globals.browserName == SiteRecruit_Constants.browser.opera)
{
	SiteRecruit_Globals.isMozilla = true;	// treat the same as Mozilla
}



// 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;
SiteRecruit_Constants.invitationType.emailDomainDeparture = 3;
    
// Cookie type flags.
SiteRecruit_Constants.cookieType = new Object();
SiteRecruit_Constants.cookieType.alreadyAsked = 1;
SiteRecruit_Constants.cookieType.inProgress = 2;
SiteRecruit_Constants.cookieType.emailDomainDeparture = 3;

// 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 = 'research';
SiteRecruit_Config.cookieDomain = '.premiercollection.eu';
SiteRecruit_Config.cookiePath = '/';

SiteRecruit_Constants.cookieJoinChar = ':';

// Settings for cookie lifetime.
SiteRecruit_Config.cookieLifetimeType = 1;

    // Duration of the cookie in days.
    SiteRecruit_Config.cookieDuration = 90 * 86400000;

// Duration of the rapid cookie.
SiteRecruit_Config.rapidCookieDuration = 0 * 86400000;

// URL of the email domain dep server.
SiteRecruit_Config.listenerUrl = '';// //
// Copyright 2008 Premier Collection Ltd. All rights reserved.

// KeepAlive class definition.
function SiteRecruit_KeepAlive()
{
    // Time between page checks.
    this.keepAlivePollDelay = 1000;

    // Unique (well, sorta) ID for this page.
    this.id = Math.random();

    // Attach methods.
    this.attemptStart = KeepAlive_attemptStart;
    this.checkCookie = KeepAlive_checkCookie;
    this.inProgressCookieExists = KeepAlive_inProgressCookieExists;
    this.cookieExists = KeepAlive_cookieExists;

    // Check for either domain dep or email domain dep cookies and act accordingly.
    function KeepAlive_attemptStart()
    {
        if (this.inProgressCookieExists())
        {
            setInterval('SiteRecruit_Globals.keepAlive.checkCookie()', this.keepAlivePollDelay);
        }
        else
        {
            if (this.cookieExists(SiteRecruit_Constants.cookieType.emailDomainDeparture))
            {
                var c = document.cookie.toString();
                var index = c.indexOf(SiteRecruit_Config.cookieName + '=' + SiteRecruit_Constants.cookieType.emailDomainDeparture);
                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);
                var values = c.split(':');
                if (values.length == 2)
                {
                    var url = SiteRecruit_Config.listenerUrl;
                    
                    // append ? to qs if needed
					url += (url.indexOf('?') == -1 ? '?' : '&');
					
                    url += 'action=log'
                        + '&user=' + values[1]
                        + '&location=' + escape(window.location);
                    
                    setTimeout("var i = new Image(); i.src = '" + url + "&' + (new Date()).getTime(); ", 5);
                }
            }
        }
    }
    
    // Check and update the cookie.
    function KeepAlive_checkCookie()
    {
        if (this.inProgressCookieExists())
        {
            var c = SiteRecruit_Config.cookieName + '=' + SiteRecruit_Constants.cookieType.inProgress
                + ':' + escape(document.location)
                + ':' + (new Date()).getTime()
                + ':' + this.id
                + '; path=' + SiteRecruit_Config.cookiePath;
            
            if (SiteRecruit_Config.cookieDomain != '')
            {
                c += '; domain=' + SiteRecruit_Config.cookieDomain;
            }
            
            document.cookie = c;
        }
    }

    // Return true if an in-progress cookie exists.
    function KeepAlive_inProgressCookieExists()
    {
        return this.cookieExists(SiteRecruit_Constants.cookieType.inProgress);
    }
    
    // Return true if a cookie of the given type exists.
    function KeepAlive_cookieExists(cookieType)
    {
        var c = SiteRecruit_Config.cookieName + '=' + cookieType;
        if (document.cookie.indexOf(c) != -1)
        {
            return true;
        }
        return false;
    }
}

// Create the KeepAlive if a suitable cookie exists.
SiteRecruit_Globals.keepAlive = new SiteRecruit_KeepAlive();
SiteRecruit_Globals.keepAlive.attemptStart();
// //
// Copyright 2008 Premier Collection Ltd. All rights reserved.

// Multiple script protection.
}
