{include file="header.tpl"}

<div id="sidebar">
{include file="sidebar.tpl"}
</div>

<div class="mainContent">

<h1>{$smarty.const.LISTING_HEADER}</h1>

{if $success}
	<p class="green"><strong>{$success}</strong></p>
{elseif $error_message}
	<p class="red"><strong>{$error_message}</strong></p>
{/if}

{if $viewsingle}
{foreach item="records" from=$singlelistdata}

<div class="desc">
	<h2 class="boxtitle">
	<span class="left"> {$records.year} {$records.make} {$records.model} </span>
	<span class="right"> {$records.listing_condition} </span> 
	</h2>
	
	<div class="boxcontent">
		<div class="descinfo">
			<div class="bigthumb">
			{if $largeIMG}
				<div class="center-align"><img id="mainimage" src="{if $records.sold}image.php?pic={/if}{$largeIMG}" alt="Selected Image" /></div>
			{elseif $records.images}
				{foreach item="image" from=$records.images}
					{if $image.mainimage}
						<div class="center-align"><img id="mainimage" src="{if $records.sold}image.php?pic={/if}{$image.imagepath}" alt="{if $image.imagepath}Main {/if}Image" /></div>
					{/if}
				{/foreach}
			{else}
				<div class="center-align"><img src="images/no_image.gif" alt="No Image" /></div>
			{/if}
			</div>
		
			<h3 class="subhead"> {$smarty.const.DETAILS} {$records.ad_title}.</h3>
			<p class="longtext">
			<strong>{$smarty.const.ADDDESC}</strong><br />
				{$records.adddesc|badwords}
			</p>
			<p class="longtext">
			{if $records.vehicle_type}
				<strong>{$smarty.const.TYPE}</strong> {$records.vehicle_type}<br />
			{/if}
			{if $records.doors}
				<strong>{$smarty.const.DOORS}</strong> {$records.doors}<br />
			{/if}
			{if $records.color}
				<strong>{$smarty.const.COLOR}</strong> {$records.color}<br />
			{/if}
			{if $records.mileage}
				<strong>{$smarty.const.MILEAGE}</strong> {$records.mileage|number_format:0:".":","}<br />
			{/if}
			{if $records.engine}
				<strong>{$smarty.const.ENGINE}</strong> {$records.engine}<br />
			{/if}
			{if $records.trans}
				<strong>{$smarty.const.TRANS}</strong> {$records.trans}<br />
			{/if}
			{if $records.drive_train}
				<strong>{$smarty.const.DRIVETRAIN}</strong> {$records.drive_train}<br />
			{/if}
			{if $records.mpg}
				<strong>{$smarty.const.MPG}</strong> {$records.mpg}<br />
			{/if}
			</p>

			<h3 class="subhead"> {$smarty.const.FEATURES}</h3>
			<ul>
			{foreach item="features" from=$featurelist}
				{foreach item="data" from=$records.features}
				{if $features.id eq $data}
					<li>{$features.features}</li>
				{/if}
				{/foreach}
			{/foreach}
			</ul>
			
			{if $sellerinfo}
			<h3 class="subhead"> {$smarty.const.SELLER_INFO}</h3>
			{foreach item="seller" from=$sellerinfo}
				<p class="longtext">{$seller.first_name} {$seller.last_name}
				</p>
			{/foreach}
			{/if}	

		</div>
		
		<div class="smallrightlist">
			<h2 class="center-align">{$smarty.const.PRICE} {$smarty.const.CURRENCY_SYMBOL}{$records.price|number_format:2:".":","}</h2>
			{foreach item="image" from=$records.images}
				<p><a href="listings.php?id={$records.id}&amp;largeIMG={$image.imagepath}"><img src="{if $records.sold}image.php?pic={/if}{$image.imagethumbpath}" onmouseover='mainimage.src=this.alt;' title="Image {counter}" alt="{if $records.sold}image.php?pic={/if}{$image.imagepath}" /></a>
				</p>
			{/foreach}
				<p class="button"><a href="contact.php?seller={$records.sellerid}&amp;record={$records.id}">{$smarty.const.LIST_LINK_CONTACT_SELLER}</a></p>
				<p class="button"><a href="paycalc.php?price={$records.price}">{$smarty.const.LIST_LINK_LOAN_CALC}</a></p>
				<p class="button"><a href="poster.php?id={$records.id}">{$smarty.const.LIST_LINK_PRINT_POSTER}</a></p>
				<!-- <p class="button"><a href="listings.php#">Send to a friend</a></p> -->
				{if $records.vin}
				<p class="center-align"><a href="http://www.carfax.com/cfm/ccc_DisplayHistoryRpt.cfm?partner=WDB_0&vin={$records.vin}"><img src='http://www.carfaxonline.com/img/new_blk_logo.gif' width='155' height='42' alt="" /></a></p>
				{/if}
			{if $records.sellerid eq $userdetails.0.id || $admin}
				<p class="button"><a href="editlisting.php?id={$records.id}">{$smarty.const.LIST_LINK_EDIT_THIS}</a></p>
			{/if}
		</div>		
	</div>
</div>
{/foreach}
{else}{*this is for general public viewing*}

<!-- tpl section for sort function
<p><span class="right">
Sort by Model:<a href="listings.php?action=sort&amp;type=model&amp;ASC=1"><img class="vertical-align" src="images/asc.jpg" title="Ascending" alt="Ascending" /></a><a href="listings.php?action=sort&amp;type=model&amp;DESC=1"><img class="vertical-align" src="images/desc.jpg" title="Descending" alt="Descending" /></a> 
Sort by Year:<a href="listings.php?action=sort&amp;type=year&amp;ASC=1"><img class="vertical-align" src="images/asc.jpg" title="Ascending" alt="Ascending" /></a><a href="listings.php?action=sort&amp;type=year&amp;DESC=1"><img class="vertical-align" src="images/desc.jpg" title="Descending" alt="Descending" /></a> 
Sort by Price:<a href="listings.php?action=sort&amp;type=price&amp;ASC=1"><img class="vertical-align" src="images/asc.jpg" title="Ascending" alt="Ascending" /></a><a href="listings.php?action=sort&amp;type=price&amp;DESC=1"><img class="vertical-align" src="images/desc.jpg" title="Descending" alt="Descending" /></a>
 </span> 
</p>
-->

<p>{* display pagination header *}
Items {$paginate.first} - {$paginate.last} of {$paginate.total} displayed.
</p>

{if !$listdata}
	<p class="red">{$smarty.const.REFINE_YOUR_SEARCH}</p>
{/if}

{foreach item="records" from=$listdata}
<div class="desc">
	<h2 class="boxtitle">
	<span class="left"> {$records.year} {$records.make} {$records.model} </span>
	<span class="right"> {$records.listing_condition} </span> 
	</h2>
	
	<div class="boxcontent">
		<div class="smallimagebox">
			{if $records.images}
				{foreach item="image" from=$records.images}
					{if $image.mainimage}
						<p><a href="listings.php?id={$records.id}"><img src="{if $records.sold}image.php?pic={/if}{$image.imagethumbpath}" alt="Image" /></a>
						</p>
					{/if}
				{/foreach}
			{else}
			<p><a href="listings.php?id={$records.id}"><img src="{if $records.sold}image.php?pic={/if}images/no_image.gif" alt="No Image" /></a>
			</p>
			{/if}
		</div>
		<p class="shorttext">
		{$smarty.const.ADDDESC} <br />
		{$records.adddesc|badwords}
		</p>
		<p class="right-align">
		{$smarty.const.CURRENCY_SYMBOL}{$records.price|number_format:2:".":","}<br />
		<a href="listings.php?id={$records.id}">{$smarty.const.LIST_LINK_MORE_DETAILS}</a>
		{if $records.sellerid eq $userdetails.0.id || $admin}
		<a href="editlisting.php?id={$records.id}">{$smarty.const.LIST_LINK_EDIT_LISTING}</a>
		{/if}
		</p>
	</div>
</div>
{/foreach}

<p>Items {$paginate.first} - {$paginate.last} of {$paginate.total} displayed.
</p>

<hr />
	<div id="paginate">
		{* display pagination info *}
 		<p>{paginate_prev} {paginate_middle format="page"} {paginate_next} 
		</p>
	</div>
{/if}

</div>

{include file="footer.tpl"}