{include file="$admingentemplates/admin_top.tpl"}
<div class="back">
    <a href="{$site_url}{$site_root}/admin/admin_settings.php">{$lang.button.back}</a>
</div>
<div class="cr"></div>

<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$lang.admin_menu.shoutbox}</div>
<div class="cr">&nbsp;</div>
<div class="cr">&nbsp;</div>
<div class="help_text" style="display:block;">
    <div class="close_help">
        <img src="{$site_root}{$template_root}/images/close_help.png" alt="">
    </div>
    <div class="help_body">
        <span class="help_title">{$lang.help}:</span>{$lang.admin_help.shoutbox_list}
    </div>
</div>
<div>
<form method="POST" action="{$file_name}?sel=save_set" class="settings_form" name="settings_form" id="settings_form">
		<table cellspacing="0" cellpadding="5" border="0">
			<tbody><tr>
				<td nowrap="" align="left" width="auto" style="margin-right:10px;padding-left:0px;" class="main_header_text">{$lang.settings.use_shoutbox_feature}:&nbsp;</td>
				<td align="center" class="main_content_text"><input type="checkbox" {if $data.use_shoutbox_feature}checked{/if} value="1" id="use_shoutbox_feature" class="use_shoutbox_feature" name="use_shoutbox_feature"></td>
				<td align="left">
					<div class="error_box_blue" id="error_box"></div>
				</td>
			</tr>
		</tbody></table>
</form>
</div>
		<script language="JavaScript" type="text/javascript">
		{literal}
			var options = { 
				success: function(data){
					ShowAjaxError(data, '', 'success');
					return false;
				},
				beforeSubmit: function() { 
					ajaxIndicator(1, 'error_box');
				}
			};
			$(document).ready(function(){
				$("#use_shoutbox_feature").change(function (){
					$('.settings_form').ajaxSubmit(options);
					return false;
				});
			});
		{/literal}
		</script>
<table cellpadding="0" cellspacing="0">
<tr>
	<td>{$lang.shoutbox.total_mess}: <b>{$stat.total_mess}</b></td>
</tr>
<tr>
	<td>{$lang.shoutbox.most_active}: <b><a href="{$stat.ma_profile_link}">{$stat.ma_login}</a></b></td>
</tr>
</table>
<br />
<div id="tooltip" onclick="hideToolTip()" style="text-align:center; background-color: #FFFFFF; border: 1px dotted; text-align: {$default_left}; position:absolute; display:none; padding:5px;"></div>
{literal}
<script type="text/javascript">
$(function() {
$('#tool_tip_4 *').tooltip();
});
</script>
{/literal}
<table border=0 cellspacing=0 cellpadding=0 width="100%">
<tr class="table_header" id="id_tr_main"  style="color:white;{if !$shoutbox}display:none;{/if}">
	<td align="left">{$lang.shoutbox.user}</td>
	<td align="left">{$lang.shoutbox.message}</td>
	<td align="center">{$lang.shoutbox.date}</td>
	<td align="right" style="padding-right:10px;">{$lang.button.action}</td>
</tr>
{foreach name=s from=$shoutbox item=item}
<tr {if $smarty.foreach.s.iteration mod 2 eq 0}class="even"{else}class="odd"{/if} id="tr{$smarty.foreach.s.iteration}">
	<td align="left" style="padding-left:20px;"><a href="{$item.profile_link}">{$item.login}</a></td>
	<td>
		<span id="id_result{$smarty.foreach.s.iteration}"></span><span id="text{$smarty.foreach.s.iteration}">{$item.text}</span><span id="editor{$smarty.foreach.s.iteration}" style="display:none;"><form><textarea id="formtext{$smarty.foreach.s.iteration}">{$item.text}</textarea><input type="hidden" id="id_id{$smarty.foreach.s.iteration}" value="{$item.id}" /></form></span>
	</td>
	<td align="center">{$item.date_add}</td>
	<td style="white-space:nowrap;width:150px;padding-right:10px;">
		<div class="block_action fr" style="display: none;">
			<div class="action_del" style="display: block;cursor:pointer;">
				<img width="16" alt="" src="{$site_root}{$template_root}/images/photo_delete.png" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.delete}');return false" onclick="deleteMessage({$smarty.foreach.s.iteration});">
			</div>
		</div>			
		<div class="block_action fr" style="display: none;">
			<div class="action_save" style="display: block;cursor:pointer;">
				<img width="16" alt="" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.save}');return false" src="{$site_root}{$template_root}/images/success.png" id="save{$smarty.foreach.s.iteration}" onclick="SubmitForm({$smarty.foreach.s.iteration});" style="display:none;">
			</div>
		</div>			
		<div style="width:10px;float:right;" class="fl">&nbsp;</div>
		<div class="block_action fr" style="display: none;">
			<div class="action_edit" style="display: block;cursor:pointer;">
				<img width="16" alt="" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.edit}');return false" src="{$site_root}{$template_root}/images/edit.png" id="edit{$smarty.foreach.s.iteration}" onclick="javascript: ShowEditor('{$smarty.foreach.s.iteration}'); return false;">
			</div>
		</div>
	</td>
</tr>
{foreachelse}
	<tr height="40">
		<td class="main_error_text" align="left" colspan="4">{$lang.shoutbox.no_messages}</td>
	</tr>
{/foreach}
<input type="hidden" name="scount" id="id_count" value="{$smarty.foreach.s.iteration}" />
<tr class="table_header"><td colspan="4">&nbsp;</td></tr>
</table>
<script type="text/javascript">
{literal}
		function showToolTip(e,text){
			if(document.all)e = event;
			var obj = document.getElementById('tooltip');
			obj.innerHTML = text;
			obj.style.display = 'block';
			var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
			if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0;
			var leftPos = e.clientX - $('#tooltip').width()-10;
			if(leftPos<0)leftPos = 0;
			obj.style.left = leftPos + 'px';
			obj.style.top = e.clientY - obj.offsetHeight -10 + st + 'px';
		}
		function hideToolTip(){
			document.getElementById('tooltip').style.display = 'none';
		}
{/literal}		
</script>
<div id="id_error" class="error_msg" {if !$form.error} style="display:none;"{/if}>* {$form.error}</div><br />
<form action="{$file_name}" name="limit_form" method="post" enctype="multipart/form-data">
	{$form.hiddens}
	<table cellpadding="0" cellspacing="0" width="100%">
		<tr>
			<td>{$lang.shoutbox.mess_limit}: <input type="text" name="limit" id="id_limit" value="{$limit}" size="3" onkeyup="javascript: checkLimit(this);"/> 
				<a href="javascript:void(0)" id="save_button" class="admin_button_major" onclick="saveLimit();">{$lang.button.save}<span>&nbsp;</span></a>
			</td>
		</tr>
	</table>
</form>
<script type="text/javascript">
	file_name = './{$file_name}';
	{literal}
	function ajaxRequestShoutbox(file_name, str, destination_odj, tmp_text, anisochronous){
	  if (str != '') {
		str = str+'&ajax=1';
		InitXMLHttpRequest();
		if (req) {
		  if (anisochronous){
			req.onreadystatechange = function() {
			  if (req.readyState == 4) {
				error_display(req.responseText);
			  } else {
				destination_odj.innerHTML = tmp_text;
			  }
			}
		  }
		  req.open("POST", file_name+'?rnd='+Math.random(), anisochronous);
		  req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8 ');
		  req.setRequestHeader("Content-length", str.length);
			  req.setRequestHeader("Connection", "close");
		  req.send(str);
		  if (!anisochronous) error_display(req.responseText);//RunJS(destination_odj,req.responseText);
		} else {
		  destination_odj.innerHTML = 'Browser unable to create XMLHttp Object';
		}
	  } else {
		destination_odj.innerHTML = "no string";
	  }
	}
	function error_display(text){
				var parent = document.getElementById('right_panel');
				var newDiv = document.createElement('div');
				newDiv.id = 'error_message';
				newDiv.style.border = '1px solid #D82B2B';
				newDiv.style.background = 'none repeat scroll 0 0 #FFFFAA';
				newDiv.style.color = '#000';
				newDiv.style.fontSize = '13px';
				newDiv.style.fontWeight = 'bold';
				newDiv.style.padding = '20px';
				newDiv.style.position = 'absolute';
				newDiv.style.top = '2px';
				newDiv.style.left = '600px';
				var text_dis = text;
				var textNode = document.createTextNode(text_dis);
				newDiv.appendChild(textNode);
				parent.appendChild(newDiv);
				setTimeout("document.getElementById('error_message').style.display = 'none';", 5000);  
	}
	function checkLimit(lim_obj){
		save_butt = document.getElementById('save_button');
		if (lim_obj.value != '')
			lim_obj.value = parseInt(lim_obj.value);
		if (isNaN(lim_obj.value)){
			lim_obj.value = '';
			save_butt.disabled = true;
		}else
			save_butt.disabled = false;
		if (lim_obj.value == '')
			save_butt.disabled = true;
	}

	function saveLimit(){
		var limit = parseInt($('#id_limit').val());
		if(limit){
			$.post('',{sel:'save_limit', limit: limit}, function(resp){ShowAjaxError(resp.msg)}, 'json');
		}
	}

	count = document.getElementById('id_count').value;
	function ShowEditor(id_line)
	{
		resetFields();
		document.getElementById('text'+id_line).style.display = 'none';
		document.getElementById('edit'+id_line).style.display = 'none';
		document.getElementById('editor'+id_line).style.display = 'inline';
		document.getElementById('save'+id_line).style.display = 'inline';
		document.getElementById('id_result'+id_line).style.display = 'none';
	}

	function resetFields(){
		for(i=1;i<=count;i++){
			document.getElementById('text'+i).style.display = 'inline';
			document.getElementById('edit'+i).style.display = 'inline';
			document.getElementById('editor'+i).style.display = 'none';
			document.getElementById('save'+i).style.display = 'none';
		}
	}

	function SubmitForm(id_line){
		resetFields();

		result_obj = document.getElementById('id_result'+id_line);
		result_obj.style.display = 'inline';

		id = document.getElementById('id_id'+id_line).value;

		text = document.getElementById('formtext'+id_line).value;
		document.getElementById('text'+id_line).innerHTML = text;

		str = 'sel=save_text&id='+id+'&text='+text;

		ajaxRequestShoutbox(file_name, str, result_obj, '', 1);
	}

	function deleteMessage(id_line){
		result_obj = document.getElementById('id_error');
		result_obj.style.display = 'inline';
		result_obj.innerHTML = '';

		id = document.getElementById('id_id'+id_line).value;

		tr = document.getElementById('tr'+id_line);

		str = 'sel=delete&id='+id;
		ajaxRequest(file_name, str, result_obj, '', 1);

		tr.style.display='none';

		del_main = true;
		for(i=1;i<=count;i++){
			if (document.getElementById('tr'+i).style.display != 'none')
				del_main=false;
		}

		if (del_main){
			document.getElementById('id_tr_main').style.display='none';
			document.getElementById('tr_zero').style.display='';
		}
	}

{/literal}
</script>
{include file="$admingentemplates/admin_bottom.tpl"}