/* Ajax Default Request Handle */

function default_handle(callback_element, strText) {
    document.getElementById(callback_element).innerHTML = strText;
}

function defaultPopupHandle(strText) {
	displayPopup(objPopup, strText, false, 250);
}

function defaultPopupHandleCentered(strText) {
	displayPopup(objPopup, strText, true, 250);
}

function hideElement(callback_element, strText) {
	document.getElementById(callback_element).style.display = 'none';
}

/* Places strHTML into callback_element's innerHTML. Runs JavaScript specified by strJS */
function updateElementRunJS(callback_element, strText) {
	var objReturn = eval('(' + strText + ')');

	default_handle(callback_element,objReturn.strHTML); /* Place strHTML */
	eval(objReturn.strJS); /* Run strJS */
}

function setAlertMessage(strResponse) {
	if(strResponse) {
		var objRecords = eval('(' + strResponse + ')');

		showHoverAlert(objRecords.strAlertMessage, objRecords.strSuccErr, 5);
	}
}


/* Ajax Http Request Function */

/*
    Desc: The AjaxRequest operates across all popular browsers and works as follows:
    The parameters of the function are 'URL', 'Element ID' where 'Return Text' will be returned,
    Function that will be called with the 'Element ID' and 'Return Text' as parameters and XML boolean.

    1st Param:
    - If you choose to just call a request on the server without having a return, you may only pass the
    first URL parameter. The file in the URL will be executed on the server with NO-return.
    
    2nd Param:
    - When you call the function with two parameters, the second should be the ID of the element where the 'echo'
    of the URL file will be returned.
    
    3rd Param:
    - When you call the function with three parameters, your third parameter will be the JavaScript function
    which will be called when the request has been executed. Instead of returning the 'echo' from the URL directly
    to the innerHTML of 'Element ID', it will call the function [callback_function]( [callback_element], 'Return Text' )
    This gives more versitility to what you want to do with the return. You can tokenize it with JavaScript, and perform
    various functions on the client side. A function call with three parameters should be used when a LOT OF DATA
    is returned in the 'Return Text'. It will decrease the amount of data that is sent between client and server
    and improve overall performance. However, if the 'Return Text' is small, this is not necessary.
    
    4th Param:
    - The forth parameter should be used when XML text is returned in the 'Return Text'. It enhances performance
    and further standardises return. This parameter should only be used if strictly XML is to be returned.
*/

function AjaxRequest(url, callback_element, callback_function, method_type ) {

    var http_request = false;

	/* Mozilla, Fire Fox, Safari, IE7 */
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
           http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { /* Internet Explorer 6 */
        try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        return false;
    }

    http_request.onreadystatechange = function() {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				var strResponseEnding = 'Text';

				if (callback_function) {
					if(callback_element == null) {
				  		callback_function(eval('http_request.response'+strResponseEnding));
					} else {
						var strTemp = eval('http_request.response'+strResponseEnding);
						if(typeof callback_function == 'string') { /* If function is passed as a string */
							eval(callback_function+'("'+callback_element+'",strTemp);');
						} else { /* If function is passed as a function */
							callback_function(callback_element,strTemp);
						}
					}
				} else {
					if( callback_element ) {
						default_handle(callback_element, eval('http_request.response'+strResponseEnding) );
					}
				}
            } else {
               /* alert('There was a problem with the request.(Code: ' + http_request.status + ')'); */
            }
        }
    };
    if( method_type == 'POST') {

		urlparams = url.split('?');
		url = urlparams[0];
		params = urlparams[1];

		http_request.open('POST', url, true);

		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", params.length );
		http_request.setRequestHeader("Connection", "close");
		http_request.setRequestHeader("Authorization", "Basic bXVjaGdhbWVzOnhldDU1am9j" );

	    http_request.send( params );
	} else {
	    http_request.open('GET', url, true);
	    http_request.send(null);
	}

}var arrPhotos 				= new Array();

var intX;
var intY;

var strLastField			= '';
var strVisitedURL 			= '';
var blnAnimation			= false;
var blnReceiverDropdownOpen = false;
var blnDropdownOpen 		= false;
var blnSending 				= false;
var blnLoader				= false;

/* Initialized the Loading icon */
var imgLoader = new Image(66,66);
imgLoader.src = 'http://www.muchgames.com/images/loading.gif';

var arrStaticTabs 		= new Object();

document.onmouseup = mouseUp;

/*
*	Function is fired when mouse is moved. It calls the calculation of mouse coordinates
*	Return: none, sets intX and intY global mouse coordinate variables
*/
function mouseUp(e){
	e			= e || window.event;

	intX = mousePosX(e);
	intY = mousePosY(e);
	
	if(blnReceiverDropdownOpen) {
		closeMessageReceiverDropdown();
	}
}

function mousePosX(e) {
	var intXPosition=0;
	
	if(!e) {
		var e=window.event;
	}
	if(e.pageX) {
		intXPosition=e.pageX;
	} else if(e.clientX&&document.body.scrollLeft) {
		intXPosition=e.clientX+document.body.scrollLeft;
	} else if(e.clientX&&document.documentElement.scrollLeft) {
		intXPosition=e.clientX+document.documentElement.scrollLeft;
	} else if(e.clientX) {
		intXPosition=e.clientX;
	}
	return intXPosition;
}

function mousePosY(e) {
	var intYPosition=0;
	
	if(!e) {
		var e=window.event;
	}
	if(e.pageY) {
		intYPosition=e.pageY;
	} else if(e.clientY&&document.body.scrollTop) {
		intYPosition=e.clientY+document.body.scrollTop;
	} else if(e.clientY&&document.documentElement.scrollTop) {
		intYPosition=e.clientY+document.documentElement.scrollTop;
	} else if(e.clientY) {
		intYPosition=e.clientY;
	}
	return intYPosition;
}

function setWindowWidth() {
	intWindowWidth = getWindowWidth();
	intXOffset = getScrollLeft();
}

function setWindowHeight() {
	intWindowHeight = getWindowHeight();
	intYOffset = getScrollTop();
}

/****** Tooltips ******/

function getElementPosition( objThis ) {
	var intPosLeft = intPosTop = 0;
	if (objThis.offsetParent) {
		do {
			intPosLeft += objThis.offsetLeft;
			intPosTop += objThis.offsetTop;
		} while (objThis = objThis.offsetParent);
	}

	if( navigator.appName == 'Safari' ){
		intPosTop += 4;
	}

	return [intPosLeft, intPosTop];
}

function initToolTip() {
	var objToolTip				= document.createElement('div');
	objToolTip.id 				= 'tooltip';
	objToolTip.className		= 'vNo';

	var objToolTipInfo 			= document.createElement('div');
	objToolTipInfo.id			= 'tooltip_info';
		
	var objToolTipArrow 		= document.createElement('div');
	objToolTipArrow.id			= 'tooltip_arrow';
	
	objToolTip.appendChild(objToolTipInfo);
	objToolTip.appendChild(objToolTipArrow);
	
	document.body.appendChild( objToolTip );
}

function initFade() {

	var objFade		= document.createElement('div');
	objFade.id 		= 'fade_alert_container';

	var objFadeWrapper	= document.createElement('div');
	objFadeWrapper.id	= 'fade_alert_wrapper';

	objFadeWrapper.innerHTML = '<div id="fade_alert_box"></div>';

	objFade.appendChild( objFadeWrapper );
	
	objTop			= document.getElementById('top');

	document.getElementById('container').insertBefore( objFade, objTop );
}

function showToolTip( objThis, strCaption ) {
	if( blnAnimation == false ) {
		arrPosition = getElementPosition( objThis );
		
		intPosLeft = arrPosition[0]-2;
		intPosTop = arrPosition[1] - 34;

		intCaptionLength = strCaption.length;

		var objToolTip 				= document.getElementById('tooltip');
		var objToolTipInfo 			= document.getElementById('tooltip_info');
		var objToolTipArrow 		= document.getElementById('tooltip_arrow');
		objToolTip.className 		= 'vYes';

		objToolTipArrow.className 			= 'tooltip_left';
		objToolTip.style.left 				= '0px';
		objToolTip.style.top 				= intPosTop+ 'px';
		
		if ( navigator.appName == 'Microsoft Internet Explorer' ) {
			if( parseFloat(navigator.appVersion.split("MSIE")[1]) == 6 ) {
				objToolTip.style.width='180px';
			}
		}

		objToolTipInfo.innerHTML 			= strCaption;

		if( intPosLeft > getWindowWidth() / 2 ){
			intFlippedPosition 			= ( intPosLeft - objToolTip.offsetWidth + objThis.offsetWidth ) + 'px';
			objToolTip.style.left 		= intFlippedPosition;
			objToolTipArrow.className 	= 'tooltip_right';
		} else {
			objToolTip.style.left 		= intPosLeft+ 'px';
		}

	}
}

function hideToolTip( ) {
	if( blnAnimation == false ) {
		document.getElementById('tooltip').className = 'vNo';
	}
}


/** Removes carriage returns and new lines and tabs ***/

function removeNL(strRemove) {
	var strClean = '';
	for (i=0;i<strRemove.length;i++) {
		if (strRemove.charAt(i) != '\n' && strRemove.charAt(i) != '\r' && strRemove.charAt(i) != '\t') {
			strClean += strRemove.charAt(i);
		}
	}
	return strClean;
}



/*** Get Scroll Positioning ***/

function getScrollTop() {
	var intScrollTop = null;
	if(window.innerHeight) {
		intScrollTop = window.pageYOffset;
	} else if(document.documentElement.clientHeight) {
		intScrollTop = document.documentElement.scrollTop;
	} else {
		intScrollTop = document.body.scrollTop;
	}
	return intScrollTop;
}

function getScrollLeft() {
	var intScrollLeft = null;
	if(window.innerWidth) {
		intXOffset = window.pageXOffset;
	} else if(document.documentElement.clientWidth) {
		intXOffset = document.documentElement.scrollLeft;
	} else {
		intXOffset = document.body.scrollLeft;
	}
	return intScrollLeft;
}

function getWindowHeight() {
	var intHeight = null;
	if(window.innerHeight) {
		intHeight = window.innerHeight;
	} else if(document.documentElement.clientHeight) {
		intHeight = document.documentElement.clientHeight;
	} else {
		intHeight = document.body.clientHeight;
	}
	return intHeight;
}

function getWindowWidth() {
	var intWidth = null;
	if(window.innerWidth) {
		intWidth = window.innerWidth - 17;
	} else if(document.documentElement.clientWidth) {
		intWidth = document.documentElement.clientWidth;
	} else {
		intWidth = document.body.clientWidth;
	}
	return intWidth;
}

function fadeElement(strElementId, intTimeInSeconds ) {

	if( intTimeInSeconds == undefined ) {
		intTimeInSeconds = 4;
	}
	if( intTimeInSeconds != 0 ) {
		setTimeout( function() { document.getElementById( strElementId ).style.display = 'none'; }, intTimeInSeconds*1000);
	}
}

/* Loads contents for a panel. Ajax can be turned off / on . */
function loadPage( intPage, strPageURL , strParams, blnAjax, strInto ) {

	var strURL = 'http://www.muchgames.com/' + strPageURL + '?' + strParams + 'intPage=' + intPage;

	if( strURL != strVisitedURL ){
		if( blnAjax ) {

			displayLoading();

			var fncCallback = function( strElementId, strResponse ){
				document.getElementById( strElementId ).innerHTML = strResponse;
				hideLoading();
			};
			AjaxRequest( strURL, strInto, fncCallback );

		} else {
			location.href = strURL;
		}
	}

	strVisitedURL = strURL;
}


/* Fills all the specified selection fields with specified values on the page */

function fillSelections( objSelects ) {
	for (var i in objSelects) {
		if(objSelects[i] != '' && parseInt(objSelects[i], 10) != 0) {
			document.getElementById(i).value = objSelects[i];
		}
	}
}


/* Fills all the specified check fields with specified values on the page */

function fillChecks( objChecks ) {
	for (var i in objChecks) {
		if( objChecks[i] == '1' || objChecks[i] == 'yes' ) {
			var objCheck = document.getElementById(i);

			objCheck.checked = true;
			toggleCheck( objCheck );
		}
	}
}

/* Toggles checkbox */

function toggleCheck( objCheck ) {

	if( objCheck.checked ) {
		strClassName = 'fBo';
		blnCheck = true;
	}
	else {
		strClassName = '';
		blnCheck = false;
	}

	if (objCheck.parentNode.nodeName == 'LABEL') {
		objCheck.parentNode.className = strClassName;
	}
	objCheck.checked = blnCheck;
}


/* Search */

function searchGames( strMode, strView ) {

	var strGameName = '';
	var strCategory = '';
	var strOrderBy = '';
	var strHot = '';
	var strMultiplayer = '';
	var strOnline = '';
	var blnTopRated = '';
	var blnPopular = '';
	var strHighscores = '';
	var strGameView = ( strView == undefined ) ? '' : strView;

	var strGameName = document.getElementById( 'strQuery'+strMode ).value;

	if( strMode == 'Advanced' ) {

		strCategory = document.frmAdvancedSearch.strCategory.value;
		strOrderBy = document.getElementById('strOrderBy').value;

		if(document.frmAdvancedSearch.strHot.checked) 			{ strHot = 'yes'; }
		if(document.frmAdvancedSearch.strMultiplayer.checked) 	{ strMultiplayer = 'yes'; }
		if(document.frmAdvancedSearch.strOnline.checked) 		{ strOnline = 'yes'; }
		if(document.frmAdvancedSearch.blnTopRated.checked) 		{ blnTopRated = 'yes'; }
		if(document.frmAdvancedSearch.blnPopular.checked) 		{ blnPopular = 'yes'; }
		if(document.frmAdvancedSearch.strHighscores.checked) 	{ strHighscores = 'yes'; }

	}

	if( strGameName == 'search games' || strGameName == '' ) {
		strGameName = '';
	}
	location.href =' http://www.muchgames.com/searchgames.php?strView='+strGameView+'&strGameName='+strGameName+'&strCategory='+strCategory+'&strHot='+strHot+'&strMultiplayer='+strMultiplayer+'&strOnline='+strOnline+'&blnTopRated='+blnTopRated+'&blnPopular='+blnPopular+'&strHighscores='+strHighscores+'&strOrderBy='+strOrderBy;
}

/* search gamers on gamers page and search gamers page */
function searchGamers( strMode ) {

	var strUserName 	= document.getElementById( 'strQuery'+strMode ).value;

	var strCountryCode 	= '';
	var intAgeFrom 		= '';
	var intAgeTo		= '';
	var strGender		= '';
	var strOnline		= '';
	var strPhoto		= '';
	var strOrderBy 		= '';

	if( strMode == 'Advanced' ) {

		if( document.getElementById('strOrderBy') ) {
			strOrderBy = document.getElementById('strOrderBy').value
		}

		strCountryCode 	= document.frmAdvancedSearch.strCountryCode.value;
		intAgeFrom 		= document.frmAdvancedSearch.intAgeFrom.value;
		intAgeTo 		= document.frmAdvancedSearch.intAgeTo.value;
		strGender 		= document.frmAdvancedSearch.strGender.value;

		strOnline = (document.frmAdvancedSearch.strOnline.checked) ? 'yes' : '';
		strPhoto = (document.frmAdvancedSearch.strPhoto.checked) ? 'yes' : '';
		
	}

	location.href =' http://www.muchgames.com/searchgamers.php?&strUserName='+strUserName+'&strCountryCode='+strCountryCode+'&intAgeFrom='+intAgeFrom+'&intAgeTo='+intAgeTo+'&strGender='+strGender+'&strOnline='+strOnline+'&strPhoto='+strPhoto+'&strOrderBy='+strOrderBy;

}


function toggleElement( strElementId ) {
	var objElement = document.getElementById( strElementId );
	objElement.className = objElement.className.indexOf( 'vNo' ) ? objElement.className.replace( 'vYes', 'vNo' ) : objElement.className.replace( 'vNo', 'vYes' );
}

function expandElement( strElementId ) {
	var objElement = document.getElementById( strElementId );
	objElement.className = objElement.className.indexOf( strElementId ) ? objElement.className.replace( 'expanded', strElementId ) : objElement.className.replace( strElementId, 'expanded' );
}

/* Showding hiding drop downs at the top */
function showDropDown( strElementId ) {
	document.getElementById( strElementId ).style.display = 'block';
	blnDropdownOpen = true;
}

function hideDropDown( strElementId ) {
	blnDropdownOpen = false;
	setTimeout( 'hideDropDownNow( \''+strElementId+'\')', 750);
}

function hideDropDownNow( strElementId ) {
	if( !blnDropdownOpen ) {
		var divDropDown = document.getElementById( strElementId );
		divDropDown.style.display = 'none';
	}
}

/* Displays a loading icon in the center of the page */
function displayLoading() {
	setWindowWidth();
	setWindowHeight();
	if( !blnLoader ) {
		objLoader = document.createElement('div');
		objLoader.className = 'loading';
		objLoader.id = 'loading';
		
		objLoader.appendChild( imgLoader );
		
		document.body.appendChild( objLoader );

		blnLoader = true;
	} else {
		objLoader = document.getElementById('loading');
	}
	objLoader.style.top = (intWindowHeight / 2) - (objLoader.clientHeight / 2) + intYOffset + 'px';
	objLoader.style.left = (intWindowWidth / 2) - (objLoader.clientWidth / 2) + intXOffset + 'px';
	objLoader.style.visibility = 'visible';
}

function hideLoading() {
	if(objLoader) {
		objLoader.style.visibility = 'hidden';
	}
}

function contact( intGameId, strGameName ) {
	window.open( 'http://www.muchgames.com/report.php?intGameId='+intGameId+'&strGameName='+strGameName, 'Contact', 'left=100,top=100,status=no,toolbar=no,menubar=no,scrollbars=yes,width=800,height=440,location');
}

function forgotLoginInfo() {
	window.open( 'http://www.muchgames.com/report.php', 'Contact', 'left=100,top=100,status=no,toolbar=no,menubar=no,scrollbars=yes,width=800,height=400,location');
}

function smilies() {
	window.open( 'http://www.muchgames.com/smilies.php', 'Smilies', 'left=100,top=100,status=no,toolbar=no,menubar=no,scrollbars=yes,width=300,height=600,location');
}

function coins() {
	objPopup = showPopup('Coins, Items and Random Events');

    var strHTML = '<div class="wL">'
    +	'<div class="fBo">What are coins used for?</div><div>- Coins are used for purchasing items from the item shop.</div>'
    +	'<div class="fBo">What are items?</div><div>- You can collect items, give them to your friends and sell them.</div>'
    +	'<div class="fBo">What are random events?</div><div>- When you perform activities on the site such as rating games, commenting or just surfing the site, you always have a small chance of finding new items, sometimes even rare ones.</div>'
	+	'<br />'
	+	'<div class="fBo">How can I get more coins?</div>'
	+	'<hr /><div class="flL wSSM fs4 fBo">+100 coins</div><div class="flL wMLM">You invite a friend to join the site. To invite your friends now, please go to the <a href="http://www.muchgames.com/account/invite">Invite Friends</a> page.</div>'
	+	'<div class="clL"></div>'
	+	'<hr /><div class="flL wSSM fs4 fBo">+100 coins</div><div class="flL wMLM">You upload an avatar for the first time.</div>'
	+	'<div class="clL"></div>'
	+	'<hr /><div class="flL wSSM fs4 fBo">+50 coins</div><div class="flL wMLM">You report something that is helpful to us. It could be a bug on the site, abuse or a helpful suggestion. We read it all and evaluate your feedback.</div>'
	+	'<div class="clL"></div>'
	+	'<hr /><div class="flL wSSM fs4 fBo">+50 coins</div><div class="flL wMLM">You advance to a new level. To advance levels, you can play games, rate them and write useful comments on them. This will get you points and coins at the same time.</div>'
	+	'<div class="clL"></div>'
	+	'<hr /><div class="flL wSSM fs4 fBo">+25 coins</div><div class="flL wMLM">You sign up to the site.</div>'
	+	'<div class="clL"></div>'
	+	'<hr /><div class="flL wSSM fs3 fBo">+5 coins</div><div class="flL wMLM">You comment on a game. <b>Important Note</b>: If your comments are not precise and related to the game, we will first deduct your points, then ban you from the site. Do <b>NOT</b> write comments JUST to earn more points!</div>'
	+	'<div class="clL"></div>'
	+	'<hr /><div class="flL wSSM fs3 fBo">+5 coins</div><div class="flL wMLM">You rate a game.</div>'
	+	'<div class="clL"></div>'
	+	'<hr /><div class="flL wSSM fs3 fBo">+1 coins</div><div class="flL wMLM">You play a game. <b>Hint</b>: Refreshing a game page a thousand times is NOT going to give you 1000 coins!</div>'
	+	'</div>';

	displayPopup(objPopup, strHTML, false, 600);
}

function getElementsByClass( strClass, strNode, strTag ) {
	var objClassElements = new Array();
	if (strNode == null) {
		strNode = document;
	}
	if (strTag == null) {
		strTag = '*';
	}

	var arrEls = strNode.getElementsByTagName(strTag);
	var intElsCount = arrEls.length;

	var strPattern = new RegExp("(^|\\s)"+strClass+"(\\s|$)");
	for (i = 0, j = 0; i < intElsCount; i++) {
		if (strPattern.test(arrEls[i].className) ) {
	    	objClassElements[j] = arrEls[i];
	    	j++;
	    }
	}
	return objClassElements;
}

function parseXML( strXML ) {
	try { /* Internet Explorer */
		objXML=new ActiveXObject("Microsoft.XMLDOM");
		objXML.async="false";
		objXML.loadXML(strXML);
		return objXML;
	} catch(e) {
		objParser=new DOMParser();
		objXML=objParser.parseFromString(strXML,"text/xml");
		return objXML;
	}
}


if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function (obj, fromIndex) {
		if (fromIndex == null) {
			fromIndex = 0;
		} else if (fromIndex < 0) {
			fromIndex = Math.max(0, this.length + fromIndex);
		}
		for (var i = fromIndex; i < this.length; i++) {
			if (this[i] === obj) {
				return i;
			}
		}
		return -1;
	};
}var strShadowBoxContent = 'pop_content_content';var strShadowBoxContentWrap = 'pop_content';var blnDarkenInit= false;function initPopup( strTitle, strNewDiv ) {var objPopup;objPopup = document.createElement('div');objPopup.innerHTML = '<div class="pop_box" id="pop_box">	<table id="pop_dialog_table" class="pop_dialog_table">		<tbody>		<tr>			<td class="pop_topleft"/>			<td class="pop_border"/>			<td class="pop_topright"/>		</tr>		<tr>			<td class="pop_border"/>			<td id="pop_content" class="pop_content">			</td>			<td class="pop_border"/>		</tr>		<tr>			<td class="pop_bottomleft"/>			<td class="pop_border"/>			<td class="pop_bottomright"/>		</tr>		</tbody>	</table></div>';document.body.appendChild(objPopup);objPopup = document.getElementById('pop_box');objPopupContent = document.getElementById(strShadowBoxContentWrap);objPopup.style.visibility = 'hidden'; if(strTitle != undefined) {strTitleHeader = '<div class="pop_title"><b>'+strTitle+'</b><div class="pop_close" onclick="javascript: hidePopup();"></div></div>';} else {strTitleHeader = '';}objPopupContent.innerHTML = strTitleHeader+'<div class="pop_content_content" id="'+strShadowBoxContent+'"></div>';return objPopup;}function showPopup( strTitle, strNewDiv ) {darkenBackground( true );var objPopup = initPopup(strTitle, strNewDiv);displayLoading();return objPopup;}function displayPopup( objPopup, strHTML, blnCentered, intWidth, intHeight ) {if(strHTML) {objContent = document.getElementById(strShadowBoxContent);objContent.innerHTML = strHTML;}var intScrollBarWidth = 20;var intLeft = 0; var intTop = 0; objPopup.style.height = '';objPopup.style.width = '';setWindowWidth();setWindowHeight();if(intHeight) {objPopup.style.height = intHeight + 'px';}if(intWidth) {objPopup.style.width = intWidth + 'px';}objPopup.style.display = 'block';intBoxWidth = objPopup.clientWidth;intBoxHeight = objPopup.clientHeight;if(intHeight) {objPopup.style.height = intBoxHeight + 'px';}if(intWidth) {objPopup.style.width = intBoxWidth + 'px';}if(blnCentered) {intLeft = intXOffset + (intWindowWidth - intBoxWidth) / 2;intTop = intYOffset + (intWindowHeight - intBoxHeight) / 2;} else {intLeft = intX;intTop = intY;}var intPadding = 14;var intYOverlap = intTop + intBoxHeight + intScrollBarWidth + intPadding - intWindowHeight - intYOffset;if(intYOverlap > 0) {intTop -= intYOverlap;}var intXOverlap = intLeft + intBoxWidth + intScrollBarWidth + intPadding - intWindowWidth - intXOffset;if(intXOverlap > 0) {intLeft -= intXOverlap;}if(intTop - intYOffset < 0) {intTop = intYOffset + 3;}if(intLeft - intXOffset < 0) {intLeft = intXOffset + 3;}objPopup.style.left = intLeft + 'px';objPopup.style.top = intTop + 'px';if(objLoader) {objLoader.style.visibility = 'hidden';}objPopup.style.visibility = 'visible';blnPopupOpen = true;}function hidePopup() {objPopup.style.visibility = 'hidden';if( document.getElementById('gamewrapper') ) {document.getElementById('gamewrapper').style.display = 'block';}blnPopupOpen = false;darkenBackground( false );}function notLoggedIn( strParameter ) {var strParameter = ( !strParameter ) ? '' : strParameter;location.href='http://www.muchgames.com/register/'+strParameter;}function blockedPopup(){objPopup = showPopup('Browser Error');var strHTML = ''+'Your browser blocked the popup. You need to <b>enable popups</b> on this site in order to use this feature. '+'<a class="fBo" href="http://www.muchgames.com/faq.php#15">Click here</a> to learn how to enable popups for your browser.'+'<div class="aC">'+'<br />'+'<input class="button" type="button" value="Close" onclick="javascript: hidePopup();" />'+ '</div>';displayPopup(objPopup, strHTML, false, 240);}function darkenBackground( blnDarken ) {if( !blnDarkenInit ) {objBackground = document.createElement('div');objBackground.id = 'darkbackground';document.body.appendChild( objBackground );blnDarkenInit = true;} else {objBackground = document.getElementById('darkbackground');}if( blnDarken ) {objBackground.style.display = 'block';} else {objBackground.style.display = 'none';}}function showFade( blnPositive, strTitle, strHTML, intFadeTime ) {positionFadeAlert();var strType = blnPositive ? 'up' : 'down';var strTitle = blnPositive ? '<span class="ccG fs3">'+strTitle+'</span>' : '<span class="ccR fs3">'+strTitle+'</span>';var objFadeBox = document.getElementById('fade_alert_box');var objFadeContainer= document.getElementById('fade_alert_container');var intFadeSeconds= ( intFadeTime == undefined ) ? '4' : 0;objFadeBox.className = 'fade_alert_box fade_alert_success';objFadeBox.innerHTML = ''+'<div class="fade_alert_close" onclick="javascript: closeFadeAlert();"></div>'+'<img src="http://www.muchgames.com/images/icons/thumb_'+strType+'_dark.gif" alt="" /> '+strTitle+''+'<div class="fs1 p7tb ccW">'+strHTML+'</div>';objFadeContainer.style.display = 'block';fadeElement( 'fade_alert_container', intFadeSeconds );}function closeFadeAlert() {document.getElementById('fade_alert_container').style.display = 'none';}function positionFadeAlert() {setWindowHeight();var objHoverAlert = document.getElementById('fade_alert_container');if(objHoverAlert) {objHoverAlert.style.top = ( ( ( intWindowHeight - 100 ) / 2 ) ) + 'px';}}function recoverLogin() {var strEmail = document.getElementById( 'strRecoveryEmail' ).value;location.href = 'http://www.muchgames.com/process_recovery.php?&strEmail='+strEmail;}function signup( strFormType ) {document.getElementById('frm'+strFormType+'Registration').submit();}function checkUserName() {var objInput = document.getElementById('strRegisterUserName');var objUserName = document.getElementById('strUserName_check');if( validateUserName( objInput.value ) ) {if( objInput.value != '' ) {AjaxRequest('http://www.muchgames.com/x_checkUserName.php?strUserName='+objInput.value, 'strUserName_check');} else {objUserName.innerHTML = '';}} else {objUserName.innerHTML = ' <img src="http://www.muchgames.com/images/icons/x.gif" /> <b>No Spaces! Only letters and numbers!</b>';}if( objUserName.innerHTML == '' ) {return true;} else {return false;}}function validateUserName( strUserName ) {var strAllowedChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';var intUsernameLength = strUserName.length;for (i = 0; i < intUsernameLength; i++) {        if ( strAllowedChars.indexOf( strUserName.charAt(i) ) == -1 ){return false;}}return true;}function checkPassword() {var strPassword = document.getElementById('strRegisterPassword').value;var strPasswordConfirm = document.getElementById('strPasswordConfirm').value;if( strPassword != '' && strPasswordConfirm != '' ) {if( strPassword != strPasswordConfirm ) {strPasswordMessage = ' <img src="http://www.muchgames.com/images/icons/x.gif" /> <b>Passwords do not match!</b>';} else {strPasswordMessage = '';}} else {strPasswordMessage = '';}document.getElementById('strPassword_check').innerHTML = strPasswordMessage;document.getElementById('strPasswordConfirm_check').innerHTML = strPasswordMessage;if( strPasswordMessage == '' ) {return true;} else {return false;}}function checkEmail() {var objInput = document.getElementById('strEmail');var objEmail = document.getElementById('strEmail_check');if( objInput.value != '' ) {AjaxRequest('http://www.muchgames.com/x_checkEmail.php?strEmail='+objInput.value, 'strEmail_check');} else {objEmail.innerHTML = '';}if( objEmail.innerHTML == '' ) {return true;} else {return false;}}function quickSwap( strType ) {if( strType == 'quickregister' ) {document.getElementById( strType ).className = '';document.getElementById( 'quicklogin' ).className = 'vNo';document.getElementById('quickmessage').innerHTML = 'Already have an account? <a href="javascript: quickSwap(\'quicklogin\');">Login Now ..</a>';} else {document.getElementById( strType ).className = 'signupbox';document.getElementById( 'quickregister' ).className = 'vNo';document.getElementById('quickmessage').innerHTML = 'Dont have an account yet? <a href="javascript: quickSwap(\'quickregister\');">Sign Up Now ..</a>';}}var arrUsers= new Array();var intLoaded= 0;var intUpdateChatTimer= 10000;var intCountDown= 0;var intCountDownId= 0;var intLoadId = 0;var blnShare = false;var objGameDiv = null;var objAdDiv = null;function setPrerollAndGame( blnPreroll, intPrerollTimer ) {if( blnPreroll ) { intCountDown = intPrerollTimer;objGameDiv = document.getElementById('gamewindow');objAdDiv = document.getElementById('prerollad');objGameDiv.style.display = 'none';objAdDiv.style.display = 'block';intIntervalTime = intPrerollTimer * 10;intLoadId = setInterval("loadGame()", intIntervalTime );}}function loadGame() {intLoaded++;var objCount = document.getElementById('loadbar_progress');objCount.style.width = intLoaded+'%';if( intLoaded >= 99 ) {showGame();}}function showGame() {objAdDiv.style.display = 'none';objGameDiv.style.display = 'block';clearInterval( intLoadId );}function rateGame( intGameId, intUserId, fltRating) {var fncCallback = function( strResponse ) {var arrParts = strResponse.split('$%^#&@@@');if( arrParts[0] == 'true' ) {var objVoteCount = document.getElementById('votecount');var objRating = document.getElementById('rating');var intNoFade = ( arrParts[1] == '' ) ? undefined : 0;intVoteCount = parseInt(objVoteCount.innerHTML);fltOldRating = parseFloat(objRating.innerHTML);fltNewRating = Math.round(((fltOldRating*intVoteCount) + fltRating)/(intVoteCount+1)*100)/100;intNewVotecount = ++intVoteCount;objRating.innerHTML = fltNewRating;objVoteCount.innerHTML = intNewVotecount;showFade( true, 'Game rated!', 'Thank you for rating the game! Please be as accurate as you can when you rate games.<hr /><ul class="coins"><li class="coin5"></li></ul> <span class="fs4 fBo">You collected 5 coins!</span><br />'+arrParts[1], intNoFade );var objRatingYes = document.getElementById('rating_yes');var objRatingNo = document.getElementById('rating_no');objRatingYes.className = '';objRatingNo.className = 'vNo';} else {var intMinutes = parseInt( arrParts[1] / 60 );var intSeconds = arrParts[1] % 60;showFade(false, 'Whoah .. Easy there!', 'Please play the game some more before you rate it. <br /><br />Please try again in <b>'+intMinutes+'</b> minutes and <b>'+intSeconds+'</b> seconds.', intNoFade );}};if( '' != '' ) {AjaxRequest('http://www.muchgames.com/x_rateGame.php?intGameId=' + intGameId + '&intUserId=' + intUserId + '&fltRating=' + fltRating, null, fncCallback);} else {notLoggedIn( 'rategame' );}}function postGameComment( intUserId, intGameId, txtComment, fltGameplay, fltGraphics, fltSound, fltEffects, fltControl ) {var fncCallback = function( strResponse ) {var objComment = document.getElementById('game_comment');var objNewComment = document.getElementById('new_comment');var objRecordCount = document.getElementById('comment_count');var objRecordFrom = document.getElementById('comment_from');var objRecordTo = document.getElementById('comment_to');var objNoData = document.getElementById('nodata');var arrParts = strResponse.split('$%^#&@@@');var intNoFade = ( arrParts[2] == '' && arrParts[0] == 'true' ) ? undefined : 0;if( arrParts[0] == 'true' ) {objComment.className = 'vNo';objNewComment.innerHTML = arrParts[1];intNewRecordCount = parseInt(objRecordCount.innerHTML);intNewRecordFrom = parseInt(objRecordFrom.innerHTML);intNewRecordTo = parseInt(objRecordTo.innerHTML);objRecordCount.innerHTML = ++intNewRecordCount;if(intNewRecordFrom == 0) {objRecordFrom.innerHTML = ++intNewRecordFrom;}if(intNewRecordTo < 10) {objRecordTo.innerHTML = ++intNewRecordTo;}if(intNewRecordCount == 1) {objNoData.className = 'vNo';}showFade(true, 'Game commented!', 'Thank you for commenting on the game. Please write your comments as detailed as you can.<hr /><ul class="coins"><li class="coin5"></li></ul> <span class="fs4 fBo">You collected 5 coins!</span><br />' +arrParts[2], intNoFade );var objCommentYes = document.getElementById('comment_yes');var objCommentNo = document.getElementById('comment_no');objCommentYes.className = '';objCommentNo.className = 'vNo';} else {var intMinutes = parseInt( arrParts[1] / 60 );var intSeconds = arrParts[1] % 60;showFade(false, 'Whoah .. Easy there!', 'Please play the game some more before you write a comment about it. Your comments should be accurate and informative. Simply writing "Cool game." or "I hated it." is not good enough. Short and useless comments get deleted and coins are deducted as a penalty.<br /><br />Please try again in <b>'+intMinutes+'</b> minutes and <b>'+intSeconds+'</b> seconds.', intNoFade );}};if( '' != '' ) {AjaxRequest('http://www.muchgames.com/x_postComment.php?intUserId='+intUserId+'&intGameId=' + intGameId + '&txtComment=' + txtComment + '&fltGameplay=' + fltGameplay + '&fltGraphics=' + fltGraphics + '&fltSound=' + fltSound + '&fltEffects=' + fltEffects + '&fltControl=' + fltControl, null, fncCallback);} else {notLoggedIn( 'postgamecomment' );}}function shareGame( strGameName, strPage ) {var arrEmails = new Array();arrEmails[0] = document.getElementById('strEmail1').value;arrEmails[1] = document.getElementById('strEmail2').value;arrEmails[2] = document.getElementById('strEmail3').value;var strName = document.getElementById('strName').value;var fncCallback = function(strResponse) {hideLoading();showFade(true, 'Game sent!', 'You have successfully sent out <b>'+strGameName+'</b> to your friends' );};if( arrEmails[0] != '' || arrEmails[1] != '' || arrEmails[2] != '' ) {if( !blnShare ) {displayLoading();AjaxRequest('http://www.muchgames.com/x_shareGame.php?strGameName='+strGameName+'&strPage='+strPage+'&arrEmails='+arrEmails+'&strName='+strName,  null, fncCallback);blnShare = true;} else {showFade(false, 'Do not spam!', 'Please do not spam. To send the game to more friends, refresh the page.', 0 );}} else {showFade(false, 'No emails entered!', 'You did not enter any emails. Make sure to fill out at least one email before trying to send.', 0 );}}function embedGame( strGamePage ) {var fncCallback = function( strResponse ) {hideLoading();objPopup = showPopup('Embed Code');displayPopup(objPopup, strResponse, true, 510, 300);};displayLoading();AjaxRequest('http://www.muchgames.com/x_embedGame.php?strGamePage='+strGamePage,  null, fncCallback);}var blnScoring = false;function score( strType, intUserId, intId, strFeedback ) {if( '' != '' ) {var fncCallback = function(strResponse) {var objScore = document.getElementById( strType+'_score_'+intId);intScore = parseInt( objScore.innerHTML );if( strFeedback == 'good' ) {objScore.innerHTML = ++intScore;} else {objScore.innerHTML = --intScore;}if( intScore > 0 ) {objScore.innerHTML = '+'+objScore.innerHTML;} else {objScore.parentNode.className = 'ccR';}document.getElementById('score_active_'+intId).className='vNo';var objThumbsActive = document.getElementById('score_inactive_'+intId);objThumbsActive.className = 'vYes';strInvFeedback = strFeedback == 'good' ? 'bad' : 'good';var objImage = document.getElementById('thumb_'+strInvFeedback+'_'+intId);objImage.src = objImage.src.replace('.gif','_gray.gif');blnScoring = false;};if( !blnScoring ) {AjaxRequest('http://www.muchgames.com/x_score.php?strType='+strType+'&intUserId='+intUserId+'&intId='+intId+'&strFeedback='+strFeedback, null, fncCallback );blnScoring = true;}} else {notLoggedIn( 'scoregamecomment' );}}var blnAnimation = false;function scrollTo(strElementId, strVerticalAlign, fncCallback) {blnAnimation = true;var intScrollTop = getScrollTop();var blnScrollDirection = null;var objElement = document.getElementById(strElementId);var intMoveToY = getElementPosition(objElement)[1];if(strVerticalAlign=="middle" || strVerticalAlign==undefined) {intMoveToY -= (getWindowHeight()/2 - objElement.clientHeight/2);}var intDistanceToScroll = null;if(intScrollTop - intMoveToY > 0) { intDistanceToScroll = intScrollTop - intMoveToY;intMultiplier = -1;} else { intDistanceToScroll = intMoveToY - intScrollTop;intMultiplier = 1;}scrollToWorker(intDistanceToScroll, 0, intMultiplier);if(fncCallback) {setTimeout(function() { fncCallback(objElement) }, 500);}}function scrollToWorker(intTotalDistanceToScroll, intDistanceScrolled, intMultiplier) {var intDistanceThisScroll;var intDistanceToScroll = intTotalDistanceToScroll - intDistanceScrolled;if(intDistanceToScroll > 5)intDistanceThisScroll = parseInt(intDistanceToScroll * 0.2);elseintDistanceThisScroll = 1;if(intDistanceScrolled <= intTotalDistanceToScroll) {intDistanceScrolled += intDistanceThisScroll;intDistanceThisScroll *= intMultiplier;window.scrollBy(0, intDistanceThisScroll);setTimeout(function() { scrollToWorker(intTotalDistanceToScroll, intDistanceScrolled, intMultiplier); }, 20);}}function highlightElement(objElement) {var objHighlight = document.createElement('div');var arrPosition = getElementPosition(objElement);var intBorderWidth = 5;var intPadding = 3;objHighlight.innerHTML = '&nbsp;';objHighlight.id = new Date().getTime();objHighlight.className = 'highlighted_element';objHighlight.style.border = intBorderWidth+'px solid #333';objHighlight.style.padding = intPadding+'px';objHighlight.style.height = objElement.clientHeight + 'px';objHighlight.style.width = objElement.clientWidth + 'px';objHighlight.style.left = (arrPosition[0]-intBorderWidth-intPadding) + 'px';objHighlight.style.top = (arrPosition[1]-intBorderWidth-intPadding) + 'px';document.body.appendChild(objHighlight);setTimeout(function() { unhighlightElement(objHighlight) }, 2000);}function unhighlightElement(objElement) {document.getElementById( objElement.id ).style.display = 'none';blnAnimation = false;} var blnLogin = false;var arrUsers= new Array();var blnSpamSafe = true;function showChatMessages( strResponse, strType ) {if( strResponse != '' ) {arrMessageReturn=strResponse.split("&@!#$");intMessageCount = arrMessageReturn.length;for(i=0;i<intMessageCount;i++) {arrParts=arrMessageReturn[i].split("@x@");if( arrParts[3] == '' ) {if( strType == 'private' ) {appendMessage(arrParts[0], arrParts[1], false, '', true, arrParts[2] );} else {appendMessage(arrParts[0], arrParts[1]);}}}}}function showChatUsers( strResponse ) {arrUserReturn = strResponse.split("&@!#$");intUserReturnCount = arrUserReturn.length;for(i=0;i<intUserReturnCount;i++) {arrUser = arrUserReturn[i].split("@x@");if(arrUsers.toString().indexOf(arrUser[0]) == -1) {appendUser( arrUser[0], arrUser[1], arrUser[2], arrUser[3], arrUser[4] );}}intUserCount = arrUsers.length;for(i=0;i<intUserCount;i++) {if(arrUserReturn.toString().indexOf(arrUsers[i]) == -1) {removeUser(arrUsers[i]);arrUsers.splice(i,1);}}document.getElementById('gamerschatting').innerHTML = arrUsers.length;}function toggleChat() {if( document.getElementById('chat').style.display == "none" ) {document.getElementById('chat').style.display = "";document.getElementById('sign').innerHTML = "-";} else {document.getElementById('chat').style.display = "none";document.getElementById('sign').innerHTML = "+";}}function toggleChatStatus() {if( blnChatStatus ) {blnChatStatus = false;document.getElementById('livechat_off').className = 'vNo';document.getElementById('livechat_on').className = '';appendMessage( '', 'You turned your chat off!', true );} else {blnChatStatus = true;document.getElementById('livechat_off').className = '';document.getElementById('livechat_on').className = 'vNo';appendMessage( '', 'You turned your chat on!', true );}}function talk( intGameId, intUserIdTo, strType ) {objMessage = document.chat_form.MESSAGE;intUserIdTo = ( strType != 'private' ) ? 0 : intUserIdTo;if( objMessage.value != '' && objMessage.value != 'type a message ..' && blnSpamSafe ) {if( strType != 'private' ) {appendMessage( '' , objMessage.value );} else {appendMessage( '' , objMessage.value, false, '', true, '' );}AjaxRequest('http://www.muchgames.com/process_chat.php?ACTION=add&GAME='+intGameId+'&USER='+intUserIdTo+'&MESSAGE='+objMessage.value+'&TYPE='+strType, '');objMessage.value = '';blnSpamSafe = false;setTimeout ( 'enableTalk()', 1000 );}}function enableTalk() {blnSpamSafe = true;}function appendMessage( strUser, txtMessage, blnNotification, strType, blnPrivate, dtmSent ) {var objTableBody = document.getElementById('messages');var objDiv = document.getElementById('chatbox');var objReference = document.getElementById('lastmessage');var objContent = document.createElement('div');var intColor= 0;objContent.id = 'lastmessage';if( blnNotification && !blnPrivate ) {if( strType == 'join' ) {intColor = 3;} else if( strType == 'leave' ) {intColor = 1;}objContent.innerHTML = '<b class="color'+intColor+'">' + strUser + txtMessage + '</b>';} else {intColor = ( arrUsers.indexOf(strUser) >= 0 ) ? arrUsers.indexOf(strUser) : 0;if( dtmSent != '' ) {dtmSent = 'Sent on '+dtmSent;}txtMessage = parseSmilies( txtMessage ) ;objContent.innerHTML = '<a title="'+dtmSent+'" class="red fBo" href="http://www.muchgames.com/users/' + strUser + '" target="_blank">' + strUser +'</a>&nbsp;:&nbsp;<span class="color'+intColor+'">' + txtMessage + '</span>';}if( !blnPrivate ) {objDiv.insertBefore( objContent, objReference );objDiv.scrollBottom = objDiv.scrollHeight;} else {objDiv.appendChild( objContent );objDiv.scrollTop = objDiv.scrollHeight;}}function appendUser( strUser, strAvatar, intLevel, intUserId, intUserIdToBlock ) {var objTableBody = document.getElementById('users');var objDiv = document.createElement('div');var objOptionsDiv = document.createElement('div');var strIcon= 'tool_block';arrUsers.push( strUser );objDiv.id = strUser;objDiv.className = 'chatuser';objDiv.innerHTML = '<img src="http://www.muchgames.com/'+strAvatar+'" alt="" />&nbsp;&nbsp;'+  '<a class="red fBo" style="position:relative; top:-5px;" href="http://www.muchgames.com/users/' + strUser + '" target="_blank">' + strUser +'</a>&nbsp;'+  '<img style="position:relative; top:-3px;" src="http://www.muchgames.com/images/level/'+intLevel+'.gif" alt="Level '+intLevel+'" />';if( intUserId != '' ) {if( intUserIdToBlock != '' ) {strIcon= 'tool_blocked';}objOptionsDiv.className = 'chatuseroptions';objOptionsDiv.innerHTML = '<a href="javascript: blockUser( '+intUserId+' );" class="hov" title="Block '+strUser+' ?"><img id="'+intUserId+'_blockicon" src="http://www.muchgames.com/images/icons/'+strIcon+'.gif" alt="" /></a>';objDiv.appendChild( objOptionsDiv );}objTableBody.appendChild(objDiv);}function blockUser( intUserId ) {var objBlockIcon = document.getElementById( intUserId+'_blockicon');var arrIconParts = objBlockIcon.src.split('/');var strImage= arrIconParts[arrIconParts.length - 1];var blnBlock= true;if( strImage == 'tool_block.gif' ) {objBlockIcon.src = 'http://www.muchgames.com/images/icons/tool_blocked.gif';} else {objBlockIcon.src = 'http://www.muchgames.com/images/icons/tool_block.gif';blnBlock = false;}AjaxRequest('http://www.muchgames.com/process_chat.php?ACTION=block&USER='+intUserId+'&STATUS='+blnBlock, '');}function removeUser( strUser ) {if( strUser ) {var objTableBody = document.getElementById('users');var objChild=document.getElementById(strUser);objTableBody.removeChild(objChild);}}function parseSmilies( txtMessage ) {objRegExp = /:([a-z0-9]+):/;arrReturn = objRegExp.exec( txtMessage );if( arrReturn ) {txtNewMessage = txtMessage.replace( arrReturn[0], '<img src="http://www.muchgames.com/images/smilies/'+arrReturn[0].replace(/:/g,'')+'.gif" alt="" />' );parseSmilies( txtNewMessage );return txtNewMessage;} else {return txtMessage;}}function addFriend(){ notLoggedIn( 'addfriend' ); }function addFavorite(){ notLoggedIn( 'addfavorite' ); }function openMessages(){ notLoggedIn( 'sendmessage' ); }function openFriends(){ notLoggedIn( 'openfriends' ); }function openFavorites(){ notLoggedIn( 'openfavorites' ); }function startPrivateChat(){ notLoggedIn( 'privatechat' ); }function postSketch(){ notLoggedIn( 'postsketch' ); }