
function getElm(name){
  var x = new Object;
  if( document.getElementById){
    x = document.getElementById(name);
  } else if( document.layers) {
    x = document.layers[name];
  } else if( document.all){
    x = document.all[name];
  } 
  return x;
}

var isIE = ( document.all) ? 1 : 0;
var StdWidth = 325;

function doNothing() { }

var stdTextLength = function(elm) {
    if (elm.nodeType == 3) { 
        return elm.nodeValue.length;
    }
    var count = 0;
    for (var i in elm.childNodes) {
        count += textLength(elm.childNodes[i]);
    }
    return count;
}

var iPhoneTextLength = function(elm) {
  return elm.firstChild.nodeValue.length;
}

var ua = navigator.userAgent.toLowerCase();
var isBadSafari = (( ua.indexOf(' safari/') != -1)
   && ( ua.indexOf(' safari/5') == -1));

var textLength = isBadSafari ? iPhoneTextLength : stdTextLength;

function showHidden(e, identifier) {

   var mx, my, Wwidth;

   if ( isIE ) {
     mx = window.event.clientX + document.documentElement.scrollLeft 
     + document.body.scrollLeft;
     my = window.event.clientY + document.documentElement.scrollTop
     + document.body.scrollTop;
     Wwidth = document.body.offsetWidth;
   } else {
     mx = e.pageX;
     my = e.pageY;
     Wwidth = window.innerWidth;
   }
	
   var obj = getElm(identifier);
   var l = mx - 30; // default left position from cursor
   var t = my + 10; // top position
   var Twidth = textLength(obj) * 8; // weak hack, font metrics unobtainable
   var MaxWidth = Wwidth * .7; // max 70% of available client area 
   var w = Twidth; // start by making it very roughly the text width
   if ( Twidth > StdWidth) { // adjust all but very short text to a set width
     w = ((( Twidth * .29) < MaxWidth) ? StdWidth : MaxWidth); 
   } 
   if ((l+w) > Wwidth) { // make sure its right extent is visible
     l = Math.max( 20, (Wwidth - w) - 35);
   }
   obj.style.width = "" + w + "px";
   obj.style.left = "" + l + "px";
   obj.style.top = "" + t + "px";
   obj.style.display = "block";

}

function hideHidden(identifier) {
  var obj = getElm(identifier);
  obj.style.display = "none";
}


function statusPermalink( strName, strDate) {
  window.status = "A permanent link to this point in the game: " 
     + strName + " at " + strDate;
  return true;
}

function setStatus( src) { 
  window.status=src;
  return true;
}

function clearStatus() {
  window.status = "";
  return true;
}

function rotchar( o)
{
  var n = o;
  if ((( o > 64) && ( o < 91)) || (( o > 96) && ( o < 123))) {
    n = o + 13;
    if (( o > 109) || (( o < 91) && ( o > 77))) {
      n -= 26;
    }
  }
  return n;
}

function rot( src)
{
  var nstr = "";
  for ( var i = 0; i < src.length; i++) { 
    nstr += String.fromCharCode(rotchar( src.charCodeAt(i)));
  }
  return nstr;
}


