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

class Goweb_View_Helper_FormPassword extends Zend_View_Helper_FormPassword{
    /**
     * Generates a 'password' element.
     *
     * @access public
     *
     * @param string|array $name If a string, the element name.  If an
     * array, all other parameters are ignored, and the array elements
     * are extracted in place of added parameters.
     *
     * @param mixed $value The element value.
     *
     * @param array $attribs Attributes for the element tag.
     *
     * @return string The element XHTML.
     */
    public function formPassword($name, $value = null, $attribs = null){
        goweb::loadJavascript('/admin/media/js/prototype.js');
        goweb::loadJavascript('/admin/media/js/scriptaculous/scriptaculous.js');
        goweb::loadJavascript('/admin/media/js/scriptaculous/effects.js');
        goweb::loadJavascript('/admin/media/js/modalbox.js');
        goweb::loadJavascript('/media/js/random_password.js');
        goweb::loadCss('/admin/media/css/modalbox.css');
        goweb::loadCss('/media/css/random_password.css');
        
        goweb::loadCss('/media/css/password_meter.css');
        goweb::loadJavascript('/media/js/password_meter.js');
        if (strpos($name, '_confirm') === false)
        $attribs['onkeyup'] = 'updateStrength(this.value,"psStrength_' . $name . '")';
        $html = parent::formPassword($name, $value, $attribs);
        if (strpos($name, '_confirm') === false){
            $baseUrl = str_replace('/admin', '', Zend_Controller_Front::getInstance()->getBaseUrl());
            $html .= '<button type="button" class="passwordGenerator" onclick="Modalbox.show(\'' . str_replace('/admin', '', goweb::link('/index/randomPassword/')) .'?campo=' . $name . '\', {title: this.title, width: 600}); return false;' . '"><span>' . translate('Gerar') . '</span></button>';
        }
        //$this->{$colName}->setAttrib('onclick', 'Modalbox.show("' . goweb::link($baseUrl . '/index/randomPassword/') . '", {title: this.title, width: 600,beforeHide: function() { updatePassword("' . $colName . '"); updatePassword("' . $colName . '_confirm' . '"); }}); return false;');
        if (strpos($name, '_confirm') === false)
		$html .= '<div class = "psContainer"><div class="psStrength" id = "psStrength_' . $name . '"></div></div>';
        return $html;
    }
}