<?php
	require_once( $GLOBALS["site_root"]."/includes/widgets/FrontendTextbox.inc.php" );

	class FrontendDate extends FrontendTextbox {
		protected $sMinDate = null;
		protected $sMaxDate = null;

		protected $aExtraObj = array();
		protected $sExtraEvalData = "";
		public function setExtraObjectData( $k , $v ) { $this->aExtraObj[$k]=$v; }
		public function setExtraEvalData( $v ) { $this->sExtraEvalData = $v; }

		public function setMinDate( $v ) { $this->sMinDate = $v; }
		public function setMaxDate( $v ) { $this->sMaxDate = $v; }

		public function __construct( $id , $parent = null ) {
			parent::__construct( $id , $parent );
			$this->setAttribute( "class" , "FrontendDate" );
		}

		public function setValue( $v ) {
			$this->sValue = str_replace( "-" , "." , $v );
		}

		public function getValue( ) {
			return str_replace( "." , "-" , $this->sValue );
		}

		public function generateLangdefs() {
			fo3_add_js_langdef( "datetimepicker_save" );
		}

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$this->generateLangdefs();
			$uid = sprintf( "js_%s_init" , $this->getId() );
			$datas = array();
			if (isset( $this->sMinDate ))
				$this->setExtraObjectData( "minDate" , str_replace( "-" , "." , $this->sMinDate ) );
			if (isset( $this->sMaxDate ))
				$this->setExtraObjectData( "maxDate" , str_replace( "-" , "." , $this->sMaxDate ) );

			/*
			// TODO ezt majd ellenorizni kell
			if (!FNTHPage::getPageFullInit( $uid ))
				FNTHPage::setPageFullInit( $uid ,
					sprintf( "InitFrontendDate( '%s' , %s );",
					$this->getId(),
					json_encode( $datas ) ) );
			*/
			return parent::render();
		}
	}
?>
