/**************************************************************************************************
																				AJAX 2.0
**************************************************************************************************/
function XHConnPOST()
{
  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("Content-Type","application/x-www-form-urlencoded");
				xmlhttp.send(sVars);
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

	/*****************************************************************************
	FUNCION:	mensaje_deseo (evento)
	UTILIDAD:	Crea el mensaje "deseo registrar el dominio 'x'.mx, con base al que ya se tiene
	ENTRADAS:	
	SALIDAS:
	*****************************************************************************/
	function mensaje_deseo(){
		var dominio = document.getElementById('dominio').value;
		
		if( escritoCorrecto(dominio) || dominio == '' ){
			document.getElementById('errores_previos').innerHTML = '';
			document.getElementById('dv_deseo_registrar').innerHTML = dominio+'.mx';
		}
		else{
			document.getElementById('errores_previos').innerHTML = 'Por favor verifica la escritura del dominio';
			document.getElementById('dv_deseo_registrar').innerHTML = '';
		}
	}

	/*****************************************************************************
	FUNCION:	escrito Correctos
	UTILIDAD:	verifica que un dominio esté escrito sintácticamente bien
	ENTRADAS:	
		dominio -> Cadena con el dominio sin extensión
	SALIDAS:	true, si está bien ecrita, false si no.
	*****************************************************************************/
	function escritoCorrecto(dominio){
		if(/^[a-zA-Z0-9]+(\-[a-zA-Z0-9]|[a-zA-Z0-9])*$/.test(dominio))
			return true;
		else
			 return false;
	}	

/*************************************************************************************
FUNCIÓN: 	 convocar
DESCRIPCION: Variación del "fajax" usado anteriormente que envía las variables por POST (verdaderamente)
ENTRADAS: 
	params  	= Parametros requerido para la accion a realizar, separados por '&' y previmante "escapados" con urlencode
	target	= id del Div o SPAN a donde se regresará el resultado
SALIDAS	
*************************************************************************************/
function convocar_mx(params,target){
	if(target != '') document.getElementById(target).innerHTML = '<img src="http://neubox.net/lod.gif"/>';
	var myConn = new XHConnPOST();
	if (!myConn) alert("XMLHTTP no esta disponible. Intenta con un navegador mas reciente.");
	var regreso = function (oXML) {
		if(target != '')
			document.getElementById(target).innerHTML = oXML.responseText; 
	};
	myConn.connect("includes/mx/validar_mx.php", "POST", params, regreso);
}

/*************************************************************************************
FUNCIÓN: 	 enviarInfor
DESCRIPCION: Limia los campos y realiza el proceso del primer paso para verificar 
						 el registro del dominio
ENTRADAS: 

SALIDAS
	
*************************************************************************************/
function enviarInfor(){	
	// Datos del dominio
	var dominio = document.getElementById('dominio').value;
	var ext = document.getElementById('ext').value;

	// Primero validar que el dominio esté bien escrito
	if(escritoCorrecto(dominio)){
		// Vaciar errores previos
		document.getElementById('errores_previos').innerHTML = '';
		// Correr el paso cero (capthcha)
		paso_cero();
	}
	else{
		document.getElementById('errores_previos').innerHTML = 'Por favor verifica la escritura del dominio';
	}
}

// Poner todos los valores como si acabara de cargar la página, pero con AJAX
function reiniciar(){
	// Mostrar imagen de proceso
	document.getElementById('procesando_request').innerHTML = '<img src="/images/bar_loading.gif"/>';
	
	var myConn = new XHConnPOST();
	var params = 'accion=mostrar_captcha';

	if (!myConn) alert("XMLHTTP no esta disponible. Intenta con un navegador mas reciente.");
	var regreso = function (oXML) {
		// Quitar el loading
		document.getElementById('div_msg_ext').style.visibility = 'visible';
		document.getElementById('div_msg_ext').style.height = '100%';
		document.getElementById('procesando_request').innerHTML = '';
		// Cargar en el hidden la detwerminación de si mostrar el capctha o no
		document.getElementById('recaptchear').value = oXML.responseText;
		// POner el estilo del inicio
		iniciarEstilo();
		// Mostrar los formularios
		iniciarFormularios();
	}
	
	myConn.connect("includes/mx/validar_mx.php", "POST", params, regreso); 
}

function paso_cero(){	
		
	//Variables del captcha
	accion = 'captcha';
	var original = document.getElementById('recaptcha_challenge_field').value;
	var reto = document.getElementById('recaptcha_response_field').value;
	var recaptchear = document.getElementById('recaptchear').value;
	
	//----------------------------------------------------------------------------------
	//Agrega a los params los valores de los captcha
	params = 'accion='+accion+'&original='+escape(original)+'&reto='+escape(reto);
	//----------------------------------------------------------------------------------
	var myConn = new XHConnPOST();
	if (!myConn) alert("XMLHTTP no esta disponible. Intenta con un navegador mas reciente.");
	var regreso = function (oXML) {
			//PROCESA EL RESULTADO DEL CAPTCHA
			switch(oXML.responseText){
				case "captcha":
					document.getElementById('span_result_captcha').innerHTML = 'La palabra introducida no es correcta';
					Recaptcha.reload();
					break;
				case "correcto":
				/*
					document.getElementById('span_result_captcha').innerHTML = '<span style="color: #009900"> </span>';
					document.getElementById('m_opc_c').innerHTML = '1) Validar la disponibilidad del mx.';
					document.getElementById('m_opc_c').style.color = '#009900';
					document.getElementById('f_opc_c').innerHTML = '&nbsp;';
					document.getElementById('r_opc_c').innerHTML = '<img src="images/chk_on.png" alt="SI" title="SI" />';
				*/
					pocesa_paso1();
				break;
				default:
					document.getElementById('span_result_captcha').innerHTML = 'La palabra introducida no es correcta';
					Recaptcha.reload();
					break;
			}
			//----------------------------------------------------------------------------------
	};
	if ( recaptchear == 'si' ) {
		if(reto != ''){
			document.getElementById('span_result_captcha').innerHTML = '<span style="color: #D1D1D1">Validando las palabras que introdujiste </span>'+
			'<img src="images/lod.gif" alt="Buscando" title="Buscando" />';
			myConn.connect("includes/mx/validar_mx.php", "POST", params, regreso); 
		}
		else{
			document.getElementById('span_result_captcha').innerHTML = 'Por favor introduce las palabras que ves en la imagen.';
		}
	}
	else {
	/*		
		document.getElementById('f_opc_c').innerHTML = '';
		document.getElementById('m_opc_c').style.color = '#009900';
		document.getElementById('r_opc_c').innerHTML = '<img src="images/chk_on.png" alt="SI" title="SI" />';
	*/
		pocesa_paso1();
	}	
}

/*************************************************************************************
FUNCIÓN: 	 iniciarEstilo
DESCRIPCION: Cambia el estilo a los divs, para la animación del proceso
ENTRADAS: 
SALIDAS
*************************************************************************************/
function iniciarEstilo(){
	
	document.getElementById('f_opc_1').innerHTML = '';
	document.getElementById('m_opc_1').innerHTML = '';
	document.getElementById('r_opc_1').innerHTML = '';
	document.getElementById('f_opc_2').innerHTML = '';
	document.getElementById('m_opc_2').innerHTML = '';
	document.getElementById('r_opc_2').innerHTML = '';
	document.getElementById('f_opc_3').innerHTML = '';
	document.getElementById('m_opc_3').innerHTML = '';
	document.getElementById('r_opc_3').innerHTML = '';

	document.getElementById('div_resultados').innerHTML = '';
	document.getElementById('div_seguimiento').innerHTML = '';
	document.getElementById('div_link_otro').innerHTML = '';

	document.getElementById('div_resultados').style.background = '#FFFFFF';	
	document.getElementById('div_paso_1').style.background = '#FFFFFF';
	document.getElementById('div_paso_2').style.background = '#FFFFFF';
	document.getElementById('div_paso_3').style.background = '#FFFFFF';
	document.getElementById('div_seguimiento').style.background = '#FFFFFF';
	
}

function iniciarFormularios(){
	var mostrar_captcha = document.getElementById('recaptchear').value;

	// Form de seguimiento
	document.getElementById('div_opciones_seguimiento').style.visibility = 'hidden';
	
	// Volver a hacer visible el formualrio de dominio y quitar el letrero de reuqest
	document.getElementById('dominio').value = ''; // quita el dominio que estaba
	document.getElementById('div_msg_ext').style.visibility = 'visible';
	document.getElementById('procesando_request').innerHTML = '';
		
	// Si la varibale mostrar está en si, quitarle el hidden al captcha y poner otro
	if(mostrar_captcha == 'si'){
		document.getElementById('span_result_captcha').innerHTML = '';
		document.getElementById('elcaptcha').style.visibility = 'visible';
		document.getElementById('elcaptcha').style.height = "100%";

		Recaptcha.reload();
	}


	// Volver a poner el botón enviar
	document.getElementById('boton_enviar').style.visibility = 'visible';
}

/*************************************************************************************
FUNCIÓN: 	 pocesa_paso1
DESCRIPCION: Realiza el proceso del paso uno y arroja el resultado correspondiente

ENTRADAS: 

SALIDAS
	
*************************************************************************************/
function pocesa_paso1(){
	// Quitar el botón de enviar
	document.getElementById('boton_enviar').style.visibility = 'hidden';
	document.getElementById('elcaptcha').style.height = "0px";

	//COLOCA LA FLECHA EN EL PASO UNO Y EL GIF DE LOADING
	document.getElementById('div_paso_1').style.background = '#EEEEEE';
	document.getElementById('m_opc_1').style.color = '#444444';
	document.getElementById('f_opc_1').innerHTML = '<img src="images/arrow.gif" alt=">>" title="" />';
	document.getElementById('r_opc_1').innerHTML = '<img src="http://neubox.net/lod.gif"/>';
	//----------------------------------------------------------------------------------
	// Datos del dominio
	dominio = document.getElementById('dominio').value;
	ext = document.getElementById('ext').value;
	
	// Ocultar el formulario y mostrarlo como letrero
	document.getElementById('div_msg_ext').style.visibility = 'hidden';
	document.getElementById('div_msg_ext').style.height = '0px';
	document.getElementById('procesando_request').innerHTML = 'Ya poseo <b>www.'+dominio+'.'+ext+'</b> <br /> y deseo registrar el dominio '+
	' <b>'+dominio+'.mx</b>';
	
	
	document.getElementById('elcaptcha').style.visibility = 'hidden';
	document.getElementById('elcaptcha').style.height = "0px";
	
	//AQUI SE INSERTAN LOS PARAMETROS PARA ENVIAR POR POST
	params = 'accion=pocesa_paso1&dominio='+dominio+'&ext='+ext; 
	
	//----------------------------------------------------------------------------------
	var myConn = new XHConnPOST();
	if (!myConn) alert("XMLHTTP no esta disponible. Intenta con un navegador mas reciente.");
	var regreso = function (oXML) {
			//QUITA EL GIF QUE INDICA QUE SE ESTA PROCESANDO Y LA FLECHA
			document.getElementById('m_opc_1').innerHTML = '1) Validando Estructura y Restricciones Posibles.';
			document.getElementById('f_opc_1').innerHTML = '';
			//----------------------------------------------------------------------------------
			//PROCESA EL RESULTADO DEL PRIMER PASO
			switch(oXML.responseText){
				case "verde":
					document.getElementById('m_opc_1').style.color = '#009900'; 
					document.getElementById('r_opc_1').innerHTML = '<img src="images/chk_on.png" alt="SI" title="SI" />';
					document.getElementById('campo_resultado_1').value = 'verde';
					pocesa_paso2(dominio);
				break;
				case "amarillo":
					document.getElementById('m_opc_1').style.color = '#FF0000';
					document.getElementById('r_opc_1').innerHTML = '<img src="images/chk_off.png" alt="NO" title="NO" />';
					document.getElementById('campo_resultado_1').value = 'amarillo';
					
					
					document.getElementById('div_resultados').style.background = '#EEEEEE';	
					document.getElementById('div_resultados').innerHTML = '<div align="center" id="titulo_reporte" style="margin:10px; font-weight:bold; font-size: 14px;'+ 
					'background:#EEEEEE;">Reporte de Elegibilidad</div><div style="margin:5px; padding:3px; background-color:#D02626;"'+
					'align="center" class="load2"><div style="background-color:#FFF; border:1px solid #D05616; padding:5px;">'+
					'<table boder="0"><tr><td>'+
					'<div align="center" style="width:40px;"><img src="images/chk_off.png" alt="NO" title="NO" /></td>'+
					'<td><div align="center" style="color: #FF0000">El dominio '+dominio+'.'+ext+'.mx no existe.</div></td>'+
					'</tr></table>'+
					'</div></div>';
					// Mostrar un botón para refrescar la página
					document.getElementById('div_link_otro').innerHTML = '<a href="#" onclick="reiniciar(); return true;">Intentar con otro dominio .MX</a>';	
					break;
				case "azul":
					document.getElementById('m_opc_1').style.color = '#FF0000';
					document.getElementById('r_opc_1').innerHTML = '<img src="images/chk_off.png" alt="NO" title="NO" />';
					document.getElementById('campo_resultado_1').value = 'rojo';
					
					
					document.getElementById('div_resultados').style.background = '#EEEEEE';	
					document.getElementById('div_resultados').innerHTML = '<div align="center" id="titulo_reporte" style="margin:10px; font-weight:bold; font-size: 14px;'+ 
					'background:#EEEEEE;">Reporte de Elegibilidad</div><div style="margin:5px; padding:3px; background-color:#D02626;"'+
					'align="center" class="load2"><div style="background-color:#FFF; border:1px solid #D05616; padding:5px;">'+
					'<table boder="0"><tr><td>'+
					'<div align="center" style="width:40px;"><img src="images/chk_off.png" alt="NO" title="NO" /></div></tr>'+
					'<td><div align="justify" style="color: #FF0000">El dominio '+dominio+'.mx no esta disponible.</div></td>'+
					'</tr></table></div></div>'+
					'<div align="justify" style="padding:10px;">'+
					'El dominio '+dominio+'.mx no esta disponible ya que se encuentra registrado o su solicitud de registro esta en proceso..</div>';
					document.getElementById('div_link_otro').innerHTML = '<a href="#" onclick="reiniciar(); return true;">Intentar con otro dominio .MX</a>';	
					break;
				case "rojo":
					document.getElementById('m_opc_1').style.color = '#FF0000';
					document.getElementById('r_opc_1').innerHTML = '<img src="images/chk_off.png" alt="NO" title="NO" />';
					document.getElementById('campo_resultado_1').value = 'rojo';
					
					document.getElementById('div_resultados').style.background = '#EEEEEE';	
					document.getElementById('div_resultados').innerHTML = '<div align="center" id="titulo_reporte" style="margin:10px; font-weight:bold; font-size: 14px;'+ 
					'background:#EEEEEE;">Reporte de Elegibilidad</div><div style="margin:5px; padding:3px; background-color:#D02626;"'+
					'align="center" class="load2"><div style="background-color:#FFF; border:1px solid #D05616; padding:5px;">'+
					'<table boder="0"><tr><td>'+
					'<div align="center" style="width:40px;"><img src="images/chk_off.png" alt="NO" title="NO" /></div></td>'+
					'<td><div align="center" style="color: #FF0000">El dominio '+dominio+'.mx esta restringido dentro de las pol&iacute;ticas del Registry .MX</div></td>'+
					'</tr></table></div></div>'+
					'<div align="justify" style="padding:10px;">'+
					'Lamentablemente el dominio '+dominio+'.mx est&aacute; restringido dentro de las políticas del Registry .MX'+
					'por lo que no podr&aacute; ser registrado. Por favor consulta las pol&iacute;ticas de nombres reservados para los dominios .MX de'+
					' primer nivel en <a href="http://www.registry.mx/reapertura/Dominios%20Reservados.pdf" target="_blank">este enlace</a>.</div>';
					document.getElementById('div_link_otro').innerHTML = '<a href="#" onclick="reiniciar(); return true;">Intentar con otro dominio .MX</a>';	
					break;
				default:
					document.getElementById('m_opc_1').style.color = '#b5a924';
					document.getElementById('r_opc_1').innerHTML = '<img src="images/signo.gif" alt="!" title="!" />';
					document.getElementById('campo_resultado_1').value = 'amarillo';
					
					
					document.getElementById('div_resultados').style.background = '#EEEEEE';	
					document.getElementById('div_resultados').innerHTML = '<div align="center" id="titulo_reporte" style="margin:10px; font-weight:bold; font-size: 14px;'+ 
				'background:#EEEEEE;">Reporte de Elegibilidad</div><div style="margin:5px; padding:3px; background-color:#FAEA32;" align="center">'+
					'<div style="background-color:#FFF; border:1px solid #EF9B52; padding:5px;">'+
					'<table boder="0"><tr><td>'+
					'<div align="center" style="width:40px;"><img src="images/signo.gif" alt="!" title="!" /></div></td>'+
					'<td><div align="center" style="color: #B5A924">Hay problemas con la conexi&oacute;n o has superado tu '+
					'l&iacute;mite por hora. Favor de intentarlo mas tarde.</div></td>'+
					'</tr></table>'+
					'</div></div>';
					// Mostrar un botón para refrescar la página
					document.getElementById('div_link_otro').innerHTML = '<a href="#" onclick="reiniciar(); return true;">Intentar otra vez</a>';	
				
			}
			//----------------------------------------------------------------------------------
	};
	myConn.connect("includes/mx/validar_mx.php", "POST", params, regreso); //-------------------------------------------------->>>>>>CAMBIAR ARCHIVO AL QUE SE ENVIA<<<<<<<<<<<<
}

/*************************************************************************************
FUNCIÓN: 	 pocesa_paso2
DESCRIPCION: Realiza el proceso del paso dos y arroja el resultado correspondiente
ENTRADAS: 
SALIDAS
	
*************************************************************************************/
function pocesa_paso2(dominio){
	//COLOCA LA FLECHA EN EL PASO DOS Y EL GIF DE LOADING
	document.getElementById('div_paso_2').style.background = '#EEEEEE';
	document.getElementById('m_opc_2').style.color = '#444444';
	document.getElementById('f_opc_2').innerHTML = '<img src="images/arrow.gif" alt=">>" title="" />';
	document.getElementById('r_opc_2').innerHTML = '<img src="http://neubox.net/lod.gif"/>';
	
	// Datos del dominio
	dominio = document.getElementById('dominio').value;
	ext = document.getElementById('ext').value;
	
	//----------------------------------------------------------------------------------
	//AQUI SE INSERTAN LOS PARAMETROS PARA ENVIAR POR POST
	var params = 'accion=pocesa_paso2&dominio='+dominio+'&ext='+ext;
	
	//----------------------------------------------------------------------------------
	var myConn = new XHConnPOST();
	if (!myConn) alert("XMLHTTP no esta disponible. Intenta con un navegador mas reciente.");
	var regreso = function (oXML) {
			//QUITA EL GIF QUE INDICA QUE SE ESTA PROCESANDO Y LA FLECHA
			document.getElementById('m_opc_2').innerHTML = '2) Validando Disponibilidad, Registrar y Fecha de Registro.';
			document.getElementById('f_opc_2').innerHTML = '';
			//----------------------------------------------------------------------------------
			//PROCESA EL RESULTADO DEL SEGUNDO PASO
			var datos = new Array();	// arreglo con los datos regresados de la ultima verificacion
			//  separar el resultado de la verificacion con un , para obtener el ID insertado
			datos = oXML.responseText.split(","); 
			switch(datos[0]){
				case "verde":
					document.getElementById('m_opc_2').style.color = '#009900'; 
					document.getElementById('r_opc_2').innerHTML = '<img src="images/chk_on.png" alt="SI" title="SI" />';
					document.getElementById('campo_resultado_2').value = 'verde';
					document.getElementById('id_solicitud').value = datos[1];
					// Continuar
					pocesa_paso3(datos[1]);
				break;			
				case "amarillo":
					document.getElementById('m_opc_2').style.color = '#b5a924';
					document.getElementById('r_opc_2').innerHTML = '<img src="images/signo.gif" alt="!" title="!" />';
					document.getElementById('campo_resultado_2').value = 'amarillo';

					document.getElementById('id_solicitud').value = datos[1];
					// Continuar
					pocesa_paso3(datos[1]);
				break;
				case "azul":
					document.getElementById('m_opc_2').style.color = '#FF0000';
					document.getElementById('r_opc_2').innerHTML = '<img src="images/chk_off.png" alt="NO" title="NO" />';
					document.getElementById('campo_resultado_2').value = 'rojo';
					
					
					document.getElementById('div_resultados').style.background = '#EEEEEE';	
					document.getElementById('div_resultados').innerHTML = '<div align="center" id="titulo_reporte" style="margin:10px; font-weight:bold; font-size: 14px;'+ 
					'background:#EEEEEE;">Reporte de Elegibilidad</div><div style="margin:5px; padding:3px; background-color:#D02626;"'+
					'align="center" class="load2"><div style="background-color:#FFF; border:1px solid #D05616; padding:5px;">'+
					'<table boder="0"><tr><td>'+
					'<div align="center" style="width:40px;"><img src="images/chk_off.png" alt="NO" title="NO" /></div></td>'+
					'<td ><div align="center" style="color: #FF0000; ">El dominio '+dominio+'.mx no esta disponible.</div></td>'+
					'</tr></table></div></div>'+
					'<div align="justify" style="padding:10px;">'+
					'El dominio '+dominio+'.mx no esta disponible ya que se encuentra registrado.</div>';
					// Mostrar un botón para refrescar la página
					document.getElementById('div_link_otro').innerHTML = '<a href="#" onclick="reiniciar(); return true;">Intentar con otro dominio .MX</a>';	
				break;
				case "rojo":
					document.getElementById('m_opc_2').style.color = '#FF0000';
					document.getElementById('r_opc_2').innerHTML = '<img src="images/chk_off.png" alt="NO" title="NO" />';
					document.getElementById('campo_resultado_2').value = 'rojo';
					
					
					document.getElementById('div_resultados').style.background = '#EEEEEE';	
					document.getElementById('div_resultados').innerHTML = '<div align="center" id="titulo_reporte" style="margin:10px; font-weight:bold; font-size: 14px;'+ 
				'background:#EEEEEE;">Reporte de Elegibilidad</div><div style="margin:5px; padding:3px; background-color:#D02626;"'+
					'align="center" class="load2"><div style="background-color:#FFF; border:1px solid #D05616; padding:5px;">'+
					'<table boder="0"><tr><td>'+
					'<div align="center" style="width:40px;"><img src="images/chk_off.png" alt="NO" title="NO" /></div></td>'+
					'<td ><div align="center" style="color: #FF0000; ">El dominio '+dominio+'.'+ext+' fue registrado despu&eacute;s del 1 de Marzo.</div></td>'+
					'</tr></table></div></div>'+
					'<div align="justify" style="padding:10px;">'+
					'Lamentablemente el dominio '+dominio+'.'+ext+'.mx fue registrado despues del 1 de Marzo por lo que no podrá ser '+
					'registrado durante el periodo de Pre-Registro que finaliza el 31 de Julio. Podrás optar por registrar el dominio '+
					dominio+'.mx a partir del 1 de Septiembre.</div>';
					// Mostrar un botón para refrescar la página
					document.getElementById('div_link_otro').innerHTML = '<a href="#" onclick="reiniciar(); return true;">Intentar con otro dominio .MX</a>';	
					break;
				case "morado":
					document.getElementById('m_opc_2').style.color = '#b5a924';
					document.getElementById('r_opc_2').innerHTML = '<img src="images/signo.gif" alt="!" title="!" />';
					document.getElementById('campo_resultado_2').value = 'amarillo';
					
					
					document.getElementById('div_resultados').style.background = '#EEEEEE';	
					document.getElementById('div_resultados').innerHTML = '<div align="center" id="titulo_reporte" style="margin:10px; font-weight:bold; font-size: 14px;'+ 
					'background:#EEEEEE;">Reporte de Elegibilidad</div><div style="margin:5px; padding:3px; background-color:#FAEA32;" align="center">'+
					'<div style="background-color:#FFF; border:1px solid #EF9B52; padding:5px;">'+
					'<table boder="0"><tr><td>'+
					'<div align="center" style="width:40px;"><img src="images/signo.gif" alt="!" title="!" /></div></td>'+
					'<td ><div align="center" style="color: #B5A924; ">Problemas de conecci&oacute;n</div></td>'+
					'</tr></table></div></div>'+
					'<div align="justify" style="padding:10px;">'+
					'En este momento estamos experminetando problemas de conecci&oacute;n con el servidor EPP. Favor de intentarlo mas tarde</div>';
					// Mostrar un botón para refrescar la página
					document.getElementById('div_link_otro').innerHTML = '<a href="#" onclick="reiniciar(); return true;">Intentar con otro dominio .MX</a>';	
					break;
			}
			//----------------------------------------------------------------------------------
	};
	myConn.connect("includes/mx/validar_mx.php", "POST", params, regreso);//-------------------------------------------------->>>>>>CAMBIAR ARCHIVO AL QUE SE ENVIA<<<<<<<<<<<<
}

/*************************************************************************************
FUNCIÓN: 	 pocesa_paso3
DESCRIPCION: Realiza el proceso del paso tres y arroja el resultado correspondiente
ENTRADAS: 
	
SALIDAS
	
*************************************************************************************/
function pocesa_paso3(id){
	//COLOCA LA FLECHA EN EL PASO TRES Y EL GIF DE LOADING
	document.getElementById('div_paso_3').style.background = '#EEEEEE';
	document.getElementById('m_opc_3').style.color = '#444444';
	document.getElementById('f_opc_3').innerHTML = '<img src="images/arrow.gif" alt=">>" title="" />';
	document.getElementById('r_opc_3').innerHTML = '<img src="http://neubox.net/lod.gif"/>';
	//----------------------------------------------------------------------------------
	//AQUI SE INSERTAN LOS PARAMETROS PARA ENVIAR POR POST
	params = 'accion=pocesa_paso3&id='+id;//----------------------------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>CADENA DE VARIABLES VIA POST<<<<<<<<<<<<
	//----------------------------------------------------------------------------------
	var myConn = new XHConnPOST();
	if (!myConn) alert("XMLHTTP no esta disponible. Intenta con un navegador mas reciente.");
	var regreso = function (oXML) {
			//QUITA EL GIF QUE INDICA QUE SE ESTA PROCESANDO Y LA FLECHA
			document.getElementById('m_opc_3').innerHTML = '3) Validando Antig&uuml;edad.';
			document.getElementById('f_opc_3').innerHTML = '';
			//----------------------------------------------------------------------------------
			//  separar el resultado de la verificacion con un , para obtener el ID insertado
			datos = oXML.responseText; 
			switch(datos){
				case "verde":
					document.getElementById('m_opc_3').style.color = '#009900'; 
					document.getElementById('r_opc_3').innerHTML = '<img src="images/chk_on.png" alt="SI" title="SI" />';
					document.getElementById('campo_resultado_3').value = 'verde';
				break;			
				case "amarillo":
					document.getElementById('m_opc_3').style.color = '#B5A924';
					document.getElementById('r_opc_3').innerHTML = '<img src="images/signo.gif" alt="!" title="!" />';
					document.getElementById('campo_resultado_3').value = 'amarillo';
					break;
				case "rojo":
					document.getElementById('m_opc_3').style.color = '#FF0000';
					document.getElementById('r_opc_3').innerHTML = '<img src="images/chk_off.png" alt="NO" title="NO" />';
					document.getElementById('campo_resultado_3').value = 'rojo';
					break;
			}
			//----------------------------------------------------------------------------------
			pocesa_paso4(); //LLAMA AL PASO CUATRO EN CUALQUIERA DE LOS CASOS
	};
	myConn.connect("includes/mx/validar_mx.php", "POST", params, regreso);//-------------------------------------------------->>>>>>CAMBIAR ARCHIVO AL QUE SE ENVIA<<<<<<<<<<<<
}

/*************************************************************************************
FUNCIÓN: 	 enviarInfor
DESCRIPCION: Despliega un mensaje segun los resultados anteriores
ENTRADAS: 
	
SALIDAS
	
*************************************************************************************/
function pocesa_paso4(){
	//OBTIENE EL RESULTADO DE LOS TRES PASOS ANTERIORES
	var disp = document.getElementById('campo_resultado_1').value;
	var con_neubox = document.getElementById('campo_resultado_2').value;
	var oldest = document.getElementById('campo_resultado_3').value;
	var id = document.getElementById('id_solicitud').value+'';
	var dominio = document.getElementById('dominio').value;
	var ext = document.getElementById('ext').value;
	
	document.getElementById('div_resultados').style.background = '#EEEEEE';	
	
	// VERDE
	if(disp == "verde" && con_neubox == "verde" && oldest == "verde"){ 
		// La liga será para contratar el MX
		llave = hex_md5(id);	// encripta la id en md5
		liga = 'contratar_paso1.php?dominio='+dominio+'&extension=mx&origen=mx&verificado='+llave;

		document.getElementById('div_resultados').innerHTML = '<div align="center" id="titulo_reporte" style="margin:10px; font-weight:bold; font-size: 14px;'+ 
		'background:#EEEEEE;">Reporte de Elegibilidad</div><div class="load1" style="margin:5px; padding:3px; background-color:#5FA83C;" align="center">'+
		'<div style="background-color:#FFF; border:1px solid #9CD65E; padding:5px;">'+
		'<table boder="0"><tr><td>'+
		'<div align="center" style="width:40px;"><img src="images/chk_on.png" alt="SI" title="SI" /></div></td>'+
		'<td><div align="center" style="color: #009900; ">&iexcl;Felicidades! Eres completamente elegible para obtener el dominio</td></tr></table></div></div>'+
		'<div align="justify" style="padding:10px;">'+
		'<strong>Para solicitar el dominio '+dominio+'.mx haz click </strong><a href="'+liga+'">en este enlace</a> y sigue las instrucciones de nuestro sistema. '+
		'Nosotros te informaremos cuando tu solicitud se halla aprobado y as&iacute; mismo puedes consultar el estado de la solicitud en tu '+
		'<a href="http://clientes.neubox.net" target="_blank">panel del cliente</a>.</div>';
	}
	// AMRILLO
	else{
		// La liga será para transferir el que ya tiene
		liga = 'contratar_paso1.php?dominio='+dominio+'&extension='+ext+'&origen=mx&tipo=2';
		if(disp == "verde" && con_neubox == "amarillo"){
			document.getElementById('div_resultados').innerHTML = '<div align="center" id="titulo_reporte" style="margin:10px; font-weight:bold; font-size: 14px;'+ 
				'background:#EEEEEE;">Reporte de Elegibilidad</div><div style="margin:5px; padding:3px; background-color:#FAEA32;" align="center">'+
			'<div style="background-color:#FFF; border:1px solid #EF9B52; padding:5px;">'+
			'<table boder="0"><tr><td>'+
			'<div align="center" style="width:40px;"><img src="images/signo.gif" alt="!" title="!" /></div></td>'+
			'<td><div align="center" style="color: #B5A924">El dominio '+dominio+'.'+ext+' no est&aacute; registrado en NEUBOX.'+
			' Para obtener el dominio '+dominio+'.mx primero deber&aacute;s transferir el dominio original a nosotros.</div>'+
			'</tr></table>'+
			'</div></div>'+
			'<div align="justify" style="padding:10px;">'+
			'Dado que el dominio '+dominio+'.'+ext+' no esta registrado con nosotros<strong> no nos es posible saber si es el mas antiguo</strong>, '+
			'por lo que no te podemos decir con certeza si eres completamente elegible de obtener el dominio '+dominio+'.mx'+
			'<br/><br/>Lo primero que tienes que hacer es <strong>transferir el dominio '+dominio+'.'+ext+' con nosotros</strong>, puedes iniciar este proceso '+
			'siguiendo <a href="'+liga+'">este enlace</a>, una vez que tu transferencia haya finalizado <strong>te notificaremos vía e-mail </strong>para que continues con el '
			'proceso de registro de '+dominio+'.mx, si deseas mas informaci&oacute;n <a href="contacto.php" target="_blank">cont&aacute;ctanos</a>.</div>';
		}
		// AMARILLO
		else{
			if(disp == "verde" && con_neubox == "verde" && oldest == "amarillo"){
				// La liga será para contratar el MX
				llave = hex_md5(id);	// encripta la id en md5
				liga = 'contratar_paso1.php?dominio='+dominio+'&extension=mx&origen=mx&verificado='+llave;
				
				document.getElementById('div_resultados').innerHTML = '<div align="center" id="titulo_reporte" style="margin:10px; font-weight:bold; font-size: 14px;'+ 
				'background:#EEEEEE;">Reporte de Elegibilidad</div><div style="margin:5px; padding:3px; background-color:#FAEA32;" align="center">'+
				'<div style="background-color:#FFF; border:1px solid #EF9B52; padding:5px;">'+
				'<table boder="0"><tr><td>'+
				'<div align="center" style="width:40px;"><img src="images/signo.gif" alt="!" title="!" /></div></td>'+
				'<td ><div align="center" style="color: #B5A924; ">El dominio '+dominio+'.'+ext+' esta registrado en NEUBOX '+
				'pero no es el mas antiguo.</div></td>'+
				'</tr></table></div></div>'+
				'<div align="justify" style="padding:10px;">'+
				'Dado que el dominio '+dominio+'.'+ext+' <strong>no es el dominio mas antiguo con el prefijo &quot;'+dominio+'&quot;</strong> es probable que alguien mas solicite el '+
				'dominio '+dominio+'.mx y tu solicitud no sea exitosa, aun as&iacute; <strong>hay probabilidad de que obtengas el dominio '+dominio+'.mx</strong>, para esto'+
				'es necesario que <strong>solicites el registro de tu dominio .MX de primer nivel.</strong><br/><br/>'+
				'Para solicitar el dominio '+dominio+'.mx  haz click en <a href="'+liga+'">este enlace</a> y sigue las instrucciones de nuestro sistema. '+
				'Nosotros te informaremos cuando tu solicitud se halla '+
				'aprobado y as&iacute; mismo puedes consultar el estado de la solicitud en tu panel del cliente.</div>';
			}
			// AMARILLO
			else{
				// ROJO
				document.getElementById('div_resultados').innerHTML = '<div align="center" id="titulo_reporte" style="margin:10px; font-weight:bold; font-size: 14px;'+ 
				'background:#EEEEEE;">Reporte de Elegibilidad</div><div style="margin:5px; padding:3px; background-color:#D02626;"'+
				'align="center" class="load2"><div style="background-color:#FFF; border:1px solid #D05616; padding:5px;">'+
				'<div align="center"><img src="images/chk_off.png" alt="NO" title="NO" /></div>'+
				'<div align="center" style="color: #FF0000">ERROR NO SE PUDO DETERMINAR ESTADO</div>'+
				'Lo sentimos. Nos se pudo determinar el estado del dominio '+dominio+'.'+ext+' por favor cont&Aacute;ctanos si crees que esto es un error.</div></div>';
			}
		}
	}
	//Función para los correos
	genera_seguimiento(id);
	
	// Mostrar un botón para refrescar la página
	document.getElementById('div_link_otro').innerHTML = '<a href="#" onclick="reiniciar(); return true;">Intentar con otro dominio .MX</a>';	
}

	/*************************************************************************************
	FUNCIÓN: 	 genera_seguimiento
	DESCRIPCION: Obtiene los datos necesario para el seguimiento de la solicitud del domino ".MX"
	ENTRADAS: 
		id 	->		Id del registro de la solicitud
	SALIDAS
		
	*************************************************************************************/
	function genera_seguimiento(id){
		document.getElementById('id_seguimiento').value = id;
		document.getElementById('div_seguimiento').innerHTML = '<img src="http://neubox.net/lod.gif" /> '+
		'Buscando un correo electr&oacute;nico registrado con nosotros para dar el seguimiento.';
		
		
		document.getElementById('div_seguimiento').style.background = '#EEEEEE';	
		
		params = 'accion=genera_seguimiento&id='+escape(id);
		var myConn = new XHConnPOST();
		if (!myConn) alert("XMLHTTP no esta disponible. Intenta con un navegador mas reciente.");
		var regreso = function (oXML) {
				if(oXML.responseText == false){
					document.getElementById('div_seguimiento').innerHTML = 'Se genero un error al buscar tu registro.';
				}
				else{
					var resultados = oXML.responseText.split('|');
					if(resultados.length == 1){
						document.getElementById('div_seguimiento').innerHTML = 'No se encontr&oacute; un registro en la base de datos.<br />';
						document.getElementById('div_seguimiento').innerHTML += ' Si deseas realizar un seguimiento de tu resultado a trav&eacute;s'+
						' de un correo electr&oacute;nico, puedes ingresar uno y a continuaci&oacute;n dar clic en &quot;Enviar&quot;.';
						document.getElementById('email_seguimiento').value = '';
						document.getElementById('nombre_seguimiento').value = '';
						document.getElementById('div_opciones_seguimiento').style.visibility = 'visible';
						document.getElementById('accion_seguimiento').value = 'no-registrado';
					}
					else{
						document.getElementById('div_seguimiento').innerHTML = 'Estimado <strong>'+resultados[0]+'</strong>,<br />'+
						'En nuestro sistema tenemos registrado el siguiente correo electr&oacute;nico. Si deseas que un reporte sea enviado a tu correo, da clic en'+
						'el bot&oacute;n &quot;Enviar&quot;.';
						document.getElementById('email_seguimiento').value = resultados[1];
						document.getElementById('nombre_seguimiento').value = resultados[0];
						document.getElementById('div_opciones_seguimiento').style.visibility = 'visible';
						document.getElementById('accion_seguimiento').value = 'registrado';
					}
				}
		};
		myConn.connect("includes/mx/validar_mx.php", "POST", params, regreso);
	}
	
	/*************************************************************************************
	FUNCIÓN: 	 enviar_seguimiento
	DESCRIPCION: Envia el correo electronico del seguimiento del resultado al solicitar un
							 dominio .MX
	ENTRADAS: 
		Ninguna
	SALIDAS
		Ninguna
	*************************************************************************************/
	function enviar_seguimiento(){
		var id = document.getElementById('id_seguimiento').value;
		var accion = document.getElementById('accion_seguimiento').value;
		var nombre = document.getElementById('nombre_seguimiento').value;
		var correos = document.getElementById('email_seguimiento').value;
		var filtro  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var bandera = true;
		email = correos.split(',');
		i=0;
		correos = '';
		while(i < email.length && bandera == true){
			if(email[i] != ''){
				if(!filtro.test(email[i])){
					bandera = false;
				}
				else{
					correos = correos+email[i]+',';
				}
			}
			i++;
		}
		if(bandera == false){
			if(correos == ''){
				document.getElementById('div_mensaje_seguimiento').innerHTML = '<div style="color:#CC0000;">El formato del correo electr&oacute;nico es invalido</div>';
			}
			else{
				document.getElementById('div_mensaje_seguimiento').innerHTML = '<div style="color:#CC0000;">El formato del correo electr&oacute;nico:"'+email[i-1]+'" es invalido</div>';
			}
		}
		else{
			if(correos == ''){
				document.getElementById('div_mensaje_seguimiento').innerHTML = '<div style="color:#CC0000;">El formato del correo electr&oacute;nico es invalido</div>';
			}
			else{
				correos = correos.substr(0,correos.length-1);
				document.getElementById('div_opciones_seguimiento').style.visibility = 'hidden';
				document.getElementById('div_seguimiento').innerHTML = '<img src="http://neubox.net/lod.gif" /> Generando el seguimiento del resultado.';
				params = 'accion=enviar_seguimiento&id='+escape(id)+'&caso='+escape(accion)+'&nombre='+escape(nombre)+'&correo='+escape(correos);
				var myConn = new XHConnPOST();
				if (!myConn) alert("XMLHTTP no esta disponible. Intenta con un navegador mas reciente.");
				var regreso = function (oXML){
						if(oXML.responseText != false){
							document.getElementById('div_seguimiento').innerHTML = 'El Reporte de Elegibilidad se envi&oacute; correctamente.';
						}
				};
				myConn.connect("includes/mx/validar_mx.php", "POST", params, regreso);
			}
		}
	}