// cookies.js - A helpful getCookie javascript method, and a Flash cookie->variable helper function

// NB:	Example ActionScript to return a cookie value:-

//	getURL("javascript:  document.all.application.SetVariable('JSESSIONID',getCookie('JSESSIONID'))");

//	So to get the JSP session cookie in ActionScript:-

//	getURL("javascript: returnCookie('JSESSIONID', 'JSESSIONID');");

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
	    begin = dc.indexOf(prefix);
	if (begin != 0) return null;
    } else
	begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
	end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
}
function returnCookie(cookieName, variableName) {
	//var application = document.all.application;
	var application;
	if(window.application)
		application = window.application;
	else if(document.application)
		application = document.application;
	if(!application)
		alert("Failed to access Flash object");
	application.SetVariable(variableName,getCookie(cookieName));
}

// Specific handling for the app.jsp file:-

var jsessionid = getCookie('JSESSIONID');

if(!jsessionid)
	// Spoof the value if missing (e.g. not served from JSP, and no JSPs hit so far)
	jsessionid = '6EE201C2F3F806D16C5988067BD17813';

/*
var flashvars = location.search.slice(1);
flashvars += "&siteXML=/DisneyChannel/supersites/jonas/site/data/global/site.xml";
flashvars += "&branch=index/home";
flashvars += "&isCuldesac=false";
flashvars += "&<InLineReplace name=ad type=SponsorLogo>";

flashvars += "&jsessionid=" + jsessionid;
flashvars += "&encoded_date=" + encoded_date;
*/

var flashvars = "encoded_date=" + encoded_date;

var flashMissingHTML = '<a href="http://www.adobe.com/go/EN_US-H-GET-FLASH"><img ' +
	' src="assets/download_flash_HTML.jpg" width="970" height="620"' +
	' alt="Download Flash Link" title="Download Flash" border="0" />' +
'</a>';

if(!FlashDetect.versionAtLeast(10))
{
	// We do not have flash, or have too low a level, so display link and image instead
	document.write(flashMissingHTML);
} 
else 
{
	// Then we have Flash 10 or higher, as required, so display the flash file
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
	    AC_FL_RunContent(
		'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
		'width', '970',
		'height', '620',
		'src', 'application',
		'quality', 'high',
		'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'showall',
		'wmode', 'window',
		'devicefont', 'false',
		'id', 'application',
		'bgcolor', '#ffffff',
		'name', 'application',
		'menu', 'true',
		'allowFullScreen', 'false',
		'allowScriptAccess','sameDomain',
		'movie', 'application',
		'salign', '',
		'FlashVars',flashvars
	    ); //end AC code
	}
							
	/*
	flashObj = new FlashObj(
		'/DisneyChannel/JonasMicrosite/application.swf', // swf
		'974', // width
		'620', // height
		'#ffffff', // background
		'', // version
		'application', // id
		flashvars, // flashVars
		true, // optional argument false = no autoplay true or blank = autoplay
		'/DisneyChannel/JonasMicrosite/', // base target
		'' // scale
	);

	flashObj.render(true,"opaque");
*/
}


