/* ============================== sophus3 ==============================
logging script for                                                               22/03/2011
   
Mazda Corporate websites
   
Version 5.4.1
Copyright (c) Sophus Ltd 2011. All rights reserved. Patent Pending.
http://www.sophus3.com
=====================================================================*/

/*=============================== Switch ==============================*/
if (typeof s3_logging_active == 'undefined') s3_logging_active = true;
// If you want to switch off the tracking use the following line instead:
// s3_logging_active = false;
/*=====================================================================*/

/* =========================== Customisation ===========================*/
// required configuration parameters

s3_site_id = s3_get_site_id();
s3_server_url = "auto.sophus3.com";

// custom functions for Mazda Portal sites
function s3_get_site_id() {
    var completedomain = document.location.hostname;
    domain = completedomain.toLowerCase();
    domain = domain.substring(domain.lastIndexOf(".") + 1);
    if (domain.toLowerCase() == "at") s3_site_id = 391;
    else if (domain.toLowerCase() == "ch") s3_site_id = 392;
    else if (domain.toLowerCase() == "de") s3_site_id = 257;
    else if (domain.toLowerCase() == "dk") s3_site_id = 393;
    else if (domain.toLowerCase() == "com") {
        if (completedomain == "www.mazda-tr.com") s3_site_id = 610;
        else if (completedomain == "mazda-tr.com") s3_site_id = 610;
        else if (completedomain == "www.mazda-es.com") s3_site_id = 258;
        else if (completedomain == "mazda-es.com") s3_site_id = 258;
        else s3_site_id = 472
    }
    else if (domain.toLowerCase() == "fr") s3_site_id = 259;
    else if (domain.toLowerCase() == "it") s3_site_id = 260;
    else if (domain.toLowerCase() == "no") s3_site_id = 394;
    else if (domain.toLowerCase() == "pt") s3_site_id = 390;
    else if (domain.toLowerCase() == "ru") s3_site_id = 396;
    else if (domain.toLowerCase() == "se") s3_site_id = 395;
    else if (domain.toLowerCase() == "uk") s3_site_id = 256;
    else if (domain.toLowerCase() == "cz") s3_site_id = 436;
    else if (domain.toLowerCase() == "sk") s3_site_id = 437;
    else if (domain.toLowerCase() == "be") s3_site_id = 438;
    else if (domain.toLowerCase() == "hr") s3_site_id = 453;
    else if (domain.toLowerCase() == "ua") s3_site_id = 452;
    else if (domain.toLowerCase() == "nl") s3_site_id = 451;
    else if (domain.toLowerCase() == "hu") s3_site_id = 450;
    else if (domain.toLowerCase() == "gr") s3_site_id = 449;
    else if (domain.toLowerCase() == "fi") s3_site_id = 448;
    else if (domain.toLowerCase() == "lu") s3_site_id = 447;
    else if (domain.toLowerCase() == "ie") s3_site_id = 446;
    else if (domain.toLowerCase() == "ro") s3_site_id = 489;
    else if (domain.toLowerCase() == "fi") s3_site_id = 448;
    else if (domain.toLowerCase() == "ee") s3_site_id = 486;
    else if (domain.toLowerCase() == "lv") s3_site_id = 487;
    else if (domain.toLowerCase() == "lt") s3_site_id = 485;
    else if (domain.toLowerCase() == "si") s3_site_id = 480;
    else if (domain.toLowerCase() == "tr") s3_site_id = 610;
    else if (domain.toLowerCase() == "pl") s3_site_id = 612;
    else if (domain.toLowerCase() == "es") s3_site_id = 258;
    else s3_site_id = 472;  // Mazda All Countries
    return s3_site_id;
}


create_netmining_tag(s3_site_id);

function create_netmining_tag(site) {
    // remove siteids for the countries
    // on which the Netmining tag should not yet be activated
    var nm_sites = new Array(391, 392, 436, 446, 451, 437, 257); //AT, CH, CZ, IE, NL, SK and DE 

    var nm_tag = false;
    for (var i = 0; i < nm_sites.length; i++)
        if (nm_sites[i] == site) nm_tag = true;

    if (nm_tag) {
        var nm_url = document.location.protocol + "//mazda.netmining.com/";
        document.write("<scr" + "ipt language='JavaScript' type='text/javascript' src='" + nm_url + "'></scr" + "ipt>\n");
    }
}

/*=====================================================================*/

/* ============================= Parameter =============================*/
/*        PLEASE ASK sophus3 TO CUSTOMISE THE CODE BELOW !          */
// attaches querystring parameters to the page alias

// If you want to to use a limited list of parameters, activate the array below
/*var usePair = new Array();
usePair['campaignid'] = 1;
usePair['advertiserid'] = 1;
usePair['bannerid'] = 1;
*/

if (typeof tc_page_alias != 'undefined') { //Compatibility with old version tagging
    s3_page_alias = tc_page_alias;
}

if (typeof s3_page_alias != 'undefined') {
    if (location.search != null && location.search.length > 1) {

        if (typeof usePair == 'undefined') { // append entire query string
            if (s3_page_alias.indexOf('?') == -1) {
                s3_page_alias = s3_page_alias + location.search;
            }
            else {
                s3_page_alias = s3_page_alias + "&" + location.search.substring(1);
            }
        }

        else { // append selected parameters
            var locSearch = location.search.substring(1);
            var s3Params = locSearch.split('&');
            var s3_params = '';
            var nextAppender = (s3_page_alias.indexOf('?') == -1) ? '?' : '&';

            for (var i = 0; i < s3Params.length; i++) {
                if (s3Params[i].indexOf('=') != -1) {
                    var pair = s3Params[i].split('=');
                    if (usePair[pair[0]] == 1) {
                        s3_params += nextAppender + s3Params[i];
                        nextAppender = '&'; // Change from ? to &
                    }
                }
            }
            s3_page_alias += s3_params;
        }
    }
}
/*=====================================================================*/

/*=========================== StandardCode ============================*/
/*             DO NOT MAKE CHANGES TO THE CODE BELOW !                */

var s3LogType = "s3def"; //default logtype

function s3_configured() {
    s3_tag_version = "5.4.1"; // no Plugin detection, see 521 comments
    s3_dtimeout = 5000;
    s3_d_loc = window.location;
    s3_sent = 0;
    if (typeof s3_server_url == 'undefined' || typeof s3_site_id == 'undefined') return false;
    s3_timeout = (typeof s3_timeout == 'undefined' ? s3_dtimeout : s3_timeout * 1000);
    s3_encfn = (typeof encodeURIComponent != 'undefined' ? encodeURIComponent : escape);
    s3_http = "http" + (s3_d_loc.href.substring(0, 6) == "https:" ? "s" : "") + "://";
    s3_server_url = s3_http + s3_server_url;
    s3_url = ((typeof s3_page_alias != 'undefined') ? s3_page_alias : s3_d_loc.href);
    s3_referrer = (typeof s3_referrer != 'undefined' && s3_referrer != "" && s3_referrer != null ? s3_referrer : (typeof document.referrer == 'undefined' ? s3_ud : (document.referrer == null ? "null" : (document.referrer == "" ? "empty" : document.referrer))));
    s3_time = new Date().getTime();
    return true;
}

function s3_log(alias, displayed) {
    s3LogType = "s3log";

    if (!s3_logging_active) return;
    alias = s3_fixURL(alias);
    s3_image = new Image();
    s3_image.src = s3_get_log_URL_s3log("i", alias, new Date().getTime(), displayed);
}
function tc_log(alias, displayed) {
    s3_log(alias, displayed);
}


function s3_dltime() {
    s3LogType = "s3dlt";

    if (!(document.getElementById || document.all)) return false;
    if (s3_logging_active && (typeof s3_done != "undefined") && s3_done && !s3_sent) { setTimeout("s3_dltime()", 1000); return false; }
    var sent = s3_sent;
    s3_image = new Image();
    s3_image.name = "s3d";
    s3_image.src = s3_get_log_URL("d");
    return sent;
}
function tc_dltime() {
    s3_dltime();
}

function s3_get_log_URL(type, locn, time, displayed) {
    if (typeof type == 'undefined') type = 'i';
    var url = s3_server_url + "/" + type + "?siteID=" + s3_site_id;
    if (type != "d") {
        url += "&ts=" + (typeof time != 'undefined' ? time : s3_time);
        var al = s3_isAlias(locn);
        if (typeof s3_containers != 'undefined') for (cc in s3_containers) url += "&ccID=" + s3_containers[cc];
        if (type == "c") url += "&log=no";
        if (al) url += "&alias=true";
        if (typeof displayed != 'undefined') url += displayed;
        if (locn == 'undefined') locn = s3_d_loc;
        locn = s3_encfn(locn);
        while (locn.length > 1999 - url.length) locn = locn.substring(0, locn.lastIndexOf(s3_encfn("&")));
        url += "&location=" + locn;
        var dg = new Object();
        dg.tagv = s3_tag_version;
        dg.tz = 0 - (new Date().getTimezoneOffset());
        dg.r = s3_encfn(s3_referrer);
        if (al) dg.aliased = s3_encfn(s3_d_loc.href);
        dg.title = s3_encfn(document.title);
        if (s3LogType == "s3def") {//Plug-in detection only for default tagging
            dg.flv = s3_getFlashVersion();
            var plg = s3_getPlugInz();
            dg.Rep = plg.Rep;
            dg.Qut = plg.Qut;
            dg.WMP = plg.WMP;
            dg.ARe = plg.ARe;
            dg.Jav = plg.Jav;
            dg.SiL = plg.SiL;
        }
        if (screen) { dg.cd = screen.colorDepth; dg.ah = screen.availHeight; dg.aw = screen.availWidth; dg.sh = screen.height; dg.sw = screen.width; dg.pd = screen.pixelDepth; }
        for (var key in dg) { var param = "&" + key + "=" + dg[key]; if (url.length + param.length < 2000) url += param; else break; }
    } else {
        url += "&dlts=" + s3_time + "&dl=" + (new Date().getTime() - s3_time);

    }
    return url;
}

function s3_get_log_URL_s3log(type, locn, time, displayed) {
    return s3_get_log_URL(type, locn, time, displayed) + "&s3log=1";
}

function s3_get_log_URL_s3red(type, locn, time, displayed) {
    return s3_get_log_URL(type, locn, time, displayed) + "&s3red=1";
}


function s3_redirect(target, url, alias, winproperties, products, script) {
    s3LogType = "s3red";
    if (typeof url == s3_ud || url == "") return;
    if (typeof script == s3_ud || script == "") script = "s3_d_loc.href='" + url + "'";
    url = s3_fixURL(url);
    if (typeof alias == s3_ud) alias = url;
    alias = s3_fixURL(alias);
    if (typeof target == s3_ud || target == "" || target == "_self") {
        if (s3_logging_active) {
            s3_timer = new Image();
            s3_timer.onload = function() { eval(script); clearTimeout(s3_timeout_id); }
            s3_timer.onerror = function() { eval(script); clearTimeout(s3_timeout_id); }
            s3_timer.src = s3_get_log_URL_s3red("i", alias, new Date().getTime());
            s3_timeout_id = setTimeout(script, s3_timeout);
        } else { eval(script); }
    }
    else if (typeof target == "object" && target.document) {

        if (s3_logging_active) { s3_timer = new Image(); s3_timer.src = s3_get_log_URL_s3red("i", alias); }
        target.location.href = url;
    }
    else { s3_open_window(target, url, alias, winproperties, products); }
}

function tc_redirect(target, url, alias, winproperties, products, script) {
    s3_redirect(target, url, alias, winproperties, products, script);
}

function s3_open_window(name, url, alias, winproperties, products) {
    if (typeof url == s3_ud || url == "") return false;
    if (s3_logging_active) {
        s3_timer = new Image();
        s3_timer.src = s3_get_log_URL("i", alias, new Date().getTime());
    }
    if (typeof winproperties == s3_ud) return window.open(url, name);
    else { return window.open(url, name, winproperties) }
}

function s3_getFlashVersion() {
    /*521

	var s3_flashversion = -1;
    // ie 
    try { 
    try { 
    // avoid fp6 minor version lookup issues 
    // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ 
    var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
    try { 
    axo.AllowScriptAccess = 'always';
    } 
    catch(e) { 
    return '6,0,0'; 
    } 
    } catch(e) {} 
    s3_flashversion = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
		
		// other browsers 
    }
    catch(e) { 
    try { 
    if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
    s3_flashversion = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
    } 
    } catch(e) {} 
    } 
	
	if(s3_flashversion == -1){
    return s3_flashversion; 
    }
    else{
    return s3_flashversion.split(',').shift(); 
    }
    521*/

    return "no detection";
}


function s3_fixURL(url) {
    if (url == "") { return s3_d_loc.href }
    if ((url.substring(0, 4) != 'http') && (url.substring(0, 1) != "/")) { url = s3_d_loc.pathname.substring(0, s3_d_loc.pathname.lastIndexOf('/') + 1) + url }
    if (url.substring(0, 1) == "/") { url = s3_http + s3_d_loc.host + url }
    var s3anchor = window.location.hash;
    if (s3anchor.length > 0) {
    	url = url.replace(s3anchor, '');
        if (url.indexOf("?") == -1) url = url + "?";
        else url = url + "&";
        url = url + "s3anchor=" + s3anchor.substring(1) + s3anchor;
    }
    return url;
}


function s3_isAlias(alias) {
    alias = (typeof alias != 'undefined' ? alias : (typeof s3_page_alias == 'undefined' ? "" : s3_page_alias));
    alias = s3_fixURL(alias);
    if (alias.indexOf("?") > 0) alias = alias.substring(0, alias.indexOf("?"));
    return (alias != s3_http + s3_d_loc.host + s3_d_loc.pathname);
}


function s3_loader() {
    s3_ud = "undefined";
    if (s3_logging_active && s3_configured() && (typeof s3_done == 'undefined' || s3_done == false)) {
        url = s3_fixURL(s3_url);
        s3_image = new Image();
        s3_image.name = "s3i";
        s3_image.onload = function() { s3_sent = true; }
        s3_image.src = s3_get_log_URL("i", url, s3_time);
    }
    s3_done = true;
}

function s3_getPlugInz() {

    var PlugIn = new Object();

    s3_ReP = "no detection";
    s3_QuT = "no detection";
    s3_WMP = "no detection";
    s3_Are = "no detection";
    s3_Jav = "no detection";
    s3_SiL = "no detection";
    /*521
    try{
    s3_nse = "";
    for (var i=0;i<navigator.mimeTypes.length;i++) s3_nse += navigator.mimeTypes[i].type.toLowerCase();
    if (s3_nse != "") {
    s3_ReP = s3_detectNS("audio/x-pn-realaudio-plugin");
    s3_QuT = s3_detectNS("video/quicktime");
    s3_WMP = s3_detectNS("application/x-mplayer2");
    s3_Are = s3_detectNS("application/pdf");
    s3_Jav = s3_detectNS("application/x-java-applet");
    s3_SiL = s3_detectNS("application/x-silverlight");
    }
    else {

		if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');
    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');
    document.writeln('\'this next function will detect most plugins');

			document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');
    document.writeln('\'and the following function handles QuickTime');

			document.writeln('Function detectQuickTimeActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject(activeXControlName)');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');
    document.writeln('</scr' + 'ipt>');

			s3_ReP = detectActiveXControl("rmocx.RealPlayer G2 Control");
    s3_QuT = detectQuickTimeActiveXControl("QuickTimeCheckObject.QuickTimeCheck");
    s3_WMP = detectActiveXControl("MediaPlayer.MediaPlayer");
    s3_Are = detectActiveXControl("PDF.PdfCtrl");

			if (s3_Are==false) s3_Are = detectActiveXControl("AcroPDF.PDF");
    s3_Jav = detectActiveXControl("JavaWebStart.isInstalled");
    s3_SiL = detectActiveXControl("AgControl.AgControl");
    }
    }
    }

	catch (e) {
    s3_ReP = "error1";
    s3_QuT = "error1";
    s3_WMP = "error1";
    s3_Are = "error1";
    s3_Jav = "error1";
    s3_SiL = "error1";
    }

	PlugIn.Rep=s3_ReP;
    PlugIn.Qut=s3_QuT;
    PlugIn.WMP=s3_WMP;
    PlugIn.ARe=s3_Are;
    PlugIn.Jav=s3_Jav;
    PlugIn.SiL=s3_SiL;
	
	521*/

    return PlugIn;
}

function s3_detectNS(s3_ClassID) {
    try {
        if (s3_nse.indexOf(s3_ClassID) != -1) {
            if (navigator.mimeTypes[s3_ClassID].enabledPlugin != null) return true;
        }
        else return false
    }
    catch (e) {
        return "error2"
    }
}

s3_loader();
