/* add a href to link in text */

function HaveAnchors(obj)
{
	if(obj.tagName.toUpperCase()=='A') { return true; }
	var chel = obj.childElements();
	var chLen = chel.length;
	if(chLen>0)
	{
		for (var i = 0; i < chLen; i++) 
		{
			if(HaveAnchors(chel[i])) return true;
		}
	}
	return false;
}

function addHrefText(obj)
{
	if(!HaveAnchors(obj))
	{
		var text = obj.innerHTML;
		if (text)
		{
			text = text.replace(/(&#8203;|\00200B|\u200b)/g, "");
			text = text.replace(/^((http:\/\/)+[\w\/\-%&#=.,:;?+$]+)/ig, " <a href='$1' target='_blank'>$1</a>");
			text = text.replace(/([^\"\'\=\(])((http:\/\/)+[\w\/\-%&#=.,:;?+$\_]+)/ig, "$1 <a href='$2' target='_blank'>$2</a>");
			text = text.replace(/[\s\^\>]((www)[\w\/\-%&#=.,:;?+$]+)/ig, " <a href='http://$1' target='_blank'>$1</a>");
			text = text.replace(/([\w.-]+@[\w.-]+\.\w+)/g, "<a href='mailto:$1'>$1</a>");
			obj.innerHTML = text;
		}
	}
}

addHref = function()
{
	var objects = $$('.href_me');
	for(i=0;i<objects.length;i++){
		addHrefText(objects[i]); 
	}	
}

addLoadEvents(addHref);
