﻿/* applyCustomLanguage */
function applyCustomLanguage()
{
    $("span[textId]").each(function (){
        var span = $(this);
        span.html(eval("language.values." + span.attr("textId")));
    })
}

/* GetCurrentDate */
function getCurrentDate()
{
    var currentDate = new Date();
    currentDate.setHours(0);
    currentDate.setMinutes(0);
    currentDate.setSeconds(0);
    currentDate.setMilliseconds(0);
    return currentDate;
}

/* dateToString 
   date is a date object
*/
function dateToString(date)
{
    var day = date.getDate();
    if (day.toString().length == 1) {day = '0' + day;}

    var month = date.getMonth() + 1;
    if (month.toString().length == 1) {month = '0' + month;}    
    
    var year = date.getFullYear();

    return day + "/" + month + "/" +  year;
}

/* dateFromString 
   dateString is a string in the form dd/MM/yyyy
*/
function dateFromString(dateString)
{
    var dateParts = dateString.split("/")
    var date = new Date();
   
    date.setFullYear(dateParts[2]);   
    date.setMonth(dateParts[1]-1);
    date.setDate(dateParts[0]);
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    date.setMilliseconds(0);
           
    return date;
}

/* dateDifferenceInDays 
   date1, date2 are both date objects
*/
function dateDifferenceInDays(date1, date2)
{
    var durationInMilliSeconds = date2 - date1;
    var durationInDays = (durationInMilliSeconds / 1000 / 60 / 60 / 24);
    durationInDays = Math.round (durationInDays ); //Just in case theres a clock change
    
    return durationInDays;
}