	var TipId="Tooltip";
	var colorpicker=null;
	var months=new Array();

	function passwordretrieval(tf)
	{
		document.getElementById("retrieval").style.display = tf ? "" : "none";
		document.getElementById("loginstuff").style.display = tf ? "none" : "";
	}

	function removeads()
	{
		alert("You can remove the ads from your site by upgrading to the paid version by clicking the 'Upgrade Service' near the top of the Administrative Menu");
	}

	// thanks to
	// http://www.quirksmode.org/js/findpos.html
	// for the findPos function
	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}

	function bbcodeguide()
	{
		window.open("bbcode.php","bbcode","width=860,height=700,resizable=yes");
	}

	function openchat()
	{
		window.open("chat.php",null,"width=600,height=500,scrollbars=yes,resizable=yes");
	}

	function getcalfilter()
	{
		engine("calendar","geteventfilter.php");
	}

	function applycalfilter()
	{
		var qs = "";
		var i = 0;
		var f = document.forms['filters'].elements;
		while(f['eventcategoryid[' + i + ']'])
		{
			if(f['eventcategoryid[' + i + ']'].checked)
				qs += "eventcategoryid[]=" + f['eventcategoryid[' + i + ']'].value + '&';
			i++;
		}
		engine(filterapplied,'saveeventfilter.php?' + qs);
	}

	function loadshoutbox()
	{
		engine(shoutcontent,"loadshoutbox.php");
	}

	function shoutcontent(msg)
	{
		document.getElementById("shoutbox_menu").innerHTML = msg;
	}

	var shoutprompt = "<table class=list cellspacing=0 cellpadding=5 width=400 height=150><tr class=listlabel align=center><td>Adding a Shout</td></tr><tr class=list1 align=center><td><textarea id=shouttext rows=4 cols=40></textarea></td></tr><tr class=listlabel align=center><td><input type=button class=button value=Cancel onClick='ctt()'><input type=button class=button value='Submit' onClick='saveshout()'></td></tr></table>";
	
	function addshout()
	{
		tt(shoutprompt);
	}

	function deleteshout(id)
	{
		redoshout();
		engine(shoutcontent,"loadshoutbox.php?delete=" + id);
	}

	function redoshout()
	{
		msg = document.getElementById("shoutbox_menu").innerHTML;
		shoutcontent("<blink>Reloading Shouts...</blink><hr>" + msg);
	}


	function saveshout()
	{
		var shout = document.getElementById("shouttext").value;
		shout = shout.replace(/&/,"%26").replace(/\+/,"%2B");
		redoshout();
		engine(shoutcontent,"loadshoutbox.php","txt=" + shout);
		ctt();
	}

	function filterapplied(msg)
	{
		loadcal('','');
	}
	var inviteschecked = 5;
	function checkinvites()
	{
		if(inviteschecked-- > 0)
			engine(chatinvite,"chatinvite.php");
	}

	function chatinvite(msg)
	{
		if(msg!=null && msg!="nothing")
			if(confirm(msg))
				openchat();
		setTimeout("checkinvites()",60000);
	}

	function donothing()
	{}
	
	function engine(type,page,text)
	{
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		if(x)
		{
			x.onreadystatechange =
				function() 
				{
					if(x.readyState==4)
					{
						if(x.status==200)
						{
							if(x.responseText.length>0)
							{
								if(typeof type == 'function')
									type(x.responseText);
								else
									engineresponse(type,x.responseText);
							}
						}
					}
				}
		
			x.open(text==null ? "GET" : "POST",page, true);
			if(text!=null)
				x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			x.send(text);
		}
	}

	function loadcommedit(id)
	{
		engine(commeditgotten,"getcommunityedit.php?communityeditpostid=" + id + "&edit=0");
	}

	function editcommedit(id)
	{
		engine(commeditgotten,"getcommunityedit.php?communityeditpostid=" + id + "&edit=1");
	}

	function savecommedit(id)
	{
		var txt = document.getElementById("commedittext" + id).value;
		txt = txt.replace("/&/","%24");
		engine(loadcommedit,"savecommunityedit.php?communityeditpostid=" + id,"txt=" + txt);
	}

	function commeditgotten(msg)
	{
		var thesplit=msg.split("*:|:*",2);
		var id = thesplit[0];
		document.getElementById("commedit" + id).innerHTML = thesplit[1];
	}

	function getElementsByName_iefix(tag, name)
	{
		var elem = document.getElementsByTagName(tag);
		var arr = new Array();
		for(i = 0,iarr = 0; i < elem.length; i++)
		{
			att = elem[i].getAttribute("name");
			if(att == name)
			{
				arr[iarr] = elem[i];
				iarr++;
			}
		}
		return arr;
	}

	function engineresponse(type,response)
	{
		switch(type)
		{
			case("password"):
				if(response.substr(0,5)=="A new")
					passwordretrieval(false);
				alert(response);
				break;
			case("calendar"):
				if(document.getElementById("cal"))
					document.getElementById("cal").innerHTML = response;
				//var cals = document.getElementsByName("calendiv");
				var cals = getElementsByName_iefix("div","calendiv");
				var i;
				for(i=0;i<cals.length;i++)
					cals[i].innerHTML = response;
				break;
			case("colorpicker"):
				colorpicker=response;
				break;
			case("thread"):
				updatethread(response);
				break;
			case("avail"):
				availresponse(response);
				break;
			case("threadtag"):
			case("savesetting"):
			case("regencss"):
			case("rankchange"):
				alert(response);
				break;
			case("getsetting"):
				enablesetting(response);
				break;
			case("submitvote"):
			case("retractvote"):
				parseresults(response);
				break;
		}
	}

	function challengerank()
	{
		var newrank = document.getElementById("newrank").value;
		engine("rankchange","challengerank.php?new=" + newrank);
		ctt();
	}

	var rankchallengehtml = null;
	function enablerankchallenge()
	{
		if(rankchallengehtml==null)
			engine(showrankchallenge,"getrankchallengedropdown.php");
		else
			tt(rankchallengehtml);
	}
	
	function showrankchallenge(msg)
	{
		rankchallengehtml = msg;
		tt(rankchallengehtml);
	}

	function parsenewcharacter(msg)
	{
		if(msg=="exists")
		{
			alert("This character already exists on this website.  A request has been entered to get that character associated with your account and will be reviewed by those in charge.");
			enablecreatechar(false);
		}
		else if(msg=="mine")
			alert("Silly you!  That character is already associated with your account! Get with the program!");
		else
		{
			var memberid=msg;
			alert("Character Created.  Redirecting you to the 'Edit Character' Screen for this new character");
			document.location.href='memberprofile.php?edit=1&memberid=' + memberid;
		}
	}
	
	function eventdetails(m,d,y)
	{
		var date = m + '/' + d + '/' + y;
		var filename = "eventdetails.php?date=" + date;
		window.open(filename,"cal"+(m*d+y),"width=900,height=600,scrollbars=yes,resizable=yes");
	}
	
	function OpenPostWindow(ThreadID, PostID)
	{
		var settings='width=650,height=600,top=50,left=50,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
		var filename='editpost.php?threadid=' + ThreadID + '&postid=' + PostID;
		window.open(filename, "editpost"+PostID+"0"+ThreadID, settings);
	}
	
	function OpenEditPostWindow(ThreadID, PostID)
	{
		var settings='width=650,height=600,top=50,left=50,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
		var filename='editpost.php?threadid=' + ThreadID + '&srcpostid=' + PostID;
		window.open(filename, "editpost"+PostID+"0"+ThreadID, settings);
	}

	function OpenPrivatePost(loginid)
	{
		var settings='width=650,height=600,top=50,left=50,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
		var filename='editpost.php?threadid=0&postid=0&loginid=' + loginid;
		window.open(filename, "editpost"+loginid, settings);
	}	

	function OpenNewsPost(newsid)
	{
		var settings='width=650,height=600,top=50,left=50,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
		var filename='editpost.php?newsid=' + newsid + '&postid=0';
		window.open(filename, "editnewspost"+newsid, settings);
	}

	
	function togglefav(img,threadid)
	{
		var tf = img.src.match(/circleopen.png/) ? 1 : 0;
		engine("favorite","markfavorite.php?threadid=" + threadid + "&tf=" + tf);
		img.src = tf ? img.src.replace(/circleopen\.png/,"circleclosed.png") : img.src.replace(/circleclosed\.png/,"circleopen.png");
	}

	function submitpw()
	{
		var email = document.getElementById("email").value;
		var page = "passwordretrieval.php?email=" + email;
		engine("password",page);
	}

	function loadcal(m,y)
	{
		var page="calendar.php?month=" + m + "&year=" + y;
		var response = engine("calendar",page);
	}	
