<?php $IEM = $tpl->Get('IEM'); ?><form method="post"  id="test" action="index.php?Page=Templates&Action=<?php if(isset($GLOBALS['Action'])) print $GLOBALS['Action']; ?>" onsubmit="return CheckForm()">
	<table cellspacing="0" cellpadding="0" width="100%" align="center">
		<tr>
			<td class="Heading1">
				<?php if(isset($GLOBALS['Heading'])) print $GLOBALS['Heading']; ?>
			</td>
		</tr>
		<tr>
			<td class="body pageinfo">
				<p>
					<?php if(isset($GLOBALS['Intro'])) print $GLOBALS['Intro']; ?>
				</p>
			</td>
		</tr>
		<tr>
			<td>
				<?php if(isset($GLOBALS['Message'])) print $GLOBALS['Message']; ?>
			</td>
		</tr>
		<tr>
			<td>
				<input class="FormButton" type="submit" value="<?php print GetLang('Next'); ?>">
				<input class="FormButton" type="button" value="<?php print GetLang('Cancel'); ?>" onClick='if(confirm("<?php if(isset($GLOBALS['CancelButton'])) print $GLOBALS['CancelButton']; ?>")) { document.location="index.php?Page=Templates" }'>
				<br />
				&nbsp;
				<table border="0" cellspacing="0" cellpadding="2" width="100%" class="Panel">
					<tr>
						<td colspan="3" class="Heading2">
							&nbsp;&nbsp;<?php if(isset($GLOBALS['TemplateDetails'])) print $GLOBALS['TemplateDetails']; ?>
						</td>
					</tr>
					<tr>
						<td width="200" class="FieldLabel">
							<?php $tmpTplFile = $tpl->GetTemplate();
			$tmpTplData = $tpl->TemplateData;
			$tpl->ParseTemplate("Required");
			$tpl->SetTemplate($tmpTplFile);
			$tpl->TemplateData = $tmpTplData; ?>
							<?php print GetLang('TemplateName'); ?>:
						</td>
						<td>
							<input type="text" name="Name" class="Field250" value="<?php if(isset($GLOBALS['Name'])) print $GLOBALS['Name']; ?>">&nbsp;<span class="HelpToolTip"><img src="images/help.gif" alt="?" width="24" height="16" border="0" /><span class="HelpToolTip_Title" style="display:none;"><?php print stripslashes(GetLang('TemplateName')); ?></span><span class="HelpToolTip_Contents" style="display:none;"><?php print stripslashes(GetLang('HLP_TemplateName')); ?></span></span>
						</td>
						<td rowspan="4" valign="top" style="display:none" id="preview">
							<div class="DisplayTemplateList" style="display: block; width: 255px; text-align: center; >
								<div><a href="javascript:void(0);" onclick="javascript:ShowPreview();"><img id="imgPreview" src="images/nopreview.gif" width="247" height="200" style="border: 1px solid black" onerror="this.src=images/nopreview.gif"></a></div>
								<div style="padding-top: 10px;"><a href="#" onclick="javascript: ShowPreview(); return false;"><img src="images/magnify.gif" border="0" style="padding-right:5px"><?php print GetLang('Preview_Template'); ?></a></div>
							</div>
						</td> 
					</tr>
					 
					<tr>
						<td width="200" class="FieldLabel">
							<?php $tmpTplFile = $tpl->GetTemplate();
			$tmpTplData = $tpl->TemplateData;
			$tpl->ParseTemplate("Required");
			$tpl->SetTemplate($tmpTplFile);
			$tpl->TemplateData = $tmpTplData; ?>
							<?php print GetLang('TemplateFormat'); ?>:&nbsp;
						</td>
						<td>
							<select name="Format">
								<?php if(isset($GLOBALS['FormatList'])) print $GLOBALS['FormatList']; ?>
							</select>
							&nbsp;
							<span class="HelpToolTip"><img src="images/help.gif" alt="?" width="24" height="16" border="0" /><span class="HelpToolTip_Title" style="display:none;"><?php print stripslashes(GetLang('TemplateFormat')); ?></span><span class="HelpToolTip_Contents" style="display:none;"><?php print stripslashes(GetLang('HLP_TemplateFormat')); ?></span></span>
						</td>
					</tr>
					<tr style="display: <?php if(isset($GLOBALS['DisplayNameOptions'])) print $GLOBALS['DisplayNameOptions']; ?>" >
						<td class="FieldLabel">
							<?php $tmpTplFile = $tpl->GetTemplate();
			$tmpTplData = $tpl->TemplateData;
			$tpl->ParseTemplate("Not_Required");
			$tpl->SetTemplate($tmpTplFile);
			$tpl->TemplateData = $tmpTplData; ?>
							Editor :
						</td>
						<td>
							<select name="usewysiwyg" id="usewysiwyg" onchange="ShowTemplate(this.value);">					
											<?php if(isset($GLOBALS['EditorList'])) print $GLOBALS['EditorList']; ?> 
								   </select>
						</td>
					</tr>
				<tr class="DisplayTemplateList" id="editorTemplate"  >
						   
					</tr>
					<tr>
						<td>
							&nbsp;
						</td>
						<td>
							<input class="FormButton" type="submit" value="<?php print GetLang('Next'); ?>">
							<input class="FormButton" type="button" value="<?php print GetLang('Cancel'); ?>" onClick='if(confirm("<?php if(isset($GLOBALS['CancelButton'])) print $GLOBALS['CancelButton']; ?>")) { document.location="index.php?Page=Templates" }'>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
<script>
	function CheckForm() {
		var f = document.forms[0];
		if (f.Name.value == '') {
			alert("<?php print GetLang('EnterTemplateName'); ?>");
			f.Name.focus();
			return false;
		}
	}
	//function for show templates
	ShowTemplate(<?php if(isset($GLOBALS['editor'])) print $GLOBALS['editor']; ?>);
function ShowTemplate(editor) { 
 
		    // document.getElementById("preview").style.display = "";
			$.ajax({
			type: "GET",
			url: "index.php?Page=newsletters&Action=getEditor&editor="+editor,
			success: function(data) {
			    if(editor == 1){
				 document.getElementById("preview").style.display = "";
				 document.getElementById("editorTemplate").innerHTML=data;
				 }
				 if(editor == 3){
				  document.getElementById("preview").style.display = "none";
				  document.getElementById("editorTemplate").innerHTML=data;
				}
				if(editor == 4){
			        document.getElementById("preview").style.display = "none";
				  document.getElementById("editorTemplate").innerHTML='';
				 }
					if(editor == 0){
			         document.getElementById("preview").style.display = "none";
				    document.getElementById("editorTemplate").innerHTML=data;
					}
				}
		});	 
	 
	}
 

	$('#Format').change(function() {
		// Hide the template preview if a text campaign was selected
		if($(this).val() == 't') {
			$('.DisplayTemplateList').hide();
		}
		else {
			$('.DisplayTemplateList').show();
		}
	});
 function ShowPreview() {
		Template = document.getElementById('TemplateID');
		selectedTemplate = Template.selectedIndex;
		if (selectedTemplate == -1 || selectedTemplate == 0) {
			alert('<?php print GetLang('SelectTemplate'); ?>');
			document.getElementById('TemplateID').focus();
			return false;
		}
		selectedTemplateID = Template.options[Template.selectedIndex].value;
		url = 'index.php?Page=Templates&Action=View&check=1&id=' + selectedTemplateID;
		window.open(url);
	}
 
	function SetValue(value) {
	 
		document.getElementById('TemplateID').value = '';
		document.getElementById('TemplateID').value =value;
		//alert('You selectd this template and click on next button');
		document.getElementById("test").submit(); 
	}
</script>
