function addTag (start, end)
{
	if (focused != "")
	{
		t = focused;
		var ss = t.selectionStart;
		var se = t.selectionEnd;
		var oldscroll = t.scrollTop;
		if (ss == se)
		{
			t.value = t.value.slice(0,ss).concat(start).concat('text').concat(end).concat(t.value.slice(se,t.value.length));
			t.selectionStart = ss + start.length;
			t.selectionEnd = se + 4 + start.length;
		}
		else
		{
			t.value = t.value.slice(0,ss).concat(start).concat(t.value.slice(ss,se)).concat(end).concat(t.value.slice(se,t.value.length));
			t.selectionStart = ss + start.length;
			t.selectionEnd = se + start.length;
		}
		t.focus();
		t.scrollTop = oldscroll;
	}
}
function ajax_q(query,id) {
	var xmlHttp;
	try
	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById(id).innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",query,true);
	xmlHttp.send(null);
}
function edit_title (title, dir)
{
	ajax_q ('?dir='+dir+'&edit_title='+title, 'edit-box');
}
