/**
* Top frame
**/
function Pmx_Frame_top($cfg, $count)
{
    global $context, $scripturl, $options, $txt;
    $context['pmx_framecount']++;
    $context['pmx_frames'][$context['pmx_framecount']] = true;
    if (!empty($cfg['config']['skip_outerframe'])) {
        $context['pmx_frames'][$context['pmx_framecount']] = false;
        return null;
    }
    // get the block title for user language have it or forum default
    $blocktitle = PortaMx_getTitle($cfg['config']);
    // the title align
    $ttladjust = '';
    switch ($cfg['config']['title_align']) {
        case 'left':
            $imgalign = 'right';
            $txtalign = 'left';
            $ttlimg = $txtalign;
            $toggleClass = 'class="float' . $imgalign;
            break;
        case 'right':
            $imgalign = 'left';
            $txtalign = 'right';
            $ttlimg = $txtalign;
            $toggleClass = 'class="float' . $imgalign;
            break;
        case 'center':
            $imgalign = 'right';
            $txtalign = 'center';
            $ttlimg = 'left';
            $toggleClass = 'class="float' . $imgalign;
    }
    if ($cfg['config']['title_icon'] == 'none.png') {
        $cfg['config']['title_icon'] = '';
    }
    if (empty($cfg['config']['title_icon'])) {
        $ttladjust = ' pmxadj';
    }
    if ($cfg['config']['title_align'] == 'center') {
        if (!empty($cfg['config']['title_icon']) && !empty($cfg['config']['collapse']) && $context['pmx']['settings']['shrinkimages'] != 2) {
            $ttladjust = ' pmxadj_center';
        } elseif (empty($cfg['config']['title_icon']) && empty($cfg['config']['collapse'])) {
            $ttladjust = '';
        } elseif (empty($cfg['config']['title_icon'])) {
            $ttladjust = ' pmxadj_' . $imgalign;
        } else {
            $ttladjust = ' pmxadj_' . $ttlimg;
        }
    }
    $cfg['config']['innerpad'] = isset($cfg['config']['innerpad']) ? $cfg['config']['innerpad'] : '4';
    $innerPad = Pmx_getInnerPad($cfg['config']['innerpad']);
    // custom css ?
    if (!empty($cfg['customclass'])) {
        $isCustHeader = !empty($cfg['customclass']['header']);
        $isCustFrame = !empty($cfg['customclass']['frame']);
    } else {
        $isCustHeader = $isCustFrame = false;
    }
    $IDtype = $cfg['blocktype'] . $cfg['id'];
    $frame = false;
    $cfg['noID'] = in_array($cfg['blocktype'], array('category', 'article', 'static_category', 'static_article'));
    $showAcs = allowPmxGroup($cfg['acsgrp']);
    $cfg['active'] = !isset($cfg['active']) ? true : $cfg['active'];
    echo '
						<div' . (empty($cfg['noID']) ? ' id="block.id.' . $cfg['id'] . '" ' : '') . ' style="margin-bottom:' . (empty($count) ? '0' : $context['pmx']['settings']['panelpad']) . 'px; overflow:hidden;' . (in_array(strtolower($cfg['side']), array('left', 'right')) ? 'width:' . $context['pmx']['settings'][strtolower($cfg['side']) . '_panel']['size'] . 'px; padding-' . (strtolower($cfg['side']) == 'left' ? 'right:' : 'left:') . $context['pmx']['settings']['panelpad'] . 'px;' : '') . (empty($cfg['active']) || empty($showAcs) ? 'display:none;' : '') . '">';
    // show the collapse, if set and have a header
    $head_bar = !empty($cfg['config']['visuals']['header']) && $cfg['config']['visuals']['header'] !== 'hide' ? str_replace('bg', '_bar', $cfg['config']['visuals']['header']) : '';
    if (!empty($cfg['config']['visuals']['header']) && $cfg['config']['visuals']['header'] != 'none' || empty($cfg['config']['visuals']['header']) && !empty($cfg['config']['visuals']['body'])) {
        echo '
							<div class="' . (!empty($head_bar) ? $head_bar : 'title_no_bar') . '">
								<h3';
        if (!empty($cfg['config']['collapse']) && $context['pmx']['settings']['shrinkimages'] != 2) {
            if (!isset($options['collapse' . $IDtype])) {
                $cook = pmx_getcookie('pmx_upshr' . $IDtype, false);
                $options['collapse' . $IDtype] = is_null($cook) ? '0' : $cook;
            }
        } else {
            $options['collapse' . $IDtype] = '0';
        }
        echo ' class="' . (!empty($cfg['config']['visuals']['header']) ? $cfg['config']['visuals']['header'] : $cfg['config']['visuals']['body']) . ' cbodypad">';
        // show the collapse / expand icon
        if (!empty($cfg['config']['collapse'])) {
            echo '
									<span id="upshrink_' . $IDtype . '_Img" ' . (empty($options['collapse' . $IDtype]) ? $toggleClass . $context['pmx_img_expand'] : $toggleClass . $context['pmx_img_colapse']) . ' title="' . (empty($options['collapse' . $IDtype]) ? $txt['pmx_collapse'] : $txt['pmx_expand']) . $blocktitle . '"></span>';
        }
        // show the title icon is set
        if (!empty($cfg['config']['title_icon'])) {
            echo '
									<img class="title_images pmx' . $ttlimg . '" src="' . $context['pmx_Iconsurl'] . $cfg['config']['title_icon'] . '" alt="*" title="' . $blocktitle . '" />';
        }
        echo '
									<span class="pmxtitle pmx' . $txtalign . $ttladjust . '">';
        // if quickedit link the title to blockedit?
        if (!empty($context['pmx']['settings']['manager']['qedit']) && allowPmx('pmx_admin') && !empty($blocktitle)) {
            $btyp = str_replace('static_', '', $cfg['blocktype']);
            echo '
										<a href="' . $scripturl . '?action=' . (allowPmx('pmx_admin', true) ? 'portamx' : 'admin') . ';area=pmx_' . (in_array($btyp, array('category', 'article')) ? $btyp == 'category' ? 'categories;sa=edit;id=' . preg_replace('/_[0-9]+/', '', $cfg['catid']) : 'articles;sa=edit;id=' . preg_replace('/_[0-9]+/', '', $cfg['id']) : 'blocks;sa=' . $cfg['side']) . ';edit=' . preg_replace('/_[0-9]+/', '', $cfg['id']) . ';' . $context['session_var'] . '=' . $context['session_id'] . '" onclick="pmxsetEditTop(this)">' . $blocktitle . '</a>';
        } else {
            echo '
									' . (empty($blocktitle) ? '&nbsp;' : $blocktitle);
        }
        echo '
									</span>
								</h3>
							</div>';
    }
    // show content frame
    $frameclass = $cfg['config']['visuals']['frame'] . ' ' . $cfg['config']['visuals']['body'] . (strpos($head_bar, 'notrnd') !== false ? ' notrnd' : '');
    if (!empty($cfg['config']['visuals']['frame']) || $isCustFrame) {
        echo '
							<div' . (!empty($cfg['config']['collapse']) ? ' id="upshrink_' . $IDtype . '"' . (empty($options['collapse' . $IDtype]) ? '' : ' style="display:none;"') : '') . '>
								<div class="' . $frameclass . '" style="padding:' . $innerPad[0] . 'px ' . $innerPad[1] . 'px !important; margin-top:0px;">
									<div';
    } else {
        echo '
							<div' . (!empty($cfg['config']['collapse']) ? ' id="upshrink_' . $IDtype . '"' . (empty($options['collapse' . $IDtype]) ? '' : ' style="display:none;"') : '') . (!empty($cfg['config']['visuals']['body']) ? ' class="blockcontent fr_' . $head_bar . ' ' . $cfg['config']['visuals']['body'] . '"' : '') . '>
								<div' . (!empty($hashead) ? ' class="pmx_noframe_' . $cfg['blocktype'] . '"' : '') . ' style="padding:' . $innerPad[0] . 'px ' . $innerPad[1] . 'px !important;">
									<div';
    }
    // have a bodytext class ?
    if (!empty($cfg['config']['visuals']['bodytext'])) {
        echo ' class="' . $cfg['config']['visuals']['bodytext'] . '"';
    }
    // have overflow and (min-/max-)height?
    if (!empty($cfg['config']['overflow'])) {
        echo ' style="' . (isset($cfg['config']['maxheight']) && !empty($cfg['config']['maxheight']) ? (empty($cfg['config']['height']) ? 'max-height' : $cfg['config']['height']) . ':' . $cfg['config']['maxheight'] . 'px;' : '') . 'overflow:' . $cfg['config']['overflow'] . ';text-overflow:ellipsis;white-space:nowrap;"';
    }
    echo '>';
    // if header or frame and can collaps?
    if (!empty($cfg['config']['collapse']) && $cfg['config']['visuals']['header'] != 'none') {
        $tmp = '
		var ' . $IDtype . ' = new smc_Toggle({
		bToggleEnabled: true,
		bCurrentlyCollapsed: ' . (empty($options['collapse' . $IDtype]) ? 'false' : 'true') . ',
		aSwappableContainers: [
			\'upshrink_' . $IDtype . '\'
		],
		aSwapImages: [
			{
				sId: \'upshrink_' . $IDtype . '_Img\',';
        if ($context['pmx']['settings']['shrinkimages'] == '0') {
            $tmp .= '
				srcCollapsed: \'' . $context['pmx_img_colapse'] . '\',
				altCollapsed: ' . JavaScriptEscape($txt['pmx_expand'] . $blocktitle) . ',';
        } else {
            $tmp .= '
				altCollapsed: ' . JavaScriptEscape($txt['pmx_expand'] . $blocktitle) . ',';
        }
        if ($context['pmx']['settings']['shrinkimages'] == '0') {
            $tmp .= '
				srcExpanded: \'' . $context['pmx_img_expand'] . '\',
				altExpanded: ' . JavaScriptEscape($txt['pmx_collapse'] . $blocktitle) . '
			}';
        } else {
            $tmp .= '
				altExpanded: ' . JavaScriptEscape($txt['pmx_collapse'] . $blocktitle) . '
			}';
        }
        $tmp .= '
		],
		oCookieOptions: {
			bUseCookie: true,
			sCookieName: \'' . 'pmx_upshr' . $IDtype . '\',
			sCookieValue: \'' . $options['collapse' . $IDtype] . '\'
		}
	});';
        addInlineJavascript("\t" . str_replace("\n", "\n\t", PortaMx_compressJS($tmp)), true);
        unset($tmp);
    }
}
    /**
     * ShowContent
     */
    function pmxc_ShowContent()
    {
        global $context, $scripturl, $user_info, $txt;
        $context['pmx']['shout_edit'] = -1;
        // smiley && bb codes popup
        $innerPad = Pmx_getInnerPad($this->cfg['config']['innerpad']);
        $bodyclass = $this->cfg['config']['visuals']['body'] == 'windowbg' ? 'windowbg2 ' : 'windowbg ';
        echo '
			<div id="bbcodes' . $this->cfg['id'] . '" style="position:absolute;z-index:9999;width:340px;height:110px;display:none">
				<div>
					<div class="' . $bodyclass . ' roundframe shoutbox_round ' . str_replace('pmxborder', '', $this->cfg['config']['visuals']['frame']) . '" style="margin:auto;text-align:center;border-radius:6px;border-width:1px;box-shadow:none;">';
        echo '
						<div style="height:25px;">';
        $half = 10;
        foreach ($this->smileys as $sm) {
            echo '
						<img onclick="InsertSmiley(' . $this->cfg['id'] . ', \'' . addslashes($sm['code']) . '\')" src="' . $sm['image'] . '" alt="*" title="' . $sm['title'] . '" style="float:left;cursor:pointer;padding:2px 7px;" />';
            $half--;
            if ($half == 0) {
                echo '
						</div>
						<div style="height:25px;">';
            }
        }
        echo '
						</div>
						<hr class="pmx_hr" />
						<div style="height:28px;">';
        foreach ($this->bb_code as $sm) {
            echo '
							<img onclick="InsertBBCode(' . $this->cfg['id'] . ', \'' . $sm['code'] . '\'); return false;" src="' . $sm['image'] . '" alt="*" title="' . $sm['title'] . '" class="shoutbox_bbcimg" />';
        }
        echo '
							<select id="shout_color' . $this->cfg['id'] . '" size="1" onchange="InsertBBColor(' . $this->cfg['id'] . ', this); return false;" style="float:right; margin:3px 4px 0 0px; width:100px;">';
        foreach ($this->bb_colors as $coltxt => $colname) {
            echo '
								<option value="' . $colname . '"' . ($colname == $coltxt ? ' selected="selected"' : '') . '>' . $coltxt . '</option>';
        }
        echo '
							</select>
						</div>
					</div>
				</div>
			</div>';
        echo '
			<div class="' . $this->cfg['side'] . '" id="shoutframe' . $this->cfg['id'] . '" style="' . (isset($this->cfg['config']['settings']['maxheight']) ? 'max-height:' . $this->cfg['config']['settings']['maxheight'] . 'px; overflow:auto; ' : '') . 'padding:0px;">';
        $haveshouts = false;
        $allowAdmin = allowPmx('pmx_admin');
        $cnt = 0;
        foreach ($this->shouts as $id => $data) {
            echo '
				<div id="shoutitem' . $this->cfg['id'] . '-' . $id . '">
					<div class="tborder shoutbox_user">';
            // show the edit/delete images
            if ($allowAdmin || $user_info['id'] == $data['uid'] && !empty($this->cfg['config']['settings']['allowedit']) && $this->canShout) {
                $haveshouts = $allowAdmin || $user_info['id'] == $data['uid'] ? true : $haveshouts;
                echo '
						<img id="' . $cnt . 'shoutimg' . $this->cfg['id'] . '" onclick="DeleteShout(' . $this->cfg['id'] . ', ' . $id . ', ' . intval(!empty($this->cfg['config']['settings']['boxcollapse'])) . ', ' . intval(!empty($this->cfg['config']['settings']['boxcollapse'])) . ');" style="cursor:pointer; margin-top:2px; display:none;float:right;margin-right:2px;" src="' . $context['pmx_imageurl'] . 'shout_del.gif" alt="*" title="' . $txt['pmx_shoutbox_shoutdelete'] . '" />';
                $cnt++;
                echo '
						<img id="' . $cnt . 'shoutimg' . $this->cfg['id'] . '" onclick="EditShout(' . $this->cfg['id'] . ', ' . $id . ', \'' . addslashes($data['post']) . '\');" style="cursor:pointer;margin-top:2px;padding-right:4px;display:none;float:right;" src="' . $context['pmx_imageurl'] . 'shout_edit.gif" alt="*" title="' . $txt['pmx_shoutbox_shoutedit'] . '" />';
                $cnt++;
            }
            // show the ip image
            if ($allowAdmin && !empty($data['ip'])) {
                echo '
						<a id="' . $cnt . 'shoutimg' . $this->cfg['id'] . '" href="' . $scripturl . '?action=trackip;searchip=' . $data['ip'] . '" style="display:none;">
							<img src="' . $context['pmx_imageurl'] . 'ip.gif" style="padding:4px 3px 0 0;float:right;margin-top:-3px;" title="' . $data['ip'] . '" alt="*" />
						</a>';
                $cnt++;
            }
            // convert smileys and bb codes
            $data['post'] = $this->BBCtoHTML($data['post'], true);
            // Guest shout?
            if ($data['uid'] != 0 && isset($this->memdata[$data['uid']])) {
                echo '
						<a style="display:block; margin-top:-2px;" href="' . $scripturl . '?action=profile;u=' . $data['uid'] . '"><span' . (isset($this->memdata[$data['uid']]['color']) && !empty($this->memdata[$data['uid']]['color']) ? ' style="color:' . $this->memdata[$data['uid']]['color'] . ';"' : '') . '>' . $this->memdata[$data['uid']]['name'] . '</span></a>';
            } else {
                $data['uid'] = 0;
                echo '
						' . $this->memdata[$data['uid']]['name'];
            }
            echo '<div class="smalltext shoutbox_date">' . timeformat($data['time']) . '</div>
					</div>
					<div class="shoutbox_post">
						' . $data['post'] . '
					</div>
				</div>';
        }
        echo '
				<input type="hidden" id="shoutcount' . $this->cfg['id'] . '" value="' . $cnt . '" />
			</div>';
        // have shout access?
        if ($this->canShout) {
            $canEdit = !$user_info['is_guest'] && ($allowAdmin && $haveshouts || $haveshouts && !empty($this->cfg['config']['settings']['allowedit']));
            $Admimg[0] = $context['pmx_imageurl'] . ($canEdit ? 'shout_admon.gif' : 'empty.gif');
            $Admimg[1] = $context['pmx_imageurl'] . ($canEdit ? 'shout_admoff.gif' : 'empty.gif');
            if (pmx_checkECL_Cookie(true)) {
                echo '
			<div style="overflow:hidden;margin-bottom:2px;margin-top:4px;">
				<input type="hidden" name="shoutbox_action" value="shout" />
				<input type="hidden" name="shoutbox_id" value="' . $this->cfg['id'] . '" />
				<input type="hidden" name="sc" value="' . $context['session_id'] . '" />
				<input type="hidden" id="shout' . $this->cfg['id'] . '" name="pmx_shout" value="" />
				<input type="hidden" id="shoutid' . $this->cfg['id'] . '" name="shoutid" value="" />
				<div id="shoutcontdiv' . $this->cfg['id'] . '" style="display:none;">
					<textarea id="shoutcontent' . $this->cfg['id'] . '"  style="height:80px;min-height:80px;max-height:250px;width:100%;resize:vertical;" name="post"></textarea>
				</div>
				<div style="border-top:1px solid #ddd;margin-top:2px;padding-top:2px;">
					<img id="shoutbbon' . $this->cfg['id'] . '" style="cursor:pointer;margin-top:6px;float:left;' . (!empty($this->cfg['config']['settings']['boxcollapse']) ? 'display:none;' : '') . '" onclick="ShoutPopup(' . $this->cfg['id'] . ');" src="' . $context['pmx_imageurl'] . 'type_bbc.gif" alt="*" title="' . $txt['pmx_shoutbox_bbc_code'] . '" />';
                if (!empty($this->cfg['config']['settings']['boxcollapse'])) {
                    echo '
					<img id="shoutbboff' . $this->cfg['id'] . '" style="margin-top:6px;float:left;" src="' . $context['pmx_imageurl'] . 'empty.gif" alt="*" title="" />';
                }
                echo '
					<img id="shout_toggle' . $this->cfg['id'] . '" style="' . ($canEdit ? 'cursor:pointer;' : '') . 'margin-top:6px;float:right;"' . ($canEdit ? ' onclick="ShoutAdmin(' . $this->cfg['id'] . ',\'check\');"' : '') . ' src="' . $Admimg[0] . '" alt="*" title="' . $txt['pmx_shoutbox_toggle'] . '" />
					<input id="shout_key' . $this->cfg['id'] . '" onclick="SendShout(' . $this->cfg['id'] . ', ' . intval(!empty($this->cfg['config']['settings']['boxcollapse'])) . ')" class="button_submit shoutbutton" type="button" name="button" value="' . (!empty($this->cfg['config']['settings']['boxcollapse']) ? $txt['pmx_shoutbox_button_open'] : $txt['pmx_shoutbox_button']) . '" title="' . (!empty($this->cfg['config']['settings']['boxcollapse']) ? $txt['pmx_shoutbox_button_title'] : $txt['pmx_shoutbox_send_title']) . '" />
				</div>
			</div>';
            }
        }
    }