/**
 * @author lcevallos
 */
$(document).ready(function(){
$("#sendmail").click(function(){
var valid = "";

/* Campos del Formulario */

var isr = " es requerido.";
var nombre = $("#txt_nombre").val();
var puesto= $("#txt_puesto").val();
var organizacion= $("#txt_empresa").val();

var direccion1 = $("#txt_direccion1").val();
var direccion2= $("#txt_direccion2").val();
var ciudad= $("#txt_ciudad").val();
var estado = $("#txt_estado").val();
var codigo_postal= $("#txt_codigo_postal").val();
var telefono_principal= $("#txt_telefono_principal").val();
var telefono_alternativo = $("#txt_telefono_alternativo").val();
var hora_llamar= $("#txt_hora_llamar").val();
var fax= $("#txt_fax").val();

var mail = $("#txt_mail").val();
var subject ="Informacion de contacto de: "+nombre;
var Feedback = $("#Feedback").val();



/* FIN Campos del Formulario */
if (nombre.length<1) {
valid += '<br />Nombre '+isr;
}
if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
valid += '<br />Un mail valido '+isr;
}
if (telefono_principal.length<1) {
valid += '<br />Telefono Principal '+isr;
}

if (valid!='') {
$("#response").fadeIn("slow");
$("#response").html("Error:"+valid);
}
else {
var text ='Datos del contacto: Nombre: ' + nombre 
text += ' Puesto: ' + puesto + ' '
text += ' Organizacion: ' + organizacion + ' '
text += ' Direccion 1: ' + direccion1 + ' '
text += ' Direccion 2: ' + direccion2 + ' '
text += ' Ciudad: ' + ciudad + ' '
text += ' Estado: ' + estado + ' '
text += ' Codigo Postal: ' + codigo_postal + ' '
text += ' Telefono Principal: ' + telefono_principal + ' '
text += ' Telefono Alternativo: ' + telefono_alternativo + ' '
text += ' Hora para llamar: ' + hora_llamar + ' '
text += ' Fax: ' + fax + ' '
text += ' Preguntas o Sugerencias: ' + Feedback + '  '
text += ''


var datastr ='nombre=' + nombre + '&mail=' + mail + '&subject=' + subject + '&text=' + text;

$("#response").css("display", "block");
$("#response").html("Su mensaje fue enviando. ");
$("#response").fadeIn("slow");
setTimeout("send('"+datastr+"')",2000);
}
return false;
});
});
function send(datastr){
$.ajax({
type: "POST",
url: "mail.php",
data: datastr,
cache: false,
success: function(html){
$("#response").fadeIn("slow");
$("#response").html(html);
setTimeout('$("#response").fadeOut("slow")',2000);
}
});
}