$.extend({
		/* PARAMOS LA EJECUCI�N*/
		stop: function(e){
        if (e.preventDefault) e.preventDefault();
        if (e.stopPropagation) e.stopPropagation();
    }, 
    /* PERSONALIZAMOS LA SALIDA POR PANTALLA */
    alert: function(str) {
    	alert(str);	
    }
});


$(document).ready(function(){

	$("form.validable").bind("submit", function(e){
		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);
			alert("Existen valores incorrectos.\nPor favor revisa los campos señalados en rojo.");
			return false;
		}
	    return true;
	});
});


var filters = {
	    requerido: function(el) {return ($(el).val() != '' && $(el).val() != -1);},
	    email: function(el) {return /^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test($(el).val());},
	    numerico: function(el){return /^[0-9\s]*$/.test($(el).val());},
	    decimal: function(el){return /^(?:\+|-)?\d+\.\d*$/.test($(el).val());},	    	    
		caracter: function(el){return /^[A-Za-z àáéèíìóòúùÁÀÉÈÍÌÓÒÚÙÑñ]*$/.test($(el).val());},										
	    nif : function(el){return /^(X(-|\.)?0?\d{7}(-|\.)?[A-Za-z]|[A-Za-z](-|\.)?\d{7}(-|\.)?[0-9A-Za-z]|\d{8}(-|\.)?[A-Za-z])$/.test($(el).val());},	
	    cp: function(el){return /^([1-9]{2}|[0-9][1-9]|[1-9][0-9])[0-9]{3}$/.test($(el).val());}
	    };
