var validaciones = {
	vacio: function(elemento) {return /[A-Za-z0-9_]/.test($(elemento).val());},
	email: function(elemento) {return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($(elemento).val());},
	telefono: function(elemento) { return /[0-9_-]/.test($(elemento).val()); }
};

function Valida(){
	$("#mensaje").fadeOut('slow');
	$("#errMsj").fadeOut('slow');
	$("#exiMsj").fadeOut('slow');
	var cadena = Array();
	$("#formularioContacto").find("input, textarea, select, div").each(function(i,elemento){
		    $.each($(elemento).attr('class').split(" "),function(c,clase){
			if( jQuery.isFunction(validaciones[clase]))
			{
				if(validaciones[clase](elemento)==false)
				{
					var id = $(elemento).attr('id');
					var campos = $(elemento).attr('title');
					$("#"+id+"_label").attr('class','for-rojo');
					if(jQuery.inArray(campos, cadena) == '-1'){
						cadena.push(campos);
					}
				}
				
			}			
		});
	
	});
	if( cadena.length > 0 )
	{
		var errores = cadena.join(', ');
		var html = "<div class=\"caja-bottom-error\">";
		html += "<div class=\"caja-top-error\">";
		html += "<p class=\"text-mensaje-error\">Revise los siguientes datos: <strong>";
		html += errores;
		html += "</strong></p>";
		html += "</div>";
		html += "</div>";
		$('#mensaje').html(html);
		$('#mensaje').fadeIn('slow');
		location.href="#";
		return false;
	}
	else
		
		$.ajax({
			type: 'POST',
			data: 'nombre='+$('#nombre').val()+'&apellido='+$('#apellido').val()+'&e-mail='+$('#e-mail').val()+'&telefono='+$('#telefono').val()+'&comentario='+$('#comentario').val()+'',
			url: '/contacto/enviar/',
			success: function( datos ){
				
				if( datos == '/contacto/' ){
					location.href='/contacto/enviado/';	
				}
				
				if( datos == '/socios/' ){
					location.href='/socios/enviado/';	
				}
			}
		});
		
		return false;
}

$(document).ready(function(){
		$(".mapa").colorbox({iframe:true, transition:"fade", fixedWidth:"550px", fixedHeight:'500px'});
})
