  /*<![CDATA[*/
  validateDate()
  IE = document.all?true:false
  is_link = false;
  today = false;
  datas = datas.split(',');
  oDatas = new Object;
  for (var i = 0; i < datas.length; i++) oDatas[datas[i].replace('p', 'd')] = true;
  var objCalendar = function(oForm, oObj, nameMonth) {
      // PROPRIEDADES DO OBJETO
      this.daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
      this.allMonth = new Array('Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro');
      this.tbody = 'calendarTbody';
      this.actualDayClass = 'today';
      this.weekendDayClass = '';
      this.comicDayClass = '';
      this.comicHojeDayClass = 'today' ;
      this.comicFdsDayClass = '';
      this.comicFdsDayClassPub = '';     
      this.comicHojeDayClassPub = 'today';           
      this.emptyClass = '';            

      this.serverDate = new Date();
      this.serverDate.setYear(year);
      this.serverDate.setMonth(month);
      this.serverDate.setDate(day);

      this.actualDate = new Date();
      day2 = getFromUrl('day') 
      month2 = getFromUrl('month') 
      year2 = getFromUrl('year')
      day = day2 != -1 ? day2 : day
      month = month2 != -1 ? month2 : month
      year = year2 != -1 ? year2 : year
      this.actualDate.setYear(year);
      this.actualDate.setMonth((month-1), day);
//      this.actualDate.setDate(day);
      this.oForm = oForm;
      this.oObj = oObj;
      this.nameMonth = nameMonth;

      // FUNCOES DO OBJETO  
      this.getNextDate = getNextDate;
      this.getPrevioustDate = getPrevioustDate;
      this.submitNewDate = submitNewDate;
      this.getMonthDays = getMonthDays;
      this.firstDayWeek = firstDayWeek;//
      this.isToday = isToday;
      this.reloadCalendar = reloadCalendar;
      this.newHref = newHref;
      this.formata_data = formata_data;
      this.is_comic = is_comic;
      this.getNextYear = getNextYear;
      this.getPreviousYear = getPreviousYear;
      this.createCalendar = createCalendar;
      this.nameNavigator = nameNavigator;
  };

  function getNextDate() {
      var date = this.actualDate;
      var ndate = new Date();
      var month = date.getMonth();
      var year = date.getFullYear();
      ndate.setDate(1);

      if (month <= 10) {
          ndate.setYear(year);
          ndate.setMonth(++month);
      } 
      else {
          ndate.setYear(++year);
          ndate.setMonth(0);
      };
      this.actualDate = ndate;
      this.reloadCalendar();
  };

  function getPrevioustDate() {
      var date = this.actualDate;
      var ndate = new Date();
      var month = date.getMonth();
      var year = date.getFullYear();

      ndate.setDate(1);   
      if (month >= 1) {
          ndate.setYear(year);
          ndate.setMonth(--month);
      } else  {
          ndate.setYear(--year);
          ndate.setMonth(11);
      };
      this.actualDate = ndate;
      this.reloadCalendar();
  };

  function submitNewDate(month, year) {
      var form = document.forms[this.oForm];
      form.month.value = month;
      form.year.value = year;
      form.submit();
  };

  function getMonthDays(date) {
      var year = date.getFullYear();
      var month = date.getMonth();
      var novaData = new Date(year, month, 32).getDate();
      return 32 - novaData;
  };

  function firstDayWeek(date) {
      var tdate = new Date(date);
      tdate.setDate(1);
      return tdate.getDay();
  };

  function isToday(dia) {
      var dt = new Date()
      return ( dt.getDate() == dia && dt.getMonth() == this.actualDate.getMonth() && dt.getFullYear() == this.actualDate.getFullYear() );
  };

  function reloadCalendar() {
      var tbody = document.getElementById(this.oObj);
      while (tbody.firstChild)
          tbody.removeChild(tbody.firstChild);
      this.createCalendar();
  };
  
  function newHref(dia, mes, ano, link) {  
      var span = document.createElement('span');  
      mes != 0 ? mes--: mes
      if (link == true) {
         sDay = dia >= 10 ? dia : '0' + dia
         sMonth = mes + 1 >= 10 ? mes + 1 : '0' + (mes + 1)
         var url = urlEstatica + '/capa_calendario,year=' + ano + '&day=' + sDay + '&month=' + sMonth + '/capa_calendario.shtml?year=' + ano + '&day=' + sDay + '&month=' + sMonth 
         var href = document.createElement('a');
         href.setAttribute('href', url);
         href.appendChild(document.createTextNode(dia));
         span.appendChild(href);
      } else {
         span.innerHTML = dia;
      }
      return span.innerHTML;
  };

  function formata_data(d, m, a) {
     if(d < 10){ d = '0'+d; }
     if(m < 10){ m = '0'+m; }  
     r = 'd'+a+'_'+m+'_'+d;    
     return r;
  };

  function is_comic(dia, mes, ano) {
     data = this.formata_data(dia, mes, ano)
     if (oDatas[data] == undefined){ return false; }
     else { return true; }
  };

  function getNextYear() {
      var date = this.actualDate;
      var ndate = new Date();
      var month = date.getMonth();
      var year = date.getFullYear();
      ndate.setDate(1);
      ndate.setMonth(month);
      ndate.setYear(++year);
      this.actualDate = ndate;
      this.reloadCalendar();
  };

  function getPreviousYear() {
      var date = this.actualDate;
      var ndate = new Date();
      var month = date.getMonth();
      var year = date.getFullYear();
      ndate.setDate(1);
      ndate.setMonth(month);
      ndate.setYear(--year);
      this.actualDate = ndate;
      this.reloadCalendar();

  };

  function createCalendar() {
      var tbody = document.getElementById(this.oObj);
      var dt = new Date()
      if(dt.getFullYear() != this.actualDate.getFullYear()) {
          document.getElementById(this.nameMonth).innerHTML = this.allMonth[ this.actualDate.getMonth() ] + ' de ' + this.actualDate.getFullYear();
      } else {
          document.getElementById(this.nameMonth).innerHTML = this.allMonth[ this.actualDate.getMonth() ]
      }
      var dayWeek = parseInt(this.firstDayWeek(this.actualDate));
      var daysMonth = this.getMonthDays(this.actualDate);
      var loopDay = 1;
      var whatNavigator = nameNavigator();
  
      for (var i = 6; i > 0; --i) {
          //if (loopDay > daysMonth) break;
          var row = document.createElement("tr");
          for (var j = 0; j < 7; ++j) {
              var cell = document.createElement("td");
              var dayValue = "&nbsp;";
              if (this.isToday(loopDay)) {   
                 if (this.is_comic(loopDay, this.actualDate.getMonth()+1, this.actualDate.getFullYear())) {
                     cell.className = this.comicHojeDayClass;
                     is_link = true;
                     today = true;
                 } 
                 else { cell.className = this.actualDayClass; }                                 
              } 
              else if ((j == 0)||(j == 6)) 
                 cell.className = this.weekendDayClass;

              // muda a classe se tiver um cadastro no banco
              if((this.is_comic(loopDay, this.actualDate.getMonth()+1, this.actualDate.getFullYear()))&&(today == false)) {  
                 if ((j == 0)||(j == 6))
                     cell.className = this.comicFdsDayClass;    
                 else
           	     cell.className = this.comicDayClass; 
                 is_link = true; 
              } 
              if ( (loopDay > 1 && loopDay <= daysMonth) || (dayWeek == j && loopDay == 1)) {
                  link = this.is_comic(loopDay, this.actualDate.getMonth()+1, this.actualDate.getFullYear())
                  cell.innerHTML = this.newHref(loopDay++, this.actualDate.getMonth()+1, this.actualDate.getFullYear(), link);
              } else {
                  cell.innerHTML = "&nbsp;";
                  cell.className = this.emptyClass;                        
              }   
              is_link = false;
              today   = false;           

              row.appendChild(cell);
          };
          tbody.appendChild(row);
      };
  };

  function shiftDate() {
      var oDate = new Date()
      day = oDate.getDate()
      month = oDate.getMonth() + 1
      year = oDate.getFullYear()
  }
  
  function validateDate() {
      lMonths = new Array(31,28,31,30,31,30,31,31,30,31,30,31)
      try {
          day = parseInt(day) 
          month = parseInt(month) 
          year = parseInt(year)
      } catch(e) {
          shiftDate()
          return false
      }
      if (!(month > 0 && month < 13)) {
          shiftDate()
          return false
      }
      if (!(day > 0 && day <= lMonths[month-1])) {
          shiftDate()
          return false
      }
      if (year < 1) {
          shiftDate()
          return false
      }
  }
  
  function nameNavigator() {
      var nav = navigator.appName; 

      if( nav == "Microsoft Internet Explorer" ) { return(true); } 
      else { return(false);};
  };

  function getFromUrl(value)
  {
      var url = window.top.location.href;
      try {
          url = url.split('?')[1]
          if(!url) return -1
      } catch(e) {
          return -1
      }
      var key1 = url.indexOf(value);
      if(key1 != -1)
      {
          var key1 = key1 + value.length + 1;
          var key2 = url.indexOf('&', key1) - 1;
          if (key2 < 0){ key2 = url.length; };

          return url.substr( key1, key2 - key1 + 1);
      }
      else { return -1; };
  };

  /*]]>*/
