// Checks to see if browser supported by NLWIS.
// If not, and ShowAlert, an alert box is displayed using
// the metadata tag "dc.language" to indicate language
function isBrowserSupported(blnShowAlert){
  var blnSupported = false;
  var strAgent = navigator.userAgent.toLowerCase();
  if (strAgent.indexOf('firefox') != -1) {
    if (isVersion(navigator.userAgent,2) >= 1.5){
      blnSupported = true;
    }
  } else if (strAgent.indexOf('msie') != -1){
    if (isVersion(navigator.appVersion,1) >= 6.0) {
      blnSupported = true;
    }
  }

  if (!blnSupported && (blnShowAlert != null && blnShowAlert)){
    var strLang = getMetaValue("dc.language");
    var message = "This application was not tested with your current browser. " +
                  "If you encounter issues working with it, we recommend you use one of " +
                  "the following: Internet Explorer 6.0 or Mozilla Firefox 1.5."
    if (strLang != null && strLang == "fre"){
      message = "Cette application n'a pas été mise à l'essai avec le navigateur " +
                "que vous utilisez. Si vous avez des difficultés à vous en servir, " +
                "nous vous recommandons d'utiliser un des navigateurs suivants : " +
                "Internet Explorer 6.0 ou Mozilla Firefox 1.5.";
    }
    alert(message);
  }
  return blnSupported;
}

// Pulls version out of the passed string.
// Looks for it in different positions if the browser
// is IE (1) vs. Firefox (2) vs. any other browser.
function isVersion(strVersion, intBrowser) {
 if (strVersion == null) {
  return 0.0;
 } else {
  switch(intBrowser){
    case 1: // IE
      strVersion = strVersion.substring(strVersion.indexOf("MSIE ") + 5);
      break;
    case 2: // Firefox
      strVersion = strVersion.substring(strVersion.indexOf("Firefox/") + 8);
      break;
    default: // keep string as passed
      break;
  }

  var strTmp0 = "";
  var strTmp1 = "";
  var strValidChars = "01234567890.";
  var blnStart = false;
  for (var i = 0; i < strVersion.length; i++) {
   strTmp1 = strVersion.substring(i, i + 1);
   if (strValidChars.indexOf(strTmp1) != -1) {
    strTmp0 = strTmp0 + strTmp1;
    blnStart = true;
   } else {
    if (blnStart) {
     break;
    }
   }
  }

  if (strTmp0.length == 0) {
    return 0.0;
  } else {
    return parseFloat(strTmp0);
  }
 }
}
