function addPoll(){
	var params = "";
	
	new Ajax.Updater("topic_table","../forum/make_poll.php",
			{
				method: 'post',
				parameters: params,
			}
		);
		
//	document.getElementById("poll").innerHTML = "<a href=\"javascript:removePoll()\"> Remove poll from topic</a>";

}

function removePoll(){
		
	document.getElementById("poll").innerHTML = "<a href=\"javascript:addPoll()\"> Add poll to topic</a>";

}

function deletePost(post_id, deleter){
	var params = "post_id="+post_id+"&deleter="+deleter;
	
	var sure = confirm("Are you sure you want to delete this post?")
	
	if(sure){
		new Ajax.Updater("post_id_"+post_id,"../!pbr42boc8/delete.php",
			{
				method: 'post',
				parameters: params,
			}
		);
	}
}

function editPost(post_id,editor){
	var params = "post_id="+post_id+"&editor="+editor;
	new Ajax.Updater("post_id_"+post_id,"editPost.php",
		{
			method: "post",
			parameters: params,
		}
	);
}

function do_ep(post_id,form_elmt){
	var params = $(form_elmt).serialize(true);
	new Ajax.Updater("post_id_"+post_id,"ep.php",
		{
			method: "post",
			parameters: $(form_elmt).serialize(true)
		}
	);
}

function dont_do_ep(post_id,form_elmt){
	var params = $(form_elmt).serialize(true);
	new Ajax.Updater("post_id_"+post_id,"noep.php",
		{
			method: "post",
			parameters: $(form_elmt).serialize(true)
		}
	);
}

function doLikeUpdate(post_id,like_action){
	var params = "post_id="+post_id+"&like_action="+like_action;
	new Ajax.Updater("like_count_"+post_id, "like.php",
		{
			method: "post",
			parameters: params,
			onSuccess: function(){
				updateLike(post_id,like_action);
						}
		}
	);
}

function updateLike(post_id,like_action){
	if (like_action == 0){
		var link = "javascript:doLikeUpdate("+post_id+",1)";
		document.getElementById("like_"+post_id).setAttribute("href", link);
		document.getElementById("like_"+post_id).innerHTML = "<img src=\"http://www.stayonsync.com/images/buttons/like.png\" />";
	}
	else if (like_action == 1){
		var link = "javascript:doLikeUpdate("+post_id+",0)";
		document.getElementById("like_"+post_id).setAttribute("href", link);
		document.getElementById("like_"+post_id).innerHTML = "<img src=\"http://www.stayonsync.com/images/buttons/unlike.png\" />";
	}
}

function showResponse(req, elmt){
	$('data_'+elmt).innerHTML= req.responseText;
}

function goToPage(x){
	window.location.href = x; 
}

function quote(postid){
	var msgbox = document.getElementById("msgbox");
	
	var params = 'post=' + postid + '&msg=' + msgbox.value;
	
	new Ajax.Request("../forum/quote.php",
			{
				method: 'post',
				parameters: params,
				onSuccess: function(t){
					msgbox.value += t.responseText;
				}
			}
		);
	
	msgbox.focus();
}



function markTopic(topic, user){
	var params = 'topic=' + topic + '&user=' + user + '&always=1';
	
	new Ajax.Updater("always", "../forum/always.php",
		{
			method: 'post',
			parameters: params
		}
	);
}

function unmarkTopic(topic, user){
	var params = 'topic=' + topic + '&user=' + user + '&always=0';
	
	new Ajax.Updater("always", "../forum/always.php",
		{
			method: 'post',
			parameters: params
		}
	);
}

function updatePPP(form_elmt){
	var params = $(form_elmt).serialize();
	
	alert(params);
	
	new Ajax.Request("../forum/updatePPP.php",
		{
			method: 'post',
			parameters: params
		}
	);
}
