/*
Collection of methods used throughout Playhouse pages
- writeShockwavePlayer: creates Shockwave Player for both NS and IE.
- FYI: cookie functions can be found in http://disney.go.com/detect/scripts/master_flash_full.js
*/

//GLOBALS

// A few variables to help figure out what platform we're on
var dc_ie  = (navigator.appName.toLowerCase().indexOf("microsoft") != -1);
var dc_ns  = (navigator.appName.toLowerCase().indexOf("netscape") != -1);
var dc_win = (navigator.platform.toLowerCase().indexOf("win") != -1);
var dc_mac = (navigator.platform.toLowerCase().indexOf("mac") != -1);
var dc_browserVer = parseFloat(dc_ie ? navigator.appVersion.substring(navigator.appVersion.toLowerCase().indexOf("msie") + 4) : navigator.appVersion);

//END GLOBALS


//DETECT FLASH - functions found in http://disney.go.com/detect/scripts/master_flash_full.js
try{
	CreateInterface();
	DetectFlash("8,0,0,0");
	}
	catch(e){
		//detect functions not found
	}
//END DETECT FLASH

// define Shockwave player version for writeShockwavePlayer (unless already defined)
if ( SHOCKWAVE_PLAYER_VERSION == null ) {
	var SHOCKWAVE_PLAYER_VERSION = "8,5,1,0";
}

function getQueryString (obj) {
	var args = new Object();
	var qString = obj.location.search.substring(1);
	var argsArray = qString.split("&");

	for (var i = 0; i < argsArray.length; i++)
	{
		var pos = argsArray[i].indexOf('=');
		if (pos == -1) continue;
		var argName = argsArray[i].substring(0, pos);
		var value = argsArray[i].substring(pos + 1);
		args[argName] = unescape(value);
	}
	return args;
}

//This is the global popDisclaimer function for ad served elements
var mLinkDest = "", popDisclaimer;
function sendToClientSide(){window.open(mLinkDest);popDisclaimer.window.focus();}
function deliverPopDisclaimer(mLink){
	mLinkDest = mLink;
	popDisclaimer=window.open("","disclaimer","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=370,height=250,top=100,left=150,screenX=180,screenY=100");
	popDisclaimer.document.write ('<html><head><title>Disney.com - Disclaimer</title>');
	popDisclaimer.document.write ('<SCR'+'IPT TYPE="text/javascript" LANGUAGE="JavaScript">');
	popDisclaimer.document.write ('closeTimer = setT'+'imeout("window.close()",18000);');
	popDisclaimer.document.write ('</scr'+'ipt>');
	popDisclaimer.document.write ('</head><body bgcolor="#FFFFFF" text="#0065CE" link="#0065CE" vlink="#0065CE" alink="#0065CE" leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>');
	popDisclaimer.document.write ('<table width="370" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><img src="http://disney.go.com/spon'+'sors/images/disclaimer_top.gif" width="370" height="27" alt="" border="0"></td></tr><tr><td><table width="330" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td><br><FONT FACE="Verdana,sans-serif" SIZE="2" COLOR="#0065CE"><b>The web site you are about to link to is not controlled by Disney Online and different terms of use and privacy policy will apply. By proceeding you agree and understand that Disney Online is not responsible for the site you are about to access.<br><br>');
	popDisclaimer.document.write ('If your page does not load within a few seconds, please <a href="'+mLink+'" target="_blank">click here</a> to open it.</b></FONT><br><br></td></tr></table>');
	popDisclaimer.document.write ('</td></tr><tr bgcolor="#0000CC"><td align="center" height="20"><a href="javascript:window.close();"><FONT FACE="Verdana,sans-serif" SIZE="1" COLOR="#FFFF00"><b>Close this window</b></font></a></td></tr></table>');
	popDisclaimer.document.write ('</body></html>');
	popDisclaimer.document.close();
	sendTimer = setTimeout("sendToClientSide()",1500);
}

function writeShockwavePlayer (sSrc,  iWidth, iHeight, sID, settings, doc) {

	if ( sSrc == null || iWidth == null || iWidth < 1 || iHeight == null || iHeight < 1 ) {
		// quit if required parameters are not set
		return;
	}
	
	// set defaults for optional parameters
	if ( sID == null ) {
		sID = '';
	}		
	if ( settings == null ) {
		settings = {};
	}		
	if (settings.quality == null ) {
		settings.quality = 'high';
	}
	if (settings.bgcolor == null ) {
		settings.bgcolor = '#FFFFFF';
	}
	
	if (doc == null ) {
		doc = document;
	}
	
	var sPlayer = '';
	var prop;
	
	// define object tag with required parameters
	sPlayer += '<OBJECT id="' + sID + '" classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=' + SHOCKWAVE_PLAYER_VERSION + '" ';
	sPlayer += 'WIDTH="' + iWidth + '" HEIGHT="' + iHeight + '" >';
	sPlayer += '<PARAM NAME="src" VALUE="'+ sSrc +'" />';
	
	// add additional parameters
	for ( prop in settings ) {
		sPlayer += '<PARAM NAME="' + prop + '" VALUE="' + settings[prop] + '" /> ';
	}

	// define embed tag with required parameters
	sPlayer += '<EMBED SRC="' + sSrc + '" WIDTH="' + iWidth + '" HEIGHT="' + iHeight +'" ';
	//sPlayer += 'swliveconnect="FALSE" ';
	sPlayer += 'TYPE="application/x-director" ';
	sPlayer += 'PLUGINSPAGE="http:/'+'/www.macromedia.com/shockwave/download/" ';

	// define optional parameters
	for ( prop in settings ) {
		sPlayer += prop + '="' + settings[prop] + '" ';
	}
	
	// close embed & object tags
	sPlayer += '></EMBED></OBJECT>';

	doc.write (sPlayer);
}

// opens a window and returns the window
popUp = function (newwin, name, url,  options ) {
	// alert ( url +' '+ name +' '+ options);
	if ((newwin == null) || (newwin.closed == true)) {
		newwin = window.open( url, name, options);
	}

	// alert (newwin);
	newwin.focus();
	return newwin;
}

popTermsOfUse = function (  ) {
	if (this.windowTerms != null && !this.windowTerms.closed ) {
		this.windowTerms.close();
		this.windowTerms = null;
	}

	var width = 320;
	var height = 260;
	// positon on screen
	var screenXW = 0;
	var screenYW = 0;

	var options = "width="+width+",height="+height+",left=" + screenXW + ",top=" + screenYW + ",toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,screenX=" + screenXW + ",screenY=" + screenYW;

	var termsUrl = "http://tv.disney.go.com/playhouse/global/legal.html";
	termsUrl += "?width=" + width;
	termsUrl += "&height=" + height;

	this.windowTerms = popUp (this.windowTerms, "TermsOfUse", termsUrl, options );
}

// opens a window
function openNewWindow(URLtoOpen,windowName,windowFeatures) {
	newWindow=window.open(URLtoOpen,windowName,windowFeatures);
}

function aReplace (path) {
	if (path.substr(0,7) != "http://") { //put "http://" at the beginning of the url if it doesn't exist
		path = "http://" + path;
	}

	//UPDATE 030919:  Windows 98 running IE 5 doesn't like the replace function, so we need to check for that combination and use location.href instead
	var windows98 = 0;
	agt = navigator.userAgent.toLowerCase();
	if ((agt.indexOf("win98")!=-1)||(agt.indexOf("windows 98")!=-1)){
		windows98 = 1;
	}

	if (windows98 == 1 && dc_browserVer == 5){
		top.location.href = path;
	}
	else{
		// replace is supported
		if (dc_browserVer>=4 || window.location.replace) {
			window.location.replace(path);
		}
		else {
			top.location.href = path;
		}
	}
}
