﻿// "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
  	//alert(appendValue);
  	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-10552718-1");  // set up a tracker to call _setVar from
  	superSetVarTracker._initData();
  	superSetVarTracker._setVar(newVar);                   // call _setVar with the new value
  } else {
	//alert("old=" + getVar);
  }
}

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.
  	//alert("remove=" + removeValue);
    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');
      //alert("r1=" + getVar);
      newVar = removePrefix[1].replace(re,""); // newVar = removePrefix[1] MINUS removeValue
      var superSetVarTracker = _gat._getTracker("UA-10552718-1");  // set up a tracker to call _setVar from
      superSetVarTracker._initData();
      superSetVarTracker._setVar(newVar);                   // call _setVar with the new value
      //alert("r2=" + newVar);
      //alert("r2=" + read_cookie('__utmv'));
    }
    
  }
}