<?php
	FNTH_class( "Select" );

	class FrontendSelect extends FNTHSelect {
		protected $bMandatory = false;
		protected $bInvalid = true;
		
		public function setMandatory( $v ) { $this->bMandatory = $v; }

		public function modifyGetPost( &$g, &$p ) {
			$id = $this->getId();
			if (isset( $this->aG[$id] )) $this->setValue( $this->aG[$id] );
			if (isset( $this->aP[$id] )) $this->setValue( $this->aP[$id] );
			parent::modifyGetPost( $g , $p );
		}
		public function __construct( $id = "FrontendSelect" , $parent = null ) {
			$this->addMediaDirectory( $GLOBALS["site_root"] , $GLOBALS["site_www"] , "design/rp/","widgets/");
			parent::__construct( $id , $parent );
			$this->setParam("language",$GLOBALS["language"]);
			$this->setAttribute( "class" , "FrontendSelect" );
		}

		public function render() {
			if ($this->bMandatory) {
				$this->bInvalid = (!strlen( $this->sValue ));
				$this->setParam( "bInvalid" , $this->bInvalid );
				if ($this->bInvalid)
					$this->setAttribute( "class" , $this->getAttribute( "class" ) . " invalid" );
				$this->setAttribute( "onchange" , sprintf( "FrontendSelectNonEmptyChanged( '%s' );" , $this->sId ) );
			}
			return parent::render();
		}
	}

?>
