// "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,act,UA) { //act 0=append 1=overwrite 2=preserve
  var getVar = read_cookie('__utmv');       // lê o cookie __utmv
  hasValue = getVar.indexOf(appendValue);   // o cookie já tem o valor que se quer adicionar?
  removePrefix = /^.*\.(.*)/.exec(getVar);  // __utmv cookie tem o formato 12345678.cookieValue - remove o prefixo ##
  if (removePrefix && removePrefix[1]) { // se o cookie possui algum valor
    if (act==2){return;} //preservar, então sai
    if (act==1){newVar=appendValue;} //substituir o valor
    if (act==0){ //concatenar
      if (hasValue==-1) { //só concatena se o valor ainda não está no cookie
        newVar = removePrefix[1] + appendValue; // concatena o valor
      }
    }
  }else{ //se o cookie não possui qualquer valor, então atribui o valor passado
    newVar = appendValue;
  }
  var superSetVarTracker = _gat._getTracker(UA);  // define o tracker para chamar o _setVar
  superSetVarTracker._initData();  
  superSetVarTracker._setVar(newVar);                   // define o _setVar com o novo valor
}

function unSetVar(removeValue,UA){
  var getVar = read_cookie('__utmv');         // lê o cookie __utmv
  hasValue = getVar.indexOf(removeValue);     // o cookie tem o valor que se quer remover?
  if ( hasValue != -1 ) {                     // se o valor está no cookie então . . .  caso contrário, não há nada a ser feito.
    removePrefix = /^.*\.(.*)/.exec(getVar);  // __utmv cookie tem o formato 12345678.cookieValue - remove o prefixo ##
    if (removePrefix && removePrefix[1]) {    // se nós removemos o prefixo então. . .
      //
      var re = removeValue + '[^/]*';
      re = new RegExp(re,'g');
      newVar = removePrefix[1].replace(re,""); // newVar = removePrefix[1] MINUS removeValue
      //
      var superSetVarTracker = _gat._getTracker(UA);  // defina o tracker para chamar o _setVar
      superSetVarTracker._initData();  
      superSetVarTracker._setVar(newVar);                   // define o _setVar com o novo valor
    }
    
  }
}