/* --------------------------------------------------- */
/* name:    utilities.js                               */
/* purpose: javascript utility functions               */
/* --------------------------------------------------- */

/* --------------------------------------------------- */
/* image rollover functions                            */
/* --------------------------------------------------- */
function imgOn(imgName) {
  if (document.images) {
    document[imgName].src = eval(imgName + "On.src");
  }
}
function imgOff(imgName) {
  if (document.images) {
    document[imgName].src = eval(imgName + "Off.src");
  }
}

/* --------------------------------------------------- */
/* position cursor at form field                       */
/* --------------------------------------------------- */
function throwFocus(focusForm, focusField) {
  theField = eval("document." + focusForm + "." + focusField);
  if (!theField.options && theField.value != "") { 
    theField.select(); 
  }
  theField.focus();
}

/* --------------------------------------------------- */
/* tab to next field when full                         */
/* --------------------------------------------------- */
function autoTab(tabField, tabLength, tabNext) {
  var fieldContents = tabField.value;
  if (fieldContents.length == tabLength) {
    theForm = tabField.form;
    nextField = eval("document." + theForm.name + "." + tabNext);
    nextField.focus();
  }
}

/* --------------------------------------------------- */
/* open new browser window with no controls            */
/* --------------------------------------------------- */
function popWindow(url, width, height, windowName) {
  /* defaults if not passed to function */
  if (!width) { width = 600; }
  if (!height) { height = 450; }
  if (!windowName) { windowName = "AMSpop"; }
  wref = window.open (url, windowName,
        "toolbar=no,width=" + width + ",height=" + height +
        ",directories=no,status=no,scrollbars=no,resizable=no,menubar=no");
  if (navigator.appName == "Netscape" || navigator.appVersion.substring(0,1) == '5') {
    wref.focus();
  }
}

/* --------------------------------------------------- */
/* display current date                                */
/* --------------------------------------------------- */
function currentDate() {
  monthName = new Array("January","February","March","April","May","June",
                        "July","August","September","October","November","December");
  var today = new Date();
  document.write(monthName[today.getMonth()] + " " + today.getDate() + ", " + today.getFullYear());
}

/* --------------------------------------------------- */
/* display current month                               */
/* --------------------------------------------------- */
function currentMonth() {
  monthName = new Array("January","February","March","April","May","June",
                        "July","August","September","October","November","December");
  var today = new Date();
  document.write(monthName[today.getMonth()]);
}

/* --------------------------------------------------- */
/* display current year                                */
/* --------------------------------------------------- */
function currentYear() {
  var today = new Date();
  document.write(today.getFullYear());
}

/* --------------------------------------------------- */
/* display timestamp                                   */
/* --------------------------------------------------- */
function timeStamp() {
  dayName = new Array("SUN","MON","TUE","WED","THU","FRI","SAT");
  var now = new Date();
  var dateTime = dayName[now.getDay()] + " ";
  dateTime += ((now.getMonth() < 9) ? "0"  : "" ) + (now.getMonth() + 1) + "/";
  dateTime += ((now.getDate() < 10)    ? "0"  : "" ) + now.getDate() + "/";
  dateTime += now.getFullYear() + " ";
  dateTime += ((now.getHours() < 10)   ? "0"  : "" ) + now.getHours();
  dateTime += ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
  dateTime += ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
  document.write(dateTime);
}

/* --------------------------------------------------- */
/* format currency                                     */
/* --------------------------------------------------- */
function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num % 100;
    num = Math.floor(num/100).toString();
    if(cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
    return (((sign)?'':'-') + num + '.' + cents);
}

