// "standard" read cookie function  (copied from Prusak's gwo_write.js)
function read_cookie(cookie_name) {
  var my_cookie = "" + document.cookie;
  var ind=my_cookie.indexOf(cookie_name);
  if (ind==-1 || cookie_name=="") return ""; 
  var ind1=my_cookie.indexOf(';',ind);
  if (ind1==-1) ind1=my_cookie.length; 
  return unescape(my_cookie.substring(ind+cookie_name.length+1,ind1));
}

function superSetVar(appendValue) {
  var getVar = read_cookie('__utmv');       // read the __utmv cookie
	hasValue = getVar.indexOf(appendValue);   // does the cookie already have the value we want to append?
  if ( hasValue == -1 ) {                   // if the new value is not already in the cookie
    removePrefix = /^.*\.(.*)/.exec(getVar);// __utmv cookie has the format 12345678.cookieValue - remove the ## prefix
    if (removePrefix && removePrefix[1]) {
      newVar = removePrefix[1] + appendValue; // append the value
    }else{
      newVar = appendValue;                 // this will execute if the cookie was not already set.
    }
		var superSetVarTracker = _gat._getTracker("UA-1-1");  // set up a tracker to call _setVar from
		superSetVarTracker._initData();  
		superSetVarTracker._setVar(newVar);                   // call _setVar with the new value
  }
}

function unSetVar(removeValue){
  var getVar = read_cookie('__utmv');         // read the __utmv cookie
  hasValue = getVar.indexOf(removeValue);     // does the cookie have the value we want to remove?
  if ( hasValue != -1 ) {                     // if the value is in the cookie then . . .  otherwise, there is nothing further to do.
    removePrefix = /^.*\.(.*)/.exec(getVar);  // __utmv cookie has the format 12345678.cookieValue - remove the ## prefix
    if (removePrefix && removePrefix[1]) {    // if we remove the prefix then. . .
      //
      var re = removeValue + '[^/]*';
      re = new RegExp(re,'g');
      newVar = removePrefix[1].replace(re,""); // newVar = removePrefix[1] MINUS removeValue
      //
      var superSetVarTracker = _gat._getTracker("UA-1-1");  // set up a tracker to call _setVar from
      superSetVarTracker._initData();  
      superSetVarTracker._setVar(newVar);                   // call _setVar with the new value
    }
  }
}

/**
 * Default Google Variables
 * source: http://groups.google.com/group/analytics-help-troubleshoot/browse_thread/thread/b17e29aa72cb1528/c3c59c4380ccbe4f?lnk=raot
 * source: http://code.google.com/apis/analytics/docs/gaTrackingTroubleshooting.html
**/
/*
utmwv	4.3 					// UTM version
utmn	205365649 		// Random number generated for each __utm.gif hit and used to prevent cacheing of gif
utmhn	bestpract.us 	// requested hostname (mysite.com)
utmcs	UTF-8					//
utmsr	1600x1200			// screen resolution
utmsc	32-bit				// screen colors
utmul	en-us					// user language
utmje	0							// Java Enabled? (0|1)
utmfl	10.0 r12			// Flash version
utmdt	mooTools poof effect | bestpract.us // document title
utmhid	586089623		// 
utmr	-							// referrer
utmp	/mootools/poof/	// page requested
utmac	UA-2161286-5	// account number
utmcc	__utma=229614991.4527267766248920000.1229550401.1229550401.1230045455.2;+__utmz=229614991.1229550677.1.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=mootools%20poof;+__utmv=229614991.%2Fcampaign%3Dblue%2Fcampaign%3Ddirect; // cookies
*/
/**
 * Google Analytics Destination UTL Variables
 * source: http://www.roirevolution.com/google-analytics/google-analytics-url-builder.htm
**/
/*
utm_source		// identifies source, search engine
utm_medium		// identify medium - email, cpc (cost-per-click)
utm_campaign 	// specfic promotion or strategic campaign
utm_term			// paid key words
utm_content		// differentiate between ads or links that point to same URL

** paid search - manually tracking - no longe rbe able to tie analytics ad adwords together
** paid search and manual vs. automatic tracking
** encrypted key in param "gclid" if google's automatically tracking (not manual)
if (gclid !== null)
*/
