// Date picker functions for YUI Calendar
function showDatePicker( base, id, datatype )
{
    var calIconID = base + '_' + datatype + '_cal_' + id;
    var calContainerID = base + '_' + datatype + '_cal_container_' + id;

    YAHOO.util.Dom.setStyle( calContainerID, 'display', 'block' );

    //YAHOO.widget.DateMath.WEEK_ONE_JAN_DATE = 4;

    window['cal'+id] = new YAHOO.widget.Calendar( base + '_' + datatype + '_calendar_' + id , calContainerID, { close: true, 
                                                                                              mindate: "1/1/1970",
                                                                                              LOCALE_WEEKDAYS: "short" } );
    var lc = window['cal' + id];
    // Correct formats for Germany: dd.mm.yyyy, dd.mm, mm.yyyy

	lc.cfg.setProperty("DATE_FIELD_DELIMITER", ".");

	lc.cfg.setProperty("MDY_DAY_POSITION", 1);
	lc.cfg.setProperty("MDY_MONTH_POSITION", 2);
	lc.cfg.setProperty("MDY_YEAR_POSITION", 3);

	lc.cfg.setProperty("MD_DAY_POSITION", 1);
	lc.cfg.setProperty("MD_MONTH_POSITION", 2);
	lc.cfg.setProperty("START_WEEKDAY", 1);

	// Date labels for German locale

	lc.cfg.setProperty("MONTHS_SHORT",   ["led", "Úno", "Bře", "Dub", "Kvě", "Čer", "Čec", "Srp", "Zář", "Říj", "Lis", "Pro"]);
	lc.cfg.setProperty("MONTHS_LONG",    ["leden", "únor", "březen", "duben", "květen", "červen", "červenec", "srpen", "září", "říjen", "listopad", "prosinec"]);
	lc.cfg.setProperty("WEEKDAYS_1CHAR", ["S", "M", "D", "M", "D", "F", "S"]);
	lc.cfg.setProperty("WEEKDAYS_SHORT", ["ne", "po", "út", "st", "čt", "pá", "so"]);
	lc.cfg.setProperty("WEEKDAYS_MEDIUM",["Son", "Mon", "Die", "Mit", "Don", "Fre", "Sam"]);
	lc.cfg.setProperty("WEEKDAYS_LONG",  ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"]);

    
    
    window['cal'+id].render();
    window['cal'+id].selectEvent.subscribe( function( type, args, obj )
    {
        var dates = args[0], date = dates[0], year = date[0], month = date[1], day = date[2];

        var idArray = obj.id.split( '_' ), id = idArray[3], datatype = idArray[1], base = idArray[0];

        var txtYear = document.getElementsByName( base + '_' + datatype + '_year_' + id );
        txtYear[0].value = year;

        var txtMonth = document.getElementsByName( base + '_' + datatype + '_month_' + id );
        txtMonth[0].value = month;

        var txtDay = document.getElementsByName( base + '_' + datatype + '_day_' + id );
        txtDay[0].value = day;

        /* Set time to 12:00, if no time is set */
        var txtHour = document.getElementsByName( base + '_' + datatype + '_hour_' + id );
        if( txtHour && txtHour[0].value.length == '' ) {
            txtHour[0].value = '12';
        }

        var txtMinute = document.getElementsByName( base + '_' + datatype + '_minute_' + id );
        if( txtMinute && txtMinute[0].value == '' ) {
            txtMinute[0].value = '00';
        }

        this.hide();
    }, window['cal'+id], true );
}

