- delayTimer = null;
- (function($) {
- $.fn.FuncemeDatePicker = function(options) {
- var settings = {
- format : 'mensal',
- success: 'return_success',
- complete: 'return_complete',
- request:true,
- file:null
- };
- var methodos = {
- iniAjax: function(file,return_ajax,complete_ajax,base_url)
- {
- if( delayTimer ){
- window.clearTimeout( delayTimer );
- }
- delayTimer = window.setTimeout(function(){
- $.ajax({
- type: "GET",
- url: file,
- dataType: "HTML",
- contentType: "application/x-www-form-urlencoded",
- success: return_ajax,
- complete:complete_ajax
- });
- }, 200 );
- },
- ajax: function(file,return_ajax,complete_ajax,base_url)
- {
- base_url = $('#base_url').val();
- if( delayTimer ){
- window.clearTimeout( delayTimer );
- }
- delayTimer = window.setTimeout(function(){
- $.ajax({
- type: "GET",
- url: base_url+"anos/"+file+"/index.xml",
- dataType: "xml",
- contentType: "application/x-www-form-urlencoded",
- success: return_ajax,
- complete:complete_ajax
- });
- }, 200 );
- },
- mapa:function(file)
- {
- var base_url = $('#base_url').val();
- var mapa_gif = base_url+"anos/"+file+"/mapa.gif";
- $('div#imagem img').attr('src',mapa_gif);
- if("#imagem_mapa"){
- $('#fdiv_texto').css('visibility',"hidden");
- return false;
- }
- },
- load_file: function()
- {
- var ob_data = new Date($('#data_dia').val());
- var mes = ob_data.getMonth()+1;
- var ano = ob_data.getFullYear();
- return ano +'/'+mes;
- },
- load_file_diario: function()
- {
- var dataInput = $('#dia').val();
- var data = dataInput.split('/');
- var dia = parseFloat(data[0]);
- var mes = data[1];
- var ano = data[2];
- return ano +'/'+mes+'/'+dia;
- },
- load_file_anual: function()
- {
- var ano = $('#ano').text();
- return ano;
- },
- load_file_decada: function()
- {
- var data_span = $('#decada').text();
- var data = data_span.split('-');
- var first = parseFloat(data[0]);
- var last = parseFloat(data[1]);
- return first+'/'+last;
- },
- change_month: function(mes)
- {
- var ob_data = new Date($('#data_dia').val());
- var data_hoje = new Date();
- ob_data.setMonth(mes);
- if(ob_data <= data_hoje){
- $('#data_dia').val(ob_data);
- }
- else{
- alert("Não há dados para o mês selecionado!"nado!");
- }
- },
- change_year: function(ano)
- {
- var ob_data = new Date($('#data_dia').val());
- var data_hoje = new Date();
- ob_data.setFullYear(ano);
- if(ob_data <= data_hoje){
- $('#data_dia').val(ob_data);
- return true;
- }else{
- alert("Não há dados para o ano selecionado. Selecione outro ano!");
- return false;
- }
- },
- criarHtmlDiario:function()
- {
- var htmld = " <div class='select_dia'><input name='dia' id='dia' class='dia_select' value=' /></div>";
- return htmld;
- },
- criarHtmlMensal:function()
- {
- var htmlm = ' htmlm = '<div class="mes">';
- htmlm += '<div class="mes_one">';
- htmlm += '<span id="mes" name=""></span>';
- htmlm += '</div>';
- htmlm += '<div class="mes_two">';
- htmlm += '<span><a class="seta_up" id=" href="xt" href=""></a></span>';
- htmlm += '<span><a class=" id="down" id=" href="ev" href=""></a></span>';
- htmlm += '</div>';
- htmlm += '</div>';
- htmlm += '<div class="ano">';
- htmlm += '<div class="ano_one">';
- htmlm += '<span id="ano"></span>';
- htmlm += '</div>';
- htmlm += '<div class="ano_two">';
- htmlm += '<span><a class="seta_up" id="yearnext" href=""></a></span>';
- htmlm += '<span><a class=" id="down" id="yearprev" href=""></a></span>';
- htmlm += '</div>';
- htmlm += '</div>';
- return htmlm;
- },
- criarHtmlAnual:function()
- {
- var htmla = '<div class="ano">';
- htmla += '<div class="ano_one">';
- htmla += '<span id="ano"></span>';
- htmla += '</div>';
- htmla += '<div class="ano_two">';
- htmla += '<span><a class="seta_up" id="yearnext" href=""></a></span>';
- htmla += '<span><a class=" id="down" id="yearprev" href=""></a></span>';
- htmla += '</div>';
- htmla += '</div>';
- return htmla;
- },
- criarHtmlDecada:function()
- {
- var htmld = '<div class="ano">';
- htmld += '<div class="ano_one">';
- htmld += '<span id="decada"></span>';
- htmld += '</div>';
- htmld += '<div class="ano_two">';
- htmld += '<span><a class="seta_up" id="tenyearnext" href=""></a></span>';
- htmld += '<span><a class=" id="down" id="tenyearprev" href=""></a></span>';
- htmld += '</div>';
- htmld += '</div>';
- return htmld;
- },
- criarHtmlMensalSelect:function()
- {
- var htmlm = '<ul class="ul_mes">';
- htmlm += '<li id="li_mes"s="li_mes"><a id="mes" class="mes_select" name="0">Janeiro</a></li>';
- htmlm += '<li id="li_mes"s="li_mes"><a id="mes" class="mes_select" name="1">Fevereiro</a></li>';
- htmlm += '<li id="li_mes"s="li_mes"><a id="mes" class="mes_select" name="2">Março<a></li>';
- htmlm += '<li id="3" class="li_mes" class="mes" class="mes_select" name="3">Abril</a></li>';
- htmlm += '<li id="4" class="li_mes" class="mes" class="mes_select" name="4">Maio</a></li>';
- htmlm += '<li id="5" class="li_mes" class="mes" class="mes_select" name="5">Junho</a></li>';
- htmlm += '<li id="6" class="li_mes" class="mes" class="mes_select" name="6">Julho</a></li>';
- htmlm += '<li id="7" class="li_mes" class="mes" class="mes_select" name="7">Agosto</a></li>';
- htmlm += '<li id="8" class="li_mes" class="mes" class="mes_select" name="8">Setembro</a></li>';
- htmlm += '<li id="9" class="li_mes" class="mes" class="mes_select" name="9">Outubro</a></li>';
- htmlm += '<li id="10" class="li_mes" class="mes" class="mes_select" name="10">Novembro</a></li>';
- htmlm += '<li id="11" class="li_mes" class="mes" class="mes_select" name="11">Dezembro</a></li>';
- htmlm += '<ul>';
- return htmlm;
- },
- criarHtmlAnualSelect: function()
- {
- var data = new Date();
- var data_ano = data.getFullYear();
- var htmla = '<ul class="ul_ano">';
- for(anos=data_ano;anos>=1974;anos--)
- {
- htmla += '<li class="li_ano" class="ano" class="ano_select" >'+anos+'</a></li>';
- }
- htmla += '</ul>';
- return htmla;
- },
- load_ini:function()
- {
- data = new Date();
- mes = data.getMonth();
- ano = data.getFullYear();
- meses = new Array(12);
- meses[0] = "Janeiro";
- meses[1] = "Fevereiro";
- meses[2] = "Março";
- meses[3] = "Abril";
- meses[4] = "Maio";
- meses[5] = "Junho";
- meses[6] = "Julho";
- meses[7] = "Agosto";
- meses[8] = "Setembro";
- meses[9] = "Outubro";
- meses[10] = "Novembro";
- meses[11] = "Dezembro";
- $("#data_dia").val(data);
- $("#mes").text(meses[mes]);
- $("#mes").attr("name",mes+1);
- $("#ano").text(ano);
- },
- load_ini_year:function()
- {
- data = new Date();
- ano_atual = parseFloat(data.getFullYear());
- data_input = new Date();
- ano_input = parseFloat(data_input.getFullYear());
- ini_ano = ano_atual-10;
- $("span#decada").text(""+ano_atual+" ");
- $(" $("#tenyearnext").attr('href',ano_input);
- $("#tenyearprev").attr('href',ini_ano);
- var data_input = new Date($("#data_dia").val());
- if(ano_input == ano_atual){
- $("#tenyearnext").css('visibility','hidden');
- }
- },
- getMonthName:function()
- {
- var ob_data = new Date($("#data_dia").val());
- var mes = ob_data.getMonth();
- meses = new Array(12);
- meses[0] = "Janeiro";
- meses[1] = "Fevereiro";
- meses[2] = "Março";
- meses[3] = "Abril";
- meses[4] = "Maio";
- meses[5] = "Junho";
- meses[6] = "Julho";
- meses[7] = "Agosto";
- meses[8] = "Setembro";
- meses[9] = "Outubro";
- meses[10] = "Novembro";
- meses[11] = "Dezembro";
- return meses[mes];
- },
- monthprev: function()
- {
- var data= new String();
- data=$("#data_dia").val();
- if(data!=""){
- date = new Date(data);
- }
- else{
- date = new Date();
- }
- date.setMonth(date.getMonth()-1);
- $("#data_dia").val(date);
- $("#mes").attr("name",date.getMonth()+1);
- $("#mes").text(meses[date.getMonth()]);
- $("#mes").val(date.getMonth()+1);
- $("#ano").text(date.getFullYear());
- $("#ano").val(date.getFullYear());
- },
- monthnext: function()
- {
- data_two = new Date()
- var data= new String();
- data=$("#data_dia").val();
- date = new Date(data);
- date_tmp = new Date(data);
- date_tmp.setMonth(date.getMonth()+1);
- if(date_tmp >= data_two){
- alert('Mudança de mês inválida!');
- return false;
- }
- else{
- date.setMonth(date.getMonth()+1);
- }
- $("#data_dia").val(date);
- $("#mes").attr("name",date.getMonth()+1);
- $("#mes").text(meses[date.getMonth()]);
- $("#mes").val(date.getMonth()+1);
- $("#ano").text(date.getFullYear());
- $("#ano").val(date.getFullYear());
- },
- yearprev: function()
- {
- var data= new String();
- data=$("#data_dia").val();
- date = new Date(data);
- if(data!=""){
- date = new Date(data);
- }
- else{
- date = new Date();
- }
- date.setFullYear(date.getFullYear()-1);
- $("#data_dia").val(date);
- $("#mes").attr("name",date.getMonth()+1);
- $("#mes").text(meses[date.getMonth()]);
- $("#mes").val(date.getMonth()+1);
- $("#ano").text(date.getFullYear());
- $("#ano").val(date.getFullYear());
- },
- yearnext: function()
- {
- data_two = new Date();
- var data= new String();
- data=$("#data_dia").val();
- date_tmp = new Date(data);
- date = new Date(data);
- date_tmp.setFullYear(date.getFullYear()+1);
- if(date_tmp >= data_two){
- alert('Mudança de ano inválida!');
- return false;
- }
- else{
- date.setFullYear(date.getFullYear()+1);
- }
- $("#data_dia").val(date);
- $("#mes").attr("name",date.getMonth()+1);
- $("#mes").text(meses[date.getMonth()]);
- $("#mes").val(date.getMonth()+1);
- $("#ano").text(date.getFullYear());
- $("#ano").val(date.getFullYear());
- },
- tenyearprev: function()
- {
- ultimo_ano = $("#tenyearprev").attr('href');
- ini_ano = ultimo_ano-10;
- if(ini_ano == 1972){
- $("#tenyearprev").css('visibility','hidden');
- }
- $("#tenyearprev").attr('href',ini_ano);
- $("span#decada").text(""+ini_ano+" - "+ultimo_ano+" ");
- if(parseFloat(ultimo_ano)){
- $("#tenyearnext").css('visibility','visible');
- }
- $("#tenyearnext").attr('href',ultimo_ano);
- },
- tenyearnext: function()
- {
- data_input = new Date();
- ano_input = parseFloat(data_input.getFullYear());
- first_ano = $("#tenyearnext").attr('href');
- total_ano = 10;
- ini_ano = eval(first_ano) + eval(total_ano);
- if(ini_ano > 1972){
- $("#tenyearprev").css('visibility','visible');
- }
- $("#tenyearnext").attr('href',ini_ano);
- $("span#decada").text("" "irst_ano+" - "+ini_ano+" ");
- if(ano_input == ini_ano){
- $("#tenyearnext").css('visibility','hidden');
- }
- $("#tenyearprev").attr('href',first_ano);
- },
- getDia:function()
- {
- file = $('#data').val();
- date = file.split('/');
- dia= parseFloat(date[0]);
- return dia;
- },
- setMonthText:function()
- {
- $('span[id=mes]').text(this.getMonthName())// Fim dos methodos
- } // Fim dos methodos
- return this.each(function()
- {
- if(options){
- $.extend( settings, options );
- }
- if(settings['format']=='diario')
- {
- $(this).html(methodos.criarHtmlDiario());
- $( "#dia" ).datepicker(
- {
- //www.funceme.br/produtos/imagens/date_2.png",
- utos/imagens/date_2.png",
- buttonImageOnly: true,
- showOn: 'both',
- onSelect: function(dateText, inst)
- {
- var file = methodos.load_file_diario();
- if(settings['request']==true)
- {
- methodos.ajax(file,settings['success']);
- methodos.mapa(file);
- }
- }
- });
- }
- if(settings['format']=='mensal' )
- {
- $(this).addClass("selectdiaMensal");
- $(this).html(methodos.criarHtmlMensal());
- $(this).find(".mes").append(methodos.criarHtmlMensalSelect());
- $(this).find(".ano").append(methodos.criarHtmlAnualSelect());
- $('.ul_mes').hide();
- $('.ul_ano').hide();
- methodos.load_ini();
- var file = methodos.load_file();
- if(settings['request']==true)
- {
- methodos.ajax(file,settings['success']);
- methodos.mapa(file);
- }
- }
- if(settings['format']=='anual' && $(').val()=="mensal" )
- {
- $(this).addClass("selectdiaAnual");
- $(this).html(methodos.criarHtmlAnual());
- $(this).find(".ano").append(methodos.criarHtmlAnualSelect());
- $('ct());
- $('.ul_ano').hide();
- methodos.load_ini();
- file = "";
- base_url = $('#base_url').val();
- produto = $('#produto').val();
- if(settings['file'] == null)
- {
- if(settings['request']==true){
- file = methodos.load_file_anual();
- methodos.ajax(file,settings['success']);
- }
- }else{
- if(settings['request']==true){
- file = settings['file']+"?data="+methodos.load_file_anual()+"&base_url="+base_url+"&produto="+produto;
- methodos.iniAjax(file,settings['success']);
- }
- }
- methodos.mapa(file);
- }
- if(settings['format']=='anual' && $('#tipo_periodo #periodo').val()=="mensal" )
- {
- $(this).addClass("selectdiaAnual");
- $(this).html(methodos.criarHtmlAnual());
- $(this).find(".ano").append(methodos.criarHtmlAnualSelect());
- $('.ul_ano').hide();
- methodos.load_ini();
- file = "";
- base_url = $('#base_url').val();
- produto = $('#produto').val();
- if(settings['file'] == null)
- {
- if(settings['request']==true){
- file = methodos.load_file_anual();
- methodos.ajax(file,settings['success']);
- }
- }else{
- if(settings['request']==true){
- file = settings['file']+"?data="+methodos.load_file_anual()+"&base_url="+base_url+"&produto="+produto;
- methodos.iniAjax(file,settings['success']);
- }
- }
- methodos.mapa(file);
- }
- if(settings['format']=='anual' && $('#tipo_periodo #periodo').val()=="anual" )
- {
- $(this).addClass("selectdiaAnual");
- $(this).html(methodos.criarHtmlAnual());
- $(this).find(".ano").append(methodos.criarHtmlAnualSelect());
- $('.ul_ano').hide();
- methodos.load_ini();
- file = "";
- base_url = $('#base_url').val();
- produto = $('#produto').val();
- if(settings['file'] == null)
- {
- if(settings['request']==true){
- file = methodos.load_file_anual();
- methodos.ajax(file,settings['success']);
- }
- }else{
- if(settings['request']==true){
- file = settings['file']+"?data="+methodos.load_file_anual()+"&base_url="+base_url+"&produto="+produto;
- methodos.iniAjax(file,settings['success']);
- }
- }
- methodos.mapa(file);
- }
- if((settings['format']=='anual' && $(').val()=="anual") || (settings[')=="anual") || (settings['format']=='anual' && $('#tipo_periodo #periodo').val()=="decadas"))
- {
- $(this).addClass("selectdiaAnual");
- $(this).html(methodos.criarHtmlDecada());
- methodos.load_ini_year();
- file = "";
- base_url = $('#base_url').val();
- produto = $('#produto').val();
- if(settings['file'] == null)
- {
- if(settings['request']==true){
- file = methodos.load_file_decada();
- methodos.ajax(file,settings['success']);
- }
- }else{
- if(settings['request']==true){
- file = settings['file']+"?decada="+methodos.load_file_decada()+"&base_url="+base_url+"&produto="+produto;
- methodos.iniAjax(file,settings['success']);
- }
- }
- methodos.mapa(file);
- $(this).find("a[id=tenyearprev]").bind('click',function(e)
- {
- e.preventDefault();
- methodos.tenyearprev();
- var file = methodos.load_file_decada();
- if(settings['file'] == null)
- {
- if(settings['request']==true){
- file = methodos.load_file_decada();
- methodos.ajax(file,settings['success']);
- }
- }else{
- if(settings['request']==true){
- file = settings['file']+"?decada="+methodos.load_file_decada()+"&base_url="+base_url+"&produto="+produto;
- methodos.iniAjax(file,settings['success']);
- }
- }
- });
- $(this).find("a[id=tenyearnext]").bind('click',function(e)
- {
- e.preventDefault();
- methodos.tenyearnext();
- var file = methodos.load_file_decada();
- if(settings['file'] == null)
- {
- if(settings['request']==true){
- file = methodos.load_file_decada();
- methodos.ajax(file,settings['success']);
- }
- }else{
- if(settings['request']==true){
- file = settings['file']+"?decada="+methodos.load_file_decada()+"&base_url="+base_url+"&produto="+produto;
- methodos.iniAjax(file,settings['success']);
- }
- }
- });
- }
- if(settings['format']=='mensal')
- {
- $(this).find("a[id=monthprev]").bind('click',function(e)
- {
- e.preventDefault();
- methodos.monthprev();
- var file = methodos.load_file();
- if(settings['request']==true){
- methodos.ajax(file,settings['success']);
- methodos.mapa(file);
- }else{
- settings.success();
- }
- });
- $(this).find("a[id=monthnext]").bind('click',function(e)
- {
- e.preventDefault();
- methodos.monthnext();
- var file = methodos.load_file();
- if(settings['request']==true){
- methodos.ajax(file,settings['success']);
- methodos.mapa(file);
- }else{
- settings.success();
- }
- });
- $(this).find("a[id=yearprev]").bind('click',function(e)
- {
- e.preventDefault();
- methodos.yearprev();
- var file = methodos.load_file();
- if(settings['request']==true){
- methodos.ajax(file,settings['success']);
- methodos.mapa(file);
- }else{
- settings.success();
- }
- });
- $(this).find("a[id=yearnext]").bind('click',function(e)
- {
- e.preventDefault();
- methodos.yearnext();
- var file = methodos.load_file();
- if(settings['request']==true){
- methodos.ajax(file,settings['success']);
- methodos.mapa(file);
- }else{
- settings.success();
- }
- });
- }else if(settings['format']=='anual' )
- {
- $(this).find("a[id=yearprev]").bind('click',function(e)
- {
- e.preventDefault();
- methodos.yearprev();
- file = "";
- base_url = $('#base_url').val();
- produto = $('#produto').val();
- if(settings['file'] == null)
- {
- if(settings['request']==true){
- file = methodos.load_file_anual();
- methodos.ajax(file,settings['success']);
- }else{
- settings.success();
- }
- }else{
- if(settings['request']==true){
- file = settings['file']+"?data="+methodos.load_file_anual()+"&base_url="+base_url+"&produto="+produto;
- methodos.iniAjax(file,settings['success']);
- }else{
- settings.success();
- }
- }
- methodos.mapa(file);
- });
- $(this).find("a[id=yearnext]").bind('click',function(e)
- {
- e.preventDefault();
- methodos.yearnext();
- var file = "";
- var base_url = $('#base_url').val();
- produto = $('#produto').val();
- if(settings['file'] == null)
- {
- if(settings['request']==true){
- file = methodos.load_file_anual();
- methodos.ajax(file,settings['success']);
- }else{
- settings.success();
- }
- }else{
- if(settings['request']==true){
- file = settings['file']+"?data="+methodos.load_file_anual()+"&base_url="+base_url+"&produto="+produto;
- methodos.iniAjax(file,settings['success']);
- }else{
- settings.success();
- }
- }
- methodos.mapa(file);
- });
- }
- $(this).find('span[id=mes]').live('click',function()
- {
- $('.mes_two').hide();
- $('span[id=mes]').hide();
- $('.ul_mes').show();
- });
- $(this).find("a[id=mes]").live("click", function()
- {
- methodos.change_month($(this).attr('name'));
- var file = methodos.load_file();
- if(settings['request']==true){
- methodos.ajax(file,settings['success']);
- methodos.mapa(file);
- }
- $('.ul_mes').hide();
- $('span[id=mes]').show();
- methodos.setMonthText();
- $('.mes_two').show();
- });
- $(this).find('span#ano').bind('click',function()
- {
- $('.ano_two').hide();
- $('span[id=ano]').hide();
- $('.ul_ano').show();
- });
- $(this).find("a[id=ano]").live("click", function()
- {
- var type = settings['format'];
- if(type == 'mensal')
- {
- var load = methodos.change_year($(this).text());
- if(load)
- {
- var file = methodos.load_file();
- if(settings['request']==true){
- methodos.ajax(file,settings['success']);
- methodos.mapa(file);
- }
- $('.ul_ano').hide();
- $('span[id=ano]').show();
- $('span[id=ano]').text($(this).text());
- $('.ano_two').show();
- }
- }
- if(type == 'anual' && $(').val()=="anual" || $('to').val()=="anual" || $('#tipo_produto #periodo').val()=="anual")
- {
- methodos.change_year($(this).text());
- var file = "";
- var base_url = $('#base_url').val();
- var produto = $('#produto').val();
- if(settings['file'] == null)
- {
- if(settings['request']==true){
- file = methodos.load_file_anual();
- methodos.ajax(file,settings['success']);
- }
- }else{
- if(settings['request']==true){
- file = settings['file']+"?data="+methodos.load_file_anual()+"&base_url="+base_url+"&produto="+produto;
- methodos.iniAjax(file,settings['success']);
- }
- }
- $('.ul_ano').hide();
- $('span[id=ano]').show();
- $('span[id=ano]').text($(this).text());
- $('.ano_two').show();
- }
- });