function checkmail(mail){
	var reg=/(^[a-zA-Z0-9._-]{1,30})@([a-zA-Z0-9.-]{1,30}$)/;
	if(reg.test(mail)) return true;
	else return false;
}
$(document).ready(function(){
	$("#formSender").live("click", function(){
		
		var QS 			= "submited=1&";
		var errores		= new Array();
		
		$("#formContacto").find("input[name],textarea[name]").each(function(){
			var validate = $(this).attr("validate");
			
			if ( validate ){
				switch ( validate ){
					case "empty":
					if ( $(this).val()!="" && $(this).val()!=null && $(this).val()!=undefined ){
						QS += $(this).attr("name") + "=" + $(this).val() + "&";
					} else {
						errores.push($(this).attr("rel") + " no es válido.");
					}
					break;
					
					case "email":
					if ( checkmail($(this).val()) ){
						QS += $(this).attr("name") + "=" + $(this).val() + "&";
					} else {
						errores.push($(this).attr("rel") + " no es válido.");
					}
					break;
				}
			}				
		});
		
		if ( errores.length > 0 ){
		
			var errorPrint = "Errores encontrados:\n-----------------------------\n";
			
			for ( i=0; i<errores.length; i++ ){
				errorPrint += "- " + errores[i] + "\n";
			}
			
			alert(errorPrint);
			
		} else {
			console.log(QS);
			ajaxPost("contenidos_contacto.php", QS);
		}			
		
	});

});	
