
// General functions

//**************************************************************************
// Checks if browser is Navigator 3.x (or higher) or MSIE 4.x (or higher)

function browserSupported() {

  var BrowserName = navigator.appName;
  var BrowserRelease = navigator.appVersion;
  var BrowserVersion = parseInt(BrowserRelease.substring(0,1));

  if (((BrowserName == "Netscape") && (BrowserVersion >= 3)) || ((BrowserName == "Microsoft Internet Explorer") && (BrowserVersion >= 4))) {
    return (true);
  } else {
    return (false);
  }
}

//**************************************************************************
// Checks if browser is Navigator 3.x (or higher) or MSIE 3.x (or higher)

function browser2Supported() {
  // Allowed browser: Navigator 3.x (or higher) or MSIE 3.x (or higher)

  var BrowserName = navigator.appName;
  var BrowserRelease = navigator.appVersion;
  var BrowserVersion = parseInt(BrowserRelease.substring(0,1));

  // alert ("BrowserName: " + navigator.appName);
  // alert ("BrowserRelease: " + navigator.appVersion);
  // alert ("BrowserVersion: " + parseInt(navigator.appVersion.substring(0,1)));

  if (((BrowserName == "Netscape") && (BrowserVersion >= 3)) || ((BrowserName == "Microsoft Internet Explorer") && (BrowserVersion >= 3))) {
    return (true);
  } else {
    return (false);
  }
}

//**************************************************************************
// Checks if browser is MSIE 4.x (or higher)

function MSIESupported() {

  var BrowserName = navigator.appName;
  var BrowserRelease = navigator.appVersion;
  var BrowserVersion = parseInt(BrowserRelease.substring(0,1));

  if ((BrowserName == "Microsoft Internet Explorer") && (BrowserVersion >= 4)) {
    return (true);
  } else {
    return (false);
  }
}

//**************************************************************************
// Open a new browser window
//
// params
//  name           window name
//  loc            location to load into window
//  winWidth       window width
//  winHeight      window height
//  hasScrollbars  1 = window has scrollbars
//  hasLocationbar 1 = window has locationbar
//  hasMenubar     1 = window has menubar
//  hasStatus      1 = window has status line
//  isResizable    1 = window is resizable
//  isDependent    1 = window depends on parent window (if parent window will be closed, this window will be closed, too)
// 
// return
//  new window object

function openWin (name, loc, winWidth, winHeight, hasScrollbars, hasLocationbar, hasMenubar, 
                  hasStatus, isResizable, isDependent)
{
  // Calculate centralized left upper window corner
  posHor = (screen.width/2) - (winWidth/2);
  posVer = (screen.height/2) - (winHeight/2);
  params = "width=" + winWidth + ",height=" + winHeight + ",scrollbars=" + hasScrollbars + ",status=" + hasStatus
           + ",locationbar=" + hasLocationbar + ",menubar=" + hasMenubar + ",resizable=" + isResizable
           + ",dependent=" + isDependent;

  if (isMicro) {
    newWin = window.open (loc, name, params);
    newWin.moveTo (posHor, posVer);
  } else {
    // Netscape and other browsers (JavaScript 1.2 compatible)
    newWin = window.open (loc, name, params + ",screenX=" + posHor + ",screenY=" + posVer);
  }
  newWin.focus();

  return;
}

//**************************************************************************
// Protect email addresses against harvesters (if they cannot execute JavaScript)
//
// params
//  strPart1        part #1 of email address
//  strPart2        part #2 of email address
//  strPart3        part #3 of email address
//  strPart4        part #4 of email address
//  strView         Alternate string for viewing
//  strAddParam     Additional parameters for mailto address
// strPart2 and strPart3 will be separated with a @ sign.
// 
// return
//  nothing

function protEM(strPart1, strPart2, strPart3, strPart4, strView, strAddParam) {
  if (strAddParam.length == 0) {
    document.write('<a href="mailto:' + strPart1 + strPart2 + '@' + strPart3 + strPart4 + '">');
  } else {
    document.write('<a href="mailto:' + strPart1 + strPart2 + '@' + strPart3 + strPart4 + '?' + strAddParam + '">');
  }
  if (strView.length == 0) {
    document.write(strPart1 + strPart2 + '@' + strPart3 + strPart4 + '</a>');
  } else {
    document.write(strView + '</a>');
  }
}

// protEMclass is the same as protEM, however you can also specify a class to be used with A HREF
function protEMclass(strPart1, strPart2, strPart3, strPart4, strView, strAddParam, strClass) {
  if (strAddParam.length == 0) {
    document.write('<a href="mailto:' + strPart1 + strPart2 + '@' + strPart3 + strPart4 + '" class="' + strClass + '">');
  } else {
    document.write('<a href="mailto:' + strPart1 + strPart2 + '@' + strPart3 + strPart4 + '?' + strAddParam + '" class="' + strClass + '">');
  }
  if (strView.length == 0) {
    document.write(strPart1 + strPart2 + '@' + strPart3 + strPart4 + '</a>');
  } else {
    document.write(strView + '</a>');
  }
}

//**************************************************************************
// Generic functions

// Do left trimming
function strTrimLeft (strText) {
  while (strText.substr(0, 1) == " ") {
    strText = strText.substr(1, strText.length);
  }
  return (strText);
}

// Do right trimming
function strTrimRight (strText) {
  while (strText.substr((strText.length - 1), 1) == " ") {
    strText = strText.substr(0, strText.length - 1);
  }
  return (strText);
}

// Do right and left trimming
function strTrim (strText) {
  strText = strTrimLeft (strText);
  strText = strTrimRight (strText);
  return (strText);
}


// Check if strText contains a number (integer)
function bCheckInt (strText) {
  for (iCnt = 0; iCnt < strText.length; iCnt++) {
    cText = strText.substr(iCnt, 1);
    if ((cText != "0") && (cText != "1") && (cText != "2") &&
        (cText != "3") && (cText != "4") && (cText != "5") &&
        (cText != "6") && (cText != "7") && (cText != "8") &&
        (cText != "9")) {
        return (false);
    }
  }
  return (true);
}
