var agt            = navigator.userAgent.toLowerCase();
var is_major       = parseInt(navigator.appVersion);
var is_minor       = parseFloat(navigator.appVersion);
var is_nav         = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav2        = (is_nav && (is_major == 2));
var is_nav3        = (is_nav && (is_major == 3));
var is_nav4        = (is_nav && (is_major == 4));
var is_nav4up      = (is_nav && (is_major >= 4));
var is_navonly     = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
var is_nav6        = (is_nav && (is_major == 5));
var is_nav6up      = (is_nav && (is_major >= 5));
var is_gecko       = (agt.indexOf('gecko') != -1);
var is_ie          = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3         = (is_ie && (is_major < 4));
var is_ie4         = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
var is_ie4up       = (is_ie && (is_major >= 4));
var is_ie5         = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5       = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up       = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up     = (is_ie && !is_ie3 && !is_ie4 && !is_ie5);


/*
   openWin('mypage.html','popupwin','width=55,height=55')

   toolbar
   displays the browser buttons (forward, back, home, print, etc) 
   location
   displays the field that shows the URL for the window 
   directories
   displays other web browser directory buttons 
   status
   displays the browser status bar at the bottom 
   menubar
   displays the web browser menu bar 
   resizable
   allows user to change the size of the window 
   scrollbars
   provides scroll bars if the content is larger than the window size 
   width=XX
   specifies the width of the window when opened, in pixels 
   height=YY
   specifies the height of the window when opened, in pixels 
*/
function openWin(url,win,options) {
	var popupwin = window.open(url,win,options);
	popupwin.focus();
}

var timeoutHandle;

function startTimeout() {  // Timeout after 1 hour and close "child" windows
  var winTimeout = 3600000;
  timeoutHandle = setTimeout("window.close()", winTimeout)
}

function resetTimeout() {
  clearTimeout(timeoutHandle);
}

function clearSelect(obj) {
  var objOptions = obj.options;
  for (var i=0; i<objOptions.length; i++)
    objOptions[i].selected = false;
}

function getSearchAsArray() {
  if (is_nav4up || is_ie4up) {
    var results = new Array();
    var input = unescape(location.search.substr(1));
    if (input) {
      var srchArray = input.split("&");
      var tempArray = new Array();
      for (var i=0; i<srchArray.length; i++) {
        tempArray = srchArray[i].split("=");
        results[tempArray[0]] = tempArray[1];
      }
    }
    return results;
  }
}

function showAllProps(obj) {
  var objName = "";
  var result = "";
  var objPropCount = 0;
  for (var i in obj) {
    objPropCount += 1;
  }
  if (objPropCount > 0) {
    objName = obj["name"];
    for (var p in obj) {
      result += objName + "." + p + " = " + obj[p] + "\t";
    }
    alert(result);
  }
}

function _onError(form_object, input_object, object_value, error_message) {
  alert(error_message);
  return false;
}

function _hasValue(obj, obj_type) {
  if (obj_type == "TEXT" || obj_type == "PASSWORD") {
    if (obj.value.length == 0)
      return false;
    else
      return true;
  }
  else if (obj_type == "SELECT") {
    for (i=0; i < obj.length; i++) {
      if (obj.options[i].selected)
        return true;
    }
    return false;  
  }
  else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX") {
    if (obj.checked)
      return true;
    else
      return false;
  }
  else if (obj_type == "RADIO" || obj_type == "CHECKBOX") {
    for (i=0; i < obj.length; i++) {
      if (obj[i].checked)
        return true;
    }
    return false;  
  }
}

function _checkdate(object_value, date_delimiter) {
  // Returns true if value is a date format or is NULL
  // otherwise returns false
  if (object_value.length == 0)
    return true;

  // Returns true if value is a date in the format 
  // mm/dd/yyyy, where "/" is the date delimiter
  isplit = object_value.indexOf(date_delimiter);

  if (isplit == -1 || isplit == object_value.length)
    return false;
  sMonth = object_value.substring(0, isplit);
  isplit = object_value.indexOf(date_delimiter, isplit + 1);

  if (isplit == -1 || (isplit + 1 ) == object_value.length)
    return false;
  sDay = object_value.substring((sMonth.length + 1), isplit);
  sYear = object_value.substring(isplit + 1);

  if (!_checkinteger(sMonth)) // check month
    return false;
  else if (!_checkrange(sMonth, 1, 12)) // check month
    return false;
  else if (!_checkinteger(sYear)) // check year
    return false;
  else if (!_checkrange(sYear, 0, 9999)) // check year
    return false;
  else if (!_checkinteger(sDay)) // check day
    return false;
  else if (!_checkday(sYear, sMonth, sDay)) // check day
    return false;
  else
    return true;
}

function _checkday(checkYear, checkMonth, checkDay) {
  maxDay = 31;
  if (checkMonth == 4 || checkMonth == 6 || checkMonth == 9 || checkMonth == 11)
    maxDay = 30;
  else if (checkMonth == 2) {
    if (checkYear % 4 > 0)
      maxDay =28;
    else if (checkYear % 100 == 0 && checkYear % 400 > 0)
      maxDay = 28;
    else
      maxDay = 29;
  }
  return _checkrange(checkDay, 1, maxDay); // check day
}

function _checkinteger(object_value) {
  // Returns true if value is a number or is NULL
  // otherwise returns false  
  if (object_value.length == 0)
    return true;

  // Returns true if value is an integer defined as
  // having an optional leading + or -.
  // otherwise containing only the characters 0-9.
  var decimal_format = ".";
  var check_char;

  // The first character can be + -  blank or a digit.
  check_char = object_value.indexOf(decimal_format)

  // Was it a decimal?
  if (check_char < 1)
    return _checknumber(object_value);
  else
    return false;
}

function _numberrange(object_value, min_value, max_value) {
  // check minimum
  if (min_value != null) {
    if (object_value < min_value)
      return false;
  }
  // check maximum
  if (max_value != null) {
    if (object_value > max_value)
      return false;
  }
  
  // All tests passed, so...
  return true;
}

function _checknumber(object_value) {
  // Returns true if value is a number or is NULL
  // otherwise returns false  
  if (object_value.length == 0)
    return true;

  // Returns true if value is a number defined as
  // having an optional leading + or -.
  // having at most 1 decimal point.
  // otherwise containing only the characters 0-9.
  var start_format = " .+-0123456789";
  var number_format = " .0123456789";
  var check_char;
  var decimal = false;
  var trailing_blank = false;
  var digits = false;

  // The first character can be + - .  blank or a digit.
  check_char = start_format.indexOf(object_value.charAt(0))

  // Was it a decimal?
  if (check_char == 1) decimal = true;
  else if (check_char < 1)
    return false;
        
  // Remaining characters can be only . or a digit, but only one decimal.
  for (var i = 1; i < object_value.length; i++) {
    check_char = number_format.indexOf(object_value.charAt(i))
    if (check_char < 0)
      return false;
    else if (check_char == 1) {
      if (decimal) // Second decimal.
        return false;
      else
        decimal = true;
    }
    else if (check_char == 0) {
      if (decimal || digits) // ignore leading blanks
        trailing_blank = true;
    }
    else if (trailing_blank)
      return false;
    else
      digits = true;
  }

  // All tests passed, so...
  return true;
}

function _checkrange(object_value, min_value, max_value) {
  // if value is in range then return true else return false
  if (object_value.length == 0)
    return true;

  if (!_checknumber(object_value))
    return false;
  else
    return (_numberrange((eval(object_value)), min_value, max_value));
  
  // All tests passed, so...
  return true;
}

function _checktime(object_value) {
  // Returns true if value is in time format or is NULL
  // otherwise returns false
  if (object_value.length == 0)
    return true;

  // Returns true if value is a date in the mm/dd/yyyy format
  isplit = object_value.indexOf(':');

  if (isplit == -1 || isplit == object_value.length)
    return false;

  sHour = object_value.substring(0, isplit);
  iminute = object_value.indexOf(':', isplit + 1);

  if (iminute == -1 || iminute == object_value.length)
    sMin = object_value.substring((sHour.length + 1));
  else
    sMin = object_value.substring((sHour.length + 1), iminute);

  if (!_checkinteger(sHour)) // check hour
    return false;
  else if (!_checkrange(sHour, 0, 23)) // check hour
    return false;
  if (!_checkinteger(sMin)) // check minutes
    return false;
  else if (!_checkrange(sMin, 0, 59)) // check minutes
    return false;

  // did they specify seconds
  if (iminute != -1) {
    sSec = object_value.substring(iminute + 1);
    if (!_checkinteger(sSec)) // check seconds
      return false;
    else if (!_checkrange(sSec, 0, 59)) // check seconds
      return false;
  }
  
  // All tests passed, so...
  return true;
}

function _checkdollar(object_value) {
  // Returns true if value is a number or is NULL
  // otherwise returns false  
  if (object_value.length == 0)
    return true;

  // Returns true if value is a number defined as
  // having an optional leading + or -.
  // having at most 1 decimal point.
  // otherwise containing only the characters 0-9.
  var start_format = " .+-0123456789$";
  var number_format = " .0123456789";
  var check_char;
  var decimal = false;
  var trailing_blank = false;
  var digits = false;

  // The first character can be + - .  blank or a digit.
  check_char = start_format.indexOf(object_value.charAt(0))

  // Was it a decimal?
  if (check_char == 1) decimal = true;
  else if (check_char < 1)
    return false;

  // Remaining characters can be only . or a digit, but only one decimal.
  for (var i = 1; i < object_value.length; i++) {
    check_char = number_format.indexOf(object_value.charAt(i))
    if (check_char < 0)
      return false;
    else if (check_char == 1) {
      if (decimal) // Second decimal.
        return false;
      else
        decimal = true;
    }
    else if (check_char == 0) {
      if (decimal || digits) // ignore leading blanks
        trailing_blank = true;
    }
    else if (trailing_blank)
      return false;
    else
      digits = true;
  }

  // All tests passed, so...
  return true;
}


function Is () {   
  var agt=navigator.userAgent.toLowerCase();

  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);

  this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1));
  this.nav4up = (this.nav && (this.major >= 4));
  this.nav5up = (this.nav && (this.major >= 5));

  this.ie = (agt.indexOf("msie") != -1);
  this.ie3 = (this.ie && (this.major < 4));
  this.ie4 = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")==-1) );
  this.ie4up = (this.ie  && (this.major >= 4));
  this.ie5 = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
  this.ie5up = (this.ie  && !this.ie3 && !this.ie4);

  this.aol   = (agt.indexOf("aol") != -1);
  this.aol4up  = (this.aol && this.ie4up);

  this.win = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
  this.mac = (agt.indexOf("mac")!=-1);
}

var is;
var isIE3Mac = false;

if ((navigator.appVersion.indexOf("Mac")!=-1) && (navigator.userAgent.indexOf("MSIE")!=-1) && (parseInt(navigator.appVersion)==3)) { isIE3Mac = true; }
else { is = new Is(); }

var browserOK = false;
if (!isIE3Mac && (is.nav4up || is.ie4up)) { browserOK = true; }
var currentSelectedImage = "";

function imgOn(img) {
  if (browserOK) {
    if (img != currentSelectedImage) {
      currentSelectedImage = img;
      var pathString = eval("document." + img + ".src");
      var pathArray = new Array();
      var fileNameArray = new Array();
      var tempString = "";
      pathArray = pathString.split("/");
      fileNameArray = pathArray[pathArray.length-1].split(".");
      for (var i=0; i<pathArray.length-1; i++) { tempString += pathArray[i] + "/"; }
      tempString += fileNameArray[0] + "_dn." + fileNameArray[1];
      eval("document." + img + ".src = '" + tempString + "'");
    }
  }
}

function imgOff(img) {
  if (browserOK) {
    if (img == currentSelectedImage) {
      currentSelectedImage = "";
      var pathString = eval("document." + img + ".src");
      var pathArray = new Array();
      var fileNameArray = new Array();
      var fileNameSubString = "";
      var tempString = "";
      pathArray = pathString.split("/");
      fileNameArray = pathArray[pathArray.length-1].split(".");
      fileNameSubString = fileNameArray[0].substring(0,fileNameArray[0].length-3);
      for (var i=0; i<pathArray.length-1; i++) { tempString += pathArray[i] + "/"; }
      tempString += fileNameSubString + "." + fileNameArray[1];
      eval("document." + img + ".src = '" + tempString + "'");
    }
  }
}

// Added on 04/29/2002
function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

// Added on 11/18/2002

function replace(string,text,by) {
// Replaces text with by in string
    var i = string.indexOf(text);
    if (string.length == 0) return string;
    if ((!i) && (text != string.substring(0,text.length))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+text.length < string.length)
        newstr += replace(string.substring(i+text.length,string.length),text,by);

    return newstr;
}


