//hilitecolorvar simplEditor = extendClass (null,{	id:'editor',	class_name:'simplEditor',	width:null,	min_width:300,	height:null,	min_height:100,	parent:null,	css:'te',	bt_height:25,	isFooter:true,	status:0,	_childObjects:{},	smileFolders:'smile/',	baseImgPathEditor:'',	_urlcss:'',	imgLoadURL:'img_load.php',  //список имагов	imgToLoadSrc:'img_load.php',  // куда грузить	allSmile:[		'heart.gif',		'hm.gif',		'kid.gif',		'lol.gif',		'love.gif',		'mad.gif',		'no.gif',		'razz.gif',		'rolleyes.gif',		'scream.gif',		'sleep.gif',		'smile.gif',		'smilk.gif',		'wink.gif',		'yes.gif',		'astro.gif',		'biggrin.gif',		'bye.gif',		'cool.gif',		'cool2.gif',		'cry.gif',		'Dmad.gif',		'eek.gif',		'evil.gif',		'frown.gif',		'loveyou.gif',		'laugh.gif',		'cry2.gif',		'vava.gif'	],	_data:'Текст новости <br />',	_charEntities:{160:'nbsp',161:'iexcl',162:'cent',163:'pound',164:'curren',165:'yen',166:'brvbar',167:'sect',168:'uml',169:'copy',170:'ordf',171:'laquo',172:'not',173:'shy',174:'reg',175:'macr',176:'deg',177:'plusmn',178:'sup2',179:'sup3',180:'acute',181:'micro',182:'para',183:'middot',184:'cedil',185:'sup1',186:'ordm',187:'raquo',188:'frac14',189:'frac12',190:'frac34',191:'iquest',192:'agrave',193:'aacute',194:'acirc',195:'atilde',196:'auml',197:'aring',198:'aelig',199:'ccedil',200:'egrave',201:'eacute',202:'ecirc',203:'euml',204:'igrave',205:'iacute',206:'icirc',207:'iuml',208:'eth',209:'ntilde',210:'ograve',211:'oacute',212:'ocirc',213:'otilde',214:'ouml',215:'times',216:'oslash',217:'ugrave',218:'uacute',219:'ucirc',220:'uuml',221:'yacute',222:'thorn',223:'szlig',224:'agrave',225:'aacute',226:'acirc',227:'atilde',228:'auml',229:'aring',230:'aelig',231:'ccedil',232:'egrave',233:'eacute',234:'ecirc',235:'euml',236:'igrave',237:'iacute',238:'icirc',239:'iuml',240:'eth',241:'ntilde',242:'ograve',243:'oacute',244:'ocirc',245:'otilde',246:'ouml',247:'divide',248:'oslash',249:'ugrave',250:'uacute',251:'ucirc',252:'uuml',253:'yacute',254:'thorn',255:'yuml',338:'oelig',339:'oelig',352:'scaron',353:'scaron',376:'yuml',710:'circ',732:'tilde',8194:'ensp',8195:'emsp',8201:'thinsp',8204:'zwnj',8205:'zwj',8206:'lrm',8207:'rlm',8211:'ndash',8212:'mdash',8216:'lsquo',8217:'rsquo',8218:'sbquo',8220:'ldquo',8221:'rdquo',8222:'bdquo',8224:'dagger',8225:'dagger',8240:'permil',8249:'lsaquo',8250:'rsaquo',8364:'euro',402:'fnof',913:'alpha',914:'beta',915:'gamma',916:'delta',917:'epsilon',918:'zeta',919:'eta',920:'theta',921:'iota',922:'kappa',923:'lambda',924:'mu',925:'nu',926:'xi',927:'omicron',928:'pi',929:'rho',931:'sigma',932:'tau',933:'upsilon',934:'phi',935:'chi',936:'psi',937:'omega',945:'alpha',946:'beta',947:'gamma',948:'delta',949:'epsilon',950:'zeta',951:'eta',952:'theta',953:'iota',954:'kappa',955:'lambda',956:'mu',957:'nu',958:'xi',959:'omicron',960:'pi',961:'rho',962:'sigmaf',963:'sigma',964:'tau',965:'upsilon',966:'phi',967:'chi',968:'psi',969:'omega',977:'thetasym',978:'upsih',982:'piv',8226:'bull',8230:'hellip',8242:'prime',8243:'prime',8254:'oline',8260:'frasl',8472:'weierp',8465:'image',8476:'real',8482:'trade',8501:'alefsym',8592:'larr',8593:'uarr',8594:'rarr',8595:'darr',8596:'harr',8629:'crarr',8656:'larr',8657:'uarr',8658:'rarr',8659:'darr',8660:'harr',8704:'forall',8706:'part',8707:'exist',8709:'empty',8711:'nabla',8712:'isin',8713:'notin',8715:'ni',8719:'prod',8721:'sum',8722:'minus',8727:'lowast',8730:'radic',8733:'prop',8734:'infin',8736:'ang',8743:'and',8744:'or',8745:'cap',8746:'cup',8747:'int',8756:'there4',8764:'sim',8773:'cong',8776:'asymp',8800:'ne',8801:'equiv',8804:'le',8805:'ge',8834:'sub',8835:'sup',8836:'nsub',8838:'sube',8839:'supe',8853:'oplus',8855:'otimes',8869:'perp',8901:'sdot',8968:'lceil',8969:'rceil',8970:'lfloor',8971:'rfloor',9001:'lang',9002:'rang',9426:'copy',9674:'loz',9824:'spades',9827:'clubs',9829:'hearts',9830:'diams'},    toolbar:[    	[	    	{name:'seperator'},	    	{name:'fontfamaly', type:2, width:115, value:'times new roman'},	    	{name:'fontsize', type:2, b:900, width:25, value:'4'},	    	{name:'forecolor', type:2, b:900, width:25, value:'A', d:'underline'},	    	{name:'hilitecolor', type:2},	    	{name:'seperator'},	    	{name:'bold', type:0},	    	{name:'italic', type:0},	    	{name:'underline', type:0},	    	{name:'strikethrough', type:0},	    	{name:'seperator'},	    	{name:'superscript', type:0},	    	{name:'subscript', type:0},	    	{name:'seperator'},	    	{name:'justifyleft', type:0},	    	{name:'justifycenter', type:0},	    	{name:'justifyright', type:0},	    	{name:'justifyfull', type:0}	    	],    	[	    	{name:'seperator'},	    	{name:'unlink', type:2},	    	{name:'insertlink', type:2},	    	{name:'insertimage', type:2},	    	{name:'seperator'},	    	{name:'selectAll', type:0},	    	{name:'removeformat', type:0},	    	{name:'seperator'},	    	{name:'undo', type:2},	    	{name:'redo', type:2},	    	{name:'smile', type:2}]    ],    fstyle:['arial','arial black','arial narrow','courier new','century gothic','comic sans ms','impact','tahoma','times new roman','trebuchet ms','verdana'],    fsize:[7,10,12,14,17,23,35],	_trim:function(str){ if (typeof str != "string") return str; str = str.replace(/^\s+|\s+$/g, ""); return str;},    _escapeChar:function(c){		if(c=='&'){return'&amp;'}		if(c=='<'){return'&lt;'}		if(c=='>'){return'&gt;'}		var cc=c.charCodeAt();		if(this.charEntities[cc]){return'&'+this.charEntities[cc]+';'}		else{return c}	},	_escapeQuot:function(str){		quot=(arguments[1]||'"');		if(quot=='"')return str.replace(/"/ig,'\\"');		return str.replace(/'/ig,"\\'");	},	_init:function(){		if (this.parent==null) this.parent = document.body;		var s = $(this.parent).size();		this.width=this.width||s.width;		this.height=this.height||s.height;		var min_w =0;		for(var i=0; i<this.toolbar.length; i++)			if (min_w < this.toolbar[i].length*30) min_w = this.toolbar[i].length*30;		if (this.width<min_w) this.width=min_w;		$().create('div').		param({id:this.id, js_class:this, className:this.css+'_frame'}).		style({width:px(this.width), height:px(this.height)}).		appendTo(this.parent);        this._createHead();		this._createArea();		this._createCodeED();		if (this.isFooter) this._createFooter();		this.loadData();		$(this.id+'_ifr1').el.contentWindow.document.designMode = "on";		if (document.addEventListener) {			$(this.id+'_ifr1').el.contentWindow.document.addEventListener("keydown", this._actionSelectEditor(), true);			$(this.id+'_ifr1').el.contentWindow.document.addEventListener("click", this._actionSelectEditor(), true);			$(this.id+'_ifr1').el.contentWindow.document.addEventListener("mouseup", this._actionSelectEditor(), true);		}		else{			$(this.id+'_ifr1').el.contentWindow.document.attachEvent("onkeydown", this._actionSelectEditor());			$(this.id+'_ifr1').el.contentWindow.document.attachEvent("onclick", this._actionSelectEditor());			$(this.id+'_ifr1').el.contentWindow.document.attachEvent("onmouseup", this._actionSelectEditor());		}		$(this.id).el.focus();	},	_createHead:function(){        $().create('div').        param({id:this.id+'_head'}).        style({width:px(this.width), height:px(25*this.toolbar.length)}).        appendTo(this.id);        for(var i=0; i<this.toolbar.length; i++){        	var p = $().create('div').style({width:px(this.width), height:px(25)}).appendTo(this.id+'_head').el;        	for(var j=0; j<this.toolbar[i].length; j++){        		if (this.toolbar[i][j].name!='seperator'){	        		var bt = $().create('div').	        			param({id:this.id+this.toolbar[i][j].name,	        			js_class:this,	        			className:this.css+'_'+this.toolbar[i][j].name,	        			onmouseover:this._events._over,						onmouseout:this._events._out	        		}).					style({height:px(this.toolbar[i][j].height||this.bt_height), width:px((this.toolbar[i][j].width||this.bt_height))}).					appendTo(p).el;					$().create('input').					param({						js_class:this,						action:this.toolbar[i][j].name,						className:this.css+'_menubt',						onmousedown:this._events._mouse_down,						_type_:this.toolbar[i][j].type,						type:'button',						value:(this.toolbar[i][j].value||'')						}).					style({height:'100%', width:'100%', fontWeight:(this.toolbar[i][j].b||400), textDecoration:(this.toolbar[i][j].d||'none')}).					appendTo(bt);				}				else $().create('div').param({className:this.css+'_'+this.toolbar[i][j].name}).				style({height:px(this.bt_height)}).appendTo(p);        	}        }	},	_createArea:function(){		$().create('div').        param({id:this.id+'_area'}).        style({width:px(this.width-2), height:px(this.height-25*this.toolbar.length-(this.isFooter?27:0)-2), border:'1px solid gray'}).        appendTo(this.id);        try{        	$().create('iframe').        	param({id:this.id+'_ifr1', frameBorder:0, width:"100%", height:"100%"}).        	style({backgroundColor:"white", border:px(0), overflow:'scroll'}).        	appendTo(this.id+'_area');        }catch(e){        	var str = '<form style="padding:0px; margin:0px;" onsubmit="return false;"><iframe id="'+this.id+'_ifr1" name="'+this.id+'_ifr1" style="background-color:#FFFFFF;" frameborder=0 width=100% height=100% scrolling="yes"></iframe></form>';        	$(this.id+'_area').el.innerHTML=str;        }	},	_createCodeED:function(){		$().create('textarea').        param({id:this.id+'_textarea'}).        style({width:px(this.width-4), height:px(this.height-29), display:'none', margin:px(0), padding:px(0)}).        appendTo(this.id);	},    _createFooter:function(){    	$().create('div').        param({id:this.id+'_footer'}).        style({width:px(this.width), height:px(25)}).        appendTo(this.id);        $().create('div').        param({id:this.id+'_design', innerHTML:'Design',onmouseover:this._events._over, onclick:function(){this.js_class._design();},					onmouseout:this._events._out, js_class:this, align:'center', className:this.css+'_footer_bt'}).        style({width:px(60), height:px(23), cursor:'default'}).        appendTo(this.id+'_footer');        $().create('div').        param({id:this.id+'_code', innerHTML:'Code',onmouseover:this._events._over, onclick:function(){this.js_class._code();},					onmouseout:this._events._out, js_class:this, align:'center', className:this.css+'_footer_bt'}).        style({width:px(60), height:px(23), cursor:'default'}).        appendTo(this.id+'_footer');    },    _actionSelectEditor:function(){    	var _self_ = this;		return function(){			var e = (arguments[0]||window.event);			try{				if (window.getSelection)				{ var selected_obj = $(_self_.id+'_ifr1').el.contentWindow.window.getSelection().focusNode;}				else if (document.getSelection)				{ var selected_obj = $(_self_.id+'_ifr1').el.contentWindow.document.getSelection().focusNode;}				else if (document.selection)				{ var selected_obj = $(_self_.id+'_ifr1').el.contentWindow.document.selection.createRange().parentElement();}            }catch (e){return;}		        var current_tag = selected_obj;				var previous_tagName = selected_obj.tagName;				_self_._reinitHead();				while(previous_tagName != "BODY"){		        	if(previous_tagName == "B" || previous_tagName == "STRONG") _self_._changeActionBt('bold');		        	else if(previous_tagName == "I" || previous_tagName == "EM") _self_._changeActionBt('italic');					else if(previous_tagName == "U")  _self_._changeActionBt('underline');					else if(previous_tagName == "STRIKE")_self_._changeActionBt('strikethrough');					else if(previous_tagName == "SUP")_self_._changeActionBt('superscript');					else if(previous_tagName == "SUB")_self_._changeActionBt('subscript');					else if(previous_tagName == "A")_self_._changeActionBt('insertlink');					else if(previous_tagName == "DIV" || previous_tagName == "P"){						var st1 = current_tag.style.textAlign;						var st0 = current_tag.getAttribute('align');						if (st0 == 'left' || st1 == 'left') _self_._changeActionBt('justifyleft');						else if (st0 == 'center' || st1 == 'center') _self_._changeActionBt('justifycenter');						else if (st0 == 'right' || st1 == 'right') _self_._changeActionBt('justifyright');						else if (st0 == 'justify' || st1 == 'justify') _self_._changeActionBt('justifyfull');					}					else if (previous_tagName == "SPAN"){						if (current_tag.style.textDecoration == 'underline')  _self_._changeActionBt('underline');						if (current_tag.style.fontStyle == 'italic')  _self_._changeActionBt('italic');						if (current_tag.style.fontWeight == 'bold')  _self_._changeActionBt('bold');						if (current_tag.style.textDecoration == 'line-through')  _self_._changeActionBt('strikethrough');					}		        	current_tag = current_tag.parentNode;		        	previous_tagName = current_tag.tagName;				}		};    },	_changeActionBt:function(bt){        var o = $(this.id+bt).el;        if (!o) return;        o.onmouseout = this._events._void;        o.style.backgroundColor='#C3C3C3';	},	_events:{		_out:function(){this.style.backgroundColor='transparent'; },		_over:function(){this.style.backgroundColor='#C3C3C3'; if (this.js_class && this.childNodes.length<2)this.js_class._dropDDMenu();},		_mouse_down:function(){			this.js_class._dropDDMenu();			switch(this._type_){				case 0: this.js_class._action(this.action); break;				case 1: this.js_class._formatBlock(this.action); break;				case 2: this.js_class['_'+this.action](); break;				case 3: this.js_class['_udf_'+this.action](this); break; // user define function			};		},		_void:function(){eventStop((arguments[0]||window.event)); return void 0;},		_stop:function(){ if ((arguments[0]||window.event).keyCode == 13){eventStop((arguments[0]||window.event));}}	},	_reinitHead:function(){		for(var i=$(this.id+'_head').el.firstChild; i!=null; i=i.nextSibling){			for(var j=i.firstChild; j!=null; j=j.nextSibling){				j.onmouseout = this._events._out;				j.style.backgroundColor='transparent';			}		}	},	_action:function(comand) {		$(this.id+'_ifr1').el.contentWindow.document.execCommand(comand, false, null);		this._changeActionBt(comand);		(this._actionSelectEditor())();	},	_insertHTML:function(html) {		if (document.all) {			var oRng = $(this.id+'_ifr1').el.contentWindow.document.selection.createRange();			oRng.pasteHTML(html);			oRng.collapse(false);			oRng.select();		}		else $(this.id+'_ifr1').el.contentWindow.document.execCommand('insertHTML', false, html);		(this._actionSelectEditor())();	},	_formatBlock:function(comand){		if (!$(this.id+'_ifr1').el.contentWindow.document.execCommand("formatblock", false, comand))		$(this.id+'_ifr1').el.contentWindow.document.execCommand("formatblock", true, '<'+comand+'>');		(this._actionSelectEditor())();	},	_undo:function(){		try		{			$(this.id+'_ifr1').el.contentWindow.document.execCommand ("undo", false, null);			$(this.id+'_ifr1').el.contentWindow.focus();		}		catch (e)		{			alert ("Not supported.");		}	},	_redo:function(){		try		{			$(this.id+'_ifr1').el.contentWindow.document.execCommand ("redo", false, null);			$(this.id+'_ifr1').el.contentWindow.focus();		}		catch (e)		{			alert ("Not supported.");		}	},	_insertlink:function(){		if (window.getSelection) var selected_obj = $(this.id+'_ifr1').el.contentWindow.window.getSelection().focusNode;		else if (document.getSelection) var selected_obj = $(this.id+'_ifr1').el.contentWindow.document.getSelection().focusNode;		else if (document.selection) var selected_obj = $(this.id+'_ifr1').el.contentWindow.document.selection.createRange().parentElement();		var current_tag = selected_obj;		var is_link = false;		while(current_tag.tagName != "HTML"){			if (current_tag.tagName == "A") {				var url = unescape(current_tag.href)				var target = current_tag.target?unescape(current_tag.target):'_self';				is_link = true;				break;			}			current_tag = current_tag.parentNode;		}		var url = arguments[0]||prompt('Введите ссылку (URL)\nпример : http://www.romanborsuk.com/', (url||''));		if (this._trim(url)=='' || !url) return ;		if (!is_link) $(this.id+'_ifr1').el.contentWindow.document.execCommand("createlink", false, url);		while(current_tag.tagName != "HTML"){			if (current_tag.tagName == "A") {				current_tag.href = url;				current_tag.target = (target||'_self');				break;			}			current_tag = current_tag.parentNode;		}	},	_unlink:function(){		$(this.id+'_ifr1').el.contentWindow.document.execCommand('unlink', false, null);		$(this.id+'_ifr1').el.contentWindow.focus();	},	__insertimage:function(){		var o =  arguments[0]||{};		var src = o.src||prompt('Урл картинки');		if (src=='' || !src) return $(this.id+'_ifr1').el.contentWindow.focus();		this._insertHTML('<img src="'+src+'" />');		$(this.id+'_ifr1').el.contentWindow.focus();	},    _design:function(){    	this.loadData($(this.id+'_textarea').el.value);    	$(this.id+'_head').show();    	$(this.id+'_area').show();    	$(this.id+'_textarea').hide();    	this.status =0;    	this._reinit();    	$(this.id+'_ifr1').el.contentWindow.focus();    },    _code:function(){    	this.getData();    	this.status =1;    	$(this.id+'_head').hide();    	$(this.id+'_area').hide();    	$(this.id+'_textarea').show().param({value:this._data}).el.focus();    },	_close:function(){		if (!$(this.id).el) return;		for(var i in this._childObjects){			if (typeof this._childObjects[i] == 'object' && typeof this._childObjects[i]._close == 'function'){this._childObjects[i]._close();}		}		$(this.id).drop();		if (window[this.class_name]) delete(window[this.class_name]);		return;	},	_resize:function(){		var s = $(this.parent).size();		var width = arguments[0]||s.width;		var height = arguments[1]||s.height;		this.width = (width>=this.min_width)?width:this.min_width;		this.height = (height>=this.min_height)?height:this.min_height;		this.onBeforResize();        $(this.id).style({width:px(this.width), height:px(this.height)});        $(this.id+'_head').style({width:px(this.width), height:px(25*this.toolbar.length)});        $(this.id+'_area').style({width:px(this.width-2), height:px(this.height-25*this.toolbar.length-(this.isFooter?27:0)-2)});        if (this.isFooter) $(this.id+'_footer').style({width:px(this.width)});        $(this.id+'_textarea').style({width:px(this.width-4), height:px(this.height-29)})		if (this.status ==0)this._reinit();		this.onAfterResize();	},	_reinit:function(){		this.loadData(this._data);		$(this.id+'_ifr1').el.contentWindow.document.designMode = "on";		if (document.removeEventListener){			$(this.id+'_ifr1').el.contentWindow.document.removeEventListener("keydown", this._actionSelectEditor(), true);			$(this.id+'_ifr1').el.contentWindow.document.removeEventListener("click", this._actionSelectEditor(), true);			$(this.id+'_ifr1').el.contentWindow.document.removeEventListener("mouseup", this._actionSelectEditor(), true);		}		else{			$(this.id+'_ifr1').el.contentWindow.document.detachEvent("onkeydown", this._actionSelectEditor());			$(this.id+'_ifr1').el.contentWindow.document.detachEvent("onclick", this._actionSelectEditor());			$(this.id+'_ifr1').el.contentWindow.document.detachEvent("onmouseup", this._actionSelectEditor());		}		if (document.addEventListener) {			//$(this.id+'_ifr1').el.contentWindow.document.execCommand("useCSS", false, null);			$(this.id+'_ifr1').el.contentWindow.document.addEventListener("keydown", this._actionSelectEditor(), true);			$(this.id+'_ifr1').el.contentWindow.document.addEventListener("click", this._actionSelectEditor(), true);			$(this.id+'_ifr1').el.contentWindow.document.addEventListener("mouseup", this._actionSelectEditor(), true);		}		else{			$(this.id+'_ifr1').el.contentWindow.document.attachEvent("onkeydown", this._actionSelectEditor());			$(this.id+'_ifr1').el.contentWindow.document.attachEvent("onclick", this._actionSelectEditor());			$(this.id+'_ifr1').el.contentWindow.document.attachEvent("onmouseup", this._actionSelectEditor());		}	},    _createDDMenu:function(to){    	var par = $().create('div').param({id:this.id+'_dd', _cc:1})    	.style({position:'relative',width:px(0), height:px(0), left:px(0),top:px(0), fontSize:0}).appendTo(to).el;    	var w = arguments[1]||(this.width - parseInt(par.offsetLeft)-25);    	var el = $().create('div').    	param({js_class:this, _cc:1,    		onmousedown:function(){var e= (arguments[0]||window.event);	this.js_class._applySelect((e.target||e.srcElement));},    		onmouseout:function(){    			var e= (arguments[0]||window.event);    			var to = (e.relatedTarget||e.toElement);    			if (!to._cc && this.js_class) this.js_class._dropDDMenu();    		}    	}).    	style({position:'absolute', width:px(w), border:'1px solid gray',backgroundColor:'#EBEBEB', padding:px(5), left:px(0),top:px(0)}).    	appendTo(par).el;    	if (arguments[2]) $(el).style({height:px(arguments[2]), overflow:'auto'});    	return el    },    _fontfamaly:function(){    	var sel = this._createDDMenu(this.id+'fontfamaly', 130);    	for(var i=0; i<this.fstyle.length; i++){			$().create('div').			param({_st:this.fstyle[i],_comand:'fontname', innerHTML:this.fstyle[i], _cc:1,				onmouseover:function(){this.style.backgroundColor='#C3C3C3';},				onmouseout:function(){var e= (arguments[0]||window.event); this.style.backgroundColor='transparent'; if (!(e.relatedTarget||e.toElement)._cc && this.js_class) this.js_class._dropDDMenu();}			}).			style({fontFamily:this.fstyle[i], fontSize:px(16), cursor:'default'}).			appendTo(sel);    	}    },    _fontsize:function(){    	var sel = this._createDDMenu(this.id+'fontsize', 30);    	for(var i=0; i<this.fsize.length; i++){			$().create('div').			param({js_class:this, _cc:1,_st:i+1,_comand:'fontsize', innerHTML:i+1,				onmouseover:function(){this.style.backgroundColor='#C3C3C3';},				onmouseout:function(){var e= (arguments[0]||window.event); this.style.backgroundColor='transparent'; if (!(e.relatedTarget||e.toElement)._cc && this.js_class) this.js_class._dropDDMenu();}			}).			style({fontSize:px(this.fsize[i]), cursor:'default'}).			appendTo(sel);    	}    },    _forecolor:function(){    	var sel = this._createDDMenu(this.id+'forecolor', 300);	    for (var s = 0; s<52; s+=4){	    	var max = 255-s*2.5;	    	var domax = 254-s*2.5;	    	var min = s*2.5;	    	var r= max;	    	var g=b=min;	    	var step = 51-s*1;	    	for (var i=0; i<30; i++){	    			 if (b<min+1 && r>domax && g<max) g+=step;	    		else if (b<min+1 && g>domax && r>min) r -=step;	    		else if (r<min+1 && g>domax && b<max) b +=step;	    		else if (r<min+1 && g>min && b>domax) g-=step;	    		else if (g<min+1 && r<domax && b>domax) r+=step;	    		else if (g<min+1 && r>domax && b>min) b-=step;	    		var color = this._toHEX(r,g ,b);	    		$().create('div').				param({_st:color, _cc:1,_comand:'forecolor', className:'color_el'}).				style({backgroundColor:color, cursor:'default', width:px(10), height:px(10), fontSize:px(0)}).				appendTo(sel);	    	}	  	}        for(var i=0; i<256; i+=7){        	var color = this._toHEX(i,i ,i);    		$().create('div').			param({_st:color, _cc:1,_comand:'forecolor', className:'color_el'}).			style({backgroundColor:color, cursor:'default', width:px(8), height:px(20), fontSize:px(0)}).			appendTo(sel);        }    },    _hilitecolor:function(){    	var sel = this._createDDMenu(this.id+'hilitecolor', 300);	    for (var s = 0; s<52; s+=4){	    	var max = 255-s*2.5;	    	var domax = 254-s*2.5;	    	var min = s*2.5;	    	var r= max;	    	var g=b=min;	    	var step = 51-s*1;	    	for (var i=0; i<30; i++){	    			 if (b<min+1 && r>domax && g<max) g+=step;	    		else if (b<min+1 && g>domax && r>min) r -=step;	    		else if (r<min+1 && g>domax && b<max) b +=step;	    		else if (r<min+1 && g>min && b>domax) g-=step;	    		else if (g<min+1 && r<domax && b>domax) r+=step;	    		else if (g<min+1 && r>domax && b>min) b-=step;	    		var color = this._toHEX(r,g ,b);	    		$().create('div').				param({_st:color, _cc:1,_comand:'hilitecolor', className:'color_el'}).				style({backgroundColor:color, cursor:'default', width:px(10), height:px(10), fontSize:px(0)}).				appendTo(sel);	    	}	  	}        for(var i=0; i<256; i+=7){        	var color = this._toHEX(i,i ,i);    		$().create('div').			param({_st:color, _cc:1,_comand:'hilitecolor', className:'color_el'}).			style({backgroundColor:color, cursor:'default', width:px(8), height:px(20), fontSize:px(0)}).			appendTo(sel);        }    },    _toHEX:function(r,g,b){    	cr =(r).toString(16).length==1?'0'+(r).toString(16):(r).toString(16);    	cg =(g).toString(16).length==1?'0'+(g).toString(16):(g).toString(16);    	cb =(b).toString(16).length==1?'0'+(b).toString(16):(b).toString(16);    	return '#'+cr+cg+cb;    },    _applySelect:function(o){    	switch (o._comand){    		case 'fontname':    			$(this.id+'_ifr1').el.contentWindow.document.execCommand("fontname", false, o._st.toString());    			$(this.id+'fontfamaly').el.firstChild.value = o._st;                $(this.id+'fontfamaly').el.firstChild.style.fontFamily=o._st;                this._dropDDMenu();    			break;    		case 'fontsize'	:    			$(this.id+'_ifr1').el.contentWindow.document.execCommand("fontsize", false, o._st.toString());    			$(this.id+'fontsize').el.firstChild.value = o._st;                this._dropDDMenu();    			break;    		case 'forecolor':    			$(this.id+'_ifr1').el.contentWindow.document.execCommand("forecolor", false, o._st.toString());    			$(this.id+'forecolor').el.firstChild.style.color = o._st;                this._dropDDMenu();    			break;            case 'hilitecolor':    			try{$(this.id+'_ifr1').el.contentWindow.document.execCommand("hilitecolor", false, o._st.toString());}    			catch(e){$(this.id+'_ifr1').el.contentWindow.document.execCommand("backcolor", false, o._st.toString());}    			$(this.id+'hilitecolor').el.style.backgroundColor = o._st;                this._dropDDMenu();    			break;    		 case 'insertimage':    			this.__insertimage(o);                this._dropDDMenu();    			break;    		case 'addimage':    			this._dropDDMenu();    			this._loadImage();    			break;    		default: break;    	};    	(this._actionSelectEditor())();    },    _dropDDMenu:function(){    	if ($(this.id+'_dd').el) $(this.id+'_dd').drop();    },    _bordersApply:function(){    	var sel = this._createDDMenu(this.id+'borders', 140);    	sel.onmouseout = this._events._void;    	sel.onmousedown = this._events._void;    	sel.style.top = px(30);        var bdr = [{id:'_bl'}, {id:'_bt'}, {id:'_br'}, {id:'_bb'}];        $().create('div').		param({_cd:1, _cc:1, className:'color_el', align:'right', innerHTML:'[x]',onmousedown:function(){$(this.parentNode.parentNode).drop()}}).		style({cursor:'default', width:px(140), height:px(15), fontSize:px(10), color:'black'}).		appendTo(sel);        for(var i=0; i<bdr.length; i++){	    	$().create('div').param({js_class:this, _cc:1, className:'color_el', id:this.id+bdr[i].id}).	    	style({width:px(20), height:px(20), border:'1px solid gray',backgroundColor:'#EBEBEB'}).	    	appendTo(sel);	        $().create('div').param({js_class:this, _cc:1, className:'color_el'}).	    	style({width:px(60), height:px(20), border:'1px solid gray',backgroundColor:'#EBEBEB'}).	    	appendTo(sel);	    	$().create('div').param({js_class:this, _cc:1, className:'color_el'}).	    	style({width:px(30), height:px(20), border:'1px solid gray',backgroundColor:'#EBEBEB'}).	    	appendTo(sel);	    	// color	    	var _self_ = this;	    	var fc = function(){	    		var e= (arguments[0]||window.event);	    		var par = $().create('div').param({id:_self_.id+'_d2', _cd:1, _cc:1})		    	.style({position:'relative',width:px(0), height:px(0), left:px(0),top:px(0), fontSize:0}).appendTo(this).el;		    	var sel = $().create('div').		    	param({ _cd:1, _cc:1,		    		onmousedown:function(){		    			var e= (arguments[0]||window.event);		    			if ((e.target||e.srcElement)._st) $(this.parentNode.parentNode).style({backgroundColor:(e.target||e.srcElement)._st});		    			$(this.parentNode.parentNode).empty();		    			eventStop(e);		    			return void 0;		    		}		    	}).		    	style({position:'absolute', width:px(300), border:'1px solid gray',backgroundColor:'#EBEBEB', padding:px(5), left:px(0),top:px(22)}).		    	appendTo(par).el;		    	$().create('div').					param({_cd:1, _cc:1, className:'color_el', align:'right', innerHTML:'[x]'}).					style({cursor:'default', width:px(300), height:px(15), fontSize:px(10), color:'black'}).					appendTo(sel);		    	for (var s = 0; s<52; s+=4){				    	var max = 255-s*2.5;				    	var domax = 254-s*2.5;				    	var min = s*2.5;				    	var r= max;				    	var g=b=min;				    	var step = 51-s*1;					    for (var i=0; i<30; i++){					    			 if (b<min+1 && r>domax && g<max) g+=step;					    		else if (b<min+1 && g>domax && r>min) r -=step;					    		else if (r<min+1 && g>domax && b<max) b +=step;					    		else if (r<min+1 && g>min && b>domax) g-=step;					    		else if (g<min+1 && r<domax && b>domax) r+=step;					    		else if (g<min+1 && r>domax && b>min) b-=step;					    		var color = _self_._toHEX(r,g ,b);					    		$().create('div').								param({_st:color, _cd:1, _cc:1,_comand:'hilitecolor', className:'color_el'}).								style({backgroundColor:color, cursor:'default', width:px(10), height:px(10), fontSize:px(0)}).								appendTo(sel);					    	}				        }				for(var i=0; i<256; i+=7){		        	var color = _self_._toHEX(i,i ,i);		    		$().create('div').					param({_st:color, _cd:1, _cc:1,_comand:'hilitecolor', className:'color_el'}).					style({backgroundColor:color, cursor:'default', width:px(8), height:px(20), fontSize:px(0)}).					appendTo(sel);				}                eventStop(e);		    	return void 0;	    	};	    	$().create('div').param({js_class:this, _cc:1, _cd:1, className:'color_el', id:this.id+bdr[i].id+'_cl',	    		onmousedown:fc	    	}).	    	style({width:px(20), height:px(20), border:'1px solid gray',backgroundColor:'#EBEBEB'}).	    	appendTo(sel);    	}    },    _borders:function(){    	try{			if (window.getSelection)			{ var selected_obj = $(this.id+'_ifr1').el.contentWindow.window.getSelection().focusNode;}			else if (document.getSelection)			{ var selected_obj = $(this.id+'_ifr1').el.contentWindow.document.getSelection().focusNode;}			else if (document.selection)			{ var selected_obj = $(this.id+'_ifr1').el.contentWindow.document.selection.createRange().parentElement();}   		}catch (e){alert(1); return;}   		var curtag = selected_obj;   		while(curtag.tagName != "BODY" && curtag.tagName != "DIV" && curtag.tagName != "P"){   			curtag = curtag.parentNode;   		}   		if (curtag.tagName != "DIV" && curtag.tagName != "P"){   			$(this.id+'_ifr1').el.contentWindow.document.execCommand('justifyfull', false, null);			try{				if (window.getSelection)				{ var selected_obj = $(this.id+'_ifr1').el.contentWindow.window.getSelection().focusNode;}				else if (document.getSelection)				{ var selected_obj = $(this.id+'_ifr1').el.contentWindow.document.getSelection().focusNode;}				else if (document.selection)				{ var selected_obj = $(this.id+'_ifr1').el.contentWindow.document.selection.createRange().parentElement();}	   		}catch (e){alert(2); return;}	   		var curtag = selected_obj;	   		while(curtag.tagName != "BODY" && curtag.tagName != "DIV" && curtag.tagName != "P"){	   			curtag = curtag.parentNode;	   		}   		}   		if (!parseInt(curtag.style.borderWidth)) curtag.style.border = "1px solid black";   		else curtag.style.borderWidth = px(0) ;    },    _smile:function(){    	var sel = this._createDDMenu(this.id+'smile', 150);    	for(var i=0; i<this.allSmile.length; i++)    		$().create('img').    		param({src:this.smileFolders+this.allSmile[i], _cc:1,_comand:'insertimage', className:'color_el', border:2,    			onmouseover:function(){this.style.borderColor='#000';},    			onmouseout:function(){this.style.borderColor='#E8E8E8';}    		}).    		style({cursor:'default', margin:px(3),borderColor:'#E8E8E8'}).			appendTo(sel);    },    _insertimage:function(){    	var sel = this._createDDMenu(this.id+'insertimage', 300);    	$().create('img').    		param({src:this.baseImgPathEditor + '/loading.gif', _cc:1}).    		style({cursor:'default', margin:px(10),borderColor:'#E8E8E8'}).			appendTo(sel);		Ajax.post(this.imgLoadURL, {tt:0},{			onSuccess:function(req){				var img = req.responseText.split('|');				$(sel).empty();				$().create('input').	    		param({_cc:1, border:2,type:'button', value:'Add image', _comand:'addimage'}).	    		style({cursor:'default', margin:px(3),borderColor:'#E8E8E8', display:'block'}).				appendTo(sel);				var r = $().create('table').param({ _cc:1,_comand:'--', width:300, height:175}).appendTo(sel).el.insertRow(0);                r._cc = 1;				var list = $().create('div').		    	param({_cc:1,_comand:'--'}).		    	style({width:px(150),height:px(175), overflowY:'auto', overflowX:'hidden',textAlign:'left'}).		    	appendTo(r.insertCell(0)).el;                r.cells[0]._cc = 1;		    	var view = $().create('div').		    	param({_cc:1,_comand:'--'}).		    	style({width:px(140),height:px(175), border:'1px solid gray',overflow:'hidden'}).		    	appendTo(r.insertCell(1)).el;                r.cells[1]._cc = 1;				for(var i=0; i<img.length; i++)					if (img[i]!=''){						$().create('span').			    		param({ _cc:1,_comand:'insertimage', border:2, innerHTML:' image №'+(i+1),  src:img[i],			    			onmouseover:function(){			    				this.style.backgroundColor='#AEAEAE';			    				$(view).empty();			    				var img = $().create('img').param({ src:this.src, _cc:1, _comand:'insertimage',			    					onload:function(){			    						var _self = this;			    						var s = $(_self).size();			    						if (s.width >= s.height)			    							if (s.width >= 140) {_self.style.width = px(140); _self.style.height = px(s.height*140/s.width);}			    						else			    							if (s.height >= 150) {_self.style.height = px(140); _self.style.width = px(s.width*140/s.height);}			    					}			    				}).			    				appendTo(view). el;			    				setTimeout(function(){			    						var s = $(img).size();			    						if (s.width >= s.height)			    							if (s.width >= 140) {img.style.width = px(140); img.style.height = px(s.height*140/s.width);}			    						else			    							if (s.height >= 150) {img.style.height = px(140); img.style.width = px(s.width*140/s.height);}			    				}, 100);			    			},			    			onmouseout:function(){this.style.backgroundColor='';}			    		}).			    		style({cursor:'pointer', width:px(130), display:'block', color:'black', fontSize:px(14)}).  //						appendTo(list);					}			}		})    },    _loadImage:function(){    	$().create('div').param({id:this.id+'_block'}).    	style({position:'relative', left:px(0),top:px(-this.height),width:px(this.width), height:px(this.height), backgroundColor:'#000'}).    	opacity(50).appendTo(this.id);    	var str = '<iframe id="'+this.id+'_upload" frameborder=0 scrolling="no" width="400" height="45" style="position:relative; top:'+(-(this.height/2)-20)+'px; left:'+(this.width/2-200)+'px"></iframe>';    	$().create('div').param({id:this.id+'_block_fr', innerHTML:str}).    	style({position:'relative', left:px(0),top:px(-this.height),width:px(this.width), height:px(this.height)}).    	appendTo(this.id);    	var str2 = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'+			'<body style="margin:0; padding:0; margin-left:5px;"><b>Загрузка файла</b> <br />'+			'<form name="" action="'+this.imgToLoadSrc+'"  enctype="multipart/form-data" method="post" style="margin:0; padding:0;">'+			'<input name="frid" type="hidden" value="'+this.id+'_upload"><input name="file" type="file" value=""><input type="submit" value="Send"><input id="close" type="button" value="Закрыть">'+			'</form></body>';    	$(this.id+'_upload').el.contentWindow.document.open();		$(this.id+'_upload').el.contentWindow.document.write(str2);		$(this.id+'_upload').el.contentWindow.document.close();		var _self = this;		$(this.id+'_upload').el.contentWindow.document.getElementById("close").onclick=function(){_self._closeUpload();};    },    _closeUpload:function(){    	$(this.id+'_block_fr').drop();    	$(this.id+'_block').drop();    },    //outer function	loadData:function(){		if (arguments[0]) this._data = arguments[0];		var css = '';		if (this._urlcss.length) css = this._urlcss;		$(this.id+'_ifr1').el.contentWindow.document.open();		$(this.id+'_ifr1').el.contentWindow.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><style type=\"text/css\">html {height:100%;background-color:#FFFFFF;} body{padding:0px;margin:0px; margin-left:7px;margin-right:7px;background-color:#FFFFFF;}" + css + "</style></head><body>" + this._data + "</body></html>");		$(this.id+'_ifr1').el.contentWindow.document.close();	},	getData:function(){		this._data = $(this.id+'_ifr1').el.contentWindow.document.body.innerHTML;		return this._data;	},	//outer events	onAfterResize:function(){},	onBeforResize:function(){}});
