function byId(id) {
  return document.getElementById(id);
}
function getTopPos(element) {
  var val = element.offsetTop;
  while ((element = element.offsetParent) != null) {
    val += element.offsetTop;
  }
  return val;
}

function getLeftPos(element) {
  var val = element.offsetLeft;
  while((element = element.offsetParent) != null) {
    val += element.offsetLeft;
  }
  return val;
}
function openFdWorldMap() {
  if (window.fdWorldMap != null && !window.fdWorldMap.closed) {
    window.fdWorldMap.focus();
    return;
  }

  var w = 800;
  var h = 600;
  var x = Math.ceil(screen.availWidth/2 - w/2);
  var y = Math.ceil(screen.availHeight/2 - h/2);

  params = "width=" + w + ",height=" + h + ",resizable=yes,status=yes," +
    "left=" + x + "," +
    "top=" + y;

  url = "/fdmaps/fd_world_map.php";
  window.fdWorldMap = window.open(url, "fdWorldMap", params);
}
function showDialogue(uid1, uid2, msgId) {
  if (window.dialogueWindow != null && !window.dialogueWindow.closed) {
    var url = '';
    if ((uid1 == dialogueWindow.uid1 && uid2 == dialogueWindow.uid2) || (uid1 == dialogueWindow.uid2 && uid2 == dialogueWindow.uid1)) {
      url = dialogueWindow.location.toString();
      var pos = url.lastIndexOf('#');
      if (pos > -1) {
        url = url.substr(0, pos);
        if (msgId != 0) url += '#' + msgId;
      }
    } else {
      url = "http://www.finaldimension.net/users/dialogue.php?uid1=" + uid1 + "&uid2=" + uid2;
      if (msgId != 0) url += '&msgId=' + msgId + '#' + msgId;
    }
    window.dialogueWindow.location = url;
    window.dialogueWindow.focus();
    return;
  }

  var w = 550;
  var h = 700;
  var x = 50;
  var y = 50;
  params = "width=" + w + ",height=" + h + ",resizable=yes,status=no,scrollbars=yes," +
    "left=" + x + "," +
    "top=" + y;

  url = "/users/dialogue.php?uid1=" + uid1 + "&uid2=" + uid2;
  if (msgId != 0) url += '&msgId=' + msgId + '#' + msgId;
  window.dialogueWindow = window.open(url, "dialogueWindow", params);
}


function createPhotoWithShadow(imgSrc, link) {
  // table created with innerHTML to simplify keep cellspacing out of css
  var div = document.createElement('div');
  div.innerHTML = '<table cellspacing="0" cellpadding="0"><thead/><tfoot/></table>';
  div.id = 'mp_face';
  var table = div.childNodes[0];
  var tbody = table.appendChild(document.createElement('tbody'));

  var tr, td, img, d = null;
  tr = tbody.appendChild(document.createElement('tr'));
  td = tr.appendChild(document.createElement('td'))
  if (link) {
    a = td.appendChild(document.createElement('a'));
    a.href = link;
    img = a.appendChild(document.createElement('img'));
    img.src = imgSrc;
  }

  td = tr.appendChild(document.createElement('td'));
  td.className = 'shadow_top_right_td';
  d = td.appendChild(document.createElement('div'));
  d.className = 'shadow_corner_div';

  img = d.appendChild(document.createElement('img'));
  img.src = '/v3/img/shadow_tr.gif';
  img.width = img.height = '7';

  tr = tbody.appendChild(document.createElement('tr'));
  td = tr.appendChild(document.createElement('td'));
  td.className = 'shadow_bottom_left_td';
  d = td.appendChild(document.createElement('div'));
  d.className = 'shadow_corner_div';
  img = d.appendChild(document.createElement('img'));
  img.src = '/v3/img/shadow_bl.gif';
  img.width = img.height = '7';

  td = tr.appendChild(document.createElement('td'));
  d = td.appendChild(document.createElement('div'));
  d.className = 'shadow_corner_div';

  img = d.appendChild(document.createElement('img'));
  img.src = '/v3/img/shadow_br.gif';
  img.width = img.height = '7';

  return div;
}

function getWindowInnerSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  var size = new Object();
  size.width = myWidth;
  size.height = myHeight;
  return size;
}

function getScrollTop() {
  var scrollTop = document.body.scrollTop;
  if (scrollTop == 0) {
    if (window.pageYOffset)
      scrollTop = window.pageYOffset;
    else
      scrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
  }
  return scrollTop;
}
function trim(str) {
  var trimmed = str.replace(/^\s+|\s+$/g, '') ;
  return trimmed;
}
