/* Calendario */

function Calendar(psID, piDay, piMonth, piYear) {
	this.browseTo = function(piMonth, piYear) {
		if (this.piMinMonth > piMonth - 1 && this.piMinYear >= piYear) {
			piNewMonth = this.piMinMonth;
			piNewYear = this.piMinYear;
		} else if (this.piMaxMonth < piMonth - 1 && this.piMaxYear <= piYear) {
			piNewMonth = this.piMaxMonth + 1;
			piNewYear = this.piMaxYear;
		} else {
			piNewMonth = piMonth;
			piNewYear = piYear;
		}
	
		this.piDay = 1;
		if (piNewMonth>12) {
			this.piMonth = 0;
			this.piYear = piNewYear + 1;
		} else if (piNewMonth<1) {
			this.piMonth = 11;
			this.piYear = piNewYear - 1;
		} else {
			this.piMonth = piNewMonth - 1;
			this.piYear = piNewYear;
		}

		this.write();
	};
	this.setMinDate = function(piDay, piMonth, piYear) {
		this.piMinDay = piDay;
		this.piMinMonth = piMonth - 1;
		this.piMinYear = piYear;
		this.write();
	}
	this.setMaxDate = function(piDay, piMonth, piYear) {
		this.piMaxDay = piDay;
		this.piMaxMonth = piMonth - 1;
		this.piMaxYear = piYear;
		this.write();
	}
	this.setToday = function(piDay, piMonth, piYear) {
		this.piNowDay = piDay;
		this.piNowMonth = piMonth - 1;
		this.piNowYear = piYear;	
	}
	this.selectDate = function(piMonth, piYear, piDay) {
		this.piDay = piDay;
		this.piMonth = piMonth;
		this.piYear = piYear;
		this.write();
	};
	this.clickDate = function(piMonth, piYear, piDay) {
		this.selectDate(piMonth, piYear, piDay);
		calendarAction(piDay, piMonth+1, piYear);
	}
	this.write = function() {
		//html inicial
		sStart = "<table width=\"190\" height=\"156\"  border=\"0\" cellpadding=\"0\" cellspacing=\"1\" class=\"Calendario\">";
		
		//html final
		sEnd = "</table>";

		//string do ano
		sYear = ""; 
		sYear += "<tr><td height=\"23\" class=\"Cal-Bold Cal-Fundo1\" align=\"center\"><table width=\"184\" align=\"center\" cellpadding=\"0\"  cellspacing=\"0\"><tr>";
		sYear += "<td width=\"10\"><div align=\"left\">";
//		LINK PARA DIMINUIR ANO
		if (this.piYear > this.piMinYear) {
			sYear += "<a href=\"javascript:void(" + this.id + ".browseTo(" + (this.piMonth+1+1) + ", " + (this.piYear-1) + "))\"><img src=\"../img/calendario/Seta_Esq_A.gif\" width=\"13\" height=\"12\" border=\"0\"></a>";
		} else if (!this.piMinYear) {
			sYear += "<a href=\"javascript:void(" + this.id + ".browseTo(" + (this.piMonth+1+1) + ", " + (this.piYear-1) + "))\"><img src=\"../img/calendario/Seta_Esq_A.gif\" width=\"13\" height=\"12\" border=\"0\"></a>";
		}
		sYear += "</div></td>";
		sYear += "<td width=\"161\"><div align=\"center\">" + this.piYear + "</div></td>";
		sYear += "<td width=\"11\"><div align=\"right\">";
//		LINK PARA AUMENTAR ANO
		if (this.piYear < this.piMaxYear) {
			sYear += "<a href=\"javascript:void(" + this.id + ".browseTo(" + (this.piMonth+1+1) + ", " + (this.piYear+1) + "))\"><img src=\"../img/calendario/Seta_Dir_A.gif\" width=\"13\" height=\"12\" border=\"0\"></a>";
		} else if (!this.piMaxYear) {
			sYear += "<a href=\"javascript:void(" + this.id + ".browseTo(" + (this.piMonth+1+1) + ", " + (this.piYear+1) + "))\"><img src=\"../img/calendario/Seta_Dir_A.gif\" width=\"13\" height=\"12\" border=\"0\"></a>";
		}
		sYear += "</div></td>";
		sYear += "</tr></table></td></tr>";
		
		//string do mes
		sMonth = "";
		sMonth += "<tr><td height=\"18\" class=\"Cal-Bold Cal-Fundo2\" align=\"center\"><table width=\"184\" align=\"center\" cellpadding=\"0\"  cellspacing=\"0\"><tr>";
		sMonth += "<td width=\"10\"><div align=\"left\">";
//		LINK PARA DIMINUIR MES
		if ((this.piYear == this.piMinYear && this.piMonth > this.piMinMonth) || (this.piYear > this.piMinYear)) {
			sMonth += "<a href=\"javascript:void(" + this.id + ".browseTo(" + (this.piMonth+1-1) + ", " + (this.piYear) + "))\"><img src=\"../img/calendario/Seta_Esq.gif\" width=\"13\" height=\"12\" border=\"0\"></a>";
		} else if (!this.piMinMonth && !this.piMinYear) {
			sMonth += "<a href=\"javascript:void(" + this.id + ".browseTo(" + (this.piMonth+1-1) + ", " + (this.piYear) + "))\"><img src=\"../img/calendario/Seta_Esq.gif\" width=\"13\" height=\"12\" border=\"0\"></a>";
		}
		sMonth += "</div></td>";
		sMonth += "<td width=\"161\"><div align=\"center\">" + this.monthLabels[this.piMonth] + "</div></td>";
		sMonth += "<td width=\"11\"><div align=\"right\">";
//		LINK PARA AUMENTAR MES
		if ((this.piYear == this.piMaxYear && this.piMonth < this.piMaxMonth) || (this.piYear < this.piMaxYear)) {
			sMonth += "<a href=\"javascript:void(" + this.id + ".browseTo(" + (this.piMonth+1+1) + ", " + (this.piYear) + "))\"><img src=\"../img/calendario/Seta_Dir.gif\" width=\"13\" height=\"12\" border=\"0\"></a>";
		} else if (!this.piMaxMonth && !this.piMaxYear) {
			sMonth += "<a href=\"javascript:void(" + this.id + ".browseTo(" + (this.piMonth+1+1) + ", " + (this.piYear) + "))\"><img src=\"../img/calendario/Seta_Dir.gif\" width=\"13\" height=\"12\" border=\"0\"></a>";
		}
		sMonth += "</div></td>";
		sMonth += "</tr></table></td></tr>";

		//string dos dias da semana
		sWeekDay = "";
		sWeekDay += "<tr><td class=\"Cal-Fundo3\" align=\"center\"><table width=\"184\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">";
		sWeekDay += "<tr>";
		sWeekDay += "</tr>";
	
		//string dos dias
		sWeek = "";
		sWeek += "<tr>";
		for (liDay = 0; liDay < 7; liDay ++) sWeek += "<td height=\"15\"><div align=\"center\">#" + liDay + "</div></td>";
		sWeek += "</tr>";
		
		//string hoje
		sToday = "";
		if (this.piNowDay && this.piNowMonth && this.piNowYear) {
			sToday += "</table></td></tr>";
//			sToday += "<tr><td height=\"20\" class=\"Cal-Fundo1\"><table width=\"100%\" cellpadding=\"3\"  cellspacing=\"0\">";
//			sToday += "<tr><td><div style=\"cursor: pointer; text-align:left; padding-left:5px;\"><img src=\"../img/calendario/Fechar.gif\" width=\"50\" height=\"11\" border=\"0\" onclick=\"document.getElementById(\'calendario'\).style.display = \'none'\;\"></div></td>";
//            sToday += "<td><div style=\"cursor: pointer; text-align:right; padding-right:5px;\"><img src=\"../img/calendario/Hoje.gif\" width=\"38\" height=\"11\" border=\"0\" onclick=\"" + this.id + ".clickDate(" + this.piNowMonth + "," + this.piNowYear + "," + this.piNowDay + ")\"></div></td></tr>";
//			sToday += "</table></td></tr>";	
		}
		
		iCount = 0;
		iDayCount = 1;
		bStarted = false;
		bMonthProblem = false;
		
		sThisMonth = "";
		for (iWeek = 0; iWeek < 6; iWeek++) {
			sThisWeek = sWeek;	
			for (iWeekDay = 0; iWeekDay < 7; iWeekDay++) {
				dTestDate = new Date(this.piYear, this.piMonth, iDayCount);
				if (dTestDate.getDate() == iDayCount && dTestDate.getDay() == iWeekDay || bStarted) {
					if ((dTestDate.getMonth() == this.piMonth || bMonthProblem) && iDayCount <32) {
						iCount++;
						bStarted = true;
						bMonthProblem = false;
						if ((this.piMinDay > iDayCount && this.piMinMonth >= this.piMonth && this.piMinYear >= this.piYear) || (this.piMaxDay < iDayCount && this.piMaxMonth <= this.piMonth && this.piMaxYear <= this.piYear)) {
							sThisWeek = sThisWeek.replace("#" + iWeekDay, "<font color=\"#CCCCCC\">" + iDayCount + "</font>");
						//} else if (this.piSelectedDay == iDayCount && this.piSelectedMonth == this.piMonth && this.piSelectedYear == this.piYear) {
						//	sThisWeek = sThisWeek.replace("#" + iWeekDay, "<a href=\"javascript:void(" + this.id + ".clickDate(" + this.piMonth + ", " + this.piYear + ", " + iDayCount + "))\" class=\"Cal-Dias\"><b><font color=\"#CC3333\">" + iDayCount + "</font></b></a>");
						} else {
							var mesCE = this.piMonth;	
							sThisWeek = sThisWeek.replace("#" + iWeekDay, "<a href=\"javascript:location.href='cursos_eventos.php?dia="+iDayCount+"&mes="+(mesCE+1)+"&ano="+this.piYear+"'\" class=\"Cal-Dias\">" + iDayCount + "</a>");
						}
					} else {
						sThisWeek = sThisWeek.replace("#" + iWeekDay, " ");		
					}
					iDayCount++;
				} else {
					sThisWeek = sThisWeek.replace("#" + iWeekDay, " ");
				}
			}
			sThisMonth += sThisWeek;
			
			if (iWeek == 5 && iCount == 0) {
				iWeek = 0;
				iWeekDay = 0;
				bStarted = true;
				bMonthProblem = true;
				sThisMonth = "";
			}
		}
		
		sHTML = sStart + sYear + sMonth + sWeekDay + sThisMonth + sToday + sEnd;

		Div = document.getElementById ? document.getElementById("Calendar_" + this.id) : document.all("Calendar_" + this.id);
		Div.innerHTML = sHTML;
	};
	
	this.id = psID;
	document.write("<div id=\"Calendar_" + this.id + "\"></div>");
	
	this.dayLabels = ['D','S','T','Q','Q','S','S'];

	this.monthLabels = ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'];
	
	this.piDay = piDay;
	this.piMonth = piMonth - 1;
	this.piYear = piYear;
	
	this.piSelectedDay = piDay;
	this.piSelectedMonth = piMonth - 1;
	this.piSelectedYear = piYear;
	
	this.piMinDay;
	this.piMinMonth;
	this.piMinYear;
	
	this.piMaxDay;
	this.piMaxMonth;
	this.piMaxYear;
	
	this.piNowDay;
	this.piNowMonth;
	this.piNowYear;
}

function calendarAction(piDay, piMonth, piYear) {
	//colocar o comando de data selecionada aqui
	if(piDay > 9) {
		if( piMonth > 9) objetoData.value = piDay + '/' + piMonth + '/' + piYear
		else objetoData.value = piDay + '/0' + piMonth + '/' + piYear
	} else {
		if( piMonth > 9) objetoData.value = '0' + piDay + '/' + piMonth + '/' + piYear
		else objetoData.value = '0' + piDay + '/0' + piMonth + '/' + piYear
	}

	document.getElementById('calendario').style.display = "none";
}
function checaContato(){
	var obj = document.cadastro;
	if(obj.nmCadastro.value == "") {
		alert('Preencha o campo Nome');
		obj.nmCadastro.focus();
	}
	else if(obj.emailCadastro.value == "") {
		alert('Preencha o campo Email');
		obj.emailCadastro.focus();
	}
	else if(obj.emailCadastro.value.indexOf('@') < 1 ){
		alert('Email incorreto!');
		obj.emailCadastro.focus();
	}
	else if(obj.senhaCadastro.value == "") {
		alert('Preencha o campo Senha');
		obj.senhaCadastro.focus();
	}
	else if(obj.repetirSenha.value == "") {
		alert('Repita a senha!');
		obj.repetirSenha.focus();
	}
	else if(obj.repetirSenha.value != obj.senhaCadastro.value) {
		alert('Você informou duas senhas diferentes!');
		obj.repetirSenha.focus();
	}
	else if(obj.dddCadastro.value == ""){
		alert('Informe o DDD');
		obj.dddCadastro.focus();
	}
	else if(obj.telCadastro.value == ""){
		alert('Informe o Telefone!');
		obj.telCadastro.focus();
	}
	else if(obj.endCadastro.value == ""){
		alert('Preencha o campo Endereço!');
		obj.endCadastro.focus();
	}
	else if(obj.numCadastro.value == ""){
		alert('Informe o Número')		
		obj.numCadastro.focus();
	}
	else if(obj.bairroCadastro.value == ""){
		alert('Informe o Bairro!');
		obj.bairroCadastro.focus();
	}
	else if(obj.cepCadastro.value == ""){
		alert('Informe o CEP!');
		obj.cepCadastro.focus();
	}
	else if(obj.cidCadastro.value == ""){
		alert('Informe a Cidade!');
		obj.cidCadastro.focus();
	}
	else if(obj.paisCadastro.value == ""){
		alert('Informe o País!');
		obj.paisCadastro.focus();
	}
	else if(obj.profCadastro.value == ""){
		alert('Informe a Profissão!');
		obj.profCadastro.focus();
	}else{
		obj.submit();
		}
}
function checaFaleconosco(){
	var obj = document.faleconosco;
	if(obj.nome.value == "") {
		alert('Preencha o campo Nome');
		obj.nome.focus();
	}
	else if(obj.email.value == "") {
		alert('Preencha o campo Email');
		obj.email.focus();
	}
	else if(obj.email.value.indexOf('@') < 1 ){
		alert('Email incorreto!');
		obj.email.focus();
	}
	else if(obj.ddd.value == ""){
		alert('Informe o DDD');
		obj.ddd.focus();
	}
	else if(obj.telefone.value == ""){
		alert('Informe o Telefone!');
		obj.telefone.focus();
	}
	else if(obj.mensagem.value == ""){
		alert('Preencha o campo Mensagem!');
		obj.mensagem.focus();
	}else{
		obj.submit();
		}
}

function zerar(campo, texto){
	if (campo.value==texto){
		campo.value="";
	}
}
function campoVazio(campo, texto){
	if (campo.value==""){
		campo.value=texto;
	}
}

function checaNewsletter(){
	var obj = document.newsletter;
	if(obj.nome.value == "Nome") {
		alert('Preencha o campo Nome');
		obj.nome.focus();
	}
	else if(obj.email.value == "E-mail") {
		alert('Preencha o campo Email');
		obj.email.focus();
	}
	else if(obj.email.value.indexOf('@') < 1 ){
		alert('Email incorreto!');
		obj.email.focus();
	}else{
		obj.submit();
		}
}
function checaProfArtesao(){
	var obj = document.profartesao;
	if(obj.email.value == "E-mail") {
		alert('Preencha o campo Email');
		obj.email.focus();
	}
	else if(obj.email.value.indexOf('@') < 1 ){
		alert('Email incorreto!');
		obj.email.focus();
	}
	else if(obj.senha.value == "*****") {
		alert('Preencha o campo Senha');
		obj.senha.focus();
	}else{
		obj.submit();
		}
}


function promocoes(){
	self.location.href="promocoes.php";
}