//  ProtoTypes:
// requires inclusion of cgiBasePath.js


// --------------------------------------------------
function getLocalDate ()
{
  var da = new Date();
  var d  = da.getDate();
  var mo = da.getMonth()+1;
  var y  = da.getYear();

  if (y < 1900)
   y += 1900;

  var dateStr = '' + y;

  if (mo < 10) dateStr += '0';  dateStr += mo;
  if (d < 10)  dateStr += '0';  dateStr += d;

  return dateStr;
}

// --------------------------------------------------

function getLocalTime ()
{
  var lda =new Date();
  var ho = lda.getHours();
  var mi = lda.getMinutes();
  var se = lda.getSeconds();
  var timeStr = '';

  if (ho < 10) timeStr += '0';  timeStr += ho;
  if (mi < 10) timeStr += '0';  timeStr += mi;
  if (se < 10) timeStr += '0';  timeStr += se;

  return timeStr;
}

// --------------------------------------------------

function getTimeZone ()
{
  var lda =new Date();
  return lda.getTimezoneOffset();
}

// --------------------------------------------------

function getLocalId ()
{
  var arg = 'locId=';
  var alen = arg.length;
  var returnId = '';
  var startPos = document.cookie.indexOf (arg, 0);
  var endPos = 0;

  if (startPos >= 0)
  {
    startPos += alen +1;
    endPos = document.cookie.indexOf (";", startPos);
    if (endPos == -1)
      endPos = document.cookie.length;

    returnId = unescape(document.cookie.substring(startPos, endPos));
  }
  else
  {
    returnId = getLocalDate() + getLocalTime ();

    var expInMinutes = 5 * 365 * 24 * 60 ; // 5 years
    var expires      = new Date();

    expires.setTime(expires.getTime() + (expInMinutes * 60 * 1000 ));
    var cookieStr = arg + "=" + escape (returnId) + "; expires=" + expires.toGMTString() + "; path=/";

    document.cookie = cookieStr;
  }
  return returnId;
}

// --------------------------------------------------

function track (doc, id, pageName, alertEmail, appName, sectionName)
{
  window.onerror=null;

  var debugMode = 2;

  var locTime = getLocalTime ();
  var tz = getTimeZone ();
  var al = '/access/ac.asp';

  var ae = alertEmail;
  var ie =0;
  var an = '' + appName;
  var sn = '' + sectionName;
  var hn = "";
  var ip = "";
  var wx = 0;
  var wy = 0;

  var pn = "" + escape(pageName);
  var ua = "" + escape(navigator.userAgent);
  var je = 0 + navigator.javaEnabled();
  var rx = window.screen.width;
  var ry = window.screen.height;
  var cd = window.screen.colorDepth;
  var rf = ""+escape(doc.referrer);

  navigator.userAgent.indexOf("MSIE") > 0 ? ie=1 : ie=0;

  if (je && !ie)
  {
    var vt = java.awt.Toolkit.getDefaultToolkit();
    var ad = java.net.InetAddress.getLocalHost();
    hn = ""+ad.getHostName();
    ip = ""+ad.getHostAddress();
  }
  if (ie)
  {
    wx=doc.body.clientWidth;
    wy=doc.body.clientHeight;
  }
  else
  {
    wx=window.outerWidth;
    wy=window.outerHeight;
  }

  // remove local id
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  document.cookie = "localId=; expires=" + exp.toGMTString();
  // document.cookie = "locId=; expires=" + exp.toGMTString();

  var ix = ((document.cookie.indexOf ('locId=', 0) >= 0) ? 1 : 0);
  var li = getLocalId ();
  var pa = "?id="+id+"&pn="+pn+"&je="+je+"&ae="+ae + "&li="+li + "&ix="+ix +
           "&wx="+wx+"&wy="+wy+"&rx="+rx+"&ry="+ry+"&cd="+cd+"&rf="+rf+"&hn="+hn+"&ip="+ip+
           "&locTime="+locTime+"&tz="+tz+"&ua="+ua+"&debug="+debugMode;

  // var pw=prompt('submitting:',pa);

  var outStr = '\n<IMG border=0 width=1 height=1 SRC="' + al + pa + '">\n';

  // alert ('outStr = ' + outStr);
  doc.write (outStr);

}


// alert ('tracker');


