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

/**
 *
 * @version    5.1.2
 * @category   Goweb
 * @package    Zend_Form_Element_FormDhtmlxColorPicker
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2010 (c) Goweb (http://www.goweb.pt)
 */
class Zend_View_Helper_FormDhtmlxColorPicker extends Zend_View_Helper_FormText {
    public function formDhtmlxColorPicker($name, $value = null, $attribs = null){
        Goweb::loadJavascript('/admin/media/js/dhtmlx/dhtmlx.js');
        Goweb::loadCss('/admin/media/js/dhtmlx/dhtmlx.css');
        $return = $this->formText($name, $value, $attribs);
        $baseUrl = str_replace('/admin', '', str_replace('/index.php', '', Zend_Controller_Front::getInstance()->getBaseUrl()));
        $return .= '<script type="text/javascript" defer="defer">' . "\n";
        $return .= '    //<![CDATA[' . "\n";
        $return .= '    var color_' . $name . ' = new dhtmlXColorPickerInput("'. $name . '");' . "\n";
        $return .= '    color_' . $name . '.setImagePath("'. $baseUrl . '/admin/media/js/dhtmlx/imgs/");' . "\n";
        $return .= '    color_' . $name . '.setPosition(20,20);' . "\n";
        if ($value){
            $return .= '    color_'. $name . '.setColor("' . $value . '");' . "\n";
        }
        $return .= '    color_'. $name . '.init();' . "\n";
        $return .= '    //]]>' . "\n";
        $return .= '</script>';
        return $return;
    }
}
