// JavaScript Document
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());},
		telefono: function(el){return /^[0-9]*$/.test($(el).val());},
		categoria: function(el){ return ($('select#mm_categoria option:selected').val());},
		contactDefault: function(el){return $(el).val() != 'Deje su mensaje.';},
		comentarioDefault: function(el){return $(el).val() != 'Aqui su comentario';},
		columnistaDefault: function(el){return $(el).val() != 'Buscar por columnista';},
	};
	
$.extend({
	stop: function(e){
		if (e.preventDefault) e.preventDefault();
		if (e.stopPropagation) e.stopPropagation();
	}
});

$(document).ready( function(){
	if($('div.thickbox').size() > 0){
		$('div.thickbox').corners('rounded 5px').fadeIn('slow');
		$('div.thickbox p a').click(function(){ $('div.thickbox').fadeOut('slow'); return false; });
	}
	
	$("#columnaCentral .item div.itemDestacadoUltimoMomento:odd").addClass("border-vertical");
	$("#encabezadoAlmas .item:first").addClass("border-top");
	$("#encabezadoAlmas .item:odd").addClass("border-horizontal");
	
	$("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;
	});
});
