// $Id: trk.js,v 1.2 2006/11/01 04:14:32 pat Exp $
//
function trk_Go()
{
  var c = "; "+document.cookie;

  // tests if persistent cookies are enabled in browser
  document.cookie = 'trk_ctest=1; expires=Sun, 18-Jan-2038 00:00:00 GMT';
  var cok = (document.cookie.indexOf('trk_ctest') != -1) ? '1' : '0';
  document.cookie = 'trk_ctest=; expires=Thu, 01-Jan-1970 00:00:01 GMT';

  if ( (document.referrer.indexOf(location.host) == -1) && (c.indexOf('; trk_done=1') == -1) ) {
    trk_Send('/trk/trk_visit.php?u='+encodeURIComponent(location)+'&r='+encodeURIComponent(document.referrer)+'&c='+cok);
    document.cookie = 'trk_done=1; path=/;';
  }

  if ( trk_uid && (c.indexOf('; trk_uid=1') == -1) ) {
    trk_Send('/trk/trk_uid.php?uid='+trk_uid);
    document.cookie = 'trk_uid=1; path=/;';
  }
}

// must be called when script is first loaded
function trk_GetBase()
{
  var s = document.getElementsByTagName("SCRIPT")
  var u = s[s.length-1].src;
  if ( u.indexOf('://') == -1 ) {
    u = location.href;
  }
  var h = u.match("^.+://[^/?]+");
  return (h) ? h[0] : '';
}

function trk_Send(u)
{
  document.write('<div style="visibility: visible; z-index:100;">');
  document.write('<im');
  document.write('g s'+'rc="'+trk_base+u+'" border=0 width=1 height=1 alt="" />');
  document.write('</div>');
// DEBUG CODE ///////////////////////////////////
//document.write('<HR>'+trk_base+u+'<HR>');
// DEBUG CODE ///////////////////////////////////
}

function trk_Event(type, name, value)
{
  trk_Send('/trk/trk_event.php?n='+encodeURIComponent(name)+'&t='+encodeURIComponent(type)+'&v='+encodeURIComponent(value)+'&u='+encodeURIComponent(location)+'&r='+encodeURIComponent(document.referrer));
}

// trk_uid is set in web page.
var trk_uid;
// must be called on first load
var trk_base = trk_GetBase();
trk_Go();
