<!-- edit listing -->

{rlHook name='editListingTop'}

<script type="text/javascript" src="{$smarty.const.RL_LIBS_URL}jquery/numeric.js"></script>
<script type="text/javascript" src="{$smarty.const.RL_LIBS_URL}jquery/jquery.qtip.js"></script>
<script type="text/javascript">flynax.qtip(); flynax.phoneField();</script>
<script type="text/javascript" src="{$smarty.const.RL_LIBS_URL}jquery/jquery.textareaCounter.js"></script>
<script type="text/javascript" src="{$smarty.const.RL_LIBS_URL}ckeditor/ckeditor.js"></script>

<!-- listing fieldset -->
{if !empty($form)}
<div class="content-padding">
	<form method="post" action="{$rlBase}{if $config.mod_rewrite}{$pageInfo.Path}.html?id={$smarty.get.id}{else}?page={$pageInfo.Path}&amp;id={$smarty.get.id}{/if}" enctype="multipart/form-data">
		<input type="hidden" name="action" value="edit" />
		<input type="hidden" name="fromPost" value="1" />
		
		<!-- crossed categories -->
		{if $plan_info.Cross}
			<input type="hidden" name="crossed_done" value="{if $smarty.session.edit_listing.crossed_done}1{/if}" />
		
			{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_header.tpl' id='crossed' name=$lang.crossed_categories}
			<div class="auth" style="margin-top: 0;">
				<div style="padding: 0 0 10px 0;">
					<div class="dark" id="cc_text">{$lang.crossed_top_text|replace:'[number]':'<b id="cc_number"></b>'}</div>
					<div class="dark hide" id="cc_text_denied">{$lang.crossed_top_text_denied}</div>
				</div>
				
				<!-- print sections/categories tree -->
				<div id="crossed_tree" class="tree{if $smarty.post.crossed_done} hide{/if}">
				{foreach from=$crossed_sections item='crossed_section'}
					{assign var='type_page_key' value='lt_'|cat:$crossed_section.Key}
					{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_header.tpl' name=$crossed_section.name}
				
					{if !empty($crossed_section.Categories)}
						{include file='blocks'|cat:$smarty.const.RL_DS|cat:'category_level_crossed.tpl' categories=$crossed_section.Categories first=true}
					{else}
						<div class="dark">{$lang.no_items_in_sections}</div>
					{/if}
			
					{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_footer.tpl'}
				{/foreach}
				</div>
				<!-- print sections/categories tree end -->
				
				<ul class="hide" id="crossed_selected"><li class="first dark"><b>{$lang.selected_crossed_categories}</b></li></ul>
				<input id="crossed_button" type="button" value="{if $smarty.post.crossed_done}{$lang.manage}{else}{$lang.done}{/if}" />
			</div>
			{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_footer.tpl'}
			
			<script type="text/javascript">
			var plans = Array();
			var selected_plan_id = {if $plan_info.ID}{$plan_info.ID}{else}0{/if};
			var ca_post = {if $crossed}[{foreach from=$crossed item='crossed_cat' name='crossedF'}['{$crossed_cat}']{if !$smarty.foreach.crossedF.last},{/if}{/foreach}]{else}false{/if};
			var cc_parentPoints = {if $parentPointsCrossed}[{foreach from=$parentPointsCrossed item='parent_point' name='parentF'}['{$parent_point}']{if !$smarty.foreach.parentF.last},{/if}{/foreach}]{else}false{/if};

			plans[{$plan_info.ID}] = new Array();
			plans[{$plan_info.ID}]['Key'] = '{$plan_info.Key}';
			plans[{$plan_info.ID}]['Cross'] = {$plan_info.Cross};
			
			{literal}
			
			$(document).ready(function(){
				flynax.treeLoadLevel('crossed', 'crossedTree');
				crossedTree(true, true);
			});
			
			{/literal}
			</script>
			<script type="text/javascript" src="{$smarty.const.RL_LIBS_URL}javascript/crossed.js"></script>
		{/if}
		<!-- crossed categories end -->
		
		<!-- print sections/categories tree -->
		<div id="change_category_options" class="hide">
		{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_header.tpl' id='crossed' name=$lang.select_category}
			<div class="area_category step_area content-padding">
				{if !$sections}
					{$lang.add_listing_deny}
				{else}
					<div class="info">{$lang.edit_listing_notice}</div>

					<ul class="select-type hide">
						{foreach from=$sections item='section' name='sectionsF'}{strip}
							<li><label><input {if $smarty.foreach.sectionsF.first}checked="checked"{/if} type="radio" name="section" value="{$section.Key}"> {$section.name}</label></li>							
						{/strip}{/foreach}
					</ul>

					<ul class="select-category">
						{foreach from=$sections item='section' name='sectionsF'}{strip}
							<li id="type_section_{$section.Key}" class="{if !$smarty.foreach.sectionsF.first}hide{/if}">
								{if !empty($section.Categories)}
									{include file='blocks'|cat:$smarty.const.RL_DS|cat:'category_level.tpl' categories=$section.Categories first=true}
								{else}
									<div><select disabled="disabled"><option value="">{$lang.no_items_in_sections}</option></select></div>
								{/if}
							</li>
						{/strip}{/foreach}
					</ul>

					<div class="form-buttons">
					<input id="apply_category_changes" class="low" type="button" value="{$lang.change}" />
					<span class="cancel red margin">{$lang.cancel}</span>
					</div>

					<script>
					var ct_selectedType = '{$category.Type}';
					var ct_selectedID = '{$category.ID}';
					var ct_parentPoints = [{foreach from=$parentPoints item='parent_point' name='parentF'}'{$parent_point}'{if !$smarty.foreach.parentF.last},{/if}{/foreach}];

					{literal}
					
					var OnCategorySelect = function(id, name){
						$('input[name=edit_category]').val(id);
					}

					$(document).ready(function(){
						flynax.treeLoadLevel();

						if ( ct_selectedType ) {
							$('ul.select-type input[value='+ct_selectedType+']').trigger('click');
						}

						$('ul.select-type input:checked').trigger('click');	
					});
					
					{/literal}
					</script>
				{/if}
			</div>
		{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_footer.tpl'}
		</div>
		<!-- print sections/categories tree end -->

		<!-- plan info -->
		{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_header.tpl' id='plan_information' name=$lang.plan_detals}
		
		{if $plan_info}
		<div class="table-cell">
			<div class="name"><div><span>{$lang.plan}</span></div></div>
			<div class="field">{$plan_info.name} / {strip} 
				{if $listing_data.Plan_type == 'account'}
					<a href="{$rlBase}{if $config.mod_rewrite}{$pages.my_profile}/purchase.html{else}?page={$pages.my_profile}&amp;purchase{/if}">{$lang.change_plan}</a>
				{else}
					<a href="{$rlBase}{if $config.mod_rewrite}{$pages.upgrade_listing}.html?id={$smarty.get.id}{else}?page={$pages.upgrade_listing}&amp;id={$smarty.get.id}{/if}">{$lang.change}</a>
				{/if}{/strip}
			</div>
		</div>
		{/if}
		<div class="table-cell">
			<div class="name"><div><span>{$lang.category}</span></div></div>
			<div class="field">
				<span id="change_category_origin">
					<span>{$category.name}</span> <span> / <a class="brown_12" href="javascript:void(0);">{$lang.change}</a></span>
				</span>

				<input name="edit_category" type="hidden" value="{$category.ID}" />
				<script type="text/javascript">
				
				{literal}
				var post_update_js = "$('#change_category_options').fadeOut('fast', function(){ $('#change_category_origin').fadeIn(); });";
				post_update_js += "$('#change_category_origin > span:eq(0)').html('[cat_name]');";
				post_update_js += "$('#apply_category_changes').val('{/literal}{$lang.change}{literal}');";
				post_update_js += "$('#change_category_origin span:eq(1)').fadeIn();";				

				$(document).ready(function(){
					$('#change_category_origin a').click(function(){
					$('#change_category_origin span:eq(1)').fadeOut('fast', function(){
							$('#change_category_options').fadeIn();
						});
					});
					$('#change_category_options span.cancel').click(function(){
						$('#change_category_options').fadeOut('fast', function(){
						$('#change_category_origin span:eq(1)').fadeIn();
							$('select[name=edit_category] option[selected=selected]').attr('selected', true);
						});
					});
					
					$('#apply_category_changes').flModal({
						caption: '{/literal}{$lang.notice}{literal}',
						content: '{/literal}{$lang.notice_change_listing_category}{literal}',
						prompt: 'xajax_changeListingCategory({/literal}{$listing_data.ID}{literal}, $("input[name=edit_category]").val(), post_update_js);$("#apply_category_changes").val("'+lang['loading']+'");',
						width: 'auto',
						height: 'auto'
					});
				});
				
				{/literal}
				</script>
			</div>
		</div>
		{if $listing_type.Photo && ($plan_info.Image || $plan_info.Image_unlim)}
		<div class="table-cell">
			<div class="name"><div><span>{$lang.listing_photos}</span></div></div>
			<div class="field">{if $plan_info.Image_unlim}{$lang.unlimited}{else}{$plan_info.Image}{/if} / <a class="brown_12" href="{$rlBase}{if $config.mod_rewrite}{$pages.add_photo}.html?id={$smarty.get.id}{else}?page={$pages.add_photo}&amp;id={$smarty.get.id}{/if}">{$lang.manage_photos}</a></div>
		</div>
		{/if}
		{if $listing_type.Video && ($plan_info.Video || $plan_info.Video_unlim)}
		<div class="table-cell">
			<div class="name"><div><span>{$lang.listing_video}</span></div></div>
			<div class="field">{if $plan_info.Video_unlim}{$lang.unlimited}{else}{$plan_info.Video}{/if} / <a class="brown_12" href="{$rlBase}{if $config.mod_rewrite}{$pages.add_video}.html?id={$smarty.get.id}{else}?page={$pages.add_video}&amp;id={$smarty.get.id}{/if}">{$lang.manage_video}</a></div>
		</div>
		{/if}

		{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_footer.tpl'}
		<!-- plan info end -->
		
		{rlHook name='editListingPreFields'}
		
		{foreach from=$form item='group'}
		{if $group.Group_ID}
			{if $group.Fields && $group.Display}
				{assign var='hide' value=false}
			{else}
				{assign var='hide' value=true}
			{/if}

			{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_header.tpl' id=$group.Key name=$lang[$group.pName]}
			{if $group.Fields}
				{include file='blocks'|cat:$smarty.const.RL_DS|cat:'field.tpl' fields=$group.Fields}
			{else}
				{$lang.no_items_in_group}
			{/if}
			{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_footer.tpl'}
		{else}
			{include file='blocks'|cat:$smarty.const.RL_DS|cat:'field.tpl' fields=$group.Fields}
		{/if}
		{/foreach}

		{if $config.security_img_edit_listing}
			<div class="submit-cell">
				<div class="name">{$lang.security_code}</div>
				<div class="field">{include file='captcha.tpl' no_caption=true}</div>
			</div>
		{/if}

		<div class="submit-cell buttons">
			<div class="name"></div>
			<div class="field"><input type="submit" value="{$lang.edit}" /></div>
		</div>
	</form>
</div>
{/if}

<script type="text/javascript">
{literal}
$(document).ready(function(){
	$("input.numeric").numeric();
	flynax.mlTabs();
	flynax.phoneField();
	{/literal}{if $config.address_on_map}flynax.onMapHandler();{/if}{literal}
	flynaxTpl.locationHandler();
	flynaxTpl.realtyPropType();
});
{/literal}
</script>

{rlHook name='editListingBottomTpl'}

<!-- edit listing end -->