var RML = {};

// Timestamp for preventing IE caching the GET request
function fetch_unix_timestamp() {
  return parseInt(new Date().getTime().toString().substring(0, 10));
}

RML.checkMemberName = function () {

  if (window.XMLHttpRequest) {
    http = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    http = new ActiveXObject("Microsoft.XMLHTTP");
  }

  handle = document.getElementById('alias');
  if (handle.value != '') {
    var url = 'http://ratemylandlord.com/common/checkMemberName.html?';
    var timestamp = fetch_unix_timestamp();
    var fullurl = url + '&alias=' + encodeURIComponent(handle.value) + '&timestamp=' + timestamp;

    // Show availability
    function statechange_members() {
      if (http.readyState == 4) {
        var html = http.responseText;
        document.getElementById('memberNameAvailability').innerHTML = html;
      }
    }

    http.onreadystatechange = statechange_members;
    http.open("GET", fullurl, true);
    http.send(null);
  } else {
    document.getElementById('memberNameAvailability').innerHTML = '&nbsp;';
  }
}
