/*
Simple Date Util Function Util Level Seven 16 Jan 2008 SH
*/

/*
Usage: DateDiff(PARAM)
PARAM = {SECONDS,MINUTES,HOURS,YEARS,DAYS}
FormatDate(dateToFormat,FORMAT)
PARAM = {"UK_SHORT","US_SHORT"}
*/
function DateUtil()
{
    //////////////////////////
    //Dates For Comparison
    this.DateFrom = new Date();
    this.DateTo = new Date();
    //AnyDate
    this.CurrentDate = new Date();
}
DateUtil.prototype.DateDiff =function DateDiff(comparison)
{           
    var diffInSeconds = (parseInt(this.DateTo.getTime()) - parseInt(this.DateFrom.getTime())) /1000;    
    switch(comparison)
    {
        case "SECONDS":
        {            
            return diffInSeconds;
            break;
        }
        case "MINUTES":
        {
            return parseInt(diffInSeconds / 60.0);
            break;
        }
        case "HOURS":
        {
            return parseInt(diffInSeconds / 3600.0);
            break;
        }
        case "DAYS":
        {
            //Round Days
            return parseInt(Math.round((diffInSeconds / 86400.0)*100)/100);
            break;
        }
        case "YEARS":
        {
            //Round Years
            return parseInt(Math.round((diffInSeconds / 31557600.0)*100)/100);
            break;
        }
    }
}
DateUtil.prototype.FormatDate = function(dateToFormat,format)
{
    var formatMonth = new Array("January","February","March","April","May","June","July","August","September","October","November","December")
    switch(format)
    {
        case "UK_SHORT":
        {
            return dateToFormat.getDate() + "/" + dateToFormat.getMonth()+1 + "/" + dateToFormat.getFullYear();            
            break;
        }
        case "US_SHORT":
        {
            return dateToFormat.getMonth()+1 + "/" + dateToFormat.getDate() + "/" + dateToFormat.getFullYear();
            break;
        }
        case "UK_LONG":
        {
            return dateToFormat.getDate() + " " + formatMonth(dateToFormat.getMonth()) + " " + dateToFormat.getFullYear();
            break;
            
        }
        
    }
}
//function(int,int,int)
DateUtil.prototype.SetDateFrom = function(day,month,year)
{
    this.DateFrom.setDate(day);
    this.DateFrom.setMonth(month-1);    
    this.DateFrom.setYear(year);   
    
}
//function(int,int,int)
DateUtil.prototype.SetDateTo = function(day,month,year)
{
    this.DateTo.setDate(day);
    this.DateTo.setMonth(month-1);    
    this.DateTo.setYear(year);
    
    
}
DateUtil.prototype.FormattedCurrentDate = function(format)
{
    this.CurrentDate = new Date();
    return this.FormatDate(this.CurrentDate,format)
}