function strstr (haystack, needle, bool) {
    var pos = 0;
     
    haystack += '';
    pos = haystack.indexOf( needle );
    if (pos == -1)
        return false;
    else
		return (bool) ? haystack.substr( 0, pos ) : haystack.slice( pos );
}
function trim12(str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}
function strip_tags( str ){
    return str.replace(/<\/?[^>]+>/gi, '');
}
function getEmailFromTxt(txt) {
	//txt = txt.replace('http://', '') + ' ';
	var ttxt = strip_tags(txt);
	//var matches = ttxt.match(/(http:\/\/)?([a-z_0-9-.]+\.[a-z]{2,3}(([ \"'>\r\n\t])|(\/([^ \"'>\r\n\t]*)?)))/g);
	var matches = ttxt.match(/((http(s?):\/\/)|(www.)|(http(s?):\/\/www.))+([\w.1-9\&=#?\-~%;\/]+)/g);
	if (matches) {
		var i = 0;
		while (i < matches.length) {
			var link = trim12(matches[i].toString());
			var a = '<a href="http://' + link.replace('http://', '') + '"' + (!strstr(link, 'reeftools.com') ? ' target="_blank"' : '') + '>http://' + link.replace('http://', '') + '</a>';
	    	txt = txt.replace(link, a);
			i ++;
		}
	}
	return txt;
}
