//<script language="JavaScript">

// initialize global variables
//FAST_MODEM = 57;
//ISDN_MODEM = 200;
	
var SLOW_MODEM		= 120;
	
var connectionSpeed = 0;	// The variable where connection speed information
var startTime		= '';	// will be stored when it is available.	
var fileSize		= 19529;	
var fileLocation	= '/NR/ContentConnector/CS2000/SiteInterface/commonLSA/js/cds.jpg';
	
var detectableWithVB	= false;
var pluginFound			= false;
var arrPlayerAvailable	= new Array(1);

arrPlayerAvailable[0]	= 'Windows Media';
arrPlayerAvailable[1]	= 'QuickTime';


var strDefaultPlayer	= (platformDetect() == 'Mac') ? 'QuickTime':  'Windows Media';


function platformDetect() {
		
	var sPlateform	= 'Mac';

	if(navigator.appVersion.indexOf("Win") != -1){ sPlateform = "Win";}

	return sPlateform;
}

function canDetectPlugins() {
	return((detectableWithVB || (navigator.plugins && navigator.plugins.length > 0)));
}

//Overwrite default player
function OverwriteDefaultPlayer(sPlayerName){

	if(!existPlayer(sPlayerName)) return;
	
	strDefaultPlayer = sPlayerName;

}

function existPlayer(sName){
	
	var bValid = false;
	
	for(i = 0; i < arrPlayerAvailable.length; i++){
		if(arrPlayerAvailable[i] == sName){
			bValid = true;
			break;
		}
	}
	return bValid;
}


function detectQuickTime() {
    
    pluginFound = detectPlugin('QuickTime');
    
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
		pluginFound = detectQuickTimeActiveXControl();
    }
	
	return pluginFound;
	
}

function detectWindowsMedia() {
    
    pluginFound = detectPlugin('Windows Media');
    
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
		pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
	
	return pluginFound;
}

function detectPlugin(sMediaName) {
    
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
		
		var pluginsArrayLength = navigator.plugins.length;
		
		// for each plugin...
		for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {

			// if desired plugin name is found in either plugin name or description
			if( (navigator.plugins[pluginsArrayCounter].name.indexOf(sMediaName) >= 0) || 
			    (navigator.plugins[pluginsArrayCounter].description.indexOf(sMediaName) >= 0) ) {
					    
			    // this name was found
			    pluginFound = true;
			    break;
					    
			}   
		}
    }
    return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}


function getPlayer(){
	
	var sPlayerName = '';
	
	if(!canDetectPlugins()){return sPlayerName;} //missinge required player
	

	switch(strDefaultPlayer){
			
		case 'Windows Media':

			if(detectWindowsMedia()){	sPlayerName = 'M';}
			else if(detectQuickTime()){	sPlayerName = 'Q';}
			
			break;
			
		case 'QuickTime':
				
			if(detectQuickTime()){			sPlayerName = 'Q';}
			else if(detectWindowsMedia()){	sPlayerName = 'M';}			
			
			break;
	}
	
	return sPlayerName; //si vide : missinge required player
}


function drawCSImageTag() {
	// This function draws the image tag required to run this process.
	// It needs to be passed:
	//     1.  (String)   The location of the file to be loaded
	//     2.  (Integer)  The size of the image file in bytes
	//     3.  (String)   The tag properties to be included in the <img> tag
	// Place a call to this function inside the <body> of your file
	// in place of a static <img> tag.
	
	// Record Start time of <img> load.		
	startTime = (new Date()).getTime();
		
	// Append the Start time to the image url
	// to ensure the image is not in disk cache.
	var strSrc = fileLocation + '?t=' + escape(startTime);

	// Write out the <img> tag.			
	document.write("<img src='" + strSrc + "' width='1' height='1' border='0' onload='setConnectionSpeedValue();'>");

	return;
}
		
function connectionType(speed) {
	// This function returns a string describing the connection type
	// being used by the user-agent hitting the page.

	// These are constants which define the base speeds
	// for a number of different connections.  They are
	// measured in units of kbps.
	
	var returnValue = (speed && (speed < SLOW_MODEM)) ? 'L' : 'H';
	
	return returnValue
}
		
function computeConnectionSpeed() {
	// This function returns the speed in kbps of the user's connection,
	// based upon the loading of a single image.  It is called via onload 
	// by the image drawn by drawCSImageTag() and is not meant to be called
	// in any other way.  You shouldn't ever need to call it explicitly.
			
	var endTime = (new Date()).getTime();
	return (Math.floor((((fileSize * 8) / ((endTime - startTime) / 1000)) / 1024) * 10) / 10);
}
		

function getConnectionType(){
	return connectionType(connectionSpeed);
}


function setConnectionSpeedValue() {

	connectionSpeed = computeConnectionSpeed();
}

function playVideo(sCode, sHTTP, sFeatures){

	var nArgs			= playVideo.arguments.length;
	var sCurrLocation	= document.location.href;
	var sCurrCode		= '';
	
	if(nArgs > 0 && sCode.length > 0){
		var sHREF = ''; 
		if(nArgs > 1){
			sHREF = (sHTTP.length > 0 && sCurrLocation.indexOf(sHTTP)<= 0) ? sHTTP : sCurrLocation;
						
			if (sHREF.match(/.*\?.*/))
			{
				var sUrl = sHREF.replace(/(.*\?)(.*)/g, "$1");
				var sSearch = escape(sHREF.replace(/(.*\?)(.*)/g, "$2")).replace(/%3D/,"=");
				sHREF = sUrl + sSearch;
				
			}
		}
	
		sHREF += (sHREF.indexOf('?') > -1) ? '&v=' + sCode : '?v=' + sCode;
			 
		sHREF += getPlayer() + getConnectionType();
		
		if(nArgs == 3){
			var iPos = sFeatures.indexOf('=');
			if(iPos >= 0){
				var sParam = sFeatures.substring(0, iPos).toLowerCase();
				var sValue = sFeatures.substring(iPos + 1)
				switch(sParam){
					case 'popup' :
						if(sValue == '1'){window.open(sHREF);}
						break;
					default :
						document.location.href = sHREF;
						break;
				}
			}
		}else{
			
			document.location.href = sHREF;
		}
	}
}

function playVideoSequence(sCode, sHTTP, sFeatures){
	var nArgs			= playVideoSequence.arguments.length;
	var sQueryString	= document.location.search;
	var sCurrLocation	= document.location.href;
	var sCurrCode		= '';
	i = sCurrLocation.split('?');
	sCurrLocation = i[0];
	if(nArgs > 0 && sCode.length > 0){
		var sHREF = '';
		if(nArgs > 1){
			sHREF = (sHTTP.length > 0 && sCurrLocation.indexOf(sHTTP)<= 0) ? sHTTP : sCurrLocation;
		}
		sHREF += (sHREF.indexOf('?') > -1) ? '&v=' + sCode : '?v=' + sCode;
		sHREF += getPlayer() + getConnectionType();
		document.location.href = sHREF;
	}
}

function parseQueryString(sQueryString){

	queryString.keys	= new Array();
	queryString.values	= new Array();
	
	var arrParams	= sQueryString.replace(/^.*\?(.+)$/,'$1').split("&");
	var sParamName	= '';
	var sValue		= '';
	var iPos		= -1;
	
	for (var i = 0; i < arrParams.length; i++){
		
		iPos = arrParams[i].indexOf('=');
		
		if(iPos >= 0){
			
			sParamName	= arrParams[i].substring(0, iPos);
			sValue		= arrParams[i].substring(iPos + 1);
			
			queryString.keys[queryString.keys.length]		= sParamName;
			queryString.values[queryString.values.length]	= sValue;		
		}
	}

}

function queryString(key){
	
	var sValue = null;

	for (var i = 0; i < queryString.keys.length; i++){
		
		if (queryString.keys[i] == key){
			sValue = queryString.values[i];
			break;
		}
	}
	
	return sValue;
}

/*
SCRIPT POUR LES RECENTS VERSION DE BROWSER
function parseQueryString(sQueryString) {
  
  var queryObject = new Object();
  
  sQueryString = sQueryString.replace(/^.*\?(.+)$/,'$1');

  while ((pair = sQueryString.match(/([^=]+)=\'?([^\&\']*)\'?\&?/)) && pair[0].length) {
    sQueryString = sQueryString.substring( pair[0].length );

    if (/^\-?\d+$/.test(pair[2])) pair[2] = parseInt(pair[2]);
    queryObject[pair[1]] = pair[2];
  }

  return queryObject;
}
*/

//Write Image Tag for read the speed
//drawCSImageTag("cds.jpg", 'border="0" width="1" height="1" alt=""');


