/* 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 intNewPhotoCount = 0;function deletePhoto( intPhotoId, strExtended ) {objPopup = showPopup('Delete This Photo?');    var strHTML = ''    +   'Are you sure you want to delete this photo?'+'<div class="aC">'+'<br />'+'<input class="button" type="button" value="Yes" onclick="javascript: hidePopup(); confirmDeletePhoto('+intPhotoId+',\''+strExtended+'\');" /> <input class="button" type="button" value="No" onclick="javascript: hidePopup();" />'+ '</div>';displayPopup(objPopup, strHTML, false, 240);}function confirmDeletePhoto( intPhotoId, strExtended ){var fncCallback = function(strResponse){document.getElementById( 'photo_'+strExtended+intPhotoId ).className = 'vNo';if( strExtended == '' ) {updateCount(false,'photos_count');}showFade( true, 'Photo deleted!', 'You sucessfully deleted the photo.' );};AjaxRequest('http://www.muchgames.com/x_photo.php?strAction=delete&intPhotoId='+intPhotoId, null, fncCallback );}function editPhoto ( intPhotoId, strPhoto ){objPopup = showPopup('Edit Photo');var strCaption = document.getElementById('strCaption_'+intPhotoId).innerHTML;    var strHTML = ''+'<div class="wM">'+'<img class="photo" src="http://www.muchgames.com/photos/thumb/'+strPhoto+'" />'+'<br /><br />'+'Caption: <br />'+'<textarea class="caption" id="strCaption">'+strCaption+'</textarea>'+'<br /><br />'+'<input class="button" type="button" value="Save" onclick="javascript: updatePhoto('+intPhotoId+'); hidePopup();" /> <input class="button" type="button" value="Close" onclick="javascript: hidePopup();" />'+ '</div>';displayPopup(objPopup, strHTML, false, 300);}function updatePhoto ( intPhotoId ){var strCaption = document.getElementById('strCaption').value;var objUpdateCaption = document.getElementById('strCaption_'+intPhotoId);objUpdateCaption.innerHTML = strCaption;var fncCallback = function(strResponse){showFade( true, 'Photo details saved!', 'You successfully saved the details of your photo.' );};AjaxRequest('http://www.muchgames.com/x_photo.php?strAction=update&arrPhotoIds='+intPhotoId+'&arrPhotoCaptions='+strCaption, null, fncCallback);}function insertPhoto( intPhotoPosition, strPhoto ) {var objUploadedPhotos = document.getElementById('uploaded_photos');document.getElementById('statusloading'+intPhotoPosition).className = 'vNo';document.getElementById('strPhoto_'+intPhotoPosition).value = '';var objSaveButton = document.getElementById('save_button');var objUploadedPhotos = document.getElementById('uploaded_photos');if(objSaveButton.className == 'vNo') {objSaveButton.className = 'vYes';}if(objUploadedPhotos.className == 'vNo') {objUploadedPhotos.className = 'vYes';}var fncCallback = function(strResponse){objNewPhoto = document.createElement('div');objNewPhoto.innerHTML = strResponse;objNewPhoto.id = 'newphoto_'+intNewPhotoCount++;objUploadedPhotos.appendChild(objNewPhoto);scrollTo( objNewPhoto.id,'middle' );};AjaxRequest('http://www.muchgames.com/x_photo.php?strAction=insert&strPhoto='+strPhoto, null, fncCallback );}function savePhotos(){var arrCaptions = document.getElementsByName('strCaption');var arrPhotoIds = new Array();var arrPhotoCaptions = new Array();intCaptionCount = arrCaptions.length;for(i=0;i< intCaptionCount; i++){objCurrentCaption = arrCaptions[i];arrParts = objCurrentCaption.id.split('_');intPhotoId = arrParts[2];var strCaption = objCurrentCaption.value;strCaption = strCaption.replace(/,/g,' ');arrPhotoIds.push( intPhotoId );if( strCaption != 'Write some text here to describe this photo.') {arrPhotoCaptions.push( strCaption );}}arrPhotoIds = arrPhotoIds.toString();arrPhotoCaptions = arrPhotoCaptions.toString();location.href = 'http://www.muchgames.com/x_photo.php?strAction=update&arrPhotoIds='+arrPhotoIds+'&arrPhotoCaptions='+arrPhotoCaptions;}function selectPhoto( strDirection, strUserName ) {if( strDirection == 'next' ) {intCurrentPosition = ( intCurrentPosition < intPhotoCount - 1 ) ? ++intCurrentPosition : 0;} else {intCurrentPosition = ( intCurrentPosition > 0 ) ? --intCurrentPosition : intPhotoCount-1;}document.getElementById('post_photo_comment').className = '';document.getElementById('txtComment').value = '';document.getElementById('currentphoto').src = 'http://www.muchgames.com/photos/normal/'+arrPhotos[intCurrentPosition].strPhoto;document.getElementById('currentphotolink').value = 'http://www.muchgames.com/users/'+strUserName+'/photos/'+arrPhotos[intCurrentPosition].intPhotoId;document.getElementById('currentcaption').innerHTML = arrPhotos[intCurrentPosition].strCaption;document.getElementById('currentposition').innerHTML = intCurrentPosition+1;document.getElementById('commentcount').innerHTML = arrPhotos[intCurrentPosition].intCommentCount;document.getElementById('currentdate').innerHTML = arrPhotos[intCurrentPosition].dtmAdded;var fncCallback = function(strResponse){document.getElementById('comments_content').innerHTML = strResponse;};AjaxRequest('http://www.muchgames.com/x_loadPhotoComments.php?intPhotoId='+arrPhotos[intCurrentPosition].intPhotoId+'&intPage=1', null, fncCallback );}function rotatePhoto( strDirection ) {var objDate = new Date();var intMillis = objDate.getTime();var fncCallback = function(strResponse){document.getElementById('currentphoto').src = 'http://www.muchgames.com/photos/normal/'+arrPhotos[intCurrentPosition].strPhoto+'?'+intMillis;};AjaxRequest('http://www.muchgames.com/x_photo.php?strAction=rotate&strPath='+arrPhotos[intCurrentPosition].strPhoto+'&strDirection='+strDirection, null, fncCallback );}var blnPosting = false;var blnReplyOpen= false;var blnRequesting = false;function clearComment( intCommentId ) {var fncCallback = function(strResponse) {document.getElementById( 'comment_'+intCommentId ).className = 'vNo';updateCount(false,'unread_photocomments_count');updateCount(false,'notification_count');showFade( true, 'Comment notification cleared!', 'You successfully cleared the photo comment notification.' );blnRequesting = false;};if(!blnRequesting){AjaxRequest('http://www.muchgames.com/x_comment.php?strAction=clear&intCommentId='+intCommentId, null, fncCallback );blnRequesting = true;}}function replyPhotoComment( intCommentId, intUserId, strUserName, intTopicId, intPhotoId, blnSmall ){var objCommentReply = document.getElementById('comment_'+intCommentId);var objCommentText = document.getElementById('comment_reply_text_'+intCommentId);strSmall= ( blnSmall ) ? '_small' : '';if( objCommentText.innerHTML == 'Reply' ) {objCommentText.innerHTML = 'Close';objReplyDiv = document.createElement('div');objReplyDiv.id = 'comment_reply_'+intCommentId;objReplyDiv.innerHTML = ''+'<div class="commenttextarea'+strSmall+'">'+'<textarea id="txtReply_'+intCommentId+'" 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="commenticon">'+'<input type="button" class="button" onclick="javascript: postPhotoComment( '+ intUserId +', \''+strUserName+'\', \'\', \''+ intTopicId +'\', true, \''+intCommentId+'\', \''+intPhotoId+'\' );" value="Reply" />'+'</div>'+'<div class="clL p3"></div>';objCommentReply.appendChild( objReplyDiv );blnReplyOpen = true;} else {objCommentText.innerHTML = 'Reply';objReplyDiv = document.getElementById('comment_reply_'+intCommentId);objCommentReply.removeChild(objReplyDiv);blnReplyOpen = false;}}function postPhotoComment( intUserId, strUserName, strFriendStatus, intTopicId, blnReply, intCommentId, intPhotoId ){if( arrPhotos.length > 0 ) {intPhotoId = arrPhotos[intCurrentPosition].intPhotoId;}intPostingUserId = '';if( intPostingUserId != '') {if( ( strFriendStatus == 'confirmed' || intUserId == intPostingUserId ) || blnReply ) {displayLoading();if( !blnReply ) {var txtComment = document.getElementById('txtComment').value;} else {var txtComment = document.getElementById('txtReply_'+intCommentId).value;}var fncCallback = function( strResponse ){hideLoading();if( !blnReply ) {var objNewComment = document.getElementById('new_comment');objNewComment.innerHTML = strResponse;document.getElementById('post_photo_comment').className = 'vNo';var objRecordFrom = document.getElementById('comment_from');var objRecordTo = document.getElementById('comment_to');var objRecordCount = document.getElementById('comment_count');var objTotalRecordCount = document.getElementById('total_comment_count');var objNoData = document.getElementById('nodata');intNewRecordFrom = parseInt(objRecordFrom.innerHTML);intNewRecordTo = parseInt(objRecordTo.innerHTML);intNewRecordCount = parseInt(objRecordCount.innerHTML);objRecordCount.innerHTML = objTotalRecordCount.innerHTML = ++intNewRecordCount;if(intNewRecordFrom == 0) {objRecordFrom.innerHTML = ++intNewRecordFrom;}if(intNewRecordTo < 10) {objRecordTo.innerHTML = ++intNewRecordTo;}if(intNewRecordCount == 1) {objNoData.className = 'vNo';}showFade(true, 'Photo comment posted!', 'You successfully posted a comment on this photo.');} else {var objReplyDiv= document.createElement('div');objReplyDiv.className= 'commentreply';objReplyDiv.innerHTML= strResponse;var objNewComment = document.getElementById('comment_'+intCommentId);objNewComment.appendChild( objReplyDiv );var objCommentReply = document.getElementById('comment_'+intCommentId);var objCommentText = document.getElementById('comment_reply_text_'+intCommentId);var objReplyDiv = document.getElementById('comment_reply_'+intCommentId);objCommentText.innerHTML = 'Reply';objCommentReply.removeChild(objReplyDiv);blnReplyOpen = false;showFade(true, 'Photo comment replied!', 'You successfully replied to the comment.');}blnPosting = false;};if( txtComment != '' && txtComment != 'post your comment here ..'){if(!blnPosting){AjaxRequest('http://www.muchgames.com/x_comment.php?strAction=insert&intPhotoId='+intPhotoId+'&intUserId='+intUserId+'&intPostingUserId=' + intPostingUserId + '&intTopicId='+intTopicId+'&txtComment=' + txtComment, null, fncCallback);blnPosting = true;}} else {hideLoading();showFade(false, 'Comment text missing!', 'You did not write anything yet. Please write a comment before you post.');}} else {notFriend( intUserId, strUserName, 'comment' );}} else {notLoggedIn( 'postphotocomment' );}}function deleteComment( intCommentId, strPage ){objPopup = showPopup('Delete This Comment?');    var strHTML = ''    +   'Are you sure you want to delete this comment?'+'<div class="aC">'+'<br />'+'<input class="button" type="button" value="Yes" onclick="javascript: hidePopup(); confirmDeleteComment('+intCommentId+',\''+strPage+'\' );" /> <input class="button" type="button" value="No" onclick="javascript: hidePopup();" />'+ '</div>';displayPopup(objPopup, strHTML, false, 270);}function confirmDeleteComment( intCommentId, strPage ){displayLoading();var fncCallback = function(strResponse){hideLoading();document.getElementById( 'comment_'+intCommentId ).className = 'vNo';if( strPage != 'feeds' ) {updateCount(false,'comment_count', 'total_comment_count');}showFade( true, 'Photo Comment Deleted!', 'You successfully deleted the photo comment.' );};AjaxRequest('http://www.muchgames.com/x_comment.php?strAction=delete&intCommentId='+intCommentId, null, fncCallback);}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;} 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' ); }