// JavaScript Document
RemoveTextFormating = function(text, noTags)
{
	try
	{
		var retString = '';
		
		if (text.slice(0,5) == '<DIV>' || text.slice(0,2)!= '<P')
		{
			return text;
		}
		text = (text.replace(/&/g,'&amp;'));
		// code for IE
		if (window.ActiveXObject)
		{
			text = '<DIV>'+text.replace(/  /g,'&#160;&#160;')+'</DIV>';
			var doc=new ActiveXObject("Microsoft.XMLDOM");
			doc.async="true";
			doc.loadXML(text);
		}
		// code for Mozilla, Firefox, Opera, etc.
		else
		{
			var parser=new DOMParser();
			var doc=parser.parseFromString('<ROOT>'+text+'</ROOT>',"text/xml");
		}
		if (!noTags)
		{
			retString += '<DIV>';
		}

		var x=doc.documentElement;
	
		if (x != null)
		{
			for(var i=0; i<x.childNodes.length;i++)
			{
				if (x.childNodes[i].nodeType==3)
				{
					alert(x.childNodes[i].data);
				}
				if (x.childNodes[i].nodeType==1)
				{
					var ptag = x.childNodes[i];
					if (!noTags)
					{
						retString += '<'+ptag.tagName+' align="'+ptag.getAttribute('ALIGN')+'">'
					}
					if (ptag.hasChildNodes())
					{
						/*
						ptag.firstChild.removeAttribute('SIZE');
						ptag.firstChild.removeAttribute('COLOR');
						ptag.firstChild.removeAttribute('FACE');
						ptag.firstChild.removeAttribute('KERNING');
						ptag.firstChild.removeAttribute('LETTERSPACING');
						*/
						if (ptag.firstChild.hasChildNodes())
						{
							for (var j=0;j<ptag.firstChild.childNodes.length;j++)
							{
								if (ptag.firstChild.childNodes[j].nodeType==3)
								{
									//alert('['+ptag.firstChild.childNodes[j].data+']')
									retString += ptag.firstChild.childNodes[j].data.replace(/  /g,"&nbsp;&nbsp;");
								}
								else if (ptag.firstChild.childNodes[j].nodeType==1)
								{
									if (window.ActiveXObject)
									{
										retString += ptag.firstChild.childNodes[j].xml.replace(/  /g,"&nbsp;&nbsp;");
									}
									else
									{
										retString += (new XMLSerializer().serializeToString(ptag.firstChild.childNodes[j])).replace(/  /g,"&nbsp;&nbsp;");
									}
								}
							}
						}
						else
						{
							retString += '&nbsp;';
						}
					}
					if (!noTags)
					{
						retString += '</'+x.childNodes[i].tagName+'>'
					}
				}
			}
		}
		if (!noTags)
		{
			retString += '</DIV>';
		}
		return retString;//.replace(/&nbsp;  /g,' ');
	}
	catch (ex)
	{
		return ex.message;
		alert('Mesage: ' + ex.message + ' - Number: ' + ex.number);
	}
	return retString;
}
