<form method="post"  id="test" action="index.php?Page=Templates&Action=%%GLOBAL_Action%%" onsubmit="return CheckForm()">
	<table cellspacing="0" cellpadding="0" width="100%" align="center">
		<tr>
			<td class="Heading1">
				%%GLOBAL_Heading%%
			</td>
		</tr>
		<tr>
			<td class="body pageinfo">
				<p>
					%%GLOBAL_Intro%%
				</p>
			</td>
		</tr>
		<tr>
			<td>
				%%GLOBAL_Message%%
			</td>
		</tr>
		<tr>
			<td>
				<input class="FormButton" type="submit" value="%%LNG_Next%%">
				<input class="FormButton" type="button" value="%%LNG_Cancel%%" onClick='alpineConfirm("%%GLOBAL_CancelButton%%", "", "OK", "Cancel", function() { 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;%%GLOBAL_TemplateDetails%%
						</td>
					</tr>
					<tr>
						<td width="200" class="FieldLabel">
							{template="Required"}
							%%LNG_TemplateName%%:
						</td>
						<td>
							<input type="text" name="Name" class="Field250" value="%%GLOBAL_Name%%">&nbsp;%%LNG_HLP_TemplateName%%
						</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">%%LNG_Preview_Template%%</a></div>
							</div>
						</td> 
					</tr>
					 
					<tr>
						<td width="200" class="FieldLabel">
							{template="Required"}
							%%LNG_TemplateFormat%%:&nbsp;
						</td>
						<td>
							<select name="Format">
								%%GLOBAL_FormatList%%
							</select>
							&nbsp;
							%%LNG_HLP_TemplateFormat%%
						</td>
					</tr>
					<tr style="display: %%GLOBAL_DisplayNameOptions%%" >
						<td class="FieldLabel">
							{template="Not_Required"}
							Editor :
						</td>
						<td>
							<select name="usewysiwyg" id="usewysiwyg" onchange="ShowTemplate(this.value);">					
											%%GLOBAL_EditorList%% 
								   </select>
						</td>
					</tr>
				<tr class="DisplayTemplateList" id="editorTemplate"  >
						   
					</tr>
					<tr>
						<td>
							&nbsp;
						</td>
						<td>
							<input class="FormButton" type="submit" value="%%LNG_Next%%">
							<input class="FormButton" type="button" value="%%LNG_Cancel%%" onClick='alpineConfirm("%%GLOBAL_CancelButton%%", "", "OK", "Cancel", function() { 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 == '') {
			alpineAlert("%%LNG_EnterTemplateName%%");
			f.Name.focus();
			return false;
		}
	}
	//function for show templates
	ShowTemplate(%%GLOBAL_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 == 2){
				 	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) {
			alpineAlert('%%LNG_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;
		//alpineAlert('You selectd this template and click on next button');
		document.getElementById("test").submit(); 
	}
</script>
