// Poll Stuff
	function parseresults(v,postid)
	{
		var line = v.split("\n");
		var i;
		for(i=0;i<line.length;i++)
		{
			var parsed = line[i].split(":=");
			if(parsed.length==2)
			{
				setpollcounts(parsed[0],postid,parsed[1]);
				dge("voter_" + postid + "_" + i).style.display="none";
			}
		}
	}

	function setpollcounts(id,postid,num)
	{
		dge("poll_" + postid + "_" + id).innerHTML=num;
	}

	function submitvote(v,postid)
	{
		engine(function(msg){parseresults(msg,postid)},"submitvote.php?pollanswerid=" + v);
		dge("answered_" + postid).style.display="";
	}

	function changevote(postid)
	{
		for(i=0;i<100;i++)
		{
			if(dge("voter_" + postid + "_" + i))
				dge("voter_" + postid + "_" + i).style.display="";
			else
				return;
		}
	}

	
	// ratings
	function ratepost(postid,rating)
	{
		if(rating>0)
			rating = 1;
		else
			rating = -1;

		engine(function(msg){fillrating(postid,msg)},"ratepost.php?postid=" + postid + "&rating=" + rating);

	}

	function fillrating(postid,msg)
	{
		dge("postrating" + postid).innerHTML = msg;
		dge("postrater" + postid).innerHTML = "";
	}

	
	
	
	// Changing PRimary Thread Tag
	function changetag(threadid,t)
	{
		dge("curtag").value=t.value;
		var text = "modifythreadtag.php?threadid=" + threadid + "&threadtagid=" + t.value;
		engine(savedthreadtag,text);
	}

	function savedthreadtag(msg)
	{
		var s = msg.split(/\n/);

		dge("primthreadtagtext").innerHTML = s[1];
		enablechangetag('prim',0);
	}

	// Changing Secondary thread tag
	function changesectag(threadid)
	{
		var t = "threadid=" + threadid;
		var i;
		for(i=0;dge("secthreadtag" + i);i++)
			if(dge("secthreadtag" + i).checked)
				t += "&threadtagid[]=" +  dge("secthreadtag" + i).value;
		var url = "savesecthreadtag.php?" + t;
		engine(sectagchanged,url);
	}

	function sectagchanged(msg)
	{
		var s = msg.split(/\n/);
		cmd = s[0];
		if(cmd=="done")
		{
			enablechangetag('sec',0);
			dge("secthreadtagtext").innerHTML = s[1];
		}
		else
			alert(msg);
	}


	
	
	function enablechangetag(t,tf)
	{
		dge(t + "threadtagtext").style.display = tf ? "none" : "";
		dge(t + "threadtaglink").style.display = tf ? "none" : "";
		dge(t + "threadtagform").style.display = tf ? "" : "none";
		if(dge(t + "threadtagsubmit"))
			dge(t + "threadtagsubmit").style.display = tf ? "" : "none";
	}


	function boldtag(id,tf)
	{
		dge("threadtaglabel" + id).style.fontWeight = tf ? "bold" : "";
	}

	
	// changing layout
	function layoutchooser(type)
	{
		var types = ["thread","threadlist","classic"];
		var f = document.forms['forumlayoutchooser'].elements;

		for(i in types)
			if(dge("forumlayout" + types[i]))
				dge("forumlayout" + types[i]).style.display = (types[i]==type ? "" : "none");
	}



	// Post Deletion
	function deletepost(threadid,postids)
	{
		if(confirm("Really Delete selected post" + (isNaN(postids) ? "s" : "") + "?"))
			engine(function(msg){postsdeleted(threadid,msg)},"deletepost.php?threadid=" + threadid + "&postids=" + postids);
	}

	function postsdeleted(threadid,msg)
	{
		alert(msg);
		if(msg.match(/thread destroyed/i))
			refilter();
		else
			viewthread(threadid);
	}

	// Thread Deletion	
	function destroythread(threadids)
	{
		var msg = "";
		var arrthreadid = threadids.split(",");
		if(arrthreadid.length==1)
			msg = "Are you sure you want to destroy this thread (delete the thread and all posts within it)?  There is no undoing this!";
		else
			msg = "Are you sure you want to destroy the selected threads (delete the threads and all containing posts)?  There is no undoing this!";
		var num = arrthreadid.length;

		if(num==0)
			alert("Nothing selected to delete");
		else if(confirm(msg))
		{
			var tids = arrthreadid.join(",");
			engine(function(msg){threaddestroyed(num,msg)},"destroythread.php?threadid=" + tids)
		}
	}

	
	function threaddestroyed(num,msg)
	{
		if(num==1)
			alert(num + " thread destroyed");
		else
			alert(num + " threads destroyed");
		refilter();
	}

	// Thread Subject Editing
	function editthread(threadid)
	{
		var text=dge("newpagetitle").innerHTML.replace(/"/g,"&quot;");
		lastsubject=text;
		var subject="<input type=text size=45 id=threadtext value=\"" + text + "\"><input type=button class=button value=Save onClick='savethread(" + threadid + ")' style='font-size:8pt'> &nbsp; <a href='javascript:uneditthread()'>Cancel</a>";
		dge("newpagetitle").innerHTML=subject;
		dge("editthreadlink").style.display="none";
	}

	function uneditthread()
	{
		dge("editthreadlink").style.display="";
		dge("newpagetitle").innerHTML=lastsubject;
	}

	function savethread(threadid)
	{
		var text=dge("threadtext").value;
		if(text.length==0)
			alert("Please put something in the thread subject");
		else
		{
			text=text.replace(/&/g,"%26");
			engine("thread","editthread.php?threadid=" + threadid + "&thread="+text);
		}
	}

	function updatethread(t)
	{
		dge("newpagetitle").innerHTML=t;
		if(dge("pagetitle"))
			dge("pagetitle").innerHTML=t;

		dge("editthreadlink").style.display="";
	}

	// Summary Stuff
	var tip = "summary";
	var summaries = Array();
	var summary_shown = false;
	var summary_timer = null;
	
	// Favorite
	function togglefav(div,threadid)
	{
		var setfav = div.className == "forum_fav" ? 0 : 1; // if currently a favorite, then we want to make it non-fav
		div.className = setfav ? "forum_fav" : "forum_nonfav";
		engine("nothing","markfavorite.php?threadid=" + threadid + "&tf=" + setfav);
	}

	function showit(type,tf)
	{
		dge(type + "link").style.display = tf ? "none" : "";
		dge(type + "text").style.display = tf ? "" : "none";
	}


	//Ignoring Stuff
	function ignorelogin(loginid,ignore)
	{
		engine(function(msg){processignore(!ignore,loginid,msg);},"ignorelogin.php?ignore=" + ignore + "&loginid=" + loginid)
	}

	function processignore(show,loginid,msg)
	{
		var i;
		for(i=0;dge("ignore_" + loginid + "_" + i);i++)
			dge("ignore_" + loginid + "_" + i).style.display = show ? "none" : "";

		for(i=0;dge("nonignore_" + loginid + "_" + i);i++)
			dge("nonignore_" + loginid + "_" + i).style.display = show ? "" : "none";
	}

	// Private Thread Changing
	function saveprivatechange()
	{
		var threadid = dge("currentthreadid").value;
		var list = dge("privatethreadloginlist").value;
		dge("privatethreadtext").innerHTML = "Saving...";
		engine(privatethreadchanged,"savethreadaccess.php","threadid=" + threadid + "&loginlist=" + list);
	}

	function changeprivatemembers()
	{
		var accesslist = dge("privatethreadloginlist").value;
		window.open("memberselector.php?field=privatethreadloginlist&access=" + accesslist,"memselthread","width=700,height=550,menubar=no,statusbar=no,scrollbars=auto");
		startprivatecheck();
	}

	var prevprivate = "start";
	function checkprivatechanged()
	{
		curprivate = dge("privatethreadloginlist").value;
		if(prevprivate=="start")
			prevprivate = curprivate
		else if(prevprivate!=curprivate)
		{
			saveprivatechange();
			prevprivate = curprivate;
			stopprivatecheck();
		}
	}

	var privatechecker = null;
	function startprivatecheck()
	{
		privatechecker = setInterval("checkprivatechanged()",200);
	}

	function stopprivatecheck()
	{
		clearInterval(privatechecker);
	}

	function privatethreadchanged(msg)
	{
		dge("privatethreadtext").innerHTML = msg;
	}


	//Private Thread Tags
	function editmytag(id)
	{
		window.open("editmythreadtag.php?threadtagid=" + id,"mytag" + id,"width=400,height=400");
	}

	function leavethreadtag(id)
	{
		if(confirm("Really OK to quit membership in this Private Thread Tag?"))
			engine(lefttag,"leaveprivatethread.php?threadtagid=" + id);
	}

	function lefttag(msg)
	{
		document.getElementById("privthreadtag" + msg).style.display = "none";
	}


	// Applications
	function notifyapp()
	{
		var a = document.forms["appnotification"].elements["appid"].value;
		var v = document.forms["appnotification"].elements["notify"].value;
		var r = document.forms["appnotification"].elements["reason"].value;
		r = r.replace("/&/","%26");
		if(v.length==0)
			alert("Please select an action");
		else if(confirm("OK to notify the application that their application has been " + (parseInt(v)==1 ? "accepted" : "rejected") + "?"))
			engine(newstatus,"notifyapp.php?appid=" + a + "&accepted=" + v,"reason=" + r);
	}

	function shownotifier(tf)
	{
		var v = document.forms["appnotification"].elements["notify"].value;
		if(v.length==0)
			alert("Please select an action");
		else
		{
			dge("notifytype").innerHTML = (parseInt(v)==1 ? "acceptance" : "rejection");
			dge("notifylink").style.display = tf ? "none" : "";
			dge("notifytext").style.display = tf ? "" : "none";
		}
	}

	function newstatus(msg)
	{
		dge("notified").innerHTML=msg;
	}


	// Mark Thread Tags as read
	function markviewed(threadid,tf)
	{
		if(dge("threadrow" + threadid) && dge("threadrow" + threadid).className)
		{
			var curclass = dge("threadrow" + threadid).className;
			var newclass="";
			if(tf)
			{
				if(curclass.match(/^new/))
					newclass = curclass.substr(3);
				else
					newclass = curclass;
			}
			else
				newclass = "new" + curclass;
			dge("threadrow" + threadid).className = newclass;
		}
	}

	// Setting Posts per page from the selector
	function setpostsperpage(postsperpage)
	{
		var qs = "threadid=" + lastthreadid + "&p=" + lastpage + "&postsperpage=" + postsperpage;
		engine(loadthread,"thread.php?" + qs);
	}


	// Thread Merging
	function mergethreads(threadids)
	{
		engine(function(msg){mergethreadlist(threadids,msg)},"threaddropdown.php?threadids=" + threadids);
	}

	var mergethread;
	function mergethreadlist(threadids,msg)
	{
		if(msg=="noprivate")
			alert("For security purposes, private threads may not be merged or split");
		else
		{
			var popup = "<div style='text-align:center'>Choose which thread is the primary thread into which the other threads will get merged?<br /><br />" + msg + "<br /><br /><input type=button class=button value=Cancel onClick=\"close_movable_window(mergethread)\" /> <input type=button class=button value=Merge onClick=\"performmerger(dge('mainthreadid').value,'" + threadids + "')\" /></div>";
			mergethread = movable_window("Merge Threads",popup,400,200);
		}
	}

	function performmerger(mainthreadid,threadids)
	{
		engine(function(msg){splitormergedthreads(mainthreadid,msg)},"mergethreads.php?threadids=" + threadids + "&mainthreadid=" + mainthreadid);
		close_movable_window(mergethread);
		enableforumfunction(false,"threadlist")
	}

	function splitormergedthreads(tothreadid,msg)
	{
		alert(msg);
		viewthread(tothreadid);
		//refilter(1);
	}

	
	
	function startmerging(threadid)
	{
		engine(mergestarted,"startmerging.php?threadid=" + threadid);
	}

	function mergestarted(threadid)
	{
		if(threadid!="0")
		{
			backtoindex();
			openmergewindow(threadid);
		}
	}

	var mergewindow;
	function openmergewindow(threadid)
	{
		var html = "<div style='text-align:center'>To complete the merger, find the target thread into which you wish to merge the contents of the previously selected thread.<Br /><Br />When you are in the target thread, a 'Complete Merger' button will appear.<br /><br /><input type=button class=button id='completemerger' value='Complete Merger' style='visibility:hidden' onClick=\"completethemerger(" + threadid + ",dge('currentthreadid').value)\" /><input type=button class=button onClick=\"close_movable_window(mergewindow);startmerging(0);\" value='Cancel' /></div>";
		mergewindow = movable_window("Merge Thread",html,300,200);
	}


	function completethemerger(srcthreadid,targetthreadid)
	{
		close_movable_window(mergewindow);
		performmerger(targetthreadid,srcthreadid);
	}
	
	function merge_split_can_finish(tf)
	{
		if(dge("completemerger"))
			dge("completemerger").style.visibility= tf ? "visible" : "hidden"; 
		if(dge("completesplit"))
			dge("completesplit").style.visibility = tf ? "visible" : "hidden";
	}


	function forumsortby(s)
	{
		document.location.href="forum.php?s=" + s;
	}


	// Mass Change Thread Tag
	var changetagwindow;
	function startchangetag(threadids)
	{
		cengine(function(html){showchangetagwindow(threadids,html)},"threadtagdropdown.php?type=mod&id=changethreadtagid","",360);
	}

	function showchangetagwindow(threadids,ddl)
	{
		var html = "<div style='text-align:center'>Select a new primary thread tag for the selected threads<br /><br />" + ddl + "<br /><input type=button class=button value='Change Thread Tag' onClick=\"markthread('" + threadids + "','threadtagid',dge('changethreadtagid').value);close_movable_window(changetagwindow);\" /><input type=button class=button value='Cancel' onClick=\"close_movable_window(changetagwindow)\" /></div>";
		changetagwindow = movable_window("Change Primary Thread Tag",html,300,200);
		
	}
		

	// Splitting Threads
	var splitwindow;
	function splittonew(threadid,postids)
	{
		cengine(function(msg){splittonewwindow(threadid,postids,msg)},"threadtagdropdown.php?id=splitthreadtagid&type=mod","",360);
	}

	function splittonewwindow(threadid,postids,ddl)
	{
		var hiddens = "<input type=hidden id=splitthreadid value='" + threadid + "' /><input type=hidden id=splitpostids value='" + postids + "' />";
		var html = "<div style='text-align:center'>Enter the title of the new thread to create for the selected posts to be split into:<br /><input type=text id=splitthread value='New Thread'><br /><br />Enter the Thread Tag for the new thread: " + ddl + "<br /><br /><input type=button class=button value='Complete Split' onClick=\"completesplittonew()\" /><input type=button class=button onClick=\"close_movable_window(splitwindow);\" value='Cancel' />" + hiddens + "</div>";
		splitwindow = movable_window("Split Thread",html,300,300);
	}


	function completesplittonew()
	{
		var thread = encodeURIComponent(dge("splitthread").value);
		var threadtagid = dge("splitthreadtagid").value;
		var splitthreadid = dge("splitthreadid").value;
		var splitpostids = dge("splitpostids").value;

		if(thread.length==0)
			alert("No thread title specified");
		else
		{
			var post = "threadtagid=" + threadtagid + "&srcthreadid=" + splitthreadid + "&postids=" + splitpostids + "&thread=" + thread;
			engine(finishedsplittonew,"splittonew.php",post);
		}
	}

	function finishedsplittonew(threadid)
	{
		alert("Split Complete");
		viewthread(threadid);
	}

	function splittoexisting(threadid,postids)
	{
		if(threadid!="0")
		{
			engine(startedsplittingtoexisting,"startsplitting.php?srcthreadid=" + threadid + "&postids=" + postids);
		}
	}

	function startedsplittingtoexisting(msg)
	{
		backtoindex();
	}
	
	function stopsplitting()
	{
		engine("nothing","startsplitting.php?srcthreadid=0");
	}


	function opensplittoexisting()
	{
		var html = "<div style='text-align:center'>To complete the split, find the target thread into which you wish to split the contents of the selected posts<Br /><Br />When you are in the target thread, a 'Complete Split' button will appear.<br /><br /><input type=button class=button id='completesplit' value='Complete Split' style='visibility:hidden' onClick=\"completethesplit(dge('currentthreadid').value)\" /><input type=button class=button onClick=\"close_movable_window(splitwindow);stopsplitting();\" value='Cancel' /></div>";
		splitwindow = movable_window("Split Thread",html,300,200);

	}

	function completethesplit(tothreadid)
	{
		engine(function(msg){splitfinished(tothreadid,msg)},"completesplit.php?tothreadid=" + tothreadid);
		close_movable_window(splitwindow);
	}

	function splitfinished(tothreadid,msg)
	{
		alert(msg);
		viewthread(tothreadid);
		//refilter(1);
	}


	//Community Edit

	var commtowatch = Array();
	function scanforcommedits()
	{
		commtowatch = Array();
		for(var i=0;dge("postid" + i);i++)
		{
			postid = dge("postid" + i).value;
			if(dge("postcommedit" + postid))
			{
				commeditid = dge("postcommedit" + postid).value;
				loadcommedit(commeditid);
				commtowatch.push(commeditid);
			}
		}
	}

	function memselector(id)
	{
		window.open("memberselector.php?field=communityeditpost" + id + ".accesslist&access=" + document.forms['communityeditpost' + id].elements['accesslist'].value,"commeditmemsel" + id,"width=700,height=550,menubar=no,statusbar=no,scrollbars=auto");
	}


	var checkingcomm = setInterval("checkforsaving()",300);

	function checkforsaving()
	{
		var i;
//		alert(commtowatch);
		for(i=0;i<commtowatch.length;i++)
		{
			if(document.forms['communityeditpost' + commtowatch[i]].elements['accesslist'].value!=document.forms['communityeditpost' + commtowatch[i]].elements['accessorig'].value)
			{
				document.forms['communityeditpost' + commtowatch[i]].elements['accessorig'].value=document.forms['communityeditpost' + commtowatch[i]].elements['accesslist'].value
				savemembers(commtowatch[i]);
			}
		}
	}

	function savemembers(id)
	{
		var accesslist = document.forms['communityeditpost' + id].elements['accesslist'].value;
		engine(loadcommedit,'savecommunityeditlogins.php?communityeditpostid=' + id,'accesslist=' + accesslist);
	}


	//Thread Sticky and Lock
	function togglesticky(threadid,sticky)
	{
		sticky = sticky ? 1 : 0;
		if(sticky)
			startstickywindow(threadid);
		else
		{
			engine("nothing","stickyme.php?threadid=" + threadid + "&sticky=0&priority=0");
			dge("stickypic").style.display = "none";
		}

		dge("stickycheck").checked=false;
	}

	function startstickywindow(threadid)
	{
		engine(fillstickywindow,"stickywindow.php?threadid=" + threadid);
	}

	var stickypriwin;
	function fillstickywindow(msg)
	{
		stickypriwin = movable_window("Sticky Thread",msg,500,300);
	}

	function setsticky(threadid)
	{
		var pri = dge("stickypriority").value;
		engine("nothing","stickyme.php?threadid=" + threadid + "&sticky=1&priority=" + pri);
		if(dge("currentthreadid").value==threadid)
		{
			dge("stickypic").style.display = "";
			dge("stickycheck").checked=true;
		}
		close_movable_window(stickypriwin);
	}
	
	function togglelocked(threadid,locked)
	{
		locked = locked ? 1 : 0;
		engine("nothing","lockme.php?threadid=" + threadid + "&locked=" + locked);
		dge("lockpic").style.display = locked ? "" : "none";
	}
	

	// Selecting Threads, Posts, and Tags (stuff that uses the checkboxes)
	var selectedclasses = new Array();
	function select_checkbox(type,id,tf)
	{
		if(tf)
		{
			if(!selectedclasses[type])
				selectedclasses[type] = new Array();
			if(dge(type + "row" + + id))
			{
				selectedclasses[type][id] = dge(type + "row" + id).className;
				if(!selectedclasses[type][id])
					selectedclasses[type][id] = "";
				dge(type + "row" + id).className = selectedclasses[type][id] + " selected" + type;
			}
		}
		else
		{
			if(selectedclasses[type] && selectedclasses[type][id]!=undefined && dge(type + "row" + id))
			{
				dge(type + "row" + id).className = selectedclasses[type][id];
				selectedclasses[type][id] = undefined;
			}
		}
	}

	function clearselected()
	{
		selectedclasses = new Array();
	}

	function markthread(threadids,type,v)
	{
		engine(threadsmarked,"markthread.php?threadid=" + threadids + "&type=" + type + "&" + type + "=" + v);
	}


	function marktag(threadtagids,type,v)
	{
		engine(threadtagsmarked,"markthread.php?threadtagid=" + threadtagids + "&type=" + type + "&" + type + "=" + v);
	}

	function threadsmarked(msg)
	{
		alert(msg);
		refilter();
	}

	function threadtagsmarked(msg)
	{
		alert(msg);
		reloadclassic();
	}

	function enableforumfunction(tf,type)
	{
		dge(type + "enablefunctiontext").style.display = tf ? "" : "none";
		dge(type + "enablefunctionlink").style.display = tf ? "none" : "";

		var disp = tf ? "" : "none";

		for(var i=0;dge("threadcheckbox_" + i);i++)
			dge("threadcheckbox_" + i).style.display = disp;
	}

	function selectall(which,type,tf)
	{
		if(which=="all")
		{
			for(var i=0;dge(type + "checkbox_" + i);i++)
			{
				dge(type + "checkbox_" + i).checked = tf;
				select_checkbox(type,dge(type + "checkbox_" + i).value,tf);
			}
		}
		else if(which=="favorite")
		{
		}
		else if(which=="read")
		{

		}
	}

	function forumfunction(t)
	{
		var name = t.name;
		var action = t.value;
		var selected = new Array();
		var numselected = 0;
		var i = 0;
		switch(name)
		{
			case("threadaction"):
				for(i=0;dge("postcheckbox_" + i);i++)
					if(dge("postcheckbox_" + i).checked)
						selected.push(dge("postcheckbox_" + i).value);
				numselected = selected.length;
				var selectedlist = selected.join(",");
				var threadid = dge("currentthreadid").value;
				
				if(numselected == 0 && action!="destroy" && action!="markunread" && action!="merge")
				{
					alert("Please select some posts to perform this action");
					t.value="";	
					return;
				}
				
				switch(action)
				{
					case("destroy"):
						destroythread(threadid);
						break;
					case("merge"):
						startmerging(threadid);
						break;
					case("markunread"):
						markthread(threadid,"read",0);
						break;
					case("delete"):
						deletepost(threadid,selectedlist);
						break;
					case("splittoexisting"):
						splittoexisting(threadid,selectedlist);
						break;
					case("splittonew"):
						splittonew(threadid,selectedlist);
						break;
					case("quote"):
						OpenPostWindow(threadid,selectedlist);	
						break;
				}
				break;
			case("threadlistaction"):
				for(i=0;dge("threadcheckbox_" + i);i++)
					if(dge("threadcheckbox_" + i).checked)
						selected.push(dge("threadcheckbox_" + i).value);
				numselected = selected.length;
				var selectedlist = selected.join(",");


				if(numselected==0 && action!="allread")
				{
					alert("Please select a thread");
					return;
				}
				switch(action)
				{
					case("merge"):
						if(numselected < 2)
							alert("Please select more than one thread to merge");
						else
							mergethreads(selectedlist);
						break;
					case("destroy"):
						destroythread(selectedlist);
						break;
					case("locked"):
						markthread(selectedlist,'locked',1);
						break;
					case("unlock"):
						markthread(selectedlist,'locked',0);
						break;
					case("sticky"):
						markthread(selectedlist,'sticky',1);
						break;
					case("unsticky"):
						markthread(selectedlist,'sticky',0);
						break;
					case("read"):
						markthread(selectedlist,'read',1);
						break;
					case("unread"):
						markthread(selectedlist,'read',0);
						break;
					case("allread"):
						doaction("markread");
						break;
					case("favorite"):
						markthread(selectedlist,'fav',1);
						break;
					case("unfavorite"):
						markthread(selectedlist,'fav',0);
						break;
					case("changetag"):
						startchangetag(selectedlist);
						break;
				}
				break;
			case("classicaction"):
				for(i=0;dge("threadtagcheckbox_" + i);i++)
					if(dge("threadtagcheckbox_" + i).checked)
						selected.push(dge("threadtagcheckbox_" + i).value);
				numselected = selected.length;
				var selectedlist = selected.join(",");
				if(numselected==0)
					alert("No Thread Tags selected");
				else
				{
					switch(action)
					{
						case("read"):
							marktag(selectedlist,'read',1);
							break;
					}
				}
				break;
		}
		t.value = "";
	}

	function showmark(tf)
	{
		showhtc(tf,1);
	}

	function threadtagcheckbox(tagid)
	{
		var i = dge("threadtaglookup" + tagid).value;
		//alert(i);
		return dge("threadtagcheckbox" + i);

	}

	// Forum Inline Edit
	function show_quick_edit(postid, tf)
	{
		dge("editpost" + postid).style.display = tf ? "" : "none";
		dge("displaypost" + postid).style.display = tf ? "none" : "";
	}

	function start_quick_edit(postid)
	{
		dge("editpost" + postid).innerHTML="<center><img src='spinner.gif'></center>";
		show_quick_edit(postid,true);
		engine(function(msg){load_quick_edit(postid,msg)},"loadquickedit.php?postid=" + postid);
	}

	function load_quick_edit(postid,msg)
	{
		dge("editpost" + postid).innerHTML = msg;
		show_quick_edit(postid,true);
	}

	function cancel_quick_edit(postid)
	{
		dge("editpost" + postid).innerHTML = "";
		show_quick_edit(postid,false);
	}

	
	function save_quick_edit(postid)
	{
		var post = dge("quickedittext" + postid).value;
		var threadid = dge("currentthreadid").value;
		var qs = "post=" + encodeURIComponent(post) + "&threadid=" + encodeURIComponent(threadid) + "&postid=" + encodeURIComponent(postid);

		engine(function(msg){quick_edit_saved(postid,msg)},"savequickpost.php",qs);

	}

	function quick_edit_saved(postid,msg)
	{
		var stat = msg.split(/\n/,2);
		if(stat[0]=="fail")
		{
			alert(stat[1]);
		}
		else
		{
			var text = msg.substr(stat[0].length);
			dge("displaypost" + postid).innerHTML = text;
			dge("editpost" + postid).innerHTML = "";
			show_quick_edit(postid,false);
			scanforcommedits();
		}
	}

	// Forum Post URL Popup
	function make_post_link(postid)
	{
		var url = "http://" + location.host + "/viewthread.php?postid=" + postid;
		var html = "<div style='text-align:center'>Here is the URL to this post if you wish to link to it:<br /><br /><br /><span style='font-family:monospace;border-style:solid;border-width:1px;border-color:grey;padding:5px'>" + url + "</span><br /><br />";
		movable_window("URL to Post",html,400,100);
	}

	//set threads per page
	function setthreadsperpage(num)
	{
		engine(refilter,"setperpage.php?type=threads&num=" + num);
	}

	function setpostsperpage(num)
	{
		engine(refilter,"setperpage.php?type=posts&num=" + num);
	}

	function refilter()
	{
		location.reload();
	}

	function viewthread(threadid,p)
	{
		if(!p)
			p = 1;
		location.href="viewthread.php?threadid=" + threadid + "&p=" + p;
	}

	function viewpost(postid)
	{
		location.href="viewthread.php?postid=" + postid;
	}

	function backtoindex()
	{
		location.href="forum.php";
	}
