	$.extend({
		stop: function(e){
	        if (e.preventDefault) e.preventDefault();
	        if (e.stopPropagation) e.stopPropagation();
	    }, 
	    alert: function(str) {
		$('#resultado').html('Error al procesar la peticion');	
	    }
	});

	
	var folder='http://www.emabesa.es/';
	
	$(document).ready(function(){

		$("form:not('.upload')").bind("submit", function(e){
		var resultado='#'+$(this).attr('target');
		var miid='#'+$(this).attr('id');
		$(resultado).css('display','block');
		if (typeof filters == 'undefined') return;
		
		    $(this).find("input, textarea, select").each(function(x,el){ 
		        if ($(el).attr("className") != 'undefined') { 
			$(el).removeClass("error");
		        $.each(new String($(el).attr("className")).split(" "), function(x, klass){
		            if ($.isFunction(filters[klass]))
		                if (!filters[klass](el))  $(el).addClass("error");
		               
		               
		        });
		        }
		    });
			if ($(this).find(".error").size() > 0) {
				$.stop(e || window.event);
				
				$('#sub').append('<div class="ro">Faltan campos obligatorios</div>');
				return false;
			}else{
			
					$.ajax({
						async:false,
						beforeSend: function(objeto){
							$(resultado).html('Enviando');
						},
						complete: function(objeto, exito){
							if(exito=="success"){
								if(miid!='#no'){
									$(miid).fadeOut(100);
								}
								$('#despues').html('Procedimiento procesado con éxito');
							}else{
								$(resultado).html('Error al procesar la peticion');
							}
						},
						type: "POST",
						url: $(this).attr('action'),
						data: $(this).serialize(),
						success: function(data){
							$(resultado).html(data);
						}
			
					});
					
					return false;
					
			}
		});
	});

	
	
	
	
	
	
	
		var filters = {
				r: function(el) {return ($(el).val() != '' && $(el).val() != -1);},
				m: function(el) {return /^[A-Za-z0-9_.-]*@[A-Za-z0-9_.-]+\.[A-Za-z0-9_.-]+[A-za-z]$/.test($(el).val());},
				n: function(el){return /^[0-9.]*$/.test($(el).val());}
		};
	
	
	
	
	
	
	
	
	
	