{if $ajax eq '0'}{include file="$admin_nl_gentemplates/admin_nl_site_head.tpl"}{else}{include file="$admin_nl_gentemplates/admin_nl_tips.tpl"}{/if}
{include file="$admingentemplates/admin_top.tpl"}
	<div class="red_header">{$header.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>{$help.billing}
    </div>
</div>
<div  class="panel_section">
<div  class="panel_content">

<div style="border:0px;">
<div class="panel_content" style="margin-bottom:0px;margin-left: 0px;">
<form method="POST" action="change.php?ajax=1&id={$id}" enctype="multipart/form-data" formid="myform"  name="EditEmail" class="EditEmail" style="margin:0px;">
<input type="hidden" name="action" value="change">
<input type="hidden" name="format" value="{$format}">
	{if $message != ""}<font class="main_header_text" color="red"><b>{$message}</b></font><br>{/if}
		<div style="display:table;">
			<div style="display:table;width:100%;">
				<div class="fl newletter_form_create">
					{$lang.newsletter.template.template_name}:&nbsp;<a onmouseover="doTooltip(event,54)" onmouseout="hideTip()" href="#"><img src="{$site_root}{$template_root}/images/newsletter/icot.gif" width="12" height="12" border=0 align="absmiddle"></a>
				</div>
				<div class="fl"><input type="text" name="name" value="{$name}" size=81 class="inpBox">
				</div>
			</div>
			<div style="display:table;width: 100%;">
				<div class="cr">&nbsp;</div>
				<div class="fl newletter_form_create">
					<b>{$lang.newsletter.template.html_templ_cont}:</b>&nbsp;<A onmouseover="doTooltip(event,55)" onmouseout="hideTip()" href="#"><IMG src="{$site_root}{$template_root}/images/newsletter/icot.gif" width="12" height="12" border=0 align="absmiddle"></A>
				</div>
				<div class="fl">
					{$redactor}
					<textarea id="body" name="body" class="redactor_normal"></textarea>
				</div>
			</div>
		</div>
		<!-- <table><tr height="40">
			<td><input type="button" value="Save template" class="button" onclick="javascript:document.EditEmail.submit();"></td>
		</tr></table> -->
		

		{literal}
		<div id="mergeDiv" style="position:absolute; overflow-y:auto; top:10; width: 420; height:180; border: solid 1px black; background-color:#FFFFFF;">
			<div class="handle" handlefor="mergeDiv" id="title" style="padding: 3px; background-color:#0066CC; height:20px; color:#FFFFFF; border-bottom: 1px solid #999999">
				&nbsp;<b> {$lang.newsletter.template.merge_fields}</b>
			</div>
			<table width="100%" cellpadding="4">
				<tr><td colspan="3" class="main_header_text">
				<div style="position: absolute; left:350" align="right">[<a class="menutext" href="javascript:void(0)" onClick="mergeDiv.style.display='none';">{$lang.newsletter.button.close}</a>]&nbsp;</div>
				{$lang.newsletter.template.basic_tags}</td></tr>
				<tr>
					<td class="main_content_text">{$lang.newsletter.template.email_address}</td>
					<td class="main_content_text">%BASIC:EMAIL%</td>
					<td class="main_content_text"><a href="javascript: InsertCode('BASIC:EMAIL')">{$lang.newsletter.button.insert}</a></td>
				</tr>
				<tr><td colspan="3"></td></tr>
				<tr>
					<td class="main_content_text">{$lang.newsletter.template.first_name}</td>
					<td class="main_content_text">%BASIC:FIRSTNAME%</td>
					<td class="main_content_text"><a href="javascript: InsertCode('BASIC:FIRSTNAME')">{$lang.newsletter.button.insert}</a></td>
				</tr>
				<tr><td colspan="3"></td></tr>
				<tr>
					<td class="main_content_text">{$lang.newsletter.template.first_name}</td>
					<td class="main_content_text">%BASIC:SECONDNAME%</td>
					<td class="main_content_text"><a href="javascript: InsertCode('BASIC:SECONDNAME')">{$lang.newsletter.button.insert}</a></td>
				</tr>
				<tr><td colspan="3"></td></tr>
				<tr>
					<td class="main_content_text">{$lang.newsletter.template.unsubscribe_link}</td>
					<td class="main_content_text">%BASIC:UNSUBLINK%</td>
					<td class="main_content_text"><a href="javascript: InsertCode('BASIC:UNSUBLINK')">{$lang.newsletter.button.insert}</a></td>
				</tr>
				<tr><td colspan="3"></td></tr>
				<tr><td colspan="3" class="main_header_text">{$lang.newsletter.template.images}</td></tr>
			{/literal}
			{section name=c loop=$images}
				<tr>
					<td class="main_content_text">{$images[c].name}</td>
					<td class="main_content_text">%IMAGE:{$images[c].id}%</td>
					<td class="main_content_text"><a href="javascript: InsertCode('IMAGE:{$images[c].id}')">{$lang.newsletter.button.insert}</a></td>
				</tr>
				<tr><td colspan="3"></td></tr>
			{/section}    
			</table>
		</div>
		{literal}
<script language="JavaScript" type="text/JavaScript">
			var options = { 
				success: function(data){
					ajaxLoadingImage(0, 'show_block');
					$('#show_block').html(data);
					/*$('#show_block').oneTime(3000, function() {
						$('#show_block').fadeOut(500);
					});*/
					return false;
				},
				beforeSubmit: function() { 
					//ajaxIndicator(1, 'show_block');
					ajaxLoadingImage(1, 'show_block');
				}
			};
			function submit(){
					//$('.EditEmail').ajaxSubmit(options);
					$('.EditEmail').submit();
			}


            var whichField = 0;
            var whichWYSIWYG = 1;
            var whichText = 0;

            mergeDiv.style.display = "none";

            function toggleMergePopup(which, whichEditor){
                whichField = which;
                whichWYSIWYG = whichEditor;
                whichText = whichEditor;

                var x = ((document.body.clientWidth / 2) - 210) + document.body.scrollLeft;
                var y = ((document.body.clientHeight / 2) - 150) + document.body.scrollTop;

                mergeDiv.style.left = x;
                mergeDiv.style.top = y;
                mergeDiv.style.display = "inline";

                whichField = which;
            }

            function InsertCode(theCode){
                window.frames['wysiwyg_rEdit'].focus();     

                var sel = document.selection;
                var r = sel.createRange();
                r.pasteHTML("%" + theCode + "%");
                mergeDiv.style.display = "none";
            }

            function addUnsubscribeLink(whichBox){
                        if(whichBox == 1){ //HTML
                            window.frames['wysiwyg_rEdit'].focus();     

                            var sel = document.selection;
                            var r = sel.createRange();
                            r.pasteHTML("%BASIC:UNSUBLINK%");
                            mergeDiv.style.display = "none";
                        }else{ //Text
                            var t = document.getElementById("TEXTBODY");
                            t.value += "%BASIC:UNSUBLINK%";
                            t.focus();
                        }
			}

			function PreparePreview(){
                        if(CheckForm()){
                            document.forms[0].target = "_blank";
                            prevAction = document.forms[0].action;
                            document.forms[0].action = "/";
                            document.forms[0].submit();
                            document.forms[0].target = "";
                            document.forms[0].action = prevAction;
                        }
			}

			function extractHTMLtoText(){
                        var f = document.forms[0];
                        f.TEXTBODY.value = document.body.innerText;
			}

			function CheckForm(){
						form_body = $('iframe').contents().find('iframe').contents().find('body').html() ? $('iframe').contents().find('iframe').contents().find('body').html() : null;
 						//if(manual_body){
// 							$('#manual_body').val(manual_body);
 //						}
   //                     var f = document.forms[0];
                        if(form_body == ""){
                            alert("{/literal}{$lang.newsletter.template.enter_html_content|escape:javascript}{literal}");
                            return false;
                        }
                        return true;
			}
		</script>
{/literal}
</form>
</div>
</div>
</div></div>
			<div style="display:table;">
				<a class="admin_button_major" onclick="if ( CheckForm() ) submit();">{$lang.newsletter.template.save_templ}<span>&nbsp;</span></a>
			</div>
{include file="$admingentemplates/admin_bottom.tpl"}
{if $ajax eq '0'}
{include file="$admin_nl_gentemplates/admin_nl_site_foot.tpl"}{/if}
