// variables
	var isRichText = false;
	var rng;
	var currentRTE;
	var allRTEs = "";
	var imagesPath;
	var includesPath;
	var cssFile;
	var designMode = true;
	var sourceMode = false;
	var RTE;
	//set browser vars
	var ua    =  navigator.userAgent.toLowerCase();
	var isIE  =  ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1));
	var isFF  =  (ua.indexOf("gecko") != -1 && ua.indexOf("safari") == -1);
	

function echo(str){return document.writeln(str);}
if(typeof($) == "undefined"){
	function $(obj){return document.getElementById(obj);}
}
function c(obj){obj.className = 'over';}
function o(obj){obj.className = 'btnImage';}



function initRTE(imgPath, incPath, css) {
	if ($ && document.designMode) isRichText = true;
	imagesPath    =  imgPath;
	includesPath  =  incPath;
	cssFile       =  css;
}

function MakeEditor(textarea,rte, width, height, buttons, readOnly) {
	$(textarea).style.display = 'none';
	my_text = $(textarea);

	my_node = my_text.parentNode;
	
	while(my_node.nodeName.toLowerCase() != 'form'){
		my_node = my_node.parentNode;
	}
	function _submit_form(){
		$(textarea).value = frames[rte].document.body.innerHTML;
	}
	
	if(my_node.attachEvent){
		my_node.attachEvent("onsubmit",_submit_form);
		//alert('IE');
	}else{
		my_node.addEventListener("submit",_submit_form,false);
		//alert('FF');
	}
	//width = $(textarea).innerWidth;
	//height = $(textarea).innerHeight;
	html = $(textarea).value;
	writeRTE(rte,$(textarea), html, width, height, buttons, readOnly);

	
}



function writeDefault(rte, html, width, height, buttons, readOnly) {
	if (!readOnly) {
		echo('<textarea name="' + rte + '" id="' + rte + '" style="width: ' + width + 'px; height: ' + height + 'px;">' + html + '</textarea>');
	} else {
		echo('<textarea name="' + rte + '" id="' + rte + '" style="width: ' + width + 'px; height: ' + height + 'px;" readonly>' + html + '</textarea>');
	}
}


function writeRTE(rte,textarea,html, width, height, buttons, readOnly) {
	RTE = rte;
	echo('<table style="border:1px solid #006699; background:#FFFFFF; padding:0px;" align="'+textarea.style.textAlign+'" cellpadding="0" cellspacing="0" width="' + width + '" id="' + rte + 'editor_table"><tr><td>');
	echo('<iframe id="' + rte + '" name="' + rte + '" width="100%" height="' + height + 'px" style="border:0px solid #006699;"></iframe>');
	echo('<iframe width="254" height="174" id="cp' + rte + '" src="' + includesPath + 'palette.htm" marginwidth="0" marginheight="0" scrolling="no" style="visibility:hidden; border:0px; display: none; position: absolute;"></iframe>');
	echo('<input type="hidden" id="hdn' + rte + '" name="' + rte + '" value="">');
	$('hdn' + rte).value = html;
	echo('</td></tr></table>');
	enableDesignMode(rte, html, readOnly);
}

function enableDesignMode(rte, html, readOnly) {
var frameHtml = html;
//frameHtml = '<div style="direction:rtl;font-family:tahoma; font-size:12px;">'+html+'</div>'
	if (document.all) {
		var oRTE = frames[rte].document;
		oRTE.open();
		oRTE.write(frameHtml);
		oRTE.close();
		if (!readOnly) oRTE.designMode = "On";
		oRTE.body.style.direction = 'rtl';
		oRTE.body.style.fontFamily = 'Tahoma';
		oRTE.body.style.fontSize = '12px';
	
	} else {
		try {
			if (!readOnly) $(rte).contentDocument.designMode = "on";
			try {
				var oRTE = $(rte).contentWindow.document;
				oRTE.open();
				oRTE.write(frameHtml);
				oRTE.close();
				oRTE.body.style.direction = 'rtl';
				oRTE.body.style.fontFamily = 'Tahoma';
				oRTE.body.style.fontSize = '12px';

			} catch (e) {

			}
		} catch (e) {

			if (isFF) {
				setTimeout("enableDesignMode('" + rte + "', '" + html + "');", 10);
			} else {
				return false;
			}
		}
	}
}


function updateRTEs() {
	var vRTEs = allRTEs.split(";");
	for (var i = 0; i < vRTEs.length; i++) {
		updateRTE(vRTEs[i]);
	}
}

function Select(rte, selectname) {
	var oRTE;
	if (document.all) {
		oRTE = frames[rte];
		
		//get current selected range
		var selection = oRTE.document.selection; 
		if (selection != null) {
			rng = selection.createRange();
		}
	} else {
		oRTE = $(rte).contentWindow;
		
		//get currently selected range
		var selection  = oRTE.getSelection();
		rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
	}
	
	var idx = $(selectname).selectedIndex;
	// First one is always a label
	if (idx != 0) {
		var selected = $(selectname).options[idx].value;
		var cmd = selectname.replace('_' + rte, '');
		oRTE.document.execCommand(cmd, false, selected);
		//$(selectname).selectedIndex = 0;
	}
	oRTE.focus();
}