// JavaScript Document
function setFocus(objID, milisecs)
{
	window.document.getElementById(objID).focus();
	clearTimeout(myTimer);
}

//var myTimer = setTimeout(setFocus, milisecs);

function embeddVideoplayer(playType, appInput, vidInput, autoPlay, videoWidth, videoHeight, buffLength, ccSource, ccAtStart, ccPosition, ccOpacity, ccTextSize, windowMode, bgColorHex)
{
	if (ccPosition.toLowerCase() == "under")
	{
		var stageWidth = Number(videoWidth) + 10;
		var stageHeight = Number(videoHeight) + 90;
	}
	else
	{
		var stageWidth = Number(videoWidth) + 10;
		var stageHeight = Number(videoHeight) + 50;
	}
	
	document.writeln("<table border=\"0\" width=\"" + stageWidth + "\" height=\"" + stageHeight + "\" cellspacing=\"0\" cellpadding=\"0\">");
	document.writeln("<tr><td>");	
	document.writeln("<script language=\"javascript\">");	
	document.writeln("	if (AC_FL_RunContent == 0) {");
	document.writeln("		alert(\"This page requires AC_RunActiveContent.js.\");");
	document.writeln("	} else {");
	document.writeln("		AC_FL_RunContent(");
	document.writeln("			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',");
	document.writeln("			'width', '" + stageWidth + "',");
	document.writeln("			'height', '" + stageHeight + "',");
	document.writeln("			'src', 'http://www.csupomona.edu/media/ezplayer/swf/ez_player',");
	document.writeln("			'quality', 'high',");
	document.writeln("			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',");
	document.writeln("			'align', 'left',");
	document.writeln("			'play', 'true',");
	document.writeln("			'loop', 'true',");
	document.writeln("			'scale', 'showall',");
	document.writeln("			'wmode', '" + windowMode + "',");
	document.writeln("			'devicefont', 'false',");
	document.writeln("			'id', 'ez_player',");
	document.writeln("			'bgcolor', '" + bgColorHex + "',");
	document.writeln("			'name', 'ez_player',");
	document.writeln("			'menu', 'true',");
	document.writeln("			'allowFullScreen', 'true',");
	document.writeln("			'allowScriptAccess','sameDomain',");
	document.writeln("			'movie', 'http://www.csupomona.edu/media/ezplayer/swf/ez_player',");
	document.writeln("			'salign', 'lt',");
	document.writeln("			'flashvars', 'playType=" + playType + "&appInput=" + appInput + "&vidInput=" + vidInput + "&autoPlay=" + autoPlay + "&videoWidth=" + videoWidth + "&videoHeight=" + videoHeight + "&buffLength=" + buffLength + "&ccSource=" + ccSource + "&ccAtStart=" + ccAtStart + "&ccPosition=" + ccPosition + "&ccOpacity=" + ccOpacity + "&ccTextSize=" + ccTextSize + "'");
	document.writeln("			); //end AC code");
	document.writeln("	}");
	document.writeln("</script>");
	document.writeln("</td></tr>");	
	document.writeln("</table>");
}

function generatePreview(playType, appInput, vidInput, autoPlay, videoWidth, videoHeight, buffLength, ccSource, ccAtStart, ccPosition, ccOpacity, ccTextSize, windowMode, bgColorHex)
{
	if (ccPosition.toLowerCase() == "under")
	{
		var stageWidth = Number(videoWidth) + 10;
		var stageHeight = Number(videoHeight) + 90;
	}
	else
	{
		var stageWidth = Number(videoWidth) + 10;
		var stageHeight = Number(videoHeight) + 50;
	}
	
	var previewHTML = "";
	previewHTML += "<table border=\"0\" width=\"" + stageWidth + "\" height=\"" + stageHeight + "\" cellspacing=\"0\" cellpadding=\"0\">\n";
	previewHTML += "<tr><td>\n";
	previewHTML  += "	<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"" + stageWidth + "\" height=\"" + stageHeight + "\" id=\"ez_player\" align=\"left\">";
	previewHTML  += "	<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
	previewHTML  += "	<param name=\"allowFullScreen\" value=\"true\" />";
	previewHTML  += "	<param name=\"movie\" value=\"http://www.csupomona.edu/media/ezplayer/swf/ez_player.swf\" />";
	previewHTML  += "	<param name=\"quality\" value=\"high\" />";
	previewHTML  += "	<param name=\"wmode\" value=\"" + windowMode + "\" />";
	previewHTML  += "	<param name=\"bgcolor\" value=\"" + bgColorHex + "\" />";
	previewHTML  += "	<embed src=\"http://www.csupomona.edu/media/ezplayer/swf/ez_player.swf\" quality=\"high\" salign=\"lt\" wmode=\"" + windowMode + "\" bgcolor=\"" + bgColorHex + "\" width=\"" + stageWidth + "\" height=\"" + stageHeight + "\" name=\"ez_player\" align=\"left\" allowScriptAccess=\"sameDomain\" allowFullScreen=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" flashvars=\"playType=" + playType + "&appInput=" + appInput + "&vidInput=" + vidInput + "&autoPlay=" + autoPlay + "&videoWidth=" + videoWidth + "&videoHeight=" + videoHeight + "&buffLength=" + buffLength + "&ccSource=" + ccSource + "&ccAtStart=" + ccAtStart + "&ccPosition=" + ccPosition + "&ccOpacity=" + ccOpacity + "&ccTextSize=" + ccTextSize + "\" />";
	previewHTML  += "	</object>";
	previewHTML += "</tr></td>\n";
	previewHTML += "</table>\n";
	
	window.document.getElementById("preview").innerHTML = previewHTML;	
}

function generateCode()
{
	var progressive = window.document.getElementById("StreamType_0").checked;
	var streaming = window.document.getElementById("StreamType_1").checked;
	
	var playType = streaming ? "streaming" : "progressive";
	var appInput = window.document.getElementById("appInput").value;
	var vidInput = window.document.getElementById("vidInput").value;
	var videoWidth = window.document.getElementById("videoWidth").value;
	var videoHeight = window.document.getElementById("videoHeight").value;
	var autoPlay = window.document.getElementById("autoPlay").value;
	var buffLength = window.document.getElementById("buffLength").value;
	var ccSource = window.document.getElementById("ccSource").value;	
	var ccAtStart = window.document.getElementById("ccAtStart").value;
	var ccPosition = window.document.getElementById("ccPosition").value;
	var ccOpacity = window.document.getElementById("ccOpacity").value;
	var ccTextSize = window.document.getElementById("ccTextSize").value;
	var windowMode = window.document.getElementById("windowMode").value;
	var bgColorHex = window.document.getElementById("bgColorHex").value;
	
	window.document.getElementById("generatedCode").value = "";
	
	if (ccPosition.toLowerCase() == "under")
	{
		var stageWidth = Number(videoWidth) + 10;
		var stageHeight = Number(videoHeight) + 90;
	}
	else
	{
		var stageWidth = Number(videoWidth) + 10;
		var stageHeight = Number(videoHeight) + 50;
	}
	
	var code = "";
	code += "<table border=\"0\" width=\"" + stageWidth + "\" height=\"" + stageHeight + "\" cellspacing=\"0\" cellpadding=\"0\">\n";
	code += "<tr><td>\n";
	code += "<script language=\"javascript\">AC_FL_RunContent = 0;</script>\n";
	code += "<script src=\"http://www.csupomona.edu/media/ezplayer/js/AC_RunActiveContent.js\" language=\"javascript\"></script>\n";
	code += "<script src=\"http://www.csupomona.edu/media/ezplayer/js/functions.js\" language=\"javascript\"></script>\n";
	code += "<script language=\"javascript\" type=\"text/javascript\">\n";
	code += "embeddVideoplayer('" + playType + "','" + appInput + "','" + vidInput + "','" + autoPlay + "','" + videoWidth + "','" + videoHeight + "','" + buffLength + "','" + ccSource + "','" + ccAtStart + "','" + ccPosition + "','" + ccOpacity + "','" + ccTextSize + "','" + windowMode + "','" + bgColorHex + "');\n";
	code += "</script>\n";

	code += "<noscript>\n";
	code += "	<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"" + stageWidth + "\" height=\"" + stageHeight + "\" id=\"ez_player\" align=\"left\">\n";
	code += "	<param name=\"allowScriptAccess\" value=\"sameDomain\" />\n";
	code += "	<param name=\"allowFullScreen\" value=\"true\" />\n";
	code += "	<param name=\"movie\" value=\"http://www.csupomona.edu/media/ezplayer/swf/ez_player.swf\" />\n";
	code += "	<param name=\"quality\" value=\"high\" />\n";
	code += "	<param name=\"wmode\" value=\"" + windowMode + "\" />\n";
	code += "	<param name=\"bgcolor\" value=\"" + bgColorHex + "\" />\n";
	code += "	<embed src=\"http://www.csupomona.edu/media/ezplayer/swf/ez_player.swf\" quality=\"high\" salign=\"lt\" wmode=\"" + windowMode + "\" bgcolor=\"" + bgColorHex + "\" width=\"" + stageWidth + "\" height=\"" + stageHeight + "\" name=\"ez_player\" align=\"left\" allowScriptAccess=\"sameDomain\" allowFullScreen=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" flashvars=\"playType=" + playType + "&appInput=" + appInput + "&vidInput=" + vidInput + "&autoPlay=" + autoPlay + "&videoWidth=" + videoWidth + "&videoHeight=" + videoHeight + "&buffLength=" + buffLength + "&ccSource=" + ccSource + "&ccAtStart=" + ccAtStart + "&ccPosition=" + ccPosition + "&ccOpacity=" + ccOpacity + "&ccTextSize=" + ccTextSize + "\" />\n";
	code += "	</object>\n";
	code += "</noscript>";
	code += "</tr></td>\n";
	code += "</table>\n";
	
	window.document.getElementById("generatedCode").value = code;	
	window.document.getElementById("movieSize").innerHTML = "The Flash movie will use a space of: <strong>" + stageWidth + "px width &amp; " + stageHeight + "px height</strong> ";	
	generatePreview(playType, appInput, vidInput, autoPlay, videoWidth, videoHeight, buffLength, ccSource, ccAtStart, ccPosition, ccOpacity, ccTextSize, windowMode, bgColorHex);
	
}



