function resizeFrame()
{
	document.getElementById("calendario").style.height=(frames["calendario"].document.body.offsetHeight/10).toString() +"em";
}

function buildCal(m, y)
{
var dim=[31,0,31,30,31,30,31,31,30,31,30,31];
var oD = new Date(y, m-1, 1);
oD.od=oD.getDay()+1; 
var todaydate=new Date();
var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0 ; // dia atual
var d_cal ="";
var ls_eventos="";
var html="";

dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28; // correções de fim de mês e ano bisexto

var t='<div><table cols="7" cellspacing="0" class="calendario"><tr align="center" class="sem">';
t+='<td>D</td><td>S</td><td>T</td><td>Q</td><td>Q</td><td>S</td><td>S</td></tr><tr align="center">';
t+='</tr><tr align="center">';

for(i=1;i<=42;i++)
	{
	var x = i-oD.od+1
	d_cal=y.toString();
	d_cal+=(m.toString().length==1)?"0"+m.toString():m.toString();
	d_cal+=(x.toString().length==1)?"0"+x.toString():x.toString();
	
	//if(x==scanfortoday) t+='<td id="today">'+x+'</td>';
	if (eventos_data[d_cal])
	{
		t+='<td class="evento">'+x+'</td>';
		ls_eventos+="<li><h3>"+x+"</h3>"+eventos_data[d_cal]+"</li>";
	}
	else if((i-oD.od>=0)&&(i-oD.od<dim[m-1])) t+='<td>'+x+'</td>';
	else t+='<td>&nbsp;</td>';

	if(((i)%7==0)&&(i<36)) t+='</tr>';
	}
t+='</table></div>';
ls_eventos=(ls_eventos!="")?"<ul class=\"eventos\">"+ls_eventos+"</ul>":"";
t=t.replace(/<tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr>/g,"");//remove linhas em branco
html=t+ls_eventos;
return html;
}

function showCal(m,y)
{
	obj=document.getElementById("cal-insercao");
	obj.innerHTML=buildCal(m,y);
}

function selMonth(m)
{
	s=document.getElementById("cal-meses").getElementsByTagName("option");
	for(var i=0;i<s.length;i++)
	{
		if(parseInt(s[i].value)==parseInt(m))
		{
			s[i].selected=true;
		}
	}
}

function loadCal()
{
	cal_year=today_date.substring(0,4);
  
  cal_month=today_date.substring(4,6);
	showCal(cal_month,cal_year);
	selMonth(cal_month);
}


function changeMonth(m)
{
	cal_month=parseInt(m);
	showCal(cal_month,cal_year);
}

function loadIr()
{
	loadCal();
	calcQuest();
}

function mostra(divId) {
	var h=0;
	for(i=1;i<totalquest;i++){
		if(document.getElementById("abre"+i).style.display != "none"){
		}
		document.getElementById("abre"+i).style.display = "none";
		document.getElementById("img"+i).src = "http://n.i.uol.com.br/economia/eco_ico_irv.gif";
	}
	if(isNaN(divId)==false) {
		document.getElementById("abre"+divId).style.display = 'block';
		document.getElementById("img"+divId).src = "http://n.i.uol.com.br/economia/eco_ico_irh.gif";
	}
	document.getElementById("col-centro").style.height=(document.getElementById("materia").offsetHeight/10).toString()+"em";
	setHeight('corpo','col-esquerda','col-centro','col-direita');

}

function calcQuest()
{
	totalquest=0;
	sp=document.getElementById("materia").getElementsByTagName("span");
	for(var i=0;i<sp.length;i++)
	{
		if(sp[i].className=="dicTxt")
		{
			totalquest++;
		}
	}
	totalquest++;
}
