// -------------------------------------------------------------------------------
// --- DEFINES
// -------------------------------------------------------------------------------
	var rTypeNone = 0;
	var rTypeText = 1;
	var rTypeRich = 2;
// ---
	var rActionBasic = 0;
	var rActionExtend = 1;
	var rActionText = 2;
	var rActionObject = 4;
// -------------------------------------------------------------------------------
// --- описание структуры rPath
// -------------------------------------------------------------------------------
	var orPath=null;
	function rPath(base_url,css_file){ // Пути до файлов RE
		this.base = base_url;				// до корня 
		this.image= "img/";					// до иконок 
		this.css	= css_file;				// файл с css
		// копия себя самого
		orPath = this;
	}
// -------------------------------------------------------------------------------
// --- описание класса rImages
// -------------------------------------------------------------------------------
	var orImages = null;
	var wrImages = null;
	function rImages(swidth,sheight){ // Поле с картинками для вставки
		if(orImages == null){
			this.width	= swidth;					// ширина картинки
			this.height	= sheight;				// высота картинки
			orImages=this;
		}
	}
// -------------------------------------------------------------------------------
// --- описание класса rLinks
// -------------------------------------------------------------------------------
	var orLinks = null;
	var wrLinks = null;
	function rLinks(){ // 
		if(orLinks == null){
			orLinks=this;
		}
	}
// -------------------------------------------------------------------------------
// --- описание класса rText
// -------------------------------------------------------------------------------
	var orTextActive = null;
	function rText(id){ // Поле редактирования RE
		if(textObj = document.all[id]){
			var originalContent = textObj.value;	// сохраняем оригинальную заполнение
			this.width	= textObj.style.width;		// сохраняем оригинальную ширину
			this.height	= textObj.style.height;		// сохраняем оригинальную высоту
			this.id			= id;											// сохраняем оригинальный идентификатор объекта
			this.type		= rTypeNone;							// текущий тип поля редактирования
			// метод : переключение типа поля редактирования RE			
			this.tswitch = rText_tswitch;
			// метод : синхронизация поля редактирования и скрытого поля хранения RE
			this.synchro = rText_synchro;
			// создаем скрытый объект для сохранения данных
			textObj.outerHTML = '<input type=hidden id="'+this.id+'" name="'+textObj.name+'"><input type=hidden id="re'+this.id+'">'; // сгенеренный HTML взамен старого
			this.content = document.all[this.id];
			this.editor  = document.all['re'+this.id];
			this.content.value = originalContent;	
			this.rObject = this;
			this.editor.rObject = this;		
			this.tswitch(rTypeRich);

			this.saver = textareaSaver;
			this.sRange = null;
		}
	}
// -------------------------------------------------------------------------------
// --- методы класса rText
// -------------------------------------------------------------------------------
	function rText_tswitch(type){ // переключение типа поля редактирования RE
		this.synchro();
		var is_not_editable = !(document.designMode);
		var oid = 're'+this.id;
		if(type==rTypeText || is_not_editable){
			// создаем новый объект на месте старого
			this.editor.outerHTML = '<textarea	id="'+oid+'" style="width:' +this.width+ '; height:' +this.height+ ';"></textarea>';
			this.editor  = document.all[oid]; // запоминаем его
			this.editor.value  = this.content.value; // обновляем значение из сохраненного	
			this.type = rTypeText;
			// устанавливаем события
			this.editor.onfocus   = function() { orTextActive.saver();orTextActive.synchro(); }
			this.editor.onclick   = function() { orTextActive.saver();orTextActive.synchro(); }
			this.editor.onchange   = function() { orTextActive.saver();orTextActive.synchro(); }

			this.editor.onkeyup		= function() { orTextActive.saver();orTextActive.synchro(); }
			this.editor.onmouseup   = function() { orTextActive.saver();orTextActive.synchro(); }
			this.editor.ondrop		= function() { setTimeout(function(){orTextActive.saver();orTextActive.synchro();},1000);	}     
			this.editor.oncut		= function() { setTimeout(function(){orTextActive.saver();orTextActive.synchro();},1000); }
			this.editor.onpaste		= function() { setTimeout(function(){orTextActive.saver();orTextActive.synchro();},1000); }
		}else if(type==rTypeRich){
			// создаем новый объект на месте старого
			this.editor.outerHTML = '<iframe	id="'+oid+'" style="width:' +this.width+ '; height:' +this.height+ ';"></iframe>';
			this.editor  = document.all[oid]; // запоминаем его
			this.edocument = document.frames[oid];
			var html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>';
			html += '<head>';
			html += '<link rel=stylesheet type=text/css href="'+orPath.base+'richedit.css" />';
			html += '<link rel=stylesheet type=text/css href="'+orPath.css+'" />';
/*			html += '<link rel=stylesheet type=text/css href="'+orPath.base+'jquery.min.js" />';
			html += '<sc'+'ript type="text/javascript" src="'+orPath.base+'jquery.min.js"></sc'+'ript>';
			html += '<sc'+'ript>';
       		html += '	$(document).ready(function(){';
			html += "		$('.reCellBordered .reTable:not(.reCellBordered) > tbody > tr > td').css('border','none');	";
			html += "		$('.reCellBordered .reTable:not(.reCellBordered) > tr > td').css('border','none');";
            html += '	})';
			html += '</sc'+'ript>';	*/	
			html += '</head>';
			html += '<body bgcolor=#ffffff topmargin=0 leftmargin=0 marginheight=0 marginwidth=0 class="richedit">';
			html += '</body>';
			html += '</html>';
			this.edocument.document.designMode = "on";
			this.edocument.document.open();
			this.edocument.document.write(html);
			this.edocument.document.close();
			this.edocument.document.body.innerHTML =  this.content.value; // обновляем значение из сохраненного	
			this.edocument.rObject = this;
			this.type = rTypeRich;		
			// устанавливаем события


			this.edocument.document.body.onfocus   = function() { orTextActive.saver();orTextActive.synchro(); }
			this.edocument.document.body.onclick   = function() { rPanel_setfocus();orTextActive.saver();orTextActive.synchro();}
			this.edocument.document.body.onchange  = function() { orTextActive.saver();orTextActive.synchro(); }

			this.edocument.document.body.onkeyup   = function() { orTextActive.saver();orTextActive.synchro(); }
			this.edocument.document.body.onmouseup = function() { orTextActive.saver();orTextActive.synchro(); }
			this.edocument.document.body.ondrop    = function() { setTimeout(function(){orTextActive.saver();orTextActive.synchro();},1000); }     
			this.edocument.document.body.oncut     = function() { setTimeout(function(){orTextActive.saver();orTextActive.synchro();},1000); }
			this.edocument.document.body.onpaste   = function() { setTimeout(function(){orTextActive.saver();orTextActive.synchro();},1000); }
		}
		this.rObject				= this;
		this.editor.rObject = this;		
		// устанавливаем события
		this.editor.onfocus			= function() { /*alert(0);*/orTextActive = this.rObject;	orPanel.update(); }
		this.editor.focus();
	}
// --- 
	function rText_synchro(){// синхронизация поля редактирования и скрытого поля хранения RE	
		if(orTextActive!=null){
			if(orTextActive.type==rTypeText){
				orTextActive.content.value = orTextActive.editor.value;	
			}else if(orTextActive.type==rTypeRich){
				orTextActive.content.value = orTextActive.edocument.document.body.innerHTML;	
			}
		}
		return true;
	}
	function textareaSaver() {
		orTextActive.sRange = null;
		if(orTextActive!=null && orTextActive.edocument.document.selection) {
			var _sRange = orTextActive.edocument.document.selection.createRange();
			if(_sRange){
				if (_sRange.length==1){
					orTextActive.sRange = _sRange;
				}else{
					orTextActive.sRange = _sRange.duplicate();
				}
			}
		}
	}
