/**************************************************************
  Javascript function to display network statistics
  tracking pixel. New functionality to track job ids,
  page titles, and email campaigns.
  Created 7/1/2008 jga
  Added 
***************************************************************/
function writeTrackingPixel() {

  var track_pixel; var b_tracked_item;

  //write beginning of image pixel to tracking variable
  track_pixel = "<img src=\"/common/track/TrackNetworkStatistics.asp";

  //if it exists, append URL of page to be tracked to the image's query string
  if (typeof(track_url) != 'undefined') {
    track_pixel = track_pixel + "?tURL=" + track_url;
    b_tracked_item = true;
  }

  //if it exists, append query string information of page to be tracked to the image's query string
  if (typeof(track_query_string) != 'undefined') {
    if (b_tracked_item) {
      track_pixel = track_pixel + "&tQS=" + track_query_string;
    } else {
      track_pixel = track_pixel + "?tQS=" + track_query_string;
      b_tracked_item = true;
    }
  }

  //if it exists, append referrer information of page to be tracked to the image's query string
  if (typeof(track_referrer) != 'undefined') {
    if (b_tracked_item) {
      track_pixel = track_pixel + "&tReferrer=" + track_referrer;
    } else {
      track_pixel = track_pixel + "?tReferrer=" + track_referrer;
      b_tracked_item = true;
    }
  }

  //if it exists, append affiliate code passed to page to be tracked to the image's query string
  if (typeof(track_affiliate) != 'undefined') {
    if (b_tracked_item) {
      track_pixel = track_pixel + "&aff=" + track_affiliate;
    } else {
      track_pixel = track_pixel + "?aff=" + track_affiliate;
      b_tracked_item = true;
    }
  }

  //if there is an affiliate or inbound click param is true, track that visit is inbound and where visit is from
  if (((typeof(track_affiliate) != 'undefined') && (track_affiliate.length > 0)) || ((typeof(track_inbound) != 'undefined') && (track_inbound == 'Y'))) {
    if (typeof(track_inbound_source) != 'undefined') {
      if (b_tracked_item) {
        track_pixel = track_pixel + "&inb=Y&inbsrc=" + track_inbound_source;
      } else {
        track_pixel = track_pixel + "?inb=Y&inbsrc=" + track_inbound_source;
        b_tracked_item = true;
      }
    } else {
      if (b_tracked_item) {
        track_pixel = track_pixel + "&inb=Y&inbsrc=";
      } else {
        track_pixel = track_pixel + "?inb=Y&inbsrc=";
        b_tracked_item = true;
      }
    }
  }

  //if a page title is defined somewhere on the page visited, track it
  if (typeof(track_page_title) != 'undefined') {
    if (b_tracked_item) {
      track_pixel = track_pixel + "&title=" + track_page_title;
    } else {
      track_pixel = track_pixel + "?title=" + track_page_title;
      b_tracked_item = true;
    }
  }

  //if this visit was from a defined email campaign, track it
  if (typeof(track_email_id) != 'undefined') {
    if (b_tracked_item) {
      track_pixel = track_pixel + "&emid=" + track_email_id;
    } else {
      track_pixel = track_pixel + "?emid=" + track_email_id;
      b_tracked_item = true;
    }
  }

  //if this visit has a 'value1' defined, track it
  if (typeof(track_value_1) != 'undefined') {
    if (b_tracked_item) {
      track_pixel = track_pixel + "&tv1=" + track_value_1;
    } else {
      track_pixel = track_pixel + "?tv1=" + track_value_1;
      b_tracked_item = true;
    }
  }
  
  //if this visit has a 'value1' defined, track it
  if (typeof(track_reference_id) != 'undefined') {
    if (b_tracked_item) {
      track_pixel = track_pixel + "&rid=" + track_reference_id;
    } else {
      track_pixel = track_pixel + "?rid=" + track_reference_id;
      b_tracked_item = true;
    }
  }
  
  //if this visit has a 'value1' defined, track it
  if (typeof(track_reference_type_id) != 'undefined') {
    if (b_tracked_item) {
      track_pixel = track_pixel + "&rtid=" + track_reference_type_id;
    } else {
      track_pixel = track_pixel + "?rtid=" + track_reference_type_id;
      b_tracked_item = true;
    }
  }
  
  //if a time is defined for the beginning of the page load, pass through a total page load time
  if (typeof(track_page_load_begin_time) != 'undefined') {
    var d2 = new Date();
    var track_page_load_end_time = d2.getTime();
    var track_page_load_time = ((track_page_load_end_time - track_page_load_begin_time) / 1000);
    if (b_tracked_item) {
      track_pixel = track_pixel + "&plt=" + escape(track_page_load_time.toString());
    } else {
      track_pixel = track_pixel + "?plt=" + escape(track_page_load_time.toString());
      b_tracked_item = true;
    }
  }

  //write closure of image tag
  track_pixel = track_pixel + "\" height=\"1\" width=\"1\">";
  
  //return completed tracking image (pixel)
  document.write(track_pixel);
  
}
