var getDaysInMonth = function(month,year) {
 return new Date(year, month, 0).getDate();
}
//t= new Date()
var eem = new Array()
eem[0]="paciente"
eem[1]="idpaciente"
eem[2]="comunapac"
eem[3]="prestacion"
eem[4]="profesional"

ddn=document.getElementById("d11")
rnn=document.getElementById("m1")
dda=ddn
rna=rnn
yy=2024
fillmes(rnn)
function fillmes(rnn)
{
        dda.style.color="#000000"
        dda.style.background="#e0e0f0"
	rna.style.color="#000000"
	rna.style.background="#e0e0f0"
	rnn.style.color="#ffff00"
	rnn.style.background="#0000f0"
	nn=rnn.id
	rna=rnn
	
	nn=nn.substr(1)
for (i=0;i<7;i++)
        document.getElementById("d6"+i).style.visibility= "visible"
	//document.getElementById("mes").innerHTML=rnn.selected.innerHTML
	fill(yy,nn)
}
function clearmes()
{
	for(i=1;i<7;i++) for(j=0;j<7;j++) 
        document.getElementById("d"+i+j).value=""
}

function fill(yy,nn)
{
clearmes()
const dn = getDaysInMonth(nn,yy)
//alert(yy+" " + nn+" "+dn)
d1 = new Date();
//alert("a"+d1 +" "+nn)
//alert("d"+nn+" "+d1)
z=1
dd=1
d1.setYear(yy);
d1.setMonth(nn-1);
while(dd<=dn)
{
d1.setDate(dd)
 let day = d1.getDay()
//alert(dd+ " " + z+day)
	document.getElementById("d"+z+day).value=dd++
	//alert(day +" z="+z)
	if(day==0) z++
}
 let day = d1.getDay()
//alert(z+" DAY=" + day)
if(z<6 || !day) for (i=0;i<7;i++)
        document.getElementById("d6"+i).style.visibility="hidden"
}
function agen(ddn)
{
	if(ddn.value!="")
	{
		dda.style.color="#000000"
		dda.style.background="#e0e0f0"
		ddn.style.color="#f0f000"
		ddn.style.background="#0000FF"
		dd=ddn.id
		dda=ddn
	}
	
	if(nn <10) nd="0"+nn
	else nd=nn
	zz=yy+nd+ddn.value

	count=iagend[zz]
	counta=count
	for(ar=0;ar<count;ar++)
	{
		rzz=zz+ar
		dc=agend[rzz]
		doc=dc.split("^")
		if(ar <10) ix="0"+ar
		else ix=ar
		pr=doc[0]+doc[5]
		pr1=pr.substr(0,7)
		eq1=eqp[pr1]
		eqq=eq1.substr(13)
		for (ind =0 ; ind<6; ind++)
		{
			if(ind <5)
			{
				txt=eem[ind]+ix
				rzz=zz+ind
				dc=agend[rzz]
				if(ar <10) ix="0"+ar
				else ix=ar
				elm=document.getElementById(txt)
				elm.value=doc[ind]
			}
			else
			{
				elm=document.getElementById(txt)
				elm.value=eqq
			}
		}
	}
function cleardoc(cll)
{
        for(ar=0;ar<cll;ar++) for (ind =0 ; ind<6; ind++)
	{
		if(ind <5)
		{
			txt=eem[ind]+ix
			rzz=zz+ind
			dc=agend[rzz]
			if(ar <10) ix="0"+ar
			else ix=ar
			elm=document.getElementById(txt)
			elm.value=doc[ind]
		}
		else
		{
			elm=document.getElementById(txt)
			elm.value=eqq
		}
	}
}


}

