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 esIE= "false";
		var javawsInstalled = 0;
		
		if (navigator.mimeTypes && navigator.mimeTypes.length) {
			var coso = navigator.mimeTypes['application/x-java-jnlp-file'];
			if (coso) javawsInstalled = 1;
		} else {
			esIE = "true";
			var version;
		
			try {
				axo = new ActiveXObject("JavaWebStart.isInstalled");
				javawsInstalled = 1;
			} catch (e) {
			}
		}
		

		var compliancy = 0;
		if (javawsInstalled === 1) compliancy = 1
		
		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 esIe6(){
			return (navegadorUA.indexOf("MSIE 6") > -1)
		}
		function esFirefox3(){
			return (navegadorUA.indexOf("Firefox/3") > -1)
		}
		function esFirefox(){
			return (navegadorUA.indexOf("Firefox") > -1 || navegadorUA.indexOf("iceweasel") > -1)
		}
		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 esIe7(){
			return (navegadorUA.indexOf("MSIE 7") > -1)
		}
		function esIe8(){
			return (navegadorUA.indexOf("MSIE 8") > -1)
		}
		function esKonqueror(){
			return (navegadorUA.indexOf("Konqueror") > -1)
		}
		
		function navegadorOk(){
			return (!esIe6() && (esFirefox3() || esOpera() || esChrome() || esSafari() || esIe7() || esIe8()))
		}
		
		function navegadorFuncional(){
			return (!navegadorOk() && !esIe6() && (esFirefox() || esKonqueror()))
		}
		
		function navegadorNoSoportado(){
			return esIe6() || !navegadorOk();
		}

		var compliancy = -1;
	
		if (navegadorOk()) compliancy = 1;
		else if (navegadorFuncional()) compliancy = 2
		else if (navegadorNoSoportado()) compliancy = 0;
		else compliancy = 2; 
	
		return compliancy;
	}
}