var detectState="";
var fn="";

function broadbandDetect(){

	if (doDetect().detectState == "ok"){
		return true;
	} else{
		window.location.href = 'detecterror.html';
	}
}

function doDetect(){
		if( ( !os.isMac()) && (!os.isWindows())){
			detectState =  "os_other";
			fn	= "error_os_not_support";
		}
		else if(os.isMac()){
		   detectState = macDetect().detectState;
		   fn = macDetect().fn;
		}
		//need to detect vista
		else if ((!os.isWindowsXP()) && (!os.isWindows2K() ) ){
		   detectState = "oldwindows";
		   fn = "error_os_not_support";
		}
		else if (isFirefox) {  
			detectState = firefoxX().detectState;
	  		fn = firefoxX().fn;
		}
		else if (flashVersion < 8 ) {
		   detectState = "oldflash";
		   fn = "error_flash";
		} else {
			detectState = "ok";
			fn = "good_to_go";
		}
		
		var pn = fn + ".js";

		
	return {detectState : detectState, fn : fn, pn : pn};
}

function firefoxX(){
	
	if((firefoxXInstall().version == "1.5" || firefoxXInstall().version == "2.0") && isActiveXInstalled()) {
		detectState = "ok";
    	fn = "good_to_go";
	} else if (navigator.appName == "Netscape") {
		detectState 	= firefoxXInstall().detectState;
	  	fn 				= firefoxXInstall().fn;
	}
	
	return {detectState:detectState, fn:fn};
}

function isActiveXInstalled() {
	// Checks if ActiveX is installed
	var geckoax=new Object();
	geckoax.installed=false;
	var isInstalled=false;
	
	if (navigator.plugins && navigator.plugins.length)
	{
		for (x=0; x<navigator.plugins.length; x++)
		{
			if (navigator.plugins[x].name.indexOf('ActiveX') != -1 && window.GeckoActiveXObject) {
				geckoax.installed=true;
			}
		}
	}
		
	if (window.ActiveXObject || geckoax.installed){
		isInstalled=true;
	} else {
		isInstalled=false;
	}

	return isInstalled;
}

function firefoxXInstall() {

	var versionindex 	= 	navigator.userAgent.indexOf("Firefox")+8;
	var version 		= 	navigator.userAgent.substring(versionindex,(versionindex+3));
	var fullversion 	=   navigator.userAgent.substring(versionindex,(versionindex+7))
	
	fn="error_browser";
	detectState="firefox"; 
	
	if (version == "1.5" || version == "2.0") {
 		fn = "error_firefox_1.5";
	} else {
		fn = "error_firefox";
	}
	return {detectState: detectState, fn : fn, version:version, fullversion:fullversion};	
}

function macDetect()
{
	var fn="error_not_osx";
	var detectState="notOSX"; 


	if (os.isMacOSX() )
	{
		if (dojo.render.html.safari)
		{
			fn = "good_to_go";
			detectState = "ok";	
		}
		else if (dojo.render.html.moz || dojo.render.html.safari)
		{
			if (!detectPlugin('Flip4Mac') && detectPlugin('Windows Media'))
			{
				fn = "error_no_mac_plugin";
				detectState = "noPlugIn";	
			}
			else
			{
				fn = "good_to_go";
				detectState = "ok";	
			}
		}
		else
		{
			fn = "error_browser";
			detectState = "nosupport";	
		}
	}
	
	return {detectState:detectState, fn:fn};
}

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


