targetX = new Array();
targetY = new Array();

<!-- The following javascript preloads the swap images -->
		if (document.images)
		{
			nav0 = new Image();
   			nav0.src = "images/splash/nav0.gif";
			nav0_o = new Image();
   			nav0_o.src = "images/splash/nav0_o.gif";
			nav1 = new Image();
   			nav1.src = "images/splash/nav1.gif";
			nav1_o = new Image();
   			nav1_o.src = "images/splash/nav1_o.gif";
			nav2 = new Image();
   			nav2.src = "images/splash/nav2.gif";
			nav2_o = new Image();
   			nav2_o.src = "images/splash/nav2_o.gif";
			nav3 = new Image();
   			nav3.src = "images/splash/nav3.gif";
			nav3_o = new Image();
   			nav3_o.src = "images/splash/nav3_o.gif";
			nav4 = new Image();
   			nav4.src = "images/splash/nav4.gif";
			nav4_o = new Image();
   			nav4_o.src = "images/splash/nav4_o.gif";
			nav5 = new Image();
   			nav5.src = "images/splash/nav5.gif";
			nav5_o = new Image();
   			nav5_o.src = "images/splash/nav5_o.gif";
			nav6 = new Image();
   			nav6.src = "images/splash/nav6.gif";
			nav6_o = new Image();
   			nav6_o.src = "images/splash/nav6_o.gif";
			nav7 = new Image();
   			nav7.src = "images/splash/nav7.gif";
			nav7_o = new Image();
   			nav7_o.src = "images/splash/nav7_o.gif";
   			generate = new Image();
   			generate.src = "images/splash/generate.gif";
   			generate_o = new Image();
			generate_o.src = "images/splash/generate_o.gif";
   			img_jeanne = new Image();
   			img_jeanne.src = "images/splash/jeanne.gif";
   			img_jeanne_o = new Image();
   			img_jeanne_o.src = "images/splash/jeanne_o.gif";
   			img_rob = new Image();
   			img_rob.src = "images/splash/rob.gif";
   			img_rob_o = new Image();
   			img_rob_o.src = "images/splash/rob_o.gif";
			/*** BSR Tutorial MouseOver images ***/
			topic0 = new Image();
   			topic0.src = "images/admin/topics.gif";
			topic0_o = new Image();
   			topic0_o.src = "images/admin/topics_o.gif";
			glossary1 = new Image();
   			glossary1.src = "/images/admin/glossary.gif";
			glossary1_o = new Image();
   			glossary1_o.src = "/images/admin/glossary_o.gif";
			faq2 = new Image();
   			faq2.src = "/images/admin/faq.gif";
			faq2_o = new Image();
   			faq2_o.src = "/images/admin/faq_o.gif";
			tutor3 = new Image();
   			tutor3.src = "/images/admin/tutorials.gif";
			tutor3_o = new Image();
   			tutor3_o.src = "/images/admin/tutorials_o.gif";
   			content4 = new Image();
   			content4.src = "/images/splash/helpContents.gif";
			content4_o = new Image();
   			content4_o.src = "/images/splash/helpContents_o.gif";
   			guide5 = new Image();
   			guide5.src = "/images/splash/uguide.gif";
			guide5_o = new Image();
   			guide5_o.src = "/images/splash/uguide_o.gif";
		}

/*** function for swapping button images ***/
function swap(doc1,doc2){
	if (document.images){
		document.images[doc1].src = eval(doc2 + ".src");
		}
	}

/*** popup window for map services ***/
function showmap(newpage, windowname){
var pageloc = newpage;
popup=window.open("",windowname,"valign=top,width=850,height=600,scrollbars=1,toolbar=1,menubar=1,status=1,statusbar=1,locationbar=0,location=0,resizable=1");
popup.location.href=pageloc;
self.popupwindow = popup;
}

/*** popup window for map legend ***/
function showlegend(newpage){
var pageloc = "http://bluesky.cfr.washington.edu/bluesky/" + newpage;
popup=window.open("","windowlegend","valign=top,align=center,left=300,top=200,width=130,height=425,resizable=0,location=0,toolbar=0,scrollbars=0,menubar=0,status=0");
popup.location.href=pageloc;
self.popupwindow = popup;
}

/*** popup window for map legend ***/
function showinfo(newpage){
var pageloc = "http://bluesky.cfr.washington.edu/bluesky/" + newpage;
popup=window.open("","windowlegend","valign=top,align=center,left=200,top=100,width=400,height=500,resizable=0,location=0,toolbar=0,scrollbars=0,menubar=0,status=0");
popup.location.href=pageloc;
self.popupwindow = popup;
}

/*** new page function ***/
function goto_URL(Area) {
window.location.href = Area.options[Area.selectedIndex].value;
}


// new date variables for year, month, day, hour 
var c_date = new Date();
var yr = c_date.getFullYear();
var mo = c_date.getMonth();
var dy = c_date.getDate();
var hr = c_date.getHours();
var tzOffset = c_date.getTimezoneOffset()/60;
var timezone = 0;
var dayLightSavings = 0;
AprilArray = new Array(5,4,3,2,1,5,5,4);			/*** first sunday in april begin 2003 ***/
OctoberArray = new Array(26,31,30,29,28,26,25,31);	/*** last sunday in october begin 2003 ***/

// Date displayed
var theFormDate = new Date(Date.UTC(yr, mo, dy, hr, 0, 0, 0));

/*** Create Date & Time Select Lists ***/
var monthArray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var zoneArray = new Array("UTC", "PST", "PDT", "MST", "MDT", "CST", "CDT", "EST", "EDT", "HST");
var zoneOffset= new Array(0, 8, 7, 7, 6, 6, 5, 5, 4, 10);
var zoneChange = new Array(0,1,1,1,1,1,1,1,1,0);  /*** some zones change, some do not ***/
var zoneDST = new Array(0,0,1,0,1,0,1,0,1,0);	/*** daylight savings time zones (summer) ***/
var hourArray = new Array("Midnight", "1 am", "2 am", "3 am", "4 am", "5 am", "6 am", "7 am", "8 am", "9 am", "10 am", "11 am", "Noon", "1 pm", "2 pm", "3 pm", "4 pm", "5 pm", "6 pm", "7 pm", "8 pm", "9 pm", "10 pm", "11 pm");

//Functions to fix bad dates in forms -- Trent's fix to evaluate and then update the form's selected indices

function calcdate(theform) {
	var hour = eval(theform.Pick_hour.options[theform.Pick_hour.selectedIndex].value);

	// Set Date object to selected time in UTC.
	theFormDate.setTime(
		Date.UTC(theform.Pick_year.options[theform.Pick_year.selectedIndex].value, 
				theform.Pick_month.options[theform.Pick_month.selectedIndex].value, 
				theform.Pick_day.options[theform.Pick_day.selectedIndex].value, hour, 0, 0, 0) );

	// Extract the components of the date back out
	yr = theFormDate.getUTCFullYear();
	mo = theFormDate.getUTCMonth();
	dy = theFormDate.getUTCDate();
	hr = theFormDate.getUTCHours();
	dayLightSavings = 0;
	for (i = 0; i < AprilArray.length; i++){			/*** check for daylight savings ***/
		k = i + 2003;
		if (yr == k){
			if (mo >= 3 && mo <= 9){
				if (mo == 3 && dy >= AprilArray[i]){dayLightSavings = 1;}
				if (mo == 9 && dy < OctoberArray[i]){dayLightSavings = 1;}
				if (mo > 3 && mo < 9){dayLightSavings = 1;}
			}
		}
	}
	timezone = theform.Pick_zone.options[theform.Pick_zone.selectedIndex].value;
	for (i = 0; i < zoneArray.length; i++){
		if (i == theform.Pick_zone.options[theform.Pick_zone.selectedIndex].value){
			if (zoneChange[i] == 1 && zoneDST[i] != dayLightSavings){
				if (dayLightSavings == 1){timezone = i+1;}
				else {timezone = i-1;}
			}
		}
	}
	updateform(theform);
}

function updateform(theform) {
	theform.Pick_year.selectedIndex = yr - 2003;
	theform.Pick_month.selectedIndex = mo;
	theform.Pick_day.selectedIndex = dy - 1;
	theform.Pick_hour.selectedIndex = hr;
	theform.Pick_zone.selectedIndex = timezone;
}

/*functions for showing and hiding*/
function show(doc) {
	if (document.layers) document.layers[doc].visibility = 'visible';
	else if (document.all) document.all[doc].style.visibility = 'visible'; 
}
function hide(doc) {
	if (document.layers) document.layers[doc].visibility = 'hidden';
	else if (document.all) document.all[doc].style.visibility = 'hidden';
}

function imgPos(){
	var doc = "";
	var imgx = (document.layers) ? parseInt(document.images['refImage'].x) : parseInt(document.images('refImage').offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft) + parseInt(document.images('refImage').offsetParent.offsetParent.offsetParent.offsetLeft) + parseInt(document.images('refImage').offsetParent.offsetParent.offsetLeft) + parseInt(document.images('refImage').offsetParent.offsetLeft) + parseInt(document.images('refImage').offsetLeft);
	var imgy = (document.layers) ? parseInt(document.images['refImage'].y) : parseInt(document.images('refImage').offsetParent.offsetParent.offsetParent.offsetParent.offsetTop) + parseInt(document.images('refImage').offsetParent.offsetParent.offsetParent.offsetTop) + parseInt(document.images('refImage').offsetParent.offsetParent.offsetTop) + parseInt(document.images('refImage').offsetParent.offsetTop) + parseInt(document.images('refImage').offsetTop);
	for (i=0; i<targetX.length; i++){
		doc = "icon" + i;
		if (document.layers){document.layers[doc].pageX = imgx + targetX[i]; document.layers[doc].pageY = imgy + targetY[i];}
		else if (document.all){document.all(doc).style.left = imgx + targetX[i]; document.all(doc).style.top = imgy + targetY[i];}
		show(doc);
	}
}


/******************************************************************************/
/******************************************************************************/
/*** These are all functions required by the BlueSky RAINS Tutorial section
     of the site ***/
/******************************************************************************/
/******************************************************************************/

<!-- tinymce -->


	// define a few variables that are required
	var vbmenu_usepopups = false;
	var ignorequotechars = 0;
	
	// #############################################################################
	// lets define the browser we have instead of multiple calls throughout the file
	var userAgent = navigator.userAgent.toLowerCase();
	var is_opera  = (userAgent.indexOf('opera') != -1);
	var is_saf    = ((userAgent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc."));
	var is_webtv  = (userAgent.indexOf('webtv') != -1);
	var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
	var is_ie4    = ((is_ie) && (userAgent.indexOf("msie 4.") != -1));
	var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
	var is_kon    = (userAgent.indexOf('konqueror') != -1);
	var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
	var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));
	
	// catch possible bugs with WebTV and other older browsers
	var is_regexp = (window.RegExp) ? true : false;
	
	// #############################################################################
	// let's find out what DOM functions we can use
	var vbDOMtype = '';
	if (document.getElementById)
	{
		vbDOMtype = "std";
	}
	else if (document.all)
	{
		vbDOMtype = "ie4";
	}
	else if (document.layers)
	{
		vbDOMtype = "ns4";
	}
	
	// make an array to store cached locations of objects called by fetch_object
	var vBobjects = new Array();
	
	// #############################################################################
	// function to emulate document.getElementById
	function fetch_object(idname, forcefetch)
	{
		if (forcefetch || typeof(vBobjects[idname]) == "undefined")
		{
			switch (vbDOMtype)
			{
				case "std":
				{
					vBobjects[idname] = document.getElementById(idname);
				}
				break;
	
				case "ie4":
				{
					vBobjects[idname] = document.all[idname];
				}
				break;
	
				case "ns4":
				{
					vBobjects[idname] = document.layers[idname];
				}
				break;
			}
		}
		return vBobjects[idname];
	}
	
	// #############################################################################
	// function to handle the different event models of different browsers
	// and prevent event bubbling
	function do_an_e(eventobj)
	{
		if (!eventobj || is_ie)
		{
			window.event.returnValue = false;
			window.event.cancelBubble = true;
			return window.event;
		}
		else
		{
			eventobj.stopPropagation();
			eventobj.preventDefault();
			return eventobj;
		}
	}


	// 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://";
	var is_v4 = false;
	if ((navigator.appVersion.indexOf("MSIE 4.") != "-1" && is_ie) || (parseInt(navigator.appVersion) == 4 && is_ns))
	{ // the v4 browsers dont support try / catch
		is_v4 = true;
	}
	
	// #############################################################################
	// function to change the appearence of a control element
	function format_control(elm, elmtype, controlstate)
	{
		return;
	}
	// #############################################################################
	// function to set 'unselectable' for an element and all its child nodes
	function set_unselectable(elm)
	{
		if (is_ie4)
		{
			return;
		}
		else if (typeof(elm.tagName) != "undefined")
		{
			if (elm.hasChildNodes())
			{
				for (var i = 0; i < elm.childNodes.length; i++)
				{
					set_unselectable(elm.childNodes[i]);
				}
			}
			elm.unselectable = true;
		}
	}
	
	// #############################################################################
	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
			{
				var 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";
	
				var bgstyle = fetch_mozilla_css_class(".wysiwyg");
				if (bgstyle != false)
				{
					// 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;
	}
	
	// array which holds the currently opened tags
	var tags = new Array();
	
	// currently selected text
	var text = "";
	
	// text which is to be added to the post
	var AddTxt = "";
	
	// form object that has to be used
	
	
	// #############################################################################
	// ############################ START FUNCTIONS ################################
	// #############################################################################
	
	// #############################################################################
	function editInit()
	{
		vbcode_init();
	}
	
	// #############################################################################
	// function to initialize the editor
	function vbcode_init()
	{
		if (editor_loaded)
		{
			// editor is already loaded, don't try to load it again, as that would be bad m'kay.
			return;
		}
	
		if (!is_ie4 && !is_ns4)
		{
			// make all toolbar elements unselectable
			set_unselectable(fetch_object("controlbar"));
			if (fetch_object("smiliebox"))
			{
				set_unselectable(fetch_object("smiliebox"));
			}
	
			// init buttons
			var divs = fetch_object("controlbar").getElementsByTagName("div");
			for (var i  = 0; i < divs.length; i++)
			{
				var elm = divs[i];
				switch (elm.className)
				{
					case "imagebutton":
					{
						elm.onmouseover = elm.onmouseout = elm.onmouseup = elm.onmousedown = button_eventhandler;
					}
					break;
				}
			}
		}
		
		
	}
	
	// #############################################################################
	// function to handle incoming events from buttons (part 1)
	function button_eventhandler(e, elm)
	{
		if (is_v4)
		{ //its ie4 and it doens't support try / catch or even changing style of a button
			//return false;
		}
	
		e = do_an_e(e);
	
		switch (e.type)
		{
			case "mousedown":
			{
				format_control(elm ? elm : this, "button", "down");
			}
			break;
	
			case "mouseover":
			case "mouseup":
			{
				format_control(elm ? elm : this, "button", "hover");
			}
			break;
	
			default:
			{
				format_control(elm ? elm : this, "button", "normal");
			}
		}
	}
	
	// #############################################################################
	// function used to check that the value in the array we're using is valid
	function thearrayisgood(thearray, i)
	{
		if (typeof(thearray[i]) == "undefined" || (thearray[i] == "") || (thearray[i] == null))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	
	// #############################################################################
	// emulation of PHP's sizeof function
	function sizeof(thearray)
	{
		for (var i = 0; i < thearray.length; i++)
		{
			if (!thearrayisgood(thearray, i))
			{
				return i;
			}
		}
		return thearray.length;
	}
	
	// #############################################################################
	// emulation of PHP's array_push function
	function array_push(thearray, value)
	{
		var thearraysize = sizeof(thearray);
		thearray[thearraysize] = value;
		return thearray[thearraysize];
	}
	
	// #############################################################################
	// emulation of PHP's array_pop function
	function array_pop(thearray)
	{
		var thearraysize = sizeof(thearray);
		var retval = thearray[thearraysize - 1];
		delete thearray[thearraysize - 1];
		return retval;
	}
	
	// #############################################################################
	function setmode(modevalue)
	{
		closeall(document.forms.rt_mod);
		if (modevalue == 1)
		{
			normalmode = false;
		}
		else
		{
			normalmode = true;
		}
		document.cookie = "vbcodemode=" + modevalue + "; path=/; expires=Wed, 1 Jan 2020 00:00:00 GMT;";
	}
	
	// #############################################################################
	function getActiveTextPageContent()
	{
		setfocusPageContent();
		if (!is_ie || (is_ie && !document.selection))
		{
			return false;
		}
	
		var sel = document.selection;
		var rng = sel.createRange();
		rng.colapse;
		if (rng != null && (sel.type == "Text" || sel.type == "None"))
		{
			text = rng.text;
		}
		if (document.forms.rt_mod.PageContent.createTextRange)
		{
			document.forms.rt_mod.PageContent.caretPos = rng.duplicate();
		}
		return true;
	}
	
	// #############################################################################
	function AddTextPageContent(NewCode)
	{
		if (typeof(document.forms.rt_mod.PageContent.createTextRange) != "undefined" && document.forms.rt_mod.PageContent.caretPos)
		{
			var caretPos = document.forms.rt_mod.PageContent.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
		}
		else
		{
			document.forms.rt_mod.PageContent.value += NewCode;
		}
		setfocusPageContent();
		getActiveTextPageContent();
		AddTxt = "";
	}
	
	// #############################################################################
	function setfocusPageContent()
	{
		document.forms.rt_mod.PageContent.focus();

	}
	
	// #############################################################################
	function vbcodePageContent(vbcode, prompttext, displayoption)
	{
		if (typeof document.forms.rt_mod != "object" && typeof must_click_message != "undefined")
		{ // QR check
			alert(must_click_message);
			return false;
		}
	
		var optioncompiled = "";
		if (displayoption)
		{
			optionvalue = prompt(construct_phrase(vbphrase["enter_option_x_tag"], vbcode), "");
			if (optionvalue != null)
			{
				optioncompiled = "=\"" + optionvalue + "\"";
			}
		}
	
		// lets call this when they try and use vbcode rather than on change
		getActiveTextPageContent();
	
		if (text)
		{ // its IE to the rescue
			if (text.substring(0, vbcode.length + 2 ) == "<" + vbcode + ">" && text.substring(text.length - vbcode.length - 3, text.length) == "</" + vbcode + ">")
			{
				AddTxt = text.substring(vbcode.length + 2, text.length - vbcode.length - 3);
			}
			else
			{
				AddTxt = "<" + vbcode + optioncompiled + ">" + text + "</" + vbcode + ">";
			}
			AddTextPageContent(AddTxt);
		}
		else if (document.forms.rt_mod.PageContent.selectionEnd && (document.forms.rt_mod.PageContent.selectionEnd - document.forms.rt_mod.PageContent.selectionStart > 0))
		{ // its mozilla and we'll need to re-write entire text
			var start_selection = document.forms.rt_mod.PageContent.selectionStart;
			var end_selection = document.forms.rt_mod.PageContent.selectionEnd;
			if (end_selection <= 2)
			{
				end_selection = document.forms.rt_mod.PageContent.textLength;
			}
	
			// fetch everything from start of text area to selection start
			var start = (document.forms.rt_mod.PageContent.value).substring(0, start_selection);
			// fetch everything from start of selection to end of selection
			var middle = (document.forms.rt_mod.PageContent.value).substring(start_selection, end_selection);
			// fetch everything from end of selection to end of text area
			var end = (document.forms.rt_mod.PageContent.value).substring(end_selection, document.forms.rt_mod.PageContent.textLength);
	
			if (middle.substring(0, vbcode.length + 2 ) == "<" + vbcode + ">" && middle.substring(middle.length - vbcode.length - 3, middle.length) == "</" + vbcode + ">")
			{
				middle = middle.substring(vbcode.length + 2, middle.length - vbcode.length - 3);
			}
			else
			{
				middle = "<" + vbcode + optioncompiled + ">" + middle + "</" + vbcode + ">";
			}
	
			document.forms.rt_mod.PageContent.value = start + middle + end;
		}
		else
		{
			if (!normalmode)
			{
				var donotinsert = false;
				var thetag = 0;
				for (var i = 0; i < tags.length; i++)
				{
					if (typeof(tags[i]) != "undefined" && tags[i] == vbcode)
					{
						donotinsert = true;
						thetag = i;
					}
				}
	
				if (!donotinsert)
				{
					array_push(tags, vbcode);
					AddTxt = "<" + vbcode + optioncompiled + ">";
					AddTextPageContent(AddTxt);
				}
				else
				{ // its already open
					var closedtag = "";
					while (typeof(tags[thetag]) != "undefined")
					{
						closedtag = array_pop(tags);
						AddTxt = "</" + closedtag + ">";
						AddTextPageContent(AddTxt);
					}
				}
			}
			else
			{
				var inserttext = prompt(vbphrase["enter_text_to_be_formatted"] + "\n<" + vbcode + ">xxx</" + vbcode + ">", prompttext);
				if ((inserttext != null) && (inserttext != ""))
				{
					AddTxt = "<" + vbcode + optioncompiled + ">" + inserttext + "</" + vbcode + "> ";
				}
				AddTextPageContent(AddTxt);
			}
		}
		setfocusPageContent();
		return false;
	}
	
	// #############################################################################
	function alignPageContent(vbcode, prompttext, displayoption)
	{
		if (typeof document.forms.rt_mod != "object" && typeof must_click_message != "undefined")
		{ // QR check
			alert(must_click_message);
			return false;
		}
	
		var optioncompiled = "";
		if (displayoption)
		{
			optionvalue = prompt(construct_phrase(vbphrase["enter_option_x_tag"], vbcode), "");
			if (optionvalue != null)
			{
				optioncompiled = "=\"" + optionvalue + "\"";
			}
		}
	
		// lets call this when they try and use vbcode rather than on change
		getActiveTextPageContent();
	
		if (text)
		{ // its IE to the rescue
			if (text.substring(0, vbcode.length + 2 ) == "<" + vbcode + ">" && text.substring(text.length - vbcode.length - 3, text.length) == "</" + vbcode + ">")
			{
				AddTxt = text.substring(vbcode.length + 2, text.length - vbcode.length - 3);
			}
			else
			{
				AddTxt = "<div align=\"" + vbcode + optioncompiled + "\">" + text + "</div>";
			}
			AddTextPageContent(AddTxt);
		}
		else if (document.forms.rt_mod.PageContent.selectionEnd && (document.forms.rt_mod.PageContent.selectionEnd - document.forms.rt_mod.PageContent.selectionStart > 0))
		{ // its mozilla and we'll need to re-write entire text
			var start_selection = document.forms.rt_mod.PageContent.selectionStart;
			var end_selection = document.forms.rt_mod.PageContent.selectionEnd;
			if (end_selection <= 2)
			{
				end_selection = document.forms.rt_mod.PageContent.textLength;
			}
	
			// fetch everything from start of text area to selection start
			var start = (document.forms.rt_mod.PageContent.value).substring(0, start_selection);
			// fetch everything from start of selection to end of selection
			var middle = (document.forms.rt_mod.PageContent.value).substring(start_selection, end_selection);
			// fetch everything from end of selection to end of text area
			var end = (document.forms.rt_mod.PageContent.value).substring(end_selection, document.forms.rt_mod.PageContent.textLength);
	
			if (middle.substring(0, vbcode.length + 2 ) == "<" + vbcode + ">" && middle.substring(middle.length - vbcode.length - 3, middle.length) == "</" + vbcode + ">")
			{
				middle = middle.substring(vbcode.length + 2, middle.length - vbcode.length - 3);
			}
			else
			{
				middle = "<" + vbcode + optioncompiled + ">" + middle + "</" + vbcode + ">";
			}
	
			document.forms.rt_mod.PageContent.value = start + middle + end;
		}
		else
		{
			if (!normalmode)
			{
				var donotinsert = false;
				var thetag = 0;
				for (var i = 0; i < tags.length; i++)
				{
					if (typeof(tags[i]) != "undefined" && tags[i] == vbcode)
					{
						donotinsert = true;
						thetag = i;
					}
				}
	
				if (!donotinsert)
				{
					array_push(tags, vbcode);
					AddTxt = "<" + vbcode + optioncompiled + ">";
					AddTextPageContent(AddTxt);
				}
				else
				{ // its already open
					var closedtag = "";
					while (typeof(tags[thetag]) != "undefined")
					{
						closedtag = array_pop(tags);
						AddTxt = "</" + closedtag + ">";
						AddTextPageContent(AddTxt);
					}
				}
			}
			else
			{
				var inserttext = prompt(vbphrase["enter_text_to_be_formatted"] + "\n<" + vbcode + ">xxx</" + vbcode + ">", prompttext);
				if ((inserttext != null) && (inserttext != ""))
				{
					AddTxt = "<div align=\"" + vbcode + optioncompiled + "\">" + inserttext + "</div>";
				}
				AddTextPageContent(AddTxt);
			}
		}
		setfocusPageContent();
		return false;
	}	
	
	// #############################################################################
	
	function imagecodePageContent(vbcode, prompttext, displayoption)
	{
		if (typeof document.forms.rt_mod != "object" && typeof must_click_message != "undefined")
		{ // QR check
			alert(must_click_message);
			return false;
		}
	
		var optioncompiled = "";
		if (displayoption)
		{
			optionvalue = prompt(construct_phrase(vbphrase["enter_option_x_tag"], vbcode), "");
			if (optionvalue != null)
			{
				optioncompiled = "=\"" + optionvalue + "\"";
			}
		}
	
		// lets call this when they try and use vbcode rather than on change
		getActiveTextPageContent();
	
		if (text)
		{ // its IE to the rescue
			if (text.substring(0, vbcode.length + 2 ) == "<" + vbcode + ">" && text.substring(text.length - vbcode.length - 3, text.length) == "</" + vbcode + ">")
			{
				AddTxt = text.substring(vbcode.length + 2, text.length - vbcode.length - 3);
			}
			else
			{
				AddTxt = "<" + vbcode + optioncompiled + " src=\"" + text + "\" border=\"0\"> ";
			}
			AddTextPageContent(AddTxt);
		}
		else if (document.forms.rt_mod.PageContent.selectionEnd && (document.forms.rt_mod.PageContent.selectionEnd - document.forms.rt_mod.PageContent.selectionStart > 0))
		{ // its mozilla and we'll need to re-write entire text
			var start_selection = document.forms.rt_mod.PageContent.selectionStart;
			var end_selection = document.forms.rt_mod.PageContent.selectionEnd;
			if (end_selection <= 2)
			{
				end_selection = document.forms.rt_mod.PageContent.textLength;
			}
	
			// fetch everything from start of text area to selection start
			var start = (document.forms.rt_mod.PageContent.value).substring(0, start_selection);
			// fetch everything from start of selection to end of selection
			var middle = (document.forms.rt_mod.PageContent.value).substring(start_selection, end_selection);
			// fetch everything from end of selection to end of text area
			var end = (document.forms.rt_mod.PageContent.value).substring(end_selection, document.forms.rt_mod.PageContent.textLength);
	
			if (middle.substring(0, vbcode.length + 2 ) == "<" + vbcode + ">" && middle.substring(middle.length - vbcode.length - 3, middle.length) == "</" + vbcode + ">")
			{
				middle = middle.substring(vbcode.length + 2, middle.length - vbcode.length - 3);
			}
			else
			{
				middle = "<" + vbcode + optioncompiled + " src=\"" + middle + "\" border=\"0\"> ";
			}
	
			document.forms.rt_mod.PageContent.value = start + middle + end;
		}
		else
		{
			if (!normalmode)
			{
				var donotinsert = false;
				var thetag = 0;
				for (var i = 0; i < tags.length; i++)
				{
					if (typeof(tags[i]) != "undefined" && tags[i] == vbcode)
					{
						donotinsert = true;
						thetag = i;
					}
				}
	
				if (!donotinsert)
				{
					array_push(tags, vbcode);
					AddTxt = "<" + vbcode + optioncompiled + ">";
					AddTextPageContent(AddTxt);
				}
				else
				{ // its already open
					var closedtag = "";
					while (typeof(tags[thetag]) != "undefined")
					{
						closedtag = array_pop(tags);
						AddTxt = "</" + closedtag + ">";
						AddTextPageContent(AddTxt);
					}
				}
			}
			else
			{
				var inserttext = prompt(vbphrase["enter_text_to_be_formatted"] + "\n<" + vbcode + ">xxx</" + vbcode + ">", prompttext);
				if ((inserttext != null) && (inserttext != ""))
				{
					AddTxt = "<" + vbcode + optioncompiled + " src=\"" + inserttext + "\" border=\"0\"> ";
				}
				AddTextPageContent(AddTxt);
			}
		}
		setfocusPageContent();
		return false;
	}
	
	// #############################################################################
	function closetag()
	{
		getActiveTextPageContent();
		if (!normalmode)
		{
			if (typeof(tags[0]) != "undefined")
			{
				var Tag = array_pop(tags)
				AddTxt = "</"+ Tag +">";
				AddTextPageContent(AddTxt);
			}
		}
		setfocusPageContent();
	}
	
	// #############################################################################
	function closeall()
	{
		getActiveTextPageContent();
		if (!normalmode)
		{
			var g = sizeof(tags);
			if (thearrayisgood(tags, g-1))
			{
				var Addtxt = "";
				var newtag = "";
				for (var h = 0; h < g; h++)
				{
					newtag = array_pop(tags);
					Addtxt += "</" + newtag + ">";
				}
				AddTextPageContent(Addtxt);
			}
		}
		setfocusPageContent();
	}
	
	// #############################################################################
	function namedlinkPageContent(thetype)
	{
		var extraspace = "";
	
		getActiveTextPageContent();
		var dtext = "";
		if (text)
		{
			dtext = text;
		}
		else
		{
			extraspace = " ";
		}
		linktext = prompt(vbphrase["enter_link_text"], dtext);
		var prompttext, prompt_contents;
		if (thetype == "URL")
		{
			prompt_text = vbphrase["enter_link_url"];
			prompt_contents = "http://";
		}
		else
		{
			prompt_text = vbphrase["enter_email_link"];
			prompt_contents = "";
		}
		var linkurl = prompt(prompt_text, prompt_contents);
		if ((linkurl != null) && (linkurl != ""))
		{
			if ((linktext != null) && (linktext != ""))
			{
				AddTxt = "[" + thetype + "=" + linkurl + "]" + linktext + "[/" + thetype + "]" + extraspace;
				AddTextPageContent(AddTxt);
			}
			else
			{
				AddTxt = "[" + thetype + "]" + linkurl + "[/" + thetype + "]" + extraspace;
				AddTextPageContent(AddTxt);
			}
		}
	}
	
	// #############################################################################
	function urllinkPageContent(thetype)
	{
		var extraspace = "";
	
		getActiveTextPageContent();
		var dtext = "";
		if (text)
		{
			dtext = text;
		}
		else
		{
			extraspace = " ";
		}
		linktext = prompt(vbphrase["enter_link_text"], dtext);
		var prompttext, prompt_contents;
		if (thetype == "URL")
		{
			prompt_text = vbphrase["enter_link_url"];
			prompt_contents = "http://";
		}
		else
		{
			prompt_text = vbphrase["enter_email_link"];
			prompt_contents = "";
		}
		var linkurl = prompt(prompt_text, prompt_contents);
		if ((linkurl != null) && (linkurl != ""))
		{
			if ((linktext != null) && (linktext != ""))
			{
				AddTxt = "<a href=\"" + linkurl + "\">" + linktext + "</a>" + extraspace;
				AddTextPageContent(AddTxt);
			}
			else
			{
				AddTxt = "<a href=\"" + linkurl + "\">" + linkurl + "</a>" + extraspace;
				AddTextPageContent(AddTxt);
			}
		}
	}
	
	// #############################################################################
	function emaillinkPageContent(thetype)
	{
		var extraspace = "";
	
		getActiveTextPageContent();
		var dtext = "";
		if (text)
		{
			dtext = text;
		}
		else
		{
			extraspace = " ";
		}
		linktext = prompt(vbphrase["enter_link_text"], dtext);
		var prompttext, prompt_contents;
		if (thetype == "URL")
		{
			prompt_text = vbphrase["enter_link_url"];
			prompt_contents = "http://";
		}
		else
		{
			prompt_text = vbphrase["enter_email_link"];
			prompt_contents = "";
		}
		var linkurl = prompt(prompt_text, prompt_contents);
		if ((linkurl != null) && (linkurl != ""))
		{
			if ((linktext != null) && (linktext != ""))
			{
				AddTxt = "<a href=\"mailto:" + linkurl + "\">" + linktext + "</a>" + extraspace;
				AddTextPageContent(AddTxt);
			}
			else
			{
				AddTxt = "<a href=\"mailto:" + linkurl + "\">" + linkurl + "</a>" + extraspace;
				AddTextPageContent(AddTxt);
			}
		}
	}
	
	// #############################################################################
	function dolistPageContent()
	{
		var listtype = prompt(vbphrase["enter_list_type"], "");
	
		if ((listtype == "a"))
		{
			thelist = "<ul>\n";
			listformat = 'ul';
		}
		else if ((listtype == "1"))
		{
			thelist = "<ol>\n";
			listformat = 'ol';
		}
		else
		{
			thelist = "<ul>\n";
			listformat = 'ul';
		}
		var listentry = "initial";
		while ((listentry != "") && (listentry != null))
		{
			listentry = prompt(vbphrase["enter_list_item"], "");
			if ((listentry != "") && (listentry != null))
			{
				thelist = thelist + "<li>" + listentry + "</li>\n";
			}
		}
		AddTxt = thelist + "<" + listformat + ">\n";
		if (!text)
		{
			AddTxt = AddTxt + " ";
		}
		AddTextPageContent(AddTxt);
	}
	
	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_normal" : [ "#ECE9D8", "#000000", "1px", "none" ], "pi_button_selected" : [ "#E1E6E8", "#000000", "0px", "1px solid #316AC5" ], "pi_menu_normal" : [ "#FFFFFF", "#000000", "0px", "1px solid #FFFFFF" ], "pi_button_down" : [ "#787878", "#000000", "0px", "solid 1px #316AC5" ], "pi_button_hover" : [ "#ACACAC", "#000000", "0px", "solid 1px #316AC5" ], "pi_menu_down" : [ "#ACACAC", "#787878", "0px", "1px solid #316AC5" ], "pi_menu_hover" : [ "#ACACAC", "#787878", "0px", "1px solid #316AC5" ], "pi_popup_down" : [ "#787878", "#000000", "0px", "1px solid #316AC5" ] };
	var normalmode = true;
	var smiliewindow_x = 240;
	var smiliewindow_y = 280;
	var ignorequotechars = 1;
	var vbphrase = {
		
	// standard only
	"enter_option_x_tag" : "Enter the option for the [%1$s] tag:",
	"enter_text_to_be_formatted" : "Enter the text to be formatted",
	"enter_link_text" : "Enter the text to be displayed for the link (optional):",
	"enter_list_type" : "What type of list do you want? Enter '1' for a numbered list, enter 'a' for an alphabetical list, or leave blank for a list with bullet points:",
	"enter_list_item" : "Enter a list item.\nLeave the box empty or press 'Cancel' to complete the list:",
	
	// 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:"
	};
