﻿/*###########  Inicio calendario */

var months = new Array("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var days = new Array("DOM", "SEG", "TER", "QUA", "QUI", "SEX", "SAB");

today = new getToday();
var element_id;

function getDays(month, year) {
    // Teste para leap ano onde fevereiro é selecionado.
    if (1 == month)
        return ((0 == year % 4) && (0 != (year % 100))) ||
			(0 == year % 400) ? 29 : 28;
    else
        return daysInMonth[month];
}


function isEmail(iCampo, iNomeCampo) {
    var str = iCampo.value;
    //alert(str);
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
    if ((!r1.test(str) && r2.test(str))) {
        return true;
    } else {
        /* iCampo.focus(); iCampo.select(); */
        alert(iNomeCampo + " inválido.");
        return false;
    }
    return true;
}


function getToday() {
    // Generate today's date.
    this.now = new Date();
    this.year = this.now.getFullYear(); // Returned year XXXX
    this.month = this.now.getMonth();
    this.day = this.now.getDate();
}


function newCalendar() {
    var parseYear = parseInt(document.all.year[document.all.year.selectedIndex].text);

    var newCal = new Date(parseYear, document.all.month.selectedIndex, 1);
    var day = -1;
    var startDay = newCal.getDay();
    var daily = 0;

    today = new getToday(); // 1st call
    if ((today.year == newCal.getFullYear()) && (today.month == newCal.getMonth()))
        day = today.day;
    // Cache the calendar table's tBody section, dayList.
    var tableCal = document.all.calendar.tBodies.dayList;

    var intDaysInMonth =
	   getDays(newCal.getMonth(), newCal.getFullYear());

    for (var intWeek = 0; intWeek < tableCal.rows.length; intWeek++)
        for (var intDay = 0;
			 intDay < tableCal.rows[intWeek].cells.length;
			 intDay++) {
        var cell = tableCal.rows[intWeek].cells[intDay];

        // Start counting days.
        if ((intDay == startDay) && (0 == daily))
            daily = 1;

        // Highlight the current day.
        cell.style.color = (day == daily) ? "red" : "";
        if (day == daily) {
            document.all.todayday.innerText = "Hoje: " + day + "/" +
					(newCal.getMonth() + 1) + "/" + newCal.getFullYear();
        }
        // Output the day number into the cell.
        if ((daily > 0) && (daily <= intDaysInMonth))
            cell.innerText = daily++;
        else
            cell.innerText = "";
    }

}

function getTodayDay() {
    var dia = today.day;
    var mes = today.month + 1;
    if (dia.toString().length == 1) {
        dia = "0" + dia.toString();
    }
    else {
        dia = dia.toString();
    }

    if (mes.toString().length == 1) {
        mes = "0" + mes.toString();
    }
    else {
        mes = mes.toString();
    }

    document.all[element_id].value = dia + "/" + (mes) + "/" + today.year;   // O separador para data de hoje colocar dentro das aspas
    //document.all.calendar.style.visibility="hidden";
    document.all.calendar.style.display = "none";
    document.all.year.selectedIndex = 100;
    document.all.month.selectedIndex = today.month;
}


function getDate() {
    // This code executes when the user clicks on a day
    // in the calendar.
    if ("TD" == event.srcElement.tagName)
    // Testa se o dia é valido.
        if ("" != event.srcElement.innerText) {
        var mes;
        var dia = event.srcElement.innerText;
        var mn = document.all.month.selectedIndex + 1;
        var tamanho = mn.length;
        if (mn.toString().length == 1) {
            mes = "0" + mn.toString();
        }
        else {
            mes = mn.toString();
        }
        if (dia.length == 1) {
            dia = "0" + dia;
        }
        else {
            dia = dia;
        }

        var Year = document.all.year[document.all.year.selectedIndex].text;
        document.all[element_id].value = dia + "/" + mes + "/" + Year; // O separador para data de hoje colocar dentro das aspas
        //document.all.calendar.style.visibility="hidden";
        document.all.calendar.style.display = "none";
    }
}

function GetBodyOffsetX(el_name, shift) {
    var x;
    var y;
    x = 0;
    y = 0;

    var elem = document.all[el_name];
    do {
        x += elem.offsetLeft;
        y += elem.offsetTop;
        if (elem.tagName == "BODY")
            break;
        elem = elem.offsetParent;
    } while (1 > 0);

    shift[0] = x;
    shift[1] = y;
    return x;
}

function SetCalendarOnElement(el_name) {
    if (el_name == "")
        el_name = element_id;
    var shift = new Array(2);
    GetBodyOffsetX(el_name, shift);
    //document.all.calendar.style.pixelLeft = shift[0];   //- document.all.calendar.offsetLeft;
    //document.all.calendar.style.pixelTop = shift[1] + 25;
}



function ShowCalendar(elem_name) {
    if (elem_name == "")
        elem_name = element_id;

    element_id = elem_name; // element_id is global variable
    newCalendar();
    SetCalendarOnElement(element_id);
    //document.all.calendar.style.visibility = "visible";
    document.all.calendar.style.display = "inline";
}

function HideCalendar() {
    //document.all.calendar.style.visibility="hidden";
    document.all.calendar.style.display = "none";
}

function toggleCalendar(elem_name) {
    //if (document.all.calendar.style.visibility == "hidden")
    if (document.all.calendar.style.display == "none")
        ShowCalendar(elem_name);
    else
        HideCalendar();
}

/*##########   Fim calendario */

function display(esconde, aparece) {
    document.getElementById(esconde).style.display = "none";
    document.getElementById(aparece).style.display = "block";

}

function display2(esconde,esconde2,esconde3,esconde4,aparece) {
     document.getElementById(esconde).style.display = "none";
    document.getElementById(esconde2).style.display = "none";
    document.getElementById(esconde3).style.display = "none";
    document.getElementById(esconde4).style.display = "none";
     document.getElementById(aparece).style.display = "block";

 }
 function limpa(valor, idd, palavra) {
    if(document.getElementById(idd).value==palavra){
        document.getElementById(idd).value = "";
    }

}
function enche(valor, idd, palavra) {
    if (document.getElementById(idd).value == "") {
        document.getElementById(idd).value = palavra;
    }

}

function slideShow() {

    //Set the opacity of all images to 0
    $('#gallery a').css({ opacity: 0.0 });

    //Get the first image and display it (set it to full opacity)
    $('#gallery a:first').css({ opacity: 1.0 });

    //Set the caption background to semi-transparent
    $('#gallery .caption').css({ opacity: 0.7 });

    //Resize the width of the caption according to the image width
    $('#gallery .caption').css({ width: $('#gallery a').find('img').css('width') });

    //Get the caption of the first image from REL attribute and display it
    $('#gallery .content').html($('#gallery a:first').find('img').attr('rel'))
	.animate({ opacity: 0.7 }, 400);

    //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
    setInterval('gallery()', 6000);

}

function gallery() {

    //if no IMGs have the show class, grab the first image
    var current = ($('#gallery a.show') ? $('#gallery a.show') : $('#gallery a:first'));

    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('caption')) ? $('#gallery a:first') : current.next()) : $('#gallery a:first'));

    //Get next image caption
    var caption = next.find('img').attr('rel');

    //Set the fade in effect for the next image, show class has higher z-index
    next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 1000);

    //Hide the current image
    current.animate({ opacity: 0.0 }, 1000)
	.removeClass('show');

    //Set the opacity to 0 and height to 1px
    $('#gallery .caption').animate({ opacity: 0.0 }, { queue: false, duration: 0 }).animate({ height: '1px' }, { queue: true, duration: 300 });

    //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
    $('#gallery .caption').animate({ opacity: 0.7 }, 100).animate({ height: '100px' }, 500);

    //Display the content
    $('#gallery .content').html(caption);


}
