<?php
goweb::loadClass('Zend_View_Helper_FormText');
/**
 * Goweb Sitemanager 5 Framework
 *
 * @version    5.0.0
 * @category   Goweb
 * @package    Zend_Form_Element
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2009 (c) Goweb (http://www.goweb.pt)
 */

/**
 *
 * @version    5.0.0
 * @category   Goweb
 * @package    Zend_Form_Element_FormColorPicker
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2009 (c) Goweb (http://www.goweb.pt)
 */
class Zend_View_Helper_FormColorPicker extends Zend_View_Helper_FormText {
    public function formColorPicker($name, $value = null, $attribs = null){
        Goweb::loadJavascript('/admin/media/js/picker.js');
        Goweb::loadCSS('/admin/media/css/picker.css');
        $return = $this->formText($name, $value, $attribs);
        $baseUrl = str_replace('/admin', '', str_replace('/index.php', '', Zend_Controller_Front::getInstance()->getBaseUrl()));
        
        $return .= '<img src="' . $baseUrl . '/admin/media/images/picker/select_arrow.gif" onmouseover="this.src=\'' . $baseUrl . '/admin/media/images/picker/select_arrow_over.gif\'" onmouseout="this.src=\'' . $baseUrl . '/admin/media/images/picker/select_arrow.gif\'" onclick="showColorPicker(this,document.forms[0].' . $name . ',\'colorShow_' . $name . '\');" alt="colorPicker_' . $name . '" title="colorPicker_' . $name . '"';
        if (($this instanceof Zend_View_Abstract) && !$this->doctype()->isXhtml()) {
            $return .= '>';
        }else{
            $return .= ' />';
        }
        $return .= "\n";
        $return .= '<div class="colorPicker" id="colorShow_' . $name . '">&nbsp;</div>';

        $return .= "<script type=\"text/javascript\">\n";
        $return .= "<!--\n";
        $return .= "\t $('colorShow_" . $name . "').style.backgroundColor = $('" . $name . "').value;;\n";
        $return .= "-->\n";
        $return .= "</script>";
        return $return;
    }
}
