        //**********************************************************************************************
        // RICHEDIT
        // Brasil, agosto de 2003
        // by Caiuby Freitas
        //
        // DISCLAIMER
        // This is a freeware. Use it anywhere you like and at youR own risk, but please do not remove
        // authoring information above. 
        // This script is Internet Explorer compatible and was not tested in others browsers yet.
        // if you have any suggestions please let me know (caiuby_freitas@yahoo.com.br)
        //**********************************************************************************************

        function MemoCounter(fld, countfld, maxlimit){
           if (fld.value.length > maxlimit) fld.value = fld.value.substring(0, maxlimit);
           else countfld.value = maxlimit - fld.value.length;
        }

	function storeCaret(Source){ if (Source.createTextRange) Source.caretPos = document.selection.createRange().duplicate(); }

        function hotkey(Source){ if (event.keyCode == 13 && event.shiftKey){ if (Source.createTextRange && Source.caretPos) document.selection.createRange().text += "<BR>";} }
    
        function preview(Source){ document.all.FinishedText.innerHTML = replace(Source.value,'','<BR>'); }

        function hide(Source){ document.all.FinishedText.innerHTML = ""; }

	function insertFormat(Source, tag){
	  if (Source.createTextRange && Source.caretPos){ document.selection.createRange().text = '<'+tag+'>'+document.selection.createRange().text+'</'+tag+'>'; }
	  else alert("Selecione uma palavra ou frase para formatação.");
        }

	function colorize(Source, colorcode){
	  if (Source.createTextRange && Source.caretPos){ document.selection.createRange().text = '<font color=\"'+colorcode+'\">'+document.selection.createRange().text+'</font>'; }
	  else alert("Selecione uma palavra ou frase para formatação.");
        }

	function alignText(Source, typealignment){
	  if (Source.createTextRange && Source.caretPos){ document.selection.createRange().text = '<p align=\"'+typealignment+'\">'+document.selection.createRange().text+'</p>'; }
	  else alert("Selecione uma palavra ou frase para formatação.");
        }

	function hyperLink(Source){
	  if (Source.createTextRange && Source.caretPos){ 
             url = prompt('Digite o endereço completo para o link.','http://');
             if ((url) && (url!="http://")) document.selection.createRange().text = '<A HREF="'+url+'" TARGET="_new">'+document.selection.createRange().text+'</A>';
          }
	  else alert("Selecione uma palavra ou frase para transformar em link.");
        }	 

	function replace(string,text,by) {
            // Replaces text with by in string
	    var strLength = string.length, txtLength = text.length;
	    if ((strLength == 0) || (txtLength == 0)) return string;
	    var i = string.indexOf(text);
	    if ((!i) && (text != string.substring(0,txtLength))) return string;
	    if (i == -1) return string;
	    var newstr = string.substring(0,i) + by;
	    if (i+txtLength < strLength) newstr += replace(string.substring(i+txtLength,strLength),text,by);
	    return newstr;
	}
