// JavaScript Document

Date.prototype.ticks = function(date)
{
   this.day = date.getDate();
   this.month = date.getMonth() + 1;
   this.year = date.getFullYear();
   this.hour = date.getHours();
   this.minute = date.getMinutes();
   this.second = date.getSeconds();
   this.ms = date.getMilliseconds();
  
   this.monthToDays = function(year, month)
   {
      var add = 0;
      var result = 0;
        if((year % 4 == 0) && ((year % 100  != 0) || ((year % 100 == 0) && (year % 400 == 0)))) add++;
        
      switch(month)
      {
         case 0: return 0;
         case 1: result = 31; break;
         case 2: result = 59; break;
         case 3: result = 90; break;
         case 4: result = 120; break;
         case 5: result = 151; break;
         case 6: result = 181; break;
         case 7: result = 212; break;
         case 8: result = 243; break;
         case 9: result = 273; break;
         case 10: result = 304; break;
         case 11: result = 334; break;
         case 12: result = 365; break;
      }
      if(month > 1) result += add;
      return result;     
   }
   this.dateToTicks = function(year, month, day)
   {
      var a = parseInt((year - 1) * 365);
      var b = parseInt((year - 1) / 4);
      var c = parseInt((year - 1) / 100);
      var d = parseInt(a + - c);
      var e = parseInt((year - 1) / 400);
      var f = parseInt(d + e);
      var monthDays = this.monthToDays(year, month - 1);
      var g = parseInt((f + monthDays) + day);
      var h = parseInt(g - 1);
      return h * 864000000000;
   }
   this.timeToTicks = function(hour, minute, second)
   {
      return (((hour * 3600) + minute * 60) + second) * 10000000;
   }  
  
   return this.dateToTicks(this.year, this.month, this.day) + this.timeToTicks(this.hour, this.minute, this.second) + (this.ms * 10000);
}

   

function change(id, newClass) {
identity=document.getElementById(id);
identity.className=newClass;
}


function exitPage()
{    
    var name = "TimeLastLoaded";
    saveTimeCookie(name);        
}




function saveTimeCookie(name) 
{
    var dt = new Date();
    var ticks = dt.getTime();
	document.cookie = name+"="+ticks+""+"; path=/";
}

function readCookie(name) 
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) 
    {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0)
            if (c.indexOf(nameEQ) == 0) 
                return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function GetSum(tb)
{	
    var tBody = tb.parentNode.parentNode.parentNode;    
    var tFoot = tBody.parentNode.childNodes[4];
    if(tFoot == null || tFoot == 'undefined')
    {
        tFoot = tBody.parentNode.childNodes[2];        
    }    
    var runningSum = 0;        
    //Grab each tb that is in a tr as the top level node and add to value of runningSum.
    //when the node is a tfoot, then grab the SumBox in the second cell of the first tr in the tfoot and make it eqaul to value
    //of runningsum
    var count = tBody.childNodes.length;                        
    for(var i = 0; i < count; i++)
    {        
        var node = tBody.childNodes[i];                
        if(node.tagName == 'TR')
        {            
            //hack for IE7                        
            if(node.childNodes.length < 3)
            {            
                if(node != null && node.childNodes != null && node.childNodes[1].childNodes != null)
                {					                      
                    var rowTB = node.childNodes[1].childNodes[0];                                                                              
                    if(rowTB.value != '' && rowTB.value != 'undefined' && rowTB.value != null)
                    {						
                        runningSum += parseInt(rowTB.value);
                    }
                }                
            }
            else
            {
                var rowTB = node.childNodes[3].childNodes[1];
                if(rowTB.value != '' && rowTB.value != 'undefined' && rowTB.value != null)
                {
                    runningSum += parseInt(rowTB.value);
                }
            }
        }               
    }            
    var sumBox;    
    if(tFoot.childNodes.length < 2)
    {		
		sumBox = tFoot.childNodes[0].childNodes[1].childNodes[0];    			
    }
		
	else    
		sumBox = tFoot.childNodes[1].childNodes[3].childNodes[1];    
    sumBox.value = runningSum;    
}

function GetSum2(tb)
{
    var tBody = tb.parentNode.parentNode.parentNode;    
    var tFoot = tBody.parentNode.childNodes.length;
    var runningSum = 0;    
    //Grab each tb that is in a tr as the top level node and add to value of runningSum.
    //when the node is a tfoot, then grab the SumBox in the second cell of the first tr in the tfoot and make it eqaul to value
    //of runningsum
    var count = tBody.childNodes.length;                
    for(var i = 0; i < count; i++)
    {        
        var node = tBody.childNodes[i];                
        if(node.tagName == 'TR')
        {            
            var rowTB = node.childNodes[3].childNodes[1];
            if(rowTB.value != '' && rowTB.value != 'undefined' && rowTB.value != null)
            {
                runningSum += parseInt(rowTB.value);
            }            
        }                   
    }        
    var sumBox = tFoot.childNodes[1].childNodes[3].childNodes[1];    
    sumBox.value = runningSum;    
}