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

/**
 *
 * @version    5.0.15
 * @category   Goweb
 * @package    Goweb_Form_Element_FormCodPostal
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2009 (c) Goweb (http://www.goweb.pt)
 */
class Goweb_View_Helper_FormCodPostal extends Zend_View_Helper_FormText {
    public function formCodPostal($name, $value = null, $attribs = null){
    	Goweb::loadJavascript('/media/js/goweb_ajax.js');
    	$return = $this->_hidden($name, $value, $attribs);
		$attribs['onkeyup'] = 'gowebUpdateCP("'.$name.'");';    	
    	if ($value){ $valueTmp = explode('-', $value) ; }
		$attribs['id'] = $name.'_cp1';
		$attribs['size'] = 4;
		$attribs['onkeypress'] = 'return restrictCharacters(this, event, digitsOnly);';
		$attribs['maxlength'] = 4;
		$return .= '<span class="cp1">';
        $return .= $this->formText($name.'_cp1', $value && isset($valueTmp[0])? $valueTmp[0] : $value, $attribs);
        $return .= '</span>';
        $return .= '<span class="cp_separator">';
        $return .= '&nbsp;-&nbsp;';
        $return .= '</span>';
        $attribs['id'] = $name.'_cp2';
        $attribs['size'] = 3;
        $attribs['maxlength'] = 3;
        $return .= '<span class="cp2">';
        $return .= $this->formText($name.'_cp2', $value && isset($valueTmp[1])? $valueTmp[1] : $value, $attribs);
        $return .= '</span>';
        return $return;
    }
}
