/* 
|	 
|	ra.jsutils.js
|	JavaScript utility package
|
*/


/* 
|	 
|	Extend built-in classes here
|
*/
String.prototype.trim = function(){ return this.replace(/(^\s+)|\s+$/g,"")}
String.prototype.ltrim = function(){ return this.replace(/(^\s+)/g,"")}
String.prototype.rtrim = function(){ return this.replace(/\s+$/g,"")}

/* 
|	 
|	Browser Detection
|	Detect IE and Firefox
|
*/
var agent = navigator.userAgent.toLowerCase();
var isIE = ( agent.indexOf( "msie" ) != -1 );
var isFfox = ( agent.indexOf( "firefox" ) != -1 );
var isFfox3 = ( agent.indexOf( "fox/3" ) != -1 );
var isChrome = ( agent.indexOf( "chrome" ) != -1 );

/* 
|	 
|	Flag to show debug info
|	in Firebug console
|
*/
var debugme = false;

/* 
|	 
|	The OMNITURE object will be used by the games service
|	installer to implement tracking
|
*/
if ( "undefined" ==  typeof OMNITURE ) {
	var OMNITURE = {};
}

/*
/
/	Game Object Utilities
/
*/
function createGameObject(sId) {
	var head = document.getElementsByTagName("HEAD").item(0);
	var obj = head.appendChild( document.createElement("OBJECT") );
	obj.id = sId;
	obj.name = sId;
	obj.classid = GAME_OBJ_CLASSID;
}

function fillGameObject( oTarget, oSource ) {
	oTarget.gameName = oSource.gamename;
	oTarget.gameid = oSource.gameid;
	oTarget.gameType = oSource.gameType;
	oTarget.languageCode = oSource.languageCode;
	oDataSource.fillGame( oTarget );
}

function getDemoMinutesTotal( oGm ) {
	try {
		return Number( oGm.demoMinutes );
	}
	catch(e) {
		return 0;
	}
}

function getDemoMinutesRemaining( oGm ) {
	try {
		return Number( oGm.minutesRemaining );
	}
	catch(e) {
		return 0;
	}
}

/*
/
/	Game Utilities
/
*/
function getGamePurchaseStatus( gm ) {
	try {
		return gm.purchaseStatus;
	}
	catch(e) {
		return 0;
	}
}

function isGameInstalled( gm ) {
	try {
		return gm.installStatus;
	}
	catch(e) {
		return false;
	}
}

function isDemoInstallation( gm ) {
	try {
		if( isGameInstalled( gm ) && !getGamePurchaseStatus( gm ) )
			return 1;
		else
			return 0;
	}
	catch(e) {
		return 0;
	}
}

function isUnlimitedPlayGame( gm ) {
	try {
		return gm.unlimitedPlay;
	}
	catch(e) {
		return false;
	}
}

function loadAndLaunchGame( gameList, gameId, gameType ) {
	var game = getGameFromGameList( gameList, gameId, gameType );
	game.launch();
}

function loadAndUninstallGame( gameList, gameId, gameType, msg ) {
	var game = getGameFromGameList( gameList, gameId, gameType );
	var confirmMsg = msg + game.gameName + "?";
	if ( confirm( confirmMsg ) ) {
		game.uninstall();
	}
}

function registerGamePlay( contextPath, id ) {

	// register game play with the server
	try {
			var bindArgs = {
			url: contextPath + "registerGames.jsf?gameId=" + id + "&type=rpg",
			mimetype: "text/json",
			error: function( type, error, httpObj ) {
				return true;
			},
			load: function( type, game, httpObj ) {
				return true;
			}
		};
		dojo.io.bind( bindArgs );
	}
	catch(e) {
		//alert(e);
	}
}

/*
/
/	Game List Utilities
/
*/
function getGameFromGameList( gameList, gameId, gameType ) {
    try {
	    for ( i=0; i<gameList.count; i++ ){
		    var myGame = gameList.item(i);
		    //alert("Game: " + myGame.gameName);
		    if( myGame.gameid == gameId ){
			    return myGame;
		    }
	    }
	    return null;
	}
	catch(e) {	
	    //alert(e);
		return false;
	}
	/*
	try {
		var queryString = "id == " + gameId  + " AND type == " + gameType;
		var raGameListFiltered = gameList.createFilteredGameList( queryString );
		
		return raGameListFiltered.item(0);
	}
	catch(e) {	
		return false;
	}
	*/
}

function sortGameList( list, sortby, bSortup ) {
	try {
		list.sortOrderAscending = bSortup;
		list.sort( sortby );
	}
	catch(e) {
		return false;
	}
}

function getPurchasedGames() {
	try {
		var arrPurchased = new Array();
		var tempGamesList = oDataSource.loadGameList( gameLists.MY_GAMES );
	    //check for purchased games
		for ( i=0; i < tempGamesList.count; i++ ) {
			var myGame = tempGamesList.item(i);
			if( myGame.purchaseStatus ) {
				arrPurchased.push( myGame );			
			}
		}
		return arrPurchased;
	}
	catch(e) {
		//alert(e);
		return false;
	}
	
}

/*
/
/	Game Status Utilities
/
*/

function checkGameStatus( o ) {
	if(debugme) console.log("Check game status for " + o.gameId)
	try {
		var returnVal = false;
		var tempGamesList = oDataSource.loadGameList( gameLists.MY_GAMES );
		
		var game = getGameFromGameList( tempGamesList, o.gameId, o.gameType );
		if( game == null) {
			returnVal = "topic-onGameUninstalled";
			if(debugme) console.log(o.gameId + returnVal)
		}
		if( getGamePurchaseStatus(game) != o.purchaseStatus ) {
			returnVal = "topic-onGamePurchased";
			if(debugme) console.log(o.gameId + returnVal)
		}	
		if( isDemoInstallation( game ) && parseInt( game.playCount ) != o.playCount ) {
			returnVal = "topic-onGamePlayFinished:" + game.gameid;
			if(debugme) console.log(o.gameId + returnVal)
		}	
		if(debugme) console.log("Publish topic: " + returnVal)
		return returnVal;		
	}
	catch(e) {
		if(debugme) console.log(e);
		//alert(e);
		return false;
	}
}

function refreshGameListContents() {	
	try {
		if(debugme) console.log("Refresh game list contents");
		var tempGamesList = oDataSource.loadGameList( gameLists.MY_GAMES );
		
		//refresh the list itself
	    if( tempGamesList.count < window.myGamesListLength ) {
	    	dojo.event.topic.publish("topic-onGameUninstalled");
	    }
	    else if( tempGamesList.count > window.myGamesListLength ) {
	    	dojo.event.topic.publish("topic-onGameInstalled");
	    }	    
	    else {
			var arrTopics = new Array();
		    //check for display updates
			for ( i=0; i < tempGamesList.count; i++ ) {
				var myGame = tempGamesList.item(i);
				var oGame = myGamesGameObjects[myGame.gameid];
				try {
					arrTopics.push( checkGameStatus( oGame  ) );			
				}
				catch(e) {
					//alert(e)
				}
			}
			//take action, if needed
			var topic="", arg="";		
			for( j=0; j<arrTopics.length; j++) {
				if (arrTopics[j]) {
					if (arrTopics[j].indexOf("onGamePlayFinished") != -1) {
						temp = arrTopics[j].split(":");
						topic = temp[0];
						arg = temp[1];
					}
					else {
						topic = arrTopics[j];
					}
				}
			}
			if (topic) {
				if(debugme) console.log("PUBLISH " + topic + " : " + arg);
				dojo.event.topic.publish(topic, arg)
			}
	    }
	}
	catch(e) {
		if(debugme) console.log(e);
		//alert(e);
	}
	
}

function refreshGameInformationContents() {	
	try {
		if(debugme) console.log("Refresh game information contents");		
		var arrTopics = new Array();
	    //check for display updates
		var oGame = gameInformationGameObject;
		try {
			arrTopics.push( checkGameStatus( oGame  ) );			
		}
		catch(e) {
			//alert(e)
		}
		//take action, if needed
		var topic="", arg="";		
		for( j=0; j<arrTopics.length; j++) {
			if (arrTopics[j]) {
				if (arrTopics[j].indexOf("onGamePlayFinished") != -1) {
					temp = arrTopics[j].split(":");
					topic = temp[0];
					arg = temp[1];
				}
				else {
					topic = arrTopics[j];
				}
			}
		}
		if (topic) {
			if(debugme) console.log("PUBLISH " + topic + " : " + arg);
			dojo.event.topic.publish(topic, arg)
		}
	}
	catch(e) {
		if(debugme) console.log(e);
		//alert(e);
	}
}
/* 
|	 
|	HTML Element Utilities
|
*/
function selectRadioButton( group, val ) {
	var group = document.getElementsByName(group);
	for ( var i = 0; i < group.length; i++ ) {
		if ( group[i]. value == val ) {
			group[i].click();
			return;
		}
	}
}

/* 
|	 
|	DOM Utilities
|
*/
function getChildElementsByTagName(nParent, tagName) {
	try {
		var arrChildren = new Array();	
		var kids = nParent.childNodes;
		for(i=0; i<kids.length; i++) {
			if( kids[i].nodeName == tagName ) {
				arrChildren.push(kids[i]);
			}
		}
		return arrChildren;
	}
	catch(e) {
		return null;
	}
};

function getChildElementById(nParent, id) {
	try {
		var kids = nParent.childNodes;
		for(i=0; i<kids.length; i++) {
			if( kids[i].id == id ) {
				return(kids[i]);
			}
		}
	}
	catch(e) {
		return null;
	}
};

function toggleElementDisplay(id) {
	try {
		var elem = document.getElementById(id);
		elem.style.display = elem.style.display == "block" ? "none" : "block";
	} 
	catch(e) {
		// alert(e);
	}
}
function createObjectTag( objectTagId, objectClassId ) {
	try {
		var head = document.getElementsByTagName("HEAD").item(0);
		var objectNode = document.createElement("OBJECT");
		objectNode.setAttribute( 'name', objectTagId );
		objectNode.setAttribute( 'id', objectTagId );
		objectNode.setAttribute( 'classid', objectClassId );
		head.appendChild( objectNode );
		return true;
	}
	catch(e) {
		return false;
	}
}

function createThumbnailLink( game ) {
	var elem = document.createElement( "IMG" );
	elem.src = oImageFactory.getGameImage( game.gameid, game.gameType, THUMBNAIL_IMAGE);
	elem.className = "cursorHand";
	var gameId = game.gameid;
	elem.onclick = function() { document.location = GAME_PAGE + gameId };
	return elem;
}

function createFeatureLink( game ) {
	var elem = document.createElement( "IMG" );
	elem.src = oImageFactory.getGameImage( game.gameid, game.gameType, FEATURE_IMAGE);
	elem.className = "cursorHand";
	var gameId = game.gameid;
	elem.onclick = function() { document.location = GAME_PAGE + gameId };
	return elem;
}

function createDivLink( height, width, cssClass, text, url ) {
	var elem = document.createElement( "DIV" );
	elem.style.width = width + "px";
	elem.style.height = height + "px";
	var link = document.createElement( "A" );
	link.className = cssClass;
	link.setAttribute( "href", url );
	link.appendChild( document.createTextNode( text) );
	elem.appendChild( link );

	return elem;
}

function createRolloverImageLink( elemType, width, height, css, onImageName, offImageName, clickAction ) {
	var elem = document.createElement( elemType );
	var sCss = "width:" + width + ";height:" + height + ";cursor:pointer;background-repeat:no-repeat;background-image:url(" + offImageName + ");";
	elem.style.cssText = sCss + css;
	elem.onmouseover = function() { this.style.backgroundImage = "url(" + onImageName + ")" };
	elem.onmouseout = function() { this.style.backgroundImage ="url(" + offImageName + ")" };
	elem.onclick = new Function( clickAction );
	return elem;
}

function appendTextNode( parent, text ) {
	document.getElementById(parent).appendChild( document.createTextNode( text ) );
}

function clearChildNodes( nParent ) {
	while ( nParent.firstChild ) {
		nParent.removeChild( nParent.firstChild );
	}
}

function createImgElement( src ) {
	var elem = document.createElement("IMG");
	elem.src = src;
	return elem;
}

function getDocumentElementWidth() {
	if ( self.innerHeight ) // all except Explorer
	{
		return self.innerWidth;
	}
	else if ( document.documentElement && document.documentElement.clientHeight )  // Explorer 6 Strict Mode
	{
		return document.documentElement.clientWidth;
	}
	else if ( document.body ) // other Explorers
	{
		return document.body.clientWidth;
	}
}

function getDocumentElementHeight() {
	if ( self.innerHeight ) // all except Explorer
	{
		return self.innerHeight;
	}
	else if ( document.documentElement && document.documentElement.clientHeight )  // Explorer 6 Strict Mode
	{
		return document.documentElement.clientHeight;
	}
	else if ( document.body ) // other Explorers
	{
		return document.body.clientHeight;
	}
}

function getVerticalScrollOffset() {
	if ( self.pageYOffset ) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if ( document.documentElement && document.documentElement.scrollTop )  // Explorer 6 Strict
	{
		return document.documentElement.scrollTop;
	}
	else if ( document.body ) // all other Explorers
	{
		return document.body.scrollTop;
	}
}

/* 
|	 
|	DHTML Utilities
|
*/
function setBgImage( elem, imageUrl ) {
	//is it an image element? if so, set the src
	if( elem.tagName == "IMG" ) {
		elem.src == imageUrl ;
	}
	//if not, it's a css background image
	else {
		elem.style.backgroundImage = "url(" + imageUrl + ")";
	}
}

function getWindowWidth() {
	return (document.all) ? document.documentElement.clientWidth : window.innerWidth;
}

function getWindowHeight() {
	return (document.all) ? document.documentElement.clientHeight : window.innerHeight;
}

function showElementOffset( elemId, width, height, X, Y )
{	
	var layerObj = document.getElementById( elemId );
	var topOfWindow = getVerticalScrollOffset();
	var bottomOfWindow = getWindowHeight() + getVerticalScrollOffset();
	var windowWidth = getWindowWidth();
	
	if( Y + height > bottomOfWindow ) Y -= ( Y + height - bottomOfWindow );
	if( X > windowWidth - width ) X -= ( X + width - windowWidth );
	
	layerObj.style.left = X + "px";
	layerObj.style.top = Y + "px";
	layerObj.style.display = "block";
}

function setWindowTitle( str ) {
	document.title = str;
}

/**********************************************************
/	function create3PieceRolloverButton
/
/	oImages is a JS object with the following properties:
/		var oImg = new Object();
/		oImg.leftOn = "";
/		oImg.leftOff = "";
/		oImg.centOn = "";
/		oImg.centOff = "";
/		oImg.rightOn = "";
/		oImg.rightOff = "";	
/	where the values are the corresponding image urls
/
************************************************************/
function create3PieceRolloverButton( id, width, height, oImages, caption, cssClassName, clickAction, contentWidth ) {
	var table = document.createElement("TABLE");
	table.images = oImages;
	table.id = id;
	table.cellPadding = "0";
	table.cellSpacing = "0";
	table.border = "0";
	table.className = "cursorHand";
	table.onclick = new Function( clickAction );
	table.onmouseover = rollOver3PieceButton;
	table.onmouseout = rollOut3PieceButton;
	var tbody = document.createElement("TBODY");
	table.appendChild( tbody );

	var row = document.createElement("TR");
	tbody.appendChild( row );

	var col1 = document.createElement("TD");
	col1.style.width = width + "px";
	col1.style.height = height + "px";
	col1.style.backgroundImage = "url(" + oImages.leftOff + ")";
	row.appendChild( col1 );

	var col2 = document.createElement("TD");
	col2.style.height = height + "px";
	col2.style.backgroundImage = "url(" + oImages.centOff + ")";
	var captionNode = document.createElement("DIV");
	captionNode.className = cssClassName;
	captionNode.style.textAlign = "center";
	if(contentWidth) captionNode.style.width = contentWidth + "px";
	captionNode.style.height = height + "px";
	var textNode = document.createTextNode( caption );
	captionNode.appendChild( textNode );
	col2.appendChild( captionNode );
	row.appendChild( col2 );

	var col3 = document.createElement("TD");
	col3.style.width = width + "px";
	col3.style.height = height + "px";
	col3.style.backgroundImage = "url(" + oImages.rightOff + ")";
	row.appendChild( col3 );
	
	return table;
}

function rollOver3PieceButton() {
	this.rows[0].childNodes[0].style.backgroundImage = "url(" + this.images.leftOn + ")";
	this.rows[0].childNodes[1].style.backgroundImage = "url(" + this.images.centOn + ")";
	this.rows[0].childNodes[2].style.backgroundImage = "url(" + this.images.rightOn + ")";
}

function rollOut3PieceButton() {
	this.rows[0].childNodes[0].style.backgroundImage = "url(" + this.images.leftOff + ")";
	this.rows[0].childNodes[1].style.backgroundImage = "url(" + this.images.centOff + ")";
	this.rows[0].childNodes[2].style.backgroundImage = "url(" + this.images.rightOff + ")";
}

/*
/
/	Image Factory
/
*/
function imageFactory() {
	//constructor function for image factory
	//properties
	this.imageBaseUrl = IMAGE_BASE_URL;
	
	//methods
	this.getGameImage = getGameImage;
	this.getScreenshotImageThumbnails = getScreenshotImageThumbnails;	//120x90
	this.getImageBaseUrl = getImageBaseUrl;
}

function getGameImage( gameId, gameType, imageType ) {
	return encodeURI( this.imageBaseUrl + gameId + "&gametype=" + gameType + "&imagetype=" + oOnlineImageMap[imageType] );
}

function getScreenshotImageThumbnails(gameid, gametype ) {
	var arrImages = new Array(3);
	for ( i = 0; i < arrImages.length; i++ )
		arrImages[i] = encodeURI( this.imageBaseUrl + gameid + "&gametype=" + gametype + "&imagetype=Game Screenshot Thumbnail&index=" + i );
	return arrImages;
}

function getImageBaseUrl() {
	return this.imageBaseUrl;
}

var oImageFactory = new imageFactory();

/* 
|	 
|	Misc pop-ups
|
*/
function launchScreenshotSlideshow( gameId, gameType ) {
	window.open( getScreenShotsUrl( gameId, gameType ), 'blank', 'scrollbars=auto,left=20,top=20,width=600,height=550,noresize');
}

/* 
|	 
|	String Utilities
|
*/
function trimAndEllipse( str, num ) {
	return ( str.length > num ) ? ( str.substr( 0,num ) + "..." ) : str ;
}

function trimAndEllipseToSpace( str, num ) {
	if ( str.length > num ) {
		var teStr = str.substr( 0,num );
		teStr = teStr.substr( 0,teStr.lastIndexOf(" ") ) + "...";
	} else {
		teStr = str;
	}
	return teStr;
}

/*
|
| Error handling utils
|
*/
function createErrorMessage( errorNumber, errorString ) {
	return errorString + "\nErrorCode: " + errorNumber;
}

/* 
|	 
|	Cookie Utilities
|
*/
// the duration here is days (pass a number)
function setCookie( name, value, duration ) {
	var dExp = new Date();
	var expiration = '';
	if ( duration > 0 ) {
	    dExp.setTime( dExp.getTime() + ( duration*24*60*60*1000 ) );
	    expiration = 'expires='+ dExp.toGMTString();
    }
	document.cookie = name + '=' + value + ';path=/;' + expiration;
}

function getCookie( name ) {
	var cookies = document.cookie.split(";");
	for( var i=0; i < cookies.length; i++ ) {
		var c = cookies[i];
		var pos = c.indexOf( "=" );
		var nm = c.substring( 0, pos );
		if ( name.trim() == nm.trim() )
			return c.substring( pos+1 );
	}
	return null;
}

function delCookie( name ) {
	var dExp = new Date();
	dExp.setTime( dExp.getTime() - ( 365*24*60*60*1000 ) );
	document.cookie = name + '=value; expires=' + dExp.toGMTString();
}

function cookieEnabled() {
	setCookie( 'rn','y' );	//try to set a cookie
	if( 'y' == getCookie('rn') ) {	//did it work?
		delCookie( 'rn' )	//it worked, clean up
		return true;
	} else {
		return false;	//it didn't work
	}
}

/*
/
/	User Utilities
/
*/
function getUserFirstName() {
	try {
		return raUserObject.firstName;
	}
	catch(e) {
		return false;
	}
}

function getUserLastName() {
	try {
		return raUserObject.lastName;
	}
	catch(e) {
		return false;
	}
}
/* 
|	 
|	Misc Utilities
|
*/
function getMonthStr(iMonth) {
	arrMonth = ["Jan","Feb","March","April","May","June","July","Aug","Sept","Oct","Nov","Dec"];
	return(arrMonth[iMonth]);
}

function pingServer( url ) {
	var elem = document.createElement("IFRAME");
	elem.style.height = "0px";
	elem.style.width = "0px";
	document.body.appendChild( elem );
	elem.src = url;
}

function loadAlternateImage( imgElem, url ) {
	try {
		imgElem.src = url;
	}
	catch(e) {
		//alert(e + " in loadAlternateImage");
	}
}

/* 
|	 
|	Drop Down Utilities
|
*/
function toggleDropDown( dropDownMenuId, dropDownMenuButtonId, staticFileBase ) {
	var dropDownMenuDiv = document.getElementById(dropDownMenuId);
    var dropDownMenuButton = document.getElementById(dropDownMenuButtonId);
    if ( dropDownMenuDiv.style.display == "none" ) {
    	dropDownMenuDiv.style.display = "block";
        dropDownMenuButton.style.background = "url(" + staticFileBase + "images/dropdown_list_button_on.gif) no-repeat";
    } else {
        dropDownMenuDiv.style.display = "none";
        dropDownMenuButton.style.background = "url(" + staticFileBase + "images/dropdown_list_button_off.gif) no-repeat";
    }
}
/* 
|	 
|	Pop Up Utilities
|
*/
function popUpOnlineGame( url, windowName ) {
	var newWindow = window.open( url, windowName,'width=800,height=800,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
	if ( window.focus ) {
		newWindow.focus();
	}
}

function popUpReview( url, windowName ) {
	var newWindow = window.open( url, windowName, 'width=540,height=500,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
	if ( window.focus ) {
		newWindow.focus();
	}
}

function popUpMessageBoard( url, windowName ) {
	var newWindow = window.open( url, windowName, 'width=540,height=500,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
	if ( window.focus ) {
		newWindow.focus();
	}
}

function popUpHelpAnswer( url, windowName ) {
	var newWindow = window.open( url, windowName, 'width=350,height=400,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
	if ( window.focus ) {
		newWindow.focus();
	}
}

/* 
|	 
|	Game Download Tool Tip
|
*/
function gameDownloadToolTip( domId, gameName ) {
	var strInstructions, imageSrc;
	
	try {
		// detect os and set values
		if ( navigator.userAgent.toLowerCase().indexOf("windows nt 6.0") != -1 ) {
			strInstructions = "To begin your download of " + gameName + ", click the \"<b>Run</b>\" button in the first window that appears, then click the \"<b>Continue</b>\" button in the second window.";
			imageSrc = "vista_download_tip.jpg";
		} else {
			strInstructions = "To begin your download of " + gameName + ", simply click the \"<b>Run</b>\" button in each window that appears.";
			imageSrc = "xp_download_tip.jpg";
		}
	
		var elem = document.createElement("DIV");
			elem.id = domId;
			elem.style.height = "249px";
			elem.style.width = "382px";
			elem.style.background = "url(" + staticFileBase + "images/gameTipBack.gif) no-repeat";
			elem.className = "gameToolTip";
		var textElem = document.createElement("DIV");
			textElem.className = "gameToolTipText";
			textElem.innerHTML = strInstructions;
		var imgNode = document.createElement("DIV");
			imgNode.className = "gameToolTipImage";
		var imgElem = document.createElement("IMG");
			imgElem.src = staticFileBase + "images/" + imageSrc;
			imgNode.appendChild( imgElem );
		var guaranteeElem = document.createElement("DIV");
			guaranteeElem.className = "gameToolTipGuarantee";
			var guaranteeText = document.createElement("SPAN");
			guaranteeText.className = "px10 bold";
			guaranteeText.appendChild( document.createTextNode("100% Safe & Secure") );
			guaranteeElem.appendChild( guaranteeText );
			guaranteeElem.appendChild( document.createElement("BR") );
			guaranteeElem.appendChild( document.createTextNode("No spyware or adware - guaranteed!") );
		var bbbElem = document.createElement("IMG");
			bbbElem.className = "gameToolTipBBSeal";
			bbbElem.src = staticFileBase + "images/bbbseal.gif";
	   
	   elem.appendChild( textElem );
	   elem.appendChild( imgNode );
	   elem.appendChild( guaranteeElem );
	   elem.appendChild( bbbElem );
	   
	   return elem;
	}
	catch(e) {
		if( window.console && console.log ) {
			console.log( e );
		}
		return false;
	}	   
}

function showToolTip( elem ) {
	try {
		if ( !createArcadeV2VersionControl() ) {
			var showAbove = false, shiftLeft = false, tmpTop, tmpLeft;
		
			var viewportWidth = (document.all) ? document.body.clientWidth : window.innerWidth;
			var viewportHeight = document.documentElement.clientHeight || window.innerHeight;
			var scrollAmount = document.documentElement.scrollTop;
			
			var evet = window.event || arguments.callee.caller.arguments[0];
			//var srcElem = evet.srcElement || evet.target;
		
			//show above?
			if ( evet.clientY > parseInt(elem.style.height) & ( viewportHeight < evet.clientY + parseInt(elem.style.height) ) ) showAbove = true;

			//shift left?
			if ( evet.clientX + parseInt(elem.style.width) > viewportWidth ) shiftLeft = true;
		
			tmpTop = showAbove ? evet.clientY - parseInt(elem.style.height) - 35 : evet.clientY + 35;
			tmpLeft = shiftLeft? evet.clientX - (evet.clientX + parseInt(elem.style.width) - viewportWidth + 20) : evet.clientX;
				
			elem.style.left = tmpLeft - 370 + "px";
			elem.style.top = tmpTop + scrollAmount + "px";
			elem.style.display = "block";
		}
	}
	catch(e){
		if( window.console && console.log ) {
		console.log( e );
		}	
	}
}

function hideToolTip( elem ) {
	elem.style.display = "none";
}

Array.prototype.contains = function(obj) {
	var i = this.length;
	while (i--) {
		if (this[i] === obj) {
			return true;
		}
	}
	return false;
}

function deleteV3CookieForMigration() {
    //if we are not in RAC v3 account application
    if (location.href.indexOf('/account/') < 0) {
            var nonMigrating = new Array('alltel_', 'alltel2_', 'belief_', 'bells-cl_', 'cbs-gday_', 'cbs-gds_', 'cbs-kbcw_', 'cbs-kcbs_', 'cbs-kcnc_', 'cbs-kdka_', 'cbs-kovr_', 'cbs-kpix_', 'cbs-kpsg_', 'cbs-kstw_', 'cbs-ktvt_', 'cbs-kyw_', 'cbs-wbbm_', 'cbs-wbz_', 'cbs-wcbs_', 'cbs-wcco_', 'cbs-wfor_', 'cbs-wgnt_', 'cbs-wjz_', 'cbs-wkbd_', 'cbs-wtog_', 'cbs-wupa_', 'cbs-wwj_', 'coke_', 'cometsys_', 'disney_', 'eons_', 'ezone_', 'ezone2_', 'freesite_', 'freesite2_', 'freesite3_', 'freesite4_', 'freez3int_', 'freeze_', 'freeze2_', 'freeze3_', 'freeze4_', 'games2win_', 'horoscope_', 'insight_', 'insight2_', 'king_', 'latimes_', 'life2_', 'lifetime_', 'Lifetime_', 'lilly_', 'lycos2_', 'mycoke_', 'myfreeze_', 'nwsource_', 'nwsource2_', 'parade_', 'parade-cl_', 'paradecl2_', 'patsajack_', 'readersd2_', 'readersdi_', 'roadrun_', 'screensav_', 'screensav2_', 'several', 'skunk_', 'skunk2_', 'superhoro_', 'uclick_', 'world2_', 'worldnow_', 'a8-jp_', 'ad-jp_', 'alc_', 'altech-jp_', 'ap_', 'aptest_', 'asiaengeo_', 'au2-ap_', 'au2-br_', 'au2-de_', 'au2-es_', 'au2-eu_', 'au2-fr_', 'au2-it_', 'au2-jp_', 'au2-kr_', 'au2-mx_', 'au2-nl_', 'au2-se_', 'au2-uk_', 'au-de_', 'au-es_', 'au-fr_', 'au-jp_', 'belgac-fr_', 'belgac-nl_', 'beness-jp_', 'blott-fr_', 'blott-uk_', 'bonsai1_', 'bonsai2_', 'bonsai3_', 'bonsai4_', 'bps-jp_', 'br_', 'brgeo_', 'brpromo_', 'brtest_', 'cagent_', 'cj-de_', 'cj-es_', 'cj-eu_', 'cj-fr_', 'cj-mx_', 'cj-nl_', 'cj-uk_', 'clariafr_', 'clariauk_', 'codema-it_', 'de_', 'degeo_', 'dengeki_', 'deoff_', 'depromo_', 'detest_', 'ekeuze-nl_', 'elmun2-es_', 'elmund-es_', 'es_', 'esgeo_', 'espromo_', 'estest_', 'etype-de_', 'etype-uk_', 'eu_', 'eupromo_', 'eutest_', 'famitsu_', 'feed-de_', 'feed-es_', 'feed-fr_', 'feed-it_', 'feed-jp_', 'feed-nl_', 'feed-uk_', 'fr_', 'fraper_', 'free-fr_', 'frgeo_', 'froog-uk_', 'frpromo_', 'frtest_', 'future-uk_', 'gmo-jp_', 'goo_', 'google-de_', 'google-es_', 'google-eu_', 'google-fr_', 'google-jp_', 'googlesp_', 'google-uk_', 'gtbt-de_', 'gtbt-es_', 'gtbt-fr_', 'gtbt-it_', 'gtbt-jp_', 'guide-ap_', 'guide-br_', 'guide-br2_', 'guide-de_', 'guide-de2_', 'guide-es_', 'guide-es2_', 'guide-eu_', 'guide-eu2_', 'guide-fr_', 'guide-fr2_', 'guide-it_', 'guide-it2_', 'guide-jp_', 'guide-kr_', 'guide-mx_', 'guide-mx2_', 'guide-nl_', 'guide-nl2_', 'guide-uk_', 'guide-uk2_', 'home-uk_', 'hotbar-de_', 'hotbar-es_', 'hotbar-fr_', 'hotbar-uk_', 'htmail-uk_', 'icommjpn_', 'ilse-nl_', 'impres-jp_', 'intl_', 'intl-ab_', 'ipm-de_', 'ipm-es_', 'ipm-fr_', 'ipm-jp_', 'it_', 'itgeo_', 'itpromo_', 'ittest_', 'japan_', 'jp_', 'jp-cl_', 'jp-en_', 'jpgeo_', 'jp-local_', 'jptest_', 'jrdx_', 'jrpass_', 'jspad_', 'kr_', 'krgeo_', 'kr-local_', 'krpromo_', 'krtest_', 'listop-jp_', 'metric-de_', 'metricsdi_', 'mixi-jp_', 'mrgood-eu_', 'mx_', 'mxgeo_', 'mxpromo_', 'mxtest_', 'nightl-de_', 'nightl-es_', 'nightl-fr_', 'nightl-jp_', 'nl_', 'nlgeo_', 'nlpromo_', 'nltest_', 'ocn_', 'over1-jp_', 'over2-jp_', 'over3-jp_', 'over4-jp_', 'over5-jp_', 'over-de_', 'over-fr_', 'over-jp_', 'overtf-uk_', 'overtures_', 'over-uk_', 'overz-nl_', 'pb18_', 'pb1-de_', 'prize-jp_', 'r1home-de_', 'r1home-es_', 'r1home-fr_', 'r1home-jp_', 'rpass-de_', 'rpass-es_', 'rpass-fr_', 'rpass-it_', 'rpass-nl_', 'rpass-se_', 'rpass-uk_', 'rpwelc-br_', 'rpwelc-de_', 'rpwelc-es_', 'rpwelc-fr_', 'rpwelc-it_', 'rtl-de_', 'rtl-de2_', 'rtl-fr_', 'se_', 'segeo_', 'sepromo_', 'setest_', 'sony-jp_', 'speedb-de_', 'startf-nl_', 'startg-nl_', 'telewest_', 'test-de_', 'test-es_', 'test-fr_', 'test-jp_', 'test-jp2_', 'tradedoub_', 'tradeduk_', 'transmeta_', 'twalker_', 'uk_', 'ukgeo_', 'ukpromo_', 'uktest_', 'valclk-de_', 'valclk-uk_', 'vector_', 'welico-br_', 'welico-de_', 'welico-es_', 'welico-eu_', 'welico-fr_', 'welico-it_', 'welico-jp_', 'welico-kr_', 'welico-mx_', 'welico-uk_', 'wind_', 'yhmail-uk_', 'zylom-de_', 'zylom-en_', 'zylom-es_', 'zylom-fr_', 'zylom-it_', 'zylom-nl_', 'zylom-se_', 'zylom-uk_');
            cookie = getCookie('games-v3');
            try {
	            if(window.tps === undefined) {
	                muncher = getCookie('cookieChanged');
	                if (cookie != null && muncher == null) {
	                        delCookie('games-v3');
	                        setCookie('cookieChanged', '1', 0);
	                        setCookie('games-v3', '1', 0);
	                }
	            } else {
		            if (nonMigrating.contains(tps)) {
	                    //if we are a non-migrating TPS, and the cookie is not a session cookie
	                    //then set the cookie to a session cookie, and add a flag cookie so we
	                    //don't do it again on the next request
	                    //alert('setting session games-v3 cookie');
		                muncher = getCookie('cookieChanged');
		                if (cookie != null && muncher == null) {
		                        delCookie('games-v3');
		                        setCookie('cookieChanged', '1', 0);
		                        setCookie('games-v3', '1', 0);
		                }
		            } else {
	                    //if we are migrating, then redirect to the storefront with a time-stamp
	                    //alert('redirecting to: ' + contextPath + '?t=' + new Date().getTime());
	                    if (cookie != null) {
	                            delCookie('games-v3');
	                    }
	                    document.location.href = contextPath + '?tstamp=' + new Date().getTime() ;
		            }
	            }
            }
            catch (e) {
            	//silently fail
            }	            
    }
}

try {
	dojo.addOnLoad(deleteV3CookieForMigration);
}
catch (e) {
	//silently fail
}