function dofw(date) {
  var dayOfWeek = new Date(date).getDay()
  return isNaN(dayOfWeek) ? null : ['Do','Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'][dayOfWeek]
}
function mon(date) {
  var mond = new Date(date).getMonth()
  return isNaN(mond) ? null : ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'][mond]
}
function calen(dd) {
var Row = document.getElementById("titrow");
var Cells = Row.getElementsByTagName("td");
		var ddd = dd.split("/")
		r=ddd[2]+"-"+ddd[1]+"-"+ddd[0]
		d=new Date(r)
		if (d=="Invalid Date") { alert( dd+": Fecha no válida") ; return}
		rd=0
		dd=tmrw(r)
		r=dd
	for (i=1;i<38;i++)
	{
		d=new Date(r)
		ld=d.getDate()
		mo=d.getMonth()
		ye=d.getFullYear()
		if(ld/1 <10) ld="0" + ld
		mo++
		if(mo/1 <10) mo="0" + mo
		wd=dofw(d)
		//alert(ld+ " " + wd)
		dd=tmrw(r)
		r=dd
		if (ld/1==1 || i==1) { color="#FFFF00";mes=mon(d) }
		else { color="#FFFFFF"; mes="" }
		if(i>1 && ld==ddd[0] )  { rd=i;color="#AAAAAA"; mes=mon(d);fren=ld+"/"+mo+"/"+ye }
		if(rd) color="#AAAAAA"
		Cells[i+4].innerHTML="<font size=\"2\" face=\"Tahoma\" color=\""+color+"\"><b>"+mes+"<br>"+wd+"<br>"+ld+"</b></font>"
		for(j=0;j<nrd;j++)
		{
			fld=nhd+nrd*ncd+j*(ncd+1)+3+i
			dd=document.pacieform.elements[fld]
//style="font-family: Arial; font-size: 8pt ;border:1px solid #7F9DB9;background-color:#FFFFFF"
//style="font-family: Arial; font-size: 8pt ;border:1px solid #7F9DB9;background-color:#E0E0E0"
			if(j%2)color="#E0E0E0"
			else color="#FFFFFF" 
			if(wd=="Sa" || wd=="Do") color="#F9A8E3"
			dd.style.background=color
		}
	}
	//alert(ld+" "+ddd[0]+" "+rd+" "+fren+" "+Cells[rd+4].innerHTML)
	return (fren) 
}
function tmrw(dd) {
var day = new Date(dd);
var nextDay = new Date(day);
nextDay.setDate(day.getDate()+1);
return nextDay
}
function sesion(idx) {
                for (j=1; j<7;j++)
                {
                        i=j-1
                        fld=nhd+nrd*ncd+i*(ncd+1)+1
                        r=document.pacieform.elements[fld]
                        r.value="0"+j
                                //fld=nhd+nrd*ncd+i*(ncd+1)+2
                                //r.value=sesio[idx+0+j]
                }
                sess(0)
                return 1
}
function sess(idx) {
                fld=nhd+nrd*ncd+idx*(ncd+1)+1
                z=document.pacieform.elements[fld+1].value
                if(z=="")
                {
                        r=document.pacieform.elements[fld+2]
                                r.value=""
                         return
                }
                for (j=idx; j<nrd;j++)
                {

                        fld=nhd+nrd*ncd+j*(ncd+1)+1
                        i=document.pacieform.elements[18].value
                        d=document.pacieform.elements[fld+1].value
                        x=document.pacieform.elements[fld].value
                        if(x!="") if(d=="") {document.pacieform.elements[fld+1].value=z;d=z}
                        //alert(i + " " + d + " " + x + " - " + sesio[i+d+x])
                        r=document.pacieform.elements[fld+2]
                                if(x!="") r.value=sesio[i+d+x]
                }
                return 1
}

function ooo()
{
		//alert("ST:"+i+":l="+r.length)
		for (j in obra) if(j.indexOf(i)>=0)
		{
		//alert(j+ "=" + i + "="+ j.indexOf(i))
			b=obra[j]
			a=b.split("|")
			var option = document.createElement("option")
			option.value=j
			option.text=a[0]
			r.add(option)
		}
}
