window.previousValue;
window.currentValue;

function cloneTextDiv(div_id, hidden_id)
{
	if	(document.getElementById(div_id) && document.getElementById(hidden_id))
	{ document.getElementById(hidden_id).value = cleanHTML(document.getElementById(div_id).innerHTML); countWords(div_id, true, true);
	
		window.currentValue = document.getElementById(div_id).innerHTML.length;
		
		if		(window.previousValue && (window.previousValue+15) < window.currentValue || !window.previousValue && 10 < window.currentValue)
		{ document.getElementById(div_id).innerHTML = cleanHTML(document.getElementById(div_id).innerHTML); window.previousValue = document.getElementById(div_id).innerHTML.length; }
		else
		{ window.previousValue = window.currentValue; } 
	}
}

function setNumValues(div_id)
{
	window.previousValue 	= document.getElementById(div_id).innerHTML.length;
	window.currentValue 	= document.getElementById(div_id).innerHTML.length;
}

function applyExeChange(exeCommand, tgt_id, exeValue, endFunc)
{	
	if		(exeCommand && exeValue)
	{ document.execCommand(exeCommand, false, exeValue); }
	else if	(exeCommand)
	{ document.execCommand(exeCommand, false, null); }

	if	(endFunc)
	{ eval(endFunc); }

	window.previousValue 	= document.getElementById(tgt_id).innerHTML.length;
	window.currentValue 	= document.getElementById(tgt_id).innerHTML.length;
}

function cleanHTML( str )
{
	str = str.replace(/<o:p>\s*<\/o:p>/g, "");
	str = str.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;");
	str = str.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" );
	str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" );
	str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" );
	str = str.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" );
	str = str.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" );
	str = str.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" );
	str = str.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" );
	str = str.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" );
	str = str.replace( /\s*tab-stops:[^;"]*;?/gi, "" );
	str = str.replace( /\s*tab-stops:[^"]*/gi, "" );
	str = str.replace( /\s*face="[^"]*"/gi, "" );
	str = str.replace( /\s*face=[^ >]*/gi, "" );
	str = str.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, "" );
	str = str.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3");
	str = str.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" );
	str = str.replace( /\s*style="\s*"/gi, '' ); 
	str = str.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ); 
	str = str.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ); 
	str = str.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3"); 
	str = str.replace( /<SPAN\s*>(.*?)<\/SPAN>/gi, '$1' ); 
	str = str.replace( /<FONT\s*>(.*?)<\/FONT>/gi, '$1' );
	str = str.replace(/<\\?\?xml[^>]*>/gi, ""); 
	str = str.replace(/<\/?\w+:[^>]*>/gi, ""); 
	str = str.replace( /<H\d>\s*<\/H\d>/gi, '' );
	str = str.replace( /<H1([^>]*)>/gi, '' );
	str = str.replace( /<H2([^>]*)>/gi, '' );
	str = str.replace( /<H3([^>]*)>/gi, '' );
	str = str.replace( /<H4([^>]*)>/gi, '' );
	str = str.replace( /<H5([^>]*)>/gi, '' );
	str = str.replace( /<H6([^>]*)>/gi, '' );
	str = str.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' );
	str = str.replace( /<B\s*>(.*?)<\/B>/gi, '<strong>$1</strong>' );
	str = str.replace( /<b\s*>(.*?)<\/b>/gi, '<strong>$1</strong>' );
	str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' );
	str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' );
	str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' );
	
	//some RegEx code for the picky browsers
	var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi");
	str = str.replace( re, "<p$2</p>" );
	var re2 = new RegExp("(<font|<FONT)([^*>]*>.*?)(<\/FONT>|<\/font>)","gi"); 
	str = str.replace( re2, "<p$2</p>");
	
	return str;
}