function hideElement(element) {
  document.getElementById(element).style.visibility = 'hidden';}

function hideKey(keyId) {
  document.getElementById(keyId).className = "";
}

function showKey(keyId,src) {
  document.getElementById(keyId).className = "visible";
  document.getElementById(keyId).src = src;
}

function topMenuHover(element) {
  element.className="hover";
}
function topMenuHoverOut(element) {element.className="";}

function validateEmail(str) {
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){return false }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false }
  if (str.indexOf(at,(lat+1))!=-1){ return false }
  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false }
  if (str.indexOf(dot,(lat+2))==-1){ return false }
  if (str.indexOf(" ")!=-1){ return false }
  return true
}

function validateSubscribe() {
  var valid = true; // assume the form is valid
  
  // check the first email field for validity
  if (validateEmail(document.getElementById("email1").value)) // email is valid
    document.getElementById("email1msg").innerHTML = "";
  else { // email is not valid
    document.getElementById("email1msg").innerHTML = "(invalid email address)";
    valid = false;}
  
  // check the second email field for validity
  if (validateEmail(document.getElementById("email2").value)) // email is valid
    document.getElementById("email2msg").innerHTML = "";
  else { // email is not valid
    document.getElementById("email2msg").innerHTML = "(invalid email address)";
    valid = false;}
  
  // check for matching email addresses
  if (document.getElementById("email1").value != document.getElementById("email2").value) {
    document.getElementById("submitmsg").innerHTML = "(email addresses do not match)";
    valid = false;}
  else 
    document.getElementById("submitmsg").innerHTML = "";
  
  // set the submit button state
  if (valid == true)
    document.getElementById("submitbutton").removeAttribute('disabled');
  else
    document.getElementById("submitbutton").disabled = "disabled";
}

var last="";
var rot13map;
function rot13init()
{
  var map = new Array();
  var s   = "abcdefghijklmnopqrstuvwxyz";
  
  for (i=0; i<s.length; i++)
    map[s.charAt(i)]      = s.charAt((i+13)%26);
  for (i=0; i<s.length; i++)
    map[s.charAt(i).toUpperCase()]  = s.charAt((i+13)%26).toUpperCase();
  return map;
}
function decode(a)
{
  if (!rot13map)
    rot13map=rot13init();
  s = "";
  for (i=0; i<a.length; i++)
    {
      var b = a.charAt(i);

      s += (b>='A' && b<='Z' || b>='a' && b<='z' ? rot13map[b] : b);
    }
  return s;
}

// jQuery stuff for links
$(document).ready(function() {
  $('a[@href^="http://"]').addClass("external").attr("target","_blank");
  //$("a.external").click(function() { return true; }); //XHTML compliant
});



