//gets a blog entry based on the cat and page
function getPageAndCat(page_val, cat_val) {
	curr_url = "/actions/viewBlog.php";
	setPopUpCoords("loadingind");
	$("#loadingind").show();
	$.get(curr_url, {bpage:page_val, cat:cat_val}, function(data) { $("#loadingind").hide(); $("div#blog_content").html(data); } );
}

function confirmDel(id_val, name_val) {
	del_url = "/actions/delPost.php";
	ret = confirm("Really delete the post called '" + name_val + "'?");
	if(ret) {
		$.get(del_url, {id:id_val}, function(data) { alert(data); getPageAndCat(1, ''); } );
	}
}

function addPost(title_id, name_id, content_id, cat_id, fb_sync_id) {
	add_url = "/actions/addPost.php";
	title_val = document.getElementById(title_id).value;
	name_val = document.getElementById(name_id).value;
	content_val = document.getElementById(content_id).value;
	cat_val = document.getElementById(cat_id).value;
	$("div#new-box").hide();
	$.post(add_url, {name:name_val, title:title_val, content:content_val, cat:cat_val}, function(data) { alert(data); getPageAndCat(1, ''); } );
}

function editPost(id_id, title_id, name_id, content_id, cat_id) {
	edit_url = "/actions/addPost.php";
	id_val = document.getElementById(id_id).value;
	title_val = document.getElementById(title_id).value;
	name_val = document.getElementById(name_id).value;
	content_val = document.getElementById(content_id).value;
	cat_val = document.getElementById(cat_id).value;
	$("div#edit-box-" + id_val).hide();
	$.post(edit_url, {id:id_val, name:name_val, title:title_val, content:content_val, cat:cat_val}, function(data) { alert(data); getPageAndCat(1, ''); } );
}

function showEditPost(id_val) {
	add_url = "/actions/getEditPost.php";
	div_name = "div#edit-box-" + id_val;
	drag_name = "tr#drag_title-edit-" + id_val;
	setPopUpCoords("loadingind");
	$("#loadingind").show();
	$.get(add_url, {id:id_val}, function(data) { $("#loadingind").hide(); $(div_name).html(data); setPopUpCoords("edit-box-" + id_val); $(div_name).show(); $(div_name).Draggable( {handle: drag_name} ); } );
}

function setPopUpCoords(id_name) {
	popUp = document.getElementById(id_name);
	popUp.style.top = Math.round((document.documentElement.clientHeight / 2) - (popUp.style.height / 2) + document.documentElement.scrollTop) + 'px';
	popUp.style.left = Math.round((document.documentElement.clientWidth / 2) - (popUp.style.width / 2)) + 'px';
}
