//Begin Cookie Functions 

function setCookie(cookieId, value, expiredays) 
{

  var ExpireDate = new Date ();
  ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24* 60  * 60 * 1000));
  var cook = cookieId + "=" + escape(value) + 
  	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString())+ "; path=/";

  document.cookie = cook;
}


function getCookie(cookieId)
{
    if (document.cookie.length > 0) 
{ 
    begin = document.cookie.indexOf(cookieId+"="); 
    if (begin != -1)   // Note: != means "is not equal to"
   { 
    begin += cookieId.length+1; 
      end = document.cookie.indexOf(";", begin);
      if (end == -1) end = document.cookie.length;
      return unescape(document.cookie.substring(begin, end));       } 
  }
return null;  
}
 

function detectBrowser() {
	// create global vars to hold browser information
	bVersion = parseFloat(navigator.appVersion); 	// get non-rounded version number (eg. "3.01")
	bName = navigator.appName;						// name, (eg. "Netscape")
	bUserAgent = navigator.userAgent;				// user agent, as reported to web server
	bPlatform = "";									// will store platform

	// local object that we'll treat as an array. we don't use the Array class
	// because array objects aren't available in javascript 1.0 and we want max compatibility
	var platformFinder = new Object();
	
	// store all the platform strings we want to match against in the array
	platformFinder[0] = navigator.appVersion.indexOf("Windows NT 5.0");		// this is win2000
	platformFinder[1] = navigator.appVersion.indexOf("WinNT");
	platformFinder[2] = navigator.appVersion.indexOf("Windows NT");			// this is winNT4 w/ie5
	platformFinder[3] = navigator.appVersion.indexOf("Mac");
	platformFinder[4] = navigator.appVersion.indexOf("95");
	platformFinder[5] = navigator.appVersion.indexOf("Win16");
	platformFinder[6] = navigator.appVersion.indexOf("98");
	platformFinder.length = 7;		// manually set the array length to stay js1.0 compliant

	// store human readable platform names in another array (these match platformFinder)
	platformName = new Object();
	platformName[0] = "Windows 2000 (aka NT 5)";
	platformName[1] = "Windows NT";
	platformName[2] = "Windows NT";
	platformName[3] = "Macintosh";
	platformName[4] = "Windows 95";
	platformName[5] = "Windows 3.1";
	platformName[6] = "Windows 98";


	// check if the users' platform matches any of the platforms we're looking for. if yes, 
	// set "bPlatform" to the corresponding human-readable name.
	var i = 0;
	while (i < platformFinder.length) {
		if (platformFinder[i] != -1) {
			bPlatform = platformName[i];
			break;
		}
		i++;
	} 
		
}


var detectableWithVB = false;
var pluginFound = false;

function goURL(daURL) {
    window.location = daURL;
    return;
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) || 
	(!pluginFound && !redirectIfFound)) ) {
	// go away
	goURL(redirectURL);
	return pluginFound;
    } else {
	// stay here and return result of plugin detection
	return pluginFound;
    }	
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}

function detectReal(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
		       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
		       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }	
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Windows Media Player');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}


function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // 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++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		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 checkAndRedirect(pluginType, notFoundUrl, FoundUrl){

    var isPresent = false; 
    var strUrl = "";
    var cookieId = "";
    cookieId = pluginType + "Cook"; 
    if (pluginType.toLowerCase() == 'real'){
	   //Cookie check
	   /* //Cookie was bing set regardless of whether the plugin existed
	   if(getCookie(cookieId)=='1') {
	   } else {
	      isPresent = detectReal(notFoundUrl);
	      setCookie(cookieId, '1', 30);
	   }
	   */
		isPresent = detectReal(notFoundUrl);
	    setCookie(cookieId, '1', 30);
	}
    if (pluginType.toLowerCase() == 'windowsmedia'){
	
	   //Cookie check
	   /*
	   if(getCookie(cookieId)=='1') {
	      isPresent = true
	   } else {
	      isPresent = detectWindowsMedia(notFoundUrl)
	      setCookie(cookieId, '1', 30) 
	   }
	   */
	   isPresent = detectWindowsMedia(notFoundUrl);
	   setCookie(cookieId, '1', 30) 
	}
	
    //Get the query string and redirect to the foundUrl
    if(isPresent) {
	strQuery = window.location.search.substring(0)
	strUrl = FoundUrl + strQuery
	window.location = strUrl
    } 
}

function checkPlugin(pluginType, notFoundUrl){
    var isPresent = false; 
    var strUrl = "";
    var cookieId = "";
    cookieId = pluginType + "Cook"; 

    if (pluginType.toLowerCase() == 'real'){
	   //Cookie check
	   if(getCookie(cookieId)!='1'){
	      isPresent = detectReal(notFoundUrl)
	      if(isPresent)
	      setCookie(cookieId, '1', 30) 
	   }
	}
    if (pluginType.toLowerCase() == 'windowsmedia'){
	
	   //Cookie check
	   if(getCookie(cookieId)!='1'){
	      isPresent = detectWindowsMedia(notFoundUrl)
	      if(isPresent)
	      setCookie(cookieId, '1', 30) 
	   }
	   
	}
    
}

function checkPluginAlert(pluginType){
var isPresent = false; 
    var strUrl = "";
    var cookieId = "";
	var notFoundUrl = "";
    if (pluginType.toLowerCase() == 'real'){
	   //Cookie check
	   /* //Cookie was bing set regardless of whether the plugin existed
	   if(getCookie(cookieId)=='1') {
	   } else {
	      isPresent = detectReal(notFoundUrl);
	      setCookie(cookieId, '1', 30);
	   }
	   */
		isPresent = detectReal(notFoundUrl);
	    //setCookie(cookieId, '1', 30);
	}
    if (pluginType.toLowerCase() == 'windowsmedia'){
	
	   //Cookie check
	   /*
	   if(getCookie(cookieId)=='1') {
	      isPresent = true
	   } else {
	      isPresent = detectWindowsMedia(notFoundUrl)
	      setCookie(cookieId, '1', 30) 
	   }
	   */
	   isPresent = detectWindowsMedia(notFoundUrl);
	   //setCookie(cookieId, '1', 30) 
	}
	
    //Get the query string and redirect to the foundUrl
    return isPresent;
    
}

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;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} 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];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// 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;
}



// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
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;
	}
}


