/*
*                         OCLC, Inc.
*
* OCLC proprietary information: the enclosed materials contain
* proprietary information of OCLC Online Computer Library Center, Inc.
* and shall not be disclosed in whole or in any part to any third party
* or used by any person for any purpose, without written consent of
* OCLC, Inc.  Duplication of any portion of these materials shall
* include this legend.
*
*/
function rot13Plus (which) // standard rot13 only encrypts alphabetics
{
    var codchr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMabcdefghijklmnopqrstuvwxyzabcdefghijklm';
    var codnum = '01234567895678901234';

    var character, position;
    var x = which.value;

    for (var text = '',i=0;i<x.length;i++)
    { 
         character = x.charAt(i);  
         position = codchr.indexOf(character);    
         if (position > -1)
             character = codchr.charAt(position + 13);
         else
         {
             position = codnum.indexOf(character);
             if (position > -1)
                 character = codnum.charAt(position+10);
         }
         text += character;
    }
    which.value = text; 
}

var defaulteyecatcher = "+-+";

function reVerse (which) 
{
    var x = which.value;
    for (var text = '', i=x.length-1; i>-1; i=i-1)
         text += x.charAt(i);
    which.value = text;
}

function enCrypt (which)
{
    var argv  = enCrypt.arguments;
    var argc  = argv.length;
    var eyecatcher  = (argc > 1) ? argv[1] : defaulteyecatcher;
    
    if (which.value.substr(0,3) == eyecatcher)  // already encrypted
        return;

    reVerse   (which);
    rot13Plus (which);
    which.value = eyecatcher + which.value;
}
