// JavaScript Document

RealRealWMpluginFound      = false     // Determines if the latest version of the plugin is installed
RealRealWMactiveXFound     = false     // Determines if the latest version of the ActiveX is installed

WMWMpluginFound      = false     // Determines if the latest version of the plugin is installed
WMWMactiveXFound     = false     // Determines if the latest version of the ActiveX is installed

// If this Microsoft Internet Explorer 4.5 for Macintosh, plugins detection is impossible
plgIe4Mac = false
if (navigator.appVersion.indexOf("PPC")!=-1 && navigator.userAgent.indexOf("MSIE 4")!=-1) {plgIe4Mac = true}

// Check if it's an IE Windows Browser
plgIeWin = false
if ( (navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1) ) {plgIeWin = true}

// Determines if a Real Player superior to G2 Gold is installed
function getReal() {

	// If IE4 Mac, plugins can't be detected
	if(plgIe4Mac) {return false}

	// Check for Plug-in presence
	RealWMpluginFound = getPlugIn("RealPlayer","G2","Plug-In")
	
	// Check for RealPlayer ActiveX
	try {
		testObject = new ActiveXObject("rmocx.RealPlayer G2 Control.1")

		// Since G2 (Real 6), all Real player version numbers begin by 6
		embedVersion = testObject.GetVersionInfo()
		
		// First version supported : 6.0.6.131 = G2 Gold
		versionArray = embedVersion.split(".")
		conditionA = versionArray[0]>=6
		conditionB = versionArray[1]>=0
		conditionC = versionArray[2]>=6
		conditionD = versionArray[3]>=131		
		
		if (conditionA && conditionB && conditionC && conditionD) {
			RealWMactiveXFound = true
		} else {
			if (conditionA) {
				RealWMactiveXFound = true	
			} else {
				RealWMactiveXFound = false			
			}		
		}		

	} catch(e) {
		RealWMactiveXFound = false
	}
	
	if (RealWMpluginFound || RealWMactiveXFound) {return true} else {return false}	
}

// Parse plugins collection with strings to find
// User has to pass strings to be found in plugin name and description
// Ex. "Shockwave","Flash","5"
function getPlugIn() {

	// search for the right plugin among all those have been installed
	allFound = false
    plugInsCollection = navigator.plugins
	
	for (i=0;i<plugInsCollection.length;i++) {

		// Get plugin description
        plugInDescription = " " + plugInsCollection[i].description
		plugInName = " " + plugInsCollection[i].name
		
		for (j=0;j<arguments.length;j++) {
		
			if (plugInDescription.indexOf(" " + arguments[j])!=-1 || plugInName.indexOf(" " + arguments[j])!=-1) {
				allFound = true
			} else {
				allFound = false
				break
			}
		}
		
		// Send back the search result
		if (allFound) {return true}
    }

	// Send back the search result
	return false
}

// Check if Windows Media Player is installed
function getWmp() {

	// If IE4 Mac, plugins can't be detected
	if(plgIe4Mac) {return false}

	// Check for the WMP plugin - Can check only if it's installed
	// Note that only WMP 7.1 takes in account Mozilla Browsers such as N6.1
	WMpluginFound = getPlugIn("Windows","Media","Player")
	
	// Check if WMP 7 ActiveX is installed
	// Note that CLSID of WMP 6.4 is : 22D6F312-B0F6-11D0-94AB-0080C74C7E95
	if (plgIeWin) {WMactiveXFound = getIEComponent("22D6F312-B0F6-11D0-94AB-0080C74C7E95")} else {WMactiveXFound=false}

	if (WMpluginFound || WMactiveXFound) {return true} else {return false}	
}

// Use the Client Capabilities behavior to check IE component installation
function getIEComponent(activeXClsId,minVersion) {
	if (plgIeWin) {return document.body.isComponentInstalled("{" + activeXClsId + "}","componentId",minVersion)} else {return false}
}

// Add Client Capabilities behavior to the document body - Must be done at load time
if (plgIeWin) {
	document.body.addBehavior("#default#clientCaps")
}

function select_player(string) {
	
	if (getWmp()) {
		ajaxpage('include/play.php'+string+"&installed=1&player=0", 'videoWindows')
		//ajaxpage('include/wmplay.php'+string, 'videoWindows')
		//ajaxpage('include/noplayer.php'+string, 'videoWindows')
		//window.location = "wmplay.php?id=<?php echo $id; ?>&type=<?php echo $type; ?>&year=<?php echo $year; ?>"
	} else {
		ajaxpage('include/play.php'+string+"&installed=0&player=0", 'videoWindows')	
		//ajaxpage('include/noplayer.php'+string, 'videoWindows')
		//window.location = "noplayer.php?id=<?php echo $id; ?>&type=<?php echo $type; ?>&year=<?php echo $year; ?>"
	}	
}