var NumberOfDraftsShowing = 0;
var RequestPending = false;
var AjaxEnabled = false;
var ChatTimeout = false;
var ChatHash = "";
var ChatIsRefereshing = false;
var is_ie = (navigator.userAgent.toLowerCase().indexOf("msie") > -1)
var ROOT = "/online/";
var LevelPreviews = new Hash();
var CommentsPanelPosition = false;
var SendingComment = false;
var addthis_pub="eflare";
var GameVersion = "1.1.4.5";

function PageLoad() {
	ROOT = $("CommonJS").src.toString().substr(0, $("CommonJS").src.toString().lastIndexOf("static/common.js"));
	//"Boxxle.NETwork - " + 
	document.title = document.title.toString().replaceAll(" - ", " // ");
	AjaxEnabled = CheckAjax();
	if (AjaxEnabled) {
		ChatTimeout = setTimeout(RefreshChat, 40000);
	}
	BindAnchors($$("a"));

	/*setCookie("boct", "1", getexpirydate(0));
	if (document.cookie.indexOf("boct") == -1) {
		document.location = ROOT + "disabledcookies/";
	}*/
}

function PageResize() {
}

function PageUnload() {
}

function Click() { }

function BindAnchors(arr) {
	for (var i = 0; i < arr.length; i++) {
		var h = arr[i].href.toString();
//		if (h.indexOf("/play/") > -1 && arr[i].parentNode.parentNode.className.indexOf("LevelBox") == -1 && arr[i].parentNode.className.indexOf("LevelBox") == -1 && h.indexOf("/login") == -1) {
		if (h.indexOf("/play/") > -1 && arr[i].up(".LevelBox") == null && arr[i].up(".Sharing") == null && h.indexOf("/login") == -1) {
			var l = $(arr[i]);
			l.observe("mouseover", LevelPreview.bindAsEventListener(l, l, true));
			l.observe("mouseout", LevelPreview.bindAsEventListener(l, l, false));
		}
	}
}

String.prototype.replaceAll = function(strTarget,strSubString) {
	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );
	while (intIndexOfMatch != -1) {
		strText = strText.replace( strTarget, strSubString );
		intIndexOfMatch = strText.indexOf( strTarget );
	}
	return( strText );
};

String.prototype.trim = function () {
	var strText = this.toString();
	strText = strText.replace(/^\s+/,'');
	strText = strText.replace(/\s+$/,'');
	return strText;
};


function setCookie(name, value, expires) {
	document.cookie= name + "=" + value + "; expires=" + getexpirydate(expires) + ";";
}
function getexpirydate(nodays){	var UTCstring;	Today = new Date();	nomilli=Date.parse(Today);	Today.setTime(nomilli+nodays*24*60*60*1000); UTCstring = Today.toUTCString(); return UTCstring; }

function CheckAjax() {
	if (window.XMLHttpRequest) { /*Mozilla, Safari,...*/
		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { /*IE*/
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) { }
		}
	}
	if (document.implementation && document.implementation.createDocument) {
		xmlDoc = document.implementation.createDocument("", "", null);
	} else if (window.ActiveXObject) {
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	}
	return (http_request && xmlDoc ? true : false);
}

function AJAXCommand(cmd, args, oncomplete, truea) {
	if (!RequestPending || (typeof truea != "undefined" && truea) ) {
		var SuppressDirtyError = (arguments.length == 4);
		DirtyInterface = false;
		var req;
		var url = ROOT + "ajaxrequest/" + cmd + "/" + RandomAppendage();
		var stateChanged = function() {
			if (req.readyState == 4) {
				RequestPending = false;
				var Response = new JLEAJAXRepsonse(req);
				if (Response.IsValid()) {
					if (typeof oncomplete != "undefined") {
						oncomplete(Response);
					}
				} else {
					//alert(1);
				}
			}
		};
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/xml');
			}
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
	
		req.onreadystatechange = stateChanged;
		req.open("POST", url, true);
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", args.length);
		req.setRequestHeader("Connection", "close");
		if (typeof truea == "undefined" || truea == null || !truea) {
			RequestPending = true;
		}
		req.send(args);
	}
}

function RandomAppendage() {
	var now = new Date();
	return (Math.random() * 3000) + now.getTime();
}

function BoxxleChatAdd_Focus(o) {
	if (o.value == o.getAttribute("defaultValue")) {
		o.value = "";
		o.style.color = "#000000";
	}
}

function BoxxleChatAdd_Blur(o) {
	if (o.value == o.getAttribute("defaultValue") || o.value == "") {
		o.value = o.getAttribute("defaultValue");
		o.style.color = "#999999";
	}
}

function BoxxleChatAdd_KeyPress(e) {
	var key= e.keyCode || e.which;
	if (key == 13){
		BoxxleChat_AddMessage();
	}
}

function BoxxleChat_AddMessage() {
	if (!ChatIsRefereshing) {
		var o = $("BoxxleChatAdd");
		if (o.value.length > 2 && o.value != o.getAttribute("defaultValue")) {
			o.disabled = true;
			o.style.color = "#999999";
			o.style.backgroundColor = "#F0F0F0";
			$("BoxxleChatSumbitMessage").update("One moment...");
			$("BoxxleChatSumbitButton").hide();
			if (AjaxEnabled) {
				ChatIsRefereshing = true;
				var ChatTimeoutIsSet = (ChatTimeout ? true : false);
				if (ChatTimeoutIsSet) {
					clearTimeout(ChatTimeout);
					ChatTimeout = false;
				}
				AJAXCommand("chat", "ChatHash=" + encodeURIComponent(ChatHash) + "&AddMessage=" + encodeURIComponent(o.value), function(Response) {
					ChatResponse(Response, ChatTimeoutIsSet);
				});
			}
		}
	}
}

function RefreshChat() {
	if (!ChatIsRefereshing && AjaxEnabled && ChatTimeout) {
		clearTimeout(ChatTimeout);
		ChatTimeout = false;
		ChatIsRefereshing = true;
		AJAXCommand("chat", "ChatHash=" + encodeURIComponent(ChatHash), function(Response) {
			ChatResponse(Response, true);
		});
	}
}

function ChatResponse(Response, RefreshTimeout) {
	if (Response.GetResponseType() == "ChatResponse") {
		var Data = Response.GetData();
		if (Data.GetChildNode("NewMessage").GetValue() == "true" && Data.GetChildNode("NewMessage").GetAttribute("Added") == "false") {
			alert("Flood protection is preventing you from adding more than one message per minute. Please try again later.");
		}
		if (Data.GetChildNode("NewData").GetValue() == "true") {
			ChatHash = Data.GetChildNode("ChatHash").GetValue();
			$("MenuChatList").update(Data.GetChildNode("ChatList").GetValue());
			BindAnchors($$("#MenuChatList a"));
			RestoreChat(Data.GetChildNode("NewMessage").GetValue() == "true");
		} else {
			RestoreChat(Data.GetChildNode("NewMessage").GetValue() == "true");
		}
		if (RefreshTimeout) {
			ChatTimeout = setTimeout(RefreshChat, 40000);
		}
	} else {
		alert("Server returned an unknown response." + Response.GetResponseType());
	}
}

function RestoreChat(NewMessage) {
	ChatIsRefereshing = false;
	try {
		var o = $("BoxxleChatAdd");
		if (NewMessage) {
			o.value = "";
		}
		o.disabled = false;
		o.style.color = "#000000";
		o.style.backgroundColor = "#FFFFFF";
		$("BoxxleChatSumbitMessage").update("");
		$("BoxxleChatSumbitButton").show();
		if (NewMessage) {
			try { o.blur(); BoxxleChatAdd_Blur(o); } catch(e) { }
			try { $("BoxxleChatSumbitMessage").focus(); BoxxleChatAdd_Blur(o); } catch(e) { }
		}
	}
	catch(e) { }
}

function ReplyToTagPost(ReplyTo) {
	if (!Object.isUndefined(ReplyTo)) {
		var o = $("BoxxleChatAdd");
		BoxxleChatAdd_Focus(o);
		o.value = "@" + ReplyTo + ": ";
		o.focus();
	}
}

function LoginFlyout(msg) {
	var o = $("NotLoggedInLink");
	var f = $("LoginFlyout");
	var m = $("FlyoutExtraMessage");
	m.hide();
	if (typeof msg != "undefined" && msg != null && msg.length > 0) {
		m.show();
		m.update(msg);
	}
	if (!f.visible()) {
		var op = o.cumulativeOffset();
		f.style.top = (op.top - 4) + "px";
		f.style.left = (op.left + 160) + "px";
		Effect.SlideRightIn(f, {
			duration: 0.5,
			afterFinish : function() {
				$("FlyoutUsername").activate();
			}
		});
		$("FlyoutUsername").value = "";
		$("FlyoutPassword").value = "";
		
		if (!f.visible()) {
			f.scrollTo();
		}
		$("FlyoutUsername").activate();
	} else {
		Effect.SlideLeftOut(f, {
			duration: 0.5
		});
	}
}

function LoginFlyoutField_KeyPress(e) {
	var key= e.keyCode || e.which;
	if (key == 13){
		Login(true);
	}
}

function LoginField_KeyPress(e) {
	var key= e.keyCode || e.which;
	if (key == 13){
		Login(false);
	}
}

function Login(flyout) {
	var msg = "Hang on, loggin you in...";
	
	var u = flyout ? $("FlyoutUsername") : $("LoginUsername");
	var p = flyout ? $("FlyoutPassword") : $("LoginPassword");
	var s = flyout ? $("FlyoutStay") : $("LoginStay");
	var t = $("LoginFlyoutTable");
	var m = $("LoginFlyoutMessage");
	var r = "";
	
	if (u.value.length > 2 && p.value.length > 2) {
			var pass = p.value;
			p.value = "";
		
			t.hide();
			m.update(msg);
			m.show();
			try {
				$("LoginTable").hide();
				$("LoginMessage").update(msg);
				if (flyout) {
					$("FlyoutExtraMessage").hide();
				}
				$("LoginMessage").show();
				r = $("LoginReturnURL").value;
			} catch(e) { }
			
			 AJAXCommand("login", "Username=" + encodeURIComponent(u.value) + "&Password=" + encodeURIComponent(pass) + "&Stay=" + (s.checked ? "1" : "0") + "&f=" + (flyout ? "1" : "0") + "&r=" + encodeURIComponent(r), function(Response) {
				var t = $("LoginFlyoutTable");
				var m = $("LoginFlyoutMessage");
				var r = $("LoginReturnTo");
								
				if (Response.GetResponseType() == "LoginResult") {
					var Data = Response.GetData();
					if (Data.GetChildNode("Success").GetValue() == "true") {
						var ReturnURL = Data.GetChildNode("ReturnURL").GetValue();
						if (ReturnURL == "_refresh_") {
							document.location = document.location.toString().sub("/login/","/");
						} else {
							document.location = ReturnURL;
						}
					} else {
						t.show();
						m.update("");
						m.hide();
						try {
							$("LoginTable").show();
							$("LoginMessage").update("");
							$("LoginMessage").hide();
						} catch(e) { }
						if (Data.GetChildNode("Success").GetAttribute("Reason") == "Inactive") {
							//alert("This account is not activated. Check your email inbox for the confirmation link that's been sent to you after signing up.\nIt is required that you visit the link sent to you in order to complete the sign up process.");
							
							myLightWindow.activateWindow({
								type: 'html',
								html : '<div class="LightWindowHTML AccountNotActivated"><p>We\'re sorry, but this account has not yet been activated.</p>' +
										'<p>Check your email inbox for the confirmation link that\'s been sent to you after signing up. It is required that you visit the link sent to you in order to complete the sign up process.</p>' +
										'<p>The email was sent from <em>no-reply@boxxle.net</em>. Be sure to allow this address to send you email and check your spam folder if necessary.</p>' +
										'<p>If you really have\'t received the activation email, <a href="javascript:ResendActivate();" onclick="ResendActivate(\'' + Data.GetChildNode("Username").GetValue() + '\');">click here</a> and we\'ll send you another one.</p>' +
										'</div>',
								title : '<span class="Title">This account is not activated</span>',
								href: '#a',
								width: 450,
								height: 180
							});
							
						} else {
							alert("Invalid username and or password.");
						}
						if (!$("LoginFlyout").visible() && document.location.toString().indexOf("/login/") > -1) {
							try {
								$("LoginPassword").activate();
							} catch(e) {
								$("LoginFlyout").show();
							}
						}
						if ($("LoginFlyout").visible()) {
							$("FlyoutPassword").activate();
						}
					}
				} else {
					alert("Unable to log you in. Server responded with an unknown response type." );
				}
			});
			
	} else if (u.value.length > 2) {
		p.activate();
	}
}

function ResendActivate(username) {
	if (!Object.isUndefined(username)) {
		$("lightwindow_contents").down("div").update("<p><br /></p><p>One moment...</p>");	

		AJAXCommand("resendactivate", "Username=" + encodeURIComponent(username), function(Response) {
				var Data = Response.GetData();
				myLightWindow.deactivate();
				if (Data.GetChildNode("Success").GetValue() == "true") {
					alert("An email with activation information has been sent to the email address you signed up with.");
				} else {
					alert("An error occurred. Please contact one of our admins.");
				}
		});
	}
		
}

function Locked(ID, Code, Name) {
	if (!Object.isUndefined(ID)) {
		myLightWindow.activateWindow({
			type: 'html',
			html : '<div class="LightWindowHTML LevelIsLocked"><p>Sorry but, this level is locked to you.</p><p>This level is part of a level pack which requires you to unlock levels. Before you are able to play this level you\'ll have to beat all levels that preceed it in the level pack.</p>' +
					(ID != null ?
					 	Code != null && Code.length > 0 ?
							'<p><a href="' + ROOT + 'browse/' + Code + '/"><img src="' + ROOT + 'img/levelgroup/icon/i' + ID + '.gif" /></a> <a href="' + ROOT + 'browse/' + Code + '/">Go to level pack ' + Name + '</a></p>'
							: '<p><img src="' + ROOT + 'img/levelgroup/icon/i' + ID + '.gif" /> Part of ' + Name + ' level pack</p>'
						: '') +
					'</div>',
			title : '<span class="Title">Level Locked</span>',
			href: '#a',
			width: 450,
			height: 140
		});
	}
}

function LoginRequiredToPlay() {
		myLightWindow.activateWindow({
			type: 'html',
			html : '<div class="LightWindowHTML LoginRequiredToPlay">' +
					'<h4>This level requires you to be logged in, in order to play.</h4>' +
					'<div class="Block LoginBlock">' +
					'	<h3>Login to your account</h3>' +
					'	<table cellpadding="0" cellspacing="0" border="0" class="LoginTable" id="LoginTable">' +
					'	  <tr>' +
					'		<th>Username:</th>' +
					'		<td><input type="text" name="LoginUsername" id="LoginUsername" onkeydown="LoginField_KeyPress(event);" /></td>' +
					'	  </tr>' +
					'	  <tr>' +
					'		<th>Password:</th>' +
					'		<td><input type="password" name="LoginPassword" id="LoginPassword" onkeydown="LoginField_KeyPress(event);" /></td>' +
					'	  </tr>' +
					'	  <tr>' +
					'		<td colspan="2"><input type="checkbox" name="LoginStay" id="LoginStay" /> <label for="LoginStay">Remember me on this computer.</label></td>' +
					'	  </tr>' +
					'	  <tr>' +
					'		<td colspan="2" class="Submit"><img src="' + ROOT + 'img/template/button/submitsmallblack.gif" alt="Submit" title="" onclick="Login(false);" class="pointer" /></td>' +
					'	  </tr>' +
					'	  <tr>' +
					'		<td colspan="2" class="ForgotPassword"><a href="' + ROOT + 'signup/recoveraccount/">Forgot your username or password?</a></td>' +
					'	  </tr>' +
					'	</table>' +
					'	<input type="hidden" name="LoginReturnURL" id="LoginReturnURL" value="' + document.location + '?AutoPlay" />' +
					'	<div id="LoginMessage" style="display:none;"></div>' +
					'</div>' +
					'<div class="Block RegisterBlock">' +
					'	<div class="InBlock">' +
					'		<h3>Register for a free account</h3>' +
					'		<p>Don\'t have an account yet? Registering for an account takes only a minute and is completly free!</p>' +
					'		<p>We don\'t ask any complicted questions, just what we really need to create your account.</p>' +
					'		<p><a href="' + ROOT + 'signup/">Sign up for Boxxle Online</a></p>' +
					'	</div>' +
					'</div>' +
					'<div class="Block DemoBlock">' +
					'	<div class="InBlock">' +
					'		<h3>Play without registering<br />Try out Boxxle Online</h3>' +
					'		<p>We can imagine that you don\'t want to register just yet.</p>' +
					'		<p>We have a special set of preview levels that anyone can play, without registering. Have a go at \'em.</p>' +
					'		<p><a href="' + ROOT + 'browse/preview/">Play any of our 120 preview levels, without signing up</a>!</p>' +
					'	</div>' +
					'</div>' +
					'<br style="clear:left;" />' +
					'</div>',
			title : '<span class="Title">Login to play</span>',
			href: '#a',
			width: 750,
			height: 350
		});
}

function LevelPreview(e, o, over) {
	if ($("LevelPreviewDisplayer") == null) {
		var n = new Element("div", { "id": "LevelPreviewDisplayer" }).hide();
		document.getElementsByTagName("body")[0].appendChild(n);
	}
	var d = $("LevelPreviewDisplayer");
	if (over) {
		var h = o.href.toString();
		if (h.substr(h.length-1, 1) == "/") {
			h = h.substr(0, h.length-1);
		}
		var ido = h.indexOf("/play/");
		var code = h.substr(ido+6, h.length-ido-6);
		
		var imgo = LevelPreviews.get(code);
		var url = "";
		if (!Object.isUndefined( imgo )) {
			url = imgo.src;
		} else {
			imgo = new Image(90, 70);
			url = imgo.src = ROOT + "gdimg/levelpreview.php?Level=" + code;
			LevelPreviews.set(code, imgo);
		}
			
		d.update("<img src=\"" + url + "\" class=\"LevelPreview\" alt=\"Level preview.\" title=\"\" />");
		var op = o.cumulativeOffset();
		d.style.left = (op.left) + "px";
		d.style.top = (op.top + o.getHeight()+1) + "px";
		d.show();
		o.setAttribute("title", "");
	} else {
		d.update("");
		d.hide();
	}
}

function Signup() {
	var UsernameRegEx = /^([a-zA-Z0-9_-]+)$/;
	var EmailRegEx = /^[\w\.\-_]+@([\w\.\-_]+\.)+[A-Za-z]{2,4}$/;
	
	var un = $("SignupUsername");
	var unv = $("SignupUsernameValidator");
	var p1 = $("SignupPassword");
	var p1v = $("SignupPasswordValidator");
	var p2 = $("SignupPasswordConfirm");
	var p2v = $("SignupPasswordConfirmValidator");
	var em = $("SignupEmail");
	var emv = $("SignupEmailValidator");
	var ch = $("SignupChallenge");
	var chv = $("SignupChallengeValidator");
	var chi = $("SignupChallengeImage");
	var chu = $("SignupChallengeUnreadable");
	var fv = $("SignupFormValidator");
	var s = $("SignupSubmit");
	var m = $("SignupMessage");
	
	var errors = 0;
	
	if (un.value.length <= 2) {
		unv.update("Your username must be at least 3 characters long.");
		errors++;
	} else if (un.value.length > 20) {
		unv.update("Your username can not be longer than 20 characters.");
		errors++;
	} else if (!UsernameRegEx.test(un.value)) {
		unv.update("Your username can only consist of letters, numbers, underscores (&quot;_&quot;) and the minus sign (&quot;-&quot;).");
		errors++;
	} else {
		unv.update("");
	}
	
	if (p1.value.length <= 2) {
		p1v.update("Your password must be at least 3 characters long.");
		errors++;
	} else {
		p1v.update("");
	}
	if (p1.value != p2.value) {
		p2v.update("The passwords do not match.");
		errors++;
	} else if (p2.value.length <= 2) {
		p2v.update("Your password must be at least 3 characters long.");
		errors++;
	} else {
		p2v.update("");
	}
	
	if (!EmailRegEx.test(em.value)) {
		emv.update("A valid email address is required.");
		errors++;
	} else {
		emv.update("");
	}
	
	if (ch.value.length < 3) {
		chv.update("Please enter the code.");
		errors++;
	} else {
		chv.update("");
	}
	
	if (errors == 0) {
		
		fv.update("");
		
		var Args = "un=" + encodeURIComponent(un.value) +
					"&pw=" + encodeURIComponent(p1.value) +
					"&em=" + encodeURIComponent(em.value) +
					"&ch=" + encodeURIComponent(ch.value) +
					"&g=1";
					
		un.disabled = p1.disabled = p2.disabled = em.disabled = ch.disabled = true;
		p1.value = p2.value = ch.value = "";
		chi.hide();
		chu.hide();
		m.update("Processing your request...");
		s.hide();
		
		AJAXCommand("signup", Args, function(Response) {
			var un = $("SignupUsername");
			var unv = $("SignupUsernameValidator");
			var p1 = $("SignupPassword");
			var p1v = $("SignupPasswordValidator");
			var p2 = $("SignupPasswordConfirm");
			var p2v = $("SignupPasswordConfirmValidator");
			var em = $("SignupEmail");
			var emv = $("SignupEmailValidator");
			var ch = $("SignupChallenge");
			var chv = $("SignupChallengeValidator");
			var chi = $("SignupChallengeImage");
			var chu = $("SignupChallengeUnreadable");
			var fv = $("SignupFormValidator");
			var s = $("SignupSubmit");
			var m = $("SignupMessage");
											 
			if (Response.GetResponseType() == "SignupResult") {
				var Data = Response.GetData();
				if (Data.GetChildNode("Success").GetValue() == "true") {
					document.location = ROOT + "signup/confirm/";
				} else {
					un.disabled = p1.disabled = p2.disabled = em.disabled = ch.disabled = false;
					NewSignupChallenge();
					chi.show();
					chu.show();
					m.update("");
					s.show();
					fv.update("Unable to submit: See message above.");
					switch(Data.GetChildNode("Success").GetAttribute("Reason")) {
						case "UsernameTaken":
							unv.update("This username is already taken.");
							break;
						case "EmailTaken":
							emv.update("This email address is already in use by a member.<div style=\"padding: 5px 2px 2px 5px;color:#800000;\">Is this your email address, but you forgot your username/password?<br /><a href=\"" + ROOT + "signup/recoveraccount/\">Recover your account here</a>.</div>");
							break;
						case "ChallengeFailed":
							chv.update("The code you entered didn't match the image.");
							break;
						default:
							fv.update("One or more fields are not entered correctly.");
							break;
					}
				}
			} else {
				alert("Unable to process your request. Server responded with an unknown response type.");
				un.disabled = p1.disabled = p2.disabled = em.disabled = ch.disabled = false;
				NewSignupChallenge();
				chi.show();
				chu.show();
				m.update("");
				s.show();
			}
		});
	} else {
		fv.update("Unable to submit: One or more fields are not entered correctly. See messages above.");
	}
}

function NewSignupChallenge() {
	var ch = $("SignupChallengeImage");
	ch.src = ch.src.toString().substr(0, ch.src.toString().indexOf(".php")+4) + "?r=" + RandomAppendage();
}

function AboutSignupChallenge() {
	alert("The confirmation code you enter when signing up is to verify that you are a human user.\nWe want to prevent automated scripts and programs from creating Boxxle Online users.");
}

function PlayLevel(LaunchFunction) {
	HideLevelRecordNotice();
	var numplayed = $("NumPlayed");
	xnumplayed = -1;
	try {
		xnumplayed = parseInt(numplayed.innerHTML);
	} catch(e) { }
	if (!isNaN(xnumplayed) && xnumplayed > -1) {
		numplayed.update(xnumplayed+1);
	}
	LaunchFunction();
}

function LaunchGame(Mode, LevelInfo, Music, Grid) {
	var params = {
		allowScriptAccess : "sameDomain",
		scale : "noScale",
		flashvars : "MODE=" + Mode + "&LEVELCODE=" + LevelInfo.LevelCode + "&DRAFT=" + (LevelInfo.Draft ? 1 : 0) + "&MUSIC=" + Music + "&GRID=" + Grid + "&g=1"
	};
	myLightWindow.activateWindow( {
		href:ROOT + "img/flash/Player" + GameVersion + ".swf",
		width:639,
		height:380,
		objectparams : params,
		title : (Mode == "play" ? "<span class=\"Title\">" + LevelInfo.Name + "</span> <span class=\"By\">by</span> <span class=\"Author\">" + LevelInfo.Author + "</span>" : "<span class=\"Title\">Level Creator</span>"),
		showAudioCheckbox : true
	} );

}

function CreateGameContainer(LevelCode, music) {
	if ($("GameTableContainer") == null) {
		var over = new Element("div", {'id': 'ShadowOverlay'});
		over.hide();
		document.getElementsByTagName("body")[0].appendChild(over);
		var con = new Element("div", {'id': 'GameTableContainer'});
		con.id = "GameTableContainer";
		con.update("<div class=\"GameContentBlock\"><img src=\"" + ROOT + "img/template/block/game/close.gif\" id=\"CloseGameButton\" alt=\"Close window\" title=\"Close window\" onclick=\"CloseGame();\" /><div class=\"t\"></div><div id=\"PlayGameBox\">One moment</div><div class=\"b\"></div></div>");	
		document.getElementsByTagName("body")[0].appendChild(con);
		con = over = null;
	}
}

function CloseGame() {
	myLightWindow.deactivate();
}

function ToggleAudioFromLightwindow() {
	var o = $("cUseAudio");
}

function Recover(Type) {
	if (AjaxEnabled) {
		var Args = "";
		if (Type == "Username") {
			Args = "RecoverUsername=" + encodeURIComponent($("RecoverUsername").value);
		} else if (Type == "Email") {
			Args = "RecoverEmail=" + encodeURIComponent($("RecoverEmail").value);
		}
		
		 AJAXCommand("recover", Args, function(Response) {
				if (Response.GetResponseType() == "RecoverResult") {
					var Data = Response.GetData();
					if (Data.GetChildNode("Success").GetValue() == "true") {
						alert("An email containing your account information has been sent to the email address associated with your account.");
						document.location = ROOT + "login/browse/";
					} else {
						if (Data.GetChildNode("Success").GetAttribute("Reason") == "Server") {
							alert("The server was unable to process this request.");
						} else if (Data.GetChildNode("Success").GetAttribute("Reason") == "NoSuchUser") {
							alert("The specified information is not associated to any known account.");
						} else if (Data.GetChildNode("Success").GetAttribute("Reason") == "NoData") {
							alert("Please fill out the username or the email field and click the respective submit button.");
						}
					}
				}
		});
	}	
}

function ShowCommentsPanel() {
	var t = $("AddCommentsText");
	var l = $("AddComentsLink");
	var f = $("AddComentsFlyout");
	var m = $("AddCommentsFlyoutMessage");
	if (!f.visible()) {
		if (!SendingComment) {
			f.show();
			if (!CommentsPanelPosition) {
				var lp = l.down("a").cumulativeOffset();
				f.style.top = (lp.top + 15) + "px";
				f.style.left = ( (lp.left + l.getWidth()) - f.getWidth()) + "px";
				CommentsPanelPosition = true;
			} else {
				l.show();
				m.hide();
			}
			l.down("a").update("Don't add your comments");
			t.value = "";
			t.activate();
		}
	} else {
		f.hide();
		l.down("a").update("Add your comments");
	}
}

function ReplyToComment(ReplyTo) {
	if (!Object.isUndefined(ReplyTo)) {
		var o = $("AddCommentsText");
		if ( !$("AddComentsFlyout").visible() ) {
			ShowCommentsPanel();
		}
		o.value = "@" + ReplyTo + ": ";
		o.focus();
	}
}

function AddComments() {
	var t = $("AddCommentsText").value;
	var l = $("AddComentsLink");
	var f = $("AddComentsFlyout");
	var a = $("AddCommentsFlyoutTable");
	var m = $("AddCommentsFlyoutMessage");
	if (!SendingComment && !t.blank() && AjaxEnabled) {
		var Args = "LevelID=" + encodeURIComponent(ThisLevelID) +
			"&Text=" + encodeURIComponent(t);
		l.hide();
		m.show();
		m.update("Adding your comment...");
		f.hide();
		SendingComment = true;
		AJAXCommand("commentonlevel", Args, function(Response) {
			SendingComment = false;
			if (Response.GetResponseType() == "CommentResponse") {
				var Data = Response.GetData();
					var m = $("AddCommentsFlyoutMessage");
				if (Data.GetChildNode("Success").GetValue() == "true") {
					var l = $("AddComentsLink");
					m.update("Comment added.");

					var n = $$(".LevelComments div.Comment");
					var isFirst = false;
					if (n != null && n.length > 0) {
						n = n.first();
					} else {
						n = $("NewComment");
						isFirst = true;
					}

					var newMessage = new Element("div").hide();
					Element.insert( n, {'before':newMessage} );
					newMessage.update( Data.GetChildNode("NewMessage").GetValue() );
					
					if (isFirst) {
						var no = $("NoComments");
						if (no != null) {
							Effect.DropOut(no);
						}
					}
					Effect.BlindDown(newMessage);

					
				} else {
					if (Data.GetChildNode("Success").GetAttribute("Reason") == "Flood") {
						alert("Flood protection is preventing you from adding more than one comment per minute. Please try again later.");
						m.update("Comment was not added.");
					}
				}
			}
		});
	}
}

function SendMessage() {
	if (AjaxEnabled) {
		var to = $("SendMessageTo");
		var su = $("SendMessageSubject");
		var suv = $("SendMessageSubjectValidator");
		var me = $("SendMessageMessage");
		var mev = $("SendMessageMessageValidator");
		var fv = $("SendMessageFormValidator");
		var s = $("SendMessageSubmit");
		var m = $("SendMessageFormMessage");

		var errors = 0;

		if (su.value.length <= 2) {
			suv.update("Please enter a subject.");
			errors++;
		} else {
			suv.update("");
		}
		
		if (me.value.length <= 5) {
			mev.update("Please enter a message.");
			errors++;
		} else {
			mev.update("");
		}
		
		if (errors == 0) {
			
			fv.update("");
			
			var Args = "to=" + encodeURIComponent(to.value) +
						"&su=" + encodeURIComponent(su.value) +
						"&me=" + encodeURIComponent(me.value) +
						"&g=1";
						
			su.disabled = me.disabled = true;
			m.update("Processing your request...");
			s.hide();
				
			AJAXCommand("sendmessage", Args, function(Response) {
				if (Response.GetResponseType() == "MessageResult") {
					var to = $("SendMessageTo");
					var su = $("SendMessageSubject");
					var suv = $("SendMessageSubjectValidator");
					var me = $("SendMessageMessage");
					var mev = $("SendMessageMessageValidator");
					var fv = $("SendMessageFormValidator");
					var s = $("SendMessageSubmit");
					var m = $("SendMessageFormMessage");
					var Data = Response.GetData();
					if (Data.GetChildNode("Success").GetValue() == "true") {
						var ReturnURL = Data.GetChildNode("ReturnURL").GetValue();
						alert("Your message has been sent.");
						document.location = ReturnURL;
					} else {
						alert("Something went wrong.\nPlease try again.");
						su.disabled = me.disabled = false;
						m.update("");
						s.show();
					}
				} else {
					alert(Response.GetResponseType());
					alert("Unable to process your request. Server responded with an unknown response type.");
				}
			});
		
		} else {
			fv.update("Unable to submit: One or more fields are not entered correctly. See messages above.");
		}
	}
}

function UpdateAuthorFields() {
	var a1 = $("AuthorDetails1");
	var a2 = $("AuthorDetails2");
	if ($("rAuthorNoWith").checked) {
		a1.show();
		a2.hide();
		$("OriginalAuthorName1").activate();
	} else if ($("rAuthorNoPublic").checked) {
		a1.hide();
		a2.show();
		$("OriginalAuthorName2").activate();
	} else {
		a1.hide();
		a2.hide();
	}
}

function UpdateAvatarFields() {
	var r0 = $("SignupAvatarType0");
	var r1 = $("SignupAvatarType1");
	var r2 = $("SignupAvatarType2");
	var d0 = $("SignupAvatarType0Details");
	var d1 = $("SignupAvatarType1Details");
	var d2 = $("SignupAvatarType2Details");
	if (r0.checked) {
		d0.show();
		d1.hide();
		d2.hide();
	} else if (r1.checked) {
		d0.hide();
		d1.show();
		d2.hide();
	} else if (r2.checked) {
		d0.hide();
		d1.hide();
		d2.show();
	} else {
		d0.hide();
		d1.hide();
		d2.hide();
	}
}

function PublishLevel() {
	if (AjaxEnabled) {
		var na = $("LevelName");
		var nav = $("LevelNameValidator");
		var co = $("LevelComments");
		var cov = $("LevelCommentsValidator");
		
		var fv = $("LevelFormValidator");
		var s = $("LevelSubmit");
		var m = $("LevelFormMessage");

		var errors = 0;

		if (na.value.length <= 2) {
			nav.update("Please enter a name for your level.");
			errors++;
		} else if (na.value.toLowerCase().indexOf("draft level") > -1 || na.value.toLowerCase().indexOf("level draft") > -1) {
			nav.update("Please enter a different name for your level. The term 'Draft level' can not be used for public levels.");
			errors++;
		} else {
			nav.update("");
		}
		
		var Author = "";
		var an = "";
		var aw = "";
		$("AuthorDetails1Validator").update("");
		$("AuthorDetails2Validator").update("");
		$("AuthorValidator").update("");
		if ($("rAuthorNoWith").checked) {
			Author = "NoWith";
			if ($("OriginalAuthorName1").value.length <= 0) {
				$("AuthorDetails1Validator").update("Please enter the name of the original author.");
				errors++;
			} else {
				$("AuthorDetails1Validator").update("");
				an = $("OriginalAuthorName1");
				aw = $("OriginalAuthorURL1");
			}
		} else if ($("rAuthorNoPublic").checked) {
			Author = "NoPublic";
			if ($("OriginalAuthorName2").value.length <= 0) {
				$("AuthorDetails2Validator").update("Please enter the name of the original author.");
				errors++;
			} else {
				$("AuthorDetails2Validator").update("");
				an = $("OriginalAuthorName2");
				aw = $("OriginalAuthorURL2");
			}
		} else if ($("rAuthorYes").checked) {
			Author = "Yes";
			$("AuthorValidator").update("");
		} else if ($("rAuthorNoWithout").checked) {
			Author = "NoWithout";
			$("AuthorValidator").update("When you are submitting the work of another person it is required that you get his or her permission. Please ask for permission from the original author or do not submit this level.");
			errors++;
		} else {
			$("AuthorValidator").update("Please provide the appropriate credit information option");
			errors++;
		}
			
		if (errors == 0) {
			
			fv.update("");
			
			if (!confirm("Are you sure you want to publish this level?\nOnce you publish it, you can't change a thing.")) {
				return;
			}
			
			var Args = "na=" + encodeURIComponent(na.value) +
						"&co=" + encodeURIComponent(co.value) +
						"&au=" + encodeURIComponent(Author) +
						"&an=" + encodeURIComponent(an.value) +
						"&aw=" + encodeURIComponent(aw.value) +
						"&ID=" + encodeURIComponent($("LevelDraftID").value) +
						"&c=" + ($("cComment").checked ? "1" : "0") +
						"&c=" + ($("cBeaten").checked ? "1" : "0") +					
						"&g=1";
			
			na.disabled = co.disabled = true;
			try {
				an.disabled = aw.disabled = true;
			} catch(e) { }
			m.update("Processing your level...");
			s.hide();
				
			AJAXCommand("publishdraft", Args, function(Response) {
				if (Response.GetResponseType() == "PublishResult") {
					var Data = Response.GetData();
					if (Data.GetChildNode("Success").GetValue() == "true") {
						var ReturnURL = Data.GetChildNode("ReturnURL").GetValue();
						alert("Your level has been successfully added to Boxxle Online.");
						document.location = ReturnURL;
					} else {
						alert("Something went wrong.\nPlease try again.");
						alert(Response.GetText());
						var na = $("LevelName");
						var co = $("LevelComments");
						
						var s = $("LevelSubmit");
						var m = $("LevelFormMessage");
						na.disabled = co.disabled = false;
						try {
							$("OriginalAuthorName1").disabled = $("OriginalAuthorURL1").disabled = $("OriginalAuthorName2").disabled = $("OriginalAuthorURL2").disabled = false;
						} catch(e) { }
						
						m.update("");
						s.show();
					}
				} else {
					alert("Unable to process your request. Server responded with an unknown response type (" + Response.GetResponseType() + ").");
				}
			});
		
		} else {
			fv.update("Unable to submit: One or more fields are not entered correctly. See messages above.");
		}
	}
}

function DeleteLevelDraft(ID, UpdateOverview) {
	if (AjaxEnabled && confirm("Are you sure you want to delete this level draft?\nOnce you delete it, it can't be restored.")) {
		 AJAXCommand("deletedraft", "ID=" + encodeURIComponent(ID) + (UpdateOverview ? "&UpdateOverview=1" : ""), function(Response) {
				if (Response.GetResponseType() == "DeleteResult") {
					var Data = Response.GetData();
					if (Data.GetChildNode("Success").GetValue() == "true") {
						if (Data.GetChildNode("UpdateOverview").GetValue() == "true") {
							try {
								var draft = $("LevelDraft" + Data.GetChildNode("DraftID").GetValue());
								Effect.DropOut(draft);
								NumberOfDraftsShowing--;
								(function() {
								if (NumberOfDraftsShowing < 1) {
									$("LevelDraftsTable").hide();
								}}).delay(3);
							} catch(e) { }
						} else {
							alert("Your draft has been deleted.");
							document.location = ROOT + "create/";
						}
					} else {
						alert("Something went wrong when deleting this draft. It hasn't been deleted.");
					}
				} else {
					alert("Unknown server response.");
				}
		});
	}	
}

function ShowPublishLevel() {
	var t = $('DraftTable');
	var l = $('PublishLevelLink');
	var n = $('LevelName');
	t.toggle();
	if (t.visible()) {
		l.update("Don't publish this level");
		n.activate();
	} else {
		l.update("Confirm data and publish this level");
	}
}


var AvatarName = false;
function SaveProfile(Special) {
	var UsernameRegEx = /^([a-zA-Z0-9_-]+)$/;
	var EmailRegEx = /^[\w\.\-_]+@([\w\.\-_]+\.)+[A-Za-z]{2,4}$/;
	
	var p1 = $("SignupPassword");
	var p1v = $("SignupPasswordValidator");
	var p2 = $("SignupPasswordConfirm");
	var p2v = $("SignupPasswordConfirmValidator");
	var em = $("SignupEmail");
	var emv = $("SignupEmailValidator");
	
	var av0 = $("SignupAvatarType0");
	var av1 = $("SignupAvatarType1");
	var av2 = $("SignupAvatarType2");
	var av3 = $("SignupAvatarType3");
	var avf1 = $("SignupAvatarURL");
	var avf2 = $("SignupAvatarUpload");
	var avv = $("SignupAvatarValidator");
	
	var si = $("SignupSignature");
	var siv = $("SignupSignatureValidator");
	var ab = $("SignupAbout");
	var abv = $("SignupAboutValidator");

	var audio = $("cAudio");
	var grid = $("cGrid");
	var updates = $("cEmailUpdates");
	var admin = $("cEmailAdmin");
	var users = $("cEmailUsers");
	var scorebeaten = $("cScoreBeaten");
	var beaten = $("cBeaten");
	var comment = $("cComment");
	
	var fv = $("SignupFormValidator");
	var s = $("SignupSubmit");
	var m = $("SignupMessage");
	
	var errors = 0;
	
	if (p1.value.length > 0 && p1.value.length <= 2) {
		p1v.update("Your password must be at least 3 characters long. Leave these fields blank when you don't want to change your password.");
		errors++;
	} else {
		p1v.update("");
	}
	if (p1.value != p2.value) {
		p2v.update("The passwords do not match.");
		errors++;
	} else if (p2.value.length > 0 && p2.value.length <= 2) {
		p2v.update("Your password must be at least 3 characters long.");
		errors++;
	} else {
		p2v.update("");
	}
	
	if (!EmailRegEx.test(em.value)) {
		emv.update("A valid email address is required.");
		errors++;
	} else {
		emv.update("");
	}
	
	if (si.value.length > 255) {
		siv.update("Your signature can not exceed 255 characters. It is currently " + si.value.length + " characters long.");
		errors++;
	} else {
		siv.update("");
	}
	
	avv.update("");
	
	if (!Object.isUndefined(Special)) {
		errors++;
		$(Special.Field + "Validator").update(Special.Reason);
	}
	
	if (errors == 0) {
		
		fv.update("");
		
		var Args = "update=1" +
					(p1.value.length > 0 ? "&pw=" + encodeURIComponent(p1.value) : "") +
					"&em=" + encodeURIComponent(em.value) +
					"&audio=" + (audio.checked ? "1" : "0") + 
					"&grid=" + (grid.checked ? "1" : "0") + 
					"&updates=" + (updates.checked ? "1" : "0") + 
					"&admin=" + (admin.checked ? "1" : "0") + 
					"&users=" + (users.checked ? "1" : "0") + 
					"&scorebeaten=" + (scorebeaten.checked ? "1" : "0") + 
					"&beaten=" + (beaten.checked ? "1" : "0") + 
					"&comment=" + (comment.checked ? "1" : "0") + 
					"&si=" + encodeURIComponent(si.value) +
					"&ab=" + encodeURIComponent(ab.value) +
					"&g=1";
					
		p1.disabled = p2.disabled = em.disabled = si.disabled = ab.disabled = audio.disabled = grid.disabled = updates.disabled = admin.disabled = users.disabled = scorebeaten.disabled = beaten.disabled = comment.disabled = true;
		p1.value = p2.value = "";
		m.update("Saving your changes...");
		s.hide();
		
		if (av2.checked) {
			if (AvatarName === false) {
				$("fAvatarupload").submit();
				m.update("Uploading your avatar, could take a minute depending on your connection speed and the image size...");
				return;
			} else {
				Args+="&uploadedavatar=" + encodeURIComponent(AvatarName);
			}
		} else if (av1.checked) {
			Args+="&externalavatar=" + encodeURIComponent(avf1.value);
		} else if (av3.checked) {
			Args+="&deleteavatar=1";
		}
		
		AJAXCommand("updateprofile", Args, function(Response) {
			var p1 = $("SignupPassword");
			var p1v = $("SignupPasswordValidator");
			var p2 = $("SignupPasswordConfirm");
			var p2v = $("SignupPasswordConfirmValidator");
			var em = $("SignupEmail");
			var emv = $("SignupEmailValidator");
			
			var av0 = $("SignupAvatarType0");
			var av1 = $("SignupAvatarType1");
			var av2 = $("SignupAvatarType2");
			var av3 = $("SignupAvatarType3");
			var avf1 = $("SignupAvatarURL");
			var avf2 = $("SignupAvatarUpload");
			
			var si = $("SignupSignature");
			var siv = $("SignupSignatureValidator");
			var ab = $("SignupAbout");
			var abv = $("SignupAboutValidator");
		
			var audio = $("cAudio");
			var grid = $("cGrid");
			var updates = $("cEmailUpdates");
			var admin = $("cEmailAdmin");
			var users = $("cEmailUsers");
			var scorebeaten = $("cScoreBeaten");
			var beaten = $("cBeaten");
			var comment = $("cComment");
			
			var fv = $("SignupFormValidator");
			var s = $("SignupSubmit");
			var m = $("SignupMessage");
											 
			if (Response.GetResponseType() == "SaveProfileResult") {
				var Data = Response.GetData();
				if (Data.GetChildNode("Success").GetValue() == "true") {
					if (Data.GetChildNode("NewEmail").GetValue() == "true") {
						alert("Your profile has been saved.\r\n\r\nHowever, by changing your email address, it is required that you reactivate your account. We do this to ensure you didn't enter the wrong email address.\r\n\r\nCheck your email inbox for the confirmation link that's been sent to you.");
						document.location = ROOT + "logout/";
					} else {
						alert("Your profile has been saved.");
						document.location = ROOT + "profile/";
					}
				} else {
					av0.disabled = av1.disabled = av2.disabled = av3.disabled = avf1.disabled = avf2.disabled = p1.disabled = p2.disabled = em.disabled = si.disabled = ab.disabled = audio.disabled = grid.disabled = updates.disabled = admin.disabled = users.disabled = beaten.disabled = scorebeaten.disabled = comment.disabled = false;
					p1.value = p2.value = "";
					m.update("");
					s.show();
					fv.update("Unable to submit: See message above.");
					switch(Data.GetChildNode("Success").GetAttribute("Reason")) {
						case "EmailTaken":
							emv.update("This email address is already in use by a member.");
							break;
						default:
							fv.update("One or more fields are not entered correctly.");
							break;
					}
				}
			} else {
				alert("Unable to process your request. Server responded with an unknown response type.");
				av0.disabled = av1.disabled = av2.disabled = av3.disabled = avf1.disabled = avf2.disabled = p1.disabled = p2.disabled = em.disabled = si.disabled = ab.disabled = audio.disabled = grid.disabled = updates.disabled = admin.disabled = users.disabled = beaten.disabled = scorebeaten.disabled = comment.disabled = false;
				p1.value = p2.value = "";
				m.update("");
				s.show();
			}
		});
	} else {
		fv.update("Unable to submit: One or more fields are not entered correctly. See messages above.");
		av0.disabled = av1.disabled = av2.disabled = av3.disabled = avf1.disabled = avf2.disabled = p1.disabled = p2.disabled = em.disabled = si.disabled = ab.disabled = audio.disabled = grid.disabled = updates.disabled = admin.disabled = users.disabled = beaten.disabled = scorebeaten.disabled = comment.disabled = false;
		p1.value = p2.value = "";
		m.update("");
		s.show();
	}
}

function UploadComplete(RequestName, UploadResult) {
	switch(RequestName) {
		case "SignupAvatarUpload":
			if (UploadResult[0][1].length > 0) {
				SaveProfile( {Field: "SignupAvatar", Reason: UploadResult[0][1]} );
			} else {
				AvatarName = UploadResult[0][0];
				SaveProfile();
			}
			break;
	}
}

function HideLevelRecordNotice() {
	var n = $("LevelRecordNotice");
	if (n.visible()) {
		Effect.BlindUp(n);
	}
}

function RefreshLevelStats(RecordID) {	
	var refreshing = "<div class=\"Refreshing\"><img src=\"" + ROOT + "img/template/overall/throbber.gif\" alt=\"...\" title=\"\" /> Refreshing</div>";
	$("NumPlayed").update(refreshing);
	$("NumBeaten").update(refreshing);
	$("ListBestScores").update(refreshing);
	$("ListLatestVictories").update(refreshing);
	
	if (AjaxEnabled) {
		 AJAXCommand("getlevelstats", "LevelID=" + ThisLevelID + "&RecordID=" + encodeURIComponent(RecordID), function(Response) {
			if (Response.GetResponseType() == "LevelStats") {
				var Data = Response.GetData();
				$("NumPlayed").update(Data.GetChildNode("NumPlayed").GetValue());
				$("NumBeaten").update(Data.GetChildNode("NumBeaten").GetValue());
				$("ListBestScores").update(Data.GetChildNode("ListBestScores").GetValue());
				$("ListLatestVictories").update(Data.GetChildNode("ListLatestVictories").GetValue());
				var n = $("LevelRecordNotice");
				n.hide();
				if (Data.GetChildNode("LevelRecordNotice").GetValue() == "true") {
					Effect.BlindDown(n, {
						afterFinish : function() {
							try {
								Effect.Pulsate("NextLevelLink", {pulses: 3, duration: 2, from: 0.2} );
							} catch(e) { }
						}
					});
				}
			} else {
				document.location = document.location;
			}
		});
	}
}

function RefreshLevelStatsAndCloseGame(RecordID) {
	CloseGame();
	RefreshLevelStats(RecordID);
}

function ShowMoreScores(LevelCode, LowListPos) {
	if (!Object.isUndefined(LevelCode) && AjaxEnabled) {
		$("MoreScoresLink").hide();
		$("MoreScoresMessage").update("One moment...");
		AJAXCommand("morescores", "Code=" + encodeURIComponent(LevelCode) + "&g=1", function(Response) {
			if (Response.GetResponseType() == "MoreScores" && Response.GetData().GetChildNode("Success").GetValue() == "true") {
				var list = $("MoreScoresList");
				$("MoreScoresMessage").hide();
				list.update( Response.GetData().GetChildNode("Scores").GetValue() );
				
				var numItems = parseInt(Response.GetData().GetChildNode("NumItems").GetValue());
				var lowListPos = !LowListPos.blank() ? parseInt(LowListPos) : 9999;
				if (numItems+5 >= lowListPos) {
					Effect.DropOut($("LowLevelList"));
					Effect.DropOut($("LowLevelText"));
				}
				
				Effect.BlindDown(list);
			} else {
				$("MoreScoresMessage").update("There are no other scores.");
			}
		});
	}
}

function FacebookShare() {
	var args = $A(arguments);
	var u=location.href;
	var t = (args.length > 0 ? args[0] + " at Boxxle and Sokoban Online" : document.title);
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'_blank','toolbar=0,status=0,width=626,height=436');
	return false;
}

function MySpace(T, C, U, L) {
	var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(T + " at Boxxle and Sokoban Online") + '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U) + '&l=' + L;
	window.open(targetUrl);
	return false;
}