var filters = {
	requerido: function(el) {return ($(el).val() != '' && $(el).val() != -1 && $(el).val() != 'undefined' || $(el).attr('value') != '');},
	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());},
	numero: function(el){return /^[0-9]*$/.test($(el).val());},
	categoria: function(el){ return ($('select#mm_categoria option:selected').val());},
	checkboxRequerido: function(el){ return ($(el).is(':checked')); },
	selectRequerido: function(el){ return ($('select option:selected').val());},
	username: function(el){return (/^[A-Za-z0-9_+\.]*$/.test($(el).val()) && $(el).val().length >= 8);},
	password: function(el){return ($(el).val().length >= 6);},
	celularDefault : function(el){ return ($(el).val() != '(341) 15x-xxxxxx');}
};
	
$.extend({
	stop: function(e){
		if (e.preventDefault) e.preventDefault();
		if (e.stopPropagation) e.stopPropagation();
	}
});

$(function(){
	$(document).pngFix();
	
	if($('#categorias').size() > 0){
		$('#categorias li a, #categorias li:first h2').wrapInner("<span></span>");
		$('#categorias li a span, #categorias li:first h2 span').css({display:'block'}).dropShadow({left: -1, top: -1, blur: 1, swap:false, color:'black'});
	}
	
	if($('.box').size() > 0){
		$('.box:last').css({margin:'0'});
	}
	
	$("form").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);
			jAlert("Necesita completar los campos marcados","El formulario no es valido");
			return false;
		}
	    return true;
	});
	
});
