{include file="$admingentemplates/admin_top.tpl"}
<div class="back">
    <a href="{$site_url}{$site_root}/admin/admin_settings.php">{$lang.button.back}</a>
</div>
<div class="cr"></div>
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$lang.settings_smtp.razdel_name}</div>
<div class="cr">&nbsp;</div>
<div class="cr">&nbsp;</div>
<div class="help_text" style="display:block;">
    <div class="close_help">
        <img src="{$site_root}{$template_root}/images/close_help.png" alt="">
    </div>
    <div class="help_body">
        <span class="help_title">{$lang.help}:</span>{$lang.admin_help.settings_smtp}
    </div>
</div>
<div class="cr">&nbsp;</div>
	<table cellpadding="0" cellspacing="0" class="admin_edit_form">
	<tr class="table_header">
		<td colspan="2">{$lang.settings_smtp.razdel_name}</td>
	</tr>
		<tr class="even">
			<th><input type="radio" onclick='{literal}$("#smtp_settings_area").hide();$("#tr_error_msg").hide();$("#error_box").html("");{/literal}' id="smtp_default" name="use_smtp_server" value="0" {if $settings.use_smtp_server eq 0}checked{/if}></th>
			<td><label for="smtp_default">{$lang.settings_smtp.default_mail}</label></td>
		</tr>
		<tr class="odd">
			<th><input type="radio" onclick='{literal}$("#smtp_settings_area").show();$("#tr_error_msg").hide();$("#error_box").html("");{/literal}' id="smtp_server" name="use_smtp_server" value="1" {if $settings.use_smtp_server eq 1}checked{/if}></th>
			<td><label for="smtp_server">{$lang.settings_smtp.smtp_server}</label></td>
		</tr>
	</table>
	<div id="smtp_settings_area">
	<table cellpadding="0" cellspacing="0" class="admin_edit_form">
	<tr>
		<td nowrap align="left" width="1%">{$lang.settings_smtp.smtp_settings}</td>
		<td align="left" width="99%">
			<a class="admin_button" onclick="saveSettings(1);">{$lang.button.defaults}<span>&nbsp;</span></a>
			<a class="admin_button" onclick="testLetter();">{$lang.button.test}<span>&nbsp;</span></a>
			<span id="img_container"></span>
		</td>
	</tr>
	<tr>
		<td nowrap align="left" width="1%">{$lang.settings_smtp.server} :</td>
		<td align="left" width="99%"><input type="text" id="server"  value="{$settings.smtp_server}" /> : <input type="text" id="port" value="{$settings.smtp_port}" size="4" /> {$lang.settings_smtp.port}</td>
	</tr>
	<tr>
		<td nowrap align="left" width="1%">{$lang.settings_smtp.use_authorization} :</td>
		<td align="left" width="99%"><input type="checkbox" id="use_authorization" {if $settings.smtp_use_authorization} checked="checked"{/if} onclick="toggleLoginDetails();" /></td>
	</tr>
	<tr id="tr_login">
		<td nowrap align="left" width="1%">{$lang.settings_smtp.login} :</td>
		<td align="left" width="99%"><input type="text" id="login" value="{$settings.smtp_login}" /></td>
	</tr>
	<tr id="tr_password">
		<td nowrap align="left" width="1%">{$lang.settings_smtp.password} :</td>
		<td align="left" width="99%"><input type="text" id="password" value="{$settings.smtp_password}" /></td>
	</tr>
	</table>
	</div>
	<table cellpadding="0" cellspacing="0" class="admin_edit_form" style="margin-top:10px;">
	<tr>
		<td align="left" width="1%" nowrap>
			{*<input type="button" value="{$lang.button.save}" onclick="saveSettings(0);" class="button_left"/>*}
			<a class="admin_button_major" onclick="saveSettings(0);">{$lang.button.save}<span>&nbsp;</span></a>
		</td>
		<td align="left" width="99%" id="tr_error_msg" style="display:none;padding-left:10px;">
			<!--font id="font_error_msg" class="error_msg"></font-->
                        <div id="error_box" class="error_box_blue" style="display: table;"></div>
		</td>
	</tr>
	</table>
	<script type="text/javascript">
	{literal}
	var	file_name = '{/literal}{$file_name}{literal}';
	function saveSettings(defaults){
		$("#tr_error_msg").hide();
		$("#error_box").html("");

		if ($("#smtp_server").attr("checked")) {
			var server = $("#server").val();
			var port = $("#port").val();
			var use_authorization = $("#use_authorization").attr("checked")?1:0;
			var login = $("#login").val();
			var password = $("#password").val();
			if (!defaults)
			var str = "sel=save_settings&mail_default=0&server="+server+"&port="+port+"&use_authorization="+use_authorization+"&login="+login+"&password="+password;
			else
			var str = "sel=save_settings&mail_default=0&server=localhost&port=25&use_authorization=0";

			$.post(file_name,str,function(data){
				data = getJQData(data);
				if (data.msg){
					ShowAjaxError(data.msg,'','info');
					/*$("#error_box").html("* "+data.msg);
					$("#tr_error_msg").show();*/
				}
				$("#server").val(data.server);
				$("#port").val(data.port);
				$("#use_authorization").val(data.use_authorization);
				if(data.use_authorization){
					$("#use_authorization").attr("checked","checked")
				}else{
					$("#use_authorization").attr("checked","")
				}
				$("#login").val(data.login);
				$("#password").val(data.password);
				toggleLoginDetails();
			});
		} else {
			var str = "sel=save_settings&mail_default=1";
			$.post(file_name,str,function(data){
				data = getJQData(data);
				if (data.msg){
					ShowAjaxError(data.msg,'','info');
					/*$("#error_box").html("* "+data.msg);
					$("#tr_error_msg").show();*/
				}
			});
		}
	}

	function toggleLoginDetails(){
		if ($("#use_authorization").attr("checked")){
			if ($("#tr_login").css("display")=='none'){
				$("#tr_login").css("display","");
			}
			if ($("#tr_password").css("display")=='none'){
				$("#tr_password").css("display","");
			}
		}else{
			if ($("#tr_login").css("display")!='none'){
				$("#tr_login").css("display","none");
			}
			if ($("#tr_password").css("display")!='none'){
				$("#tr_password").css("display","none");
			}
		}
		return;
	}

	function testLetter(){
		var test_letter_cofirm_tpl = "{/literal}{$lang.settings_smtp.test_letter_cofirm|escape:javascript}{literal}";
		var site_email = "{/literal}{$settings.site_email}{literal}";
		var test_letter_cofirm = test_letter_cofirm_tpl.replace("[site_email]", site_email);
		if (!confirm(test_letter_cofirm)) return false;

		$("#test_button").hide();
		ajaxLoadingImage(1,'img_container');

		var server = $("#server").val();
		var port = $("#port").val();
		var use_authorization = $("#use_authorization").attr("checked")?1:0;
		var login = $("#login").val();
		var password = $("#password").val();
		var str = "sel=test_email&server="+server+"&port="+port+"&use_authorization="+use_authorization+"&login="+login+"&password="+password;
		$.post(file_name,str,function(data){
			$("#test_button").show();
			ajaxLoadingImage(0,'img_container');
			if (data)
				alert(data);
			else
				alert('{/literal}{$lang.settings_smtp.test_letter_check_settings|escape:javascript}{literal}');
		});
		return;
	}

	toggleLoginDetails();
	{/literal}
	{if $settings.use_smtp_server eq 0}
	{literal}
	$("#smtp_settings_area").hide();
	{/literal}
	{/if}
	</script>
{include file="$admingentemplates/admin_bottom.tpl"}