﻿var IERegExp=new RegExp("MSIE\\s\\d*\\.\\d*");
var FFRegExp=new RegExp("Firefox/\\d*\\.\\d*");
var OpRegExp=new RegExp("Opera/\\d*\\.\\d*");

var allowedBrowsers=[["MSIE",6,0],["Firefox",2,0],["Opera",9,0]];
//var allowedPlugins=[["flash",8,0],["acrobat",5,0]];
var allowedFlashVersion=8;

function webBrowser() {
    this.isIE=false;
    this.isFF=false;
    this.isOP=false;
    this.isUnknown=false;
    this.hasAx=false;
    this.name="";
    this.hasPlugins=false;
    this.version="";
    this.majorVersion="";
    this.minorVersion="";
    this.isAllowedBrowser=false;
    this.hasAllowedFlash=false;
    this.flashVersion=0;
    if (window.navigator.userAgent) {
        //alert(window.navigator.userAgent);
        var str=IERegExp.exec(window.navigator.userAgent);
        if (str) {
            this.name="MSIE";
            this.isIE=true;
            this.version=str[0].split(" ")[1];
        } else {
            str=FFRegExp.exec(window.navigator.userAgent);
            if (str) {
                this.name="Firefox";
                this.isFF=true;
                this.version=str[0].split("/") [1];
            } else {
                str=OpRegExp.exec(window.navigator.userAgent);
                if (str) {
                    this.name="Opera";
                    this.isOp=true;
                    this.version=str[0].split("/")[1];
                }else {
                    this.isUnknown=true;
                }
            }
        }
        if (this.version.length>0) {
            this.majorVersion=this.version.split(".")[0];
            this.minorVersion=this.version.split(".")[1];
        } 
        if (window.navigator.plugins) { this.hasPlugins=true; }
        if (window.ActiveXObject) {this.hasAx=true;}
     
    } else {
        this.isUnknown=true;
    }
    
    
    for (var b in allowedBrowsers) {
        if (allowedBrowsers[b][0]==this.name) {
            if (parseInt(this.majorVersion)==allowedBrowsers[b][1]) {
                if (parseInt(this.minorVersion)>=allowedBrowsers[b][2]) {
                    this.isAllowedBrowser=true;
                } 
            } else if (parseInt(this.majorVersion)>allowedBrowsers[b][1]) {
                this.isAllowedBrowser=true;
            } 
        }
    }
    
    try {
    
        if (this.hasAx) {
            for (var i=25;i>0;i--) {

                try {
                    var flash=new ActiveXObject("shockwaveflash.shockwaveflash." + i);
                    break;
                }catch (e) {
                    this.flashVersion=i-1;
                }
            }
        }else {
            if (navigator.plugins != null && navigator.plugins.length > 0) {
              
              var flashPlugin = navigator.plugins['Shockwave Flash']; 
              if (typeof flashPlugin == 'object') {
                    for (i=25;i>0;i--) {
                          if (flashPlugin.description.indexOf(i+'.') != -1){ 
                                   this.flashVersion = i;
                          }
                    }
              }
            }  
        }  
    } catch (e) {
        this.flashVersion=0;
    }
    if (this.flashVersion>=allowedFlashVersion) {this.hasAllowedFlash=true};
    
}
      

