//---------------------------------------------------------------------
//Función que valida el formulario de la mini-alta (AJAX)
//---------------------------------------------------------------------
function validacionMiniAlta(form, url_home)
{ 

	var validado = true;

	document.getElementById("BocadilloMiniAlta").style.visibility="hidden";
		
	// Comprobamos si el e-mail introducido es correcto
	if (!existeMail(form.email.value)) {
		document.getElementById("BocadilloMiniAlta").style.background="url("+url_home+"/img/bocadillo1.gif) no-repeat";
		document.getElementById("BocadilloMiniAlta").style.visibility="visible";
		document.getElementById("BocadilloMiniAltaContent").innerHTML = "El e-mail es incorrecto <br /> o tiene caracteres no permitidos.";
	    validado = false;
	}
	
	// Comprobamos si el email ya esta registrado
	
	// Construccion url
	var url = url_home + "/usuario/altaValidacionAjax.cfm?email=" + form.email.value;
	
	var xhr;
	try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
	catch (e) 
	{
		try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
		catch (e2) 
	    {
	    	try {  xhr = new XMLHttpRequest();     }
	        catch (e3) {  xhr = false;   }
		}
	}
	
	xhr.open("POST", url,  false);
	xhr.send(null); 
		  	
	// Corto los 50 primeros caracteres para evitar la basura del debugger
	respuesta=xhr.responseText.replace(/^\s*|\s*$/g,"").substring(0,50);
	 
	if (respuesta.indexOf('existeEmail')!=-1) {
		if (respuesta.indexOf('(RN:S)')!=-1) {
			// Mostrar warning email ya tiene activado el flag de news
			document.getElementById("BocadilloMiniAlta").style.background="url("+url_home+"/img/bocadillo2.gif) no-repeat";
	    	document.getElementById("BocadilloMiniAlta").style.visibility="visible";
	    	document.getElementById("BocadilloMiniAltaContent").innerHTML = "Este e-mail ya está registrado en <strong>mailxmail</strong> <br />y recibe periódicamente nuestras novedades.";
	    	validado = false;
	    }
		else {	    			
	    	// Mostrar warning email ya registrado
			document.getElementById("BocadilloMiniAlta").style.background="url("+url_home+"/img/bocadillo3.gif) no-repeat";
			document.getElementById("BocadilloMiniAlta").style.visibility="visible";
	    	document.getElementById("BocadilloMiniAltaContent").innerHTML = "Este e-mail ya está registrado en <strong>mailxmail</strong>. <br/>Si quieres recibir nuestras novedades haz clic <br/> en este enlace: <a href='" + url_home + "/usuario/menu.cfm'>Menú personal</a></center>";
	    	validado = false;
	    }
	    validado = false;
	}
	
	return validado;
}

function ocultarBocadillo(){
	document.getElementById("BocadilloMiniAlta").style.visibility="hidden";
}

function submitFormulario(form, url_home){

	form.okMiniAlta.value = "true";
	return validacionMiniAlta(form, url_home);
}
