function Popup(URLtoOpen, windowName, windowFeatures){newWindow=window.open(URLtoOpen, windowName, windowFeatures);}

showInstructions = false;
var SID = parent.GetUserSessionID();

function WriteFlash(aFile, aWidth, aHeight, aP1, aP1Name, aP2, aP2Name, aP3, aP3Name, aP4, aP4Name)
{
	// parameters
	var sFlashVars = "";

	if (aP1 != undefined) sFlashVars = sFlashVars + aP1Name + '=' + aP1;
	if (aP2 != undefined) sFlashVars = sFlashVars + '&' + aP2Name + '=' + aP2;
	if (aP3 != undefined) sFlashVars = sFlashVars + '&' + aP3Name + '=' + aP3;
	if (aP4 != undefined) sFlashVars = sFlashVars + '&' + aP4Name + '=' + aP4;

	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+aWidth+'" height="'+aHeight+'" id="show" align="middle">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write(' <param name="movie" value="'+aFile+'"><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');
	document.write(' <embed src="'+aFile+'" FlashVars="'+ sFlashVars +'" quality="high" bgcolor="#ffffff" width="'+aWidth+'" height="'+aHeight+'" name="show" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');

	if (sFlashVars != "") document.write('<param name=FlashVars value="'+sFlashVars+'">');

	document.write('</object>');
}

function getParameter ( parameterName )
{
	var queryString = location.href;
	var parameterName = parameterName + "=";
	if ( queryString.length > 0 )
	{
		begin = queryString.indexOf ( parameterName );
		if ( begin != -1 )
		{
			begin += parameterName.length;
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 )
			{
				end = queryString.length;
			}

 			return unescape ( queryString.substring ( begin, end ) );
 		}

		return "null";
 	}
}

function AddParamURL()
{
	if(SID == null || typeof(SID) == 'undefined' || SID == '')
	{
		rUrl = parent.top.location.href;
		rUrl = escape(rUrl);
		parent.top.location.href = 'https://sso.itv.com/register/signin.html?OriginPage=' + rUrl;
	}
}

function writeGameContent()
{
	var sUrl = 'http://itv.jaildog.com/sites/itv/ivbg/' + production_name + '.swf?itvsid=' + SID;

	WriteFlash(sUrl, production_width, production_height);	

	document.write('<br>');
	document.write('<SPAN ID="span_instructions">');
	document.write('</SPAN>');
}

function padZeroes(iNumber, iPad)
{
	var sResult = "";

	while(iPad)
	{
		sResult = String(iNumber%10) + sResult;
		iNumber= Math.floor(iNumber/10);
		iPad--;
	}

	return sResult;
}

function getInstructionsURL(production, page)
{
	return('http://itv.vo.llnwd.net/o1/ivbg/web/' + production + "/" + production + "_" + padZeroes(page, 2) + ".htm");
}

function showInstructionsPage(production, page)
{
	document.getElementById("span_instructions").innerHTML = "<iframe src='" + getInstructionsURL(production, page) + "' name='iframe_instructions' width=" + production_width + " height=250 frameborder=0>";
}

function JWIshowInstructions(production, page)
{
	showInstructionsPage(production, page);
	showInstructions = true;
}

function JWIsetInstructionPage(production, page)
{
	if (showInstructions)
	{
		showInstructionsPage(production, page);
	}
}

function JWIhideInstructions()
{
	document.getElementById("span_instructions").innerHTML = "";
	showInstructions = false;
}

function JWIenableExternalSWF()
{
}

function JWIpopUp(sUrl)
{
 window.open(sUrl);
}

