$(document).ready(function() {
	i = 0;
	while(i<fotos.length){
		$("#fotos").append("<img height='250px' style='display:none;position:absolute;' id='foto"+i+"' src='imagenes/"+fotos[i]+"' />");
		i++
	}
	verFoto()
	t=setInterval("run()",6000);
	
	$("#cmbEnviar").click(function() {
		enviarMail()
	});
});

var fotos = [ "logo.gif", "home.png"];
var index = 0;

function run() {
	verFoto()
	if(index==fotos.length)
		index = 0;
}

function verFoto(){
	$("#foto"+index).fadeIn(3000);
	$("#foto"+index).fadeOut(3000);
	index++;
}

function enviarMail(){
	var nombre = $("#txtNombre").val();
	var mail = $("#txtMail").val();	
	var asunto = $("#txtAsunto").val();
	var empresa = $("#txtEmpresa").val();
	var telefono = $("#txtTelefono").val();
	if(nombre==""){
		alert("El nombre es un campo obligatorio.")
		return false;
	}
	if(mail==""){
		alert("El mail es un campo obligatorio.")
		return false;
	}
	else{
		if(validarMail(mail)==false){
			alert("El mail "+mail+"no es correcto.")
			return false;
		}
	}
	if(asunto==""){
		alert("El asunto es un campo obligatorio.")
		return false;
	}

	$.ajax({
		type: "POST",
		url: "./clases/ajax.php",
		data: "action=enviarMail&nombre="+nombre+"&mail="+mail+"&asunto="+asunto+"&empresa="+empresa+"&telefono="+telefono,
		success: function(datos){
			if(datos=="OK"){
				alert("Email enviado con exito");
				document.location.reload();
			}
			else{
				alert("ERROR "+ datos)
			}
		}
	});
}

