function showOutdated()
  {
   // Look for "datefield" class
   var elements = $("td.datefield");

   for (var i = 0; i < elements.length; i++)
     {
  	  // read its text content
	  var datestring = $(elements[i]).text();
	
	  // This one should contain the date as text, but we check that first...
	  if (datestring != null)
	    {
		 // Take the contents and split it apart
	 	 var dateparts = splitDate(datestring);

		 // If the split was successful, check the date
		 if (dateparts != null)
		   {
		    var date = new Date(dateparts[0],dateparts[1]-1,dateparts[2]);
		    var now  = new Date();

		    // If the given date has no information on the time, set the current time to 0, so that
		    // the script will only show an entry as old if the full day has passed
		    // Note that time support isn't implemented yet
		    if (date.getHours() == 0 && date.getMinutes() == 0 && date.getSeconds() == 0)
			  {
			   now.setHours(0);
			   now.setMinutes(0);
			   now.setSeconds(0);

			   date.setSeconds(1);
			  }                 

		    // The given date lies before the current date
		    if (now > date)
			  {
			   // Get the parent table row
			   var row = elements[i].parentNode;
			   var rowspan = parseInt(elements[i].getAttribute("rowspan"));

			   if (rowspan == null) rowspan = 1;
			  
			   // Set the row to "old" style
			   // If the date field spans multiple rows, set for all rows
			   do
				 {
				  if (row.nodeType == 1) rowspan--;
				  row.className = "old";

				  row = row.nextSibling;
				 }
			   while (rowspan > 0 && row != null)
			  }
		   }
	    }
     }
  }
  
function getText(element)
  {
   if (element == null) return null;
   
   // it is a text node
   if (element.nodeType == 3) return element.nodeValue;
   
   // regular node
   if (element.nodeType == 1)
     {
	  var text = "";
	  
	  for (i = 0; i < element.childNodes.length; i++)
	    {
		 text += getText(element.childNodes[i]);
		}
		
	  return text;
	 }
	 
   return null;
  }
  
/**
 * Returns the date split in parts, with part[0] being the year, part[1] being the month
 * and part[2] being the day.
 */

function splitDate(date)
  {
   if (isISODate(date)) return splitISO(date);
   else if (isGERDate(date)) return splitGER(date);
   else return null;
  }
  
function isISODate(date)
  {
   return (date.indexOf("-") > -1);
  }

function isGERDate(date)
  {
   return (date.indexOf(".") > -1);
  }

function splitISO(date)
  {
   return date.split("-");
  }

function splitGER(date)
  {
   var parts = date.split(".");
   
   // use current year if it is missing
   if (parts.length == 2 || parts[2] == "") parts[2] = new Date().getFullYear();
   
   return parts.reverse();
  }

attachOnLoad(showOutdated);
