//Data em JavaScript - Aquarista Junior

function longMonthArray() {
        this[0] = "Janeiro";    this[1] = "Fevereiro";  this[2] = "Março";
        this[3] = "Abril";      this[4] = "Maio";        this[5] = "Junho";
        this[6] = "Julho";       this[7] = "Agosto";     this[8] = "Setembro";
        this[9] = "Outubro";    this[10] = "Novembro";  this[11] = "Dezembro";
        return (this);
}

function shortMonthArray() {
        this[0] = "Jan";        this[1] = "Fev";        this[2] = "Mar";
        this[3] = "Abr";        this[4] = "Mai";        this[5] = "Jun";
        this[6] = "Jul";        this[7] = "Ago";        this[8] = "Set";
        this[9] = "Out";        this[10] = "Nov";       this[11] = "Dez";
        return (this);
}

function longDayArray() {
        this[0] = "Domingo,";     this[1] = "Segunda Feira,";     this[2] = "Terça Feira,";
        this[3] = "Quarta Feira,";  this[4] = "Quinta Feira,";   this[5] = "Sexta Feira,";
        this[6] = "Sábado,";
        return (this);
}

function shortDayArray() {
        this[0] = "Dom"; this[1] = "Seg"; this[2] = "Ter"; this[3] = "Qua";
        this[4] = "Qui"; this[5] = "Sex"; this[6] = "Sab";
        return (this);
}

function getShortYear(year)
{
shortyear =  year%100;
     if (shortyear < 10) shortyear = "0"+shortyear;
        return shortyear
}

function getLongYear(year)
{
  if (year > 1900) return year
  return year+1900;
}

function writeDateLong(format)
{
   shortDays = new shortDayArray();
   longDays = new longDayArray();
   shortMonths = new shortMonthArray();
   longMonths = new longMonthArray();
   d = new Date();
   day = d.getDate();
   month = d.getMonth();
        year = d.getYear();
   if (format == 0)
     str = shortDays[d.getDay()] + " " + shortMonths[month] +". " + day + ", "+getLongYear(year);
  else if (format == 1)
     str = shortDays[d.getDay()] + " " + longMonths[month] + " " + day + ", "+getLongYear(year);
  else if (format == 2)
     str = longDays[d.getDay()] + "de" + longMonths[month] + "de" + day + ", "+getLongYear(year);
  else if (format == 3)
     str = longMonths[month] + " " + day + ", "+getLongYear(year);
   else if (format == 4)
     str = shortDays[d.getDay()] + " " + day + " " + shortMonths[month] +". " +getLongYear(year);
  else if (format == 5)
     str = shortDays[d.getDay()] + " " + day + " " + longMonths[month] + " " +getLongYear(year);
  else if (format == 6)
     str = longDays[d.getDay()] + " " + day + " de " + longMonths[month] + " de " + getLongYear(year);
  else if (format == 7)
     str = day + " " + longMonths[month] + ", "+getLongYear(year);
  else {
     month++;
     shortyear = getShortYear(year);
     if (format == 8)
       str = month + "/" + day + "/" + shortyear;
     else if (format == 9)
       str = month + "/" + day + "/" + getLongYear(year);
     else if (format == 10)
       str = day + "/" + month + "/" + shortyear;
     else if (format == 11)
       str = day + "/" + month + "/" + getLongYear(year);
     else if (format == 12)
       str = shortyear + "/" + month + "/" + day;
     else if (format == 13)
       str = shortyear + "/" + month + "/" + day;
     else {
        if (day < 10) day = "0"+day
        if (month < 10) month = "0"+month
        if (format == 14)
          str = month + "/" + day + "/" + shortyear;
        else if (format == 15)
          str = month + "/" + day + "/" + getLongYear(year);
        else if (format == 16)
          str = day + "/" + month + "/" + shortyear;
        else if (format == 17)
          str = day + "/" + month + "/" + getLongYear(year);
        else if (format == 18)
          str = shortyear + "/" + month + "/" + day;
        else if (format == 19)
          str = shortyear + "/" + month + "/" + day;
        }
     }
  document.writeln(str);
}

function writeDate()
{
   writeDateLong(0);
}

function writeTimeLong(format)
{
   d = new Date();
   hour=d.getHours();
   min=d.getMinutes();
   sec=d.getSeconds();
   if (hour < 10) hour = "0"+hour;
   if (min < 10) min = "0"+min;
   if (sec < 10) sec = "0"+sec;
   
   if (format == 0)
      str = hour+":"+min+":"+sec;
   else if (format == 1)
      str = hour+":"+min;
   
   document.writeln(str);
}

function writeTime()
{
   writeTimeLong(0);
}