/* 
|	 
|	global.js
|
*/


/*
|	some utility functions
*/

function swapImage(img,str) {
    try {
        document.images[img].src = str;
    }
    catch(e) {/*fail silently*/};
}

function hideElement(o) {
	document.getElementById(o).style.display = "none";
}

function showElementInline(o) {
	document.getElementById(o).style.display = "inline";
}

function showElementBlock(o) {
	document.getElementById(o).style.display = "block";
}

function getMonthStr(iMonth) {
	arrMonth = ["Jan","Feb","March","April","May","June","July","Aug","Sept","Oct","Nov","Dec"];
	return(arrMonth[iMonth]);
}

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

function getCookie(name) {
	var sCookie,lenName,iName,iPos,iValue,value;
	name = name + '='
	sCookie = document.cookie;
	lenName = name.length
	iName = sCookie.indexOf(name);
	if (iName >=0) {
		iPos = iName + lenName;
		iValue = sCookie.indexOf(';',iPos);
		if (iValue == -1) iValue = sCookie.length; 
			value = sCookie.substring(iPos,iValue)
			return value;
		} else {
			return false;
	}
}

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');
	if(getCookie('rn') == 'y') {
		delCookie('rn')
		return true;
	} else {
		return false;
	}
}

/*-----------------------------------------------------------------------------------------------------------

	Defector detector (works in IE 5+ & Netscape 6+).
	To implement, do this:

	1) assign "Init();" to the window's onload event, and "DefDetect();" to the window's onunload event
	2) ensure that "arcadeInstalled" is set equal to the value of  ebi attrameter  'games.racInstalled'
	    on the page prior to calling Init()


-------------------------------------------------------------------------------------------------------------*/

//detect browser and assign event listener
function Init() {
	//initialize detector flag
	window.bHLink = false;

	if (arcadeInstalled != 1)
		if (document.attachEvent) {	//IE
		  document.attachEvent('onclick', clickHandler);
		}
		else if (document.addEventListener) {	//NN
		  document.addEventListener('click', clickHandler, false);
		}
}


//onClick event handler
//sets bHLink to true if click was a link
function clickHandler (evt) {
	if (document.attachEvent) {
		if (window.event.srcElement.tagName == "A") {
			bHLink = true;
		}  else {
			var el = window.event.srcElement;
			while ((el != null) && (el.tagName != "A") && (el.tagName !="HTML")) {
				el = el.parentElement
				if (el.tagName == "A") {
					bHLink = true;
				} else {
					bHLink = false;
				}
			}
		}
	} else if (document.addEventListener) {
		if (evt.target.parentNode.nodeName == "A" || evt.target.nodeName == "A") {
			bHLink = true;
		} else {
			bHlink = false;
		}
	}	
}

//check cookie for detector expiration
function bDetectorEnabled() {
	if (getCookie('def')=='y') {
		//detector is disabled
		return false;
	} else {
		//disable detector for 24 hours
		setCookie('def','y','1')
		return true;
	}
}

//def detector action code, called in body.onunload()
//if clicking on a 'leave' link, spawn window
function DefDetect() {
	if ( arcadeInstalled != 1 && bHLink == false && bDetectorEnabled() ) {
		//ignore for NN 4.7
		if (!(navigator.appName=="Netscape" && (parseFloat(navigator.appVersion) <= 4.8))){
		    window.open("http://www.realarcade.com/popup_030818.html?src=&distcode=R140&tps="+thirdParty,"winMessage","scrollbars=no,left=20,top=20,width=250,height=300,noresize");

		}
	}
}

/*-----------------------------------------------------------------------------------------------------------

	End Defector detector:

-------------------------------------------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------------------------------------

	Tool Tip (works in IE 5+ (& Netscape 6+ (not yet!))).
	To implement, do this:

	call showLayer on mouseover and hideLayer on mouseout
	pass a string containing the div's id


-------------------------------------------------------------------------------------------------------------*/
function showLayer(layerID)
{	
	var evt = window.event || arguments.callee.caller.arguments[0];
	var layerObj = document.getElementById(layerID);
	var dmlayerOffsetTop = layerObj.scrollHeight + 20;

	var docWidth = (document.all) ? document.body.clientWidth : window.innerWidth;
	var tmpTop = (document.body.scrollTop + evt.clientY) - dmlayerOffsetTop;

	var tmpLeft = evt.clientX + 20;
	var layerObjAbsRt = docWidth - 170;
	if(tmpLeft > layerObjAbsRt) tmpLeft = layerObjAbsRt
	var layerObjAbsLft = (tmpLeft < 0) ? 1 : tmpLeft;

	var layerObjAbsTop = (tmpTop < document.body.scrollTop) ? document.body.scrollTop + 0 : tmpTop;

	if (document.all) {
		//ie
		layerObj.style.posLeft = layerObjAbsLft;
		layerObj.style.posTop = layerObjAbsTop;
	} 
	/*
	else {
		//netscape
		layerObj.style.left = layerObjAbsLft;
		layerObj.style.top = layerObjAbsTop;
	}
	*/
	layerObj.style.visibility = "visible";
}

function hideLayer(layerID)
{
	document.getElementById(layerID).style.visibility="hidden";
}


/*-----------------------------------------------------------------------------------------------------------

	sizeWindowToContent(winDiv,frmName,frmDiv)
	 - used by web game pages

-------------------------------------------------------------------------------------------------------------*/
function sizeWindowToContent(winDiv,frmName,frmDiv) {
	try
	{
		if(frmName)
		{
			document.getElementById(frmName).style.height = window.frames[frmName].document.getElementById(frmDiv).offsetHeight;
		}

		var oH = document.getElementById(winDiv).offsetHeight;
		var oW = document.getElementById(winDiv).offsetWidth;

		window.resizeTo( oW + 200, oH + 100 );

		var myW = 0, myH = 0;

		myW = window.document.body.clientWidth; 
		myH = window.document.body.clientHeight;

		resW = ( ( oW + ( ( oW + 200 ) - myW ) ) < screen.availWidth ) ? ( oW + ((oW + 200 ) - myW) )  : screen.availWidth;
		resH = ( ( oH + ((oH + 100 ) - myH ) ) < screen.availHeight ) ? ( oH + ((oH + 100 ) - myH) ) : screen.availHeight;

		if(document.all)
		{
			window.resizeTo( resW, resH);
		}
		else
		{
			window.innerHeight = oH;
			window.innerWidth = oW;
		}
	}
	catch(e) 
	{
		return false;
	}
	
}

/*-----------------------------------------------------------------------------------------------------------

	nextDlImage
	 - used by web game pages

-------------------------------------------------------------------------------------------------------------*/
function nextDlImage(d, arr) {
	str = "url(" + arr[imgIndex].src + ")";
	if ( !arr[imgIndex].loadError ) document.getElementById(d).style.backgroundImage = str;
	imgIndex++;
	if( imgIndex == (arr.length) ) imgIndex = 0;
}

function preloadError() {
	this.loadError = true;
}