
//Filtros
var filters = {
    notempty: 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());},
    telefono: function(el){return /^[0-9]*$/.test($(el).val());},
    password: function(el){return ($(el).val().length >=6);}};
// Extensiones
$.extend({
	stop: function(e){
        if (e.preventDefault) e.preventDefault();
        if (e.stopPropagation) e.stopPropagation();
    }
});
// Código
$(document).ready(function(){

	$("form.validateit").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("Los campos marcados en rojo son obligatorios");
			return false;
		}

		if ($('#usr_password').val() != $('#usr_password_retry').val())
		{
			alert("La contrase\u00f1a y su confirmaci\u00f3n no coinciden");
			return false;
		}

	    return true;
	});
});


