function deletepost(url, post)
{
	var answer = confirm("Are you sure you want to delete this?");
	if (answer)
	{
	   window.location = url + "deleting.php?mode=post&id=" + post;
	}
}

function actionConfirmation(url, question)
{
	var answer = confirm(question);
	if (answer)
	{
	   window.location = url;
	}
}

function changePage(topic, page)
{
	var container;
	var url;
	var content;
	var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
	
	xmlHttp = GetXmlHttpObject();

	container = document.getElementById("recentreplies");
	container.innerHTML = "<table height=480><tr><td valign=top>Loading, please wait..</td></tr></table>";
	url = "topic.php";
	content = "t=" + topic + "&page=" + page + "&mode=newpost";
	
	xmlHttp.onreadystatechange=function()
	{ 
		if(xmlHttp.readyState == 4)
		{
			container.innerHTML = xmlHttp.responseText;
		}
	};
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-Type", contentType);
    xmlHttp.send(content);
}
//=================================================================
//Edit User Pictures
//=================================================================
function updateAvatar(id, action)
{
	try {
		var container, form;
		var url;
		var content;
		var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
		
		var name, path;
		
		xmlHttp = GetXmlHttpObject();
		container = document.getElementById('table'+id);
		form = document.getElementById('frmAvatar'+id);
		name = form.name.value;
		path = form.path.value;
		
		container.innerHTML = "Loading, please wait..";
		url = "edituserpics.php";
		content = "pid=" + id + "&submit=" + action + "&name=" + name + "&path=" + path;
		
		xmlHttp.onreadystatechange=function()
		{ 
			if(xmlHttp.readyState == 4)
			{
				container.innerHTML = xmlHttp.responseText;
			}
		};
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type", contentType);
		xmlHttp.send(content);
	}
	catch (e)
	{
		alert(e);
	}
}
//=================================================================
//Copies the contents of a textarea and updates usersforum with it.
//-Will either update a label, annoucing the time of the last autosave
//  or will obtain whatever's already saved and display it in the textarea
//=================================================================
function autoSave(mode)
{
	try
	{
		var xmlHttp = GetXmlHttpObject();
		var text = document.getElementsByTagName('textarea')[0].value;
		var content;
		var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
		
		
		
		if(mode==1)
			content = "action=obtain";
		else
			content = "action=save&text=" + text;
		
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{	//Get data from the server's response
				if(mode==1)
					document.getElementsByTagName('textarea')[0].innerHTML = xmlHttp.responseText;
				else
					document.getElementById("autosave").innerHTML = xmlHttp.responseText;
			}
		}
		xmlHttp.open("POST","autosave.php",true);
		xmlHttp.setRequestHeader("Content-Type", contentType);
		xmlHttp.send(content);
	}
	catch (e)
	{
		alert(e);
	}
}
//===============================================//
// Enables the ajax, yo
//=================================================//
function GetXmlHttpObject()
{
	var xmlHttp;
	try
	{ //Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch(e)
	{ //Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{	//Chump's browser don't like Ajax.
				return null;
			}
		}
	}
	return xmlHttp;
}