<?php

Yii::import('zii.widgets.jui.CJuiDatePicker');

class CrmDatePicker extends CJuiDatePicker
{

	public function run()
	{
		$this->language =  'pt-BR';
		if(!isset($this->options['language'])) {
			$this->options['language'] =  'pt-BR';
		}
		
		if(!isset($this->htmlOptions['class'])) {
			$this->htmlOptions['class'] = 'datepicker format_data';
		} else {
			$this->htmlOptions['class'] .= ' datepicker format_data';
		}

		if(!isset($this->htmlOptions['maxlength'])) {
			$this->htmlOptions['maxlength'] = '10';
		}

		if(!isset($this->options['showButtonPanel'])) {
			$this->options['showButtonPanel'] =  false;
		}

		if(!isset($this->options['changeYear'])) {
			$this->options['changeYear'] =  true;
		}

		if(!isset($this->options['dateFormat'])) {
			$this->options['dateFormat'] =  'dd/mm/yy';
		}

		if($this->hasModel() && empty($this->value)) {
			$this->value = $this->model->{$this->attribute};
		}

		parent::run();
	}
}