// BUSCADOR DE DOMINIOS
// Validar el dominio que se ha escrito
function validarDominio(dominio){
	if (/^\w+(\-\w|\w)*$/.test(dominio)){
		return (true);
	}
	else{
	   alert(" El dominio que has escrito es incorrecto:\n  * Solo puede contener numeros, letras y guiones.\n  * No puede haber dos giones seguidos.\n  * No puede empezar o terminar en guión.\n");
	   return (false);
	}
}



function limpiarDivs(){
	document.getElementById('dvcom').innerHTML = '';
		
}



function buscar(){
	
	// Dominio a buscar
	var dominio = document.getElementById('dominio').value;
	
	
	limpiarDivs();
	
	if(validarDominio(dominio)){
		var extencion = document.getElementById('ext').value;
		
		consultarAjax(dominio,extencion,"dvcom");
		
	}
	
}


function buscar2(variable){
	
	// Dominio a buscar
	var dominio = document.getElementById('dominio').value;
	
	
	limpiarDivs();
	
	if(validarDominio(dominio)){
		var extencion = document.getElementById('ext').value;
		
		consultarAjax2(dominio,extencion,"dvcom",variable);
		
	}
	
}


// Función que crea la Clase de tipo coneccion ajax (XMLHTTPRequest)
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

// Búsqueda asincrona con Ajax
function consultarAjax(dominio,ext,target)
{
	document.getElementById(target).innerHTML = '<table width="100%" border="0"><tr align="left"><td width="34%" class="tituloNegro"><div align="left"><b>'+dominio+'.'+ext+'</b></div></td><td width="38%" class="tituloNegro"><div align="left"><img src="http://neubox.net/v3/mx/lod.gif" /></div></td><td width="28%" class="tituloNegro"><div align="left">&nbsp;</div></td></tr></table>';

	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP no esta disponible. Intenta con un navegador mas reciente.");
    var peticion = function (oXML) {  document.getElementById(target).innerHTML = oXML.responseText; };
	
	//alert(dominio+ "." + ext);
	
	if(window.document.getElementById('operacionDominio1').checked)	
    tipo = window.document.getElementById('operacionDominio1').value;
	
	if(window.document.getElementById('operacionDominio2').checked)	
    tipo = window.document.getElementById('operacionDominio2').value;
	
	if(window.document.getElementById('operacionDominio3').checked)	
    tipo = window.document.getElementById('operacionDominio3').value;
	
	plan = window.document.getElementById('plan').value;
	
		
	myConn.connect("../VerificarDominio_VER3.php?dominio="  + dominio + "&ext=" + ext + "&tipo=" + tipo + "&plan=" + plan, "POST", "", peticion);
		
}

function consultarAjax2(dominio,ext,target,variable)
{
	document.getElementById(target).innerHTML = '<table width="100%" border="0"><tr align="left"><td width="34%" class="tituloNegro"><div align="left"><b>'+dominio+'.'+ext+'</b></div></td><td width="38%" class="tituloNegro"><div align="left"><img src="http://neubox.net/v3/mx/lod.gif" /></div></td><td width="28%" class="tituloNegro"><div align="left">&nbsp;</div></td></tr></table>';

	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP no esta disponible. Intenta con un navegador mas reciente.");
    var peticion = function (oXML) {  document.getElementById(target).innerHTML = oXML.responseText; };
	
	//alert(dominio+ "." + ext);
	
	if(window.document.getElementById('operacionDominio1').checked)	
    tipo = window.document.getElementById('operacionDominio1').value;
	
	if(window.document.getElementById('operacionDominio2').checked)	
    tipo = window.document.getElementById('operacionDominio2').value;
	
	if(window.document.getElementById('operacionDominio3').checked)	
    tipo = window.document.getElementById('operacionDominio3').value;
	
	plan = window.document.getElementById('plan').value;
	
		
	myConn.connect("../VerificarDominio_VER3.php?variable=" + variable + "&dominio="  + dominio + "&ext=" + ext + "&tipo=" + tipo + "&plan=" + plan, "POST", "", peticion);
		
}



// Abre una ventana pop-Up para los detalles del dominio
function popUp(URL) {
	window.open(URL, "Detalles", 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=610,height=240');
}
