function popdate(obj,div,tam,ddd,obj2)
{
	
    if (ddd) 
    {
        day = ""
        mmonth = ""
        ano = ""
        c = 1
        char = ""
        for (s=0;s<parseInt(ddd.length);s++)
        {
            char = ddd.substr(s,1)
            if (char == "/") 
            {
                c++; 
                s++; 
                char = ddd.substr(s,1);
            }
            if (c==1) day    += char
            if (c==2) mmonth += char
            if (c==3) ano    += char
        }
        ddd = mmonth + "/" + day + "/" + ano
    }
  
    if(!ddd) {today = new Date()} else {today = new Date(ddd)}
    date_Form = eval (obj)
    if (date_Form.value == "") { date_Form = new Date()} else {date_Form = new Date(date_Form.value)}
  
    ano = today.getFullYear();
    mmonth = today.getMonth ();
    day = today.toString ().substr (8,2)
  
    umonth = new Array ("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro")
    days_Feb = (!(ano % 4) ? 29 : 28)
    days = new Array (31, days_Feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

    if ((mmonth < 0) || (mmonth > 11))  alert(mmonth)
    if ((mmonth - 1) == -1) {month_prior = 11; year_prior = ano - 1} else {month_prior = mmonth - 1; year_prior = ano}
    if ((mmonth + 1) == 12) {month_next  = 0;  year_next  = ano + 1} else {month_next  = mmonth + 1; year_next  = ano}
	var cls=cal_class;
	if(!cls)
		cls='';
    txt  = "<table class='"+cls+"' style='border:solid #FFFFFF; border-width:2' cellspacing='0' cellpadding='3' border='0' width='"+tam+"' height='"+tam*1.1 +"'>"
   
	txt += "<tr><td colspan='6' class='mes'>"
	for(i=0;i<mesesMostrar.length;i++)
	{
		txt += "<a class='mes' style=text-transform:capitalize' href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+mesesMostrar[i][0]+"')>"+mesesMostrar[i][1]+"</a>";
		if(i<mesesMostrar.length-1)
			txt += " | ";	
	}
	
	txt += "</td><td align='right'>";
	if(!naoFecha)
		txt += "<a href=javascript:force_close('pop1') class='mes' style='color:#FFFFFF' title='Fechar Calend&aacute;rio'><strong>X</strong></a>";
	txt += "</td></tr>";
    txt += "<tr bgcolor='#FFFFFF'><td width='14%' class='dia' align=center><b>Dom</b></td><td width='14%' class='dia' align=center><b>Seg</b></td><td width='14%' class='dia' align=center><b>Ter</b></td><td width='14%' class='dia' align=center><b>Qua</b></td><td width='14%' class='dia' align=center><b>Qui</b></td><td width='14%' class='dia' align=center><b>Sex<b></td><td width='14%' class='dia' align=center><b>Sab</b></td></tr>"
    today1 = new Date((mmonth+1).toString() +"/01/"+ano.toString());
    diainicio = today1.getDay () + 1;
    week = d = 1
    start = false;

    for (n=1;n<= 42;n++) 
    {
        if (week == 1)  txt += "<tr align=center>"
        if (week==diainicio) {start = true}
        if (d > days[mmonth]) {start=false}
        if (start) 
        {
            dat = new Date((mmonth+1).toString() + "/" + d + "/" + ano.toString())
            day_dat   = dat.toString().substr(0,10)
            day_today  = date_Form.toString().substr(0,10)
            year_dat  = dat.getFullYear ()
            year_today = date_Form.getFullYear ()          
			colorcell='';
			var dReal = d;
			if(d<10) 
			{
				d="0"+d;
			}
			omes="";
			omes=(mmonth+1).toString();			
			var hoje=false;
			var marcar=false;			
			if(dReal+"/"+omes+"/"+ano.toString() == dataAtualCalendario)
			{
				hoje=true;
				marcar=true;
			}
			else
			{				
				for(i=0;i<datasMarcarCalendario.length;i++)
				{
					if(datasMarcarCalendario[i]==(dReal+"/"+omes+"/"+ano.toString()+"*"))
					{
						marcar=true;
						break;
					}
				}
			}	
			if(marcar)
			{
				if(hoje)
					hoje="class='hoje'";
				else
					hoje="";
				txt += "<td "+hoje+" align=center><a style='text-decoration:underline' href=javascript:block('"+  d + "/" + omes + "/" + ano.toString() +"','"+ obj +"','" + div +"') class='data'><b>"+ d.toString() + "</b></a></td>";
			}
			else
			{
				txt += "<td align=center><span class='data'>"+ d.toString() + "</span></td>";
			}            
            d ++ 
        } 
        else 
        { 
            txt += "<td class='data' align=center> </td>"
        }
        week ++
        if (week == 8) 
        { 
            week = 1; txt += "</tr>"} 
        }
        txt += "</table>"
        div2 = eval (div)
        div2.innerHTML = txt 
}
  
// função para exibir a janela com os meses
function pop_month(obj, div, tam, ano)
{
  txt  = "<table bgcolor='#F5FAFC' border='0' width=80>"
  for (n = 0; n < 12; n++) { txt += "<tr><td align=center><a style='color:#000000;font-size:11px' href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+("01/" + (n+1).toString() + "/" + ano.toString())+"')>" + umonth[n] +"</a></td></tr>" }
  txt += "</table>"
  popd.innerHTML = txt
}

// função para exibir a janela com os anos
function pop_year(obj, div, tam, umonth)
{
  txt  = "<table bgcolor='#F5FAFC' border='0' width=160>"
  l = 1
  for (n=1991; n<2012; n++)
  {  if (l == 1) txt += "<tr>"
     txt += "<td align=center><a style='color:#000000;font-size:11px' href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+(umonth.toString () +"/01/" + n) +"')>" + n + "</a></td>"
     l++
     if (l == 4) 
        {txt += "</tr>"; l = 1 } 
  }
  txt += "</tr></table>"
  popd.innerHTML = txt 
}

// função para fechar o calendário
function force_close(div) 
    { div2 = eval (div); div2.innerHTML = ''}
    
// função para fechar o calendário e setar a data no campo de data associado
function block(data, obj, div)
{     
	force_close (div)
    obj2 = eval(obj)
    obj2.value = data 
	try{
		obj2.focus();
	}
	catch(eig)
	{}
	if(obj2.getAttribute('AutoPostBack')=='1')
		obj2.form.submit();
	else
	{
		try{
			onchangeData(data);
		}
		catch(eig)
		{}
	}
}

function tdata(data)
{	
	var d=data.split('/')[0];
	var m=new Number(data.split('/')[1]);
	if(m==1) 	  m='Jan';
	else if(m==2) m='Fev';
	else if(m==3) m='Mar';
	else if(m==4) m='Abr';
	else if(m==5) m='Mai';
	else if(m==6) m='Jun';
	else if(m==7) m='Jul';
	else if(m==8) m='Ago';
	else if(m==9) m='Set';
	else if(m==10) m='Out';
	else if(m==11) m='Nov';
	else if(m==12) m='Dez';
	return d+m;
}