function load_post_list(href)
{
	ajaxExecute("/blog/blog.fexec?" + href + "&mode=ajaxpostlist");
	return false;
}

function load_post(id)
{
	ajaxExecute("/blog/blog.fexec?mode=ajaxpostshow&id=" + id + "&seed=" + Math.random());
	return false;
}

function load_post_comments(id)
{
	ajaxExecute("/blog/blog.fexec?mode=ajaxpostcomments&id=" + id + "&seed=" + Math.random());
	return false;
}

function send_post_comment(textareaid, captchaid, imgid, postid)
{
	var ta = document.getElementById(textareaid);
	var cpt = document.getElementById(captchaid);
	var img = document.getElementById(imgid);
	if (!ta || !cpt || !img) return;
	if (ta.value == "") 
	{
		alert("Cообщение не должно быть пустым");
		return;
	}
	//ajaxExecute("/blog/blog.fexec?mode=ajaxsendpostcomment&id=" + postid + "&word=" + cpt.value + "&message=" + ruescape(ta.value) + "&seed=" + Math.random());
	FormPost(document.getElementById("commentform"), "");
	cpt.value = "";
	var q_u_id = document.getElementById("quoting_user_id");
	q_u_id.value = "";
}

function send_post(titleid, textareaid, captchaid, imgid, uid, editid)
{
	var tt = document.getElementById(titleid);
	var ta = document.getElementById(textareaid);
	var cpt = document.getElementById(captchaid);
	var img = document.getElementById(imgid);
	var edt = document.getElementById(editid);
	if (!tt || !ta || !cpt || !img || !edt) return;
	if (tt.value == "" || ta.value == "") 
	{
		alert("Заголовок и сообщение не должны быть пустыми");
		return;
	}
	//var foredit = "";
	//if (edt.value != "") foredit = "&editpost=" + edt.value;
	//ajaxExecute("/blog/blog.fexec?mode=ajaxsendpost&id=" + uid + foredit + "&word=" + cpt.value + "&title=" + ruescape(tt.value) + "&message=" + ruescape(ta.value) + "&seed=" + Math.random());
	//cpt.value = "";
	FormPost(document.getElementById("postform"), "");
	cpt.value = "";	
}

function clear_post(titleid, textareaid, editid)
{
	var tt = document.getElementById(titleid);
	var ta = document.getElementById(textareaid);
	var edt = document.getElementById(editid);
	if (!tt || !ta || !edt) return;
	if (tt.value != "" || ta.value != "") 
	{
		if (!confirm("Вы уверены?"))
			return;
	}
	tt.value = ta.value = edt.value = "";
}

function ArrowHover(obj,hover) {
	obj.className = (hover) ? 'step_active' : 'step';
	obj.style.cursor = 'pointer' || 'hand';
}

function ArrowHoverRow(obj,hover) {
	obj.className = (hover) ? 'row_active' : '';
	obj.style.cursor = 'pointer' || 'hand';
}

function ajaxEnd() 
{ 
	ajaxCleanup();
	hideAjaxClock(); 
}

function blog_quote_comment(id, quoting_user_id)
{
	var hiddencomment = document.getElementById(id);
	var textarea = document.getElementById("commentmessage");
	if (hiddencomment && textarea)
	{
		textarea.value = hiddencomment.innerHTML + textarea.value;
		var q_user_id = document.getElementById("quoting_user_id");
		if( !q_user_id.value ) q_user_id.value = quoting_user_id;
		 else q_user_id.value = q_user_id.value  + ',' + quoting_user_id;
	}
	return false;
}

function blog_delete_comment(cid, pid)
{
	if (confirm("Вы уверены?"))
	{
		ajaxExecute("/blog/blog.fexec?mode=ajaxdeletecomment&id=" + pid + "&cid=" + cid + "&seed=" + Math.random());
	}
	return false;
}

function blog_delete_post(id, pid)
{
	if (confirm("Вы уверены?"))
	{
		ajaxExecute("/blog/blog.fexec?mode=ajaxdeletepost&id=" + id + "&pid=" + pid + "&seed=" + Math.random());
	}
	return false;
}

function blog_edit_post(id)
{
	var title = document.getElementById("bptitle_" + id).innerHTML;
	var text = document.getElementById("bptext_" + id).innerHTML;
	document.getElementById("titlemessage").value = title;
	document.getElementById("commentmessage").value = text;
	document.getElementById("editid").value = id;
	//window.scrollBy(0, 50000);
	return false;
}

var imgwin = null;

function img_popup() 
{
	imgwin = window.open("/blog/blog.fexec?mode=imagewizard","trcsms"+r_id,'width=550,height=440,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1');
	/*try 
	{
		imgwin.close();
	} catch (e)
	{*/
	// none
	/*} finally {
		//var ajax_str = "/blog/templates/imagewizard.html&seed=" + Math.random();
		imgwin = window.open("/blog/imagewizard.html","trcsms"+r_id,'width=480,height=180,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1');
		//popup_body = null;
		//ajaxExecute(ajax_str);
		//fill_imgwin(imgwin);
	}*/
}

function fill_imgwin(obj) 
{
	if(!window.popup_body) 
	{
		setTimeout(function() {fill_imgwin(obj); 478 },10);
	}
	else 
	{
		obj.document.open();
		obj.document.write(popup_body);
		obj.document.close();
	}
}
var bbIntervalID = 0;
function insertblogeditor()
{
	bbIntervalID = setInterval(function() {if (insertBBEditor("commentmessage")) clearInterval(bbIntervalID) }, 300);
}

function insertimgwizard()
{
	document.getElementById("bbimgbtn").onclick = function() {img_popup()};
}

function undisable()
{
	var form = document.getElementById("commentform");
	if (!form) return;
	for (var i = 0; i < form.elements.length; i++)
	{
		form.elements[i].disabled = false;
	}
}