// Detect various things about the browser client software and operating system

// initialize global variables
var detectableWithVB = false;
var pluginFound = false;
var haveWMP7 = false;
var haveWMP64 = false;

document.write('<OBJECT ID="WMPlay7" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject" width="0" height="0"></OBJECT>');
document.write('<OBJECT ID="WMPlay64" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" type="application/x-oleobject" width="0" height="0"></OBJECT>');

// Determine OS based upon UserAgent string
function SelectOs() {

	var agent = navigator.userAgent.toLowerCase(); // not supported in NS3.0

	if ((agent.indexOf('windows xp') != -1) || (agent.indexOf('winxp') != -1) || (agent.indexOf('win xp') != -1) || (agent.indexOf('Windows NT 5.0') != -1) || (agent.indexOf('WinNT5') != -1)) {
		document.contact.os.options[1].selected=1;
	}

	if ((agent.indexOf('windows nt') != -1) || (agent.indexOf('winnt') != -1) || (agent.indexOf('win nt') != -1)) {
		document.contact.os.options[2].selected=1;
	}

	if ((agent.indexOf('windows 2000') != -1) || (agent.indexOf('win2000') != -1) || (agent.indexOf('win 2000') != -1)) {
		document.contact.os.options[3].selected=1;
	}

	if ((agent.indexOf('windows me') != -1) || (agent.indexOf('winme') != -1) || (agent.indexOf('win me') != -1)) {
		document.contact.os.options[4].selected=1;
	}

	if ((agent.indexOf('windows 98') != -1) || (agent.indexOf('win98') != -1) || (agent.indexOf('win 98') != -1)) {
		document.contact.os.options[5].selected=1;
	}

	if ((agent.indexOf('windows 95') != -1) || (agent.indexOf('win95') != -1) || (agent.indexOf('win 95') != -1)) {
		document.contact.os.options[6].selected=1;
	}

	if (agent.indexOf('linux') != -1) {
		document.contact.os.options[7].selected=1;
	}

	if ((agent.indexOf('mac os x') != -1) || (agent.indexOf('mac_os_x') != -1) || (agent.indexOf('mac_osx') != -1) || (agent.indexOf('mac osx') != -1)) {
		document.contact.os.options[8].selected=1;
	}
	else {

		if (agent.indexOf('mac') != -1) {
			document.contact.os.options[9].selected=1;
		}

	}

}

// Detect whether browser has cookies turned on and select that.
function SelectCookie() {

	if (navigator['cookieEnabled']) {
		document.contact.cookie[0].checked=1;
	}
	else {
		document.contact.cookie[1].checked=1;
	}

}

// Select the browser they are using from the dropdown
function SelectBrowser() {
	var agent = navigator.userAgent.toLowerCase(); // not supported in NS3.0

	if ((agent.indexOf('msie') != -1) && (agent.indexOf('opera') == -1)) {
		document.contact.browser.options[1].selected=1;
	}

	if ((agent.indexOf('mozilla') != -1) && (agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1) && (agent.indexOf('opera') == -1) && (agent.indexOf('webtv') == -1) && (agent.indexOf('hotjava') == -1) ) {
		document.contact.browser.options[2].selected=1;
	}

	if (agent.indexOf('aol') != -1) {
		document.contact.browser.options[3].selected=1;
	}

	if (agent.indexOf('compuserv') != -1) {
		document.contact.browser.options[4].selected=1;
	}

	if (agent.indexOf('opera') != -1) {
		document.contact.browser.options[5].selected=1;
	}


	if (agent.indexOf('webtv') != -1) {
		document.contact.browser.options[6].selected=1;
	}

}

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

// Try to detect if windows media player is installed.
function detectWindowsMedia() {
	pluginFound = detectPlugin('Windows Media Player');
	// if not found, try to detect with VisualBasic
	if(!pluginFound && detectableWithVB) {
		pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
	}
	return pluginFound;
}

// Detect if they have window's media player and drop a hidden text field
function HasWmp() {
	var ans=detectWindowsMedia();

 	if (document.WMPlay7.controls) {
 		haveWMP7 = true;
 		var wmp7ver=WMPlay7.versionInfo;
 	} 

 	if (document.WMPlay64) { 
 		haveWMP64 = true; 
 	}

	document.write('<input type="hidden" name="wmp" value="'+ans+'">\n');
	document.write('<input type="hidden" name="wmp64" value="'+haveWMP64+'">\n');
	document.write('<input type="hidden" name="wmp7" value="'+haveWMP7+'">\n');
	document.write('<input type="hidden" name="wmp7ver" value="'+wmp7ver+'">\n');
}

// Output a hidden text field with some information about their browser.
function ClientProbe() {
	document.write('<input type="hidden" name="appName" value="'+navigator.appName+'">\n');
	document.write('<input type="hidden" name="appVersion" value="'+navigator.appVersion+'">\n');
	document.write('<input type="hidden" name="appMinorVersion" value="'+navigator.appMinorVersion+'">\n');
	document.write('<input type="hidden" name="platform" value="'+navigator.platform+'">\n');
}

// Write a block of VBScript that determines if plugins are detectable
// in:
// out: detectableWithVB = true if VBScript detection will work,
// detectActiveXControl(activeXControlName) returns true if control can be made,
// detectQuickTimeActiveXControl() special code to detect quicktime
function WriteVBDetectBlock() {

	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>');
	}

}

