var getLogin = "ajax/getLogin.php?param="; // The server-side script
var getEmail = "ajax/getEmail.php?param=";

function handleHttpResponse() {
  if (http.readyState == 4) { //servidor responde corretamente
	//O login já foi escolhido
	if(http.responseText == "erroLogin"){
		alert("Este login já foi escolhido por outro usuário. Escolha outro Login!");
		document.getElementById("login").value = "";
		document.getElementById("login").focus();
		return false;
	}
	//O email já foi escolhido
	if(http.responseText == "erroEmail"){
		
		alert("Este email já foi escolhido por outro usuário. Escolha outro email!");
		document.getElementById("email").value = "";
		document.getElementById("email").focus();
		return false;
	}
	
  }
}

function checkLogin() {
  var myLogin = document.getElementById("login").value;
  http.open("GET", getLogin + escape(myLogin), true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}

function checkEmail() {
  var myEmail = document.getElementById("email").value;
  
  http.open("GET", getEmail + escape(myEmail), true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}

function checkEmailEdit() {
  var myEmail = document.getElementById("email").value;
  var emailUser = document.getElementById("emailUser").value;
  http.open("GET", getEmail + escape(myEmail) + "&emailUser=" + emailUser, true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
