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)
		alert(dd)
		if (d=="Invalid Date") return
		dd=tmrw(r)
		r=dd
	for (i=1;i<31;i++)
	{
		d=new Date(r)
		ld=d.getDate()
		if(ld/1 <10) ld="0" + ld
		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="" }
		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.paci1form.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
		}
	}
}
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.paci1form.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.paci1form.elements[fld+1].value
		if(z=="")
		{
			r=document.paci1form.elements[fld+2]
				r.value=""
			 return
		}
		for (j=idx; j<nrd;j++)
		{
		
			fld=nhd+nrd*ncd+j*(ncd+1)+1
			i=document.paci1form.elements[18].value
			d=document.paci1form.elements[fld+1].value
			x=document.paci1form.elements[fld].value
			if(x!="") if(d=="") {document.paci1form.elements[fld+1].value=z;d=z}
			//alert(i + " " + d + " " + x + " - " + sesio[i+d+x])
			r=document.paci1form.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)
		}
}
