
function showHint(str)
{
	
	if (str.length==0)
	{
		return false;
	}
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}	
	xmlhttp.open("GET","comprobar_email.php?email="+str,false);
	xmlhttp.send();
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		if(xmlhttp.responseText=="1")
			return true;
		else
			return false;
	}
}

function actualizarcaptcha()
{
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}	
	xmlhttp.open("GET","actualizar_captcha.php",false);
	xmlhttp.send();
	document.getElementById("ca").src="captcha.php"+ '?' + (new Date()).getTime();
}

function compruebaDominio(F)
{
	document.getElementById("boton").disabled=true;
	if(F.dominio.value!="")
	{
		document.getElementById("resultado").innerHTML="Espere mientras se obtiene una respuesta...";
		if (window.XMLHttpRequest)
		{
			xmlhttp=new XMLHttpRequest();
		}
		else
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}	
		xmlhttp.open("GET","examples_domain.php?dominio="+F.dominio.value+"."+F.extension.value,false);
		xmlhttp.send();
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
				document.getElementById("resultado").innerHTML=xmlhttp.responseText;
		}
	}
	else
	{
		document.getElementById("resultado").innerHTML="Por favor introduce un nombre de dominio";
	}
	document.getElementById("boton").disabled=false;
	return false;
}

function echeck(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		
		return false
	 }

	 return true					
}




function vacio(q) {
        for ( i = 0; i < q.length; i++ ) {
                if ( q.charAt(i) != " " ) {
                        return true
                }
        }
        return false
}



//valida que el campo no este vacio y no tenga solo espacios en blanco
function valida(F) 
{
	document.body.disabled=true;
	document.body.style.cursor="wait";
	document.getElementById("bloc").style.display="block";
	document.getElementById("bloc1").style.display="block";
		var error="";
		var error1="";
        var comprueba;
		comprueba=0;	
		
		e=document.getElementById("uno").className = 'cajita';
		e=document.getElementById("dos").className = 'cajita';
		e=document.getElementById("tres").className = 'cajita';
		e=document.getElementById("cuatro").className = 'cajita';
		e=document.getElementById("cinco").className = 'cajita';
		if(vacio(F.empresa.value) == false)
		{
			error+="El campo de Empresa está vacio.\n";
			comprueba++;
			e=document.getElementById("uno").className = 'cajitaError';
		}
		if(vacio(F.persona.value) == false)
		{
			error+="El campo de Persona de contacto está vacio.\n";
			comprueba++;
			e=document.getElementById("dos").className = 'cajitaError';
		}
		if(showHint(F.email.value) == false)
		{
			error+="El campo de Mail está vacio o es incorrecto debido a que no se encontró una entrada MX válida para el dominio.\n";
			comprueba++;
			e=document.getElementById("tres").className = 'cajitaError';
		}
		if(vacio(F.texto.value) == false)
		{
			error+="El campo de Consulta está vacio.\n";
			comprueba++;
			e=document.getElementById("cuatro").className = 'cajitaError';
		}
		if(vacio(F.cacha.value) == false)
		{
			error+="El campo de Código anti robots está vacio.\n";
			comprueba++;
			e=document.getElementById("cinco").className = 'cajitaError';
		}

		if(comprueba!=0)
		{
			if(comprueba==1)
			{
				error1="Se ha producido el siguiente error.\n\n";
			}
			else
			{
				error1="Se ha producido los siguientes errores.\n\n";
			}
			document.getElementById("bloc1").style.display="none";
			alert(error1+error);
			document.body.disabled=false;
			document.body.style.cursor="default";
			document.getElementById("bloc").style.display="none";
			return false
        } 
		else 
		{
                document.body.disabled=false;
				document.body.style.cursor="default";
				document.getElementById("bloc1").style.display="none";
				document.getElementById("bloc").style.display="none";
                return true
        }

        
}
