// ----
// ----
//
// WarpMail 2 Copyright ZK 2008
//
// 2.00.0000 ZK 2008.10.28 Creation from 1.03.0007
// 2.00.0001 ZK 2008.10.29 Debug switch internalised
//
// WarpMail is an anti-spambot contrivance that dynamically recreates an  email hyperlink
// anchor on a web page using a  spelt-out version of the address  in a predefined anchor
// of the form <a id=praw href="#praw">nobody dot noname at nowhere dot co dot uk</a>.
//
// Using it is simple, just...
//
// Insert <script type="text/javascript" src="path/warpmail.js"></script> within the head
// section of an appropriate web page; path is the path to the script file.
//
// Insert  <a id=praw href="#praw">nobody dot noname at nowhere dot co dot uk</a>  in the
// body section for the click on mail hyperlink anchor. Spell out the email address using
// words 'dot' and 'at' instead of the real  thing in the  anchor content as shown above,
// including spaces, e.g., 'name at company dot com' instead of 'name@company.com'.
//
// Note, id and href should match, and should be set to 'praw', which is 'warp' inverted;
// WarpMail uses these  attributes when  regenerating the  anchor after the page loads in
// the browser. The regenerated anchor only  exists as a phantom within the browser,  not
// in the physical page itself - use menu item 'view/source' to "not" see it - therefore,
// spambots shouldn't find it when scanning web  pages.  Hovering  the link  displays the
// regenerated email address in the browser window status area as per usual.
//
// IF, the predefined id and href values of 'praw' conflict with a pre-existing hyperlink
// anchor on a web page, it can be changed with caution in the section marked 'WARP', but
// choose something unrelated to mail. Don't forget to change the id and href in the link
// to match and amend the version, copyright, etc, at the top of the file to reflect who,
// why, what, when and the rest.
//
// WarpMail also attaches a subject to the regenerated link, it's set to 'Info'; this too
// can be changed in the 'WARP' section but avoid subjects with embedded spaces, WarpMail
// subject processing is primitive.  A copy of the warp singularity  follows in case it's
// accidentally corrupted!
//
// window.onload = function(){WarpMail("praw", "Info");};
//
// On no account change anything in the section marked 'CORE'.
//
// On browsers that don't support JavaScript, or have scripts turned off,  degradation is
// gracefull - the link will show the original spelt-out content and the href goes up its
// own reality, i.e., links itself, which is okay - and it's all spambot proof too; all a
// client needs to do is copy the spelt-out email address into an emailer  and change the
// 'dot' and 'at' to the real thing.
//
// No warranties. No guarantees. No fees. No support. Use at your own risk.   !!!RTFM !!!
//
// ----
// ----


// ++++ WARP !!! Edit with caution !!!
    window.onload = function(){WarpMail("praw", "Info");};
// ---- WARP !!! Edit with caution !!!


// ++++ CORE !!! Do NOT edit !!!
    function WarpMail(id, subject)
    {
        // Personal debug switch
        var debug = false;

        // Get element reference
        var target = document.getElementById(id);

        // Get current element content
        var content = target.firstChild.nodeValue;

        // Warning, the following statement contains embedded tabs/spaces for testing purposes!
        if(debug) {content = "   w		dot x y at z       dot co		  dot uk   ";}
        if(debug) {window.status = content;}

        // Warp content - detab, cut multi-spaces, translate 'dot' and 'at', and final despace!
        {
            while(content.indexOf("\t",    0) != -1) {content = content.replace("\t",    " ");}
            while(content.indexOf("  ",    0) != -1) {content = content.replace("  ",    " ");}
            while(content.indexOf(" dot ", 0) != -1) {content = content.replace(" dot ", ".");}
            while(content.indexOf(" at ",  0) != -1) {content = content.replace(" at ",  "@");}
            while(content.indexOf(" ",     0) != -1) {content = content.replace(" ",     "" );}
        }

        // Set element href and content with warped href and content
        target.href = "mailto:" + content + "?subject=" + subject;
        target.firstChild.nodeValue = content;

        if(debug) {window.status += "|" + target.href + "|";}
    }
// ---- CORE !!! Do NOT edit !!!

