
$(document).ready(function() {

  if($("#pgpkey").size() > 0) {
    return;
  }

  var token = $("#emailtoken").val();
  var result = "";
  for(i = 0; i < token.length; i++)
  {
    result += String.fromCharCode(137 ^ token.charCodeAt(i));
  }

  $("<a href=\"mailto:" + result + "\"><img src=\"http://"+window.location.hostname+"/images/email-icon.png\" alt=\"E-Mail\" title=\"E-Mail\" /></a>").insertBefore($("#pgpimage"));

  token = $("#xmpptoken").val();
  result = "";
  for(i = 0; i < token.length; i++)
  {
    result += String.fromCharCode(137 ^ token.charCodeAt(i));
  }

  $("<a href=\"xmpp:" + result + "\"><img src=\"http://"+window.location.hostname+"/images/xmpp-icon.png\" alt=\"XMPP\" title=\"XMPP\" /></a>").insertAfter($("#pgpimage"));

  var key = $("#pgpimage").children('img').attr('alt');
  key = key.substring(key.length - 10);
  $("<input type=\"text\" value=\"" + key + "\" id=\"pgpkey\" title=\"PGP Key\"readonly=\"readonly\">").insertAfter($("#pgpimage"));
  $('#pgpkey').width(100);
  $('#pgpkey').focus(function() {
       $(this).select();
  });
  $('#pgpkey').blur(function() {
       $(this).val('');
       $(this).val(key);
  });

});


