//  Copyright (C) 2005-2006  Xenno Group group.xennobb.com.
//  Visit XennoBB at www.xennobb.com.
//
//  XennoBB is free software; you can redistribute it and/or modify it
//  under the terms of the GNU General Public License as published
//  by the Free Software Foundation; either version 2 of the License,
//  or (at your option) any later version.
//
//  XennoBB is distributed in the hope that it will be useful, but
//  WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//  MA 02110-1301 USA
function xBB_Cascade(elem)
{
	e_state = document.getElementById(elem).style.display;
	if (e_state == "none") document.getElementById(elem).style.display="block";
	else document.getElementById(elem).style.display="none";
}
function xBB_Tag_URL()
{
	var FoundErrors = '';
	var enterURL = prompt("Enter URL", "http://");
	var enterTITLE = prompt("Enter title", "Click me");
	if (!enterURL) FoundErrors += " " + "Please enter the URL";
	if (!enterTITLE) FoundErrors += " " + "Please enter the title";
	if (FoundErrors)
	{
		alert("Error! "+FoundErrors);
		return;
	}
	xBB_Insert_Text("[url="+enterURL+"]"+enterTITLE+"[/url]", "", false);
}
function xBB_Color_Picker()
{
	var width = 400;
	var height = 230;
	window.open('../include/functions/ColorPicker.php', 'cp', 'alwaysRaised=yes, dependent=yes, resizable=no, location=no, width='+width+', height='+height+', menubar=no, status=no, scrollbars=no, menubar=no');
}
function xBB_Tag_Mail()
{
	var FoundErrors = '';
	var enterADDRESS = prompt("Enter address", "");
	var enterNAME = prompt("Enter name", "Name");
	if (!enterADDRESS) FoundErrors += " " + "Please enter address";
	if (!enterNAME) FoundErrors += " " + "Please enter name";
	if (FoundErrors)
	{
		alert("Error! "+FoundErrors);
		return;
	}
	xBB_Insert_Text("[email="+enterADDRESS+"]"+enterNAME+"[/email]", "", false);
}
function xBB_Tag_Font_Size()
{
	var FoundErrors = '';
	var enterText = prompt("Enter text", "");
	var enterSize = prompt("Enter font size", "12");
	if (!enterText) FoundErrors += " " + "Please enter text";
	if (!enterSize) FoundErrors += " " + "Please enter font size";
	if (FoundErrors)
	{
		alert("Error! "+FoundErrors);
		return;
	}
	xBB_Insert_Text("[size="+enterSize+"]"+enterText+"[/size]", "", false);
}
function xBB_Tag_Img()
{
	var FoundErrors = '';
	var enterIMG = prompt("Enter image address", "http://");
	if (!enterIMG) FoundErrors += " " + "Please enter URL";
	if (FoundErrors)
	{
		alert("Error! "+FoundErrors);
		return;
	}
	xBB_Insert_Text("[img]"+enterIMG+"[/img]", "", false);
}
function xBB_Tag_Spoiler()
{
	var FoundErrors = '';
	var enterSpoiler = prompt("Enter spoiler text", "");
	if (!enterSpoiler) FoundErrors += " " + "Please enter spoiler text";
	if (FoundErrors)
	{
		alert("Error! "+FoundErrors);
		return;
	}
	xBB_Insert_Text("[spoiler]"+enterSpoiler+"[/spoiler]", "", false);
}
var state = 'none';
function xBB_Show_Hide(layer_ref)
{
	if (state == 'block') state = 'none';
	else state = 'block';
	if (document.all) eval( "document.all." + layer_ref + ".style.display = state");
	if (document.layers) document.layers[layer_ref].display = state;
	if (document.getElementById &&!document.all)
	{
		hza = document.getElementById(layer_ref);
		hza.style.display = state;
	}
}
function xBB_Insert_Text(open, close)
{
	msgfield = (document.all) ? document.all.req_message : document.forms['post']['req_message'];
	if (document.selection && document.selection.createRange)
	{
		msgfield.focus();
		sel = document.selection.createRange();
		sel.text = open + sel.text + close;
		msgfield.focus();
	}
	else if (msgfield.selectionStart || msgfield.selectionStart == '0')
	{
		var startPos = msgfield.selectionStart;
		var endPos = msgfield.selectionEnd;
		msgfield.value = msgfield.value.substring(0, startPos) + open + msgfield.value.substring(startPos, endPos) + close + msgfield.value.substring(endPos, msgfield.value.length);
		msgfield.selectionStart = msgfield.selectionEnd = endPos + open.length + close.length;
		msgfield.focus();
	}
	else
	{
		msgfield.value += open + close;
		msgfield.focus();
	}
	return;
}
function xBB_Update_Upload_Slots()
{
	var html = '';
	var slot_count = document.forms[0].upload_slots.value;
	var i = 0;
	for (i = 0; i < slot_count; i++) html += "\t\t\t\t\t\t\t\t<p><input type='file' name='image_upload[]' size='70' /></p>\n";
	document.getElementById("image_upload").innerHTML = html;
}
function xBB_Clear_Upload_Slots()
{
	document.getElementById("image_upload").innerHTML = '';
}
