// Copyright 2003-2008 by The Software Interface

var usrAgent = navigator.userAgent.toLowerCase();
var usrMajor = parseInt(navigator.appVersion);
var usrMinor = parseFloat(navigator.appVersion);

var isIE     = ((usrAgent.indexOf('msie') != -1) && (usrAgent.indexOf('opera') == -1));
var isFF     = (usrAgent.indexOf('firefox') != -1);
var isOpera  = (usrAgent.indexOf('opera') != -1);
var isGecko  = (usrAgent.indexOf('gecko') != -1);
var isSafari = (usrAgent.indexOf('safari') != -1);

function isArray(obj) {
  return obj && typeof obj == 'object' && obj.constructor == Array;
}
function isBoolean(obj) {
  return typeof obj == 'boolean';
}
function isFunction(obj) {
  return typeof obj == 'function';
}
function isNumber(obj) {
  return typeof obj == 'number'; // && isFinite(obj);
}
function isString(obj) {
  return typeof obj == 'string';
}
function isObject(obj) {
  return obj && (typeof obj == 'object' || typeof obj == 'function');
}
function isUndefined(obj) {
  return typeof obj == 'undefined';
} 
function isEmpty(obj) {
  var i, v;
  if (isObject(obj)) {
    for (i in obj) {
      v = obj[i];
      if (isUndefined(v) && isFunction(v)) {
        return false;
      }
    }
  }
  else if (isString(obj)) {
    return obj.length == 0;
  }
  return true;
}

function basename(url) {
  return url.replace(/^.*\//,'');
}
function dirname(url) {
  return url.match(/^.*(?=\/)/);
}

function GetFunctionName(fn) {
  var fname = /\W*function\s+([\w\$]+)\(/.exec(fn);
  return fname ? fname[1] : '<no name>';
}
function DumpProps(obj,name,like) {
  if (arguments.length < 3) like = '';
  var i=0, props = new Array();
  for (var o in obj) {
    if (like && o.toLowerCase().indexOf(like) == -1) continue;
    props[i++] = o;
  }
  var str = props.sort().join(', ');
  if (name) str = name+': '+str;
  alert(str);
}

function GetPos(obj) {
  //if ( document.layers ) { // this is Netscape 4.?
  //  return { x:obj.x, y:obj.y };
  var res = { x:0, y:0 };       // IE or DOM browsers
  while ( obj ) {               // iteration ensures no stack overflow
    res.x += parseInt(obj.offsetLeft);  // parseInt ignores denominator
    res.y += parseInt(obj.offsetTop);
    obj = obj.offsetParent;
  }
  return res;
}
// http://hartshorne.ca/2006/01/23/javascript_cursor_position/
function GetCursorPos(e) {
 if (!e) e = window.event;
 var cursor = {x:0, y:0};
 if (e.pageX || e.pageY) {
 cursor.x = e.pageX;
 cursor.y = e.pageY;
 }
 else {
 var d = document.documentElement;
 var b = document.body;
 cursor.x = e.clientX + (d.scrollLeft || b.scrollLeft) - (d.clientLeft || 0);
 cursor.y = e.clientY + (d.scrollTop  || b.scrollTop ) - (d.clientTop  || 0);
 }
 return cursor;
}

function TodaysDate() {
  var months = "January February March April May June July August September October November December".split(' ');
  var t=new Date();
  var m=months[t.getMonth()];
  var d=t.getDate();
  var y=t.getYear();
  if (y < 1000) y += 1900;
  return m+' '+d+', '+y;
}


// Cookies

function SetCookie(name,value) {
  // 8-6-06: For now, clear default path cookie, if present
  // 8-6-06: Also, IE6 keeps the previous value around, until IE exit
  document.cookie = name + "=; expires=01-Jan-70 00:00:01 GMT";

  var expires = new Date();
  var year = expires.getFullYear();
  expires.setFullYear(year+1);
  document.cookie = name + "=" + value +
                    "; expires=" + expires.toGMTString() +
                    "; path=/"; // + (path != '' ? path : '/');
  //alert(DumpCookies());
}
function GetCookie(name) {
  //alert(DumpCookies());
  var value  = null;
  var cookies = document.cookie.split(';');
  var prefix = name + '=';
  for (i = 0; i < cookies.length; i++) {
    var cookie = cookies[i];
    if (cookie.charAt(0) == ' ')
      cookie = cookie.substring(1,cookie.length);
    if ((index = cookie.indexOf(prefix)) == 0) {
      value = cookie.substring(index+prefix.length);
      // 8-6-06: ignore the old deleted value
      //if (value != '') break;
    }
  }
  return value;
}
function DeleteCookie(name) {
  document.cookie = name + "=; expires=01-Jan-70 00:00:01 GMT; path=/";
  // 8-6-06: For now, clear default path cookie, too
  document.cookie = name + "=; expires=01-Jan-70 00:00:01 GMT";
}
function DumpCookies() {
  var result  = document.cookie;
  var cookies = document.cookie.split(';');
  for (i = 0; i < cookies.length; i++) {
    var cookie = cookies[i];
    if (cookie.charAt(0) == ' ')
      cookie = cookie.substring(1,cookie.length);
    result += "\n"+i+": "+cookie;
  }
  return result;
}
