/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 3.0.0 Release Candidate 4
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000–2004 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/


var fontoptions = new Array("Arial", "Arial Black", "Arial Narrow", "Book Antiqua", "Century Gothic", "Comic Sans MS", "Courier New", "Fixedsys", "Franklin Gothic Medium", "Garamond", "Georgia", "Impact", "Lucida Console", "Lucida Sans Unicode", "Microsoft Sans Serif", "Palatino Linotype", "System", "Tahoma", "Times New Roman", "Trebuchet MS", "Verdana");
var sizeoptions = new Array(1, 2, 3, 4, 5, 6, 7);
var istyles = new Array(); istyles = { "pi_button_down" : [ "#98B5E2", "#000000", "0px", "1px solid #316AC5" ], "pi_button_hover" : [ "#C1D2EE", "#000000", "0px", "1px solid #316AC5" ], "pi_button_normal" : [ "#ECE9D8", "#000000", "1px", "none" ], "pi_button_selected" : [ "#E1E6E8", "#000000", "0px", "1px solid #316AC5" ], "pi_menu_down" : [ "#98B5E2", "#316AC5", "0px", "1px solid #316AC5" ], "pi_menu_hover" : [ "#C1D2EE", "#316AC5", "0px", "1px solid #316AC5" ], "pi_menu_normal" : [ "#FFFFFF", "#000000", "0px", "1px solid #FFFFFF" ], "pi_popup_down" : [ "#98B5E2", "#000000", "0px", "1px solid #316AC5" ] };
var normalmode = false;
var smiliewindow_x = 240;
var smiliewindow_y = 280;
var ignorequotechars = 1;
var vbphrase = {
	
	// wysiwyg only
	"wysiwyg_please_wait" : "Please wait for the WYSIWYG editor to finish loading...",
	"wysiwyg_initialized" : "WYSIWYG Editor initialized for %1$s in %2$s seconds.",
	"wysiwyg_command_invalid" : "This command is invalid or not implemented.",
	"moz_must_select_text" : "Mozilla requires that you must select some text for this function to work",
	"moz_edit_config_file" : "You need to edit your Mozilla config file to allow this action.",
	"enter_tag_option" : "Please enter the option for your %1$s tag:",
	
	// both
	"must_enter_subject" : "You must enter a title / subject!",
	"message_too_short" : "The message you have entered is too short. Please lengthen your message to at least %1$s characters.",
	"enter_link_url" :  "Please enter the URL of your link:",
	"enter_image_url" : "Please enter the URL of your image:",
	"enter_email_link" : "Please enter the email address for the link:"
    };

/*	Definitions for the colors for the editor popup (based on colours from MS Word)
	you may edit these colors if you wish, but there MUST be exactly 40 colors
	defined. If the color you wish to use does not have an HTML name, you
	must enter the hexadecimal version on both sides of the colon, for example:
	"#FFFF00" : "Yellow",
	"#FEFEFE" : "#FEFEFE",
*/
var coloroptions = new Array();
coloroptions = {
	"#000000" : "Black",
	"#A0522D" : "Sienna",
	"#556B2F" : "DarkOliveGreen",
	"#006400" : "DarkGreen",
	"#483D8B" : "DarkSlateBlue",
	"#000080" : "Navy",
	"#4B0082" : "Indigo",
	"#2F4F4F" : "DarkSlateGray",
	"#8B0000" : "DarkRed",
	"#FF8C00" : "DarkOrange",
	"#808000" : "Olive",
	"#008000" : "Green",
	"#008080" : "Teal",
	"#0000FF" : "Blue",
	"#708090" : "SlateGray",
	"#696969" : "DimGray",
	"#FF0000" : "Red",
	"#F4A460" : "SandyBrown",
	"#9ACD32" : "YellowGreen",
	"#2E8B57" : "SeaGreen",
	"#48D1CC" : "MediumTurquoise",
	"#4169E1" : "RoyalBlue",
	"#800080" : "Purple",
	"#808080" : "Gray",
	"#FF00FF" : "Magenta",
	"#FFA500" : "Orange",
	"#FFFF00" : "Yellow",
	"#00FF00" : "Lime",
	"#00FFFF" : "Cyan",
	"#00BFFF" : "DeepSkyBlue",
	"#9932CC" : "DarkOrchid",
	"#C0C0C0" : "Silver",
	"#FFC0CB" : "Pink",
	"#F5DEB3" : "Wheat",
	"#FFFACD" : "LemonChiffon",
	"#98FB98" : "PaleGreen",
	"#AFEEEE" : "PaleTurquoise",
	"#ADD8E6" : "LightBlue",
	"#DDA0DD" : "Plum",
	"#FFFFFF" : "White"
};

// variable to prevent init being called twice
var editor_loaded = false;

// initialize some arrays
var popupcontrols = new Array();
var colorindex = new Array();
var fontoptions = new Array();
var sizeoptions = new Array();
var buttonstatus = new Array();

// default values for URL / Image prompts
var imgurl = "http://";
var linkurl = "http://";

if ((navigator.appVersion.indexOf("MSIE 4.") != "-1" && is_ie) || (parseInt(navigator.appVersion) == 4 && is_ns))
{ // the v4 browsers dont support try / catch
	var is_v4 = true;
}

// #############################################################################
// function to change the appearence of a control element
function format_control(elm, elmtype, controlstate)
{
	// if we do not *need* to change the control state, then don't
	if (controlstate == elm.controlstate)
	{
		return;
	}
	
	// construct the name of the appropriate array key from the istyles array
	istyle = "pi_" + elmtype + "_" + controlstate;

	// set element background, color, padding and border
	elm.style.background = istyles[istyle][0];
	elm.style.color = istyles[istyle][1];
	if (elmtype != "menu")
	{
		elm.style.padding = istyles[istyle][2];
	}
	elm.style.border = istyles[istyle][3];
	
	// set the element controlstate variable
	elm.controlstate = controlstate;
	
	// handle some special cases for popup elements
	if (in_array(elm.cmd, popupcontrols) != -1)
	{
		tds = elm.getElementsByTagName("td");
		for (var i = 0; i < tds.length; i++)
		{
			switch (tds[i].className)
			{
				// set the right-border for popup_feedback class elements
				case "popup_feedback":
				{
					tds[i].style.borderRight = iif(controlstate == "normal", istyles["pi_menu_normal"][3], istyles[istyle][3]);
				}
				break;
				
				// set the border colour for popup_pickbutton class elements
				case "popup_pickbutton":
				{
					tds[i].style.borderColor = iif(controlstate == "normal", istyles["pi_menu_normal"][0], istyles[istyle][0]);
				}
				break;
				
				// set the left-padding and left-border for alt_pickbutton elements
				case "alt_pickbutton":
				{
					if (buttonstatus[elm.cmd])
					{	
						tds[i].style.paddingLeft = istyles["pi_button_normal"][2];
						tds[i].style.borderLeft = istyles["pi_button_normal"][3];
					}
					else
					{
						tds[i].style.paddingLeft = istyles[istyle][2];
						tds[i].style.borderLeft = istyles[istyle][3];
					}
				}
			}
		}
	}
}

// #############################################################################
// function to set 'unselectable' for an element and all its child nodes
function set_unselectable(elm)
{
	if (is_ie4)
	{
		return;
	}
	else if (elm.tagName)
	{
		if (elm.hasChildNodes())
		{
			for (var i = 0; i < elm.childNodes.length; i++)
			{
				set_unselectable(elm.childNodes[i]);
			}
		}
		elm.unselectable = true;
	}
}

// #############################################################################
function build_fontoptions(is_wysiwyg)
{
	if (is_wysiwyg)
	{
		for (key in fontoptions)
		{
			document.writeln('<tr><td class="ofont">' + fontoptions[key] + '</td></tr>');
		}
	}
	else
	{
		for (key in fontoptions)
		{
			document.writeln('<option value="' + fontoptions[key] + '">' + fontoptions[key] + '</option>');
		}
	}
}

// #############################################################################
function build_sizeoptions(is_wysiwyg)
{
	if (is_wysiwyg)
	{
		for (key in sizeoptions)
		{
			document.writeln('<tr><td class="osize"><font size="' + sizeoptions[key] + '">' + sizeoptions[key] + '</font></td></tr>');
		}
	}
	else
	{
		for (key in sizeoptions)
		{
			document.writeln('<option value="' + sizeoptions[key] + '">' + sizeoptions[key] + '</option>');
		}
	}
}

// #############################################################################
function build_coloroptions(is_wysiwyg)
{
	if (is_wysiwyg)
	{
		for (var y = 0; y < 5; y++)
		{
			document.write('<tr align="center">');		
			for (var x = 0; x < 8; x++)
			{
				document.write('<td class="ocolor"><div></div></td>');
			}		
			document.write('</tr>');
		}
	}
	else
	{
		for (key in coloroptions)
		{
			document.writeln('<option value="' + coloroptions[key] + '" style="background-color:' + coloroptions[key] + ';">' + coloroptions[key].replace(/([a-z]{1})([A-Z]{1})/g, "$1 $2") + '</option>');
		}
	}
}

// #############################################################################
function set_default_text(textvalue, is_wysiwyg, non_wysiwyg_obj)
{
	if (is_wysiwyg)
	{
		if (is_ie)
		{
			if (textvalue == "")
			{
				textvalue = "<p style=\"margin:0px\"></p>";
			}
			fetch_object("htmlbox").innerHTML = textvalue;
			fetch_object("htmlbox").className = "wysiwyg";
		}
		else
		{
			htb = fetch_object("htmlbox").contentWindow.document;
			htb.open();
			htb.write("<html><head><title>Mozilla WYSIWYG</title></head><body>" + textvalue + "</body></html>");
			htb.close();
			htb.body.style.cursor = "text";
			
			if (bgstyle = fetch_mozilla_css_class(".wysiwyg"))
			{
				// got bgstyle
			}
			else
			{
				// just set up a default style
				bgstyle = {
					"backgroundColor" : "white",
					"color"           : "black",
					"fontFamily"      : "verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif",
					"fontSize"        : "10pt"
				};
			}
			
			htb.body.style.backgroundColor = bgstyle.backgroundColor;
			htb.body.style.color = bgstyle.color;
			htb.body.style.fontFamily = bgstyle.fontFamily;
			htb.body.style.fontSize = bgstyle.fontSize;
		}
	}
	else
	{
		non_wysiwyg_obj.value = textvalue;
	}
}

// #############################################################################
function fetch_mozilla_css_class(selector)
{
	for (var s = 0; s < document.styleSheets.length; s++)
	{
		for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
		{
			if (document.styleSheets[s].cssRules[r].selectorText == selector)
			{
				return document.styleSheets[s].cssRules[r].style;
			}
		}
	}
	
	return false;
}

// #############################################################################
function open_smilie_window(x_width, y_width, wysiwyg)
{
	window.open("misc.php?" + SESSIONURL + "do=getsmilies&wysiwyg=" + wysiwyg, "smilies", "statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=" + x_width + ",height=" + y_width);
}

/*======================================================================*\
|| ####################################################################
|| # Downloaded: 21:19, Wed Feb 11th 2004
|| # CVS: $RCSfile: vbulletin_editor.js,v $ - $Revision: 1.1 $
|| ####################################################################
\*======================================================================*/