{include file="$gentemplates/$header_tpl"}
<div style="width:100%;">
	<h2>{$blog_info.title}</h2>
		
	{*if $form.err}
	<p class="error_msg">*&nbsp;{$form.err}</p>
	{/if*}
        
	{include file="$gentemplates/blog_menu.tpl"}
	{*if $form.blog_page ne '3'*}
		
			<div style="display:table; width:100%;">	
			
				<h3 class="p-b5"><a href="{$blog_info.blog_link}">{$blog_info.title}</a>
					{if $data.is_user eq '1'}
						<div style="">	
							<a style="margin-top:-24px;" class="edit-icon float_right" href="#" onclick="javascript: location='{$data.edit_link}'" title="{$lang.blog.edit_post}">&nbsp;</a>
							<a style="margin-top:-24px;" class="delete-icon float_right" href="#" onclick="javascript: location='{$data.delete_link}'" title="{$lang.blog.delete_post}">&nbsp;</a>
							<a style="margin-top:-24px;" class="addfav-icon float_right" href="#" onclick="javascript: location='{$site_root}/{$seo.blog}?sel=post'" title="{$lang.blog.blog_menu_3}">&nbsp;</a>	
						</div>
					{/if}
				</h3>
			</div>
	{*/if*}
	<p class="text_hidden">
		{$lang.blog.posted_at}&nbsp;{$data.creation_date}&nbsp;{$data.creation_time}{if $data.show eq 0}&nbsp;{$lang.blog.hidden_post}{/if}
	</p>
	
	<p class="text_head">{$data.title}</p>
	<div class="blog_body">
		<div class="wysiwyg_content">{$data.body}</div>
	</div>
	{if $data.can_comment eq '1' || $data.is_user eq '1'}
		<a href="#" onclick="ShowCommentForm('main');">{$lang.blog.add_comment}</a>
	

	<div class="blog_comment_add" id="comment_main_form" {if $form.edit eq 1 && $form.id_reply eq 'main'} style="display: inline;" {else} style="display: none;" {/if}>
		<form name="post_main_form" id="post_main_form" action="{$site_root}/{$seo.blog}?sel=save_comment" method="post" enctype="multipart/form-data">
			<p>
				{$lang.blog.comment_title}:<br />
				<input type="text" name="comment_title" id="comment_title" onkeyup="BadWords('comment_title');" value="{$data.comment_title}" maxlength="500"/>
                <div id="bad_div_comment_title" class="bad_div_left"></div>
				<input type="hidden" name="id_post" value="{$form.id_post}">
                                <input type="hidden" name="id_user_to" value="{$blog_info.id_user}">
			</p>
			<p>
				{$lang.blog.comment_body}:<br />

				{$redactor}
				<textarea id="comment_body" name="comment_body" class="redactor_normal"></textarea>
				<div id="bad_div_comment_body" class="bad_div_left"></div>
			</p>
			<p>
				<input type="submit" value="{$lang.blog.add_comment}">
			</p>
		</form>
	</div>
	{/if}
	{if $data.blog_comments ne 'empty'}
		<h3 class="p-b5">{$lang.blog.admin.comms}</h3>
		{section name=b loop=$data.blog_comments}		
			<div class="float_left" style="margin-{$default_right}: 10px;">
				{if $data.blog_comments[b].deleted eq '1'}
					<img src="{$form.default_icon}" class="imgcanvas" alt="">
				{else}
					{if $data.blog_comments[b].is_user eq 0}
						<a class="imgcanvas_container" href="{$data.blog_comments[b].profile_link}" target="_blank"><img src="{$data.blog_comments[b].comment_icon}" class="imgcanvas" alt=""></a>
					{else}
						<a class="imgcanvas_container"><img src="{$data.blog_comments[b].comment_icon}" class="imgcanvas" alt=""></a>
					{/if}
				{/if}
			</div>
			<div class="float_left">
				{if $data.blog_comments[b].deleted!='1'}
					<font class="text_head">{$data.blog_comments[b].title}</font>&nbsp;
					{$lang.blog.posted_by}&nbsp;
					{if $data.blog_comments[b].is_user eq 0}
						<a href="{$data.blog_comments[b].profile_link}" target="_blank">{$data.blog_comments[b].name}</a>
					{else}
						{$data.blog_comments[b].name}
					{/if}
				{else}
					{$lang.blog.no_title}
				{/if}
				<br />
				<span class="text_hidden">{$data.blog_comments[b].creation_date}&nbsp;{$data.blog_comments[b].creation_time}</span>
				<div {if $data.blog_comments[b].deleted eq '1'}class="error_msg"{/if}><div class="wysiwyg_content">{$data.blog_comments[b].body}</div></div>
				{if $data.blog_comments[b].deleted ne '1'}
					<p>
						{if $data.can_comment}
							<a href="#" onclick="ShowCommentForm('{$data.blog_comments[b].id}');">
								{$lang.blog.leave_reply}
							</a>&nbsp;
						{/if}
						{if $data.blog_comments[b].can_edit eq 1}
							|&nbsp;<a href="{$data.blog_comments[b].delete_link}">{$lang.blog.delete_comment}</a>
						{/if}
					</p>
				{/if}
			</div>
			<div style="clear:both"></div>
			<div  class="blog_comment_add" id="comment_form_{$data.blog_comments[b].id}" {if $form.edit eq 1 && $form.id_reply eq $data.blog_comments[b].id} style="display: inline;" {else} style="display: none;" {/if}>
				<form name="post_form_{$data.blog_comments[b].id}" id="post_form_{$data.blog_comments[b].id}" action="{$site_root}/{$seo.blog}?sel=save_comment&id_reply={$data.blog_comments[b].id}&id_user_to={$blog_info.id_user}" method="post" enctype="multipart/form-data">
					<p>
						{$lang.blog.comment_title}:<br />
						<input type="text" name="comment_title" id="comment_title_1" onkeyup="BadWords('comment_title_1');" value="{$data.comment_title}" style="width: 150px" maxlength="500">
						<div id="bad_div_comment_title_1" class="bad_div_left"></div>
						<input type="hidden" name="id_post" value="{$form.id_post}">
					</p>
					<p>
						{$lang.blog.comment_body}:<br />
						{*$data.blog_comments[b].editor*}
						
						{$data.blog_comments[b].redactor}
						<textarea id="comment_body_{$data.blog_comments[b].id}" name="comment_body_{$data.blog_comments[b].id}" class="redactor_normal"></textarea>
						<div id="bad_div_comment_body_{$data.blog_comments[b].id}" class="bad_div_left"></div>
					</p>
					<p>
						<input type="submit" value="{$lang.button.save}">
					</p>
				</form>
				
			</div>
			{if $data.blog_comments[b].sub_comments !=''}
				{foreach item=item name=item from=$data.blog_comments[b].sub_comments}
				<p>
					<div class="float_left" style="margin-{$default_right}: 10px;">
						{if $item.deleted eq '1'}
							<img src="{$form.default_icon}" class="imgcanvas" alt="">
						{else}
							{if $item.is_user eq 0}
								<a class="imgcanvas_container" href="{$item.profile_link}" target="_blank"><img src="{$item.comment_icon}" class="imgcanvas" alt=""></a>
							{else}
								<a class="imgcanvas_container"><img src="{$item.comment_icon}" class="imgcanvas" alt=""></a>
							{/if}
						{/if}
					</div>
					<div class="float_left">
						{if $item.title}<font class="text_head">{$item.title}</font>&nbsp;
							{$lang.blog.posted_by}&nbsp;
							{if $item.is_user eq 0}
								<a href="{$item.profile_link}" target="_blank">{$item.login}</a>
							{else}
								{$item.login}
							{/if}	
						{else}
							{$lang.blog.no_title}
						{/if}<br />
						<span class="text_hidden">{$item.creation_date}&nbsp;{$item.creation_time}</span><br />
						<p {if $item.deleted eq '1'} class="error_msg" {/if}>{$item.body}</p>
						{if $item.deleted ne '1'}
						<p>
							{if $data.can_comment}<span class="link" onclick="ShowCommentForm('{$item.id}');" style="text-decoration: underline; cursor: pointer;">{$lang.blog.leave_reply}</span>&nbsp;|&nbsp;{/if}{if $item.can_edit eq 1}<a href="{$item.delete_link}">{$lang.blog.delete_comment}</a>{/if}
						</p>
						{/if}
					</div>
				</p>
				<div style="clear:both"></div>
				<div id="comment_form_{$item.id}" {if $form.edit eq 1 && $form.id_reply eq $item.id} style="display: inline;" {else} style="display: none;" {/if}>
				<form name="post_form_{$item.id}" id="post_form_{$item.id}" action="{$site_root}/{$seo.blog}?sel=save_comment&id_reply={$item.id}&id_user_to={$blog_info.id_user}" method="post" enctype="multipart/form-data">
					<p>
						{$lang.blog.comment_title}:<br />
						<input type="text" name="comment_title" id="comment_title" onkeyup="BadWords('comment_title');" value="{$data.comment_title}" style="width: 150px" maxlength="500"/>
                        <div id="bad_div_comment_title" class="bad_div_left"></div>
						<input type="hidden" name="id_post" value="{$form.id_post}"/>
					</p>
					<p>
						{$lang.blog.comment_body}:<br />
						{$item.redactor}
						<textarea id="comment_body_{$item.id}" name="comment_body_{$item.id}" class="redactor_normal"></textarea>
						<div id="bad_div_comment_body_{$item.id}" class="bad_div_left"></div>
					</p>
					<p>
						<input type="submit" value="{$lang.button.save}" class="button">
					</p>
				</form>
				</div>
				{/foreach}
			{/if}
		<p></p>
		{/section}
		
		{if $links}
			<p>
				{foreach item=item from=$links}
					<div class="page_div{if $item.selected eq '1'}_active{/if}">
						<div style="margin: 5px"><a href="{$item.link}" class="page_link{if $item.selected eq '1'}_active{/if}">{$item.name}</a></div>
					</div>
				{/foreach}
			</p>
		{/if}
	{/if}
	{* {if $banner.right}<div style="float: left;">{$banner.right}</div>{/if}	*}				
{literal}
<script type="text/javascript">
function ShowCommentForm(par) {
	if (par == 'main') {
		document.getElementById('comment_main_form').style.display = 'inline';
		document.getElementById('post_main_form').comment_title.value = '';
		document.getElementById('post_main_form').comment_body.value = '';
		{/literal}
		{section name=b loop=$data.blog_comments}
			document.getElementById('comment_form_{$data.blog_comments[b].id}').style.display = 'none';
			document.getElementById('post_form_{$data.blog_comments[b].id}').comment_title.value = '';
			document.getElementById('post_form_{$data.blog_comments[b].id}').comment_body_{$data.blog_comments[b].id}.value = '';
			{foreach item=item from=$data.blog_comments[b].sub_comments}
				document.getElementById('comment_form_{$item.id}').style.display = 'none';
				document.getElementById('post_form_{$item.id}').comment_title.value = '';
				document.getElementById('post_form_{$item.id}').comment_body_{$item.id}.value = '';
			{/foreach}
		{/section}
		{literal}
	} else {
		document.getElementById('comment_main_form').style.display = 'none';
		document.getElementById('post_main_form').comment_title.value = '';
		document.getElementById('post_main_form').comment_body.value = '';
		{/literal}
		{section name=b loop=$data.blog_comments}
			document.getElementById('post_form_{$data.blog_comments[b].id}').comment_title.value = '';
			document.getElementById('post_form_{$data.blog_comments[b].id}').comment_body_{$data.blog_comments[b].id}.value = '';
			{literal}
			if (par == {/literal}{$data.blog_comments[b].id}{literal}){
				document.getElementById('comment_body_{/literal}{$data.blog_comments[b].id}{literal}').value = '';
				document.getElementById('comment_form_{/literal}{$data.blog_comments[b].id}{literal}').style.display = 'inline';
			} else {
				document.getElementById('comment_body_{/literal}{$data.blog_comments[b].id}{literal}').value = '';
				document.getElementById('comment_form_{/literal}{$data.blog_comments[b].id}{literal}').style.display = 'none';
			}
			{/literal}
			{foreach item=item from=$data.blog_comments[b].sub_comments}
			document.getElementById('post_form_{$item.id}').comment_title.value = '';
			document.getElementById('post_form_{$item.id}').comment_body_{$item.id}.value = '';
			{literal}
			if (par == {/literal}{$item.id}{literal}){
				document.getElementById('comment_form_{/literal}{$item.id}{literal}').style.display = 'inline';
			} else {
				document.getElementById('comment_form_{/literal}{$item.id}{literal}').style.display = 'none';
			}
			{/literal}
			{/foreach}
		{/section}
		{literal}
	}
	return;
}

// Startup variables
var imageTag = false;
var theSelection = false;
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;

var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);

bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[url]','[/url]');
imageTag = false;

// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

function bbstyle(bbnumber, par) {
	if (par == 'main') {
		var txtarea = document.post_main_form.comment_body;
	} else {
		{/literal}
		{section name=b loop=$data.blog_comments}
			{literal}
			if (par == '{/literal}{$data.blog_comments[b].id}{literal}'){
				var txtarea = document.post_form_{/literal}{$data.blog_comments[b].id}{literal}.comment_body;
			}
			{/literal}
			{foreach item=item from=$data.blog_comments[b].sub_comments}
			{literal}
			if (par == '{/literal}{$item.id}{literal}'){
				var txtarea = document.post_form_{/literal}{$item.id}{literal}.comment_body;
			}
			{/literal}
			{/foreach}
		{/section}
		{literal}
	}

	txtarea.focus();
	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {
			// Add tags around selection
			document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
			txtarea.focus();
			theSelection = '';
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
		return;
	}

	// Find last occurance of an open tag the same as the one just clicked
	for (i = 0; i < bbcode.length; i++) {
		if (bbcode[i] == bbnumber+1) {
			bblast = i;
			donotinsert = true;
		}
	}

	if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];
				if (par == 'main') {
					buttext = eval('document.post_main_form.addbbcode' + butnumber + '.value');
				} else {
					buttext = eval('document.post_form_'+ par +'.addbbcode' + butnumber + '.value');
				}
				tobtn = buttext.substr(0, 1) + buttext.substr(2,buttext.length);
				if (par == 'main') {
					eval('document.post_main_form.addbbcode' + butnumber + '.value ="' + tobtn + '"');
				} else {
					eval('document.post_form_'+ par +'.addbbcode' + butnumber + '.value ="' + tobtn + '"');
				}

				imageTag = false;
			}
			txtarea.focus();
			return;
	} else { // Open tags

		txtarea.value += bbtags[bbnumber];
		arraypush(bbcode,bbnumber+1);
		if (par == 'main') {
			eval('document.post_main_form.addbbcode'+bbnumber+'.value = "' +bbtags[bbnumber+1]+ '"');
		} else {
			eval('document.post_form_'+ par +'.addbbcode'+bbnumber+'.value = "' +bbtags[bbnumber+1]+ '"');
		}
		txtarea.focus();
		return;
	}
	storeCaret(txtarea);
}

// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}

// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}


//-->
</script>
{/literal}
{include file="$gentemplates/$footer_tpl"}