<!--
//Look and feel is determined by the "DOTcalhead" "DOTcaldays" stylesheets, which
//are applied to all header cells and normal cells. However, only DOTcalhead should
//have a background colour. The main background is determined by the attributes
//on the div or layer. The lack of a styled background on the normal cells is
//necessary for the rollover background changes to work. These rollover colours
//are specified by the variables below. You must also specify today's text colour.
var BGTABLE = "#FF9458"; //background colour for the table
var UNBG = "#ffffff"; //background colour for normal cells
var SELECTBG = "#FFC593"; //"#fff0b4"; //background colour for selected cells
var TODAYFONT = "red";//"#ff0000"; //font colour for today

//some variables
var MONTHS = new Array ("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
var DAYS = new Array ("Do", "Lu", "Ma", "Mi", "Ju", "Vi", "Sa");
var DAYFIRST = false; //whether the day should come first or the month
var SELECTDAY=100, LASTDAY=30; //two global variables which are used later

//what to do when something is clicked, this should be overridden
function returndate (whichone, timems, daysshown, extras, wherefrom) {
  //it takes as arguments the calendar which was clicked, the time chosen,
  //the number of days being shown, any extra HTML appended to links, and
  //where it was called from (clicking on a day, month, or year)
}

//make the specified calendar visible
function showcalendar (whichone, initialdate, daysshown, thex, they, extras) {
  setcalendar(whichone, 0, initialdate, daysshown, extras); 
  if (document.layers) {
	if (thex) {document.layers["calendar_" + whichone].left = thex;}
    if (they) {document.layers["calendar_" + whichone].top = they;}
	document.layers["calendar_" + whichone].hidden=false;
  }
  else if (document.getElementById) {document.getElementById("calendar_" + whichone).style.visibility = "visible";}
}

//hide the specified calendar
function hidecalendar (whichone) {
  if (document.layers) {document.layers["calendar_" + whichone].hidden=true;}
  else if (document.getElementById) {document.getElementById("calendar_" + whichone).style.visibility = "hidden";}
}

//fill the specified calendar with HTML
function setcalendar (whichone, monthoffset, initialdate, daysshown, extras) {
  var thetext = formcalendar (whichone, monthoffset, initialdate, daysshown, extras);
  if (document.layers) {var d=document.layers["calendar_" + whichone].document; d.open(); d.writeln (thetext); d.close();}
  else if (document.getElementById) {document.getElementById("calendar_" + whichone).innerHTML = thetext;}
  highlightdays (whichone, SELECTDAY, daysshown, LASTDAY);
}

//to account for Linux Netscape which says 2002 is 102
function makeyear (year) {return year < 500 ? (year + 1900) : year;} 
function props (o) {var r=""; for (var p in o) {r += p + ": " + o[p] + "\t";} alert (r);}
function initialdate (thedate) { //return either the current time right now or the input time
  var parts = thedate.split ("/");
  return parts.length == 3 ? new Date (parts[2], (DAYFIRST ? parts[1] : parts[0]) - 1, (DAYFIRST ? parts[0] : parts[1])).getTime() : 0;
}

//create the calendar for a certain month
function formcalendar (whichone, monthoffset, initialdate, daysshown, extras) {
  //start the function
  var todaydate = new Date(); //gets the day in the timezone of the user
  var startdate = initialdate ? new Date(initialdate) : new Date (); //initaldate can be any form of acceptable date
  initialdate = startdate.getTime(); //but it is only used by us in milliseconds
  var thedayselected = monthoffset == 0 ? startdate.getDate() : 100; //the date for the selected day, or an invalid one
  SELECTDAY = thedayselected;
  startdate.setMonth (startdate.getMonth() + monthoffset); //the startdate month incorporating the offset
  var thedaytoday = startdate.getMonth() == todaydate.getMonth() && startdate.getYear() == todaydate.getYear() ? todaydate.getDate() : 100; //the date for today if it's in this month
  startdate.setDate (1); //go back to the first day of the month
  startdate.setHours(1); //blank out the time components
  startdate.setMinutes(0);
  startdate.setSeconds(0);
  var returndate = new Date (startdate.toGMTString()); //the first day of the month in GMT
  var r = ""; //start the return string
  //the graphics on the table
  r += "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">";
  r += "<tr bgcolor=\""+BGTABLE+"\"><td><img src=\"images/_comunes/px_00.gif\" width=\"3\" height=\"3\"></td>"; //the top left corner
  r += "<td><img src=\"images/_comunes/px_00.gif\" border=\"0\" width=\"3\" height=\"3\"></td>"; //the strip across the  top
  r += "<td><img src=\"images/_comunes/px_00.gif\" width=\"3\" height=\"3\"></td></tr>"; //the top right corner
  r += "<tr><td  bgcolor=\""+BGTABLE+"\"><img src=\"images/_comunes/px_00.gif\" border=\"0\" width=\"3\" height=\"£\"></td><td>"; //the left side image
  //the data in the table
  r += "<table border=\"0\" width=\"100%\" cellspacing=\"1\" cellpadding=\"1\"  bgcolor=\""+BGTABLE+"\">"; //start the return string
  r += "<tr align=\"center\" class=\"bodytext\"><td><a class=\"bodytext\" href=\"javascript:setcalendar('" + whichone + "'," + (monthoffset-1) + "," + initialdate + "," + daysshown + ",'" + extras + "')\">&lt;</a></td>";
  //r += "<td colspan=\"5\"><a class=\"bodytext\" href=\"javascript:returndate('" + whichone + "'," + returndate.getTime() + "," + daysshown + ",'" + extras + "','month')\">" + (daysshown == 300 ? "<font color=\"" + TODAYFONT + "\">" : "") + MONTHS[startdate.getMonth()] + (daysshown == 300 ? "</font>" : "") + "</a> ";
  //r += "<a class=\"bodytext\" href=\"javascript:returndate('" + whichone + "'," + returndate.getTime() + "," + daysshown + ",'" + extras + "','year')\">" + (daysshown == 365 ? "<font color=\"" + TODAYFONT + "\">" : "") + makeyear(startdate.getYear()) + (daysshown == 365 ? "</font>" : "") + "</a></td>";
 
  r += "<td colspan=\"5\"><a class=\"bodytext\" href=\"javascript:returndate('" + whichone + "'," + returndate.getTime() + "," + daysshown + ",'" + extras + "','month')\">" + MONTHS[startdate.getMonth()] + " " + makeyear(startdate.getYear()) + "</a></td>";
  
  r += "<td><a class=\"bodytext\" href=\"javascript:setcalendar('" + whichone + "'," + (monthoffset+1) + "," + initialdate + "," + daysshown + ",'" + extras + "')\">&gt;</a></td></tr><tr class=\"bodytext\" align=\"center\">";
  for (var theday=0; theday<7; theday++) {r += "<td width=\"30\" class=\"bodytext\">&nbsp;" + DAYS[theday] + "&nbsp;</td>";}
  r += "</tr><tr align=\"center\" class=\"bodytext\">";
  var dayoffset = startdate.getDay(); //get the day of week of this first day of the month
  startdate.setMonth (startdate.getMonth()+1); //go forward a month
  startdate.setDate (0); //go back one day, now we are on the last day of the next month
  var lastday = startdate.getDate(); //get the last day of the month
  LASTDAY = lastday; //used later to highlight the correct calendar place
  if (dayoffset) {r += "<td colspan=\"" + dayoffset + "\" bgcolor=\"" + UNBG + "\"> </td>";}
  for (var theday=1; theday<=lastday; theday++) {
    returndate.setDate (theday);
    //display the day, with background highlighted if it is the selected day and we are in Netscape, in IE the dynamic highlighting works instead
    //r += "<td id=\"day" + theday + "\" class=\"bodytext\" bgcolor=\"" + (theday == thedayselected && document.layers ? SELECTBG : UNBG) + "\"><a class=\"bodytext\" href=\"javascript:returndate('" + whichone + "'," + returndate.getTime() + "," + daysshown + ",'" + extras + "','day')\" onMouseOver=\"highlightdays('" + whichone + "'," + theday + "," + daysshown + "," + lastday + ")\">";
    
	r += "<td id=\"day" + theday + "\" class=\"bodytext\" bgcolor=\"" + (theday == thedayselected && document ? SELECTBG : UNBG ) + "\"><a class=\"bodytext\"          href=\"javascript:returndate('" + whichone + "'," + returndate.getTime() + "," + daysshown + ",'" + extras + "','day')            \" onMouseOver=\"highlightdays('" + whichone + "'," + theday + "," + daysshown + "," + lastday + ")\">";	
	r += (theday == thedaytoday) ? ("<font color=\"" + TODAYFONT + "\">" + theday + "</font>") : theday;
	r += "</a></td>"; 
	
	if ((theday+dayoffset) % 7 == 0) {r += "</tr><tr align=\"center\">";}
  }
  if ((lastday + dayoffset) % 7 > 0) {r += "<td " + ((lastday + dayoffset) % 7 != 6 ? ("colspan=\"" + (7 - ((lastday + dayoffset) % 7)) + "\" ") : "") + "class=\"bodytext\" bgcolor=\"" + UNBG + "\"></td></tr><tr align=\"center\">";}
  
  //this table finishes with a space because IE5 on a Mac seems to need it to finish the table properly
  r += "<td colspan=\"7\" class=\"bodytext\"><a class=\"bodytext\" href=\"javascript:hidecalendar('" + whichone + "')\">cerrar</a></td>\n</tr></table> "; //the close button and finishing the table
  //finishing the graphics on the table
  r += "</td><td  bgcolor=\""+BGTABLE+"\"><img src=\"images/_comunes/px_00.gif\" border=\"0\" width=\"3\" height=\"3\"></td></tr>"; //the right side image
  r += "<tr  bgcolor=\""+BGTABLE+"\"><td><img src=\"images/_comunes/px_00.gif\" width=\"3\" height=\"3\"></td>"; //the bottom left corner
  r += "<td><img src=\"images/_comunes/px_00.gif\" border=\"0\" width=\"3\" height=\"3\"></td>"; //the strip across the bottom
  r += "<td><img src=\"images/_comunes/px_00.gif\" width=\"3\" height=\"3\"></td></tr></table> "; //the bottom right corner
  return r;
}

//highlight the days as a rollover
function highlightdays (whichone, startday, numdays, upto) {
  var colour;
  //500 or more are special values, and this only works on IE
  if (numdays < 500 && document.getElementById) { 
    for (var i=1; i<=upto; i++) { //loop through each of the days in this month
      colour = (i >= startday && i < (startday + numdays)) ?  SELECTBG : UNBG;
      if (document.layers) {var d=document.layers["calendar_" + whichone].document["day" + i].style.bgColor = colour;}
      else if (document.getElementById) {document.getElementById("day" + i).bgColor = colour;}
    } //highlight the appropriate days
  } //special values 500 for a whole month and 600 for a whole year
}

//function objectprops (o) {r= ""; for (p in o) {r += p + ": " + o[p] + "\t";} alert (r);}
//-->

