/* ================================================== *\
   2006 (c) Copyright AdvanceOnline Solutions, Inc. All rights reserved.
\* -------------------------------------------------- */

function SystemProfile (aPlatforms, aOSs, aScreens, aApps, sCookies, sBlocker, sCss, sFlash, aAcrobat) {
	this.testType = ['Platform', 'OS', 'Screen', 'Browser', 'Cookie', 'Blocker', 'Css', 'Flash', 'Acrobat'];

	this.userPlatform = 'unknown';
	this.userOS       = 'unknown';
	this.userScreen   = 'unknown';
	this.userBrowser  = 'unknown';
	this.userCookie   = 'unknown';
	this.userBlocker  = 'unknown';
	this.userCss      = 'unknown';
	this.userFlash    = 'unknown';
	this.userAcrobat  = 'unknown';
	this.FlashPI      = 'unknown';
	this.AcrobatPI    = 'unknown';

	this.requiredPlatform = (this.$isUndefined (aPlatforms) && aPlatforms != null) ? aPlatforms : ['MacPPC', 'Win32', 'MacIntel'];
	this.requiredOS = (this.$isUndefined (aOSs) && aOSs != null) ? aOSs : ['Mac OS X', 'Windows XP', 'Windows NT 4.0', 'Windows 98', 'Windows ME', 'Microsoft Windows'];
	this.requiredScreen = (this.$isUndefined (aScreens) && aScreens != null) ? aScreens : ['800 x 600', '1024 x 768', '1280 x 1024'];
	this.requiredBrowser = (this.$isUndefined (aApps) && aApps != null) ? aApps : ['Internet Explorer 7.0', 'Internet Explorer 6.0', 'Firefox 2.0', 'Firefox 3.0', 'Firefox 3.5'];
	this.requiredCookie = (sCookies != '' && sCookies != null) ? sCookies : 'Enabled';
	this.requiredBlocker = (sBlocker != '' && sBlocker != null) ? sBlocker : 'Disabled';
	this.requiredCss = (sCss != '' && sCss != null) ? sCss : 'Supported';
	this.requiredFlash = (sFlash != '' && sFlash != null) ? sFlash : ['Shockwave Flash 7.0','Shockwave Flash 8.0','Shockwave Flash 9.0','Shockwave Flash 10.0',];
	this.requiredAcrobat = (aAcrobat != '' && aAcrobat != null) ? aAcrobat : ['Adobe Acrobat 5.0', 'Adobe Acrobat 6.0', 'Adobe Acrobat 7.0', 'Adobe Acrobat 8.0', 'Adobe Acrobat 9.0', 'Adobe PDF Plug-In For Firefox and Netscape', 'Adobe Acrobat'];

	this.passPlatform = false;
	this.passOS = false;
	this.passScreen = false;
	this.passBrowser = false;
	this.passCookie = false;
	this.passBlocker = false;
	this.passCss = false;
	this.passFlash = false;
	this.pasaAcrobat = false;

	this.passSystem = 'You are not missing any requirements.';

	this.failSystem = {
		Platform:'Your computer type is not supported by our content.',
		OS:'Your operating system is not supported by our content.',
		Screen:'Your screen resolution is not within the limits for viewing our content. Our prefered viewing resolution is 1024 x 768. Having a small screen resolution will limit the amout of information you may view on screen at any given time. Where as having a larger screen resolution will decrease the size of text making it harder to read.',
		Browser:'Your internet browser is not supported by our content.',
		Cookie:'You do not have cookies enabled. This will prevent you from viewing a course.',
		Blocker:'You have a pop up blocker enabled. This will prevent you from viewing a course.',
		Css:'Your browser does not support cascading style sheets. This will prevent you from viewing a course.',
		Flash:'Your version of <a name="flash" title="Get Flash Player." href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Flash Player</a> is not supported by our content.',
		Acrobat:'Your version of <a name="acrobat" title="Get Adobe Acrobat Reader." href="http://www.adobe.com/products/acrobat/readstep2.html" target="_blank">Adobe Acrobat</a> is not supported by our content.'
	};
}

var oSystemProfile = SystemProfile.prototype;

oSystemProfile.detectSystem = function () {
	this.$createCookie ();

	this.userPlatform = navigator.platform;
	this.userOS = this.$parseOS ();
	this.userScreen = screen.width + ' x ' + screen.height;

	this.$parseBrowser ();
	this.userCookie = this.$detectCookie ();
	var oFindDom = new FindDOM ();
	var oDiv = oFindDom.find ('oiLayout', 'id');
	this.userCss = (oDiv.style) ? 'Supported' : 'Unsupported';

	this.FlashPI = this.$findPlugIn ('Shockwave Flash');
	if (this.FlashPI) {
		var sDescription = this.FlashPI.description;
		var nIndexOf = sDescription.indexOf ('.');
		var sSupport = sDescription.substr (0, nIndexOf);
		this.userFlash = sSupport + '.0';
	} else {
		this.userFlash = 'not installed';
	}

	this.AcrobatPI = this.$findPlugIn ('Adobe Acrobat');
	if (this.AcrobatPI) {
		var sDescription = this.AcrobatPI.description;
		var nIndexOf = sDescription.indexOf ('.');
		var sVersion = sDescription.substr (nIndexOf - 1, 1);
		this.userAcrobat = 'Adobe Acrobat'; // 'Adobe Acrobat ' + sVersion + '.0';
	} else {
		this.AcrobatPI = this.$findPlugIn ('Acrobat7');
		if (this.AcrobatPI) {
			var sDescription = this.AcrobatPI.description;
			var nIndexOf = sDescription.indexOf ('.');
			var sVersion = sDescription.substr (nIndexOf - 1, 1);
			this.userAcrobat = 'Adobe Acrobat';
		} else {
			this.userAcrobat = 'not installed';
		}
	}
	
	var isFirefox = this.userBrowser.indexOf( "Firefox" );
	( (isFirefox > -1) && (this.userPlatform == "MacPPC" || this.userPlatform == "MacIntel") ) ? this.userAcrobat = 'Macintosh computers using Firefox will view PDFs in <b><i>Preview<\/i><\/b> or the standalone version of Acrobat Reader. You do not need to check for <i>Adobe Acrobat Reader<\/i>, unless you require 508 Accessibility. <i>Preview<\/i> comes pre-installed, but does not include support for 508 Accessibility' : null;
}

oSystemProfile.testSystem = function () {
	var aCheck = this.testType;
	var nCheck = aCheck.length;
	for (var x = 0; x < nCheck; x++) {
		var sCheck = aCheck[x];
		var sUser = this['user' + sCheck];
		var Required = this['required' + sCheck];

		if (typeof Required == 'object') {
			var sAcceptable, nLength = Required.length;
			for (var y = 0; y < nLength; y++) {
				sAcceptable = Required[y];
				if (sCheck == 'Acrobat') {
					if (this.userPlatform == 'MacPPC' || this.userPlatform == 'MacIntel') {
						this['pass' + sCheck] = true;
					} else {
						if (sUser == sAcceptable) {
							this['pass' + sCheck] = true;
							break;
						}
					}
				} else {
					if (sUser == sAcceptable) {
						this['pass' + sCheck] = true;
						break;
					}
				}
			}
		} else {
			if (sUser == Required) {
				this['pass' + sCheck] = true;
			}
			if (sCheck == 'Flash') {
				var nRequiredVersion = Required.substr(Required.indexOf('.') - 1, 1);
				var nUserVersion = sUser.substr(sUser.indexOf('.') - 1, 1);
				if (nUserVersion >= nRequiredVersion) this['pass' + sCheck] = true;
			}
		}
	}
}

oSystemProfile.$findPlugIn = function (sKey) {
	var oPlugin;
	if (!window.ActiveXObject) {
		var bMatch = false;
		var aPlugins = navigator.plugins;
		for (var x = 0; x < aPlugins.length; x++) {
			oPlugin = aPlugins[x];
			var sName = oPlugin.name;
			if (sKey == sName) {
				bMatch = true;
				break;
			}
		}
		if (bMatch) return oPlugin;
	} else {
		var sPlugin, nVersionOld, nVersionNew;
		switch (sKey) {
		case 'Shockwave Flash' :
			sPlugin = 'ShockwaveFlash.ShockwaveFlash.';
			nVersionOld = 7;
			nVersionNew = 10;
			break;
		case 'Adobe Acrobat' :
			sPlugin = 'Pdf.PdfCtrl.';
			nVersionOld = 5;
			nVersionNew = 7;
			break;
		case 'Acrobat7' :
			sPlugin = 'AcroPDF.PDF.';
			nVersionOld = 1;
			nVersionNew = 6;
			break;
		}
		for (var x = nVersionOld; x <= nVersionNew; x++) {
			try {
				oPlugin = eval (new ActiveXObject (sPlugin + x));
				if (oPlugin) {
					oPlugin = {description:sKey + ' ' + x + '.0'};
				}
			} catch (oError) {
			}
		}
		return oPlugin;
	}
}

oSystemProfile.$createCookie = function () {
	document.cookie = 'cookiesEnabled=true';
}
// 10/31/2006 Julian Calzada Changed: This function needed to be redone to work with the additional cookies created by the new site.
oSystemProfile.$detectCookie = function () {
	var sCookie = document.cookie;
	var nIndex = sCookie.indexOf('cookiesEnabled');
	var sValue = sCookie.substr(nIndex + 15, 4);
	var sSupport = (sValue == 'true') ? 'Enabled' : 'Disabled';
	return sSupport;
}

oSystemProfile.$parseOS = function () {
	var sPlatform = navigator.platform;
	var sUserAgent = navigator.userAgent;
	var sOS = ''; var nIndexOf = 0;
	if (sPlatform == 'MacPPC') {
		nIndexOf = sUserAgent.indexOf ('Mac OS');
		sOS = (nIndexOf == -1) ? 'Mac OS' : sUserAgent.substr (nIndexOf, 8);
	} else {
		this.aUserAgent = sUserAgent.split ('; ');
		nIndexOf = sUserAgent.indexOf ('Windows');
		var nNTIndexOf = sUserAgent.indexOf ('NT', nIndexOf);
		var nNTVersion = sUserAgent.indexOf ('4', nNTIndexOf);
		var nLength = (nNTIndexOf == -1) ? 10 : 14;
		sOS = sUserAgent.substr (nIndexOf, nLength);
		if (nNTVersion == -1) {
			sOS = sUserAgent.substr (nIndexOf, 8) + 'XP';
		}
		sOS = 'Microsoft Windows';
	}
	return sOS;
}

oSystemProfile.$parseBrowser = function () {
	var sUserAgent = navigator.userAgent;
	var sAppName = navigator.appName;
	if (sAppName == 'Netscape') {
		var nMozilla = sUserAgent.indexOf ('Mozilla');
		var nFirefox = sUserAgent.indexOf ('Firefox');
		var nNetscape = sUserAgent.indexOf ('Netscape');
		var nSafari = sUserAgent.indexOf ('Safari');
		if (nFirefox != -1) {
			this.userBrowser = 'Firefox ' + sUserAgent.substr (nFirefox + 8, 3);
		} else if (nSafari != -1) {
			var nVersion = sUserAgent.substr (nSafari + 7, 3);
			var aVersion = nVersion.split ('');
			this.userBrowser = 'Safari ' + aVersion[0] + '.' + aVersion[1];
		} else if (nNetscape != -1) {
			this.userBrowser = 'Netscape ' + sUserAgent.substr (nNetscape + 9, 3);
		} else if (nMozilla != -1) {
			var nRev = sUserAgent.indexOf ('rv:');
			this.userBrowser = 'Mozilla ' + sUserAgent.substr (nRev + 3, 3);
		}
	} else {
		var nMSIE = sUserAgent.indexOf ('MSIE');
		if (nMSIE != -1) {
			this.userBrowser = 'Internet Explorer' + ' ' + sUserAgent.substr (nMSIE + 5, 3);
		}
	}
}

oSystemProfile.$isUndefined = function (oCheck) {
	var oUndefined;
	return oCheck === oUndefined;
}

delete oSystemProfile;

