
var tastySpam = "mailto:";
var lovelySpam = "@";
var wonderfulSpam = ".";

var TRIM_SIZE = 2;


/**
 * Modifys the specified link's href so that it is a mailto:
 * to the specified email address.
 * @parm theLink Link to modify.
 * @parm name Username part of the email address with TRIM_SIZE appended random characters.
 * @parm host Host part of the email address with TRIM_SIZE appended random characters.
 * @parm tld Top level domain part of the email address with TRIM_SIZE appended random characters.
 */
function buildMailtoLink( theLink, name, host, tld )
{
    theLink.href = tastySpam + trimParm( name ) + lovelySpam + trimParm( host ) + wonderfulSpam + trimParm( tld );
}

/**
 * Writes the email address to the body or innerHtml of the tag specified by the ID.
 * Bascially forces the person scrapping to run javascript to get the email, and still displays it nicely.
 *
 * @param elementId
 * @param name
 * @param host
 * @param tld
 * @param writeEmail
 */
function setEmailToLink( elementId, name, host, tld )
{
    document.getElementById( elementId ).innerHTML = trimParm( name ) + lovelySpam + trimParm( host ) + wonderfulSpam + trimParm( tld );
}


/**
 * Trims the last TRIM_SIZE characters from the specified parameter.
 * @parm parm Parameter to trim.
 */
function trimParm( parm )
{
    if ( !parm )
    {
        return;
    }

    else if ( parm.length <= TRIM_SIZE )
    {
        return parm;
    }

    else
    {
        return parm.slice( 0, -2 );
    }
}