$().ready(function()
	{
		$("#enviar_email").submit(enviarMail);
		$("#respuesta").ajaxStart(function(){$(this).html("<strong>...ENVIANDO... </strong>");});
	}
);

function validarEmail(valor) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
	{
		
		return true;
	} 
	else 
	{
		
		return false;
	}
}

function enviarMail(){
	var nombre=$("#nombre").val();
	var empresa=$("#empresa").val();
	var telefono=$("#telefono").val();
	var ciudad=$("#ciudad").val();
	var email=$("#email").val();
	var comentario=$("#comentario").val();
	
	
	
	if(nombre == "")
	{
		$("#respuesta").html("<strong>NOMBRE, Por favor escriba su nombre. </strong>");
		return false;
	}		
		
	if(empresa == "")
	{
		$("#respuesta").html("<strong>EMPRESA, Por favor escriba su nombre de empresa.</strong>");
		return false;
	}	
	if(telefono == "")
	{		$("#respuesta").html("<strong>TELEFONO, Por favor escriba un telefono.</strong>");
		return false;	}	
		
		
	if(ciudad == "")
	{		$("#respuesta").html("<strong>CIUDAD, Por favor escriba su ciudad.</strong>");
		return false;	}	
			
		
	if(email == "")
	{		$("#respuesta").html("<strong>EMAIL, Por favor escriba su e-mail.</strong>");
		return false;	}	
		
			
	if(!validarEmail(email))
	{		$("#respuesta").html("<strong>hay un error en su e-mail, intentelo de nuevo.</strong>");
		return false;	}
		
		
	if(comentario == "")
	{		$("#respuesta").html("<strong>MENSAJE, Por favor escriba un mensaje o comentario.</strong>");
		return false;	}
	
	
	$.post('contacto/mail.php',
		{	nombre:nombre,
			empresa:empresa,
			telefono:telefono,
			ciudad:ciudad,
			email:email,
			comentario:comentario
			},
		
		
	function(data){
			$("#respuesta").html(data);
			//$("#enviar_email").reset();
			$("#enviar_email").clearForm()
		});	return false; }



$.fn.clearForm = function() {
  return this.each(function() {
	var type = this.type, tag = this.tagName.toLowerCase();
	if (tag == 'form')
	  return $(':input',this).clearForm();
	if (type == 'text' || type == 'password' || tag == 'textarea')
	  this.value = '';
	else if (type == 'checkbox' || type == 'radio')
	  this.checked = false;
	else if (tag == 'select')
	  this.selectedIndex = -1;
  		})
  }  
