<?php
class GnutecaCalendarField extends MTextField
{
    public function __construct( $name='', $value='', $label='', $size=20, $hint='', $type='calendar-win2k-1' )
    {
        parent::__construct( $name, $value, $label, $size, $hint);

        $page = $this->page;
        $page->addScript('datepicker/calendar.js',              'gnuteca3');
        $page->addScript('datepicker/lang/calendar-pt-br.js',   'gnuteca3');
        $page->addScript('datepicker/calendar-setup.js',        'gnuteca3');

        $this->setValidator( new DATEDMYValidator( $name, $label ) );
    }


    public function generateInner()
    {
        parent::generateInner();

        if ( ! $this->readonly )
        {
            $location = $this->manager->getUI()->getImage('', 'cal.gif' );
            $imgName  = 'btn'.$this->name;

            $image = new MImage( $imgName, _M('Click to open the calendar'), $location );

            $this->page->onload( "Calendar.setup({inputField:\"{$this->name}\", ifFormat:\"%d/%m/%Y\", button:\"$imgName\"});" );
            $image->generateInner();
            $this->inner .= '&nbsp;' . $image->getInner();
        }
    }
}

?>