Color Coding Script

_SP2007

Users like it to somehow get notified when tasks are overdue on their task lists or otherwise highlight content in a list. This can be done easily with a script that color codes certain rows in the list.
I guess this is one of many color coding scripts out there.
This one I put together myself from the best pieces I found on the web. :)

Simply put in the name of the column you want to calculate the due date on and set the conditions for the color codes and you are done.

// Put the name of the column here  
var fieldName = "Date Required";  

// todays date
today = new Date();

$(function(){    
var index = $("table.ms-listviewtable")       
.find("tr.ms-viewheadertr")       
.find("table[DisplayName='"+ fieldName + "']")       
.closest("th").index();     

var rows = $("table.ms-listviewtable > tbody > tr:not('.ms-viewheadertr')");     

rows.each(function(){
var field = $(this).children("td:nth-child("+ index +")");
var requiredDate = field.text();

//alert(requiredDate);

var suspense = field.text().split('/');
      var suspenseMonth = suspense.shift();
      var suspenseDay = suspense.shift();
      var suspenseYear = suspense.shift();
      var suspenseDate1 = suspenseDay + "." + suspenseMonth + "." + suspenseYear;
      
//alert(suspenseDay + "." + suspenseMonth + "." + suspenseYear);

      var suspenseDate = new Date();
      suspenseDate.setTime(0);
      suspenseDate.setHours(0);
      suspenseDate.setFullYear(suspenseYear, suspenseMonth - 1, suspenseDay);
 
//alert(suspenseDate);

// calculate time difference
      difference = today.getTime() - suspenseDate.getTime();
      difference = Math.floor(difference / (1000 * 60 * 60 * 24));

// color coding section - set the conditions

// green 
	if (difference < 1)
	{
	  $(this).css("background-color","green"); 
	}

// red 
	if (difference >= 1)
	{
	  $(this).css("background-color","red"); 
	}

// blue
	if (difference == 0)
	{
	$(this).css("background-color","blue"); 
	}

// orange - 3 days
	if (difference == -1 || difference == -2 || difference == -3)
	{
	 $(this).css("background-color","#f6890a"); 	
	}

   
}); 
});   

Is this Pages usefull? Usefull Useless 1 of 3 people say this Pages is usefull.