<?php
/**
 * SelectBox
 * @date 13.07.2006
 * @name SelectBox
 * @author Margo Poolak <margo 'dot' poolak 'at' mail 'dot' ee>
 * @copyright Copyright &copy;2006 Margo Poolak. All Rights Reserved.
 * @version 2.0
 * @package System.Web.UI.HtmlControls
 * @category 
 * 
 * Generates the html input fields text, password, checkbox, radio etc.
 *
 */
class SelectBox extends HtmlControl
{
	private $id;
	private $element;
	private $selectedValue;
	private $selectedKey;
	private $param;
	/*
	*
	*/	
	function __construct($id = '')
	{
		if(isset($id))
			$this->setID($id);
	}
	/*
	*
	*/
	function setOption($key,$value='')
	{
		if(is_array($key))
		{
			foreach($key as $k=>$v)
			{
				$this->element[$k] = $v;
			}
		}else
			$this->element[$key] =$value;
	}
	/*
	*
	*/
	function setSelectedValue($value)
	{
		unset($this->selectedKey);// if was set then remove
		$this->selectedValue = $value;
	}
	/*
	*
	*/
	function setSelectedKey($value)
	{
		unset($this->selectedValue);// if was set then remove
		$this->selectedKey = $value;
	}	
	/*
	*
	*/
	function render()
	{
		$this->onLoad();
		if(is_array($this->element))
		{
			$options = '';
			foreach($this->element as $key=>$value)
			{
				if(isset($this->selectedValue) && $value == $this->selectedValue)
					$options .= '<option value="'.$key.'" selected="selected">'.$value.'</option>'; 
				elseif(isset($this->selectedKey) && $key==$this->selectedKey)
					$options .= '<option value="'.$key.'" selected="selected">'.$value.'</option>'; 
				else
					$options .= '<option value="'.$key.'">'.$value.'</option>'; 
			}
			return "<select ".$this->renderAttributes().">$options</select>";
		}
		return ;
	}
}
?>