

var FD = {

	version: "1.0",

	description: "Javascript tool for feature detection for the Open English Platform.  It checks for the correct version of java, pdf reader, flash and browser.",
	
	/*
	*  Return 0 if does not have the feature, 1 if has it and it's compliant, and 2 if has it but not compliant or can't tell
	*/
	
	hasJavaWS: function() {

	    var compliancy = 0;
	    
	    var browserName=navigator.userAgent; 
	    var fullVersion  = ''+parseFloat(navigator.appVersion); 
	        
	    function getInternetExplorerVersion()

	    {
	      var rv = -1; 
	      if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ 
	        rv =new Number(RegExp.$1) ;
	      }
	      return rv;
	      
	    }
	    
	    function navigatorSupportJavaDetection () {
	      var msieVersion = getInternetExplorerVersion();
	      if ( (/Opera/.test(navigator.userAgent))   || 
	           (/Firefox/.test(navigator.userAgent)) || 
	           (msieVersion >= 3.0 && msieVersion != 4.0) || 
	           (/Chrome/.test(navigator.userAgent)) ||
	           (/Safari/.test(navigator.userAgent) && fullVersion >= 1.2 ) ||
	           (/Netscape/.test(navigator.userAgent) && fullVersion >= 4 )){ 
	        return true;
	      } else {
	        return false;
	      }
	    } 
	    
	    
	    if (navigatorSupportJavaDetection()) {
	      if ( navigator.javaEnabled()) {
	        var versions = deployJava.getJREs();
	        if (versions.length == 0) {
	          compliancy = 0;
	        } else {
	          var maximo=versions[0];
	          for (var j=1;j<versions.length;j++) {
	            if(versions[j]<maximo){
	              maximo=Math.max(maximo,a[j]);
	            }
	          }
	          if (maximo.substring(0, 3) >= 1.6) {
	            compliancy =1;
	          } else {
	            compliancy = 2;
	          }
	        }
	      } else {
	        
	        compliancy = 0;
	      }
	    } else {
	      compliancy = 2;
	    }
	    
	    return compliancy;
	},
	
	hasPDFPlugin: function() {
		var isPdfInstalled = false;
		var Pdfversion = null;
		if (window.ActiveXObject) {  //Rutina para IE
		    var Pdfcontrol = null;
		    try {
		        // AcroPDF.PDF is used by version 7 and later
		        Pdfcontrol = new ActiveXObject('AcroPDF.PDF');
		    } catch (e) {
		        // Do nothing
		    }
		    if (!Pdfcontrol) {
		        try {
		            // PDF.PdfCtrl is used by version 6 and earlier
		            Pdfcontrol = new ActiveXObject('PDF.PdfCtrl');
		        } catch (e) {
		            //return;
		        }
		    }
		    if (Pdfcontrol) {
		        isPdfInstalled = true;
/*		        Pdfversion = Pdfcontrol.GetVersions().split(',');
		        Pdfversion = Pdfversion[0].split('=');
		        Pdfversion = parseFloat(Pdfversion[1]);
*/		    }
		} else { //Rutina para otros
			var num_of_plugins = navigator.plugins.length;
			
			for (var i=0; i < num_of_plugins; i++) {
				var list_number=i+1;
				if (navigator.plugins[i].name.indexOf("Acrobat") > -1 || navigator.plugins[i].name.indexOf("PDF") > -1 || navigator.plugins[i].name.indexOf("Foxit Reader") > -1){
					isPdfInstalled = true;
					break;
				};
			}

		}

		var compliancy = 2;
		if (isPdfInstalled) compliancy = 1
		
		return compliancy;
	
	},
	
	hasFlash: function() {
		var compliancy = 0;

		var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
		var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
		var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

		function ControlVersion()
		{
			var version;
			var axo;
			var e;
		
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.10");
				version = axo.GetVariable("$version");
			} catch (e) {
			}
		
			if (!version)
			{
				try {
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.9");
					axo.AllowScriptAccess = "always";
					version = axo.GetVariable("$version");
		
				} catch (e) {
					version = -1;
				}
			}
		
			return version;
		}
		function GetSwfVer(){
			// NS/Opera version >= 3 check for Flash plugin in plugin array
			var flashVer = -1;
			
			if (navigator.plugins != null && navigator.plugins.length > 0) {
				if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
					var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
					var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
					var descArray = flashDescription.split(" ");
					var tempArrayMajor = descArray[2].split(".");			
					var versionMajor = tempArrayMajor[0];
					var versionMinor = tempArrayMajor[1];
					var versionRevision = descArray[3];
					if (versionRevision == "") {
						versionRevision = descArray[4];
					}
					if (versionRevision[0] == "d") {
						versionRevision = versionRevision.substring(1);
					} else if (versionRevision[0] == "r") {
						versionRevision = versionRevision.substring(1);
						if (versionRevision.indexOf("d") > 0) {
							versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
						}
					}
					var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		//			alert("flashVer="+flashVer);
				}
			}
			// MSN/WebTV 2.6 supports Flash 4
			else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
			// WebTV 2.5 supports Flash 3
			else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
			// older WebTV supports Flash 2
			else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
			else if ( isIE && isWin && !isOpera ) {
				flashVer = ControlVersion();
			}	
			return flashVer;
		}


		function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
		{
			versionStr = GetSwfVer();
			if (versionStr == -1 ) {
				return false;
			} else if (versionStr != 0) {
				if(isIE && isWin && !isOpera) {
					// Given "WIN 2,0,0,11"
					tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
					tempString        = tempArray[1];			// "2,0,0,11"
					versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
				} else {
					versionArray      = versionStr.split(".");
					
				}
				var versionMajor      = versionArray[0];
				var versionMinor      = versionArray[1];
				var versionRevision   = versionArray[2];
		
		        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
				if (versionMajor > parseFloat(reqMajorVer)) {
					return true;
				} else if (versionMajor == parseFloat(reqMajorVer)) {
					if (versionMinor > parseFloat(reqMinorVer))
						return true;
					else if (versionMinor == parseFloat(reqMinorVer)) {
						if (versionRevision >= parseFloat(reqRevision))
							return true;
					}
				}
				return false;
			}
		}


		if (DetectFlashVer(10, 0, 0)) compliancy = 1
		else if (DetectFlashVer(9, 0, 0)) compliancy = 2
		
		return compliancy;
	},
	
	hasSupportedBrowser: function() {
		var navegadorName = navigator.appCodeName;
		var navegadorUA = navigator.userAgent;

		function getInternetExplorerVersion()
		// Returns the version of Internet Explorer or a -1
		// (indicating the use of another browser).
		{
		  var rv = -1; // Return value assumes failure.
		  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
			  rv =new Number(RegExp.$1) // capture x.x portion and store as a number
		  }
		  return rv;
		  
		}
		
		function getFirefoxVersion () {
			var rv = -1;
			if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
				 rv = new Number(RegExp.$1) // capture x.x portion and store as a number
			}
			return rv;
			
		}
		
		var IEVersion = getInternetExplorerVersion();
		var firefoxVersion =  getFirefoxVersion();
		
		function esOpera(){
			return (navegadorUA.indexOf("Opera") > -1)
		}
		function esChrome(){
			return (navegadorUA.indexOf("Chrome") > -1)
		}
		function esSafari(){
			return (navegadorUA.indexOf("Safari") > -1 && navegadorUA.indexOf("Chrome") == -1)
		}

		function esKonqueror(){
			return (navegadorUA.indexOf("Konqueror") > -1)
		}
		
		function navegadorOk(){
			return ( firefoxVersion>=3.0 || IEVersion>=7.0 ||  esOpera() || esChrome() || esSafari())
		}
		
		function navegadorFuncional(){
			return (!navegadorOk() && (IEVersion < 6.0 ||  IEVersion >= 7.0)  && (firefoxVersion != -1  || esKonqueror()))
		}
		
		function navegadorNoSoportado(){
			return ( IEVersion < 7.0 && IEVersion!= -1 ) || !navegadorOk();
		}

		var compliancy = -1;
	
		if (navegadorOk()) compliancy = 1;
		else if (navegadorFuncional()) compliancy = 2
		else if (navegadorNoSoportado()) compliancy = 0;
		else compliancy = 2; 
	
		return compliancy;
	}
}
