		var imgaligncenter = null;
		var imgaligncenter_on = null;
		var imgalignjustify = null;
		var imgalignjustify_on = null;
		var imgalignleft = null;
		var imgalignleft_on = null;
		var imgalignright = null;
		var imgalignright_on = null;
		var imgbold = null;
		var imgbold_on = null;
		var imgcopy = null;
		var imgcopy_on = null;
		var imgcut = null;
		var imgcut_on = null;
		var imgfont = null;
		var imgfont_on = null;
		var imgfontcolor = null;
		var imgfontcolor_on = null;
		var imgfontsize = null;
		var imgfontsize_on = null;
		var imghighlight = null;
		var imghighlight_on = null;
		var imgindent = null;
		var imgindent_on = null;
		var imgitalic = null;
		var imgitalic_on = null;
		var imglink = null;
		var imglink_on = null;
		var imgnew = null;
		var imgnew_on = null;
		var imgorderedlist = null;
		var imgorderedlist_on = null;
		var imgoutdent = null;
		var imgoutdent_on = null;
		var imgpaste = null;
		var imgpaste_on = null;
		var imgprint = null;
		var imgredo = null;
		var imgredo_on = null;
		var imgremlink = null;
		var imgremlink_on = null;
		var imgremoveformat = null;
		var imgremoveformat_on = null;
		var imgsave = null;
		var imgsave_on = null;
		var imgspacer = null;
		var imgstrikethrough = null;
		var imgstrikethrough_on = null;
		var imgsubscript = null;
		var imgsubscript_on = null;
		var imgsuperscript = null;
		var imgsuperscript_on = null;
		var imgtable = null;
		var imgtable_on = null;
		var imgunderline = null;
		var imgunderline_on = null;
		var imgundo = null;
		var imgundo_on = null;
		var imgunorderedlist = null;
		var imgunorderedlist_on = null;
		var imgpicture = null;
		var imgpicture_on = null;
		
		var target_iframe = null;
		
		var swap_oldHeight = null;
		var swap_oldWidth = null;
		
function rte_load(iCount){
	if(!iCount) iCount = 0;
	var editorwin = rte_getIFrameDocument();
	if(editorwin)
		{
		//-- Preload Images
		imgaligncenter = new Image();
		imgaligncenter.src = '/common/RTEbuttons/align-center.gif';
		imgaligncenter_on = new Image();
		imgaligncenter_on.src = '/common/RTEbuttons/align-center_on.gif';
		imgalignjustify = new Image();
		imgalignjustify.src = '/common/RTEbuttons/align-justify.gif';
		imgalignjustify_on = new Image();
		imgalignjustify_on.src = '/common/RTEbuttons/align-justify_on.gif';
		imgalignleft = new Image();
		imgalignleft.src = '/common/RTEbuttons/align-left.gif';
		imgalignleft_on = new Image();
		imgalignleft_on.src = '/common/RTEbuttons/align-left_on.gif';
		imgalignright = new Image();
		imgalignright.src = '/common/RTEbuttons/align-right.gif';
		imgalignright_on = new Image();
		imgalignright_on.src = '/common/RTEbuttons/align-right_on.gif';
		imgbold = new Image();
		imgbold.src = '/common/RTEbuttons/bold.gif';
		imgbold_on = new Image();
		imgbold_on.src = '/common/RTEbuttons/bold_on.gif';
		imgcopy = new Image();
		imgcopy.src = '/common/RTEbuttons/copy.gif';
		imgcopy_on = new Image();
		imgcopy_on.src = '/common/RTEbuttons/copy_on.gif';
		imgcut = new Image();
		imgcut.src = '/common/RTEbuttons/cut.gif';
		imgcut_on = new Image();
		imgcut_on.src = '/common/RTEbuttons/cut_on.gif';
		imgfont = new Image();
		imgfont.src = '/common/RTEbuttons/font.gif';
		imgfont_on = new Image();
		imgfont_on.src = '/common/RTEbuttons/font_on.gif';
		imgfontsize = new Image();
		imgfontsize.src = '/common/RTEbuttons/fontsize.gif';
		imgfontsize_on = new Image();
		imgfontsize_on.src = '/common/RTEbuttons/fontsize_on.gif';
		imgfontcolor = new Image();
		imgfontcolor.src = '/common/RTEbuttons/fontcolor.gif';
		imgfontcolor_on = new Image();
		imgfontcolor_on.src = '/common/RTEbuttons/fontcolor_on.gif';
		imghighlight = new Image();
		imghighlight.src = '/common/RTEbuttons/highlight.gif';
		imghighlight_on = new Image();
		imghighlight_on.src = '/common/RTEbuttons/highlight_on.gif';
		imgindent = new Image();
		imgindent.src = '/common/RTEbuttons/indent.gif';
		imgindent_on = new Image();
		imgindent_on.src = '/common/RTEbuttons/indent_on.gif';
		imgitalic = new Image();
		imgitalic.src = '/common/RTEbuttons/italic.gif';
		imgitalic_on = new Image();
		imgitalic_on.src = '/common/RTEbuttons/italic_on.gif';
		imglink = new Image();
		imglink.src = '/common/RTEbuttons/link.gif';
		imglink_on = new Image();
		imglink_on.src = '/common/RTEbuttons/link_on.gif';
		imgnew = new Image();
		imgnew.src = '/common/RTEbuttons/new.gif';
		imgnew_on = new Image();
		imgnew_on.src = '/common/RTEbuttons/new_on.gif';
		imgorderedlist = new Image();
		imgorderedlist.src = '/common/RTEbuttons/orderedlist.gif';
		imgorderedlist_on = new Image();
		imgorderedlist_on.src = '/common/RTEbuttons/orderedlist_on.gif';
		imgoutdent = new Image();
		imgoutdent.src = '/common/RTEbuttons/outdent.gif';
		imgoutdent_on = new Image();
		imgoutdent_on.src = '/common/RTEbuttons/outdent_on.gif';
		imgpaste = new Image();
		imgpaste.src = '/common/RTEbuttons/paste.gif';
		imgpaste_on = new Image();
		imgpaste_on.src = '/common/RTEbuttons/paste_on.gif';
		imgprint = new Image();
		imgprint.src = '/common/RTEbuttons/print.gif';
		imgredo = new Image();
		imgredo.src = '/common/RTEbuttons/redo.gif';
		imgredo_on = new Image();
		imgredo_on.src = '/common/RTEbuttons/redo_on.gif';
		imgremlink = new Image();
		imgremlink.src = '/common/RTEbuttons/remlink.gif';
		imgremlink_on = new Image();
		imgremlink_on.src = '/common/RTEbuttons/remlink_on.gif';
		imgremoveformat = new Image();
		imgremoveformat.src = '/common/RTEbuttons/removeformat.gif';
		imgremoveformat_on = new Image();
		imgremoveformat_on.src = '/common/RTEbuttons/removeformat_on.gif';
		imgsave = new Image();
		imgsave.src = '/common/RTEbuttons/save.gif';
		imgsave_on = new Image();
		imgsave_on.src = '/common/RTEbuttons/save_on.gif';
		imgspacer = new Image();
		imgspacer.src = '/common/RTEbuttons/spacer.gif';
		imgstrikethrough = new Image();
		imgstrikethrough.src = '/common/RTEbuttons/strikethrough.gif';
		imgstrikethrough_on = new Image();
		imgstrikethrough_on.src = '/common/RTEbuttons/strikethrough_on.gif';
		imgsubscript = new Image();
		imgsubscript.src = '/common/RTEbuttons/subscript.gif';
		imgsubscript_on = new Image();
		imgsubscript_on.src = '/common/RTEbuttons/subscript_on.gif';
		imgsuperscript = new Image();
		imgsuperscript.src = '/common/RTEbuttons/superscript.gif';
		imgsuperscript_on = new Image();
		imgsuperscript_on.src = '/common/RTEbuttons/superscript_on.gif';
		imgtable = new Image();
		imgtable.src = '/common/RTEbuttons/table.gif';
		imgtable_on = new Image();
		imgtable_on.src = '/common/RTEbuttons/table_on.gif';
		imgunderline = new Image();
		imgunderline.src = '/common/RTEbuttons/underline.gif';
		imgunderline_on = new Image();
		imgunderline_on.src = '/common/RTEbuttons/underline_on.gif';
		imgundo = new Image();
		imgundo.src = '/common/RTEbuttons/undo.gif';
		imgundo_on = new Image();
		imgundo_on.src = '/common/RTEbuttons/undo_on.gif';
		imgunorderedlist = new Image();
		imgunorderedlist.src = '/common/RTEbuttons/unorderedlist.gif';
		imgunorderedlist_on = new Image();
		imgunorderedlist_on.src = '/common/RTEbuttons/unorderedlist_on.gif';
		imgpicture = new Image();
		imgpicture.src = '/common/RTEbuttons/picture.gif';
		imgpicture_on = new Image();
		imgpicture_on.src = '/common/RTEbuttons/picture_on.gif';
	
		rte_initWindowMode();
			
		//rte_loadFormValue();
	}
}

function rte_initWindowMode()
{
	var editorwin = rte_getIFrameDocument();
	editorwin.designMode = "On";
	if(document.layers)
		editorwin.execCommand("useCSS", false, true);
}

function rte_swapImage(img){
	var imgName = new String(img.src);
	if(imgName.indexOf("_on") > -1) {
		if(newImage = eval("img" + imgName.substring(imgName.lastIndexOf("/"), imgName.lastIndexOf(".")).replace(/[^\w]/g, "").replace("_on", ""))){
			img.src = newImage.src;
		} else {
			img.src = imgName.replace("_on", "");
		}
	} else {
		if(newImage = eval(new String("img" + imgName.substring(imgName.lastIndexOf("/"), imgName.lastIndexOf(".")) + "_on").replace(/[^\w]/g, ""))){
			img.src = newImage.src;
		} else {
			img.src = imgName.substr(0, imgName.lastIndexOf(".")) + "_on" + imgName.substr(imgName.lastIndexOf("."), imgName.length);
		}
	}
}

function rte_getIFrameDocument()
{
	var id = "rte_editorWindow";
	var obj = null
	try
	{
		return document.getElementById(id).contentWindow.document;
	}
	catch(e)
	{
		return false;
	}
}

function rte_getIFrameWindow()
{
	var id = "rte_editorWindow";
	var obj = null
	try
	{
		return document.getElementById(id).contentWindow;
	}
	catch(e)
	{
		return false;
	}
}
 
function rte_doCommand(aName, aArg){
	var obj = rte_getIFrameDocument();
	if(obj)
	{
		try{
			if(aArg == "custom"){
				aArg = prompt("Enter your hexadecimal color value:\nE.G.: #FFFFFF");	
			}
			
			obj.execCommand(aName, false, aArg);
			document.getElementById('rte_editorWindow').contentWindow.focus();
		} catch(e) {
			alert("You're browser does not properly support that action.\n\nAction: " + aName + "\nProperties: " + aArg);
		}
	}
	else
		return false;
} 
	
function rte_addLink(){
	var obj = rte_getIFrameDocument();
	if(obj)
	{
		var myUrl = prompt("Please enter a URL:", "");
		rte_getIFrameDocument().execCommand("createLink", false, myUrl);
	}
}    

function rte_setfontSize(increment){
	var obj = rte_getIFrameDocument();
	if(obj)
	{
		obj.execCommand("fontSize", false, increment);
	}
}

function rte_setfontName(name){
	var obj = rte_getIFrameDocument();
	if(obj)
	{
		obj.execCommand("fontName", false, name);
	}
}

function OpenImageWindow(url,id,width,height) {
	var rand_name = 'image_'+id;
	width = (width  - 0) + 20;
	height = (height  - 0) + 20;
	newWindow = window.open(url, rand_name,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0, resizable=0,width="+width+",height="+height,'true');
	newWindow.window.focus();
}

function rte_addImage(path)
{
	var obj = rte_getIFrameDocument();
	if (obj) {
			obj.execCommand("InsertImage", false, path);
	}
}

function rte_addTable(){
	var obj = rte_getIFrameDocument();
	var bod = obj.body;
	var win = rte_getIFrameWindow();
	if(obj)
	{
		var rows = 0;
		var cols = 0;
		var arrayCells = [];
		arrayCells[0] = [];
		var selection = "";
		
		if(win.getSelection)
		{ // Mozilla
			var rsel = win.getSelection().getRangeAt(0);
			var selection = new String(win.getSelection());
			var par = rsel.commonAncestorContainer;
		}
		else
		{ //IE
			var rsel = obj.selection.createRange();
			var selection = new String(rsel.text);
			var par = rsel.parentElement();
		}
		
		var padding = parseInt(prompt('How much cell-padding do you want?  (0 = none)', '5'));
		if(isNaN(padding)) return false;
		
		var border = parseInt(prompt('What size of a border do you want? (0 = none)', '1'));
		if(isNaN(border)) return false;
		
		var selectedText = new String(selection);
		
		if(selectedText.length){
			var arrayCells = selectedText.split(/\r\n/g);
			for(i=0; i < arrayCells.length; i++)
			{
				var working = arrayCells[i];
				working = working.split(/\t/g);
				cols = (working.length > cols) ? working.length : cols;
				arrayCells[i] = working;
			}
			rows = arrayCells.length;
		} else {
			rows = parseInt(prompt("How many rows do you want?", "2"));
			if(isNaN(rows)) return false;
			cols = parseInt(prompt("How many columns do you want?", "2"));
			if(isNaN(cols)) return false;
		}
				
		if(rows && cols){
					
			var table = document.createElement('table');
			table.border = border;
			table.cellPadding = padding;
			table.cellSpacing = 0;
			
			for(i=0; i<rows; i++)
			{
				row = document.createElement('tr');
				for(j=0; j<cols; j++)
				{
					var cellText = "";
					if(arrayCells[i]){
						if(arrayCells[i][j]){
							cellText = arrayCells[i][j];
						}
					}
					cell = document.createElement('td');
					cell.align = 'left';
					cell.vAlign = 'top';
					cell.innerHTML = cellText || '&nbsp;';
					row.appendChild(cell);
				}
				table.appendChild(row);
			}
			
			if(win.getSelection){// Mozilla
				rsel.deleteContents();	
				rsel.collapse(true);
				rsel.insertNode(table);
			} else { //IE
				var container = document.createElement('div');
				container.appendChild(table);
				rsel.pasteHTML(container.innerHTML);
			}
			
			document.getElementById('rte_editorWindow').contentWindow.focus();
		}
	}
}

function rte_newDocument(){
	var obj = rte_getIFrameDocument();
	if(obj)
	{
		obj.body.innerHTML = "";
		document.getElementById('rte_editorWindow').contentWindow.focus();
	}
}

function rte_setFormValue(theField){
	var obj = rte_getIFrameDocument();
	if(obj)
	{
		theField.value = obj.body.innerHTML;
		return true;
	}
	else
		return false;
}

function rte_loadFormValue(){
	var obj = rte_getIFrameDocument();
	if(obj)
	{
		if(obj.body){
			obj.body.innerHTML = document.getElementById("rte_loadSourceLayer").innerHTML;
		} else {
			setTimeout("rte_loadFormValue()", 500);
		}
	}
}

function rte_updateEditorSource(selem)
{
	var ed = rte_getIFrameDocument();
	ed.body.innerHTML = selem.value;
	return true;
}

function rte_SwapView()
{
	var view_rich = document.getElementById("rte_RichView");
	var view_html = document.getElementById("rte_SourceView");
	
	var ed = rte_getIFrameDocument();
	var source = document.getElementById("rte_SourceEditor");
	
	if(view_rich.style.visibility == 'hidden')
	{
		if(!swap_oldHeight)swap_oldHeight = view_html.offsetHeight;
		
		view_rich.style.visibility = 'visible';
		view_rich.style.position = 'static';
		view_rich.style.top = 'auto';
		view_rich.style.width =  '100%';
		view_rich.style.height = swap_oldHeight + 'px';
		
		view_html.style.visibility = 'hidden';
		view_html.style.position = 'absolute';
		view_html.style.top = '0px';
		view_html.style.width = '1px';
		view_html.style.height = '1px';
		
		document.getElementById('rte_btnSwapView').innerText = 'Switch to Source View';
	}
	else
	{
		if(!swap_oldHeight)swap_oldHeight = view_rich.offsetHeight;
		
		source.value = ed.body.innerHTML;
		
		view_html.style.visibility = 'visible';
		view_html.style.position = 'static';
		view_html.style.top = 'auto';
		view_html.style.width = '100%';
		view_html.style.height = swap_oldHeight + 'px';
		
		view_rich.style.visibility = 'hidden';
		view_rich.style.position = 'absolute';
		view_rich.style.top = '0px';
		view_rich.style.width = '1px';
		view_rich.style.height = '1px';
		document.getElementById('rte_btnSwapView').innerText = 'Switch to Layout View';
	}
	rte_initWindowMode();
}