//------- Gather plugin data and set a cookie to store them

var flash = { installed: false, version: false };
//var windowsmedia = { installed: false, version: false };
//var quicktime = { installed: false, version: false };
//var acrobat = { installed: false, version: false };
//var java = { installed: false, version: false };
//var realplayer = { installed: false, version: false };





//Ajax Code for writing the Plugin data
function pluginGetXmlHttpObject()
{
	xmlHttp=null;
// code for Mozilla, etc.
	if (window.XMLHttpRequest)
  	{
  		xmlHttp=new XMLHttpRequest();
  	}
// code for IE
	else if (window.ActiveXObject)
  	{
  		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	return xmlHttp;
}



function pluginWriteToDB() {
	xmlHttp = pluginGetXmlHttpObject();	
	if (xmlHttp!=null)
	  	{
  			xmlHttp.open("POST","/cmsadmin/pluginUpdate",true);
  			xmlHttp.send(null);
  	  	}
	else
  		{
  			//alert("Your browser does not support XMLHTTP.");
  		}
}







function gatherPluginData() {
	var cookieName="pluginData";
	var cookieExpire="Sun, 24-Apr-2033 00:00:00 GMT";
	var separator="&";
	
	var windowWidth = 0;
	var windowHeight = 0;
	
	//some processing for window height and width
	
	if (window.innerWidth) {
		windowWidth = window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		windowWidth = document.documentElement.clientWidth;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
	}
		
	if (window.innerHeight) {
		windowHeight = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowHeight = document.body.clientHeight;
	}
	
	if ( navigator.plugins && navigator.plugins.length > 0 ) {
		detectPluginVersions();
	} else if ( window.ActiveXObject ) {
		detectAXVersions();
	}
	
	cookieValue = "cookieEnabled=" + navigator.cookieEnabled +
		separator + "colorDepth=" + screen.colorDepth +
		separator + "screenHeight=" + screen.height +
		separator + "screenWidth=" + screen.width +
		separator + "windowHeight=" + windowHeight +
		separator + "windowWidth=" + windowWidth +
		separator + "flash=" + flash.installed +
		separator + "flashVer=" + ( flash.version ? flash.version : '0.0' );
		//separator + "windowsMedia=" + windowsmedia.installed +
		//separator + "windowsMediaVer=" + ( windowsmedia.version ? windowsmedia.version : '0.0' ) +
		//separator + "quicktime=" + quicktime.installed +
		//separator + "quicktimeVer=" + ( quicktime.version ? quicktime.version : '0.0' ) +
		//separator + "acrobat=" + acrobat.installed +
		//separator + "acrobatVer=" + ( acrobat.version ? acrobat.version : '0.0' ) +
		//separator + "java=" + java.installed +
		//separator + "javaVer=" + ( java.version ? java.version : '0.0' ) +
		//separator + "realPlayer=" + realplayer.installed +
		//separator + "realPlayerVer=" + (realplayer.version ? realplayer.version : '0.0' );
	
	document.cookie = cookieName + '=' + cookieValue + ';expires=' + cookieExpire + ';path=/';
}


function detectPluginVersions() {
	
	/*
	if ( window.GeckoActiveXObject ) {
		// Try to get windowsmedia this way first
		var e;
		var control = null;
		try {
			control = new GeckoActiveXObject('WMPlayer.OCX.7');
			if (control)
			{
				windowsmedia.installed = true;

				// A weird bug in the Gecko ActiveX plug-in may return undefined
				// at the first call, but the correct value on the second.
				parseFloat(control.versionInfo);
				windowsmedia.version=parseFloat(control.versionInfo);
				
				if ( windowsmedia.version.toString().length < 3 ) {
					windowsmedia.version+='.0';
				}
			}
		} catch(e) {
		}
	}
	*/
	
	for ( i=0; i<navigator.plugins.length; i++ ) {
		pluginName = navigator.plugins[i].name.toLowerCase();
		if (!flash.version && pluginName.indexOf('shockwave flash') != -1) {
			flash.installed = true;
			descArray = navigator.plugins[i].description.split(' ');
			versionArray = descArray[2].split(".");
			if ( descArray[3] != "" ) {
				revision = descArray[3].split("r")[1];
			} else {
 				revision = descArray[4].split("r")[1];
			}
			flash.version = versionArray[0]+"."+versionArray[1]+( (revision > 0) ? '.'+revision : '' );
			continue;
		}
		/*
		if (!windowsmedia.version && pluginName.indexOf('windows media') != -1) {
			windowsmedia.installed = true;
			continue;
		}
		if (!quicktime.version && pluginName.indexOf('quicktime plug-in') != -1) {
			quicktime.installed = true;
			quicktime.version = pluginName.split(' ')[2];
			continue;
		}
		if (!acrobat.version && pluginName.indexOf('adobe acrobat') != -1) {
			acrobat.installed = true;
			acrobat.version = parseVersion( navigator.plugins[i].description );
			continue;
		}
		if (!java.version && pluginName.indexOf('java plug') != -1) {
			java.installed = true;
			java.version = parseVersion( navigator.plugins[i].description );
			continue;
		}
		if (!realplayer.version && ((pluginName.indexOf('realplayer') != -1) ||
		    (pluginName.indexOf('realone') != -1) || (pluginName.indexOf('realmedia') != -1 ))) {
			realplayer.installed = true;
			realplayer.version = parseVersion( navigator.plugins[i].description );
		}
		*/
	}
}

/*
function parseVersion( desc ) {
	descArray = desc.split(' ');
	for (j=0; j < descArray.length; j++) {
		if((descArray[j].charAt(0) >= 0) && (descArray[j].charAt(0) <= 9)){
			return descArray[j];
		}
	}
	return false;
}
*/

function detectAXVersions() {
	var axo;
	var e;

	try {
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		flash.installed = true;
		flash.version = axo.GetVariable("$version");
	} catch (e) {
	}
	if (!flash.version)	{
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			flash.installed = true;
									
			// careful, GetVariable("$version") crashes for versions 6.0.22 through 6.0.29
			// throws if AllowScriptAccess does not exist (introduced in 6.0r47)		
			flash.version = "WIN 6,0,21,0";
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			flash.version = axo.GetVariable("$version");

		} catch (e) {
		}
	}
	if (!flash.version) {
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			flash.installed = true;
			flash.version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	
	/*
	try {
		axo = new ActiveXObject('WMPlayer.OCX.7');
		windowsmedia.installed=true;
		windowsmedia.version=parseFloat(axo.versionInfo);
		if (windowsmedia.version.toString().length < 3) {
			windowsmedia.version+='.0';
		}
	} catch(e) {
	}

	try {
		axo = new ActiveXObject('QuickTimeCheckObject.QuickTimeCheck.1');
		quicktime.installed = axo.IsQuickTimeAvailable(0);
		quicktime.version = parseInt(axo.QuickTimeVersion.toString(16).substring(0,3))/100;
	} catch(e) {
	}

	try {
		axo = new ActiveXObject('AcroPDF.PDF.1');
		acrobat.installed=true;
		acrobat.version='7.0+';
	} catch(e) {
	}
	if ( !acrobat.version ) {
		try {
			axo = new ActiveXObject('PDF.PdfCtrl.6');
			acrobat.installed=true;
			acrobat.version='6.0';
		} catch(e) {
		}
    }
	if ( !acrobat.version ) {
		try {
			axo = new ActiveXObject('PDF.PdfCtrl.5');
			acrobat.installed=true;
			acrobat.version='5.0';
		} catch(e) {
		}
    }
	if ( !acrobat.version ) {
		try {
			axo = new ActiveXObject('PDF.PdfCtrl.1');
			acrobat.installed=true;
			acrobat.version='4.0';
		} catch(e) {
		}
	}

	java.installed = navigator.javaEnabled();
	
	try {
		axo = new ActiveXObject("rmocx.RealPlayer G2 Control.1");
		realPlayer.installed=true;
		realPlayer.version=axo.GetVersionInfo();
	} catch(e) {
	}
	*/
}

gatherPluginData();

