var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function storeQueryString() {
    var querystring = new Array;
    var q = String(document.location).split('?')[1];
    if (!q) return false;
    q = q.split('&');
    for (var i = 0; i < q.length; i++) {
        var o = q[i].split('=');
        querystring[o[0]] = o[1];
    }
    return querystring;
}

function noPercent(x)
{
	x = unescape(x);
	return x.replace(/\+/g," ").replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function sleuth()
{
		var sleuthTracker = _gat._getTracker('UA-1');
		pageTracker._setAllowHash(false);
		pageTracker._setAllowLinker(true);
	if(document.location.search.indexOf("gclid")!=-1||document.location.search.indexOf("cpc")!=-1) {
		ref = document.referrer;
		re = /(\?|&)(q|p|query|encquery|qt|terms|rdata|qs|wd|text|szukaj|k|searchExpr|search_for|string|search_query|searchfor)=([^&]+)/;
		searchq = re.exec(ref);
		if(searchq) {
			searchq[3] = noPercent(searchq[3]);
			sleuthTracker._setVar(searchq[3]);
		}
		else {
			sleuthTracker._setVar('Referral: ' + document.referrer);
		}
	}
}

function SuperCookie() {
    this.source = " ";
    this.medium = " ";
    this.campaign = " ";
    this.keyword = " ";
    this.timestamp = " ";
    this.adgroup = " ";
    this.custom = " ";

	this._getValue = function(){ return this.source + '|' + this.medium + '|' + this.campaign + '|' + this.keyword + '|' + this.timestamp + '|' + this.adgroup + '|' + this.custom;
	};

	this._setCookie = function(name, value, expires, path, domain, overwrite) {
			// set time, it's in milliseconds
			var today = new Date();
			today.setTime(today.getTime());
			/*
				if the expires variable is set, make the correct 
				expires time, the current script below will set 
				it for x number of days, to make it for hours, 
				delete * 24, for minutes, delete * 60 * 24
			*/
			if (expires) {
				expires = expires * 1000 * 60 * 60 * 24;
			}
			else {
				expires = 365 * 24 * 60 * 60 * 1000;
			}
			var expires_date = new Date(today.getTime() + (expires));
			if (!value) {
				value = this.source + '|' + this.medium + '|' + this.campaign + '|' + this.keyword + '|' + this.timestamp + '|' + this.adgroup + '|' + this.custom;
			}
			if(overwrite == true || !document.cookie.match('(^|;\\s)' + name)){
			document.cookie = name + "=" + value + ((expires) ? ";expires=" + expires_date.toGMTString() : "") + ((path) ? ";path=" + path: ";path=/") + ((domain) ? ";domain=" + domain: "");
			}
	};
	
	this._initData = function(type) {
		var cancel_campaign = false;
		var cancel_medium = false;
		var cancel_keyword = false;
		var cancel_source = false;
		var cancel_content = false;
		if (type && document.cookie.match('(^|;\\s)' + type) && type != '__utmz') {
			var c2 = readCookie(type);
			var ca2 = c2.split('|');
			this.medium = ca2[0];
			this.source = ca2[1];
			this.campaign = ca2[2];
			this.keyword = ca2[3];
			this.timestamp = ca2[4];
			this.adgroup = ca2[5];
			this.custom = ca2[6];
		}
		if (!type || type == 'both' || type == 'query') {
			var q = storeQueryString();
			if (q['utm_source']) {
				this.source = q['utm_source'];
				cancel_source = true;
			}
			if (q['utm_medium']) {
				this.medium = q['utm_medium'];
				cancel_medium = true;
			}
			if (q['utm_campaign']) {
				this.campaign = q['utm_campaign'];
				cancel_campaign = true;
			}
			if (q['utm_term']) {
				this.keyword = q['utm_term'];
				cancel_keyword = true;
			}
			if (q['utm_content']) {
				this.adgroup = q['utm_content'];
				cancel_content = true;
			}
			if (q['ga_campaign']) {
				this.campaign = q['ga_campaign'];
				cancel_campaign = true;
			}
			if (q['ga_keyword']) {
				this.keyword = q['ga_keyword'];
				cancel_keyword = true;
			}
			if (q['ga_ad_content']) {
				this.custom = q['ga_ad_content'];
			}
			if (q['ga_adgroup']) {
				this.adgroup = q['ga_adgroup'];
				cancel_content = true;
			}
		}
		if (!type || type == 'both' || type == '__utmz') {
			if (document.cookie.indexOf('__utmz') != -1) {
				var c2 = readCookie('__utmz'); //This gets the cookie
				var ca2 = c2.split('|'); //This splits the cookie into parts
				temp2 = ca2[0].substring(ca2[0].indexOf('utmcsr'));
				temp2 = temp2.substring(temp2.indexOf('utmgclid'));
				ca2[0] = temp2; // We then replace the item in the array with just the variable data									
				for (i = 0; i < ca2.length; i++) {
					temp3 = ca2[i]; //First, take each variable (ex. utmcsr=sourcename)
					temp4 = temp3.split('='); //Splits into an array, with temp4[0] = 'utmcsr, and temp4[1] = 'sourcename' using our above example
					if (temp4[0] == 'utmgclid') //Identifies the varaible and replaces appropriate items for Google Adwords Campaigns
					{
						if (!cancel_source) {
							this.source = 'google';
							cancel_source = true;
						}
						if (!cancel_medium) {
							this.medium = 'cpc';
							cancel_medium = true;
						}
						if (!cancel_campaign) {
							this.campaign = 'google';
							cancel_campaign = true;
						}
					}
					if (temp4[0] == 'utmcsr' && !cancel_source) {
						this.source = temp4[1];
					}
					if (temp4[0] == 'utmccn' && !cancel_campaign) {
						this.campaign = temp4[1];
					}
					if (temp4[0] == 'utmcmd' && !cancel_medium) {
						this.medium = temp4[1];
					}
					if (temp4[0] == 'utmctr' && !cancel_keyword) {
						this.keyword = temp4[1];
					}
					if (temp4[0] == 'utmcct' && !cancel_content) {
						this.adgroup = temp4[1];
					}
				}
			}
		}
	};

	this._setAll = function(src,med,camp,key,time,adgr,cust){
		var today = new Date();
		today.setTime(today.getTime()); 
		(src) ? this.source = src : this.source = " ";
		(med) ? this.medium = med : this.medium = " ";
		(camp) ? this.campaign = camp : this.campaign = " ";
		(key) ? this.keyword = key : this.keyword = " ";
		(time) ? this.timestamp = time : this.timestamp = today.getUTCFullYear() + '/' + (today.getUTCMonth() + 1) + '/' + today.getUTCDate();
		(adgr) ? this.adgroup = adgr : this.adgroup = " ";
		(cust) ? this.custom = cust : this.custom = " ";
	};

    this._setSource = function(x) {
        this.source = x;
    };
    this._setMedium = function(x) {
        this.medium = x;
    };
    this._setCampaign = function(x) {
        this.campaign = x;
    };
    this._setKeyword = function(x) {
        this.keyword = x;
    };
    this._setAdgroup = function(x) {
        this.adgroup = x;
    };
    this._setTimestamp = function(x) {
       if(x){ 
		this.timestamp = x;
	   }
	   else{
		var today = new Date();
		today.setTime(today.getTime()); 
	   	this.timestamp = today.getUTCFullYear() + '/' + (today.getUTCMonth() + 1) + '/' + today.getUTCDate();
	   }
    };
    this._setCustom = function(x) {
        this.custom = x;
    };
}
function runSC(){
	if (readCookie("__utmtrack") == null) {
		var sc = new SuperCookie();
      	sc._initData();
      	sc._setTimestamp();
      	sc._setCookie('__utmtrack','','','','closecombattraining.com','');
	}
	var page = document.location.pathname;
	 if (page == "/cctraining/cctspecials/SSDupgrade.php"){
		var sc = new SuperCookie();
      	sc._initData('__utmtrack');
      	scdata = sc._getValue();
	}
}

/*function setLandingPageCookie(cookfirst,cooklast,myhost) {
	var bcookie = readCookie('__utmb').split('.');
	if(bcookie[1]=='1') {
	convregexp = new RegExp(/pixel\.php/);
	if(document.cookie.match('__utmb') && document.cookie.match('__utmc')) {
		if (convregexp.exec(location.pathname)){
			setProduct();
		}
		else {
			pageTracker._trackPageview();
		}
	}
	else {
		var x = new SuperCookie();
		var y = new SuperCookie();
		var z = new SuperCookie();
		x._initData();
		x._setCustom(location.pathname);
		x._setTimestamp();
		x._setCookie(cookfirst,'', '', '',myhost,false);
		x._setCookie(cooklast,'', '', '',myhost,true);
		y._initData(cooklast);
		z._initData(cookfirst);
		if(y.sleuth != ' ') {
			var newsleuth = y.sleuth;
		}
		if(z.sleuth != ' ') {
			var initsleuth = z.sleuth;
		}
		pageTracker._trackPageview(location.pathname + (location.search ? '&' : '?') + (initsleuth ? 'initsleuth=' + initsleuth : 'initsleuth=none') + (newsleuth ? '&newsleuth=' + newsleuth : '&newsleuth=none'));
	}
}*/

/*function setProduct() {
	var pcookie = readCookie('__utmtrial');
	var trialtoday = new Date();
	trialtoday.setTime(trialtoday.getTime());
	var trialexpires = (365 * 24 * 60 * 60 * 1000)/2;
	var trialexpires_date = new Date(trialtoday.getTime() + (trialexpires));
	var xecom = new SuperCookie();
	var zecom = new SuperCookie();
	xecom._initData('__utmfirst');
	zecom._initData('__utmlast');
	var yecom = xecom._getValue() + '|' + zecom.sleuth;
	var ecomorderid = storeQueryString();
	ecomorderid = ecomorderid['clientid'];
	var pageTracker2=_gat._getTracker("UA-336469-1");
	pageTracker2._setDomainName("roirevolution.com");
	pageTracker2._addIgnoredRef("roirevolution.com");
	pageTracker2._addIgnoredRef("www.roirevolution.com");
	pageTracker2._addIgnoredRef("app.roirevolution.com");
	pageTracker2._addIgnoredRef("help.roirevolution.com");
	pageTracker2._addIgnoredRef("community.roirevolution.com");
	pageTracker2._setSessionTimeout(14400);
	if(pcookie) {
		if(pcookie.match('trial')) {
			var gwoCookie = readCookie("__utmx");
			if(gwoCookie) {
				if(gwoCookie.match("0822122855")) {
					var gwoTracker=_gat._getTracker("UA-336469-4");
					gwoTracker._setDomainName("roirevolution.com");
					gwoTracker._trackPageview("/0822122855/goal");
				}
			}
			if(readCookie("afid")) {
				var myAFID = readCookie("afid");
				pageTracker2._trackPageview("/upgrade.php?roitype=paid&roiafid=" + myAFID + "&supercookie=" + yecom);
			}
			else {
				pageTracker2._trackPageview("/upgrade.php?roitype=paid&roiafid=other&supercookie=" + yecom);
			}
			document.cookie = "__utmtrial=customer;expires=" + trialexpires_date + ";path=/;domain=roirevolution.com";
			pageTracker2._addTrans(ecomorderid,yecom,"","","","","","");
			pageTracker2._addItem(ecomorderid,"trialupgrade","Trial Upgrade","Trial Upgrade","","1");
			pageTracker2._trackTrans();
			pageTracker2._setVar('paid');
			return 'Trial Upgrade';
		}
		else if(pcookie.match('customer')) {
			if(readCookie("afid")) {
				var myAFID = readCookie("afid");
				pageTracker2._trackPageview("/upgrade.php?roitype=upgrade&roiafid=" + myAFID + "&supercookie=" + yecom);
			}
			else {
				pageTracker2._trackPageview("/upgrade.php?roitype=upgrade&roiafid=other&supercookie=" + yecom);
			}
			document.cookie = "__utmtrial=upgrade;expires=" + trialexpires_date + ";path=/;domain=roirevolution.com";
			pageTracker2._addTrans(ecomorderid,yecom,"","","","","","");
			pageTracker2._addItem(ecomorderid,"upgrade","Paid Upgrade","Paid Upgrade","","1");
			pageTracker2._trackTrans();
			pageTracker2._setVar('upgrade');
			return 'Customer Upgrade';
		}
	}
	else {
		if(readCookie("afid")) {
			var myAFID = readCookie("afid");
			pageTracker2._trackPageview("/upgrade.php?roitype=trial&roiafid=" + myAFID + "&supercookie=" + yecom);
		}
		else {
			pageTracker2._trackPageview("/upgrade.php?roitype=trial&roiafid=other&supercookie=" + yecom);
		}
		document.cookie = "__utmtrial=trial;expires=" + trialexpires_date + ";path=/;domain=roirevolution.com";
		pageTracker2._addTrans(ecomorderid,yecom,"","","","","","");
		pageTracker2._addItem(ecomorderid,"trial","Trial","Trial","","1");
		pageTracker2._trackTrans();
		pageTracker2._setVar('trial');
		return 'New Trial Account';
	}
}*/
var scdata;
var pageTracker;

function runGA() {            
	if(typeof(_gat)=='object') {
		pageTracker = _gat._getTracker("UA-516637-4");
		pageTracker._setAllowHash(false);
		pageTracker._setAllowLinker(true);
		pageTracker._addIgnoredRef("www.mcssl.com");
		if (document.referrer.indexOf("mcssl.com") > -1) {
			pageTracker._setReferrerOverride("");
		}
		sleuth();
		runSC();
		pageTracker._trackPageview();	
		
		// some variables used for tagging links
		var oneSCLinks = document.getElementsByTagName("a");
		var linkCount;
		
		// link tagging script
		for (linkCount = 0; linkCount < oneSCLinks.length; linkCount += 1) {
				if (oneSCLinks[linkCount].href.indexOf("www.1shoppingcart.com") > -1) {
						oneSCLinks[linkCount].onclick = function () {
							   this.href = pageTracker._getLinkerUrl(this.href);
					   }
				}
		}
		
	} else {
    	setTimeout("runGA();",100);
	}
} 
runGA();