var isNav5 = false;
var isNav4 = false;
var isNav  = false;
var isSafari  = false;
var isIE4  = false;
var isIE5  = false;
var isIE   = false;
var isWin  = false;
var isMac  = false;
var hasPopup = false;
setDefaults();

if (navigator.appName == "Netscape") {
	isNav = true;
	if (parseInt(navigator.appVersion) == 4) isNav4 = true;
	if (parseInt(navigator.appVersion) == 5) isNav5 = true;
	if (navigator.appVersion.indexOf("Safari") != -1) isSafari = true;
} else if (navigator.appName == "Microsoft Internet Explorer") {
	isIE = true;
	if (navigator.appVersion.indexOf("MSIE 4") != -1) isIE4 = true;
	if (navigator.appVersion.indexOf("MSIE 5") != -1) isIE5 = true;
}

if (navigator.platform.indexOf("Win") != -1) isWin = true;
if (navigator.platform.indexOf("Mac") != -1) isMac = true;

//For now in CD archives, Java doesn't matter
//if (ckJava) { checkJava(); }
ckJava = false;
javaVer = 0;

function setDefaults() {
	if (typeof ckMedia == "undefined") ckMedia = true;
	if (typeof ckSW == "undefined") ckSW = true;
	if (typeof ckFlash == "undefined") ckFlash = true;
	if (typeof ckJava == "undefined") ckJava = false;
	if (typeof ckPopup == "undefined") ckPopup = false;
	if (typeof WMP_version == "undefined") WMP_version = "0";
	if (typeof WMP7_version == "undefined") WMP7_version = 'unknown';
}

function popupWindow() {
	pwin = window.open('about:blank','popup','resizable=no,width=100,height=100,left=10,top=10,screenX=10,screenY=10');
	if (pwin) {
		hasPopup = true;
		setTimeout('pwin.close()',2000);
	}
}

function OpenWindow(theURL,winName,features) {
	avawin = window.open(theURL,winName,features);
	avawin.focus();
}

function CloseWindow() {
	avawin.close();
}

function AvaWinPlayer(theURL,w,h,r) {
	if (typeof w == "undefined") w = 750;
	if (typeof h == "undefined") h = 563;
	if (typeof r == "undefined") r = "yes";
	playerwin =  window.open(theURL,'AvaPlayer','resizable=' + r + ',width=' + w + ',height=' + h + ',left=10,top=10,screenX=10,screenY=10');
	playerwin.focus();
}

//Deprecated as of 4.1, but needed for older entry pages
function AvaWinPlayer_noresize(theURL) {
	playerwin = window.open(theURL,'AvaPlayer','resizable=no,width=750,height=563,left=10,top=10,screenX=10,screenY=10');
	playerwin.focus();
}

function AvaWinAdmin(theURL) {
	if ((isMac) && (isIE)) {
		adminwin =  window.open(theURL,'AvaAdmin','resizable=yes,width=900,height=700,left=5,top=5,screenX=5,screenY=5');
	} else {
		adminwin = window.open(theURL,'AvaAdmin','resizable=no,width=900,height=700,left=5,top=5,screenX=5,screenY=5');
	}
	adminwin.focus();
}

function replaceEntryPage(thisUrl) {
	// Dummy function in case this gets called unintentionally
	// used in preflt_bottom.php, where it is also defined locally
}

function AVA_OpenOnUnload(theURL,w,h) {
  winOpts = "width=" + w + ",height=" + h + ",scrollbars=yes,left=10,top=10,screenX=10,screenY=10";
  window.open(theURL,'_blank',winOpts);
}

function ckWinResize(mediaType) {
	if (mediaType == "Real") {
		window.resizeBy(1,1);
	}
	if ((mediaType == "QuickTime") && isWin) {
		setTimeout('window.resizeBy(1,1)', 15000);
	}
}

function redrawVideo(mediaType, left) {
	if (typeof Layer1.style == "object") {
		Layer1.style.left = left - 1;
		var s = 'Layer1.style.left = "' + left + '"';
		setTimeout(s, 1);
	}
}

function DisplayConfig(preflightLink, usingRP, usingWMP, usingQT, bgColor, textColor, textSize, textFont, eventID, flashVer) {
	var extraText, statusRP, statusWMP, statusSW, statusFlash, statusJava, statusPopup, statusborderColor;
	borderColor = textColor;
	if (preflightLink == "no") {
		extraText = "&nbsp;&nbsp;&nbsp;&nbsp;";
	} else {
		extraText = 'Make sure you are ready to go! Run your computer through the <a href="/preflight/index.php?eventID=' + eventID + '">Player Preflight tests<\/a>.';
	}
	var installed = '<img src="lib/checkmark.gif" width=18 height=15>';
	var notinstalled = '&nbsp;&nbsp;';
	if (ckPopup) {
		popupWindow();
		if (hasPopup) { statusPopup = installed; } else { statusPopup = notinstalled; }
	}
	// has* and javaVer defined in mediacheck.js
	if (hasRP) { statusRP = installed; } else { statusRP = notinstalled; }
	if (hasWMP) { statusWMP = installed; } else { statusWMP = notinstalled; }
	if (WMP_version != "0") {
		statusWMP += 'version: <b>' + WMP_version + '<\/b>';
		if ((WMP_version == "6.4") && (WMP7_version == "unknown")) statusWMP += '+<br>(exact version unknown)';
	}
	if (hasQT) { statusQT = installed; } else { statusQT = notinstalled; }
	if (ckJava && hasJava) {
		statusJava = installed + 'version: <b>' + javaVer + '<\/b>';
	} else {
		statusJava = notinstalled;
	}
	if (hasShockwave) { statusSW = installed; } else { statusSW = notinstalled; }
	statusSW += 'version: <b>' + shockwaveVer + '<\/b>';
	// flashVer defined in flashck.js
	if (typeof flashVer != "undefined") { 
		if (flashVer < 6) { statusFlash = notinstalled; } else { statusFlash = installed; }
		statusFlash += 'version: <b>' + flashVer + '<\/b>';
	} else {
		statusFlash = "unknown";
	}
	var tableStyle;
	tableStyle = 'style="border-style: solid; border-width: 2px;';
	tableStyle += ' border-color: ' + borderColor + ';';
	tableStyle += ' background-color: ' + bgColor + ';';
	tableStyle += '"';
	document.write('<table width=516 cellpadding=2 cellspacing=0 border=0 ' + tableStyle + '>\n');
	document.write('<tr><td width=340>\n');
	document.write('<table width=340 cellpadding=3 cellspacing=0 border=0>\n');
	document.write('<tr><td colspan=2 align=center><b>Browser Status<\/b><\/td><\/tr>\n');
	if (usingRP) document.write('<tr><td align=right valign=top>RealPlayer:<\/td><td>' + statusRP + '<\/td><\/tr>\n');
	if (usingWMP) document.write('<tr><td align=right valign=top>Windows Media:<\/td><td>' + statusWMP + '<\/td><\/tr>\n');
	if (usingQT) document.write('<tr><td align=right valign=top>QuickTime:<\/td><td>' + statusQT + '<\/td><\/tr>\n');
	if (ckFlash) document.write('<tr><td align=right valign=top>Macromedia Flash:<\/td><td>' + statusFlash + '<\/td><\/tr>\n');
	if (ckSW) document.write('<tr><td align=right valign=top>Macromedia Shockwave:<\/td><td>' + statusSW + '<\/td><\/tr>\n');
	if (ckJava) document.write('<tr><td align=right valign=top>Java:<\/td><td>' + statusJava + '<\/td><\/tr>\n');
	if (ckPopup) document.write('<tr><td align=right valign=top>Window Pop-ups:<\/td><td>' + statusPopup + '<\/td><\/tr>\n');
	document.write('<\/table><\/td>\n');
	document.write('<td width=7>&nbsp;&nbsp;<\/td>\n');
	document.write('<td width=146>' + extraText + '<\/td>\n');
	document.write('<td width=7>&nbsp;&nbsp;<\/td>\n');
	document.write('<\/tr><\/table>\n');
	document.write('<br>\n');
}

function DisplayConfigMsg() {
	// Shockwave
	if ((ckSW) && (hasShockwave == false)) {
		var xx;
		if (typeof minShockwaveVer == "undefined") minShockwaveVer = 8.5;
		if (typeof avaMode == "undefined") avaMode = "player";
		if (avaMode == "player") {xx = "Shockwave Version link";} else {xx = "Avacaster Administrator";}
		document.write('<p>To use the ' + xx + ', you must have Macromedia Shockwave (version ' + minShockwaveVer + ' or greater). Install it by <a href="http://www.macromedia.com/shockwave/download/">clicking here<\/a>.');
		if (isWin && isIE) 
			document.write(' Windows Internet Explorer users: the browser will try to install it automatically if you click a Shockwave link below.)');
		if (isMac) 
			document.write(' OS X: To find out the exact version, check the Preflight page');
		document.write('<\/p>');
	}

	// Flash
	if ((ckFlash) && (actualFlashVersion < 6)) {
		document.write('<p>To use the Flash Version link, you must have Macromedia Flash (version 6.0 or greater). Install it by <a href="http://www.macromedia.com/software/flashplayer/">clicking here<\/a>. (Windows Internet Explorer users: the browser may attempt to install Flash automatically.)<\/p>');
	}

	if (ckMedia) {
		// Real
		if ((usingRP == true) && (hasRP == false)) {
			document.write('<p>RealPlayer was not detected. If you want to use <a href="http://proforma.real.com/real/player/player.html?src=001222realhome_1,010110rpchoice_h1&amp;dc=124123122" target="_blank">RealPlayer<\/a> you must download the latest version.<\/p>');
		}
		// Windows Media
		if ((usingWMP == true) && (hasWMP == false)) {
			var dnld = '<a href="http://www.microsoft.com/windows/windowsmedia/en/download/default.asp" target="_blank">download the latest version<\/a>.';
			if (WMP_version == "0") {
				document.write('<p>Windows Media was not detected. To use this media type, please ' + dnld);
			} else {
				if (isIE && isWin) {
					document.write('<p>You need a newer version of Windows Media (' + minWMPver + '). To use this media type, please ' + dnld);
				} else {
					document.write('<p>Unable to determine whether Windows Media is the minimum required version (' + minWMPver + '). You may need to ' + dnld);
				}
			}
			if (isMac) 
			document.write(' Please note that Windows Media is not recommended on Macs unless using version 9 in Safari on OS 10.3.');
			document.write('<\/p>');
		}
		// QuickTime
		if ((usingQT == true) && (hasQT == false)) {
			document.write('<p>QuickTime was not detected. If you want to use <a href="http://www.apple.com/quicktime/download/" target="_blank">QuickTime<\/a> you must download the latest version.<\/p>');
		}
	}
	
	// Java
	var msg = '';
	var n = 'Update'; var u; var u2; var f;
	if (ckJava) {
		if (hasJava == false) {
			msg = 'Java was not detected. Java is required';
		} else if (javaVer == 'unknown') {
			msg = 'Unable to determine your Java version. Java ' + minJavaVer + ' or higher is recommended';
		} else if (hasMinJava == false) {
			msg = 'A newer version of Java (' + minJavaVer + ' or higher) is recommended';
		} else { msg = ''; }
	}
	if (msg != '') {
		document.write('<p>' + msg + ' if you intend to use the Screen Sharing feature (ask your event coordinator if you are not sure).');
		if (isMac) {
			u = 'http://www.info.apple.com/support/downloads.html';
			u2 = 'http://docs.info.apple.com/article.html?artnum=75097';
			f = 'scrollbars=yes,resizable=yes,width=640,height=480,left=25,top=25,screenX=25,screenY=25';
			document.write(' Visit the Apple web site to download the latest <a href="#" onclick="OpenWindow(\'' + u + '\',\'' + n + '\',\'' + f + '\');return false;">Java OSX Update<\/a> or <a href="#" onclick="OpenWindow(\'' + u2 + '\',\'' + n + '\',\'' + f + '\');return false;">MRJ (OS9 users)<\/a>.');
			if (isIE) document.write(' IE 5.2 users on OS X: Note that it may not be possible to update your Java version.');
		} else {
			u = 'http://www.java.com/en/download/';
			f = 'menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=640,height=480,left=25,top=25,screenX=25,screenY=25';
			document.write(' Screen sharing may work fine, but if it doesn\'t, try installing <a href="#" onclick="OpenWindow(\'' + u + '\',\'' + n + '\',\'' + f + '\');return true;">Java from Sun Microsystems<\/a>.');
		}
		document.writeln('<\/p>');
	}
	
	// Popup windows
	if ((ckPopup) && (hasPopup == false)) {
		document.writeln('<p>Pop-up windows are blocked in this browser. You will not be able to use the Avacaster Sharing feature unless you unblock them. Ask your event coordinator if you are not sure whether this feature will be used.<\/p>');
	}
	
}

