  var Fonts = new Array();
	Fonts[0] = "Arial";
	Fonts[1] = "Sans Serif";
	Fonts[2] = "Tahoma";
	Fonts[3] = "Verdana";
	Fonts[4] = "Courier New";
	Fonts[5] = "Georgia";
	Fonts[6] = "Times New Roman";
	Fonts[7] = "Impact";
	Fonts[8] = "Comic Sans MS";

// List of available block formats (not in use)
var BlockFormats = new Array();
	BlockFormats[0]  = "Address";
	BlockFormats[1]  = "Bulleted List";
	BlockFormats[2]  = "Definition";
	BlockFormats[3]  = "Definition Term";
	BlockFormats[4]  = "Directory List";
	BlockFormats[5]  = "Formatted";
	BlockFormats[6]  = "Heading 1";
	BlockFormats[7]  = "Heading 2";
	BlockFormats[8]  = "Heading 3";
	BlockFormats[9]  = "Heading 4";
	BlockFormats[10] = "Heading 5";
	BlockFormats[11] = "Heading 6";
	BlockFormats[12] = "Menu List";
	BlockFormats[13] = "Normal";
	BlockFormats[14] = "Numbered List";

// List of available font sizes
var FontSizes = new Array();
	FontSizes[0]  = "1";
	FontSizes[1]  = "2";
	FontSizes[2]  = "3";
	FontSizes[3]  = "4";
	FontSizes[4]  = "5";
	FontSizes[5]  = "6";
	FontSizes[6]  = "7";

/* ---------------------------------------------------------------------- *\
  Function    : insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()
  Description : Emulates insertAdjacentHTML(), insertAdjacentText() and 
	              insertAdjacentElement() three functions so they work with 
								Netscape 6/Mozilla
  Notes       : by Thor Larholm me@jscript.dk
\* ---------------------------------------------------------------------- */
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
  HTMLElement.prototype.insertAdjacentElement = function
  (where,parsedNode)
	{
	  switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) 
      this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function
  (where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function
  (where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
};




// Create viewTextMode global variable and set to 0
// enabling all toolbar commands while in HTML mode
viewTextMode = 0;

function viewSource(n) {

  var getDocument = document.getElementById("wysiwyg" + n).contentWindow.document;
  var browserName = navigator.appName;
	
	// View Source for IE 	 
  if (browserName == "Microsoft Internet Explorer") {
    var iHTML = getDocument.body.innerHTML;
    getDocument.body.innerText = iHTML;
	}
 
  // View Source for Mozilla/Netscape
  else {
    var html = document.createTextNode(getDocument.body.innerHTML);
    getDocument.body.innerHTML = "";
    getDocument.body.appendChild(html);
	}
  
	// Hide the HTML Mode button and show the Text Mode button
    document.getElementById('HTMLMode' + n).style.display = 'none'; 
	document.getElementById('textMode' + n).style.display = 'inline';
	
	// set the font values for displaying HTML source
	getDocument.body.style.fontSize = "12px";
	getDocument.body.style.fontFamily = "Courier New"; 
	
  viewTextMode = 1;
};



/* ---------------------------------------------------------------------- *\
  Function    : viewSource()
  Description : Shows the HTML source code generated by the WYSIWYG editor
  Usage       : showFonts(n)
  Arguments   : n   - The editor identifier (the textarea's ID)
\* ---------------------------------------------------------------------- */
function viewText(n) { 
  var getDocument = document.getElementById("wysiwyg" + n).contentWindow.document;
  var browserName = navigator.appName;
	
	// View Text for IE 	  	 
  if (browserName == "Microsoft Internet Explorer") {
    var iText = getDocument.body.innerText;
    getDocument.body.innerHTML = iText;
	}
  
	// View Text for Mozilla/Netscape
  else {
    var html = getDocument.body.ownerDocument.createRange();
    html.selectNodeContents(getDocument.body);
    getDocument.body.innerHTML = html.toString();
	}
  
	// Hide the Text Mode button and show the HTML Mode button
  document.getElementById('textMode' + n).style.display = 'none'; 
	document.getElementById('HTMLMode' + n).style.display = 'inline';
	
	// reset the font values
  getDocument.body.style.fontSize = "";
	getDocument.body.style.fontFamily = ""; 
	viewTextMode = 0;
};


function processcontent() {

	var myBody = document.getElementsByTagName("body")[0];

	for (i=0; i<myBody.getElementsByTagName("textarea").length; i++){
		
		if (myBody.getElementsByTagName("textarea")[i].id.indexOf("rftextarea") == 0) {
				
			var ii = myBody.getElementsByTagName("textarea")[i].id.replace("rftextarea","");
			var n = "rftextarea" + ii;
			var content = document.getElementById(n).value;	
			var doc = document.getElementById("wysiwyg" + ii).contentWindow.document; 


			// Write the textarea's content into the iframe 
			doc.open(); 
			doc.write("working..."); 
			doc.body.contentEditable = true; 
			doc.designMode = "on"; 
			doc.write("<link rel='stylesheet' type='text/css' href='/rfSystem/rfCSS/rfPlatformBeeEditor.css'>" + content.replace(/<rfscript/g, "<script").replace(/LATEROBJECT/g, "OBJECT").replace(/rfsrc=/g, "src=").replace(/LATERTEXTAREA/g, "TEXTAREA")); 
			
		//	doc.styleSheets[0].href = "/rfsystem/rfcss/rfplatformbee.css";
			doc.close(); 
		}
	}
}




function updateTextArea(n) {

  if (viewTextMode==1) {
	viewText(n);
  }
  document.getElementById("rftextarea" + n).value = document.getElementById("wysiwyg" + n).contentWindow.document.body.innerHTML;
};

function show_out(src) {
	if(src.type=="button" || src.type=="image") {
		window.status="";
		src.className="flat";
	}
}

function show_over(src) {
	
	if(src.type=="button" || src.type=="image") {
		window.status="";
		src.className="outset";
	}
}

function show_down(src) {
	if(src.type=="button" || src.type=="image") {
		src.className="inset";
	}
}

function show_up(src) {
	if(src.type=="button" || src.type=="image") {
		src.className="outset";
	}
}

var qsParm = new Array();


/* ---------------------------------------------------------------------- *\
  Function    : retrieveWYSIWYG()
  Description : Retrieves the textarea ID for which the image will be inserted into.
\* ---------------------------------------------------------------------- */
function retrieveWYSIWYG() {

  var query = window.location.search.substring(1);
  var parms = query.split('&');
  for (var i=0; i<parms.length; i++) {
    var pos = parms[i].indexOf('=');
    if (pos > 0) {
       var key = parms[i].substring(0,pos);
       var val = parms[i].substring(pos+1);
       qsParm[key] = val;
    }
  }
}

function InsertWebbug() {
	// Get details of selected text
	var content = window.opener.document.getElementById('wysiwyg' + qsParm['wysiwyg']).contentWindow.document.selection.createRange();

	// create details of fields to insert
	var storedDetails = "[WEBBUG]<IMG width=1 height=1 src='/login/management/webping.asp' alt=''>[/WEBBUG]";
	
	// insert the content
	window.opener.insertHTML(content.text + storedDetails, qsParm['wysiwyg']);

	// Close popup window
	window.close();
}


function InsertButton() {
	// Get details of selected text
	var content = window.opener.document.getElementById('wysiwyg' + qsParm['wysiwyg']).contentWindow.document.selection.createRange();

	// create details of fields to insert
	var storedDetails = "<a href='/rfSystem/rfButtons/rfButtons.asp?sessionid=rfsessionid&action=gobutton&buttonid=" + document.all.insertButton.buttonid.value;
	storedDetails += "&dodiag=" + document.all.insertButton.diag.value + "'"
	
	if (document.all.insertButton.fieldclass.value != "") {
		storedDetails += " class='" + document.all.insertButton.fieldclass.value + "'";
		}
	
	if (document.all.insertButton.fieldtarget.value != "") {
		storedDetails += " target='" + document.all.insertButton.fieldtarget.value + "'";
		}
		
	// replace text in document
	window.opener.insertHTML(storedDetails + ">" + content.text + "</a>", qsParm['wysiwyg']);
 
	// Close popup window
	window.close();
}

function InsertDataCapture() {
	// Get details of selected text
	var content = window.opener.document.getElementById('wysiwyg' + qsParm['wysiwyg']).contentWindow.document.selection.createRange();

	// create details of fields to insert
	var storedDetails = "[DC." + document.all.insertDataCapture.datacaptureid.value + ".";
	storedDetails += document.all.insertDataCapture.Diag.value + "." + document.all.insertDataCapture.Param1.value + ".";
	storedDetails += document.all.insertDataCapture.Param2.value + "." + document.all.insertDataCapture.Param3.value + ".";
	storedDetails += document.all.insertDataCapture.Param4.value + "]";

	// replace text in document
	window.opener.insertHTML(storedDetails + content.text + "[/DC]", qsParm['wysiwyg']);
 
	// Close popup window
	window.close();
}


function InsertReport() {
	// Get details of selected text
	var content = window.opener.document.getElementById('wysiwyg' + qsParm['wysiwyg']).contentWindow.document.selection.createRange();

	// create details of fields to insert
	var storedDetails = "[REPORT." + document.all.insertReport.datasetid.value + "." + document.all.insertReport.templateid.value + ".";
	storedDetails += document.all.insertReport.Diag.value + "." + document.all.insertReport.output.value + "." + document.all.insertReport.Param1.value + ".";
	storedDetails += document.all.insertReport.Param2.value + "." + document.all.insertReport.Param3.value + ".";
	storedDetails += document.all.insertReport.Param4.value + "]";

	// replace text in document
	window.opener.insertHTML(storedDetails + content.text + "[/REPORT]", qsParm['wysiwyg']);
 
	// Close popup window
	window.close();
}

function InsertEmbedded() {
	// Get details of selected text
	var content = window.opener.document.getElementById('wysiwyg' + qsParm['wysiwyg']).contentWindow.document.selection.createRange();

	// create details of fields to insert
	var storedDetails = "<iframe frameborder=0 width='" + document.all.insertEmbedded.Width.value + "' height='" + document.all.insertEmbedded.Height.value + "' ";
	storedDetails += "class='" + document.all.insertEmbedded.Class.value + "' name='" + document.all.insertEmbedded.Name.value + "' ";
	storedDetails += "ID='" + document.all.insertEmbedded.ID.value + "' Scrolling='" + document.all.insertEmbedded.Scrolling.value + "' ";

	if (document.all.insertEmbedded.webpageid.value != "0") {
		storedDetails += "src='/rfsystem/index.aspx?pageid=" + document.all.insertEmbedded.webpageid.value + "'";
	}
	else
	{
		storedDetails += "src='/rfSystem/blank.htm'";
	}

	// replace text in document
	window.opener.insertHTML(content.text + storedDetails + ">iFrames are not supported. Please adjust your browser settings.</iframe>", qsParm['wysiwyg']);
 
	// Close popup window
	window.close();
}

function InsertCondition() {
	// Get details of selected text
	var content = window.opener.document.getElementById('wysiwyg' + qsParm['wysiwyg']).contentWindow.document.selection.createRange();

	// create details of fields to insert

	if (document.all.insertField.outtype.value == "IF") {
		var storedDetails = "[" + document.all.insertField.outtype.value + ".";
			storedDetails += document.all.insertField.dsn.value + ".";
		
		if (document.all.insertField.dsn.value == 'none') {
			storedDetails += ".";
		}
			
			storedDetails += document.all.insertField.field.value + ".";
			storedDetails += document.all.insertField.operator.value + "." + document.all.insertField.testvalue.value + ".";
			storedDetails += document.all.insertField.pkfield.value + "." + document.all.insertField.pkfieldvalue.value + "]";
	}
	else {
		var storedDetails = "[" + document.all.insertField.outtype.value + "]";
	}
	
	// replace text in document
	window.opener.insertHTML(storedDetails + content.text, qsParm['wysiwyg']);
 
	// Close popup window
	window.close();
}

function InsertText() {
	// Get details of selected text
	var content = window.opener.document.getElementById('wysiwyg' + qsParm['wysiwyg']).contentWindow.document.selection.createRange();

	// create details of fields to insert
	var storedDetails = document.all.insertField.dsn.value + "." + document.all.insertField.field.value + "." + document.all.insertField.pkfield.value + ".";
	storedDetails += document.all.insertField.pkfieldvalue.value;
	
	// replace text in document
	window.opener.insertHTML("[INSERT." + storedDetails + "]" + content.text + "[/INSERT]", qsParm['wysiwyg']);
 
	// Close popup window
	window.close();
}


function InsertTag() {
	// Get details of selected text
	var content = window.opener.document.getElementById('wysiwyg' + qsParm['wysiwyg']).contentWindow.document.selection.createRange();

	// create details of fields to insert
	var storedDetails = "[" + document.all.insertTag.tagtype.value + ".";
	storedDetails += document.all.insertTag.profilename.value + ".";
	storedDetails += document.all.insertTag.fieldname.value + ".";
	storedDetails += document.all.insertTag.nohtml.value + ".";
	storedDetails += document.all.insertTag.rating.value + "]";
	
	// replace text in document
	window.opener.insertHTML("[TAG]" + storedDetails + content.text + "[/TAG]", qsParm['wysiwyg']);
 
	// Close popup window
	window.close();
}

function InsertEndTag() {
	// Get details of selected text
	var content = window.opener.document.getElementById('wysiwyg' + qsParm['wysiwyg']).contentWindow.document.selection.createRange();
	
	// replace text in document
	window.opener.insertHTML("[END_TAG]" + content.text, qsParm['wysiwyg']);
 
	// Close popup window
	window.close();
}

function getSelected(opt) {
    var selected = new Array();
    var index = 0;
    for (var intLoop = 0; intLoop < opt.length; intLoop++) {
        if ((opt[intLoop].selected) ||
           (opt[intLoop].checked)) {
           index = selected.length;
           selected[index] = new Object;
           selected[index].value = opt[intLoop].value;
           selected[index].index = intLoop;
        }
    }
    return selected;
}

function applyFont(n) {

	formatText('FontName',n,document.getElementById('fontselect' + n).value); 
	document.getElementById('fontselect' + n).selectedIndex=0;
}

function applyFontSize(n) {

	formatText('FontSize',n,document.getElementById('fontsize' + n).value); 
	document.getElementById('fontsize' + n).selectedIndex=0;

}

function InsertDiv() {
	// Get details of selected text
	var content = window.opener.document.getElementById('wysiwyg' + qsParm['wysiwyg']).contentWindow.document.selection.createRange();

	// get src of iframe
	var storedDetails = "<div name='" + document.all.insertDiv.Name.value + "' ID='" + document.all.insertDiv.ID.value + "' ";
	storedDetails += "style='width:" + document.all.insertDiv.DivWidth.value + "; height:" + document.all.insertDiv.DivHeight.value + "; ";
	
	if (document.all.insertDiv.scrollbarx.value != 'none') {
		storedDetails += "overflow-x:" + document.all.insertDiv.scrollbarx.value + "; ";
	}
	if (document.all.insertDiv.scrollbary.value != 'none') {
		storedDetails += "overflow-y:" + document.all.insertDiv.scrollbary.value + "; ";
	}

	storedDetails += "' class='" + document.all.insertDiv.Class.value + "'>";

	// replace text in document
	window.opener.insertHTML(storedDetails + content.text + "</div>", qsParm['wysiwyg']);
 
	// Close popup window
	window.close();
}

function InsertParagraph() {

	// Get details of selected text
	var content = window.opener.document.getElementById('wysiwyg' + qsParm['wysiwyg']).contentWindow.document.selection.createRange();

	// replace text in document
	window.opener.insertHTML("<p class='" + document.all.insertPara.thisclass.value + "'>" + content.text + "</p>", qsParm['wysiwyg']);
 
	// Close popup window
	window.close();
}

function InsertImage(thisFile) {


	// Get details of selected text
	var content = parent.opener.document.getElementById('wysiwyg' + qsParm['wysiwyg']).contentWindow.document.selection.createRange();

	// replace text in document
	parent.opener.insertHTML("<img src='" + thisFile + "' border=0 align=absmiddle>" + content.text, qsParm['wysiwyg']);
 
	// Close popup window
	parent.close();
}

function NoParagraph() {

	// Get details of selected text
	var content = window.opener.document.getElementById('wysiwyg' + qsParm['wysiwyg']).contentWindow.document.selection.createRange();

	// replace text in document
	window.opener.insertHTML(content.text, qsParm['wysiwyg']);
 
	// Close popup window
	window.close();
}

function rfcustom_Insert_Image(i) {

 	popup = window.open("/rfSystem/rfEditor/includes/insertImage.asp?wysiwyg=" + i, "popup", "width=400,height=300,toolbar=0,status=0");
	popup.focus();
}

function rfcustom_Paragraph(i) {

 	popup = window.open("/rfSystem/rfEditor/includes/insertParagraph.asp?wysiwyg=" + i, "popup", "width=400,height=240,toolbar=0,status=0");
	popup.focus();
}

function rfcustom_Insert_Database_Field(i) {

 	popup = window.open("/rfSystem/rfEditor/includes/insertField.asp?wysiwyg=" + i, "popup", "width=400,height=200,toolbar=0,status=0");
	popup.focus();
}

function rfcustom_Insert_Aimlet(i) {

 	popup = window.open("/rfSystem/rfEditor/includes/insertAimlet.asp?wysiwyg=" + i, "popup", "width=400,height=380,toolbar=0,status=0");
	popup.focus();
}

function rfcustom_Insert_Div(i) {

 	popup = window.open("/rfSystem/rfEditor/includes/insertDiv.asp?wysiwyg=" + i, "popup", "width=400,height=270,toolbar=0,status=0");
	popup.focus();
}

function rfcustom_If_Then_Else(i) {

 	popup = window.open("/rfSystem/rfEditor/includes/insertConditional.asp?wysiwyg=" + i, "popup", "width=400,height=270,toolbar=0,status=0,scrollbars=0");
	popup.focus();
}

function rfcustom_Insert_Embedded_Page(i) {

 	popup = window.open("/rfSystem/rfEditor/includes/insertEmbedded.asp?wysiwyg=" + i, "popup", "width=400,height=300,toolbar=0,status=0,scrollbars=1");
	popup.focus();
}

function rfcustom_Insert_Data_Capture(i) {

 	popup = window.open("/rfSystem/rfEditor/includes/insertDataCapture.asp?wysiwyg=" + i, "popup", "width=400,height=300,toolbar=0,status=0,scrollbars=1");
	popup.focus();
}

function rfcustom_Insert_Report(i) {

 	popup = window.open("/rfSystem/rfEditor/includes/insertReport.asp?wysiwyg=" + i, "popup", "width=400,height=300,toolbar=0,status=0,scrollbars=1");
	popup.focus();
}

function rfcustom_Insert_Button(i) {

 	popup = window.open("/rfSystem/rfEditor/includes/insertButton.asp?wysiwyg=" + i, "popup", "width=400,height=180,toolbar=0,status=0,scrollbars=0");
	popup.focus();
}

function rfcustom_Insert_Webbug(i) {

 	popup = window.open("/rfSystem/rfEditor/includes/insertWebbug.asp?wysiwyg=" + i, "popup", "width=50,height=50,toolbar=0,status=0,scrollbars=0");
	popup.focus();
}

function rfcustom_Table(i) {

 	popup = window.open("/rfSystem/rfEditor/includes/insertTable.asp?wysiwyg=" + i, "popup", "width=450,height=350,toolbar=0,status=0,scrollbars=0");
	popup.focus();
}

function rfcustom_Hyperlink(i) {

 	popup = window.open("/rfSystem/rfEditor/includes/hyperlink.asp?wysiwyg=" + i, "popup", "width=450,height=200,toolbar=0,status=0,scrollbars=0");
	popup.focus();
}

function rfcustom_Forecolour(i) {

      var w = screen.availWidth;
      var h = screen.availHeight;
      var popW = 210, popH = 165;
      var leftPos = (w-popW)/2, topPos = (h-popH)/2;
      var currentColor = _dec_to_rgb(document.getElementById("wysiwyg" + i).contentWindow.document.queryCommandValue("forecolor"));
   
	    window.open('/rfSystem/rfEditor/includes/insertcolour.asp?color=' + currentColor + '&command=forecolor&wysiwyg=' + i,'popup','location=0,status=0,scrollbars=0,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}

function rfcustom_Backcolour(i) {

      var w = screen.availWidth;
      var h = screen.availHeight;
      var popW = 210, popH = 165;
      var leftPos = (w-popW)/2, topPos = (h-popH)/2;
      var currentColor = _dec_to_rgb(document.getElementById("wysiwyg" + i).contentWindow.document.queryCommandValue("backcolor"));
   
	    window.open('/rfSystem/rfEditor/includes/insertcolour.asp?color=' + currentColor + '&command=backcolor&wysiwyg=' + i,'popup','location=0,status=0,scrollbars=0,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}

function _dec_to_rgb(value) {
  var hex_string = "";
  for (var hexpair = 0; hexpair < 3; hexpair++) {
    var myByte = value & 0xFF;            // get low byte
    value >>= 8;                          // drop low byte
    var nybble2 = myByte & 0x0F;          // get low nybble (4 bits)
    var nybble1 = (myByte >> 4) & 0x0F;   // get high nybble
    hex_string += nybble1.toString(16);   // convert nybble to hex
    hex_string += nybble2.toString(16);   // convert nybble to hex
  }
  return hex_string.toUpperCase();
};

/* ---------------------------------------------------------------------- *\
  Function    : outputFontSelect()
  Description : creates the Font Select drop down and inserts it into 
	              the toolbar
  Usage       : outputFontSelect(n)
  Arguments   : n   - The editor identifier that the Font Select will update
	                    when making font changes (the textarea's ID)
\* ---------------------------------------------------------------------- */
function outputFontSelect(n) {

  	var FontSelect = '/rfSystem/rfEditor/includes/images/custom/select_font.gif';
  	var FontSelectOn = '/rfSystem/rfEditor/includes/images/custom/select_font_on.gif';
  	
	Fonts.sort();
	var FontSelectDropDown = new Array;
	FontSelectDropDown[n] = '<table align=left border="0" cellpadding="0" cellspacing="0">';
	FontSelectDropDown[n] += '<tr><td onMouseOver="document.getElementById(\'selectFont' + n + '\').src=\'' + FontSelectOn + '\';" onMouseOut="document.getElementById(\'selectFont' + n + '\').src=\'' + FontSelect + '\';"><img src="' + FontSelect + '" id="selectFont' + n + '" width="85" height="20" onClick="showFonts(\'' + n + '\');" unselectable="on"><br>';
	FontSelectDropDown[n] += '<span id="Fonts' + n + '" class="dropdown" style="width: 145px;">';

	for (var i = 0; i <= Fonts.length;) {
	  if (Fonts[i]) {
       FontSelectDropDown[n] += '<div onClick="formatText(\'FontName\',\'' + n + '\',\'' + Fonts[i] + '\')\; hideFonts(\'' + n + '\');" onMouseOver="this.className=\'mouseDown\'" onMouseOut="this.className=\'mouseOut\'" class="Jim" style="width: 120px;"><table cellpadding="0" cellspacing="0" border="0"><tr><td align="left" style="font-family:' + Fonts[i] + '; font-size: 12px;">' + Fonts[i] + '</td></tr></table></div><br>';	
    }	  
	  i++;


  }
	FontSelectDropDown[n] += '</span></td></tr></table>';
	document.getElementById('FontSelect' + n).insertAdjacentHTML("afterBegin", FontSelectDropDown[n]);
};



/* ---------------------------------------------------------------------- *\
  Function    : outputFontSizes()
  Description : creates the Font Sizes drop down and inserts it into 
	              the toolbar
  Usage       : outputFontSelect(n)
  Arguments   : n   - The editor identifier that the Font Sizes will update
	                    when making font changes (the textarea's ID)
\* ---------------------------------------------------------------------- */
function outputFontSizes(n) {

  var FontSize           = '/rfSystem/rfEditor/includes/images/custom/select_size.gif';
  var FontSizeOn         = '/rfSystem/rfEditor/includes/images/custom/select_size_on.gif';

	FontSizes.sort();
	var FontSizesDropDown = new Array;
	FontSizesDropDown[n] = '<table align=left border="0" cellpadding="0" cellspacing="0"><tr><td onMouseOver="document.getElementById(\'selectSize' + n + '\').src=\'' + FontSizeOn + '\';" onMouseOut="document.getElementById(\'selectSize' + n + '\').src=\'' + FontSize + '\';"><img src="' + FontSize + '" id="selectSize' + n + '" width="49" height="20" onClick="showFontSizes(\'' + n + '\');" unselectable="on"><br>';
	FontSizesDropDown[n] += '<span id="Sizes' + n + '" class="dropdown" style="width: 170px;">';

	for (var i = 0; i <= FontSizes.length;) {
	  if (FontSizes[i]) {
      FontSizesDropDown[n] += '<div type="button" onClick="formatText(\'FontSize\',\'' + n + '\',\'' + FontSizes[i] + '\')\;hideFontSizes(\'' + n + '\');" onMouseOver="this.className=\'mouseOver\'" onMouseOut="this.className=\'mouseOut\'" class="mouseOut" style="width: 145px;"><table cellpadding="0" cellspacing="0" border="0"><tr><td align="left" style="font-family: arial, verdana, helvetica;"><font size="' + FontSizes[i] + '">size ' + FontSizes[i] + '</font></td></tr></table></div><br>';	
    }	  
	  i++;
  }
	FontSizesDropDown[n] += '</span></td></tr></table>';
	document.getElementById('FontSizes' + n).insertAdjacentHTML("afterBegin", FontSizesDropDown[n]);
};



/* ---------------------------------------------------------------------- *\
  Function    : hideFonts()
  Description : Hides the list of font names in the font select drop down
  Usage       : hideFonts(n)
  Arguments   : n   - The editor identifier (the textarea's ID)
\* ---------------------------------------------------------------------- */
function hideFonts(n) {
  document.getElementById('Fonts' + n).style.display = 'none'; 
};



/* ---------------------------------------------------------------------- *\
  Function    : hideFontSizes()
  Description : Hides the list of font sizes in the font sizes drop down
  Usage       : hideFontSizes(n)
  Arguments   : n   - The editor identifier (the textarea's ID)
\* ---------------------------------------------------------------------- */
function hideFontSizes(n) {
  document.getElementById('Sizes' + n).style.display = 'none'; 
};



/* ---------------------------------------------------------------------- *\
  Function    : showFonts()
  Description : Shows the list of font names in the font select drop down
  Usage       : showFonts(n)
  Arguments   : n   - The editor identifier (the textarea's ID)
\* ---------------------------------------------------------------------- */
function showFonts(n) { 
  if (document.getElementById('Fonts' + n).style.display == 'block') {
    document.getElementById('Fonts' + n).style.display = 'none';
	}
  else {
    document.getElementById('Fonts' + n).style.display = 'block'; 
    document.getElementById('Fonts' + n).style.position = 'absolute';		
  }
};



/* ---------------------------------------------------------------------- *\
  Function    : showFontSizes()
  Description : Shows the list of font sizes in the font sizes drop down
  Usage       : showFonts(n)
  Arguments   : n   - The editor identifier (the textarea's ID)
\* ---------------------------------------------------------------------- */
function showFontSizes(n) { 
  if (document.getElementById('Sizes' + n).style.display == 'block') {
    document.getElementById('Sizes' + n).style.display = 'none';
	}
  else {
    document.getElementById('Sizes' + n).style.display = 'block'; 
    document.getElementById('Sizes' + n).style.position = 'absolute';		
  }
};

/* ---------------------------------------------------------------------- *\
  Function    : formatText()
  Description : replace textarea with wysiwyg editor
  Usage       : formatText(id, n, selected);
  Arguments   : id - The execCommand (e.g. Bold)
                n  - The editor identifier that the command 
								     affects (the textarea's ID)
                selected - The selected value when applicable (e.g. Arial)
\* ---------------------------------------------------------------------- */
function formatText(id, n, selected) {

  // When user clicks toolbar button make sure it always targets its respective WYSIWYG
  document.getElementById("wysiwyg" + n).contentWindow.focus();
	
	// When in Text Mode these execCommands are disabled
	var formatIDs = new Array("FontSize","FontName","Bold","Italic","Underline","Subscript","Superscript","Strikethrough","Justifyleft","Justifyright","Justifycenter","InsertUnorderedList","InsertOrderedList","Indent","Outdent","ForeColor","BackColor","InsertImage","InsertTable","CreateLink");
  
	// Check if button clicked is in disabled list
	for (var i = 0; i <= formatIDs.length;) {
		if (formatIDs[i] == id) {
			 var disabled_id = 1; 
		}
	  i++;
	}
	
	// Check if in Text Mode and disabled button was clicked
	if (viewTextMode == 1 && disabled_id == 1) {
	  alert ("You are in HTML Mode. This feature has been disabled.");	
	}
	
	else {
	
	  // FontSize
	  if (id == "FontSize") {
      document.getElementById("wysiwyg" + n).contentWindow.document.execCommand("FontSize", false, selected);
	  }
	  
		// FontName
	  else if (id == "FontName") {
      document.getElementById("wysiwyg" + n).contentWindow.document.execCommand("FontName", false, selected);
	  }
	
	  // ForeColor and BackColor
    else if (id == 'ForeColor' || id == 'BackColor') {
      var w = screen.availWidth;
      var h = screen.availHeight;
      var popW = 210, popH = 165;
      var leftPos = (w-popW)/2, topPos = (h-popH)/2;
      var currentColor = _dec_to_rgb(document.getElementById("wysiwyg" + n).contentWindow.document.queryCommandValue(id));
   
	    window.open(popupsDir + 'select_color.html?color=' + currentColor + '&command=' + id + '&wysiwyg=' + n,'popup','location=0,status=0,scrollbars=0,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
    }
	  
		// InsertImage
	  else if (id == "InsertImage") {
      window.open(popupsDir + 'insert_image.html?wysiwyg=' + n,'popup','location=0,status=0,scrollbars=0,resizable=0,width=400,height=190');
	  }
	  
		// InsertTable
	  else if (id == "InsertTable") {
	    window.open(popupsDir + 'create_table.html?wysiwyg=' + n,'popup','location=0,status=0,scrollbars=0,resizable=0,width=400,height=360');
	  }
	  
		// CreateLink
	  else if (id == "CreateLink") {
	    window.open(popupsDir + 'insert_hyperlink.html?wysiwyg=' + n,'popup','location=0,status=0,scrollbars=0,resizable=0,width=300,height=110');
	  }
	  
		// ViewSource
	  else if (id == "ViewSource") {
	    viewSource(n);
	  }
		
		// ViewText
		else if (id == "ViewText") {
	    viewText(n);
	  }

		// Help
		else if (id == "Help") {
	    window.open(popupsDir + 'about.html','popup','location=0,status=0,scrollbars=0,resizable=0,width=400,height=330');
	  }

		// Skype
		else if (id == "Skype") {
      window.open(popupsDir + 'paste_test.html?wysiwyg=' + n,'popup','location=0,status=1,scrollbars=0,resizable=0,width=400,height=190');
	  }
	  
		// Every other command
	  else {
		document.getElementById("wysiwyg" + n).contentWindow.document.execCommand(id, false, null);
		}
  }
};

function insertHTML(html, n) {

  var browserName = navigator.appName;
	 	 
	if (browserName == "Microsoft Internet Explorer") {	  
	  document.getElementById('wysiwyg' + n).contentWindow.document.selection.createRange().pasteHTML(html);   
	} 
	 
	else {
	  var div = document.getElementById('wysiwyg' + n).contentWindow.document.createElement("div");
		 
		div.innerHTML = html;
		var node = insertNodeAtSelection(div, n);		
	}
	
}



function progressBar(myID) {

	var thisBar = document.getElementById(myID);
	thisBar.style.display="";
	thisBar.style.left=((document.body.clientWidth / 2)-50);
	thisBar.style.top=((document.body.clientHeight / 2)-50);
	self.scrollTo(0,0);
//	alert(document.body.clientHeight);
}
