var is_xhtml;

jQuery.fn.br2nl = function(){
    return this.each(function(){
        jQuery(this).val(jQuery(this).val().replace(/\<br(\s*\/|)\>/g, "\r\n"));
    });
};

function nl2br (str, is_xhtml) {
    // Converts newlines to HTML line breaks  
    // 
    // version: 1009.2513
    // discuss at: http://phpjs.org/functions/nl2br    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Philip Peterson
    // +   improved by: Onno Marsman
    // +   improved by: Atli Þór
    // +   bugfixed by: Onno Marsman    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Maximusya
    // *     example 1: nl2br('Kevin\nvan\nZonneveld');    // *     returns 1: 'Kevin\nvan\nZonneveld'
    // *     example 2: nl2br("\nOne\nTwo\n\nThree\n", false);
    // *     returns 2: '<br>\nOne<br>\nTwo<br>\n<br>\nThree<br>\n'
    // *     example 3: nl2br("\nOne\nTwo\n\nThree\n", true);
    // *     returns 3: '\nOne\nTwo\n\nThree\n'    var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '' : '<br>';
	var breakTag = '<br />';

    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}

function html2bb(str)
{	
	str = str.replace(/(\<strong\>)(.*)(\<\/strong\>)/g, '[b]$2[/b]');
	str = str.replace(/\<a href=\"(.*)\" target=\"_blank\"\>(.*)\<\/a\>/g, '[url=$1]$2[/url]');
	str = str.replace(/\<em\>(.*)\<\/em\>/g, '[i]$1[/i]');
	str = str.replace(/\<span style=\"text\-decoration: line\-through;\"\>(.*)\<\/span\>/g, '[s]$1[/s]');
	str = str.replace(/\<span style=\"text\-decoration: underline;\"\>(.*)\<\/span\>/g, '[u]$1[/u]');
	str = str.replace(/\<br(\s*\/|)\>/g, "");
	return str;
}
