(function($){
	$(function(){
		$('form.wm_forms').submit(function(){
			var $valid = true;
			// reset color
			$(this).find('li h4').css('color','black');
			// text
			$elems = $(this).find('input[type="text"].not_null[value=""]');
			if($elems.length>0){
				$valid = false;
				$elems.prev().css('color','red');
			}
			// select
			$elems = $(this).find('select.not_null[value=""]');
			if($elems.length>0){
				$valid = false;
				$elems.prev().css('color','red');
			}
			// radio
			$(this).find('input[type="radio"].not_null').each(function(){
				$elems = $(this).parents('li:first').find('input.not_null[checked=true]');
				if($elems.length<=0){
					$valid = false;
					$(this).parents('li:first').find('h4:first').css('color','red');
				}
			});
			// checkbox
			$(this).find('input[type="checkbox"].not_null').each(function(){
				$elems = $(this).parents('li:first').find('input.not_null[checked=true]');
				if($elems.length<=0){
					$valid = false;
					$(this).parents('li:first').find('h4:first').css('color','red');
				}
			});
			// is valid?
			if(!$valid){
				alert('Tem de preencher todos os campos obrigatórios.');
				return false;
			}
		});
	});
})(jQuery);

