/*
 * $Id$
 * Copyright 2003,2004 WorldTicket A/S
 *
 * @version $Revision$ $Date$
 * @author Claus Br¿ndby Reimer (CBR) / 2M business applications a|s
 */


/**
 * The CalendarLocaleFactory creates locale objects based on different client
 * systems.
 */
function CalendarLocaleFactory() {
}


/**
 * Creates a <code>CalendarLocale</code> based on how the system is running.
 *
 * @return CalendarLocale A locale for the currently running system or an
 *                        english locale if it is not availeble.
 */
CalendarLocaleFactory.getLocale = function() {
    var locale;

    switch (System.locale) {
        case "se_SV":
            locale = new CalendarLocaleSE();
            break;

        case "da_DK":
            locale = new CalendarLocaleDA();
            break;

        case "en_GB":
            locale = new CalendarLocaleEN();
            break;

        default:
            locale = new CalendarLocaleEN();
            break;
    }

    return locale;
}


/**
 * Calendar locale for english.
 */
function CalendarLocaleEN() {
}


/**
 * Gets an array of the names of the months.
 *
 * @return String[] The names for the months.
 */
CalendarLocaleEN.prototype.getMonths = function() {
    return ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
}


/**
 * Gets an array of the names for week days.
 *
 * @return String[] The names for week days.
 */
CalendarLocaleEN.prototype.getWeekDays = function() {
    return ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
}


/**
 * Gets the first day of the week.
 *
 * @return number The first day of the week
 */
CalendarLocaleEN.prototype.getWeekStart = function() {
    return 1;
}


/**
 * Converts the date to a short as short format.
 *
 * @return String the date as a short displayable date.
 */
CalendarLocaleEN.prototype.asShortFormat = function(date) {
    var str;

    str = date.getDate();
    str += "-";
    str += (date.getMonth()+1);
    str += "-";
    str += date.getFullYear();

    return str;
}


/**
 * Converts the <code>String</code> formated as a short date to a
 * <code>Date</code> object.
 *
 * @return Date the date as a <code>Date</code> object.
 */
CalendarLocaleEN.prototype.fromShortFormat = function(date) {
    var re_date = /^(\d+)\-(\d+)\-(\d+)/;
    var return_Date;

	if (!re_date.exec(date)) {
		alert("Invalid date\nThe date must be formated as dd-mm-yyyy");
    } else {
        return_Date = new Date();
        return_Date.setFullYear(RegExp.$3);
        return_Date.setMonth(RegExp.$2-1);
        return_Date.setDate(RegExp.$1);
        return_Date.setMinutes(return_Date.getMinutes() + 1);
    }

    return return_Date;
}


/**
 * Gets the locale name.
 *
 * @return String The locale name.
 */
CalendarLocaleEN.prototype.getName = function() {
    return "en";
}



/**
 * Calendar locale for danish.
 */
function CalendarLocaleDA() {
}


/**
 * Gets an array of the names of the months.
 *
 * @return String[] The names for the months.
 */
CalendarLocaleDA.prototype.getMonths = function() {
    return ["januar", "februar", "marts", "april", "maj", "juni", "juli", "august", "september", "oktober", "november", "december"];
}


/**
 * Gets an array of the names for week days.
 *
 * @return String[] The names for week days.
 */
CalendarLocaleDA.prototype.getWeekDays = function() {
    return ["s&oslash;", "ma", "ti", "on", "to", "fr", "l&oslash;"];
}


/**
 * Gets the first day of the week.
 *
 * @return number The first day of the week
 */
CalendarLocaleDA.prototype.getWeekStart = function() {
    return 1;
}


/**
 * Gets the locale name.
 *
 * @return String The locale name.
 */
CalendarLocaleDA.prototype.getName = function() {
    return "da";
}


/**
 * Converts the date to a short as short format.
 *
 * @return String the date as a short displayable date.
 */
CalendarLocaleDA.prototype.asShortFormat = function(date) {
    var str;

    str = date.getDate();
    str += "-";
    str += (date.getMonth()+1);
    str += "-";
    str += date.getFullYear();

    return str;
}


/**
 * Converts the <code>String</code> formated as a short date to a
 * <code>Date</code> object.
 *
 * @return Date the date as a <code>Date</code> object.
 */
CalendarLocaleDA.prototype.fromShortFormat = function(date) {
    var re_date = /^(\d+)\-(\d+)\-(\d+)/;
    var return_Date;

	if (!re_date.exec(date)) {
		alert("Invalid date\nThe date must be formated as dd-mm-yyyy");
    } else {
        return_Date = new Date();
        return_Date.setFullYear(RegExp.$3);
        return_Date.setMonth(RegExp.$2-1);
        return_Date.setDate(RegExp.$1);
        return_Date.setMinutes(return_Date.getMinutes() + 1);
    }

    return return_Date;
}


/**
 * Calendar locale for english.
 */
function CalendarLocaleSE() {
}


/**
 * Gets an array of the names of the months.
 *
 * @return String[] The names for the months.
 */
CalendarLocaleSE.prototype.getMonths = function() {
    return ["Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December"];
}


/**
 * Gets an array of the names for week days.
 *
 * @return String[] The names for week days.
 */
CalendarLocaleSE.prototype.getWeekDays = function() {
    return ["SÃ¶", "MÃ¥", "Ti", "On", "To", "Fr", "LÃ¶"];
}


/**
 * Gets the first day of the week.
 *
 * @return number The first day of the week
 */
CalendarLocaleSE.prototype.getWeekStart = function() {
    return 1;
}


/**
 * Converts the date to a short as short format.
 *
 * @return String the date as a short displayable date.
 */
CalendarLocaleSE.prototype.asShortFormat = function(date) {
    var str;

    str = date.getDate();
    str += "-";
    str += (date.getMonth()+1);
    str += "-";
    str += date.getFullYear();

    return str;
}


/**
 * Converts the <code>String</code> formated as a short date to a
 * <code>Date</code> object.
 *
 * @return Date the date as a <code>Date</code> object.
 */
CalendarLocaleSE.prototype.fromShortFormat = function(date) {
    var re_date = /^(\d+)\-(\d+)\-(\d+)/;
    var return_Date;

	if (!re_date.exec(date)) {
		alert("Invalid date\nThe date must be formated as dd-mm-yyyy");
    } else {
        return_Date = new Date();
        return_Date.setFullYear(RegExp.$3);
        return_Date.setMonth(RegExp.$2-1);
        return_Date.setDate(RegExp.$1);
        return_Date.setMinutes(return_Date.getMinutes() + 1);
    }

    return return_Date;
}


/**
 * Gets the locale name.
 *
 * @return String The locale name.
 */
CalendarLocaleSE.prototype.getName = function() {
    return "se";
}


