/**
*@author bobby hagan
*@MDW Tech Support
*@param String text
*This function hyperlinks a substring of text that begins "www." and
* ends with ".com", ".org", ".gov", ".edu", or ".net"
*@return result the processed string
*/
function hyperLinkWww(text, keyword){
var temp = text;
var result = "";
var keyFlag =0;
var uHTMLLink;
cRegExp = /\.com/gi;
oRegExp = /\.org/gi;
gRegExp = /\.gov/gi;
eRegExp = /\.edu/gi;
nRegExp = /\.net/gi;
var wRegExp;
if(keyword == "www."){
wRegExp = /www/gi;
temp=temp.replace(/(<([^>]+)>)/ig,'');
}
else{
wRegExp = /www\./gi;
}
var wIndex = temp.search(wRegExp);
var comIndex;
var dns;
if(temp.search(cRegExp) != -1){
comIndex = temp.indexOf(".com",wIndex );
}
if(temp.search(oRegExp) != -1){
comIndex = temp.indexOf(".org",wIndex );
}
if(temp.search(gRegExp) != -1){
comIndex = temp.indexOf(".gov",wIndex );
}
if(temp.search(eRegExp) != -1){
comIndex = temp.indexOf(".edu",wIndex );
}
if(temp.search(nRegExp) != -1){
comIndex = temp.indexOf(".net",wIndex );
}
/*
if(comIndex < wIndex){
comIndex = temp.indexOf(dns, comIndex + 4);
}*/
//alert(comIndex)
comIndex = comIndex + 4;
var uLink = temp.slice(wIndex, comIndex);
//check for keyword
if(keyword != ""){
if(uLink.search(keyword) != -1){
uHTMLLink = uLink;
keyFlag = 1;
//strip html tags
uLink = uLink.replace(/(<([^>]+)>)/ig,'');
}
}
newLink = ""+ uLink + "";
if(keyFlag==1){
var uRegExp = new RegExp(uHTMLLink, "gi");
}
else{var uRegExp = new RegExp(uLink, "gi");}
result = temp.replace(uRegExp, newLink);
//alert(result)
return result;
}
/**
*@author bobby hagan
*@MDW Tech Support
*@param String text
*This function hyperlinks a vaild email address
*@return result the processed string
*/
function hyperLinkEmail(text, keyword){
var temp = text;
var result = "";
var keyFlag =0;
var uHTMLLink;
var uLink;
cRegExp = /\.com/gi;
oRegExp = /\.org/gi;
gRegExp = /\.gov/gi;
eRegExp = /\.edu/gi;
nRegExp = /\.net/gi;
aRegExp = new RegExp("@.*\.[a-z]{3}", "gi");
var aIndex = temp.search(aRegExp);
//alert(aIndex);
var comIndex = temp.indexOf(".com", aIndex);
var netIndex = temp.indexOf(".net", aIndex);
var govIndex = temp.indexOf(".gov", aIndex);
var orgIndex = temp.indexOf(".org", aIndex);
var eduIndex = temp.indexOf(".edu", aIndex);
var startIndex;
//find the index of first char in email address
for(i = aIndex; i >=0; i--){
if( temp.charAt(i) == " "){
startIndex = i + 1;
break;
}
}
if (comIndex != -1){
uLink = temp.slice(startIndex, comIndex+4);
}
if (netIndex != -1){
uLink = temp.slice(startIndex, netIndex+4);
}
if (govIndex != -1){
uLink = temp.slice(startIndex, govIndex+4);
}
if (orgIndex != -1){
uLink = temp.slice(startIndex, orgIndex+4);
}
if (eduIndex != -1){
uLink = temp.slice(startIndex, eduIndex+4);
}
//check for keyword
if(uLink.search(keyword) != -1){
uHTMLLink = uLink;
keyFlag = 1;
//strip html tags
uLink = uLink.replace(/(<([^>]+)>)/ig,'');
}
newLink = ""+ uLink + "";
var uRegExp;
if(keyFlag==1){
uRegExp = new RegExp(uHTMLLink, "gi");
}
else{
uRegExp = new RegExp(uLink, "gi");}
result = temp.replace(uRegExp, newLink);
return result;
}
/**
*@author bobby hagan
*@MDW Tech Support
*@param String text
*This function hyperlinks a substring of text that begins "http://." and
* ends with ".com", ".org", ".gov", ".edu", or ".net"
*@return result the processed string
*/
function hyperLinkHttp(text, keyword){
var temp = text;
var result = "";
var keyFlag =0;
var uHTMLLink;
cRegExp = /\.com/gi;
oRegExp = /\.org/gi;
gRegExp = /\.gov/gi;
eRegExp = /\.edu/gi;
nRegExp = /\.net/gi;
hRegExp = new RegExp("http://", "gi");
var hIndex = temp.search(hRegExp);
var comIndex;
var dns;
if(temp.search(cRegExp) != -1){
comIndex = temp.search(cRegExp);
dns = ".com"
}
if(temp.search(oRegExp) != -1){
comIndex = temp.search(oRegExp);
dns = ".org"
}
if(temp.search(gRegExp) != -1){
comIndex = temp.search(gRegExp);
dns = ".gov"
}
if(temp.search(eRegExp) != -1){
comIndex = temp.search(eRegExp);
dns = ".edu"
}
if(temp.search(nRegExp) != -1){
comIndex = temp.search(nRegExp);
dns = ".net"
}
if(comIndex < wIndex){
comIndex = temp.indexOf(dns, comIndex + 4);
}
comIndex = comIndex + 4;
uLink = temp.slice(hIndex, comIndex);
//check for keyword
if(uLink.search(keyword) != -1){
uHTMLLink = uLink;
keyFlag = 1;
//strip html tags
uLink = uLink.replace(/(<([^>]+)>)/ig,'');
}
newLink = "" + uLink + "";
if(keyFlag==1){
var uRegExp = new RegExp(uHTMLLink, "gi");
}
else{var uRegExp = new RegExp(uLink, "gi");}
result = temp.replace(uRegExp, newLink);
return result;
}
/**
*@author bobby hagan
*@MDW Tech Support
*@param String text
*This function hyperlinks a substring of text that begins "http://." and
* ends with ".com", a substring that begins with "www." and ends with ".com" , ".org", ".gov", ".edu", or ".net". and
*a valid email address
*@return result the processed string
*/
function hyperLink(text,keyword){
var result = text;
hRegExp = new RegExp("http://", "gi");
wRegExp = new RegExp("www.","gi");
aHRegExp = new RegExp(" result.search(emailRegExp)) || (result.indexOf(".net", eIndex) != -1 && result.indexOf(".net", eIndex) > result.search(emailRegExp)) ||( result.indexOf(".org", eIndex) != -1 && result.indexOf(".org", eIndex) > result.search(emailRegExp)) || (result.indexOf(".gov", eIndex) != -1 && result.indexOf(".gov", eIndex) > result.search(emailRegExp)) || (result.indexOf(".edu", eIndex) != -1 && result.indexOf(".edu", eIndex) > result.search(emailRegExp))) ){
result = hyperLinkEmail(result, keyword);
}
return result;
}