// JavaScript Document
$(document).ready(function()
{	
	
	$("#forma_informa").submit(function()
	{
		
		var correo= $("#info_mail").val();
		var nombre= $("#info_nombre").val();
		
		//alert(correo);
		
		if(!validaCorreo(correo))
		{
			span=document.createElement("span");
			span.className="invalido";
			span.innerHTML="Verifique su correo electrónico";
			
			document.getElementById("info_resp").appendChild(span);
			setTimeout(function()
					{
					span.style.display="none";	
					$("#info_resp > span").remove();
					//document.getElementById("info_resp").removeChild(span);
					},5000);
			
		}else{
				$.ajax({
				async: true,
				type: "POST",
				dataType: "html",
				contentType: "application/x-www-form-urlencoded",
				url: "include/correoNews.php",
				data: "correo="+correo+"&nombre="+nombre,
				success: function(data)
					{
					span=document.createElement("span");
					//span.className="valido";
					span.innerHTML=data;
					
					document.getElementById("info_resp").appendChild(span);
					setTimeout(function()
							{
							span.style.display="none";	
							$("#info_resp > span").remove();
							//document.getElementById("info_resp").removeChild(span);
							$("#info_mail").val("");
							$("#info_nombre").val("");
							},5000);
						
					}
				});
			}
		
		return false;
	});
	
	/*-----------------------------------------------------------------------------------------*/	
	$("#forma_recomienda").submit(function()
	{
		
		var nombre= $("#rec_nombre").val();
		var amigo= $("#rec_amigo").val();
		var correo= $("#rec_mail").val();
		
		//alert(correo);
		
		if(!validaCorreo(correo))
		{
			span=document.createElement("span");
			span.className="invalido";
			span.innerHTML="Verifique su correo electrónico";
			
			document.getElementById("rec_resp").appendChild(span);
			setTimeout(function()
					{
					span.style.display="none";	
					$("#rec_resp > span").remove();
					//document.getElementById("rec_resp").removeChild(span);
					},5000);
			
		}else{
				$.ajax({
				async: true,
				type: "POST",
				dataType: "html",
				contentType: "application/x-www-form-urlencoded",
				url: "include/correoRecom.php",
				data: "correo="+correo+"&nombre="+nombre+"&amigo="+amigo,
				success: function(data)
					{
					span=document.createElement("span");
					//span.className="valido";
					span.innerHTML=data;
					
					document.getElementById("rec_resp").appendChild(span);
					setTimeout(function()
							{
							span.style.display="none";	
							$("#rec_resp > span").remove();
							//document.getElementById("rec_resp").removeChild(span);
							$("#rec_nombre").val("");
							$("#rec_amigo").val("");
							$("#rec_mail").val("");
							},5000);	
						
					}
				});
			}
		
		return false;
	});

});

function validaCorreo(valor)
{
	var reg=/(^[a-zA-Z0-9._-]{1,30})@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$/;
	if(reg.test(valor)) return true;
	
	return false;
}

