/*gms_gaswitch-v100.js
Benutzerdefinierter Opt-Out-Schalter f. Google Analytics
Version: 1.00.4
Datum: 07.01.2010
www.gandke.de

Infos siehe http://www.gandke.de/analytics-opt-out-download.html

*/

var gmsGAOptState = 'undefined';
var expdate = new Date();
var _showDebug = true;
expdate.setDate(expdate.getDate()+365);

//Dummy, um per Klick getrackte Events, Transaktionen und virtl. Pageviews abzufangen
function gmsDummyTracker() {
  this._trackPageview = function(s) { } 
  this._trackEvent = function(a,b,c,d) { } 
  this._addTrans = function(a,b,c,d,e,f,g,h) { } 
  this._addItem = function(a,b,c,d,e,f) { } 
  this._trackTrans = function() { } 
  
  this._link = function(a, b) { }
  this._linkByPost = function(a, b) { }
  this._setAllowHash = function(a) { }
  this._setAllowLinker = function(a) { }
  this._setCookiePath = function(a) { }
  this._setDomainName = function(a) { }
  this._cookiePathCopy = function(a) { }
  this._getLinkerUrl = function(a, b) { }
  this._deleteCustomVar = function(a) { }
  this._getAccount = function() { }
  this._getVersion = function() { }
  this._getVisitorCustomVar = function(a) { }
  this._initData = function() { }
  this._addVar = function(a) { }
  this._setCookiePersistence = function(a) { }
  this._setCustomVar = function(a, b, c, d) { }
  this._setSampleRate = function(a) { }
  this._setSessionTimeout = function(a) { }  
  this._setAllowAnchor = function(a) { }
  this._setCampContentKey = function(a) { }
  this._setCampMediumKey = function(a) { }
  this._setCampNameKey = function(a) { }
  this._setCampNOKey = function(a) { }
  this._setCampSourceKey = function(a) { }
  this._setCampTermKey = function(a) { }
  this._setCampaignTrack = function(a) { }
  this._setCookieTimeout = function(a) { }
  this._setReferrerOverride = function(a) { }
  this._addIgnoredOrganic = function(a) { }
  this._addIgnoredRef = function(a) { }
  this._addOrganic = function(a, b, c) { }
  this._clearIgnoredOrganic = function() { }
  this._clearIgnoredRef = function() { }
  this._clearOrganic = function() { }
  this._getClientInfo = function() { }
  this._getDetectFlash = function() { }
  this._getDetectTitle = function() { }
  this._setClientInfo = function() { }
  this._setDetectFlash = function() { }
  this._setDetectTitle = function() { }
  this._getLocalGifPath = function() { }
  this._getServiceMode = function() { }
  this._setLocalGifPath = function(a) { }
  this._setLocalRemoteServerMode = function() { }
  this._setLocalServerMode = function() { }
  this._setRemoteServerMode = function() { }
}

//Komplett aus dem Beispiel bei http://www.web-analytics-nutzen.de/ uebernommen:
function getCookie(value) {
    var dc = document.cookie;
    var prefix = value + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
    } else {
    begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
    end = dc.length;
    }
    return dc.substring(begin + prefix.length, end);
}

//Benutzerauswahl im Cookie f. 1 Jahr speichern:
function gmsSwitchGAActive(s, domain) {
  if (s == true)
    document.cookie = 'gmsGAOptOut=false;expires='+expdate.toGMTString()+';path=/'+( ( domain ) ? ";domain=" + domain : "" );
  else {  
    document.cookie = 'gmsGAOptOut=true;expires='+expdate.toGMTString()+';path=/'+( ( domain ) ? ";domain=" + domain : "" );
    try {
      //Hier ggf. Variablennamen des Trackers anpassen oder das Eventtracking bei 
      //Bedarf komplett weglassen...
      pageTracker._trackEvent('SwitchTracking', 'Off', document.URL);
    } catch(err) {}
  } 
  return true;
}

//Abruf des akt. Zustands des Trackings aus Cookie oder als gespeichertes Ergebnis
function gmsGATrackingActive()
{
   if (gmsGAOptState == "undefined") {
     var gmsGAOptOut = getCookie("gmsGAOptOut");
     if ((gmsGAOptOut != null) && (gmsGAOptOut == 'true')) { 
       gmsGAOptState =  'disabled'
     } else {
       gmsGAOptState =  'active';
     } 
   }
   return (gmsGAOptState != 'disabled') ;  
}

//Zuweisung des Klickevents und Setzen der Checkbox je nach Benutzerauswahl
function gmsInitGASwitch(s, domain)
{
   var cbox = null;
   if (s != "") cbox = document.getElementById(s);
   if (cbox != null) {
     cbox.checked = gmsGATrackingActive();
     cbox.onclick = function (){ gmsSwitchGAActive(this.checked, domain);};  
     return true;
   }
}     

