/* join screens are not compatible with jquery */

/* initialize global join vars */
var manualJoinPref = false;

var axEnabled = false;
var jwsEnabled = false;
var nsPluginEnabled = false;

/* join timer vars */
var jTimerID = 0;
var jTimeLeft = 10;
var ellipsisTrk = 0;
var ellipsisMax = 3;
var ellipsis = '';
var joinType = '';

/* session join timer vars */
var sjCounter = 0;
var sjTimerID = null;

var os, osVersion, browser, ie6, ie7, ie6Plus, gecko

/* join functions */

function showHideJoinEl(eln, show) {
	var el = document.getElementById(eln);
	if (el)
		el.style.display = (show ? 'inline' : 'none'); 
}

function popBrowserVars() {
	// detect browser properties
	var browObj = jdetectBrowserProps();

	os = browObj["os"]["name"];
	osVersion = browObj["os"]["version"];
	browser = browObj["browser"]["name"];
	browser = browser.toLowerCase();
	
	ie6 = false;
	ie7 = false;

	if (browser == 'ie') {
		ie6 = browObj["browser"]["ie6"];
		ie7 = browObj["browser"]["ie7"];
	}
	
	ie6Plus = (os == 'win' && browser == 'ie' && (ie6 || ie7) ? true : false);
	gecko = browObj["browser"]["gecko"];
}

function initJoinSession() {
	popBrowserVars();

	//if (!joinObj.pluginInstall && !joinObj.intJoin) {
	if (!joinObj.pluginInstall) {
		/* check every 15 seconds, stop after 30 seconds */
		sjCounter = 0;
		sjTimerID = setInterval("sessionJoinedChk(joinObj.aID, joinObj.uID)", 15000);
	}

	/* check for manual join pref cookie */
	//manualJoinPref = (joinObj.disableStubInstaller ? false : jgetCookie('manual_join_pref'));

	if (manualJoinPref) {
		/* just in case Perl did not catch cookie */
		joinObj['disableActiveXJoin'] = true;
		joinObj['disableJavaJoin'] = true;
	}

	if (!manualJoinPref) {
		if (joinObj.pluginInstall)
			showHideJoinEl('join_pluginPrepare', true);
		else
			showHideJoinEl('join_joinPrepare', true);
	}

	/* join order: java, activex, manual (stub) */
	if (!joinObj.disableJavaJoin) {
		isJavaEnabled();

		launchJavaJoin();
	}

	/* activex enabled check */
	if (browser == 'ie' && !joinObj.disableActiveXJoin && !jwsEnabled) {
		/* object must be written on page load */
		// see if ActiveX is enabled
		if (isObjectEnabled()) {
			axEnabled = true;
		}
	}
	/* ns/mozilla plug-in enabled check */	
	if (browser != 'ie' && !joinObj.disableActiveXJoin && !jwsEnabled) {
		isNSPluginEnabled();
	}

	/* activex or ns/mozilla plug-in join */
	if (joinObj.disableJavaJoin && !joinObj.disableActiveXJoin) {
		if (browser == 'ie') {
			launchActiveXJoin();
		} else {
			launchNSPluginJoin();
		}
	}

	/* stub installer join */
	if (!joinObj.disableStubInstaller && joinObj.disableJavaJoin && joinObj.disableActiveXJoin) {
		launchManualInstall();
	}
}

function launchActiveXJoin() {
	if (!axEnabled) {
		if (isObjectEnabled()) {
			axEnabled = true;
		}
	}

	if (axEnabled || (!axEnabled && ie6Plus)) {
		if (joinObj.pluginInstall) {
			showHideJoinEl('join_pluginPrepare', false);
			showHideJoinEl('join_pluginAXContainer', true);
	
			if (!joinObj.disableStubInstaller)
				showHideJoinEl('join_pluginAXPreMnl', true);
	
			if (joinObj.inclHelpInfo)
				showHideJoinEl('join_pluginAXSupport', true);
		} else {
			showHideJoinEl('join_joinPrepare', false);
			showHideJoinEl('join_joinAXContainer', true);
			if (!joinObj.isRec) {
				showHideJoinEl('join_joinAXCon', true);
			} else {
				showHideJoinEl('join_joinAXCon', false);
				showHideJoinEl('join_joinRecording', true);
			}
	
			if (!joinObj.disableStubInstaller)
				showHideJoinEl('join_joinAXPreMnl', true);
	
			if (joinObj.inclHelpInfo)
				showHideJoinEl('join_joinAXSupport', true);
		}
	}

	joinType = (joinObj.pluginInstall ? 'plugin' : 'ax');

	/* start join timer */	
	startJoinTimer();

	initiateActiveX();
	/* use timeout to slow down launch */
	//var axTimeout = setTimeout("initiateActiveX()", 1000);
}

function isObjectEnabled() {
	var xObj = null;

	try {
		xObj = new ActiveXObject(joinObj.activeXObjectName);
	} catch(e) {
		xObj = null;
	}

	var isEnabled;
	isEnabled = false;

	if (xObj == null) {
		isEnabled = false;
	} else {
		isEnabled = xObj.IsActiveXAvailable();
		if (isEnabled == "")
			isEnabled = false;
	}

	return isEnabled;
}

function initiateActiveX() {
	var xObj = null;

	try {
		xObj = new ActiveXObject(joinObj.activeXObjectName);
	} catch(e) {
		xObj = null;
	}

	if (xObj != null) {
		if (isObjectEnabled()) {
			xObj.JoinClass(joinObj.paramstring);
		}
	}
}

function launchNSPluginJoin() {
	if (joinObj.pluginInstall)
		showHideJoinEl('join_pluginPrepare', false);
	else
		showHideJoinEl('join_joinPrepare', false);

	if (nsPluginEnabled) {
		joinType = 'moz';
		initiateNSPlugin();

		// refresh plugins - launching session installs plug-in
		//navigator.plugins.refresh(true);

		if (joinObj.pluginInstall) {
			showHideJoinEl('join_pluginMozContainer', true);
			if (joinObj.inclHelpInfo)
				showHideJoinEl('join_pluginMozSupport', true);
		} else {
			showHideJoinEl('join_joinMozContainer', true);
			if (joinObj.inclHelpInfo)
				showHideJoinEl('join_joinMozSupport', true);
		}

	} else {
		 launchManualInstall();
	}
}

function initiateNSPlugin() {
	var nsDiv = document.getElementById('join_NSObjectDiv');
	if (nsDiv) {
		nsDiv.innerHTML = '<EMBED type="application/x-iLinc' + joinObj.serverVersion + 'Install-plugin" name="iLinc' + joinObj.serverVersion + ' Install Plugin" hidden="hidden" Parameters="'+ joinObj.paramstring + '">';
	}
}

function isNSPluginEnabled() {
	var plugLength = navigator.plugins.length;
	for (var i = 0; i < plugLength; i++) {
		if (navigator.plugins[i].name == "iLinc Communications Netscape/Mozilla Install Plugin v "+joinObj.nsPluginVersion) {
			nsPluginEnabled = true;
			i = plugLength;
		}
	}
}

function isJavaEnabled() {
	// check to see if java and java web start are enabled
	if (os == 'mac') {
		jwsEnabled = true;
	} else {
		if (!jwsEnabled) {
			if (browser != 'ie') {
				if (navigator.mimeTypes && navigator.mimeTypes.length) { 
					var x = navigator.mimeTypes['application/x-java-jnlp-file']; 
					if (x) { 
						jwsEnabled = true; 
					} 
				} 
			} else { // likely if ActiveX is disabled
				var appletCodebase = ilcCCDocsDir + '/applet';
				var appDiv = document.getElementById('join_appletDiv');
				if (appDiv) {
					appDiv.innerHTML = '<applet code=javaDetectionApplet.class codebase="' + appletCodebase + '" name="javaDetect" width=1 height=1></applet>';
				}
		
				var applet = document.javaDetect;
				if (applet == null) {
					jwsEnabled = false;
				} else {
					// ie may still recognize object, wrap in try
					try {
						// this fails if java is not installed
						jwsEnabled = (document.javaDetect.getJavaVersion() < 1.4 ? false : true);
					} catch(e) {
						jwsEnabled = false;
					}
				}
			}
		}
	}
}

function launchJavaJoin() {
	/* outlook/gw plug-in does not configure correctly
		using java on windows, should be disabled */

	/* close divs */
	showHideJoinEl('join_joinPrepare', false);

	if (jwsEnabled) {
		if (os == 'mac') {
			showHideJoinEl('join_joinJavaMacContainer', true);
			if (browser == 'safari')
				showHideJoinEl('join_jnlpDownloadSafari', true);
			else
				showHideJoinEl('join_jnlpDownloadFF', true);
			
			if (joinObj.inclHelpInfo)
				showHideJoinEl('join_joinJavaMacSupport', true);
		} else {
			showHideJoinEl('join_joinJavaWinContainer', true);

			if (browser == 'ie') {
				showHideJoinEl('join_joinWithJavaNotIE', false);
				showHideJoinEl('join_joinWithJavaIE', true);
			}

			if (!joinObj.disableStubInstaller)
				showHideJoinEl('join_joinJavaPreMl', true);

			if (joinObj.inclHelpInfo)
				showHideJoinEl('join_joinJavaWinSupport', true);

			joinType = 'java';

			/* start join timer */	
			startJoinTimer();
		}

		/*	get jnlp file
			do a redirect to avoid IE download block */
		/* use timeout to allow divs to display before redirecting */
		var javaTimeout = setTimeout("initiateJavaJoin()", 1000);
	} else {
		/* java should already be installed on a mac */
		if (os == 'win') {
			if (browser == 'ie' && (!joinObj.disableActiveXJoin || joinObj.activeXEnabled)) {
				/* move on to activex join if java not installed */
				/* reload the page with axjoin param so that activex object gets loaded */

				var inpObj = {
					'activity_id': joinObj.aID,
					'user_id': joinObj.uID,
					'on_menu': 1,
					'axjoin': 1
				};

				jCreateForm('joinForm', ilcModPerlRelPath+'/lms/vc_launch.pl','',inpObj);
				var form = document.getElementById('joinForm');
				form.submit();
			} else if (browser != 'ie' && !joinObj.disableActiveXJoin) {
				joinObj.disableJavaJoin = true;
			} else {
				if (osVersion == 'vista') {
					/* for vista, skip to stub installer */
					joinObj.disableStubInstaller = false;
					joinObj.disableJavaJoin = true;
				} else {
					showHideJoinEl('join_joinJavaWinContainer', true);
					showHideJoinEl('join_joinWithJava', false);
					showHideJoinEl('join_joinNoJava', true);
					if (!joinObj.disableStubInstaller)
						showHideJoinEl('join_joinJavaPreMnl', true);

					if (joinObj.inclHelpInfo)
						showHideJoinEl('join_joinJavaWinSupport', true);

					joinType = 'java';

					if (!joinObj.disableStubInstaller) {
						/* start join timer */	
						startJoinTimer();
					}
				}
			}
		}
	}
}

function initiateJavaJoin() {
	window.location = joinObj.jnlpLoc + (joinObj.pluginInstall == 'O' || joinObj.pluginInstall == 'G' ? '&isPlgn=' + joinObj.pluginInstall : '');
}


function getJREInstaller() {
	window.location = joinObj.JREDownloadURL;
}

function reJoinSession() {
	window.location.reload();
}

function launchManualInstall() {
	if (!joinObj.disableStubInstaller) {
		/* close divs */
		if (joinObj.pluginInstall) {
			showHideJoinEl('join_pluginPrepare', false);
			showHideJoinEl('join_pluginAXContainer', false);
			showHideJoinEl('join_pluginMozContainer', false);
		} else {
			showHideJoinEl('join_joinPrepare', false);
			showHideJoinEl('join_joinAXContainer', false);
			showHideJoinEl('join_joinMozContainer', false);
		}

		/* open stub div */
		showHideJoinEl('join_stubJoinContainer', true);
		if (joinObj.pluginInstall) {
			showHideJoinEl('join_stubPluginInstall', true);
			divButtonFocus('join_stubPluginInstallButton');
			if (joinObj.inclHelpInfo)
				showHideJoinEl('join_stubPluginInstallSupport', true);
		} else {
			showHideJoinEl('join_stubJoinInstall', true);
			divButtonFocus('join_stubJoinInstallButton');
			if (joinObj.inclHelpInfo)
				showHideJoinEl('join_stubJoinInstallSupport', true);
		}

		if (manualJoinPref) {
			var el = document.getElementById('manual_join_pref_stub');
			el.checked = true;
		}
	}
}

function aboutManualInstall() {
	if (joinObj.pluginInstall)
		showHideJoinEl('join_stubPluginInstall', false);
	else
		showHideJoinEl('join_stubJoinInstall', false);

	showHideJoinEl('join_stubJoinAbout', true);
	if (joinObj.pluginInstall) {
		showHideJoinEl('join_stubInstallAboutButton', true);
		divButtonFocus('join_stubInstallAboutButtonLink');
	} else {
		showHideJoinEl('join_stubJoinAboutButton', true);
		divButtonFocus('join_stubJoinAboutButtonLink');
	}

	if (joinObj.inclHelpInfo)
		showHideJoinEl('join_stubJoinAboutSupport', true);
}

function startJoinTimer() {
	jTimerID = setInterval(joinTimer, 1000);
}

function joinTimer() {
	jTimeLeft--;

	ellipsisTrk++;
	if (ellipsisTrk > ellipsisMax) { // reset
		ellipsisTrk = 1;
		ellipsis = '.';
	} else {
		ellipsis += '.';
	}

	/* update ellipsis */
	if (!joinObj.isRec) {
		var el = document.getElementById('joinEllipsis_'+joinType);
		if (el)
			el.innerHTML = ellipsis;
	}	

	if (jTimeLeft == 0) {
		if (jTimerID) {
			clearInterval(jTimerID);
		}
		if (os != 'mac') {
			/* switch to next div */
			if ( (joinType == 'ax' || joinType == 'plugin') && !joinObj.disableActiveXJoin) {
				showHideJoinEl('join_joinAXCon', false);

				if (!joinObj.disableStubInstaller) {
					var jtype = (joinObj.pluginInstall ? 'plugin' : 'join');

					showHideJoinEl('join_'+jtype+'AXPreMnl', false);
					showHideJoinEl('join_'+jtype+'AXSupport', false);

					showHideJoinEl('join_'+jtype+'AXMnl', true);
					divButtonFocus('join_'+jtype+'AXMnlButton');

					if (joinObj.inclHelpInfo)
						showHideJoinEl('join_'+jtype+'AXMnlSupport', true);

					if (manualJoinPref && !joinObj.pluginInstall) {
						var el = document.getElementById('manual_join_pref_ax');
						el.checked = true;
					}
				}
			} else if (joinType == 'java' && !joinObj.disableJavaJoin && !joinObj.disableStubInstaller) {
				showHideJoinEl('join_joinJavaPreMnl', false);
				showHideJoinEl('join_joinJavaSupport', false);

				showHideJoinEl('join_joinJavaMnl', true);
				divButtonFocus('join_joinJavaMnlButton');
				if (joinObj.inclHelpInfo)
					showHideJoinEl('join_joinJavaSupport', true);

				if (manualJoinPref) {
					var el = document.getElementById('manual_join_pref_java');
					el.checked = true;
				}
			}	
		} 
	}
}

function divButtonFocus(id) {
	if (document.getElementById(id))
		document.getElementById(id).focus();
}

function getInstaller() {
	var url = joinObj.installerUrl;
	window.location = url;
}

function manualJoinSel() {
	manualJoinPref = (manualJoinPref ? 0 : 1);
	var cookieOn = (manualJoinPref ? true : false);
	if (cookieOn)
		jsetCookie('manual_join_pref', '1', 180, '/', joinObj.globalCookieDomain, joinObj.useSSLCookie);
	else
		jdelCookie('manual_join_pref', '/', joinObj.globalCookieDomain, joinObj.useSSLCookie);
}

function sessionJoinedChk(aID, uID) {
	if (sjCounter < 11) {
		sjCounter = sjCounter + 1;

		if (browser != 'ie') {
			/* need special ilincAjax function for ie */
			var ajaxObj = new ilincAjax('join_sessionJoinedChk', 'join_sessionJoinedChkCallback');
			ajaxObj.addParam('activity_id', aID);
			ajaxObj.addParam('user_id', uID);
			ajaxObj.send();
		} else {
			if (document.getElementById('join_sessionJoinedIframe')) {
				document.getElementById('join_sessionJoinedIframe').src = ilcProductSuiteRelPath + '/lms/launch_chk.pl?activity_id=' + aID + '&user_id=' + uID;
			}
		}
		if (sjCounter == 2) {
			/* check every 30 seconds for 4-1/2 minutes */
			clearSJTimer();
			sjTimerID = setInterval("sessionJoinedChk(joinObj.aID, joinObj.uID)", 30000);
		}
	} else {
		clearSJTimer();
	}
}

function clearSJTimer() {
	if (sjTimerID) {
		clearInterval(sjTimerID);
		sjTimerID = null;
	}
}

function join_sessionJoinedChkCallback(retObj) {
	if (retObj.in_session == 1) {
		clearSJTimer();
		if (joinObj.intJoin && browser != 'ie') {
			if (browser == 'firefox') {
				// clear out plugin div to avoid relaunch
				var nsDiv = document.getElementById('join_NSObjectDiv');
				if (nsDiv) {
					nsDiv.innerHTML = null;
				}
			}
			/* close thickbox */
			parent.tb_remove();
		} else {
			/* close window */
			ilcCloseWin();
		}
	}
}

function ilcCloseWin() {
	/* close window without prompts */
	var browObj = jdetectBrowserProps();
	var browser = browObj["browser"]["name"];
	browser = browser.toLowerCase();

	if (browser == 'ie') {	
		if (browObj["browser"]["ie6"]) {
			window.opener = window;
			window.close();
		} else if (browObj["browser"]["ie7"]) {
			/* closes tab or window if no tabs are open */
			var objWindow = window.open(location.href, "_self");
			objWindow.close();
		}	
	} else if (browser == 'safari') {
		/* closes tab or window if no tabs are open */
		var objWindow = window.open(location.href, "_self");
		objWindow.close();
	}
}

/* session cookie functions */

function jgetCookie(cName) {
	if (document.cookie.length > 0) {
		var cStart = document.cookie.indexOf(cName+"=");
		if (cStart != -1) {
			cStart = cStart + cName.length + 1;
			var cEnd = document.cookie.indexOf(";", cStart);
			if (cEnd == -1)
				cEnd = document.cookie.length;

			return unescape(document.cookie.substring(cStart, cEnd));
		}
	} else {
		return "";
	}
}

function jsetCookie(cName, cVal, expDays, path, domain, secure) {
	var expDate = new Date();
	expDate.setDate(expDate.getDate()+expDays);
	document.cookie = cName + "=" + escape(cVal) + 
		( ( expDays ) ? ";expires=" + expDate.toUTCString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure == 1 ) ? ";secure" : "" );
}

function jdelCookie(cName, path, domain, secure) {
	// use same info as setCookie
	if ( jgetCookie(cName) ) document.cookie = cName + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ( domain ) ? ";domain=" + domain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT" + 
		( ( secure == 1 ) ? ";secure" : "" );
}

function jdetectBrowserProps() {
	//initialization, browser, os detection

	var d, dom, nu='', brow='', ie, ie4, ie5, ie5x, ie6, ie7;
	var ns4, moz, moz_rv_sub, release_date='', moz_brow, moz_brow_nu='', moz_brow_nu_sub='', rv_full=''; 
	var mac, win, old, lin, ie5mac, ie5xwin, konq, saf, op, op4, op5, op6, op7;
	var success;
		
	d = document;
	n = navigator;
	nav = n.appVersion;
	nan = n.appName;
	nua = n.userAgent;
	old = (nav.substring(0,1)<4);
	mac = (nav.indexOf('Mac')!=-1);
	win = ( ( (nav.indexOf('Win')!=-1) || (nav.indexOf('NT')!=-1) ) && !mac)?true:false;
	lin = (nua.indexOf('Linux')!=-1);

	var os = '';
	var osAry = new Array('lin', 'mac', 'win');
	for (var i=0; i<osAry.length; i++) {
		if (eval(osAry[i])) {
			os = osAry[i];
		}
	}

	var uaAry = nua.split("/");
	var tmpAry = uaAry[1].split(";");
	//var osVersion = trim(tmpAry[2]);
	var osVersion = tmpAry[2];
	osVersion = osVersion.toLowerCase();
	osVersion = (osVersion.indexOf('windows nt 6') != -1 ? 'vista' : osVersion);

	// begin primary dom/ns4 test
	// this is the most important test on the page
	if ( !document.layers )
	{
		dom = ( d.getElementById ) ? d.getElementById : false;
	}
	else { 
		dom = false; 
		ns4 = true;// only netscape 4 supports document layers
	}
	// end main dom/ns4 test
		
	op=(nua.indexOf('Opera')!=-1);
	saf=(nua.indexOf('Safari')!=-1);
	konq=(!saf && (nua.indexOf('Konqueror')!=-1) ) ? true : false;
	moz=( (!saf && !konq ) && ( nua.indexOf('Gecko')!=-1 ) ) ? true : false;
	ie=((nua.indexOf('MSIE')!=-1)&&!op);
	if (op)
	{
		str_pos=nua.indexOf('Opera');
		nu=nua.substr((str_pos+6),4);
		brow = 'Opera';
		success = 0;
	}
	else if (saf)
	{
		// updated for Safari 3
		var vAry = nua.split("/");
		str_pos=nua.indexOf('Safari');
		//nu=nua.substr((str_pos+7),5);
		var v = vAry[3];
		vArySplit = v.split(" ");
		nu = vArySplit[0];

		// based on Safari build, not AppleWebKit
		var sVerAry = new Array();
		sVerAry['412'] = '2';
		sVerAry['412.2'] = '2';
		sVerAry['412.2.2'] = '2';
		sVerAry['412.5'] = '2.0.1';
		sVerAry['416.12'] = '2.0.2';
		sVerAry['416.13'] = '2.0.2';
		sVerAry['417.8'] = '2.0.3';
		sVerAry['417.9.2'] = '2.0.3';
		sVerAry['417.9.3'] = '2.0.3';
		sVerAry['419.3'] = '2.0.4';
		sVerAry['100'] = '1.1';
		sVerAry['100.1'] = '1.1.1';
		sVerAry['125.7'] = '1.2.2';
		sVerAry['125.8'] = '1.2.2';
		sVerAry['125.9'] = '1.2.3';
		sVerAry['125.11'] = '1.2.4';
		sVerAry['125.12'] = '1.2.4';
		sVerAry['312'] = '1.3';
		sVerAry['312.3'] = '1.3.1';
		sVerAry['312.3.1'] = '1.3.1';
		sVerAry['312.5'] = '1.3.2';
		sVerAry['312.6'] = '1.3.2';
		sVerAry['85.5'] = '1';
		sVerAry['85.7'] = '1.0.2';
		sVerAry['85.8'] = '1.0.3';
		sVerAry['85.8.1'] = '1.0.3';

		if (sVerAry[nu])
			nu = sVerAry[nu];

		brow = 'Safari';
		success = 1; // safari ok
	}
	else if (konq)
	{
		str_pos=nua.indexOf('Konqueror');
		nu=nua.substr((str_pos+10),3);
		brow = 'Konqueror';
		success = 0;
	}
	// this part is complicated a bit, don't mess with it unless you understand regular expressions
	// note, for most comparisons that are practical, compare the 3 digit rv number, that is the output
	// placed into 'nu'.
	else if (moz)
	{
		// regular expression pattern that will be used to extract main version/rv numbers
		pattern = /[(); \n]/;
		// moz type array, add to this if you need to
		moz_types = new Array( 'Firebird', 'Phoenix', 'Firefox', 'Galeon', 'K-Meleon', 'Camino', 'Epiphany', 
			'Netscape6', 'Netscape', 'MultiZilla', 'Gecko Debian', 'rv' );
		rv_pos = nua.indexOf( 'rv' );// find 'rv' position in nua string
		rv_full = nua.substr( rv_pos + 3, 6 );// cut out maximum size it can be, eg: 1.8a2, 1.0.0 etc
		// search for occurance of any of characters in pattern, if found get position of that character
		rv_slice = ( rv_full.search( pattern ) != -1 ) ? rv_full.search( pattern ) : '';
		//check to make sure there was a result, if not do nothing
		// otherwise slice out the part that you want if there is a slice position
		( rv_slice ) ? rv_full = rv_full.substr( 0, rv_slice ) : '';
		// this is the working id number, 3 digits, you'd use this for 
		// number comparison, like if nu >= 1.3 do something
		nu = rv_full.substr( 0, 3 );
		for (i=0; i < moz_types.length; i++)
		{
			if ( nua.indexOf( moz_types[i]) !=-1 )
			{
				moz_brow = moz_types[i];
				break;
			}
		}
		if ( moz_brow )// if it was found in the array
		{
			str_pos=nua.indexOf(moz_brow);// extract string position
			moz_brow_nu = nua.substr( (str_pos + moz_brow.length + 1 ) ,3);// slice out working number, 3 digit
			// if you got it, use it, else use nu
			moz_brow_nu = ( isNaN( moz_brow_nu ) ) ? moz_brow_nu = nu: moz_brow_nu;
			moz_brow_nu_sub = nua.substr( (str_pos + moz_brow.length + 1 ), 8);
			// this makes sure that it's only the id number
			sub_nu_slice = ( moz_brow_nu_sub.search( pattern ) != -1 ) ? moz_brow_nu_sub.search( pattern ) : '';
			//check to make sure there was a result, if not do  nothing
			( sub_nu_slice ) ? moz_brow_nu_sub = moz_brow_nu_sub.substr( 0, sub_nu_slice ) : '';
		}
		if ( moz_brow == 'Netscape6' )
		{
			moz_brow = 'Netscape';
		}
		else if ( moz_brow == 'rv' || moz_brow == '' )// default value if no other gecko name fit
		{
			moz_brow = 'Mozilla';
		} 
		if ( !moz_brow_nu )// use rv number if nothing else is available
		{
			moz_brow_nu = nu;
			moz_brow_nu_sub = nu;
		}
		if (n.productSub)
		{
			release_date = n.productSub;
		}
		brow = moz_brow;
		nu = moz_brow_nu;

		if (brow == 'Netscape') {
			success = (parseFloat(nu) >= 7 ? 1 : 0);
		} else {
			success = 1;
		}
	}
	else if (ie)
	{
		str_pos=nua.indexOf('MSIE');
		nu=nua.substr((str_pos+5),3);
		//brow = 'Microsoft Internet Explorer';
		brow = 'IE';	
		success = (parseFloat(nu) >= 5 && !mac ? 1 : 0);
	}
	// default to navigator app name
	else 
	{
		brow = nan;
		nu=parseFloat(navigator.appVersion);

		if (brow == 'Netscape') {
			success = (parseFloat(nu) >= 7 ? 1 : 0);
		} else {
			success = 0;
		}
	}		
	op5=(op&&(nu.substring(0,1)==5));
	op6=(op&&(nu.substring(0,1)==6));
	op7=(op&&(nu.substring(0,1)==7));
	ie4=(ie&&!dom);
	ie5=(ie&&(nu.substring(0,1)==5));
	ie6=(ie&&(nu.substring(0,1)==6));
	ie7=(ie&&(nu.substring(0,1)==7));

	// default to get number from navigator app version.
	if(!nu) {
		nu = nav.substring(0,1);
		if (brow == 'Netscape') {
			success = (parseFloat(nu) >= 7 ? 1 : 0);
		} else {
			success = 0;
		}
	}
	
	/*ie5x tests only for functionality. dom or ie5x would be default settings. 
	Opera will register true in this test if set to identify as IE 5*/
	ie5x=(d.all&&dom);
	ie5mac=(mac&&ie5);
	ie5xwin=(win&&ie5x);
	var gecko = (nua.indexOf('Gecko')!= -1);

	var ret = new Object();
	ret["browser"] = new Object();
	ret["browser"]["name"] = brow;
	ret["browser"]["version"] = nu;
	ret["browser"]["supported"] = success;
	ret["browser"]["ie6"] = (ie6 ? true : false);
	ret["browser"]["ie7"] = (ie7 ? true : false);
	ret["browser"]["gecko"] = (gecko ? true : false);
	ret["os"] = new Object();
	ret["os"]["name"] = os;
	ret["os"]["version"] = osVersion;
	ret["success"] = success;

	return ret;
}

function enterJoinSubmit(e, mode) {
	if (window.event && window.event.keyCode == 13) {
		if (mode == 'm')
			getInstaller();

		return false;
	} else if (e && e.which == 13) {
		if (mode == 'm')
			getInstaller();

		return false;
	} else {
		return true;
	}
}

function jCreateForm(fId,fAction,fTarget,iObj) {
	var bAry = document.getElementsByTagName('body');
	var b = bAry[0];
	if (b) {
		var f = document.createElement('form');
		if (f) {
			f.setAttribute('name',fId);
			f.setAttribute('id',fId);
			f.setAttribute('method','post');
			f.setAttribute('action',fAction);
			f.setAttribute('target',fTarget);
			f.style.display = 'none';
			b.appendChild(f);
 
			for (iId in iObj) {
				var i = document.createElement('input');
				if (i) {
					i.setAttribute('name',iId);
					i.setAttribute('id',iId);
					i.setAttribute('type','hidden');
					i.setAttribute('value',iObj[iId]);
					f.appendChild(i);
				}
			}
		}
	}
}

function jOpenWin(url, winName, winWidth, winHeight, scrollbars) {
	var params;

	if (winWidth && winHeight) {
		winX = (screen.width - winWidth)/2;
		winY = (screen.height - winHeight)/2;

		params = "width=" + winWidth + ",height=" + winHeight + ",status=no,resizable=yes,toolbar=no,scrollbars=" + scrollbars + ",menubar=no,screenX=" + winX + ",screenY=" + winY + ",left=" + winX + ",top=" + winY;
	} else { // open full screen
 		params  = 'width='+screen.width;
 		params += ', height='+screen.height;
 		params += ', top=0, left=0'
 		params += ', fullscreen=yes';
	}

	var win = window.open(url, winName, params);
	if (win) win.focus();

	return win;
}

