<%@ Reference Control="~/bitrix/components/bitrix/catalogue.element.detail/component.ascx" %>
<%@ Control Language="C#" AutoEventWireup="true" Inherits="Bitrix.IBlock.Components.CatalogueElementDetailTemplate" %>
<%@ Import Namespace="Bitrix.IBlock.Components" %>

<%
if (!String.IsNullOrEmpty(Component.errorMessage))
{ 
	%><span class="errortext"><%=Component.errorMessage%></span><%
}
else if (Component.Element != null)
{
	%><div class="catalog-element">
	
	<table width="100%" cellspacing="0" cellpadding="2" border="0">
	<tr>
		<% 
		if (Component.DetailImage != null && Component.PreviewImage != null) 
		{ 
			%><td width="0%" valign="top">
				<img border="0" src="<%= Component.PreviewImage.FilePath %>" width="<%= Component.PreviewImage.Width %>" title="<%= Component.ElementName %>" height="<%= Component.PreviewImage.Height %>" alt="<%= Component.PreviewImage.Description %>" id="image_<%= Component.PreviewImage.Id %>" style="display:block;cursor:pointer;cursor: hand;" onclick="document.getElementById('image_<%= Component.PreviewImage.Id %>').style.display='none';document.getElementById('image_<%= Component.DetailImage.Id %>').style.display='block'" />
				<img border="0" src="<%= Component.DetailImage.FilePath %>" width="<%= Component.DetailImage.Width %>" title="<%= Component.ElementName %>" height="<%= Component.DetailImage.Height %>" alt="<%= Component.DetailImage.Description %>" id="image_<%= Component.DetailImage.Id %>"  style="display:none;cursor:pointer; cursor: hand;" onclick="document.getElementById('image_<%= Component.DetailImage.Id %>').style.display='none';document.getElementById('image_<%= Component.PreviewImage.Id %>').style.display='block'" />
			</td><%
		}
		else if (Component.DetailImage != null)
		{
			%><td width="0%" valign="top"><img class="detail-picture" border="0" title="<%= Component.ElementName %>" src="<%= Component.DetailImage.FilePath %>" width="<%= Component.DetailImage.Width %>"
				height="<%= Component.DetailImage.Height %>" alt="<%= Component.DetailImage.Description %>" /></td><%
		}
		else if (Component.PreviewImage != null)
		{
			%><td width="0%" valign="top"><img class="preview-picture" border="0" title="<%= Component.ElementName %>" src="<%= Component.PreviewImage.FilePath %>" width="<%= Component.PreviewImage.Width %>"
				height="<%= Component.PreviewImage.Height %>" alt="<%= Component.PreviewImage.Description %>" /></td><%
		}
		%>
		<td width="100%" valign="top">
		
		<%
		foreach (CatalogueElementDetailComponent.ElementDetailProperty property in Component.Properties)
		{
			if (!String.IsNullOrEmpty(property.DisplayValue) && Component.ShowProperties.Contains(property.Code))
			{
				%><span class="catalog-element-property"><%=property.Name%>: <b><%=property.DisplayValue%></b></span><br /><%
			}
		}
		%>
		</td>
	</tr>
	</table>
	<br />
	<%
	if (Component.Element.DetailText.Length > 0)
	{
		%><%= Component.Element.DetailText%><br /><%
	}
	else if (Component.Element.PreviewText.Length > 0)
	{
		%><%= Component.Element.PreviewText%><br /><%
	}
	
	%></div><%
} 
%>

<%
	
%>
<% 
	string title = Parameters.Get("Template_BackTitle");
	string url = Parameters.Get("Template_BackUrlTemplate");
	bool link = false;
	if (!string.IsNullOrEmpty(title) && !string.IsNullOrEmpty(url))
	{
		Bitrix.DataTypes.BXParamsBag<object> replace = new Bitrix.DataTypes.BXParamsBag<object>();
		
		replace["ElementId"] = replace["ELEMENT_ID"] = Component.ElementId;
		replace["ElementCode"] = replace["ELEMENT_CODE"] = Component.ElementCode;
		
		int sectionId = Parameters.GetInt("SectionId");
		if (sectionId == 0 && Component.Element.Sections.Count != 0)
			sectionId = Component.Element.Sections[0].SectionId;
		replace["SectionId"] = replace["SECTION_ID"] = sectionId;
		
		replace["SectionCode"] = replace["SECTION_CODE"] = Parameters.GetString("SectionCode", "");
		url = Component.ResolveTemplateUrl(url, replace);
		link = true;
	}
%>
<% if (link) { %>
	<p><a enableajax="true" href="<%= Encode(url) %>"><%= Encode(title) %></a></p>
<% } %>


<script runat="server">
	protected override void PreLoadTemplateDefinition(Bitrix.Components.BXParametersDefinition def)
	{
		def["Template_BackTitle"] = new Bitrix.Components.BXParamText(GetMessageRaw("Param.BackTitle"), GetMessageRaw("DefaultBackTitle"), Bitrix.Components.BXCategory.UrlSettings);
		def["Template_BackUrlTemplate"] = new Bitrix.Components.BXParamText(GetMessageRaw("Param.BackUrlTemplate"), "", Bitrix.Components.BXCategory.UrlSettings);
	}
</script>