var ie      = new RegExp("msie", "i");
var firefox = new RegExp("firefox", "i");
var safari  = new RegExp("safari", "i");

var hasActiveX = TestActiveX();
var hasPlugin  = TestPlugin();

function eraseAlbumCover()
{
	if (!document.form.cover.value)
	{
		document.form.deleteimg.value = confirm("You left Album Cover blank. " +
									"Click OK to keep the existing image or " +
									"Cancel to delete it from the server.");
	}	
}
function changeOrder(num, direction)
{
	document.form.action.value = direction;
	document.form.num.value=num;
	document.form.submit();
}
function updateClicked()
{
	document.form.action.value="update";
	document.form.submit();
}

function editTracksClicked()
{
	document.form.action.value="edittracks";
	document.form.submit();
}

function editClicked(num)
{
	document.form.action.value="edit";
	document.form.num.value=num;
	document.form.submit();
}
function deleteClicked(num)
{
	if (confirm("Are you sure you want to delete?"))
	{
		document.form.action.value="delete";
		document.form.num.value=num;	
		document.form.submit();
	}
}
function clearAction()
{
	document.form.action.value="";
}

function showAction()
{
	alert(document.form.action.value);
}

function TestActiveX()
{
	try 
	{	
		return (window.ActiveXObject || window.GeckoActiveXObject)
	}
	// Something weird just happened..
	catch(e) { return false; }
}

function playFile(filename) {		
	try {
		var player;
		if (navigator.appName.indexOf("Microsoft")!= -1) {
			//alert("IE" + filename);
			player = window["groovedgeplayer"];
		} else {
			//alert("IE sucks.  Let's do this right.\n" + filename);
			player = document["groovedgeplayer"];
		}
		if (player)
			player.playFile(filename);
		else
			alert("Error loading player.");
	}
	catch (e) {
		alert("Error: " + e.toString());
	}
}


/*
 * Depricated
*/
function TestPlugin()
{
	try 
	{	
		return (navigator.mimeTypes["application/x-mplayer2"].enabledPlugin)
	}
	// Something weird just happened..
	catch(e) { return false; }
}


/*
 * Depricated
*/
function playMedia(file)
{
	var player = document.getElementById('MediaPlayer1');									
	if (player)
	{
		//alert("playing file: " + file);
		//alert(navigator.userAgent);
		try 
		{
			// Here we can script the player	
			if (hasActiveX)
			{
				//alert("using activeX")
				player.Stop();
				player.FileName = file;
				player.Play();
			}
			
			// Here we have to control the 
			// player with server side code
			else if (hasPlugin)
			{
				//alert("using plugin");
				document.macsNeedLoveToo.src.value = file;
				document.macsNeedLoveToo.submit();
			}
		} catch(e)
		{
			// Something weird just happened..
			//alert(e.toString());
			
			// IF Firefox, detect the version and ask user if they
			// want to install the activeX plugin from http://www.iol.ie/~locka/mozilla/plugin.htm
			if (hasActiveX && firefox.test(navigator.userAgent))
			{
				// get the version
				var firefoxVersion = new RegExp("firefox\/([0-9\.]+).*$", "i");
				firefoxVersion.exec(navigator.userAgent)
				var ver = RegExp.lastParen
				var askInstall = 'This page requires a plugin for Firefox that is not intalled. Install it now?';

				//alert("Firefox " + ver);
				
				switch (ver)
				{
					case "1.5.0.2":
						if (confirm(askInstall)) installAxFF15();
						break;
					case "1.5.0.1":
						if (confirm(askInstall)) installAxFF15();
						break;
					case "1.5":
						if (confirm(askInstall)) installAxFF15();
						break;
					case "1.0.7":
						if (confirm(askInstall)) installAxFF107();
						break;
					case "1.0.6":
						if (confirm(askInstall)) installAxFF106();
						break;
					case "1.0.4":
						if (confirm(askInstall)) installAxFF104();
						break;
					case "1.0.3":
						if (confirm(askInstall)) installAxFF103();
						break;
					case "1.0":
						if (confirm(askInstall)) installAxFF10();
						break;
					default:
						document.location = "firefox.php";
						break;
				}
			}
		}		
	}
}

var site = 'http://www.iol.ie/~locka/mozilla/';
function installAxFF15() { xpi={'Mozilla Firefox 1.5 ActiveX Plug-in': site + 'mozactivex-ff-15.xpi'}; InstallTrigger.install(xpi); } 
function installAxFF107() { xpi={'Mozilla Firefox 1.0.7 ActiveX Plug-in': site + 'mozactivex-ff-107.xpi'}; InstallTrigger.install(xpi); } 
function installAxFF106() { xpi={'Mozilla Firefox 1.0.6 ActiveX Plug-in': site + 'mozactivex-ff-106.xpi'}; InstallTrigger.install(xpi); } 
function installAxFF104() { xpi={'Mozilla Firefox 1.0.4 ActiveX Plug-in': site + 'mozactivex-ff-104.xpi'}; InstallTrigger.install(xpi); } 
function installAxFF103() { xpi={'Mozilla Firefox 1.0.3 ActiveX Plug-in': site + 'mozactivex-ff-103-2.xpi'}; InstallTrigger.install(xpi); } 
function installAxFF10() { xpi={'Mozilla Firefox 1.0 ActiveX Plug-in': site + 'mozactivex-ff-10.xpi'}; InstallTrigger.install(xpi); } 