onAvailable(fullyLoaded,deMoronize);

function pickColor()
{
	var color = new RGBColor(threec[2]);
	document.getElementById("color-wrap").style.backgroundColor = threec[2];
	setCPDrawColor(document.getElementById("colorBox"),"rgb(" + color.r + ", " + color.g + ", " + color.b + ")");
	setSquare(adeg);
	prevc = threec[2];
	return false;
}
function validate_field(field,type,len)
{
	var valid = false;
	valid = validate_required(field,"Please enter a value");
	var value = field.value;
	if (valid)
	{
		switch(type)
		{
			case "string":
			if (len != null && value.length > len)
			{
				valid = false;
				alert("Please enter fewer then "+len+" characters");
			}
			else if(value == '')
			{
				valid = false;
				alert("Please enter some text into this field");
			}
			break;
			case "textarea":
			if (len != null && value.length > len)
			{
				valid = false;
				alert("Please enter fewer then "+len+" characters");
			}
			else if (value == '')
			{
				valid = false;
				alert("Please enter some text into the box");
			}
			break;
			case "integer":
			if (isNaN(parseInt(value)))
			{
				valid = false;
				field.value = '';
				alert("Please enter a valid number");
			}
			else field.value = parseInt(value);
			break;
			case "email":
			valid = validate_email(field,"Please enter a valid email address");
			break;
		}
	} // if (valid)

	if (!valid) field.style.borderColor = "#FF0000";
	else field.style.borderColor = "#DDDDDD";
	return valid;
}

function validate_required(field,alerttxt)
{
	with (field)
	{
		if (value==null||value=="")
		{
			if (alerttxt != null && alerttxt != "") alert(alerttxt);
			field.style.borderColor = "#FF0000";
			return false;
		}
		else
		{
			field.style.borderColor = "#DDDDDD";
			return true
		}
	}
}

function validate_email(field,alerttxt)
{
	with (field)
	{
		apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")
		if (1 > apos || 2 > dotpos-apos)
		{alert(alerttxt);return false}
		else {return true}
	}
}

var previousSelection;

function playsound()
{
	var playlist = document.getElementById("trial_id");
	var player = document.getElementById("player");

	var selection = playlist[playlist.selectedIndex].value;

	if (selection !== "")
	{
		if (selection.indexOf("mp3") === (selection.length - 3))
		{
			objectStr = "<object type='application/x-shockwave-flash' data='./files/player.swf' id='audioplayer1' height='24' width='290'>"+
			"<param name='movie' value='./files/player.swf'/>"+
			"<param name='FlashVars' value='playerID=1&amp;soundFile="+selection+"&amp;autostart=yes'/>"+
			"<param name='quality' value='high'/>"+
			"<param name='menu' value='false'/>"+
			"<param name='wmode' value='transparent'/>"+
			"<embed height='42' width='400' src='"+selection+"' controller='true' autoplay='true'></embed>"+
			"<noembed><bgsound src='"+selection+"'/></noembed>"+
			"</object>";
		}
		else objectStr = "<a href='"+selection+"' target='_new'>Listen to this sound.</a>"
		if (selection !== previousSelection) player.innerHTML = objectStr;
		previousSelection = selection;
	}
	else
	{
		player.innerHTML = "";
	}
}

function testsound(selSound) {
	audioFile = "./audio/"+selSound+".mid";
	//alert(audioFile);
	//audioFile = URLEncode(audioFile);

	var testplayer = document.getElementById("testplayer");

	objectStr = "<object id='MediaPlayer' height='46' classid='CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95' standby='Loading Windows Media Player components...' type='application/x-oleobject' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112'>";
	objectStr += "<param name='filename' value='"+audioFile+"'>";
	objectStr += "<param name='Showcontrols' value='True'>";
	objectStr += "<param name='autoStart' value='True'>";
	objectStr += "<param name='transparentatStart' value='true'>";
	objectStr += "<param name='animationatStart' value='true'>";
	objectStr += "<embed type='application/x-mplayer2' src='"+audioFile+"' name='MediaPlayer'></embed>";
	objectStr += "</object>";
	//alert(objectStr);
	testplayer.innerHTML = objectStr;
}
