String.prototype.trim = function() {
  return this.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
};


function validateEmail(strEmail)
{
	  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	  return (strEmail.search(validRegExp) == -1); 
}

function clearBuscar()
{
	if (document.getElementById("textSearched").value == 'Buscar')
	{
		document.getElementById("textSearched").value = "";
	}	
}


function contactoRapido()
{
	var txtNombre = document.getElementById("nombre").value;
	var txtEmail = document.getElementById("email").value;
	var txtMensaje = document.getElementById("mensaje").value;
	
	if( txtNombre.trim() == '' )
	{
	  document.getElementById("errorContactoRapido").style.display = "block";
	  document.getElementById("messageContactoRapido").style.display = "none";
	  return false;
	}
	
	if( validateEmail(txtEmail) )
	{
	  document.getElementById("errorContactoRapido").style.display = "block";
	  document.getElementById("messageContactoRapido").style.display = "none";
	  return false;
	}
	
	if( txtMensaje.trim() == '' )
	{
	  document.getElementById("errorContactoRapido").style.display = "block";
	  document.getElementById("messageContactoRapido").style.display = "none";		
	  return false;
	}
	
	$.ajax(
	{
	   type: "post",
	   dataType: "html",
	   url: "/contacto/enviorapido",
	   data: "nombre=" + txtNombre + "&email=" + txtEmail + "&mensaje=" + txtMensaje,
	   cache: false,
	   success: function(results) { document.getElementById("messageContactoRapido").style.display = "block"; } }
	  );
		
	document.getElementById("errorContactoRapido").style.display = "none";
	return true;
}


function suscribirse()
{
	var txtEmail = document.getElementById("email_newsletter").value;
		
	if( validateEmail(txtEmail) )
	{
	  document.getElementById("errorSuscripcion").style.display = "block";
	  document.getElementById("messageSuscripcion").style.display = "none";
	  return false;
	}
	
	$.ajax(
	{
	   type: "post",
	   dataType: "html",
	   url: "/contacto/suscribirse",
	   data: "email=" + txtEmail,
	   cache: false,
	   success: function(results) { document.getElementById("messageSuscripcion").style.display = "block"; } }
	  );
	  
	document.getElementById("errorSuscripcion").style.display = "none";
	return true;
}
