The thing was end-of-line (EOL) character in perm.php file. The oryginal file it was set MAC style (CR). I changed the file to DOS (CR+LF) or Unix (LF).
$permArray = include XOOPS_ROOT_PATH.'/modules/extgallery/include/perm.php';
$config = array (...); //array from perm.php
$permArray = $config;
function pf_dateForm($c, $n, $s, $v, $alt='calendar')
{
global $xoopsModule;
$jstime = formatTimestamp( strtotime(date('Y-m-d')), 'F j Y, H:i:s' );
include_once XOOPS_ROOT_PATH . '/include/calendarjs.php';
$tray = new XoopsFormElementTray($c,'');
$frm = new XoopsFormText('', $n, $s, 10, $v);
$tray->addElement($frm);
$img="<img alt='" . $alt . "' src='" . XOOPS_URL . "/modules/" . $xoopsModule->getVar('dirname') . "/images/date.png' style='cursor: pointer;' onclick='return showCalendar("" . $n . "");' />";
$btn = new XoopsFormLabel('',$img);
$tray->addElement($btn);
return $tray;
}
$form -> addElement( pf_dateForm(...) );