var set_act;
//utworzenie głównej zmiennej
var WYSIWYG = {
	settings: function() {
		this.imgpath="jscript/wysiwyg/images/";
		this.stylefile="jscript/wysiwyg/style/wysiwyg.css";
		this.poppath="jscript/wysiwyg/popup/";
		this.uploadpath="uploader.php";
	},
	attach: function(id, settings) {
		if(id!="all") { addEvent(window, "load", function gen() { WYSIWYG.create(id,settings); }); }
		else { addEvent(window, "load", function gen() { WYSIWYG.create_alls(settings); }); }
		set_act=settings;
	},
	create_alls: function(settings) {
		var areas=document.getElementsByTagName("textarea");
		for(var ra=0; ra<areas.length; ra++)
		{ if(areas[ra].id!="" && areas[ra].id.substring(0,6)!="cache_") { WYSIWYG.create(areas[ra].id, settings); } }
	},
	create: function(id, settings) {
		addCss(document, settings.stylefile);
		var textarea = document.getElementById(id);
		//wygaszenie textarea
		textarea.style.display="none";
		//utworzenie warsty głównej
		var warstwa_gl=document.createElement("div");
		warstwa_gl.id="layer_wysiwyg_"+id;
		warstwa_gl.className="wysiwyg_glowny";
		warstwa_gl.style.background=settings.background;
		warstwa_gl.style.width=settings.width;
		warstwa_gl.style.height=settings.height;
		//utworzenie rzędów
		for(var b=0; b<settings.icons.length; b++)
		{
			var line_one=document.createElement("div");
			line_one.className="wysiwyg_line";
			for(var a=0; a<settings.icons[b].length; a++)
			{
				var tmp=addIcon(this.toolbox, settings.imgpath, settings.icons[b][a], id, settings);
				if(tmp) { line_one.appendChild(tmp); }
			}
			warstwa_gl.appendChild(line_one);
		}
		//utworzenie pola tekstowego
		var warstwa_tx=document.createElement("div");
		warstwa_tx.id="layer_wysiwyg2_"+id;
		warstwa_tx.style.width="100%";
		warstwa_tx.style.height=(settings.height.replace("px","")-settings.icons.length*25)+"px";
		warstwa_tx.style.background=settings.background;
		var frame=document.createElement("iframe");
		frame.id="wysiwyg_"+id;
		frame.className="wysiwyg_frame";
		frame.style.width="99%"
		frame.style.height="99%"
		warstwa_tx.appendChild(frame);
		warstwa_gl.appendChild(warstwa_tx);
		//utworzenie cache
		var cache=document.createElement('textarea');
		cache.id="cache_"+id;
		cache.style.display="none";
		warstwa_gl.appendChild(cache);
		//dodanie wszystkiego do wyglądu
		textarea.parentNode.appendChild(warstwa_gl);
		//przepisanie tekstu i wejście w tryb edycji
		var content=textarea.value;
		var doc=document.getElementById("wysiwyg_"+id).contentWindow.document;
		doc.open();
	    doc.write(content);
	    doc.close();
		setAttribute(doc.body, "style", settings.defaultstyle);
		if (doc.body.contentEditable) { doc.body.contentEditable = true; }
		else { doc.designMode = "on"; }
		addCss(view_w(id).document, settings.stylefile);
		//dodanie funkcji przepisania przy wysłaniu
		var ele=document.getElementById(id);
		while(ele.nodeName.toLowerCase()!="form" && ele.nodeName.toLowerCase()!="body")
		{ ele=ele.parentNode; }
		if(ele.nodeName.toLowerCase()=="form")
		{ addEvent(ele, "submit", function update_wyswig() { przepisz(id) }); }		
	},
	//tabela konfiguracji paska
	toolbox: {
		"pogrubienie":			['Bold',				lang_pogrubienie,			   		'bold.gif',			   'bold_on.gif'],
		"pochylenie":			['Italic',				lang_pochylenie,			 	'italics.gif',			'italics_on.gif'],
		"podkreslenie":			['Underline',			lang_podkreslenie,		  	'underline.gif',		  'underline_on.gif'],
		"przekreslenie":		['Strikethrough',		lang_przekreslenie,	  	'strikethrough.gif',	  'strikethrough_on.gif'],
		"przerwa":				['',					'',				   		'seperator.gif',		  'seperator.gif'],
		"index_dolny":			['Subscript',			lang_index_dolny,		  	'subscript.gif',		  'subscript_on.gif'],
		"index_gorny":			['Superscript',			lang_index_gorny,			'superscript.gif',		'superscript_on.gif'],
		"do_lewej":				['Justifyleft',			lang_do_lewej,			'justify_left.gif',	   'justify_left_on.gif'],
		"do_srodka":			['Justifycenter',		lang_do_srodka,	  	'justify_center.gif',	 'justify_center_on.gif'],
		"do_prawej":			['Justifyright',		lang_do_prawej,	   		'justify_right.gif',	  'justify_right_on.gif'],
		"wyjustowanie":			['Justifyfull',			lang_wyjustowanie, 			'justify_justify.gif', 	  'justify_justify_on.gif'], 
		"lista_punkt":			['InsertUnorderedList',	lang_lista_punkt,	'list_unordered.gif',	 'list_unordered_on.gif'],
		"lista_numer":			['InsertOrderedList',	lang_lista_numer,  	'list_ordered.gif',	   'list_ordered_on.gif'],
		"zm_wciecie":			['Outdent',				lang_zm_wciecie,				'indent_left.gif',		'indent_left_on.gif'],
		"zw_wciecie":			['Indent',				lang_zw_wciecie,			 	'indent_right.gif',	   'indent_right_on.gif'],
		"wytnij":				['Cut',					lang_wytnij,					'cut.gif',				'cut_on.gif'],
		"kopiuj":				['Copy',				lang_kopiuj,			   		'copy.gif',			   'copy_on.gif'],
		"wklej":				['Paste',				lang_wklej,			  	'paste.gif',			  'paste_on.gif'],
		"kolor_text":			['ForeColor',			lang_kolor_text,		  	'forecolor.gif',		  'forecolor_on.gif'],
		"kolor_tlo":			['BackColor',			lang_kolor_tlo,		  	'backcolor.gif',		  'backcolor_on.gif'],
		"wstecz":				['Undo',				lang_wstecz,			   		'undo.gif',			   'undo_on.gif'],
		"dalej":				['Redo',				lang_dalej,			   		'redo.gif',			   'redo_on.gif'],
		"tabela":				['InsertTable',			lang_tabela,			'insert_table.gif',	   'insert_table_on.gif'],
		"grafika":				['InsertImage',			lang_grafika,			'insert_picture.gif',	 'insert_picture_on.gif'],
		"link":					['CreateLink',			lang_link,		 	'insert_hyperlink.gif',   'insert_hyperlink_on.gif'],
		"html":					['ViewSource',			lang_html,		 	'view_source.gif',		'view_source_on.gif'],
		"text":					['ViewText',			lang_text,		   	'view_text.gif',		  'view_text_on.gif'],
		"help":					['Help',				lang_help,			   		'help.gif',			   'help_on.gif'],
		"czcionka":				['FontName',			lang_czcionka,			'select_font.gif',		'select_font_on.gif'],
		"rozmiar":				['FontSize',			lang_rozmiar,			'select_size.gif',		'select_size_on.gif'],
		"naglowek":				['FormatBlock',			lang_naglowek,			'select_heading.gif',	 'select_heading_on.gif'],
		"podglad":				['Preview',				lang_podglad,	   	 		'preview.gif',			  'preview_on.gif'],
		"drukuj":				['Print',				lang_drukuj,	   	 	 	'print.gif',			  'print_on.gif'],
		"usun_format":			['RemoveFormat',		lang_usun_format,		'remove_format.gif',	  'remove_format_on.gif'],
		"usun":					['Delete',				lang_usun,					'delete.gif',	 		  'delete_on.gif'],
		"zapisz":				['Save',				lang_zapisz,			'save.gif', 			  'save_on.gif'],
		"orginal":				['Return',				lang_orginal,	'return.gif', 			  'return_on.gif'],
		"max":					['Maximize',			lang_max,		'maximize.gif', 		  'maximize_on.gif']
	}
	


}
//odczytanie panelu wysiwyg'a
function view_w(id) { return document.getElementById("wysiwyg_"+id).contentWindow; }
//dodawanie zdarzenia do objektu
function addEvent(obj, event, fuct)
{
	if (obj.attachEvent) { obj.attachEvent("on"+event, fuct); }
	else { obj.addEventListener(event, fuct, false); }
}
function removeEvent(obj, event, fuct)
{
	if (obj.attachEvent) { obj.detachEvent("on"+event, fuct); }
	else { obj.removeEventListener(event, fuct, false); }
}
//dołączanie styli
function addCss(doc ,path)
{
	var link = document.createElement("link");
	setAttribute(link, "rel", "stylesheet");
	setAttribute(link, "type", "text/css");
	setAttribute(link, "href", path);
	var heads = doc.getElementsByTagName("head");
	for(var i=0;i<heads.length;i++) { heads[i].appendChild(link); }
}
//dodawanie atrybutów
function setAttribute(node, attr, value)
{
	if(value == null || node == null || attr == null) return;
	if(attr.toLowerCase() == "style")
	{ setStyleAttribute(node, value); }
	else { node.setAttribute(attr, value); }
}
//dodawanie atrybutów styli
function setStyleAttribute(node, style)
{
	if(style == null) return;
	var styles = style.split(";");
	var pos;
	for(var i=0;i<styles.length;i++)
	{
		var attributes = styles[i].split(":");
		if(attributes.length == 2)
		{
			try {
				var attr = trim(attributes[0]);
				while((pos = attr.search(/-/)) != -1)
				{
					var strBefore = attr.substring(0, pos);
					var strToUpperCase = attr.substring(pos + 1, pos + 2);
					var strAfter = attr.substring(pos + 2, attr.length);
					attr = strBefore + strToUpperCase.toUpperCase() + strAfter;
				}
				var value = trim(attributes[1]).toLowerCase();
				node.style[attr] = value;
			} catch (e) { alert(e); }
		}
	}
}
//obcinanie
function trim(str) { return str.replace(/^\s*|\s*$/g,""); }
//dodaj ikone
function addIcon(toolbox, path, icon, id, set)
{
	var icons=document.createElement('div');
	if(toolbox[icon])
	{
		if(icon=="czcionka" || icon=="rozmiar" || icon=="naglowek")
		{
			icons.className="wysiwyg_select";
			var sele=document.createElement('select');
			sele.onchange=function() { commands(id,toolbox[icon][0]); }
			sele.alt=toolbox[icon][1];
			sele.title=toolbox[icon][1];
			sele.id=id+"_"+toolbox[icon][0];
			sele.className="wysiwyg_sel";
			var opt=document.createElement('option');
			if(icon=="czcionka"){ opt.text=lang_sel_f; }
			else if(icon=="rozmiar"){ opt.text=lang_sel_s; }
			else if(icon=="naglowek"){ opt.text=lang_sel_h; }
			sele.appendChild(opt);
			for(var a=0; a<set.sel[icon].length; a++)
			{
				var opt=document.createElement('option');
				opt.text=set.sel[icon][a];
				opt.value=set.sel[icon][a];
				sele.appendChild(opt);
			}
			icons.appendChild(sele);
			return icons;
		}
		else
		{
			icons.className="wysiwyg_icon";
			var img=document.createElement('img');
			img.src=path+toolbox[icon][2];
			img.onmousemove=function() { document.getElementById(this.id).src=path+toolbox[icon][3]; }
			img.onmouseout=function() { document.getElementById(this.id).src=path+toolbox[icon][2]; }
			img.onclick=function() { commands(id,toolbox[icon][0]); }
			img.alt=toolbox[icon][1];
			img.title=toolbox[icon][1];
			img.id=id+"_"+toolbox[icon][0]
			icons.appendChild(img);
			return icons;
		}
	}
	else { return false }
}
//wykonywanie poleceń
function commands(id, cmd)
{
	if(cmd=="ForeColor") { color_wind("f",id); }
	else if(cmd=="BackColor") { color_wind("t",id); }
	else if(cmd=="Cut") { cut_txt(id); }
	else if(cmd=="Copy") { copy_txt(id); }
	else if(cmd=="Paste") { paste_txt(id); }
	else if(cmd=="InsertTable") { new_pop(set_act.poppath+"table.html?id="+id,lang_tabela,810,400); }
	else if(cmd=="InsertImage")
	{
		var tmp=window.location.pathname.split("/");
		var action=pages_up[tmp[tmp.length-1]];
		new_pop(set_act.uploadpath+"?action="+action+"&id="+id,lang_tabela,810,420);
	}
	else if(cmd=="CreateLink") { new_pop(set_act.poppath+"link.html?id="+id,lang_help,410,400); }
	else if(cmd=="Preview") { new_wind(set_act.poppath+"print.html?id="+id,lang_podglad); }
	else if(cmd=="Print") { new_wind(set_act.poppath+"print.html?id="+id+"&p=1",lang_drukuj); }
	else if(cmd=="Save")
	{
		var txt=view_w(id).document.body.innerHTML;
		txt=txt.replace(/&lt;br&gt;<br>/gi,"&lt;br&gt;");
		txt=txt.replace(/&lt;/gi,"<");
		txt=txt.replace(/&gt;/gi,">");
		view_w(id).document.body.innerHTML=txt;
		przepisz(id);
		var ele=document.getElementById(id);
		while(ele.nodeName.toLowerCase()!="form" && ele.nodeName.toLowerCase()!="body")
		{ ele=ele.parentNode; }
		if(ele.nodeName.toLowerCase()=="form")
		{ ele.submit(); }
	}
	else if(cmd=="ViewSource") { txt_to_code(id); }
	else if(cmd=="ViewText") { code_to_txt(id); }
	else if(cmd=="Maximize") { maximize(id); }
	else if(cmd=="Minimize") { minimize(id); }
	else if(cmd=="Help") { new_pop(set_act.poppath+"help.html",lang_help,420,420); }
	else if(cmd=="RemoveFormat") { remove_format(id); }
	else if(cmd=="FontName" || cmd=="FontSize" || cmd=="FormatBlock")
	{
		var option=document.getElementById(id+"_"+cmd).value;
		if(option){ view_w(id).document.execCommand(cmd, false, option); }
	}
	else { view_w(id).document.execCommand(cmd, false, null); }
	view_w(id).focus();
}
//pole kolorów
function color_wind(cmd, id)
{
	try{
	var width = document.getElementById('layer_head').clientWidth;
	var height = document.getElementById('layer_head').clientHeight;
	var res_x=screen.width;
	var res_y=screen.height;
	if(res_y>height){ height=res_y; }
	//główna warstwa
	var layer=document.createElement('div');
	layer.id="color_layer1";
	layer.className='wysiwyg_back';
	layer.style.width=width+"px";
	layer.style.height=height+"px";
	layer.style.top=0+"px";
	layer.style.left=0+"px";
	//narysowanie powłoki z grafiką
	var colors=document.createElement('div');
	colors.id="color_layer2";
	colors.className="wysiwyg_color";
	colors.style.width=(width/2)+"px";
	colors.style.height=(res_y/2)+"px";
	colors.style.top=(res_y/4)*0.75+"px";
	colors.style.left=(width/4)+"px";
	//utworzenie napisu
	header=document.createElement('div');
	header.className="wysiwyg_colorh";
	if(cmd=="f") { header.innerHTML=lang_colf_nag; }
	else { header.innerHTML=lang_colt_nag; }
	colors.appendChild(header);
	//przycisk zamknięcia
	closer=document.createElement('div');
	closer.className="wysiwyg_colorc";
	closer.innerHTML="X";
	closer.onclick=function() { close_color() };
	colors.appendChild(closer);
	//narysowanie tabeli kolorów
	for(var a1=0; a1<4; a1++)
	{
		var row=document.createElement('div');
		row.className="wysiwyg_color_row";
		row.style.left=((width/2)-320)/2+"px";
		row.style.top=(a1*80+40)+"px";
		for(var a2=0; a2<4; a2++)
		{
			var col=document.createElement('div');
			col.className="wysiwyg_color_col";
			for(var a3=0; a3<16; a3++)
			{
				var elr=document.createElement('div');
				elr.className="wysiwyg_color_elr";
				for(var a4=0; a4<16; a4++)
				{
					var el=document.createElement('div');
					el.className="wysiwyg_color_el";
					var colort="#"+dec_to_hex(((a1*4+a2)*256*256+a3*256+a4)*16);
					el.style.background=colort;
					el.id=colort
					//document.getElementById('aaa').value+=colort+" ";
					el.onclick=function() { ustaw_kolor(cmd, id, this.id); }
					elr.appendChild(el);
				}
				col.appendChild(elr);
			}
			row.appendChild(col);
		}
		colors.appendChild(row);
	}
	document.body.appendChild(layer);
	document.body.appendChild(colors);
	}catch(err){alert(err);}
}
//zamkniecie kolorów
function close_color()
{
	document.body.removeChild(document.getElementById("color_layer1"));
	document.body.removeChild(document.getElementById("color_layer2"));
}
//ustawienie kolorów
function ustaw_kolor(cmd, id, color)
{
	if(cmd=="f") { view_w(id).document.execCommand("ForeColor", false, color); }
	else { view_w(id).document.execCommand("BackColor", false, color); }
	close_color();
}
//konwersja koloru
function dec_to_hex(value)
{
	var hex_string = "";
	for (var hexpair = 0; hexpair < 3; hexpair++)
	{
		var myByte = value & 0xFF;
		value >>= 8;
		var nybble2 = myByte & 0x0F;
		var nybble1 = (myByte >> 4) & 0x0F;
		hex_string += nybble1.toString(16);
		hex_string += nybble2.toString(16);
	}
	return hex_string.toUpperCase();
}
//konwersja text-kod
function txt_to_code(id)
{
	view_w(id).document.body.style.fontFamily = "Courier New";
	var txt=view_w(id).document.body.innerHTML;
	txt=txt.replace(/</gi,"&lt;");
	txt=txt.replace(/>/gi,"&gt;");
	txt=txt.replace(/&lt;br&gt;/gi,"&lt;br&gt;<br>");
	view_w(id).document.body.innerHTML=txt;
	//zamienienie ikony
	var icon=document.getElementById(id+"_ViewSource");
	icon.src=icon.src.replace("view_source_on.gif","view_text.gif");
	icon.onmousemove=function() { this.src=this.src.replace("view_text.gif","view_text_on.gif"); }
	icon.onmouseout=function() { this.src=this.src.replace("view_text_on.gif","view_text.gif"); }
	icon.onclick=function() { commands(id,"ViewText"); }
	icon.alt=lang_text;
	icon.title=lang_text;
	//wyłaczenie ikon
	try{
	for(var a=0; a<set_act.icons.length; a++)
	{
		for(var b=0; b<set_act.icons[a].length; b++)
		{
			var name=WYSIWYG.toolbox[set_act.icons[a][b]][0];
			if(name!="Save" && name!="Preview" && name!="Print" && name!="ViewSource" && name!="Maximize" && name!="Help"){ document.getElementById(id+"_"+name).style.visibility='hidden'; }
		}
	}
	}catch(err){alert(err);}	
}
//konwersja kod-text
function code_to_txt(id)
{
	setAttribute(view_w(id).document.body, "style", set_act.defaultstyle);
	var txt=view_w(id).document.body.innerHTML;
	txt=txt.replace(/&lt;br&gt;<br>/gi,"&lt;br&gt;");
	txt=txt.replace(/&lt;/gi,"<");
	txt=txt.replace(/&gt;/gi,">");
	view_w(id).document.body.innerHTML=txt;
	//zamienienie ikony
	var icon=document.getElementById(id+"_ViewSource");
	icon.src=icon.src.replace("view_text_on.gif","view_source.gif");
	icon.onmousemove=function() { this.src=this.src.replace("view_source.gif","view_source_on.gif"); }
	icon.onmouseout=function() { this.src=this.src.replace("view_source_on.gif","view_source.gif"); }
	icon.onclick=function() { commands(id,"ViewSource"); }
	icon.alt=lang_html;
	icon.title=lang_html;
	//właczenie ikon
	for(var a=0; a<set_act.icons.length; a++)
	{
		for(var b=0; b<set_act.icons[a].length; b++)
		{
			var name=WYSIWYG.toolbox[set_act.icons[a][b]][0];
			document.getElementById(id+"_"+name).style.visibility='visible';
		}
	}
}
//maksymalizacja
function maximize(id)
{
	//pobranie rozmiarów
	var width = document.getElementById('layer_head').clientWidth;
	var height = document.getElementById('layer_head').clientHeight;
	var roz = document.getElementById("layer_wysiwyg_"+id).clientHeight-document.getElementById("layer_wysiwyg2_"+id).clientHeight;
	//powiększenie głownego
	document.getElementById("layer_wysiwyg_"+id).style.position="absolute";
	document.getElementById("layer_wysiwyg_"+id).style.top="0px";
	document.getElementById("layer_wysiwyg_"+id).style.left="0px";
	document.getElementById("layer_wysiwyg_"+id).style.width=width+"px";
	document.getElementById("layer_wysiwyg_"+id).style.height=height+"px";
	document.getElementById("layer_wysiwyg2_"+id).style.width=width+"px";
	document.getElementById("layer_wysiwyg2_"+id).style.height=(height-roz)+"px";
	document.getElementById(id+"_Maximize").onclick=function() { commands(id,"Minimize"); };
	document.getElementById(id+"_Maximize").alt=lang_min;
	document.getElementById(id+"_Maximize").alt=lang_min;
}
//minimalizacja
function minimize(id)
{
	//pobranie rozmiarów
	var roz = document.getElementById("layer_wysiwyg_"+id).clientHeight-document.getElementById("layer_wysiwyg2_"+id).clientHeight;
	//pomniejszenie głownego
	document.getElementById("layer_wysiwyg_"+id).style.position="static";
	document.getElementById("layer_wysiwyg_"+id).style.width=set_act.width;
	document.getElementById("layer_wysiwyg_"+id).style.height=set_act.height;
	document.getElementById("layer_wysiwyg2_"+id).style.width=set_act.width;
	document.getElementById("layer_wysiwyg2_"+id).style.height=(set_act.height.replace("px","")-roz)+"px";
	document.getElementById(id+"_Maximize").onclick=function() { commands(id,"Maximize"); };
	document.getElementById(id+"_Maximize").alt=lang_max;
	document.getElementById(id+"_Maximize").alt=lang_max;
}
//otwieranie w pop-up'ie
function wnew_pop(adres,name,width,height)
{ var okno=window.open(adres,'okno','width='+width+',height='+height+'').focus(); okno.focus(); }
//otwieranie w oknie
function wnew_wind(adres,name)
{ var okno=window.open(adres,'okno').focus(); okno.focus(); }
//pobranie zaznaczonego
function getSelection2(id)
{
	var ifrm = view_w(id);
	var doc = ifrm.document;
	var sel = null;
	if(ifrm.getSelection){ sel = ifrm.getSelection(); }
	else if (doc.getSelection) { sel = doc.getSelection(); }
	else if (doc.selection) { sel = doc.selection; }
	return sel;
}
function getRange2(sel)
{ return sel.createRange ? sel.createRange() : sel.getRangeAt(0); }
//skopiowanie zaznaczonego tekstu do cache
function copy_txt(id)
{
	var sel=getSelection2(id);
	var range=getRange2(sel);
	if(sel!="[object]") { var txt=sel; }
	else { var txt=range.text; }
	if(txt!=""){ document.getElementById("cache_"+id).value=txt; }
}
//wklejenie skopiowanego tekstu
function paste_txt(id)
{
	var txt=document.getElementById("cache_"+id).value;
	if(txt!="")
	{
		var sel=getSelection2(id);
		var range=sel.getRangeAt(0);
		var node=document.createTextNode(txt);
		range.insertNode(node);
	}
	else { alert(lang_cache_empty); }
}
//skopiowanie zaznaczonego tekstu do cache i usunięcie
function cut_txt(id)
{
	var sel=getSelection2(id);
	var range=getRange2(sel);
	var range2=sel.getRangeAt(0);
	if(sel!="[object]") { var txt=sel; }
	else { var txt=range.text; }
	document.getElementById("cache_"+id).value=txt;
	range2.deleteContents();
}
//przepisanie tekstu z wysiwyga do textarea
function przepisz(id)
{ try { document.getElementById(id).value=view_w(id).document.body.innerHTML; } catch(err) {} }
//zamiana
function replace_txt(old,news,id)
{ view_w(id).document.body.innerHTML=view_w(id).document.body.innerHTML.replace(old,news); }
//dodanie tabeli
function add_table(node, id)
{
	var sel=getSelection2(id);
	var range=sel.getRangeAt(0);
	range.insertNode(node);
}
//czyszczenie formatowania
function remove_format(id)
{
	var str = view_w(id).document.body.innerHTML;
	str = str.replace(/<ol>/gi, '');
	str = str.replace(/<ul>/gi, '');
	str = str.replace(/<li>/gi, '');
	str = str.replace(/<sup>/gi, '');
	str = str.replace(/<sub>/gi, '');
	str = str.replace(/<h[1-6]>/gi, '');
	str = str.replace(/<\/ol>/gi, '');
	str = str.replace(/<\/ul>/gi, '');
	str = str.replace(/<\/li>/gi, '');
	str = str.replace(/<\/sup>/gi, '');
	str = str.replace(/<\/sub>/gi, '');
	str = str.replace(/<\/h[1-6]>/gi, '');
	str = str.replace(/<a([^>])*>(&nbsp;)*\s*<\/a>/gi, '');
	str = str.replace(/<a[^>]*>/gi, '');
	str = str.replace(/<\/a[^>]*>/gi, '');
	str = str.replace(/<span([^>])*>(&nbsp;)*\s*<\/span>/gi, '');
	str = str.replace(/<span[^>]*>/gi, '');
	str = str.replace(/<\/span[^>]*>/gi, '');
	str = str.replace(/<p([^>])*>(&nbsp;)*\s*<\/p>/gi, '');
	str = str.replace(/<p[^>]*>/gi, '');
	str = str.replace(/<\/p[^>]*>/gi, '');
	str = str.replace(/<h([^>])[0-9]>(&nbsp;)*\s*<\/h>/gi, '');
	str = str.replace(/<h[^>][0-9]>/gi, '');
	str = str.replace(/<\/h[^>][0-9]>/gi, ''); 
	str = str.replace (/<B [^>]*>/ig, '<b>');
	str = str.replace (/<DIV[^>]*>/ig, '');
	str = str.replace (/<\/DIV>/gi, '');
	str = str.replace (/<[\/\w?]+:[^>]*>/ig, '');
	str = str.replace (/(&nbsp;){2,}/ig, '&nbsp;');
	str = str.replace (/<STRONG>/ig, '');
	str = str.replace (/<\/STRONG>/ig, '');
	str = str.replace (/<TT>/ig, '');
	str = str.replace (/<\/TT>/ig, '');
	str = str.replace (/<FONT [^>]*>/ig, '');
	str = str.replace (/<\/FONT>/ig, '');
	str = str.replace (/STYLE=\"[^\"]*\"/ig, '');
	str = str.replace(/<([\w]+) class=([^ |>]*)([^>]*)/gi, '<$1$3');
	str = str.replace(/<([\w]+) style="([^"]*)"([^>]*)/gi, '<$1$3'); 
	str = str.replace(/width=([^ |>]*)([^>]*)/gi, '');
	str = str.replace(/classname=([^ |>]*)([^>]*)/gi, '');
	str = str.replace(/align=([^ |>]*)([^>]*)/gi, '');
	str = str.replace(/valign=([^ |>]*)([^>]*)/gi, '');
	str = str.replace(/<\\?\??xml[^>]>/gi, '');
	str = str.replace(/<\/?\w+:[^>]*>/gi, '');
	str = str.replace(/<st1:.*?>/gi, '');
	str = str.replace(/o:/gi, ''); 
	str = str.replace(/<!--([^>])*>(&nbsp;)*\s*<\/-->/gi, '');
	str = str.replace(/<!--[^>]*>/gi, '');
	str = str.replace(/<\/--[^>]*>/gi, '');
	view_w(id).document.body.innerHTML = str;
}
function new_wind(adres,name)
{ window.open(adres,name).focus(); }

function getTextRange(element)
{
  var range = element.parentTextEdit.createTextRange();
  range.moveToElementText(element);
  return range;
}
function findParent(parentTagName, range)
{
  parentTagName = parentTagName.toUpperCase();
  var rangeWorking;
  var elmWorking = null;
  try
  {
    if(!isMSIE())
    {
      var node = range.startContainer;	
      var pos = range.startOffset;
      if(node.nodeType != 3) { node = node.childNodes[pos]; }
      return findParentNode(parentTagName, node);
    }
    else
    {
      elmWorking = (range.length > 0) ? range.item(0): range.parentElement();					
      elmWorking = findParentNode(parentTagName, elmWorking);
      if(elmWorking != null) return elmWorking;
      rangeWorking = range.duplicate();
      rangeWorking.collapse(true);
      rangeWorking.moveEnd("character", 1);
      if (rangeWorking.text.length>0) 
      {
        while (rangeWorking.compareEndPoints("EndToEnd", range) < 0)
        {
          rangeWorking.move("Character");
          if (null != this.findParentTag(parentTagName, rangeWorking))
          { return this.findParentTag(parentTagName, rangeWorking); }
        }
      }
      return null;
    }
  }
  catch(e) { return null; }
}
function findParentNode(tagName, node)
{
  while (node.tagName != "HTML")
  {
    if (node.tagName == tagName)
    { return node; } 
	  node = node.parentNode;
	}
	return null;
}
function isMSIE() { navigator.appName == "Microsoft Internet Explorer" ? true : false }
