
function checkboxForm(check)
{
	if ($(check).prop('checked') )
	{
		$(check).val(1);
	}
	else
	{
		$(check).val(0);
	}
}

function atualizarCheckboxsForm()
{
	$(':checkbox').each(function() {
		if ($(this).val() == "1")
		{
			$(this).prop('checked','true');
		}
	});
}	

function iniciaValorForm()
{
	
	$(".form").each(function(i){   
		if ($(this).attr("valueDefault")) { 
         $(this).val($(this).attr("valueDefault")); 
		} 
    });
	
	$(':checkbox').each(function() {
		if ($(this).attr("valueDefault") == "1")
		{
			$(this).prop('checked','true');
		}
	});
	
	$(':radio').each(function() {
		if ($(this).attr("valueDefault") == "checked")
		{
			$(this).prop('checked','true');
		}
		else
		{
			//$(this).prop('checked','false');
		}	
	});
	
}

/*trabalhando com grupo de botões padãr; salvar, cancelar, excluir, novo*/
$(document).on("input",".form", function() { 
	habilitarComponente("#btnSalvar");
	habilitarComponente("#btnCancelar");
	habilitarComponente(".btnSalvar");
	habilitarComponente(".btnCancelar");
});

$(document).on("change",".hasDatepicker", function() { 
	habilitarComponente("#btnSalvar");
	habilitarComponente("#btnCancelar");
	habilitarComponente(".btnSalvar");
	habilitarComponente(".btnCancelar");
});

$(document).on("click",":checkbox", function() { 
	habilitarComponente("#btnSalvar");
	habilitarComponente("#btnCancelar");
	habilitarComponente(".btnSalvar");
	habilitarComponente(".btnCancelar");
});

$(document).on("click",":file", function() { 
	habilitarComponente("#btnSalvar");
	habilitarComponente("#btnCancelar");
	habilitarComponente(".btnSalvar");
	habilitarComponente(".btnCancelar");
});

$(document).on("click",":radio", function() { 
	habilitarComponente("#btnSalvar");
	habilitarComponente("#btnCancelar");
	habilitarComponente(".btnSalvar");
	habilitarComponente(".btnCancelar");
});

$(document).on("click","#btnNovo", function() {
	desabilitarComponente("#btnSalvar");
	desabilitarComponente("#btnCancelar");
	desabilitarComponente("#btnExcluir");
	desabilitarComponente(".btnSalvar");
	desabilitarComponente(".btnCancelar");
	desabilitarComponente(".btnExcluir");
	
});
$(document).on("click","#btnCancelar", function() {
	desabilitarComponente("#btnSalvar");
	desabilitarComponente("#btnCancelar");
	desabilitarComponente("#btnExcluir");
	desabilitarComponente(".btnSalvar");
	desabilitarComponente(".btnCancelar");
	desabilitarComponente(".btnExcluir");
	//$(".form").val($(".form").attr("value"));
	iniciaValorForm();
	
});

atualizarCheckboxsForm();
iniciaValorForm();


requisicaoAtual = null

/*	
	$(".datalist").bind("keyup", function() { 
		if(requisicaoAtual !== null){
			//alert("entrou");
			//requisicaoAtual.abort();
			requisicaoAtual = null;
		}
	//alert($(this).attr("requisicao")+"?"+$(this).attr("valuePost")+ "="+$(this).val());
	input = this;
	if(  ! $(this).attr("usar_key") )
	{	
		//alert($(input).val().length);
		valor = $(input).val() ;
		if (valor.length > 1)
		{	
			setTimeout(function(){
				$("input[name*="+$(input).attr("valuePost")+"]").val("");
				requisicaoAtual = $.post( $(input).attr("requisicao")+"&"+$(input).attr("valuePost")+ "="+valor,
					function (data)
					{
						requisicaoAtual = null;
						$("#"+$(input).attr("list")).html(data);
					}	
				)
						
				//$("#"+$(input).attr("list")).load($(input).attr("requisicao")+"&"+$(input).attr("valuePost")+ "="+$(input).val());
			}, (1000/2));
			
		}
	}	
});*/
/*
$(".datalist").focusout(function(){
   $("input[name*="+$(this).attr("valuePost")+"]").val($('option[value="'+$(this).val()+'"]').attr("data-id"));
});*/



function buscarListaValor(datalist, datalistCustom, tipoForm = "form")
{
	$(".dataListCustom").css("display", "none");
	//se o data list estiver no final da pag empurra ele pra cima pra poder clicar
	windowHeight = window.innerHeight;
	formDataListTop = $("#"+datalist).offset().top
	dataListCustom = $("#"+datalistCustom).offset().top
	difeEntreTelaEDatalist = windowHeight - formDataListTop
	//alert( difeEntreTelaEDatalist)//windowWidth)
	/*if (difeEntreTelaEDatalist < 151)
	{
		$("#"+datalistCustom).css("top", (formDataListTop-102)+"px");
		
	}
	else
	{
		$("#"+datalistCustom).css("top", (formDataListTop+40)+"px");
		
	}
	$("#"+datalistCustom).css("position","fixed");*/
	$("#"+datalistCustom).css("position","absolute");
	$("#"+datalistCustom).css("z-index","9999");
	$("#"+datalistCustom).css("max-width","80%");
	//$("#"+datalistCustom).css("position","absolute");
	$("#"+datalistCustom).html("<center><img src='css/load.gif'/></center>");
	if(requisicaoAtual !== null){
			//alert("entrou");
			//requisicaoAtual.abort();
			requisicaoAtual = null;
		}
	//alert($(this).attr("requisicao")+"?"+$(this).attr("valuePost")+ "="+$(this).val());
	input = $("#"+datalist);
	//alert($(input).val().length);
	valor = $(input).val() ;
	//if (valor.length > 1)
	//{	
		//ALERT(tipoForm+" "+$(input).attr("requisicao")+"&"+$(input).attr("valuePost")+ "="+valor+"&tipoForm="+tipoForm)
		setTimeout(function(){
			$("#"+$(this).closest('form').prop("id")+" input[name*="+$(input).attr("valuePost")+"]").val("");
			//requisicaoAtual = $.post( $(input).attr("requisicao")+"&"+$(input).attr("valuePost")+ "="+valor+"&tipoForm="+tipoForm,
			requisicaoAtual = $.post( $(input).attr("requisicao")+"&valor="+valor+"&tipoForm="+tipoForm+"&valuePost="+$(input).attr("valuePost"),
				function (data)
				{
					requisicaoAtual = null;
					$("#"+$(input).attr("list")).html(data);
				}	
			)
					
			//$("#"+$(input).attr("list")).load($(input).attr("requisicao")+"&"+$(input).attr("valuePost")+ "="+$(input).val());
		}, (1000/2));
		
	//}	
	$("#"+datalistCustom).css("display", "block");
	
}

function buscarListaValorGridEditavel(datalist, datalistCustom, tipoForm = "form")
{
	$(".dataListCustom").css("display", "none");
	//se o data list estiver no final da pag empurra ele pra cima pra poder clicar
	windowHeight = $(".div_grid_editavel").height();
	formDataListTop = $("#"+datalist).parent().position().top
	dataListCustom = $("#"+datalistCustom).offset().top
	difeEntreTelaEDatalist = windowHeight - formDataListTop
	//alert( difeEntreTelaEDatalist)//windowWidth)
	if (difeEntreTelaEDatalist < 100)
	{
		$("#"+datalistCustom).css("top", (formDataListTop-102)+"px");
		//$("#"+datalistCustom).css("top", (formDataListTop+30)+"px");
	}
	else
	{
		//$("#"+datalistCustom).css("top", (formDataListTop+40)+"px");
		$("#"+datalistCustom).css("top", (formDataListTop+30)+"px");
	}
	//$("#"+datalistCustom).css("left", ($("#"+datalist).offset().left)+"px");
	
	//$("#"+datalistCustom).css("position","fixed");
	//$("#"+datalistCustom).css("top", formDataListTop+"px");
	$("#"+datalistCustom).css("position","absolute");
	$("#"+datalistCustom).html("<center><img src='css/load.gif'/></center>");
	if(requisicaoAtual !== null){
			//alert("entrou");
			//requisicaoAtual.abort();
			requisicaoAtual = null;
		}
	//alert($(this).attr("requisicao")+"?"+$(this).attr("valuePost")+ "="+$(this).val());
	input = $("#"+datalist);
	//alert($(input).val().length);
	valor = $(input).val() ;
	//if (valor.length > 1)
	//{	
		//ALERT(tipoForm+" "+$(input).attr("requisicao")+"&"+$(input).attr("valuePost")+ "="+valor+"&tipoForm="+tipoForm)
		setTimeout(function(){
			$("#"+$(this).closest('form').prop("id")+" input[name*="+$(input).attr("valuePost")+"]").val("");
			//requisicaoAtual = $.post( $(input).attr("requisicao")+"&"+$(input).attr("valuePost")+ "="+valor+"&tipoForm="+tipoForm,
			requisicaoAtual = $.post( $(input).attr("requisicao")+"&valor="+valor+"&tipoForm="+tipoForm+"&valuePost="+$(input).attr("valuePost"),
				function (data)
				{
					requisicaoAtual = null;
					$("#"+$(input).attr("list")).html(data);
				}	
			)
					
			//$("#"+$(input).attr("list")).load($(input).attr("requisicao")+"&"+$(input).attr("valuePost")+ "="+$(input).val());
		}, (1000/2));
		
	//}	
	$("#"+datalistCustom).css("display", "block");
	
}

$(".datalist").focusout(function(){
   $("#"+$(this).closest('form').prop("id")+" input[name*="+$(this).attr("valuePost")+"]").val($('option[value="'+$(this).val()+'"]').attr("data-id"));
});

$(document).on("click", ".atualizaData", function(){
	//alert($(this).attr("data-id"))
	//alert($(this).closest('form').prop("id"))
   $("#"+$(this).closest('form').attr("id")+" input[name*="+$(this).attr("valuepost")+"]").val($(this).attr("data-id"));
   $("#"+$(this).closest('form').attr("id")+" input[id*="+$(this).attr("formPost")+"]").val($(this).html());
   //$("#datalist"+$(this).attr("valuepost")).css("display", "none");
   $(".dataListCustom").css("display", "none");
   habilitarComponente("#btnSalvar");
	habilitarComponente("#btnCancelar");
	habilitarComponente(".btnSalvar");
	habilitarComponente(".btnCancelar");
});

function expandirOuRecolherSeletor(id)
{
	if ($(id).css("display") == "block")
	{
		
		$(id).css("display","none");
		$(id+" div").css("display","none");
		/*$(id+" > div").each( function(index, value) {
			alert(this);
			 $(this).css("display","none");
		});*/

	}
	else
	{
		$(id).css("display","block");
		//$(id+" div").css("display","block");
	}	

}

 $( function() {
    $( "#tabs" ).tabs();
	$("#tabs, #tabs *").removeClass('ui-widget ui-widget-content'); //buga a fonte
  } );
  


var myControl=  {
	create: function(tp_inst, obj, unit, val, min, max, step){
		$('<input class="ui-timepicker-input" value="'+val+'" style="width:50%; padding: 0px;">')
			.appendTo(obj)
			.spinner({
				min: min,
				max: max,
				step: step,
				change: function(e,ui){ // key events
						// don't call if api was used and not key press
						if(e.originalEvent !== undefined)
							tp_inst._onTimeChange();
						tp_inst._onSelectHandler();
					},
				spin: function(e,ui){ // spin events
						tp_inst.control.value(tp_inst, obj, unit, ui.value);
						tp_inst._onTimeChange();
						tp_inst._onSelectHandler();
					}
			});
		return obj;
	},
	options: function(tp_inst, obj, unit, opts, val){
		if(typeof(opts) == 'string' && val !== undefined)
			return obj.find('.ui-timepicker-input').spinner(opts, val);
		return obj.find('.ui-timepicker-input').spinner(opts);
	},
	value: function(tp_inst, obj, unit, val){
		if(val !== undefined)
			return obj.find('.ui-timepicker-input').spinner('value', val);
		return obj.find('.ui-timepicker-input').spinner('value');
	}
};

dataAjustPaginaView = "";
if($('input[data-mask="00/00/0000"]').length)
{
	$('input[data-mask="00/00/0000"]').datepicker({
		dateFormat: 'dd/mm/yy',
		dayNames: ['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado'],
		dayNamesMin: ['D','S','T','Q','Q','S','S','D'],
		dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb','Dom'],
		monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
		monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
		nextText: 'Próximo',
		prevText: 'Anterior',
		beforeShow:function(input) {
			$(input).css({
				"z-index": 999999
			});
			dataAjustPaginaView = ""; ///correçõs no calendario ao avançar ou retroceder data/ pega o seletor proximo na pagina view
			//alert("a");
			//setTimeout(ajustar_clicks_avanc_e_retorced(),900);
		},
		afterShow:function(input) {
			setTimeout(ajustar_clicks_avanc_e_retorced(),300);
		}
		
	});
	$('input[data-mask="00/00/0000"]').on('focus', function (e) {
		e.preventDefault();
		$(this).datepicker('show');
		$(this).datepicker('widget').css('z-index', 99999);
		
	});
	
	
}


if($('input[data-mask="00/00/0000 00:00"]').length)
{	
	$('input[data-mask="00/00/0000 00:00"]').datetimepicker({
		 dateFormat: 'dd/mm/yy',
		controlType: myControl,
		dayNames: ['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado'],
		dayNamesMin: ['D','S','T','Q','Q','S','S','D'],
		dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb','Dom'],
		monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
		monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
		nextText: 'Próximo',
		prevText: 'Anterior',
		beforeShow:function(input) {
			$(input).css({
				"z-index": 999999
			});
		}
	});
}	

if($('input[data-mask="00/00"]').length)
{	
	$('input[data-mask="00/00"]').datepicker({
		dateFormat: 'dd/mm',
		dayNames: ['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado'],
		dayNamesMin: ['D','S','T','Q','Q','S','S','D'],
		dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb','Dom'],
		monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
		monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
		nextText: 'Próximo',
		prevText: 'Anterior',
		beforeShow:function(input) {
			$(input).css({
				"z-index": 999999
			});
		}
	});
	$('input[data-mask="00/00"]').on('focus', function (e) {
		e.preventDefault();
		$(this).datepicker('show');
		$(this).datepicker('widget').css('z-index', 99999);
	});
}

if($('input[data-mask="00/00/0000 00:00:00"]').length)
{	
	$('input[data-mask="00/00/0000 00:00:00"]').datetimepicker({
		dateFormat: 'dd/mm/yy',
		timeFormat: 'HH:mm:ss',
		controlType: myControl,
		dayNames: ['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado'],
		dayNamesMin: ['D','S','T','Q','Q','S','S','D'],
		dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb','Dom'],
		monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
		monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
		nextText: 'Próximo',
		prevText: 'Anterior',
		beforeShow:function(input) {
			$(input).css({
				"z-index": 999999
			});
		}
	});
}	
  
/*  
function buscarListaValor(datalist, datalistCustom)
{
	//se o data list estiver no final da pag empurra ele pra cima pra poder clicar
	windowHeight = window.innerHeight;
	formDataListTop = $("#"+datalist).offset().top
	dataListCustom = $("#"+datalistCustom).offset().top
	difeEntreTelaEDatalist = windowHeight - formDataListTop
	//alert( difeEntreTelaEDatalist)//windowWidth)
	if (difeEntreTelaEDatalist < 151)
	{
		$("#"+datalistCustom).css("top", (formDataListTop-102)+"px");
	}
	else
	{
		$("#"+datalistCustom).css("top", (formDataListTop+40)+"px");
	}
	$("#"+datalistCustom).html("<center><img src='css/load.gif'/></center>");
	if(requisicaoAtual !== null){
			//alert("entrou");
			//requisicaoAtual.abort();
			requisicaoAtual = null;
		}
	//alert($(this).attr("requisicao")+"?"+$(this).attr("valuePost")+ "="+$(this).val());
	input = $("#"+datalist);
	//alert($(input).val().length);
	valor = $(input).val() ;
	//if (valor.length > 1)
	//{	
		setTimeout(function(){
			$("input[name*="+$(input).attr("valuePost")+"]").val("");
			requisicaoAtual = $.post( $(input).attr("requisicao")+"&"+$(input).attr("valuePost")+ "="+valor,
				function (data)
				{
					requisicaoAtual = null;
					$("#"+$(input).attr("list")).html(data);
				}	
			)
					
			//$("#"+$(input).attr("list")).load($(input).attr("requisicao")+"&"+$(input).attr("valuePost")+ "="+$(input).val());
		}, (1000/2));
		
	//}	
	$("#"+datalistCustom).css("display", "block");
	
}


$(document).on("click", ".atualizaData", function(){
	//alert($(this).attr("data-id"))
   $("input[name*="+$(this).attr("valuepost")+"]").val($(this).attr("data-id"));
   $("input[id*="+$(this).attr("formPost")+"]").val($(this).html());
   $("#datalist"+$(this).attr("valuepost")).css("display", "none");
});*/

//altura da tabela e cabeçalho fixo
if($('#listtable').length > 0)
{	
	document.getElementById("listtable").addEventListener("scroll", function(){
	   var translate = "translate(0,"+this.scrollTop+"px)";
	   this.querySelector("thead").style.transform = translate;
	});
	//alert($("#listtable").last().offset().top + " "+$(window).height())
	tamanhoTabela = $(window).height() - ($("#listtable").last().offset().top) - 100
	if(tamanhoTabela < 200)
	{
		tamanhoTabela = 200
	}
	$("#listtable").css("height", tamanhoTabela + "px");
	
	//alert($("#listtable td").length)
	$("#listtable").css("width", "100%");
	//$("#listtable thead").css("width", ($("#listtable td").length * 280)+"px");
	//$("#listtable thead").css("min-width", "100%");
}	
var WindowsSize=function(){
    if($('#listtable').length > 0)
	{
		tamanhoTabela = $(window).height() - ($("#listtable").last().offset().top) - 100
		if(tamanhoTabela < 200)
		{
			tamanhoTabela = 200
		}
		//$("#listtable").css("height", tamanhoTabela + "px");
	}

	///ajusta posição do datalist em relação ou input
	/*
	$(".filtroForm_grid_editavel").each(function(i){
		$(this).children("input").each(function() {
			windowHeight = window.innerHeight;
			datalist = $(this).attr("id");
			datalistCustom = $(this).attr("list");
			formDataListTop = $("#"+datalist).offset().top
			dataListCustom = $("#"+datalistCustom).offset().top
			difeEntreTelaEDatalist = windowHeight - formDataListTop
			//alert( difeEntreTelaEDatalist)//windowWidth)
			if (difeEntreTelaEDatalist < 151)
			{
				//$("#"+datalistCustom).css("top", (formDataListTop-102)+"px");
				$("#"+datalistCustom).css("top", ($("#"+datalist).offset().top+30)+"px");
			}
			else
			{
				//$("#"+datalistCustom).css("top", (formDataListTop+40)+"px");
				$("#"+datalistCustom).css("top", ($("#"+datalist).offset().top+30)+"px");
			}
			$("#"+datalistCustom).css("left", ($("#"+datalist).offset().left)+"px");	
		});
	});*/
 };
$(document).ready(WindowsSize); 
$(window).resize(WindowsSize); 

//desabilitar tecla enter nos formulários
$(document).on("keypress", 'form', function (e) {
    var code = e.keyCode || e.which;
    if (code == 13) {
        e.preventDefault();
        return false;
    }
});

function inicia_select2()
{
		if ($("select").length > 1)
	{
		$( "select" ).each(function() {
			
			if(! $(this).attr("noselect2"))
			{
				 tamanho = 200
				 maior_qtd_char = 0
				 $(this).children("option").each(function(){
					if($(this).html().length > maior_qtd_char)
					{
						maior_qtd_char = $(this).html().length
					}
				});
				if(maior_qtd_char > 0 )
				{
					tamanho = maior_qtd_char*9;
				}
				if(tamanho > 500)
				{
					tamanho = 500
				}
				if(tamanho < 150)
				{
					tamanho = 150;
				}
				if(tamanho > $( document ).width())
				{
					$( this ).parent().css("width","100%");
				}
				else
				{	
					$( this ).parent().css("width",tamanho+"px");
				}	
				readonly = false;
				if($(this).attr("readonly"))
				{
					readonly = true;
				}
				if(! readonly)
				{	
					$( this ).css("width","100%");
					 $( this ).select2( {
						placeholder: $( this ).attr("placeholder"),
						allowClear: true,
						readonly:readonly,
						dropdownParent: $( this ).parent()
					} ).on('select2:open',function(){

					$('.select2-dropdown--above').attr('id','fix');
					$('#fix').removeClass('select2-dropdown--above');
					$('#fix').addClass('select2-dropdown--below');

			});
					
				}
			}	
		});
		
		$(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
		  $(this).closest(".select2-container").siblings('select:enabled').select2('open');
		});

		// steal focus during close - only capture once and stop propogation
		$('select.select2').on('select2:closing', function (e) {
		  $(e.target).data("select2").$selection.one('focus focusin', function (e) {
			e.stopPropagation();
		  });
		});
		
		
	}
}
inicia_select2();
if(($(".filtroForm_grid_editavel").length > 0 || $(".filtroForm").length > 0 ) ) //bloquear
{	
	$( "*" ).scroll(function() {
		///ajusta posição do datalist em relação ou input
		//alert("aa")
		/*$(".filtroForm_grid_editavel").each(function(i){
			$(this).children("input").each(function() {
				if($(this).attr("list"))
				{	
					windowHeight = window.innerHeight;
					datalist = $(this).attr("id");
					datalistCustom = $(this).attr("list");
					formDataListTop = $("#"+datalist).offset().top
					dataListCustom = $("#"+datalistCustom).offset().top
					difeEntreTelaEDatalist = windowHeight - formDataListTop
					//alert( difeEntreTelaEDatalist)//windowWidth)
					if (difeEntreTelaEDatalist < 151)
					{
						//$("#"+datalistCustom).css("top", (formDataListTop-102)+"px");
						$("#"+datalistCustom).css("top", ($("#"+datalist).offset().top+30)+"px");
					}
					else
					{
						//$("#"+datalistCustom).css("top", (formDataListTop+40)+"px");
						$("#"+datalistCustom).css("top", ($("#"+datalist).offset().top+30)+"px");
					}
					$("#"+datalistCustom).css("left", ($("#"+datalist).offset().left)+"px");	
				}	
			});
		});*/
		if($(".datalist").length > 0 )
		{	
			$(".filtroForm_grid_editavel .datalist").each(function(i){
				//$(this).children("input").each(function() {
					if($(this).attr("list") && $("#"+$(this).attr("list")).length > 0)
					{	
						windowHeight = $(".div_grid_editavel").height();
						datalist = $(this).attr("id");
						datalistCustom = $(this).attr("list");
						formDataListTop = $("#"+datalist).parent().position().top
						dataListCustom = $("#"+datalistCustom).offset().top
						difeEntreTelaEDatalist = windowHeight - formDataListTop
						//alert( difeEntreTelaEDatalist)//windowWidth)
						if (difeEntreTelaEDatalist < 100)
						{
							$("#"+datalistCustom).css("top", (formDataListTop-102)+"px");
							//$("#"+datalistCustom).css("top", (formDataListTop+30)+"px");
						}
						else
						{
							//$("#"+datalistCustom).css("top", (formDataListTop+40)+"px");
							$("#"+datalistCustom).css("top", (formDataListTop+30)+"px");
						}
						$("#"+datalistCustom).css("left", ($("#"+(datalist)).parent().left)+"px");	
						$("#"+datalistCustom).css("position","absolute");
						$("#"+datalistCustom).css("z-index","9999");
						$("#"+datalistCustom).css("max-width","80%");
					}	
				//});
			});
		}	
	});
}
$(document).on("click", ".selection", function(){
   habilitarComponente("#btnSalvar");
	habilitarComponente("#btnCancelar");
	habilitarComponente(".btnSalvar");
	habilitarComponente(".btnCancelar");
});

///correçõs no calendario ao avançar ou retroceder data/ pega o seletor proximo na pagina view
dataAjustPaginaView = "";
function ajustar_clicks_avanc_e_retorced()
{
	//dataAjust = "";
	//alert("aaa");
	if($("#pagina_view").length > 0) //usar apenas no dashiboard nas páginas
	{
		$(".ui-datepicker-prev").click(function(){
				//$('.hasDatepicker').val("01/01/2024");
				leftPicker = $(this).parent().offset().left
				topPicker = $(this).parent().offset().top
				$('.hasDatepicker').each(function(i,v){
					leftSeletor = $(this).offset().left
					topSeletor = $(this).offset().top
					difLeft = leftPicker-leftSeletor
					difTop = topPicker-topSeletor
					//alert(difTop+" "+difLeft)
					if((difLeft >= -20 && difLeft <= 20 ) && (difTop >= -50 && difTop <= 50))
					{
						//$(this).val("01/01/2024");
						//alert($(this).attr("id"))
						if(dataAjustPaginaView == ""){ dataAjustPaginaView = $(this).val(); dataOriginal = $(this).val();}
						aData = dataAjustPaginaView.split("/");
						//dataOriginal = dataAjustPaginaView;
						if(aData.length > 1)
						{
							if(parseInt(aData["1"]) > 1)
							{
								mes = (parseInt(aData["1"])-1);
								if(mes < 10) {mes = "0"+mes};
								//$(this).val(aData[0]+"/"+mes+"/"+aData[2]);
								$(this).datepicker('setDate',aData[0]+"/"+mes+"/"+aData[2]);
							}
							else
							{
								ano = (parseInt(aData["2"])-1);
								//$(this).val(aData[0]+"/12/"+ano);
								$(this).datepicker('setDate',aData[0]+"/12/"+ano);
							}
							dataAjustPaginaView = $(this).val();
							$(this).val(dataOriginal);
						}
					}
					//alert(leftSeletor+" "+topSeletor)
				});
			});
			
			$(".ui-datepicker-next").click(function(){
				//$('.hasDatepicker').val("01/01/2024");
				leftPicker = $(this).parent().offset().left
				topPicker = $(this).parent().offset().top
				$('.hasDatepicker').each(function(i,v){
					leftSeletor = $(this).offset().left
					topSeletor = $(this).offset().top
					difLeft = leftPicker-leftSeletor
					difTop = topPicker-topSeletor
					//alert(difTop)
					if((difLeft >= -20 && difLeft <= 20 ) && (difTop >= -50 && difTop <= 50))
					{
						if(dataAjustPaginaView == ""){ dataAjustPaginaView = $(this).val(); dataOriginal = $(this).val();}
						//$(this).val("01/01/2024");
						aData = dataAjustPaginaView.split("/");
						//dataOriginal = dataAjustPaginaView;
						if(aData.length > 1)
						{
							if(parseInt(aData["1"]) < 12)
							{
								mes = (parseInt(aData["1"])+1);
								if(mes < 10) {mes = "0"+mes};
								//$(this).val(aData[0]+"/"+mes+"/"+aData[2]);
								$(this).datepicker('setDate',aData[0]+"/"+mes+"/"+aData[2]);
							}
							else
							{
								ano = (parseInt(aData["2"])+1);
								//$(this).val(aData[0]+"/01/"+ano);
								$(this).datepicker('setDate',aData[0]+"/01/"+ano);
							}
						}
						dataAjustPaginaView = $(this).val();
						$(this).val(dataOriginal);
					}
					//alert(leftSeletor+" "+topSeletor)
				});
			});
			
			$(".ui-state-default").click(function(){
				leftPicker = $(this).parent().parent().parent().parent().parent().offset().left
				topPicker = $(this).parent().parent().parent().parent().parent().offset().top
				ano = $(this).parent().attr("data-year");
				mes = parseInt($(this).parent().attr("data-month"))+1;
				if(mes < 10) {mes = "0"+mes};
				dia = parseInt($(this).html());
				if(dia < 10) {dia = "0"+dia};
				$('.hasDatepicker').each(function(i,v){
					leftSeletor = $(this).offset().left
					topSeletor = $(this).offset().top
					difLeft = leftPicker-leftSeletor
					difTop = topPicker-topSeletor
					//alert(difTop)
					if((difLeft >= -20 && difLeft <= 20 ) && (difTop >= -50 && difTop <= 50))
					{
						$(this).val(dia+"/"+mes+"/"+ano);
					}
				});
				
			});	
	}
}
////fim ajuste