
			
		
			var formvalues = {};
			
			$(function(){
				applyShowRules();
				applyRequiredRules();
				$('body').on("change",':input',function() {
					applyShowRules();
					applyRequiredRules();
				});		
				$('body').on('keyup',':input',function() {		
					delay(function(){
					  applyShowRules();
					  applyRequiredRules();
					}, 500 );
				});
			});
			
			var delay = (function(){
			  var timer = 0;
			  return function(callback, ms){
				clearTimeout (timer);
				timer = setTimeout(callback, ms);
			  };
			})();

			function updateFormvalues(){
				formvalues = {};
				$(':input').each(function(i){
					var id = $(this).attr('name');
					if($(this).is(":checkbox")){
						if(!formvalues[id]) formvalues[id] = {};
						if(!formvalues[id].value) formvalues[id].value = [];
							
						if($(this).is(":checked")){
							formvalues[id].value = $(this).is(":checked");
						}	
					} else if($(this).is(":radio")){
						if(!formvalues[id]) formvalues[id] = {};
						if(!formvalues[id].value) formvalues[id].value = "";
						if($(this).is(":checked")){
							formvalues[id].value = $(this).val();
						}	
					} else{
						formvalues[id] = {};
						formvalues[id].value = $(this).val();
					}
				});
			}
			
			function evalRule(r) {
				/* Funções auxiliares que poderão ser usadas no ShowRule */
				var contains = function(id, check) {
					return formvalues[id].value.indexOf(check) != -1;
				};
				return eval(r);
			}
	
			function applyShowRules(){
				updateFormvalues();
				
				$('*[show-rule]').each(function(i) {
					if(evalRule($(this).attr('show-rule'))) {
						$(this).show();
						$(':input', $(this)).each(function(){
							if(!$(this).is("[data-hasdisabled]")) {
								$(this).removeAttr('disabled');
							}
							$(this).removeAttr('readonly');
							$(this).removeAttr('hidedbyShowRule');
						});
					} else {
						$(this).hide();
						$(':input', $(this)).each(function(){
							if(!$(this).is("[data-hasdisabled]")) {
								$(this).attr('disabled', 'true');
							}
							$(this).attr('readonly', 'true');
							$(this).attr('hidedbyShowRule', 'true');
						});
					}
				});		

				bodyH = document.body;
				htmlH = document.documentElement;

				maxHeight = Math.max( bodyH.scrollHeight, bodyH.offsetHeight, htmlH.clientHeight, htmlH.scrollHeight, htmlH.offsetHeight );
			}	
			
			function applyRequiredRules(){
				updateFormvalues();
				
				$('*[required-rule]').each(function(i) {
					if(evalRule($(this).attr('required-rule'))) {
						$(":input", this).removeAttr("required");
						$(":input", this).attr("required","");
					} else {
						$(":input", this).removeAttr("required");
					}
				});		
			}	
			
			
		
	