var isNav4,
    isIE4,
    isIE5,
    isIE6,
    isNav6;


var range = "";
var styleObj = "";
var browserName = navigator.appName;
var browserVersion = getBrowserVersion(navigator.appVersion);
var debugBrowserAPI = false;

if(navigator.appVersion.charAt(0) == "4"){
   if(navigator.appName == "Netscape"){
      isNav4 = true;
      insideWindowWidth = window.innerWidth;
   } else {
      isIE4 = true;
      range = "all.";
      styleObj = ".style";
   }
} else {
   range = "all.";
   styleObj = ".style";
}

var browserName = navigator.appName;
var browserVersion = getBrowserVersion(navigator.appVersion);


// Get browser version
function getBrowserVersion(appVersion){
  startIndex = (appVersion.indexOf("MSIE") > 0) ? appVersion.indexOf("MSIE"): 0;
  version = appVersion.substring(startIndex, appVersion.indexOf(";", startIndex));

  if(browserName == "Microsoft Internet Explorer"){
    version = version.substring(version.indexOf(" ") + 1, version.indexOf(" ") + 2);
    return version;
  }
}

// compare browser version
function compareBrowserVersion(operator, version){
  if(debugBrowserAPI) alert("BROWSERAPI.js: compareBrowserVersion(): beginning.");
  var returnValue = null;

  if(operator == "<"){
    returnValue = (this.version < version)? true : false;
  } else if(operator == "<="){
    returnValue = (this.version <= version)? true : false;
  } else if(operator == "=="){
    returnValue =(this.version == version)? true : false;
  } else if(operator == ">="){
    returnValue = (this.version >= version)? true : false;
  } else if(operator == ">"){
    returnValue = (this.version > version)? true : false;
  }

  if(debugBrowserAPI) alert("BROWSERAPI.js: compareBrowserVersion(): returnValue: " + returnValue);

  return returnValue;
}

// checks to see if the clientBrowser is the same as browserName1 or browserName2
// and the version are the same as version
function isBrowserCompliant2(browserName1, browserName2, operator, version){
  if(debugBrowserAPI) alert("compareBrowserVersion2: begining");
  if(this.name == browserName1 || this.name == browserName2){
    if(debugBrowserAPI) alert("compareBrowserVersion: " + compareBrowserVersion(operator, version));
    return compareBrowserVersion(operator, version);
  }
}

// checks to see if the clientBrowser is the same as browserName1
// and the version are the same as version

function isBrowserCompliant1(browserName1, operator, version){
  if(this.name == browserName1){
    if(debugBrowserAPI) alert("compareBrowserVersion: " + compareBrowserVersion(operator, version));
    return compareBrowserVersion(operator, version);
  }
}

// set the client browser shortname from the browser fullname
function setBrowserStatus(){
   if(this.version.charAt(0) == "4"){
      if(this.name == "Netscape"){
         this.browserShortName = "Nav";
      } else if(this.version.indexOf("MSIE") != -1){
         this.browserShortName = "IE";
      }
   }
}


// Browser constructor
function Browser(name, version){
  this.name = name;
  this.version = version;
  this.browserShortName = null;


  this.setBrowserStatus = setBrowserStatus;
  this.isBrowserCompliant1 = isBrowserCompliant1;
  this.isBrowserCompliant2 = isBrowserCompliant2;
  this.compareBrowserVersion = compareBrowserVersion;
}

var clientBrowser = new Browser(browserName, browserVersion);


