{include file="$gentemplates/$header_tpl"}
	{include file="$gentemplates/classified_menu.tpl"}

        <h3 class="p-b5">
            {if $id_object==0}{$lang.classified.new_ad}{else}{$lang.classified.edit_ad}{/if}
        </h3>
        <div class="classfields">
            <form name="add_object" action="{$form.action}" method="POST" enctype="multipart/form-data" onsubmit="javascript: return checkObjectForm();">
				{$form.hiddens}
				<div class="line">
					<div class="name_side">{$lang.classified.add_to_cat}:</div>
					<div class="float_left">
						<select name="id_root" style="width:305px" onchange="javascript: LoadCategoryForm({$id_object}, this.value, 'ado_form_div');">
							{foreach name=s item=item key=key from=$cats}
								<option value="{$item.id}" {if $item.id==$id_root} selected="selected"{/if}>{section name=s loop=$item.level-1}&nbsp;&nbsp;{/section}{$item.name}</option>
							{/foreach}
						</select>
					</div>
				</div>
				<div class="line">
					<div class="name_side">{$lang.common.subject}:</div>
					<div class="float_left">
						<input type="text" name="name" id="name" style="width:305px" onkeyup="BadWords('name');" value="{if isset($smarty.post.name)}{$smarty.post.name}{else}{$object.name}{/if}" />
                        <div id="bad_div_name" class="bad_div_left"></div>
					</div>
				</div>
				<div id="ado_form_div">
				{include file="$gentemplates/classified_ajax_form.tpl"}
				</div>
				<div class="line">
					<div class="name_side">{$lang.common.body}:</div>
					<div class="float_left">						
						<div>
							{$redactor}
							<textarea name="body" id="message" class="text_area redactor_normal">{*if isset($smarty.post.body)}{$smarty.post.body}{else}{$object.body|nl2br}{/if*}</textarea>
                            <div id="bad_div_message" class="bad_div_left"></div>
						</div>
					</div>
				</div>
				<div class="line">
					<input type="submit" value="{$lang.button.save}" class="button"/>&nbsp;
					<input type="button" value="{$lang.button.back}" class="button" onclick="javascript: location.href='{$back_link}'"/>
				</div>
			</form>
        </div>		
<script type="text/javascript" src="{$site_root}{$template_root}/js/classified.js"></script>
<script language="javascript" type="text/javascript">
{literal}
function checkObjectForm(){
	var form=document.add_object;
	var res=checkForm();
	if(res==false) return res;

	if(form.name.value==''){
		{/literal}
		alert("{$lang.err.empty_subject|escape:javascript}");
		form.name.focus();
		return false;
		{literal}
	}
	if(form.body.value==''){
		{/literal}
		alert("{$lang.err.empty_classbody|escape:javascript}");
		form.body.focus();
		return false;
		{literal}
	}
	return true;
	return true;
}
{/literal}
</script>
<script type="text/javascript">

var	smileLayer	= 0;

var	bbcode		= Array();
bbcode['b']		= Array('[b]', '[/b]');
bbcode['i']		= Array('[i]', '[/i]');
bbcode['u']		= Array('[u]', '[/u]');
bbcode['img']	= Array('[img]', '[/img]');
bbcode['url']	= Array('[url={$lang.forum.insert_link_url}]', '{$lang.forum.insert_link_name}[/url]');

bbcode['s1']	= Array(' :) ');
bbcode['s2']	= Array(' ;) ');
bbcode['s3']	= Array(' :D ');
bbcode['s4']	= Array(' 8) ');
bbcode['s5']	= Array(' :] ');
bbcode['s6']	= Array(' :O ');
bbcode['s7']	= Array(' :/ ');
bbcode['s8']	= Array(' :( ');
bbcode['s9']	= Array(' ;( ');
bbcode['s10']	= Array(' O_O ');

{literal}
function insertBB(code)
{
	var tag1 = typeof bbcode[code] != 'undefined' ? bbcode[code][0] : " "+code+" ";
	if (typeof bbcode[code] != 'undefined') {var tag2 = bbcode[code][1];}
	var txta = document.getElementById('message');
	txta.focus();
	
	if (typeof document.selection != 'undefined') {
		var range = document.selection.createRange();
		var sel = range.text;
		range.text = tag2 ? tag1 + sel + tag2 : tag1;
		range = document.selection.createRange();
		if (tag2 && !sel.length) range.move('character', -tag2.length);
		else if (tag2) range.move('character', tag1.length + sel.length + tag2.length);
		range.select();
	}
	else if (typeof txta.selectionStart != 'undefined') {
		var scroll = txta.scrollTop;
		var start  = txta.selectionStart;
		var end    = txta.selectionEnd;
		var before = txta.value.substring(0, start);
		var sel    = txta.value.substring(start, end);
		var after  = txta.value.substring(end, txta.textLength);
		txta.value = tag2 ? before + tag1 + sel + tag2 + after	: before + tag1 + after;
		var caret = sel.length == 0	? start + tag1.length : start + tag1.length + sel.length + tag2.length;
		txta.selectionStart = caret;
		txta.selectionEnd = caret;
		txta.scrollTop = scroll;
	}
	return false;
}

function displaySmileLayer()
{
	if (document.getElementById('smiles').style.display == 'none') {
		document.getElementById('smiles').style.display = 'block';
	} else {
		document.getElementById('smiles').style.display = 'none';
	}
	return false;
}
{/literal}
</script>
{include file="$gentemplates/$footer_tpl"}