

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


	
	$(document).ready(function(){
	
		$("form:is('.jq')").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);
				$(resultado).html('<div class="rojo">Error de formato o campos vacios</div>');
				return false;
			}else{
			
				$.ajax({
					async:false,
					beforeSend: function(objeto){
						$(miid+' '+resultado).html('<img alt="procesando datos" src="http://www.malagavende.es/imgs/loading.gif"/>');
					},
					complete: function(objeto, exito){
					
						if(exito=="success"){

							if(error!=1){
							
									$(miid+' '+resultado).hide();
									$(miid+' .campos').fadeOut(200,function(){
										$(miid+' '+resultado).fadeIn(200);

									});
								}
						}else{
							$(miid+' '+resultado).html('<div class="rojo">Error al procesar los datos</div>');
						}
					},
					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);},
				ma: 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());}
		};
	
	
	
	
	
	
	
	
	
	
