function replaceURLWithHTMLLinks(text) {
  var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  return text.replace(exp,"<a href='$1'>$1</a>"); 
}


(function($){
 	$.fn.extend({ 
 		
 		frontFormatter: function(undo) {

    		return this.each(function() {
			
				var txt = $(this).html();

				if (!undo)
				{
    				txt = txt.replace(/\*\*([\s\S]*?)\*\*/g, '<b>$1</b>');
    				txt = ' '+txt+' ';
    				txt = txt.replace(/([^a-z0-9\?\.\,\+\-\&\#])\_([\s\S]*?)\_([^a-z0-9\?\.\,\+\-\&\#])/gi, '$1<i>$2</i>$3');
    				txt = txt.replace(/\[\/quote\]/g, " [/quote]");
    				//txt = txt.replace(/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/g, '<a href="$&">$&</a>'); 
    				txt = txt.replace(/\[quote \((.*?)\)\]/gmi, '<div class="quote"><div class="quote_info">$1</div>');
    				txt = txt.replace(/\[\/quote\]/gmi, '</div>');
                    txt = replaceURLWithHTMLLinks(txt);
                }
                else
                {
                    txt = txt.replace(/<b>([\s\S]*?)<\/b>/gmi, '**$1**');
                    txt = txt.replace(/<i>([\s\S]*?)<\/i>/gmi, '_$1_');
                    txt = txt.replace(/<a href=["'](.*?)["'](.*?)<\/a>/gi, "$1");
                    txt = txt.replace(/<div class=\"quote\"><div class=\"quote_info\">([\s\S]*?)<\/div>/gi, '[quote ($1)]');
                    txt = txt.replace(/<\/div>/gi, '[/quote]');
                }
                
                
                $(this).html(txt);			                        
    		});
    	}    	
	});

})(jQuery);
