/* Sophus3 logging request. http://www.sophus3.com
 * Site identifier code for Fiat UK
 * Copyright (c) Sophus Ltd All rights reserved. Patent Pending.
 *
 * Change the value of tc_logging_active to switch off logging on the site.
 * HitsIntoLeads extended Version
 * Issued on 04/07/2007
 */

tc_logging_active = true;
/* Custom Code by AKQA - to process the JustLoggedIn and LoginFailed cookies that are used to signify that a user has well, just logged in (or there's been an error)! */
var jloCookieName = 'JustLoggedIn';
var loginFailedCookieName = 'LogInFailed';

// The cookie functions used below are in /library/main.js

function ProcessLoginTrackingCookie()
{
    if (readCookie(jloCookieName) != null)
    {
        tc_log('/user_account/login/login_success.htm');
        eraseCookie(jloCookieName);
    }
    if (readCookie(loginFailedCookieName) != null)
    {
        tc_log('/user_account/login/login_failure.htm');
        eraseCookie(loginFailedCookieName);
    }
}
/* END */

/* Custom Code by AKQA - to append the 'usePair' parameters only to the tc_page_alias if found */
var usePair = new Array();
usePair['campaignid'] = 1;
usePair['advertiserid'] = 1;
usePair['bannerid'] = 1;
usePair['s3c_channel'] = 1;
usePair['s3c_model'] = 1;
usePair['s3c_event'] = 1;
usePair['s3c_type'] = 1;
usePair['s3c_period'] = 1;
usePair['s3c_targeting'] = 1;
usePair['s3c_payment'] = 1;
usePair['s3c_brand'] = 1;
usePair['s3c_competitor'] = 1;

if (location.search != null && location.search.length > 1) {
    var locSearch = location.search.substring(1);
    var fiatTcParams = locSearch.split('&');
    var fiat_tc_params = '';
    var nextAppender = (tc_page_alias.indexOf('?') == -1) ? '?' : '&';
    for (var i=0; i<fiatTcParams.length; i++) {
        if (fiatTcParams[i].indexOf('=') != -1) {
            var pair = fiatTcParams[i].split('=');
            if (usePair[pair[0]] == 1) {
                fiat_tc_params += nextAppender + fiatTcParams[i];
                nextAppender = '&'; // Change from ? to &
            }
        }
    }
    tc_page_alias += fiat_tc_params;
}
/* END */

// required configuration parameters
if (tc_logging_active) {
	tc_site_id = 75;
	tc_server_url = "fiat.touchclarity.com";
	tc_log_page = "/touchclarity";
	document.write("<scr"+"ipt src='/touchclarity/logging-code.js'></scr"+"ipt>\n");
	//the following call is no longer used by fiat uk
	//document.write("<scr"+"ipt language='JavaScript' type='text/javascript' defer='defer' src='" + window.location.protocol + "//uk.fiat.netmining.com/'></scr"+"ipt>\n");
}

