// Sets the referrer to the current value of the DCS.dcsuri
function setReferrer() {
  if (!(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)<4)){
    DCS.dcsref = self.location.href.substring(0,self.location.href.indexOf(self.location.pathname)) + DCS.dcsuri;
  }  
}

// Returns the page path starting from the web root directory.
function getFolder(){
  return thisFolder = self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')+1);
}


// objectReference must be a relative path: e.g "test.pdf" or "downloads/test.pdf".
// A path outside the current directory is NOT allowed: e.g. "../download/test.pdf".
// If the referrer for a new function call should not be changed, the value of the attribute "keepLastReferrer" must be "1" or "true".
// Otherwise the attribute should not be used.
// The referrer should not be changed, if an event should be tracked without taking the User to a new page:
// e.g. when tracking a download file (*.pdf, *.zip, etc.).
function trackRelative(objectReference,objectTitle,keepLastReferrer){
  setReferrer();
  currentUri = DCS.dcsuri;
  if (objectReference.indexOf('?') != -1) {
    DCS.dcsqry = objectReference.substring(objectReference.indexOf('?'));
    objectReference = objectReference.substring(0, objectReference.indexOf('?'));
  }
  path = getFolder() + objectReference;
  dcsMultiTrack('DCS.dcsuri',path,'WT.ti',objectTitle);
  if (keepLastReferrer) {
    DCS.dcsuri = currentUri;
  }
}

// objectReference must be an absolute path starting from the web root directory: e.g "/com/en/downloads/test.pdf".
// The path must begin with a slash: e.g. "/".
// If the referrer for a new function call should not be changed, the value of the attribute "keepLastReferrer" must be "1" or "true".
// Otherwise the attribute should not be used.
// The referrer should not be changed, if an event should be tracked without taking the User to a new page:
// e.g. when tracking a download file (*.pdf, *.zip, etc.).
function trackAbsolute(objectReference,objectTitle,keepLastReferrer){
  setReferrer();
  currentUri = DCS.dcsuri;
  if (objectReference.indexOf('?') != -1) {
    DCS.dcsqry = objectReference.substring(objectReference.indexOf('?'));
    objectReference = objectReference.substring(0, objectReference.indexOf('?'));
  }
  path = objectReference;
  dcsMultiTrack('DCS.dcsuri',path,'WT.ti',objectTitle);
  if (keepLastReferrer) {
    DCS.dcsuri = currentUri;
  }
}

// objectReference must be a URL to an external website that is not part of your website tracking: e.g "www.microsoft.com".
// The URL protocol, e.g. "http://", is NOT allowed as part of the reference.
function trackExternal(objectReference,objectTitle){
  setReferrer();
  currentUri = DCS.dcsuri;
  if (objectReference.indexOf('?') != -1) {
    DCS.dcsqry = objectReference.substring(objectReference.indexOf('?'));
    objectReference = objectReference.substring(0, objectReference.indexOf('?'));
  }
  path = getFolder() + "external/" + objectReference;
  dcsMultiTrack('DCS.dcsuri',path,'WT.ti',objectTitle);
  DCS.dcsuri = currentUri;
}

