//Copyright (c) 2008, Omnicognic LLC.
//All rights reserved.
//Written by Conrad Sollitt.
//Software License Agreement (BSD License)
//See full version of InfoFind Web Tools for full license.

//Environment Object
//Note - Browser detection should only be used in very specific situations.
//It's used in this page to determine if the Browser is a known stable browser.
//For example, the animation code can make IE5 crash. If this code doesn't run
//the page still looks nice and has all functionality with the exception of the
//animated slide show. The animation code itself does not contain any browser
//checking. Also, this code does not check for spoofing so in some cases this
//code may think Opera is IE and so on. This code is very forgiving and will allow
//anything to run that is marked as Mozilla/5.0 or later. Basically almost any new
//Broswer will run this code, except for the oldest Browsers.
var Environment = new Object();
Environment.Browser = "";
Environment.BrowserVersion = 0;

//Check for a Known Browser.
Environment.DetermineBrowser = function() {
    var ua = navigator.userAgent;
    var SearchFor = ["MSIE ", "Firefox/", "Chrome/", "Opera/", "Opera ", "Safari/", "Mozilla/"];
    var BrowserName = ["IE", "Firefox", "Chrome", "Opera", "Opera", "Safari", "Mozilla"];
    var n = 0, m = 0, CharCount = 0;
    for (n = 0; n < SearchFor.length; n++) {
        m = ua.indexOf(SearchFor[n]);
        if (m != -1) {
            Environment.Browser = BrowserName[n];
            if (SearchFor[n] == "Safari/") {
                SearchFor[n] = "Version/";
                m = ua.indexOf(SearchFor[n]);
            }
            m = m + SearchFor[n].length + 1;
            CharCount = ua.length - m + 1
            Environment.BrowserVersion = parseFloat(ua.substring(m - 1, m + CharCount - 1));
            return;
        }
    }
}

//Only include tested stable Browsers.
Environment.IsSupported = function() {
    if (Environment.Browser == "IE") {
        if (Environment.BrowserVersion >= 6) {
            return true;
        }
    } else if (Environment.Browser == "Firefox") {
        return true;
    } else if (Environment.Browser == "Opera") {
        if (Environment.BrowserVersion >= 8) {
            return true;
        }
    } else if (Environment.Browser == "Safari") {
        if (Environment.BrowserVersion >= 2) {
            return true;
        }
    } else if (Environment.Browser == "Chrome") {
        return true;
    } else if (Environment.Browser == "Mozilla") {
        if (Environment.BrowserVersion >= 5) {
            return true;
        }
    }
    return false;
}

