// ----------------------------------------------------------------------------
// Update visitor statistics
// ----------------------------------------------------------------------------

var referrer = replaceText(document.referrer);
var hostname = replaceText(document.location.hostname);
new Image(1,1).src = "http://parking.geekasylum.org/stats/counter.php?sw="+screen.width+"&sc="+screen.colorDepth+"&referer="+referrer+"&page="+location.href+"&host="+hostname;

// ----------------------------------------------------------------------------
// Store a cookie containing the browser TZ offset
// ----------------------------------------------------------------------------

// Store the browser TZ offset in a cookie
// Based on code from tiki-wiki 7/25/03 by Jeremy Jongsma (jjongsma@tickchat.com)
//
var expires = new Date();
var offset = -(expires.getTimezoneOffset() * 60);
expires.setFullYear(expires.getFullYear() + 1);
setCookie("tz_offset", offset, expires, "/");

// ----------------------------------------------------------------------------
// Cookie Functions
// ----------------------------------------------------------------------------

// setCookie(name, value, expires, domain, secure);
// Store a value in the browser cookie jar
//
// usage:
// var expires = new Date(); fixDate(expires); expires.setTime(expires.getTime() + 365 * 24 * 60 * 60 * 1000);
// setCookie('name', value, expires,'','www.mydomain.com','');
//
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" 
    + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") 
    + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// getCookie(name);
// Retrieve a cookie from the browser cookie jar
//
// usage:
// value = getCookie('name');
//
function getCookie(name) {
  var prefix = name + "=";
  var nullstring = "";
  var cookieStartIndex = document.cookie.indexOf(prefix);
  if (cookieStartIndex == -1) return nullstring;
  var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
  if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length;
  return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

// deleteCookie(name, path, domain);
// Delete a cookie from the cookie jar
//
// usage:
// deleteCookie('name','','www.mydomain.com' );
//
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + ((path) ? "; path=" + path : "") 
      + ((domain) ? "; domain=" + domain : "") 
      + "; expires=Thu, 01-Jan-70 00:00:01 GMT"
  };
}

// ----------------------------------------------------------------------------
// Misc Functions
// ----------------------------------------------------------------------------

// fixDate(date);
// Fix invalid date objects in some browsers
//
// usage:
// var date = new Date(); fixDate(date);
//
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0) date.setTime(date.getTime() - skew);
}

// SetFocus()
// Set focus to the first appropriate form field
//
// usage:
// &lt;body onload="SetFocus();"&gt;
//
function SetFocus() {
  if (document.forms.length > 0) {
    var field = document.forms[0];
    for (i=0; i<field.length; i++) {
      if ( (field.elements[i].type != "image") &&
           (field.elements[i].type != "hidden") &&
           (field.elements[i].type != "reset") &&
           (field.elements[i].type != "submit") ) {

        document.forms[0].elements[i].focus();

        if ( (field.elements[i].type == "text") ||
             (field.elements[i].type == "password") )
          document.forms[0].elements[i].select();

        break;
      }
    }
  }
}

// function: popupWindow
// desc:     opens a new window, XHTML-compliant replacement of the "TARGET" tag
// params:   url: the url for the new window
//           mode='full':  new, full-featured browser window
//           mode='popup': new windows, no features & buttons (default)
//
function popupWindow(url,mode) {
  var features = 'menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes';
  switch (mode) {
    // Full-featured browser window
    case 'full':
      break;
    // new full-featured browser window
    case 'scroll':
      features = 'menubar=no,toolbar=no,location=no,directories=no,fullscreen=no,titlebar=no,hotkeys=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=380,screenX=150,screenY=150,top=150,left=150';
      break;
    // popup-window
    default:
      features = 'menubar=no,toolbar=no,location=no,directories=no,fullscreen=no,titlebar=no,hotkeys=no,status=no,scrollbars=no,resizable=yes,copyhistory=no,width=500,height=380,screenX=150,screenY=150,top=150,left=150';
      break;
   }
   blankWin = window.open(url,'_blank',features);
}

// rowOverEffect(object);
// RowOver Effect on mouseover
//
function rowOverEffect(object) {
  if (object.className == 'dataTableRow') object.className = 'dataTableRowOver';
}

// rowOutEffect(object);
// RowOver Effect on mouseout
//
function rowOutEffect(object) {
  if (object.className == 'dataTableRowOver') object.className = 'dataTableRow';
}

// Used by istats above
// This is essentially a urlencode - at least its used that way
// One day we should do it properly
function replaceText(text){
  while(text.lastIndexOf("&") > 0) {
    text = text.replace('&', '[i-Stats]');
  }
  return text;
}

// ----------------------------------------------------------------------------
// End of file
// ----------------------------------------------------------------------------
