//
// Functions for checking browser versions, etc.
//

/*
 * Check if the browser is one of the supported ones
 * returns true If the browser is supported
 */
function isBrowserSupported()
{
  return (isNetscape(7) || isExplorer(6) || isFirefox(1) || isSafari(1));
}

/*
 * Check if the browser is Netscape and what version
 * v Major version to check for - may be empty
 * returns true If it is Netscape and version is equal or greater
 */
function isNetscape(v)
{
  browserOk = -1 != navigator.userAgent.indexOf("Netscape");
  versionOk = true;
  if (browserOk && v != null)
  {
    verIdx = navigator.userAgent.indexOf("Netscape/");
    verStr = navigator.userAgent.substring(verIdx + 9, verIdx + 11);
	major = parseInt(verStr);
	versionOk = major >= v;
  }
  return browserOk && versionOk;
}

/*
 * Check if the browser is Microsoft Explorer and what version
 * v Major version to check for - may be empty
 * returns true If it is Explorer and version is equal or greater
 */
function isExplorer(v)
{
  browserOk = -1 != navigator.userAgent.indexOf("MSIE");
  versionOk = true;
  if (browserOk && v != null)
  {
    verIdx = navigator.userAgent.indexOf("MSIE");
    verStr = navigator.userAgent.substring(verIdx + 5, verIdx + 7);
    major = parseInt(verStr);
    versionOk = major >= v;
  }
  return browserOk && versionOk;
}

/*
 * Check if the browser is Firefox and what version
 * v Major version to check for - may be empty
 * returns true If it is Firefox and version is equal or greater
 */
function isFirefox(v)
{
  browserOk = -1 != navigator.userAgent.indexOf("Firefox");
  versionOk = true;
  if (browserOk && v != null)
  {
    verIdx = navigator.userAgent.indexOf("Firefox/");
    verStr = navigator.userAgent.substring(verIdx + 8, verIdx + 10);
	major = parseInt(verStr);
	versionOk = major >= v;
  }
  return browserOk && versionOk;
}

/*
 * Check if the browser is Safari and what version
 * v Major version to check for - may be empty
 * returns true If it is Safari and version is equal or greater
 */
function isSafari(v)
{
  browserOk = -1 != navigator.userAgent.indexOf("Safari");
  versionOk = true;
  if (browserOk && v != null)
  {
    verIdx = navigator.userAgent.indexOf("Version/");
    verStr = navigator.userAgent.substring(verIdx + 8, verIdx + 10);
	major = parseInt(verStr);
	versionOk = major >= v;
  }
  return browserOk && versionOk;
}

function closeWindow() {
  var browserName=navigator.appName;
  if (isNetscape(7) || isFirefox(1)) {
    window.open('','_parent','');
    window.close();
  }
  else if (isExplorer(6)) {
    window.opener = self;
    window.close();
  }
}

function getBrowserSettings() {
        // Create an array to hold each of the browser's items.
        var tempArr = new Array();

        // Loop over each item in the browser's navigator object.
        for (var name in navigator) {
            var value = navigator[name];
            /*
            If the current value is a string or Boolean object, add it to the
            array, otherwise ignore the item.
            */
            switch (typeof(value)) {
                case "string":
                case "boolean":
                    /*
                    Create a temporary string which will be added to the array.
                    Make sure that we URL-encode the values using JavaScript's
                    escape() function.
                    */
                    var tempStr = "navigator." + name + "=" + escape(value);
                    // Push the URL-encoded name/value pair onto the array.
                    tempArr.push(tempStr);
                    break;
            }
        }
        // Loop over each item in the browser's screen object.
        for (var name in screen) {
            var value = screen[name];
            /*
            If the current value is a number, add it to the array, otherwise
            ignore the item.
            */
            switch (typeof(value)) {
                case "number":
                    var tempStr = "screen." + name + "=" + escape(value);
                    tempArr.push(tempStr);
                    break;
            }
        }
        // Return the array as a URL-encoded string of name-value pairs.
        return tempArr.join("&");
}
