/********************************************************
 ** This object is designed to handle the different ways
 ** that a date can be formatted based on a user's locale
 ** setting.
 **
 ** e.g. en_GB use DD/MM/YYYY and en_US uses MM/DD/YYYY
 **
 ** TODO: This could definitely use a bit of refactoring
 ** because right now the switch statements in the 
 ** parseDate and toString functions really should match
 ** up exactly or it'll have unexpected behaviour.
 ********************************************************/

var DateLocale = {

    month: 1,
    day: 1,
    year: 1970,
    locale: 'en_US',

    parseDate: function( str ) {
        var date_parse = str.split('/');

        switch( this.locale ) {
            case 'en_US':
            case 'en_CA':
                this.month = parseInt(date_parse[0]);
                this.day = parseInt(date_parse[1]);
                this.year = parseInt(date_parse[2]);
                break;
            default:
                this.month = parseInt(date_parse[1]);
                this.day = parseInt(date_parse[0]);
                this.year = parseInt(date_parse[2]);
                break;
        }
    },

    setDate: function( day, month, year ) {
        this.day = day;
        this.month = month;
        this.year = year;
    },

    toString: function() {
        switch( this.locale ) {
            case 'en_US':
            case 'en_CA':
                return this.month + '/' + this.day + '/' + this.year;
                break;
            default:
                return this.day + '/' + this.month + '/' + this.year;
                break;
        }
    },

    getTime: function() {
        var dt = new Date(this.year, this.month - 1, this.day)
        return dt.getTime();
    },

    setMonth: function( month ) {
        this.month = month;
    },

    setDay: function( day ) {
        this.day = day;
    },

    setYear: function( year ) {
        this.year = year;
    },

    setLocale: function( locale ) {
        this.locale = locale;
    }
};

