init();
function openCalendarWindow(cwo) 
{
	var x = (screen.width - (wcal+9)) / 2
	var y = (screen.height - (hcal+40)) / 2
	calwin=this.open("","JanelaCalendar",cwo+"screenx="+x+",screeny="+y+",left="+x+",top="+y);
 	if (calwin!=null) {
 		calwin.focus();
 	}
	return calwin;
}
if (navigator.appName=='Microsoft Internet Explorer') {	this.browser='MSIE';} 
else {	this.browser='Netscape';}
this.versao=navigator.appVersion.substring(0,1);
this.servidor='';
function makeArray(n) 
{
	this.length = n;
	return this;
}
function init () 
{
	theDate       = new Date();
	today         = new Date();
	currMonth     = today.getMonth()+1;
	msPerDay      = 24*60*60*1000;
	monthName     = new makeArray(13);
	monthName[1]  = "Janeiro";
	monthName[2]  = "Fevereiro";
	monthName[3]  = "Mar&ccedil;o";
	monthName[4]  = "Abril";
	monthName[5]  = "Maio";
	monthName[6]  = "Junho";
	monthName[7]  = "Julho";
	monthName[8]  = "Agosto";
	monthName[9]  = "Setembro";
	monthName[10] = "Outubro";
	monthName[11] = "Novembro";
	monthName[12] = "Dezembro";
	
	wcal=162;
	hcal=190;
	fundoMes="#98A8E0"
	corfonteDias="Black"
	fundoDias="#1D368B"
	fundoNumeros="#FFFFFF"
	fundoAtual="#A4A49A"
}
function openCalendarWindow(cwo) 
{
	calwin=this.open("","JanelaCalendar",cwo);
	if (browser=="Netscape") 
	{
		if (calwin!=null) 
			calwin.focus();
	}
	return calwin;
}
function openCalendar (dataFldname,diaFldname,mesFldname) 
{
	datahoje= new Date()
	windowOptions  = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=yes,width="+wcal+",height="+hcal;
	calendarWindow = openCalendarWindow(windowOptions)
	if (dataFldname!=null) 
	{
		if ((dataFldname.value=="") || (dataFldname.value=="dd/mm/aaaa") || (dataFldname.value.indexOf("/")<1)) 
		{ 
			mes = datahoje.getMonth()+1;
			ano=datahoje.getFullYear();
			dia=0;
		} else 
		{
			posdia=dataFldname.value.indexOf("/")
			dia=eval(dataFldname.value.substring(0,posdia));
			posmes=dataFldname.value.indexOf("/",posdia+1)
			mes=eval(dataFldname.value.substring(posdia+1,posmes))
			ano=eval(dataFldname.value.substring(posmes+1,10))
			if (ano<1000) 
				ano += 2000
		}
	} 
	else 
	{
		dia=diaFldname.selectedIndex+1;
		mes=mesFldname.selectedIndex+1;
		ano=datahoje.getFullYear();
	}
	redraw(dia,mes,ano,dataFldname,diaFldname,mesFldname,window);
}
function redraw(dia,mes,ano,dataFld,diaFld,mesFld,pai) 
{
	calendarWindow.document.open();
	calTitle = "<TITLE>Calend&aacute;rio</TITLE>";
	calendarWindow.document.write(calTitle);
	calInit = "<sc";
	calInit+="ript language=\"javascript\"> ";
	calInit+="callingForm=null;dataFld=null;diaFld=null;mesFld=null;</scr";
	calInit+="ipt>";
	calendarWindow.document.write(calInit);
	htmlBuf=drawCalendar(dia,mes,ano);
	calendarWindow.document.write(htmlBuf);
	calendarWindow.document.close();
	if (dataFld!=null) 
	{
		calendarWindow.dataFld=dataFld;
	} else 
	{
		calendarWindow.diaFld=diaFld;
		calendarWindow.mesFld=mesFld;
	}
	calendarWindow.callingForm=pai;
	if (browser!='MSIE' && versao!='2') 
	{
		calendarWindow.focus();
	}
}
function fillDate(dia,mes,ano,dataFld,diaFld,mesFld) 
{
	var AnoYY
	if (dataFld!=null) 
	{
		AnoYY = ano%1000
		if (AnoYY<10)
			AnoYY = "0" + AnoYY
		if (dia<10)
			dia = "0" + dia
		if (mes<10)
			mes = "0" + mes			
		dataFld.value=dia+"/"+mes+"/"+ano
	} 
	else 
	{
		diaFld.selectedIndex=dia-1
		mesFld.selectedIndex=mes-1
	}
	calendarWindow.close();
}
function changeMonth (increment,mes,ano,dataFld,diaFld,mesFld,pai) 
{
	nextMonth = mes;
	if (increment == 1) 
	{
		nextMonth++ ;
	} else 
	{
		nextMonth-- ;
	}
	if (nextMonth > 12)   
	{
		nextMonth = 1;
		ano++;
	} 
	else
		if (nextMonth<1) 
		{
			nextMonth=12;
			ano--;
		}
	redraw(0,nextMonth,ano,dataFld,diaFld,mesFld,pai);
}
function drawCalendar (diaNum,mesNum,anoNum) 
{
	theDate = new Date(anoNum,mesNum-1,1);
	Dir = "/images/"
	htmlBuffer  = "<HTML>";
	htmlBuffer += "<head><style>.pacotes { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight: normal; color: #000000; text-decoration: none;}.branco4 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; color: #FFFFFF; text-decoration: none; TEXT-TRANSFORM: uppercase;}.pacote2 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold;color: #000000;text-decoration: none;}</style></head>";	
	htmlBuffer += "<BODY leftMargin=0 topMargin=0 marginheight=0 marginwidth=0>";
	htmlBuffer += "<FORM id=form1 name=form1>";
	//htmlBuffer += "<link rel='STYLESHEET' type='text/css' href='/css.css'>";
	htmlBuffer += "<center><table border=0 cellspacing=0 cellpadding=0 width="+wcal+" height="+hcal+" bgcolor=#98A8E0>";
	htmlBuffer += "<tr>";
	htmlBuffer += "<td align=center colspan=7 bgcolor="+fundoMes+"><table width=100%><tr width=100%><td width=10% align=left><a href=\"javascript:callingForm.changeMonth(-1,"+mesNum+","+anoNum+",dataFld,diaFld,mesFld,callingForm)\"><img src='' border=0></a></td>";
	htmlBuffer += "<td align=center width=121 height=13><font class=pacote2><b>";
	htmlBuffer += monthName[mesNum];
	htmlBuffer += " de " + anoNum;
	htmlBuffer += "</b></font></td>";
	htmlBuffer += "<td width=10% align=right><a href=\"javascript:callingForm.changeMonth(1,"+mesNum+","+anoNum+",dataFld,diaFld,mesFld,callingForm)\"><img src='' border=0></a></td></tr>";
	htmlBuffer += "</table><table border=0 cellspacing=0 cellpadding=0 width="+wcal+" height=100%><tr>";
	htmlBuffer = htmlBuffer+"<td align=center bgcolor="+fundoDias+" height=26><font class=branco4><b>D</b></font></td><td align=center bgcolor="+fundoDias+"><font class=branco4 color="+corfonteDias+"><b>S</b></font></td><td align=center bgcolor="+fundoDias+"><font class=branco4 color="+corfonteDias+"><b>T</b></font></td><td align=center bgcolor="+fundoDias+"><font class=branco4 color="+corfonteDias+"><b>Q</b></font></td><td align=center bgcolor="+fundoDias+"><font class=branco4 color="+corfonteDias+"><b>Q</b></font></td><td align=center bgcolor="+fundoDias+"><font class=branco4 color="+corfonteDias+"><b>S</b></font></td><td align=center bgcolor="+fundoDias+"><font class=branco4 color="+corfonteDias+"><b>S</b></font></td></tr>";
	drawBody(diaNum,theDate,anoNum);
	//htmlBuffer += "</tr></table></td></tr>";
	htmlBuffer += "</body></HTML>";
	return htmlBuffer;
}
function drawBody (dia,theDate,ano) 
{
	thisMonth = theDate.getMonth();
	thisDate  = theDate.getDate();
	firstSunday(theDate);
	
	today = new Date()
		
	for (w=0; w<7; w++) 
	{
		htmlBuffer   += "<tr>";
		for (d=0; d<7; d++) 
		{
			date = theDate.getDate();
			htmlBuffer   += "<td align=center ";
			if ((date==dia)&&(theDate.getMonth()== thisMonth)) 
			{
				htmlBuffer+=" bgcolor="+fundoAtual+"><font class=pacotes>";
			} 
			else 
			{
				htmlBuffer=htmlBuffer+" bgcolor="+fundoNumeros+"><font class=pacotes>";
			}
			// skip previous month
			if (theDate.getMonth() != thisMonth) 
			{
				htmlBuffer += "<BR>";
			} 
			else 
			{
				if( ano > today.getFullYear() || ( ano == today.getFullYear() && thisMonth > today.getMonth() ) || ( ano == today.getFullYear() && thisMonth == today.getMonth() && date >= today.getDate() ) )
				{
					htmlBuffer += "<a href=\"javascript:";
					htmlBuffer += "callingForm.fillDate(" + theDate.getDate() + "," + (theDate.getMonth()+1) + "," + ano  + ",dataFld,diaFld,mesFld)\" class=pacotes3>";
				}
				else
					htmlBuffer += "<font color=\"#A4A49A\">";
				
				if ( date < 10 ) 
				{
					htmlBuffer += "0";
				}
				htmlBuffer += date;
				
				if( ano > today.getFullYear() || ( ano == today.getFullYear() && thisMonth > today.getMonth() ) || ( ano == today.getFullYear() && thisMonth == today.getMonth() && date >= today.getDate() ) )
					htmlBuffer += "</a>";
				else
					htmlBuffer += "</font>";
					
			}
			htmlBuffer += "</font></td>";
			// increment the date
			newTime = theDate.getTime() + msPerDay;
			theDate.setTime(newTime);
			// check for DST 
			if (theDate.getHours() != 23) 
			{
				theDate.setTime(newTime + 3600000);
			} 
		}
		htmlBuffer += "</tr>";
	}
	htmlBuffer += "</table></center>";
	htmlBuffer += "</form>";
}
function firstSunday (fromDate) 
{
	while (fromDate.getDay() != 0) 
	{
		newTime = fromDate.getTime() - msPerDay;
		fromDate.setTime(newTime);
	}
}