<?php
/** @var Psr\Container\ContainerInterface $container */
$container = App::getContainer();

/** @var Johncms\Api\UserInterface $systemUser */
$systemUser = $container->get(Johncms\Api\UserInterface::class);

/** @var Johncms\Api\ConfigInterface $config */
$config = $container->get(Johncms\Api\ConfigInterface::class);

/** @var Johncms\Api\BbcodeInterface $bbcode */
$bbcode = $container->get(Johncms\Api\BbcodeInterface::class);

/** @var Johncms\Counters $counters */
$counters = $container->get('counters');

$userConfig = $systemUser->getConfig();


echo '<div class="Block">
        <div class="Block-tl"></div>
        <div class="Block-tr"></div>
        <div class="Block-bl"></div>
        <div class="Block-br"></div>
        <div class="Block-tc"></div>
        <div class="Block-bc"></div>
        <div class="Block-cl"></div>
        <div class="Block-cr"></div>
        <div class="Block-cc"></div>
        <div class="Block-body">
            <div class="BlockHeader">
                <div class="l"></div>
                <div class="r"></div>
                <div class="header-tag-icon">';
                echo '<div class="t"><i class="icon-comment-alt"></i> ChatBox</div>';
            echo '</div>
            </div><div class="BlockContent">
                    <div class="BlockContent-tl"></div>
                    <div class="BlockContent-tr"></div>
                    <div class="BlockContent-bl"></div>
                    <div class="BlockContent-br"></div>
                    <div class="BlockContent-tc"></div>
                    <div class="BlockContent-bc"></div>
                    <div class="BlockContent-cl"></div>
                    <div class="BlockContent-cr"></div>
                    <div class="BlockContent-cc"></div>
                    <div class="BlockContent-body">
                <div>';
 
if ($systemUser->isValid() && $userConfig->chatbox) {
//echo '<div class="mainblok">';
echo '<script type="text/javascript" src="' . $config['homeurl'] . '/system/plugin/src/Js/Jquery.js"></script><script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>';
echo '<script type="text/javascript" src="' . $config['homeurl'] . '/system/plugin/src/Js/chat.js"></script>';
//echo '<div class="phdr"><i class="icon-comment-alt"></i> ChatBox</div>';
echo '<div class="topmenu"><a href="' . $config['homeurl'] . '/guestbook/index.php">Guestbook</a></div>';

echo '<script language="JavaScript" type="text/javascript">
function tag(text1, text2) {
if ((document.selection)) {
document.form.msg.focus();
document.form.document.selection.createRange().text = text1+document.form.document.selection.createRange().text+text2;
} else if(document.forms[\'form\'].elements[\'msg\'].selectionStart!=undefined) {
var element = document.forms[\'form\'].elements[\'msg\'];
var str = element.value;
var start = element.selectionStart;
var length = element.selectionEnd - element.selectionStart;
element.value = str.substr(0, start) + text1 + str.substr(start, length) + text2 + str.substr(start + length);
} else {
document.form.msg.value += text1+text2;
}
}

function show_hide(elem) {
              obj = document.getElementById(elem);
              if( obj.style.display == "none" ) {
                obj.style.display = "block";
              } else {
                obj.style.display = "none";
              }
            }
</script>';
$refer = base64_encode($_SERVER['REQUEST_URI']);
$token = mt_rand(1000, 100000);
$_SESSION['token'] = $token;
//echo '<div class="gmenu">';
echo $bbcode->buttons('form', 'msg');
echo '<form id="form" action="" method="POST">
<textarea cols="5" rows="5" placeholder="Post messages" placeholder="Chat comment" id="postText" name="msg" class="form-control"></textarea>';


echo '<span class="button-wrapper">
                    <span class="l"> </span>
                    <span class="r"> </span>
				<button class="button" type="submit" name="submit" id="submit">Send</button></span>';


//echo '<button name="submit" type="submit" id="submit" class="aan-blue">Send</button>';

echo '<input type="hidden" name="token" value="' . $token . '"/>
</form>';
//echo '</div>';
echo '<div id="alert"></div><div id="postText"></div><div id="idChat"></div>';

echo '<div class="topmenu"><br/></div>';
//echo '</div>';
}


echo '</div>
            <div class="cleared"></div>
				   </div>
				  </div>
<div class="cleared"></div>
        </div>
</div>';
?>


