// Browser typing and cross-browser declarations here

var NS4 = (document.layers) ? 1 : 0;
var IE4 = (document.all) ? 1 : 0;
var docObj = (document.all) ? "document.all." : "document.";

// Field validation functions

function isEmpty(str) {
   return ((str == null) || (str.length == 0) || (str == " "))
   }

function isNumeric(str) {
   return (str.search(/^\s*\d+\s*$/) != -1);
   }

function isAlphanumeric(str) {
   return (str.search(/^\s*\w+\s*$/) != -1);
   }

function isZip(str) {
   return (str.search(/^\d{5}(-\d{4})?$/) != -1);
   }

function isDollarAmt(str) {
   return (str.search(/^\$?(\d{1,3}(,)?)*\d{1,3}(\.\d{2})?$/) != -1);
   }

function isEmail(string) {
   return (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1);
   }

function isPhone(string) {
   return (string.search(/^\(?(\d{3})?\)?\s?\d{3}\-\d{4}$/) != -1);
   }

// Date and time utilities

function getCurrentDateStr() {
   // since this is javascript, running in the browser, it shows the local date of the browser
   var dayName = new Array ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
   var monName = new Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
   var now = new Date;
   // browsers handle the Javascript getYear function differently.
   var year = (now.getYear() < 1900) ? now.getYear() + 1900 : now.getYear();
   // and we use non-breaking spaces, since this is for HTML display
   return (monName[now.getMonth()] + "&nbsp;" + now.getDate() + "&nbsp;" + year);
   }

function getCurrentTimeStr() {
   // since this is javascript, running in the browser, it shows the local time of the browser
   var now = new Date;
   var theHour = now.getHours();
   var theMinutes = now.getMinutes();
   var meridian = (theHour > 11) ? "PM" : "AM";

   if (theHour == 0) theHour = 12;
   if (theHour > 12) theHour = theHour - 12;
   if (theHour < 10) theHour = "0" + theHour;
   if (theMinutes < 10) theMinutes = "0" + theMinutes;

   // we don't display the seconds, for now
   return  (theHour + ":" + theMinutes  + " " + meridian);
   }

function getCurrentDateAndTimeStr() {
   return (getCurrentDateStr() + ", " + getCurrentTimeStr());
   }

// Text processing

function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
  }
String.prototype.trim = trimString;

function splitStr(str, splitAt, replaceWith) {
   newStr = ""
   strArray = str.split(splitAt);
   for (var i=0; i < strArray.length; i++) {
     newStr += strArray[i];
     newStr +=  replaceWith;
     }
   return newStr;
   }

// Misc functions

function submitOnEnter(myfield, e) {
   var keycode;
   if (window.event)
      keycode = window.event.keyCode;
   else if (e)
      keycode = e.which;
   else
      return true;
   if (keycode == 13) {
      myfield.form.submit();
      return false;
      }
   else
      return true;
   }

function displayHelpWin(url) {
  if (document.layers)
    helpWin = window.open(url, 'helpWin', 'width=350,height=400,resizable=yes,scrollbars=yes,toolbar=no,screenX=0,screenY=0');
  else
    helpWin = window.open(url, 'helpWin', 'width=350,height=400,resizable=yes,scrollbars=yes,toolbar=no,top=0,left=0');
  helpWin.focus();
  }

function displayDtdWin(url) {
  if (document.layers)
    dtdWin = window.open(url, 'dtdWin', 'width=350,height=400,resizable=yes,scrollbars=yes,toolbar=no,screenX=0,screenY=0');
  else
    dtdWin = window.open(url, 'dtdWin', 'width=350,height=400,resizable=yes,scrollbars=yes,toolbar=no,top=0,left=0');
  dtdWin.focus();
  }
