/* 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>';}}function saveProfileLayout( strPageType, intTypeId ) {var objLeftDiv = document.getElementById('left');var objRightDiv = document.getElementById('right');var objInputLeft= document.getElementById('strLeftPanels');var objInputRight= document.getElementById('strRightPanels');var txtCode= document.getElementById('txtCode').value;  strSeperator = '';strLeftPanels = '';for( i in objLeftDiv.childNodes ) {if( objLeftDiv.childNodes[i].className == 'sortItem' && objLeftDiv.childNodes[i].id != '' ) {strLeftPanels += strSeperator + objLeftDiv.childNodes[i].id;strSeperator = '|';}}strSeperator = '';strRightPanels = '';for( i in objRightDiv.childNodes ) {if( objRightDiv.childNodes[i].className == 'sortItem' && objRightDiv.childNodes[i].id != '' ) {strRightPanels += strSeperator + objRightDiv.childNodes[i].id;strSeperator = '|';}}objInputLeft.value= strLeftPanels;objInputRight.value= strRightPanels;document.getElementById('frmLayout').submit();}function rateUser( intPageUserId, 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, 'User profile rated!', 'Thank you for rating this user\'s profile! Please be as accurate as you can when you rate profiles. Take into consideration layout, backgrounds, colors and text.<br />'+arrParts[1], intNoFade );var objRatingYes = document.getElementById('rating_yes');var objRatingNo = document.getElementById('rating_no');objRatingYes.className = '';objRatingNo.className = 'vNo';} else {showFade(false, 'Whoah .. Easy there!', 'Please try again in <b>'+arrParts[1]+'</b> seconds, refresh the page and try again.', intNoFade );}};if( '' != '' ) {AjaxRequest('http://www.muchgames.com/x_rateUser.php?intPageUserId=' + intPageUserId + '&fltRating=' + fltRating, null, fncCallback);} else {notLoggedIn( 'rateuser' );}}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 blnPosting = false;var blnReplyOpen= false;var blnRequesting = false;function clearNote( intNoteId ) {var fncCallback = function(strResponse) {document.getElementById( 'note_'+intNoteId ).className = 'vNo';updateCount(false,'unread_notes_count');updateCount(false,'notification_count');showFade( true, 'Note notification cleared!', 'You successfully cleared the note notification.' );blnRequesting = false;};if(!blnRequesting){AjaxRequest('http://www.muchgames.com/x_note.php?strAction=clear&intNoteId='+intNoteId, null, fncCallback );blnRequesting = true;}}function replyNote( intNoteId, intUserId, strUserName, blnSmall ){objNoteReply = document.getElementById('note_'+intNoteId);objReplyText = document.getElementById('note_reply_text_'+intNoteId);strSmall= ( blnSmall ) ? '_small' : '';if( objReplyText.innerHTML == 'Reply' ) {objReplyText.innerHTML = 'Close';objReplyDiv = document.createElement('div');objReplyDiv.id = 'note_reply_'+intNoteId;objReplyDiv.innerHTML = ''+'<div class="notetextarea'+strSmall+'">'+'<textarea id="txtReply_'+intNoteId+'" onblur="javascript: if(this.value == \'\') this.value = \'post your reply here ..\';" onfocus="javascript: if(this.value == \'post your reply here ..\') this.value = \'\';">post your reply here ..</textarea>'+'</div>'+'<div class="noteicon">'+'<input type="button" class="button" onclick="javascript: postNote( '+ intUserId +', \'\', true, '+ intNoteId +', \''+ strUserName +'\' );" value="Reply" />'+'</div>'+'<div class="clL p3"></div>';objNoteReply.appendChild( objReplyDiv );blnReplyOpen = true;} else {objReplyText.innerHTML = 'Reply';objReplyDiv = document.getElementById('note_reply_'+intNoteId);objNoteReply.removeChild(objReplyDiv);blnReplyOpen = false;}}function postNote ( intUserId, strFriendStatus, blnReply, intNoteId, strUserName ){var intPostingUserId = '';if( intPostingUserId != '') {if( ( strFriendStatus == 'confirmed' || intUserId == intPostingUserId ) || blnReply ) {displayLoading();if( !blnReply ) {var txtNote = document.getElementById('txtNote').value;} else {var txtNote = document.getElementById('txtReply_'+intNoteId).value;}function fncCallback( strResponse ){hideLoading();if( !blnReply ) {var objNewNote = document.getElementById('new_note');objNewNote.innerHTML = strResponse;var objPostNote = document.getElementById('post_note').className = 'vNo';var objRecordFrom = document.getElementById('note_from');var objRecordTo = document.getElementById('note_to');var objRecordCount = document.getElementById('note_count');var objTotalCount = document.getElementById('note_totalcount');var objNoData = document.getElementById('nonotedata');intNewRecordFrom = parseInt(objRecordFrom.innerHTML);intNewRecordTo = parseInt(objRecordTo.innerHTML);intNewRecordCount = parseInt(objRecordCount.innerHTML);objRecordCount.innerHTML = objTotalCount.innerHTML = ++intNewRecordCount;if(intNewRecordFrom == 0) {objRecordFrom.innerHTML = ++intNewRecordFrom;}if(intNewRecordTo < 10) {objRecordTo.innerHTML = ++intNewRecordTo;}if(intNewRecordCount == 1) {objNoData.className = 'vNo';}showFade(true, 'Note posted!', 'You successfully posted a note on the <b>'+strUserName+'</b>\'s page.');} else { objReplyText.innerHTML = 'Reply';objReplyDiv = document.getElementById('note_reply_'+intNoteId);objNoteReply.removeChild(objReplyDiv);blnReplyOpen = false;showFade(true, 'Note replied!', 'You successfully replied to <b>'+strUserName+'</b> note. A note has been posted on <b>'+strUserName+'</b>\'s page.');}blnPosting = false;}if( txtNote != '' && txtNote != 'post a note here ..'){if(!blnPosting){AjaxRequest('http://www.muchgames.com/x_note.php?strAction=insert&intUserId='+intUserId+'&intPostingUserId=' + intPostingUserId + '&txtNote=' + txtNote, null, fncCallback);blnPosting = true;}} else {hideLoading();showFade(false, 'Note text missing!', 'You did not write anything. Please write a note before you post.');}} else {notFriend( intUserId, strUserName, 'note' );}} else {notLoggedIn( 'postnote' );}}function deleteNote( intNoteId ){objPopup = showPopup('Delete This Note?');    var strHTML = ''    +   'Are you sure you want to delete this note?'+'<div class="aC">'+'<br />'+'<input class="button" type="button" value="Yes" onclick="javascript: hidePopup(); confirmDeleteNote('+intNoteId+');" /> <input class="button" type="button" value="No" onclick="javascript: hidePopup();" />'+ '</div>';displayPopup(objPopup, strHTML, false, 240);}function confirmDeleteNote( intNoteId ){displayLoading();var fncCallback = function(strResponse){hideLoading();document.getElementById( 'note_'+intNoteId ).className = 'vNo';updateCount(false,'note_count', 'note_totalcount');showFade( true, 'Note deleted!', 'You sucessfully deleted the note.' );};AjaxRequest('http://www.muchgames.com/x_note.php?strAction=delete&intNoteId='+intNoteId, null, fncCallback);}var strSketchType = null;function clearSketch( intSketchId ) {var fncCallback = function(strResponse) {document.getElementById( 'sketch_'+intSketchId ).className = 'vNo';updateCount(false,'unread_sketches_count');updateCount(false,'notification_count');showFade( true, 'Sketch notification cleared!', 'You successfully cleared the sketch notification.' );blnRequesting = false;};if(!blnRequesting){AjaxRequest('http://www.muchgames.com/x_sketch.php?strAction=clear&intSketchId='+intSketchId, null, fncCallback );blnRequesting = true;}}function postSketch( strSketchName, strDescription ) {var intUserId = document.getElementById('intUserId').innerHTML;var strUserName = document.getElementById('strUserName').innerHTML;var strFriendStatus = document.getElementById('strFriendStatus').innerHTML;var strType = ( !strSketchType ) ? 'pagesketch' : strSketchType;if( '' != '' ) {if( strFriendStatus == 'confirmed' ) {displayLoading();var fncCallback = function( strResponse ) {hideLoading();var objNewSketch = document.getElementById('new_sketch');objNewSketch.innerHTML = strResponse;objNewSketch.id = 'existing_sketch';objNewSketch.innerHTML = objNewSketch.innerHTML+'<div id=\'new_sketch\'></div>';if( strSketchType == 'pagesketch' ) {var objPostNote = document.getElementById('post_sketch').className = 'vNo';var objRecordFrom = document.getElementById('sketch_from');var objRecordTo = document.getElementById('sketch_to');var objRecordCount = document.getElementById('sketch_count');var objTotalCount = document.getElementById('sketch_totalcount');var objNoData = document.getElementById('nosketchdata');intNewRecordFrom = parseInt(objRecordFrom.innerHTML);intNewRecordTo = parseInt(objRecordTo.innerHTML);intNewRecordCount = parseInt(objRecordCount.innerHTML);objRecordCount.innerHTML = objTotalCount.innerHTML = ++intNewRecordCount;if(intNewRecordFrom == 0) {objRecordFrom.innerHTML = ++intNewRecordFrom;}if(intNewRecordTo < 10) {objRecordTo.innerHTML = ++intNewRecordTo;}if(intNewRecordCount == 1) {objNoData.className = 'vNo';}showFade(true, 'Sketch posted!', 'You successfully posted a sketch on the <b>'+strUserName+'</b>\'s page.');} else {var objRecordCount = document.getElementById('sketch_count');intNewRecordCount = parseInt(objRecordCount.innerHTML);objRecordCount.innerHTML = ++intNewRecordCount;}};AjaxRequest('http://www.muchgames.com/x_sketch.php?strAction=insert&strType='+strType+'&intUserId='+intUserId+'&strSketchName='+strSketchName+'&strDescription='+strDescription, null, fncCallback);} else {notFriend( intUserId, strUserName, 'sketch');}} else {notLoggedIn( 'postsketch' );}}function deleteSketch( intSketchId, strPage ){objPopup = showPopup('Delete This Sketch?');    var strHTML = ''    +   'Are you sure you want to delete this sketch? It will remove the sketch from \'My Sketches\' as well as from the page where it was posted.'+'<div class="aC">'+'<br />'+'<input class="button" type="button" value="Yes" onclick="javascript: hidePopup(); confirmDeleteSketch('+intSketchId+', \''+strPage+'\' );" /> <input class="button" type="button" value="No" onclick="javascript: hidePopup();" />'+ '</div>';displayPopup(objPopup, strHTML, false, 240);}function confirmDeleteSketch( intSketchId, strPage ){displayLoading();var fncCallback = function(strResponse){hideLoading();document.getElementById( 'sketch_'+intSketchId ).className = 'vNo';if( strPage == 'mysketches' ) {updateCount(false,'sketch_count');} else if( strPage != 'feeds' ) {updateCount(false,'sketch_count', 'sketch_totalcount');} else {updateCount(false,'unread_sketches_count');}showFade( true, 'Sketch deleted!', 'You sucessfully deleted the sketch.' );};AjaxRequest('http://www.muchgames.com/x_sketch.php?strAction=delete&intSketchId='+intSketchId, null, fncCallback);}function showSketch( intUserId, intSketchId ) {blnSketchWindow = window.open( 'http://www.muchgames.com/sketch/'+intUserId+'/'+intSketchId, 'Sketch', 'left=200,top=200,status=no,toolbar=no,menubar=no,scrollbars=yes,width=525,height=480,location');if( !blnSketchWindow ) {alert('You must enable popups in order to view the sketches.');}}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' ); }