function getHTTPObject(){var xmlhttp;if(!xmlhttp&&typeof XMLHttpRequest!='undefined'){try{xmlhttp=new XMLHttpRequest();}catch(e){xmlhttp=false;}}
return xmlhttp;}

var http=getHTTPObject();

function handleHttpResponseContacto()
{	if(http.readyState==4)
	{	document.getElementById("mensaje-respuesta").innerHTML=http.responseText;
		document.getElementById("formularioContacto").reset();
	}
}

function cerrarAviso(){document.getElementById("mensajeError").innerHTML="";document.getElementById("capaError").style.display='none';}

function validarEmail(valor)
{	return(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor));}

function validarLetrasSinEspacio(valor)
{	return(/^[a-zA-Z]+$/.test(valor));}


function tiene_letras(texto){
	var letras="abcdefghyjklmnñopqrstuvwxyz";

   texto = texto.toLowerCase();
   for(i=0; i<texto.length; i++){
      if (letras.indexOf(texto.charAt(i),0)!=-1){
         return 1;
      }
   }
   return 0;
} 

function buscarMotorpoint(){
	if(document.getElementById("frmBuscar").textoBuscar.value.length<1)
	{	alert("Introduzca el texto de búsqueda");
		document.getElementById("frmBuscar").reset();
	}
	else
		document.getElementById("frmBuscar").submit()
}

function contactarMotorpoint(){
	var Texto;
	var cadenaEnvio;
	var Nombre;
	var Email;	
	var Mensaje;

	Texto="";
	Nombre = document.getElementById("formularioContacto").nombre.value;
	Email = document.getElementById("formularioContacto").email.value;	
	Mensaje = document.getElementById("formularioContacto").mensaje.value;
	cadenaEnvio="";	

	if (Nombre == "") 
		Texto+="**Ingrese un nombre ";	
	else
		if (Nombre.length < 3)
			Texto+="**Ingrese un nombre vAlido ";
			//SI longitud pero NO solo caracteres A-z
		else 
			if (!tiene_letras(Nombre))
				Texto+="**Ingrese letras ";
			else
				cadenaEnvio="nombre="+Nombre;			

	if (Email!="")
		if (!validarEmail(Email))
			Texto+="**Formato de E-mail incorrecto ";
		else
			cadenaEnvio+="&email="+Email;	
	else
		Texto+="**Debe indicar su e-mail ";
		
	if (Mensaje == "")
		Texto+="**Ingrese un comentario/mensaje ";
	else
		if (Mensaje.length < 3)
			Texto+="**Ingrese un comentario/mensaje ";
		else
			cadenaEnvio+="&mensaje="+Mensaje;			

	if (Texto!="")
	{	document.getElementById("mensajeError").innerHTML=Texto;
		document.getElementById("capaError").style.display='block';
	}
	else
	{	document.getElementById("mensaje-respuesta").innerHTML="";
		document.getElementById("mensajeError").innerHTML="";
		document.getElementById("capaError").style.display='none';
		http.open("GET","/funcion/procesarContacto.php?"+cadenaEnvio,true);
		http.onreadystatechange=handleHttpResponseContacto;
		http.send(null);
	}
}
 
