<? $this->load->view( $this->aSystemVar['template_viewer_root'] . 'admin/_header') ?>

<script language="javascript">

	function insertVar( container, variable )
	{

		container = document.getElementById(container);
		variable = '__' + variable + '__';

		container.focus();

		if ( 0 <= container.selectionStart )
		{
			var sStart = container.selectionStart;
			var sEnd = container.selectionEnd;

			container.value = container.value.substring(0, sStart) + variable + container.value.substring(sEnd);

		}
		else if (document.selection)
		{
	// IE
			document.selection.createRange().text = variable;
		}

		return true;

	}

</script>

				<div class="bigCaption">Email Templates</div>
						<?= form_open('admin/email_template'); ?>

						<? foreach ( $Email_template['TemplateList'] as $aTemplate ) : ?>
							<div class="eTBox">
								<div class="eTCap"><?= $aTemplate['Description'] ?></div>
								<div class="eTBody">
									<div class="eTS">
										Subject:
										<br />
										<input type="text" class="text" id="<?= $aTemplate['Name']?>_subject" name="<?= $aTemplate['Name']?>_subject" value="<?= $aTemplate['Subject'] ?>" />
									</div>
									<div class="eTt">
										<div class="clearBoth"></div>
										<div class="left">
											Body<br />
											<textarea id="<?= $aTemplate['Name']?>_body" name="<?= $aTemplate['Name']?>_body" cols="60" rows="6"><?= $aTemplate['Body'] ?></textarea>
										</div>
										<div class="right">
											variables <br />
											<select name="noname" size="7" style="width:200px;" ondblclick="insertVar('<?= $aTemplate['Name']?>_body', this.value);">
											<?

												$aCommonVar = array_keys($this->Catalog_model->GetMailVar());
												foreach ( $aCommonVar as $sVar )
												 	echo '<option value="' . $sVar . '">' . $sVar .'</option>';

												preg_match_all( '/\'(.+?)\'/', $aTemplate['SpecialVar'], $aVar );
												foreach ( $aVar[1] as $sVar )
												 	echo '<option value="' . $sVar . '">' . $sVar .'</option>';

											?>
											</select>
										</div>
										<div class="clearBoth"></div>
									</div>
								</div>
							</div>
						<? endforeach; ?>

						<div style="clear:both"></div>
						<div class="submit"><input type="submit" name="save" value="save" /></div>
						<?= form_close(); ?>
<? $this->load->view( $this->aSystemVar['template_viewer_root'] . 'admin/_footer') ?>