// WebTrends SmartSource Data Collector Tag
// Version: 1.1.1
// Created: 3/27/2008 6:09:34 AM

// <%-- $Id: wtinit.js,v 1.12 2008/04/24 14:16:49 powem Exp $ --%>

/*
 * configured for MerckVaccines.com development environment
 * reset this.domain for production SDC server when ready
 *
 * Last File update $Date: 2008/04/24 14:16:49 $
 * 
 * Updated to autoconfigure based on location (IT, UAT, Prod)
 * Automatically configures SDC domain, FPC domain, onsite domains and split
 * value, based on the hostname of the page, for these domains:
 * * localhost
 * * merckvaccines-it.merck.com / merckvaccines2-it.merck.com == IT
 * * merckvaccines-ut.merck.com / merckvaccines2-ut.merck.com == UAT
 * * merckvaccines.com == PROD
 *
 */

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getReferrerCookie(cookieName){
    var nameEQ = cookieName + "=";
    var value = null;
    var cookieArray = document.cookie.split(';');
    for(var i=0;i < cookieArray.length; i++) {
        var crumb = cookieArray[i];
        while (crumb.charAt(0)==' ') 
            crumb = crumb.substring(1,crumb.length);
        if (crumb.indexOf(nameEQ) == 0){ 
            value = crumb.substring(nameEQ.length,crumb.length);
            break;
        }
    }
    return value;
} // end getReferrerCookie

if (!runonce) { //runonce is a global var set to make sure that multiple istances of referrer cookie initialization don't overwrite each other

	var topref = top.document.referrer;

	if (!topref)
           topref = document.referrer;

	if (topref) {
	    if (!getReferrerCookie("wtReferringURL")) {
		createCookie("wtReferringURL", topref, 0);
//	alert("Referrer cookie (set once by wtinit.js) = "+topref);
	    }
	    else
//	alert("wtinit.js detected a cookie, foregoing");
       var runonce = 1;
       }
}


function DcsInit(){
    var that=this;
    this.dcsid="dcsnts29e00000oiidx4xg1ax_8k2p";
    this.domain=sdcServer; // defined according to location, below
    this.enabled=true;
    this.exre=(function(){return(window.RegExp?new RegExp("dcs(uri)|(ref)|(aut)|(met)|(sta)|(sip)|(pro)|(byt)|(dat)|(p3p)|(cfg)|(redirect)|(cip)","i"):"");})();
    this.fpc="WT_FPC";
    this.fpcdom=fpcDomain; // defined according to location, below
    this.i18n=false;
    this.images=[];
    this.index=0;
    this.qp=[];
    this.re=(function(){return(window.RegExp?(that.i18n?{"%25":/\%/g}:{"%09":/\t/g,"%20":/ /g,"%23":/\#/g,"%26":/\&/g,"%2B":/\+/g,"%3F":/\?/g,"%5C":/\\/g,"%22":/\"/g,"%7F":/\x7F/g,"%A0":/\xA0/g}):"");})();
    this.onsitedoms=onSiteDomains; // defined according to location, below
    this.adclickparam="WT.ac";
    this.downloadtypes="xls,doc,pdf,txt,csv,zip";
    this.rightclicktypes="xls,doc,pdf,txt,csv,zip";
    this.split=splitValue; // defined according to location, below
    this.timezone=-5;
    this.trackevents=true;
    (function(){if(that.enabled&&(document.cookie.indexOf(that.fpc+"=")==-1)&&(document.cookie.indexOf("WTLOPTOUT=")==-1)){document.write("<scr"+"ipt type='text/javascript' src='"+"http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+that.domain+"/"+that.dcsid+"/wtid.js"+"'><\/scr"+"ipt>");}})();
    
}


/*
* MerckVaccines.com-specific code added by M. Powe, Technology Leaders
* Last file update $Date: 2008/08/21 01:00:00 by P. Arnaudov, Technology Leaders
*/

// setting code execution location:  IT, UAT, Production

var host = window.location.hostname;
var sdcServer = "www.mercksdc.com";
var fpcDomain = ".merckvaccines.com";
var onSiteDomains = "merckvaccines.com";
var splitValue = "";




function getLocation(host){
    
    var loc = "localhost";
    var IT = { hostMatch : "merckvaccines-it", name : "IT" };
    var UAT = {hostMatch : "merckvaccines-ut", name : "UAT"};
    var DEV1 = {hostMatch : "local.merckvaccines.com", name : "DEV1"};
    var DEV2 = {hostMatch : "merckvaccines.merck.com", name : "DEV2"}; 
    var PROD = {hostMatch : "merckvaccines.com", name : "PROD"};
    
    if (host.search(IT.hostMatch) != -1)
        loc = IT.name;
    else if (host.search(UAT.hostMatch) != -1)
        loc = UAT.name;
    else if (host.search(DEV1.hostMatch) != -1)
        loc = DEV1.name;
    else if (host.search(DEV2.hostMatch) != -1)
        loc = DEV2.name;
    else if (host.search(PROD.hostMatch) != -1)
        loc = PROD.name;

    return loc;
}


function setSdcParameters(){

    switch(getLocation(host)){
        
        case "IT" :
            sdcServer = "sdc-test.merck.com";
            fpcDomain = ""; // sets cookie to current subdomain.domain only
            onSiteDomains="merckvaccines-it.merck.com,merckvaccines2-it.merck.com";
            splitValue = "merckvaccines-it.merck.com";
        break;
        
        case "UAT" :
            sdcServer = "sdc-test.merck.com";
            fpcDomain = ""; // sets cookie to current subdomain.domain only
            onSiteDomains = "merckvaccines-ut.merck.com,merckvaccines2-ut.merck.com";
            splitValue = "merckvaccines-ut.merck.com";
        break;

        case "DEV1" :
            sdcServer = "sdc-test.merck.com";
            fpcDomain = ""; // sets cookie to current subdomain.domain only
            onSiteDomains = "local.merckvaccines.com";
            splitValue = "local.merckvaccines.com";
        break;

        case "DEV2" :
            sdcServer = "sdc-test.merck.com";
            fpcDomain = ""; // sets cookie to current subdomain.domain only
            onSiteDomains = "merckvaccines.merck.com";
            splitValue = "merckvaccines.merck.com";
        break;

        
        case "PROD" :
            sdcServer = "www.mercksdc.com";  // v8 server
            fpcDomain = ".merckvaccines.com";  // sets cookie to all subdomains
            onSiteDomains="merckvaccines.com";
            splitValue = "www.merckvaccines.com";
        break;
        
        default:
            sdcServer = "sdc-test.merck.com";
            fpcDomain = ""; // sets cookie to current domain only
            onSiteDomains = "localhost";
            splitValue = "localhost";
        break;
    }

} // end setSdcServer

function setCookieLocation(loc){

    var site = "";
    
    switch(loc){
        
        case "merckvaccines-it.merck.com" :
            site = "merckvaccines-it";
        break;
        
        case "merckvaccines.com" :
            site = "merckvaccines.com";
        break;
        
        case "merckvaccines-ut.merck.com" :
            site = "merckvaccines-ut";
        break;
        
        case "merckvaccines2-it.merck.com" :
            site = "merckvaccines2-it";
        break;
        
        case "merckvaccines2-ut.merck.com" :
            site = "merckvaccines2-ut.merck.com";
        break;
        
        default:
            site = "MerckVaccines";
        break;
        
    } // end switch
    return site;
} // end setCookieLocation


// ============================================================================
//                      cookie code for handling referrers
// ============================================================================
function setReferrerCookie(name){
    var expiry = '; expires=""';
    var value = null;
    var path = "; path=/";
    var site = setCookieLocation(host);

            if (top.document.referrer.indexOf(site) == -1){
                value = ("int:"+top.document.referrer);
            } else {
            	  value = ("ext:"+top.document.referrer);
            }

    document.cookie = name+"="+value+expiry+path;
} // end setReferrerCookie



function setDcsReferrer(){

    var dcsref = null;
    var docurl = location.href;
    var site = setCookieLocation(host);

		if (top.document.referrer) {

		if (top.document.referrer == docurl) // catches bookmarks (referrer is self) in theory unless there are page forwards

		  createCookie("wtReferringURL", top.document.referrer, 0);

			if (top.document.referrer.indexOf(site) == 1) {
		  		DCS.dcsref = "";
			}
			else 
		          DCS.dcsref = top.document.referrer;
		}

		else  {  
			dcsref = getReferrerCookie("wtReferringURL");
 

			if (!dcsref) {
			}

			else if (dcsref == docurl) { // catches bookmarks (referrer is self) unless there are page forwards
			DCS.dcsref = "";
			}

			else { //cookie value is used so no need to update cookie
			DCS.dcsref = dcsref;
			}

		} // end of read from cookie


} // end setDcsReferrer

/*
 * ============================================================================
 * Begin function calls for SDC code initialization
 * ============================================================================
 */
 
 // order is important! -- MP
 

var DCS={};
var WT={};
var DCSext={};

setDcsReferrer();
setSdcParameters();

var dcsInit=new DcsInit();

                