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

	class KeywordSearchForm extends Widget {
		protected $sValue = "";
		protected $bGoogle = true;
		
		public function setGoogle( $v ) { $this->bGoogle = $v; }

		protected function generateLangDefs() {
			fo3_add_js_langdef( "Freetext_search" );
			fo3_add_js_langdef( "Freetext_search_no_search_phrase_given" );
		}

		public function modifyGetPost( &$g , &$p ) {
			if (isset( $g["q"] )) {
				$this->sValue = $g["q"];
			}
			return parent::modifyGetPost( $g , $p );
		}

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$this->setParam( "bGoogle" , $this->bGoogle );
			$this->setParam( "url_freetext_search" , KeywordSearchURL::renderURL() );
			if ($this->bGoogle) {
				$this->setParam( "google_cx" , $GLOBALS["fo3_freetext_google_cx"] );
				$this->setParam( "google_cof" , $GLOBALS["fo3_freetext_google_cof"] );
			}
			$this->generateLangDefs();
			FNTHPage::addUniquePageFullInit( sprintf( "InitKeywordSearchForm('%s');",$this->getId() ) );
			if (empty( $this->sValue )) $this->sValue = fo3_add_js_langdef( "Freetext_search" );
			$this->setParam( "value" , $this->sValue );
			return parent::render();
		}
	}

?>
