/**
 * Google analytics javascript from ROIRevolution.
 *
 * @package    wyattresearch
 * @subpackage Webroot
 * @author     Caitlin Cook <ccook@roirevolution.com>
 * @version    $Id: gascript.js 704 2010-12-16 13:22:16Z millsd $
 */
// gascript 1.1.0

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"));

var x = location.hostname;

function noPercent(x) {
	if (x) {
		x = unescape(x);
		return x.replace(/\+/g," ").replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	} else {
		return x;
	}
}

function readSubCookie(name) {      
      var nameRegex = RegExp("(?:\\||\\.|^|; )" + name + "=([^|;]+)"),
            nameValue;
      nameValue = nameRegex.exec(noPercent(document.cookie));
      if (nameValue) {
            return nameValue[1];
      } else {
            return null;
      }
}

function readQuery(name) { 
	var nameRegex = RegExp("(?:\\?|&)" + name + "=([^&]+)");
	nameValue = nameRegex.exec(noPercent(location.search));
	if(nameValue) {
		return nameValue[1];
	} else {
		return null;
	}
}

function exactQuery() {
	var re = new RegExp(/(?:\?|&)(?:q|p|query|encquery|qt|terms|rdata|qs|wd|text|szukaj|k|searchExpr|search_for|string|search_query|searchfor)=([^&]+)/);
	var searchq = re.exec(document.referrer);
	if (searchq) {
		searchq = "|" + noPercent(searchq[1]);
		return searchq;
	} else {
		return "|(not set)";
	}
}

function sleuth() {
	if(readQuery("gclid")||readQuery("utm_medium")=="cpc") {
		if (!pageTracker._getVisitorCustomVar(1)) {
			pageTracker._setCustomVar(1, "exact_keyword", exactQuery() , 1);
		}
	}
}

function modifyForm(name) {
	if (name) {
		var fieldNames = ["ga_source", "ga_campaign", "ga_adgroup", "ga_keyword", "ga_landingpage"];
		if (document.forms[name]) {
			for (i = 0; i < fieldNames.length; i+= 1) {
				var gaField = document.createElement("input");
				gaField.setAttribute("name", fieldNames[i]);
				gaField.setAttribute("value", noPercent(pageTracker._getVisitorCustomVar(i + 1)));
				gaField.setAttribute("type", "hidden");
				document.forms[name].appendChild(gaField);
			}
		}
	} 
}

function isFirstVisit() {
    var acookie = readCookie('__utma').split('.');
    var bcookie = readCookie('__utmb').split('.');
    if (acookie[5] == 1 && bcookie[1] < 1) {
        return true;
    }
    else {
        return false;
    }
}

wr_incomeRE = new RegExp(/wyattresearchincome\.com/);
wr_greenRE = new RegExp(/wyattresearchgreenenergy\.com/);
wr_goldRE = new RegExp(/wyattresearchgold\.com/);
wr_chinaRE = new RegExp(/wyattresearchchina\.com/);
wr_pennyRE = new RegExp(/wyattresearchpennystocks\.com/);
wr_commoditiesRE = new RegExp(/wyattresearchcommodities\.com/);
wr_energyRE = new RegExp(/wyattresearchenergy\.com/);
mutualAdvisorsRE = new RegExp(/mutualsadvisor\.com/);
NewsletterAdvisorsRE = new RegExp(/newsletteradvisors\.com/);
HiddenStocksRE = new RegExp(/hiddenstocks\.com/);
DailyProfitRE = new RegExp(/dailyprofit\.com/);
IRC_RE = new RegExp(/investorresearchcenter\.com/);
roiregexp = new RegExp(/roirevolutiontraining\.com/);


var pageTracker, firstTracker;
var ua = "1";

function runGA() {            
	if(typeof(_gat)=='object') {
		if (wr_incomeRE.exec(x)){
			ua = "17551617-1"}			
		if (wr_greenRE.exec(x)){
			ua = "17551233-1";}
		if (wr_goldRE.exec(x)){
			ua = "17548578-1";}
		if (wr_chinaRE.exec(x)){
			ua = "17548576-1";}
		if (wr_pennyRE.exec(x)){
			ua = "17551623-1";}
		if (wr_commoditiesRE.exec(x)){
			ua = "17592146-1";}
		if (wr_energyRE.exec(x)){
			ua = "17592350-1";}
		if (mutualAdvisorsRE.exec(x)){
			ua = "3754000-1";}
		if (NewsletterAdvisorsRE.exec(x)){
			ua = "4340139-1";}			
		if (HiddenStocksRE.exec(x)){
			ua = "4340437-2";}		
		if (DailyProfitRE.exec(x)){
			ua = "17573119-1";}		
		if (roiregexp.exec(x)){
			ua = "000000-0"}	
		try{
			pageTracker = _gat._getTracker('UA-'+ ua);
			pageTracker._trackPageview();
			sleuth();	
		}catch(err){}
	} else {
            setTimeout("runGA();",100);
	  }
}

runGA();

