function $get(id)
{
  return document.getElementById(id);
}

function createXHR()
{
  if (typeof XMLHttpRequest != "undefined")
  {
    return new XMLHttpRequest();
  }
  else
  {
    var aVersions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0"];
    for (var z=0; z < aVersions.length; z++)
    {
      try
      {
        var oXHR = new ActiveXObject(aVersions[z]);
        return oXHR;
      }
      catch (oError)
      {
      }
    }
  }

  throw new Error("XMLHttpRequest or XMLHttp could not be created");
}

function checkPIN(PIN)
{
  $get('PINError').style.display = 'none';
  if(PIN.length == 17)
  {
    var xhr = createXHR();
    xhr.open("POST", site_url+"ajax/checkPIN.php", false);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr.send('PIN='+PIN);
    var rows = xhr.responseText.split("\n");
    if(rows[0] == 'OKAY')
    {
      $get('PINError').innerHTML = '';
      $get('PINError').style.display = 'none';
    }
    else
    {
      var errorText = rows[1];
      $get('PINError').innerHTML = errorText;
      $get('PINError').style.display = 'block';
    }
  }
}

