// Função para pesquisar se o domínio já existe no sistema
function pesquisar_licenca( dominio,local ) {
  
  if(dominio == "") {
  
  document.getElementById('status').innerHTML="";
  document.getElementById('dominio').style.border="";
  
  if(local == "assinatura") {
  document.getElementById('Assinar').disabled = true;
  document.getElementById('Assinar').value = "Informe o sub-domínio";
  }
  
  } else {
  
  if(local == "admin") {
  var path = "";
  } else if(local == "assinatura") {
  var path = "painel/";  
  } else {
  var path = "../";
  }
  
  document.getElementById('status').innerHTML = "&nbsp;<img src='"+path+"img/spinner.gif' />";
  
  var http = new Ajax();
  http.open("GET", ""+path+"inc/funcoes.php?acao=pesquisar_licenca&dominio=" + dominio, true);
  http.onreadystatechange = function() {
	
  if (http.readyState == 4) {
    resultado = http.responseText;
    if (resultado) {
      document.getElementById('dominio').style.border="";
	  document.getElementById('status').innerHTML = "&nbsp;<img src='"+path+"img/ok.png' />";
	  
	  if(local == "assinatura") {
	  document.getElementById('Assinar').disabled = false;
	  document.getElementById('Assinar').value = "Concluir";
	  }
	  
	  } else {
	  var dominio = document.getElementById( 'dominio' ).value;
	  alert("O domínio "+dominio+" já está em uso por outro cliente! Por favor escolha outro.");
	  document.getElementById('dominio').value = '';
	  document.getElementById('dominio').style.border="1px solid red";
	  document.getElementById('dominio').focus();
	  document.getElementById('status').innerHTML = "&nbsp;<img src='"+path+"img/atencao2.png' />";
	  
	  if(local == "assinatura") {
	  document.getElementById('Assinar').disabled = true;
	  document.getElementById('Assinar').value = "Informe o sub-domínio";
	  }
	  
	}
  }
  
  }
  http.send(null);
  delete http;  
  }
}
// Rotina AJAX
function Ajax() {
var req;

try {
 req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
 try {
	req = new ActiveXObject("Msxml2.XMLHTTP");
 } catch(ex) {
	try {
	 req = new XMLHttpRequest();
	} catch(exc) {
	 alert("Esse browser não tem recursos para uso do Ajax");
	 req = null;
	}
 }
}

return req;
}
