
function BoldClick() {
	var frm = document.postForm;
	frm.frm_post.value += "[b][/b]";
	frm.frm_post.focus();
}

function BoldOver() {
	exampleStr.innerHTML = "[b] text [/b] (make text <b>bold</b>)";
}

function ButtonOut() {
	exampleStr.innerHTML = "&nbsp;";
}

function CheckPostForm( frm ) {
	if ( ! confirm( "Submit this post?" )) return false;
	else {
		if ( emotwin && ! emotwin.closed ) emotwin.close();
		return true;
	}
}

function DeletePost( post_id, page ) {
	if ( ! confirm( "Delete post?" )) return;
	self.location.href = "forum_post_delete.php?id=" + escape( post_id ) + "&page=" + escape( page );
}

function DeleteTopic( topic_id ) {
	if ( ! confirm( "Delete topic?" )) return;
	self.location.href = "forum_topic_delete.php?id=" + escape( topic_id );
}

function EditPost( cat_id, topic_id, post_id, page ) {
	if ( ! confirm( "Edit this post?" )) return;
	var url = "forum_post_edit.php?cat_id=" + escape( cat_id ) + "&topic_id=" + escape( topic_id ) +
	          "&edit=" + escape( post_id ) + "&page=" + escape( page );
	self.location.href = url;
}

var entrywin = null;
function EntryClick() {
	var frm = document.postForm;
	if ( ! entrywin || entrywin.closed )
		entrywin = open( "forum_entry_select.php", "entrywindow",
		                 "width=800,height=700,resizable=1,scrollbars=1" );
	entrywin.focus();
	//frm.frm_post.value += "[entry=]";
}

function EntryOver() {
	exampleStr.innerHTML = "[entry=id][/entry] (click button to choose an entry)";
}

function ImgClick() {
	var frm = document.postForm;
	frm.frm_post.value += "[img][/img]";
	frm.frm_post.focus();
}

function ImgOver() {
	exampleStr.innerHTML = "[img] http://image_url [/img] (Do not link to large images!)";
}

function ItalClick() {
	var frm = document.postForm;
	frm.frm_post.value += "[i][/i]";
	frm.frm_post.focus();
}

function ItalOver() {
	exampleStr.innerHTML = "[i] text [/i] (make text <i>italic</i>)";
}

function MarkAllRead( cat_id ) {
	if ( cat_id >= 0 ) var str = "Mark all topics in this category as read?";
	else var str = "Mark all topics in ALL categories as read?";
	if ( ! confirm( str )) return;
	self.location.href = "forum_mark_read.php?cat=" + escape( cat_id );
}

function MoveTopic( frm, topic_id ) {
	if ( ! confirm( "Move this topic to a new category?" )) return;
	var idx = frm.catList.selectedIndex;
	var cat_id = frm.catList[idx].value;
	var url = "forum_topic_move.php?id=" + topic_id + "&cat=" + cat_id;
	self.location.href = url;
}

function PollVote( frm, poll_id, topic_id ) {
	var selopt = -1;
	for ( var i = 0 ; i < frm.poll.length ; i++ )
		if ( frm.poll[i].checked ) selopt = frm.poll[i].value;
	if ( selopt < 0 ) {
		alert( "Select an option" );
		return;
	}

	var url = "forum_poll_vote.php?id=" + escape( poll_id ) + "&opt=" + escape( selopt ) +
	          "&topic=" + escape( topic_id );
	self.location.href = url;
}

function PostEditClose() {
	if ( emotwin && ! emotwin.closed ) emotwin.close();
	self.history.back();
}

var previewWin = null;
function PostPreview( frm ) {
	if ( ! previewWin || previewWin.closed )
		previewWin = open( "/blank.htm", "previewWindow",
		                   "width=800,height=700,resizable=1,scrollbars=1" );
	var d = previewWin.document;
	d.open( "text/html", "replace" );
	d.writeln( "<html><body><form name='hf' method='post' action='forum_topic_preview.php'>\n" );
	d.writeln( "<input type='hidden' name='post' value='" + escape( frm.frm_post.value ) + "'>\n" );

	if ( frm.frm_poll && frm.frm_poll.value.length > 0 ) {
		d.writeln( "<input type='hidden' name='poll' value='" + escape( frm.frm_poll.value ) + "'>\n" );
		for ( var i = 1 ; i <= 10 ; i++ ) {
			var optval = eval( "frm.frm_poll" + i + ".value" );
			d.writeln( "<input type='hidden' name='opt" + i + "' value='" + escape( optval ) + "'>\n" );
		}
	}

	d.writeln( "</form></body></html>\n" );
	d.close();

	previewWin.document.hf.submit();
	previewWin.focus();
}

function QuoteClick() {
	var frm = document.postForm;
	frm.frm_post.value += "[quote][/quote]";
	frm.frm_post.focus();
}

function QuoteOver() {
	exampleStr.innerHTML = "[quote] text [/quote] <b>or</b> [quote=username] text [/quote]";
}

var emotwin = null;
function ShowEmoticons() {
	if ( ! emotwin || emotwin.closed )
		emotwin = open( "forum_emoticons_show.php", "emotwindow",
		                "width=600,height=400,resizable=1,scrollbars=1" );
	else emotwin.location.reload();

	emotwin.focus();
}

function ShowPostsByTime( sel, cat ) {
	var idx = sel.selectedIndex;
	if ( idx <= 0 ) return;

	var mins = sel[idx].value;
	var url = "forum_posts_by_time.php?mins=" + escape( mins );
	if ( cat && cat > 0 ) url += "&cat=" + escape( cat );
	self.location.href = url;
}

function TopicNotify( box, topic_id ) {
	if ( box.checked && ! confirm( "Do you wish to receive an email whenever a reply is added to this topic?" )) {
		box.checked = false;
		return;
	}

	if ( ! box.checked && ! confirm( "Do you wish to remove notification of replies to this topic?" )) {
		box.checked = true;
		return;
	}

	var url = "forum_topic_notify.php?topic=" + escape( topic_id ) + "&notify=" +
	          ( box.checked ? "Y" : "N" );
	self.location.href = url;
}

function UnderClick() {
	var frm = document.postForm;
	frm.frm_post.value += "[u][/u]";
	frm.frm_post.focus();
}

function UnderOver() {
	exampleStr.innerHTML = "[u] text [/u] (make text <u>underlined</u>)";
}

function UpdatePage( topic_id, page ) {
	var url = "forum_topic.php?id=" + escape( topic_id ) + "&page=" + escape( page );
	self.location.href = url;
}

function UpdatePageSize( topic_id, perpage ) {
	var url = "forum_setpagesize.php?id=" + escape( topic_id ) + "&pagesize=" + escape( perpage );
	self.location.href = url;
}

function URLClick() {

	var url = prompt( "Enter the URL", "http://" );
	if ( ! url ) return;
	if ( url.indexOf( "http://" ) < 0 ) url = "http://" + url;

	var urlguess = url.substr( url.indexOf( "//" ) + 2 );
	var txt = prompt( "Enter the link text", urlguess );

	if ( ! txt ) var insert = "[url]" + url + "[/url]";
	else var insert = "[url=" + url + "]" + txt + "[/url]";

	var frm = document.postForm;
	frm.frm_post.value += insert;
	frm.frm_post.focus();
}

function URLOver() {
	exampleStr.innerHTML = "[url]http://url[/url] <b>or</b> [url=http://url]URL text[/url]";
}
