function nativeToAscii(str)
{
  var newstr = "";
  var charcode;

  for (x = 0; x < str.length; x++) {
    charcode = str.charCodeAt(x);
    if (charcode > 127) {
      newstr += "&#" + charcode + ";";
    } else {
      newstr += str.charAt(x);
    }
  }

  return newstr;
}

function asciiToNative(str)
{
  var newstr = "";

  for (x = 0; x < str.length; x++) {
    if (str.charAt(x) == '&' && str.charAt(x+1) == '#' && str.charAt(x+5) == ';') {
      newstr += String.fromCharCode(str.substring(x+2,x+5) - 0);
      x = x + 5;
    } else {
      newstr += str.charAt(x);
    }
  }

  return newstr;
}

// this function takes the same parameters as window.open
// but parses out the values of width/height from the features
// and adds left/top and screenX/screenY values to center the
// new window on the screen
function windowOpenCentered(url, name, features)
{
  var str = features;
  var height = 0;
  var width = 0;
  var startpos = -1, endpos = -1;

  if (str.charAt(str.length - 1) != ',') {
     str += ",";
  }

  startpos = str.indexOf("height=");
  if (startpos >= 0) {
    endpos = str.indexOf(",",startpos);
    height = str.substring(startpos + 7, endpos);
  }

  startpos = str.indexOf("width=");
  if (startpos >= 0) {
    endpos = str.indexOf(",",startpos);
    width = str.substring(startpos + 6, endpos);
  }  

  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += "left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }

  var win = window.open(url, name, str);

  return win;
}