// Gather Source Data - (c)2009 Ty Roden, TBS
var z = _uGC(document.cookie, '__utmz=', ';');
// utmcsr  = campaign source
// utmcmd  = campaign medium
// utmctr  = campaign term (keyword)
// utmcct  = campaign content (used for A/B testing)
// utmccn  = campaign name
// utmgclid = unique identifier used when AdWords auto tagging is enabled
//
var source  = _uGC(z, 'utmcsr=', '|');
var medium  = _uGC(z, 'utmcmd=', '|');
var term    = _uGC(z, 'utmctr=', '|');
var content = _uGC(z, 'utmcct=', '|');
var campaign = _uGC(z, 'utmccn=', '|');
var gclid   = _uGC(z, 'utmgclid=', '|');
//
if (gclid !="-") {
      source = 'google';
      medium = 'cpc';
}
function _uGC(l,n,s) {
   // used to obtain a value from a string of key=value pairs
   if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
   var i,i2,i3,c="-";
   i=l.indexOf(n);
   i3=n.indexOf("=")+1;
   if (i > -1) {

      i2=l.indexOf(s,i); if (i2 < 0) { i2=l.length; }

      c=l.substring((i+i3),i2);
   }
   return c;
}

// Attempt ga.js cookie poll, if manual variables on URL, overwrite.

function writeCookie(cname, value, days){ // standard cookie routine to writeout
  if(days){
    (t=new Date()).setTime(new Date().getTime()+days*24*60*60*1000);
    var e='; expires='+t.toGMTString();
  }else{
    var e='';
  }
  document.cookie=cname+"="+value+e+"; path=/";
}

function varlookup(name, url) { // optional- pass URL otherwise parse current
	if (!url) url = window.location.href;
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var results = new RegExp("[\\?&]"+name+"=([^&#]*)").exec(url);
	if( results == null ) return null;		// return null if not found
	else // decodeURIComponent doesn't recognize '+' as encoding for space
		return decodeURIComponent(results[1].replace(/\\+/g," "));
}

if(varlookup('utm_source') != null){
    var source = varlookup("utm_source"); // setup the var + store
    writeCookie('johnsonlawsource', source, '31');
}
if(varlookup('utm_medium') != null){
    var medium = varlookup("utm_medium");
    writeCookie('johnsonlawmedium', medium, '31');
}
if(varlookup('utm_term') != null){
    var keyword = varlookup("utm_term");
    writeCookie('johnsonlawkeyword', keyword, '31');
}
if(varlookup('source') != null){
    var source = varlookup("source"); // setup the var + store
    writeCookie('johnsonlawsource', source, '31');
}
if(varlookup('medium') != null){
    var medium = varlookup("medium");
    writeCookie('johnsonlawmedium', medium, '31');
}
if(varlookup('keyword') != null){
    var keyword = varlookup("keyword");
    writeCookie('johnsonlawkeyword', keyword, '31');
}

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

if (readCookie('johnsonlawsource') != null) {
    source = readCookie('johnsonlawsource');
}
if (readCookie('johnsonlawmedium') != null) {
    medium = readCookie('johnsonlawmedium');
}
if (readCookie('johnsonlawkeyword') != null) {
    term = readCookie('johnsonlawkeyword');
}


