﻿//This script will prevent webcrawlers from harvesting email addresses from the page.

var at = "%40";
var encryptedName;
var encryptedDomain;

function mToDisplay(name, domain, display) {
    //convert name string to hex
    for( n=0; n < name.length; n++ ) {
        encryptedName += "%" + name.charCodeAt(n).toString(16);
    }
    
    //convert domain string to hex
    for( n=0; n < domain.length; n++ ) {
        encryptedDomain += "%" + domain.charCodeAt(n).toString(16);
    }
    
    //convert "mailto" to hex
    var encryptedMailTo = "%6d%61%69%6c%74%6f%3a";
    
    //write obfuscated email address and link to page  
    document.write( '<a href="'
        + unescape( encryptedMailTo ) + encryptedName.replace("undefined", "") + at + encryptedDomain.replace("undefined", "")
        + '">' + display + '</a>' );
        
    //clear variables in case there is more than one contact (prevents different email addresses from being concatenated to each other)
    encryptedName = "";
    encryptedDomain = "";

}

//function that creates obuscated mailto link
function mTo(name, domain) {
    //convert name string to hex
    for( n=0; n < name.length; n++ ) {
        encryptedName += "%" + name.charCodeAt(n).toString(16);
    }
    
    //convert domain string to hex
    for( n=0; n < domain.length; n++ ) {
        encryptedDomain += "%" + domain.charCodeAt(n).toString(16);
    }
    
    //convert "mailto" to hex
    var encryptedMailTo = "%6d%61%69%6c%74%6f%3a";
    
    //write obfuscated email address and link to page  
    document.write( '<a href="'
        + unescape( encryptedMailTo ) + encryptedName.replace("undefined", "") + at + encryptedDomain.replace("undefined", "")
        + '">' + unescape(encryptedName.replace("undefined", "")) + unescape(at) + unescape(encryptedDomain.replace("undefined", "")) + '</a>' );
        
    //clear variables in case there is more than one contact (prevents different email addresses from being concatenated to each other)
    encryptedName = "";
    encryptedDomain = "";
}

