/*
$Id: codebuttons.js,v 1.26 2002/12/08 03:15:16 eofredj Exp $

Oxygen v1.0.11
©2002 Oxygen Development Team
Oxygen : http://o2php.ogdn.net

Please see GPL.txt in the docs directory of this distribution.

File Last Updated:
02-12-27 01:44:12

*/
var defmode = "normalmode"; // default mode. either normalmode, advmode, or helpmode

var bold_active = false;
var hide_active = false;
var italic_active = false;
var underline_active = false;
var center_active = false;
var hyperlink_active = false;
var mail_active = false;
var img_active = false;
var code_active = false;
var quote_active = false;

if(defmode == "advmode")
{
	helpmode = false;
	normalmode = false;
	advmode = true;
}
else if(defmode == "helpmode")
{
	helpmode = true;
	normalmode = false;
	advmode = false;
}
else
{
	helpmode = false;
	normalmode = true;
	advmode = false;
}

function chmode(swtch)
{
	if(swtch == 1)
	{
		advmode = false;
		normalmode = false;
		helpmode = true;
		alert("Help Mode\nClick on any of the formatting buttons for a description and instructions.");
	}
	else if(swtch == 0)
	{
		helpmode = false;
		normalmode = false;
		advmode = true;
		alert("Advanced Mode\nThe BB Code will be inserted without options as soon as you hit the button.");
	}
	else if(swtch == 2)
	{
		helpmode = false;
		advmode = false;
		normalmode = true;
		alert("Normal Mode\nPopups will bring you step by step through the process of inserting BB Code.");
	}
}

function colorswap(object, color)
{
	if(is_nav5up || is_ie4up || is_opera)
	{
		object.style.backgroundColor = color;
	}
	else
	{
		return false;
	}
}

function redirlocate(object, prefix)
{
	if(is_nav4up || is_ie4up || is_opera)
	{
		if(object.options[object.selectedIndex].value != '')
		{
			window.location = (prefix + object.options[object.selectedIndex].value);
		}
	}
	else
	{
		return false;
	}
}

function selecttxt()
{
	if(is_opera)
	{
		Selection = false;
	}
	else if(is_ie4up)
	{
		Selection = document.selection.createRange().text;
	}
	else
	{
		Selection = false;
	}
	return Selection;
}

function AddText(text, selection)
{
	if(selection)
	{
		document.selection.createRange().text = text;
		setfocus();
	}
	else
	{
		TextElement = document.post.message;
		insertAtCaret(TextElement, text);
		TextElement.focus();
	}
	return true;
}

function email(image_bbcode, imgdir)
{
	Selection = selecttxt();

	if(Selection)
	{
		AddTxt = "[email=" + Selection + "]" + Selection + "[/email]";
		AddText(AddTxt, true);
		Selection = '';
	}
	else
	{
		if(helpmode)
		{
			alert("Email Tag\nTurns an email address into a mailto hyperlink.\nUsage: [email]someone@anywhere.com[/email]\nUsage: [email=someone@anywhere.com]link text[/email]");
		}
		else if(advmode)
		{
			if (mail_active)
			{
				AddTxt = "[/email]";
				mail_active = false;
				image_bbcode.src = imgdir + "/bb_email.gif";
			}
			else
			{
				AddTxt = "[email=]";
				mail_active = true;
				image_bbcode.src = imgdir + "/bb_email_active.gif";
			};
			AddText(AddTxt, false);
		}
		else
		{ 
			txt2 = prompt("What name should be shown\nIf this field is empty the email address will be visible",""); 
			if(txt2 != null)
			{
				txt = prompt("Please enter an email address.", "name@domain.com");      
				if(txt != null)
				{
					if(txt2 == "")
					{
						AddTxt = "[email]" + txt + "[/email]";
					
					}
					else
					{
						AddTxt = "[email=" + txt + "]" + txt2 + "[/email]";
					} 
					AddText(AddTxt, false);
				}
			}
		}
	}
}

function chsize(size)
{
	Selection = selecttxt();

	if(Selection)
	{
		AddTxt = "[size=" + size + "]" + Selection + "[/size]";
		AddText(AddTxt, true);
		Selection = '';
	}
	else
	{
		if(helpmode)
		{
			alert("Size Tag\\nSets the text size.\\nPossible values are 1 to 6.\\n 1 being the smallest and 6 the largest.\\nUsage: [size="+size+"]This is size "+size+" text[/size]");
		}
		else if(advmode)
		{
			AddTxt = "[size=" + size + "] [/size]";
			AddText(AddTxt, false);
		}
		else
		{
			txt = prompt("Please enter the text to be size " + size,"Text"); 
			if(txt != null)
			{
				AddTxt = "[size=" + size + "]" + txt + "[/size]";
				AddText(AddTxt, false);
			}
		}
	}
}

function chfont(font)
{
	Selection = selecttxt();

	if(Selection)
	{
		AddTxt = "[font=" + font + "]" + Selection + "[/font]";
		AddText(AddTxt, true);
		Selection = '';
	}
	else
	{
		if(helpmode)
		{
			alert("Font Tag\\nSets the font face for the enclosed text.\\nUsage: [font=" + font + "]The font of this text is " + font + "[/font]");
		}
		else if(advmode)
		{
			AddTxt = "[font=" + font + "] [/font]";
			AddText(AddTxt, false);
		}
		else
		{
			txt = prompt("Please enter the text to be in " + font,"Text");
			if(txt != null)
			{
				AddTxt = "[font=" + font + "]" + txt + "[/font]";
				AddText(AddTxt, false);
			}
		}
	}
}

function bold(image_bbcode, imgdir)
{
	Selection = selecttxt();

	if(Selection)
	{
		AddTxt = "[b]" + Selection + "[/b]";
		AddText(AddTxt, true);
		Selection = '';
	}
	else
	{
		if(helpmode)
		{
			alert("Bold Tag\nMakes the enclosed text bold.\nUsage: [b]This is some bold text[/b]");
		}
		else if(advmode)
		{
			if (bold_active)
			{
				AddTxt = "[/b]";
				bold_active = false;
				image_bbcode.src = imgdir + "/bb_bold.gif";
			}
			else
			{
				AddTxt = "[b]";
				bold_active = true;
				image_bbcode.src = imgdir + "/bb_bold_active.gif";
			};
			AddText(AddTxt, false);
		}
		else
		{
			txt = prompt("Please enter the text that should be bolded.","Text");
			if(txt != null)
			{
				AddTxt = "[b]" + txt + "[/b]";
				AddText(AddTxt, false);
			}
		}
	}
}

function hide(image_bbcode, imgdir)
{
	Selection = selecttxt();

	if(Selection)
	{
		AddTxt = "[hide]" + Selection + "[/hide]";
		AddText(AddTxt, true);
		Selection = '';
	}
	else
	{
		if(helpmode)
		{
			alert("Hide Tag\nMakes the enclosed text hidden.\nUsage: [hide]This is some hidden text[/hide]");
		}
		else if(advmode)
		{
			if (hide_active)
			{
				AddTxt = "[/hide]";
				hide_active = false;
				image_bbcode.src = imgdir + "/bb_hide.gif";
			}
			else
			{
				AddTxt = "[hide]";
				hide_active = true;
				image_bbcode.src = imgdir + "/bb_hide_active.gif";
			};
			AddText(AddTxt, false);
		}
		else
		{
			txt = prompt("Please enter the text that should be hidden.","Text");
			if(txt != null)
			{
				AddTxt = "[hide]" + txt + "[/hide]";
				AddText(AddTxt, false);
			}
		}
	}
}

function italicize(image_bbcode, imgdir)
{
	Selection = selecttxt();

	if(Selection)
	{
		AddTxt = "[i]" + Selection + "[/i]";
		AddText(AddTxt, true);
		Selection = '';
	}
	else
	{
		if(helpmode)
		{
			alert("Italicize Tag\nMakes the enclosed text italicized.\nUsage: [i]This is some italicized text[/i]");
		}
		else if(advmode)
		{
			if (italic_active)
			{
				AddTxt = "[/i]";
				italic_active = false;
				image_bbcode.src = imgdir + "/bb_italicize.gif";
			}
			else
			{
				AddTxt = "[i]";
				italic_active = true;
				image_bbcode.src = imgdir + "/bb_italicize_active.gif";
			};
			AddText(AddTxt, false);
		}
		else
		{   
			txt = prompt("Please enter the text that should be italicized.","Text");     
			if(txt != null)
			{
				AddTxt = "[i]" + txt + "[/i]";
				AddText(AddTxt, false);
			}
		}
	}
}

function quote(image_bbcode, imgdir)
{
	Selection = selecttxt();

	if(Selection)
	{
		AddTxt = "[quote]" + Selection + "[/quote]";
		AddText(AddTxt, true);
		Selection = '';
	}
	else
	{
		if(helpmode)
		{
			alert("Quote tag\nQuotes the enclosed text to reference something specific that someone has posted.\nUsage: [quote]This is a quote[/quote]");
		}
		else if(advmode)
		{
			if(quote_active)
			{
				AddTxt = "[/quote]";
				quote_active = false;
				image_bbcode.src = imgdir + "/bb_quote.gif";
			}
			else
			{
				AddTxt = "[quote]";
				quote_active = true;
				image_bbcode.src = imgdir + "/bb_quote_active.gif";
			}
			AddText(AddTxt, false);
		}
		else
		{   
			txt = prompt("Please enter the text you want quoted.","Text");     
			if(txt != null)
			{
				AddTxt = "[quote]" + txt + "[/quote]";
				AddText(AddTxt, false);
			}
		}
	}
}

function chcolor(color)
{
	Selection = selecttxt();

	if(Selection)
	{
		AddTxt = "[color=" + color + "]" + Selection + "[/color]";
		AddText(AddTxt, true);
		Selection = '';
	}
	else
	{
		if(helpmode)
		{
			alert("Color Tag\nSets the text color.  Any named color can be used.\nUsage: [color=" + color + "]This is some " + color + " text[/color]");
		}
		else if(advmode)
		{
			AddTxt = "[color=" + color + "] [/color]";
			AddText(AddTxt, false);
		}
		else
		{  
			txt = prompt("Please enter the text that should be " + color,"Text");
			if(txt != null)
			{
				AddTxt = "[color=" + color + "]" + txt + "[/color]";
				AddText(AddTxt, false);
			}
		}
	}
}

function center(image_bbcode, imgdir)
{
	Selection = selecttxt();

	if(Selection)
	{
		AddTxt = "[center]" + Selection + "[/center]";
		AddText(AddTxt, true);
		Selection = '';
	}
	else
	{
		if(helpmode)
		{
			alert("Centered tag\nCenters the enclosed text.\nUsage: [align=center]This text is centered[/align]");
		}
		else if(advmode)
		{
			if(center_active)
			{
				AddTxt = "[/center]";
				center_active = false;
				image_bbcode.src = imgdir + "/bb_center.gif";
			}
			else
			{
				AddTxt = "[center]";
				center_active = true;
				image_bbcode.src = imgdir + "/bb_center_active.gif";
			};
			AddText(AddTxt, false);
		}
		else
		{  
			txt = prompt("Please enter the text that should be centered.","Text");     
			if(txt != null)
			{
				AddTxt = "[center]" + txt + "[/center]";
				AddText(AddTxt, false);
			}
		}
	}
}

function hyperlink(image_bbcode, imgdir)
{
	Selection = selecttxt();

	if(Selection)
	{
		AddTxt = "[url=" + Selection + "]" + Selection + "[/url]";
		AddText(AddTxt, true);
		Selection = '';
	}
	else
	{
		if(helpmode)
		{
			alert("Hyperlink Tag\nTurns an url into a hyperlink.\nUsage: [url]http://www.anywhere.com[/url]\nUsage: [url=http://www.anywhere.com]link text[/url]");
		}
		else if(advmode)
		{
			if(hyperlink_active)
			{
				AddTxt = "[/url]";
				hyperlink_active = false;
				image_bbcode.src = imgdir + "/bb_url.gif";
			}
			else
			{
				AddTxt = "[url=]";
				hyperlink_active = true;
				image_bbcode.src = imgdir + "/bb_url_active.gif";
			}
			AddText(AddTxt, false);
		}
		else
		{ 
			txt2 = prompt("What name should be shown?\nIf this Field is blank the URL would be visible",""); 
			if(txt2!=null)
			{
				txt = prompt("Please enter the url for the hyperlink.","http://");
				if(txt != null)
				{
					if(txt2=="")
					{
						AddTxt = "[url]" + txt + "[/url]";
						AddText(AddTxt, false);
					}
					else
					{
						AddTxt = "[url=" + txt + "]" + txt2 + "[/url]";
						AddText(AddTxt, false);
					}
				}
			}
		}
	}
}

function image(image_bbcode, imgdir)
{
	Selection = selecttxt();

	if(Selection)
	{
		AddTxt = "[img]" + Selection + "[/img]";
		AddText(AddTxt, true);
		Selection = '';
	}
	else
	{
		if(helpmode)
		{
			alert("Image Tag\nInserts an image into the post.\nUsage: [img]http:\www.anywhere.comimage.gif[/img]");
		}
		else if(advmode)
		{
			if(img_active)
			{
				AddTxt = "[/img]";
				img_active = false;
				image_bbcode.src = imgdir + "/bb_image.gif";
			}
			else
			{
				AddTxt = "[img]"
				img_active = true;
				image_bbcode.src = imgdir + "/bb_image_active.gif";
			};
			AddText(AddTxt, false);
		}
		else
		{
			txt = prompt("Please enter the URL to the image you wish to insert.","http://");    
			if(txt != null)
			{
				AddTxt = "[img]" + txt + "[/img]";
				AddText(AddTxt, false);
			}
		}
	}
}

function code(image_bbcode, imgdir)
{
	Selection = selecttxt();

	if(Selection)
	{
		AddTxt = "[code]" + Selection + "[/code]";
		AddText(AddTxt, true);
		Selection = '';
	}
	else
	{
		if(helpmode)
		{
			alert("Code Tag\nBlockquotes the text you reference and preserves the formatting.\nUsefull for posting code.\nUsage: [code]This is formated text[/code]");
		}
		else if(advmode)
		{
			if(code_active)
			{
				AddTxt = "[/code]";
				code_active = false;
				image_bbcode.src = imgdir + "/bb_code.gif";
			}
			else
			{
				AddTxt = "[code]";
				code_active = true;
				image_bbcode.src = imgdir + "/bb_code_active.gif";
			}
			AddText(AddTxt, false);
		}
		else
		{   
			txt = prompt("Please enter the text you wanted blockquoted.","");     
			if(txt != null)
			{
				AddTxt = "[code]" + txt + "[/code]";
				AddText(AddTxt, false);
			}
		}
	}
}

function list()
{
	if(helpmode)
	{
		alert("List Tag\nBuilds a bulleted, numbered, or alphabetical list.\nUsage: [list]\n[*]item1\n[*]item2\n[*]item3\n[/list]");
	}
	else if(advmode)
	{
		AddTxt = "[list]\r[*]\r[*]\r[*]\r[/list]";
		AddText(AddTxt, false);
	}
	else
	{
		txt = prompt("Please select your list type\n ('A' for aplhabetic, '1' for nummeric) You can leave this field blank","");               
		while((txt != "") && (txt != "A") && (txt != "a") && (txt != "1") && (txt != null))
		{
			txt = prompt("ERROR!\nThe only possible values for type of list are blank 'A' and '1'.", "");               
		}

		if(txt != null)
		{
			if(txt == "")
			{
				AddTxt = "[list]\r\n";
			}
			else
			{
				AddTxt = "[list=" + txt + "]\r";
			}

			txt2 = txt;
			txt = "1";
			while((txt != "") && (txt != null))
			{
				txt = prompt("List Item:\nLeave it blank to End the List", ""); 
				if(txt != "")
				{
					AddTxt += "[*]" + txt + "\r"; 
				}
			}

			if(txt2 == "")
			{
				AddTxt += "[/list]\r\n";
			}
			else
			{
				AddTxt += "[/list=" + txt2 + "]\r";
			}

			AddText(AddTxt, false);
		}
	}
}

function underline(image_bbcode, imgdir)
{
	Selection = selecttxt();

	if(Selection)
	{
		AddTxt = "[u]" + Selection + "[/u]";
		AddText(AddTxt, true);
		Selection = '';
	}
	else
	{
		if(helpmode)
		{
			alert("Underline Tag\nUnderlines the enclosed text.\nUsage: [u]This text is underlined[/u]");
		}
		else if(advmode)
		{
			if(underline_active)
			{
				AddTxt = "[/u]";
				underline_active = false;
				image_bbcode.src = imgdir + "/bb_underline.gif";
			}
			else
			{
				AddTxt = "[u]";
				underline_active = true;
				image_bbcode.src = imgdir + "/bb_underline_active.gif";
			};
			AddText(AddTxt, false);
		}
		else
		{  
			txt = prompt("Please enter the text that should be underlined.","Text");     
			if(txt != null)
			{
				AddTxt = "[u]" + txt + "[/u]";
				AddText(AddTxt, false);
			}
		}
	}
}

function storeCaret(TextElement)
{
	if(is_nav5up || is_ie4up || is_opera)
	{
		if(TextElement.createTextRange)
		{
			TextElement.caretPos = document.selection.createRange().duplicate();
			selectedInputArea = TextElement;
		}
	}
	else
	{
		return false;
	}
}

function insertAtCaret(TextElement, text)
{
	if(TextElement.createTextRange && TextElement.caretPos)
	{
		var caretPos = TextElement.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	}
	else
	{
		TextElement.value  += text;
	}
}

function icon(icon)
{
	AddText(icon, selecttxt());
}

function setfocus()
{
	document.post.message.focus();
}

function Popup(url, window_name, window_width, window_height) 
{
	var win_width = (screen.width - window_width) / 2;
	var win_height = (screen.height - window_height) / 2;
	settings = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=" + window_width + ", height=" + window_height + ", top=" + win_height + ", left=" + win_width;
	window.open(url, window_name, settings);
}

function moresmilies(icon)
{ 
	TextElement = opener.document.post.message;
	insertAtCaret(TextElement, icon);
	TextElement.focus();	
} 

function CheckAll(form, me, name)
{
	for(var i = 0; i < form.elements.length; i++)
	{
		var e = form.elements[i];
		
		if ((e != me) && (e.type == 'checkbox') && (e.name == name))
			 e.checked = form[me.name].checked;
	}
}

function setimage(img)
{
	if(img[img.selectedIndex].value != "")
	{
		document.images['avatarpic'].src = img[img.selectedIndex].value;
		img.form.avatarurl.value = img[img.selectedIndex].value;
	}
	else
	{
		document.images['avatarpic'].src = "images/common/pixel.gif";
		img.form.avatarurl.value = "";
	}
}
