/****************************************************
 * Parse utmz cookie values into salesforce fields
 * **************************************************/ 
// extract one utmz parameter
function _uGC(l,n,s) {
   // used to obtain a value form 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;
}
// parse all utmz params
function parse_utmz() {
  var z = _uGC(document.cookie, "__utmz=", ";");
  if (document.getElementById("u00N20000002EVAU")) {
    document.getElementById("u00N20000002EVAU").value = _uGC(z,"utmcsr=", "|"); //utmz source
  }
  if (document.getElementById("u00N20000002EVB7")) {
    document.getElementById("u00N20000002EVB7").value = _uGC(z,"utmcmd=", "|"); //utmz medium
  }
  if (document.getElementById("u00N20000002EUiy")) {
    document.getElementById("u00N20000002EUiy").value = _uGC(z,"utmctr=", "|"); //utmz keyword
  }
  if (document.getElementById("u00N20000002EVBC")) {
    document.getElementById("u00N20000002EVBC").value = _uGC(z,"utmcct=", "|"); //utmz ad content
  }
  if (document.getElementById("u00N20000002DfKm")) {
    document.getElementById("u00N20000002DfKm").value = _uGC(z,"utmccn=", "|"); //utmz campaign name
  }
  if (document.getElementById("Campaign_ID")) {
    document.getElementById("Campaign_ID").value     = _uGC(z,"utmccn=", "|"); //utmz campaign name
  }
  if (document.getElementById("u00N20000002EXsC")) {
    document.getElementById("u00N20000002EXsC").value = document.referrer;      //http_referer
  }
  return;
}

