<div class="BodyContainer">

	<script language="JavaScript" type="text/javascript">
		function ShowTab(T)
		{
			i = 0;
			while (document.getElementById("tab" + i) != null) {
				document.getElementById("div" + i).style.display = "none";
				document.getElementById("tab" + i).className = "";
				i++;
			}

			document.getElementById("div" + T).style.display = "";
			document.getElementById("tab" + T).className = "active";
		}

		function ToggleRelatedQuestions()
		{
			if ($('#detectrelated').attr("checked")) {
				$('#related_category_cont').hide();
			} else {
				$('#related_category_cont').show();
			}
		}

		function ConfirmCancel()
		{
			if(confirm('%%LNG_CancelMessage%%')) {
				document.location.href='index.php?ToDo=%%GLOBAL_cancelTodo%%';
			} else {
				return false;
			}
		}

		function CheckAddQuestionForm()
		{
			// Make sure that all of the form variables, etc are valid
			var f = document.frmAddQuestion;
			var aText = '';
			if (typeof(wysiwyg) != 'undefined') {
				aText = wysiwyg.getHTMLContent();
			} else {
				var tas = document.getElementsByTagName('textarea');
				for (i=0; i<tas.length; i++) {
					if (tas[i].name == "wysiwyg_html") {
						aText = tas[i].value;
						break;
					}
				}
			}
			if (f.title.value.length == 0) {
				alert('%%LNG_EnterQuestionTitle%%');
				f.title.focus();
				f.title.select();
				return false;
			}
			if (document.getElementById("category").selectedIndex <= 0) {
				alert('%%LNG_ChooseQuestionCategory%%');
				document.getElementById("category").focus();
				return false;
			}

			if (aText == "&nbsp;" || aText == "<br/>"
				|| aText == "" || aText == "&nbsp;<br/>") {
				alert('%%LNG_NoAnswer%%');
				return false;
			}

			if (isNaN(f.sortorder.value)) {
				alert('%%LNG_BadSort%%');
				ShowTab(1);
				f.sortorder.focus();
				f.sortorder.select();
				return false;
			}

			// If they have the last updated field checked then we need to clear
			// the value so that it gets a new value upon submission
			if ($('#lastupdatedcheck') && $('#lastupdatedcheck').attr('checked') == true) {
				$('#lastupdated').val('');
			}

			// Select all the related questions so they get sent through in the
			// post request only if we arnt auto detecting related questions
			if (!$("#detectrelated").attr('checked')) {
				SelectAllOptions('questionsrelated');
			}

			// If this is an email to submitter form, check if the user will
			// be able to see it or not
			if (f.emailtosubmitter) {
				if (!f.visible.checked) {
					return confirm('%%LNG_SubmittedQuestionNotVisible%%');
				}

				if (document.getElementById("category").selectedIndex == 0) {
					return confirm('%%LNG_SubmittedQuestionNoParentCategory%%');
				}

			}

			if (($("#restrictPrivate").checked) && ($("#groups").selectedIndex == -1)) {
				alert("%%LNG_ErrArticleGroupRestrictNoChosen%%");
				return false;
			}

			// Everything is OK, return true
			return true;
		}

		function SelectAllOptions(id)
		{
			var rel = document.getElementById(id);
			for (i=0; i < rel.options.length; i++) {
				rel.options[i].selected = true;
			}
		}

		function ShowMoreAttachments()
		{
			document.getElementById("trMoreAttachments").style.display = "none";
			// Simple test for ie ... if its ie then display the tr as a block
			// otherwise display it as a table-row
			if (document.all) {
				document.getElementById("trAttachments").style.display = "block";
			} else {
				document.getElementById("trAttachments").style.display = "table-row";
			}
		}

		function MoveBetweenSelects(from, toName)
		{

			if (document.getElementById('related_category').selectedIndex <= 0) {
				return false;
			}

			if (from.selectedIndex > -1) {
				var to = document.getElementById(toName);

				// Add the option to the new select
				t = from[from.selectedIndex].text;
				v = from[from.selectedIndex].value;
				to.options[to.options.length] = new Option(t, v);

				// Remove the option from the old select
				from[from.selectedIndex] = null;
				//from.options.length--;
			}
		}

		/*
		* disableOptions, restore and emulate are to be able to disable options in ie
		*/
		function disableOptions() {
			if (document.getElementsByTagName) {
				var s = document.getElementsByTagName("select");
				if (s.length > 0) {
					window.select_current = new Array();
					for (var i=0, select; select = s[i]; i++) {
						select.onfocus = function(){ window.select_current[this.id] = this.selectedIndex; }
						select.onchange = function(){ restore(this); }
						emulate(select);
					}
				}
			}
		}

		function restore(e) {
			if (e.options[e.selectedIndex].disabled) {
				e.selectedIndex = window.select_current[e.id];
			}
		}

		function emulate(e) {
			for (var i=0, option; option = e.options[i]; i++) {
				if (option.disabled) {
					option.style.color = "graytext";
				} else {
					option.style.color = "menutext";
				}
			}
		}

		var req;
		var url = '%%GLOBAL_pathToKB%%/admin/remote.php';

		function DoCallback(data)
		{
			if (!req) {
				// branch for native XMLHttpRequest object
				if (window.XMLHttpRequest) {
					req = new XMLHttpRequest();
				// branch for IE/Windows ActiveX version
				} else if (window.ActiveXObject) {
					req = new ActiveXObject('Microsoft.XMLHTTP')
				}
			}
			req.onreadystatechange = processReqChange;
			req.open('POST', url, true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(data);
		}


		function processReqChange() {
			// only if req shows 'loaded'
			if (req.readyState == 4) {
				// only if 'OK'
				if (req.status == 200) {
					ProcessData(req.responseXML);
				} else {
					alert('There was a problem retrieving the XML data:\n' +
						req.responseText);
				}
			}
		}

		function GetQuestions(selObj)
		{
			// Clear the questions list
			rel = document.getElementById("related_category_questions");
			rel.options.length = 0;

			cat = document.getElementById("related_category");
			qid = document.getElementById("questionid").value;

			if (cat.selectedIndex > 0) {
				// Get the products using XML
				var catid = cat.options[cat.selectedIndex].value;

				rel.options[0] = new Option("%%LNG_Loading%%", "-1");
				rel.options.length = 1;
				window.status = "%%LNG_RelatedQuestionWaitMessage%%";
				DoCallback("type=questionlist&categoryid="+catid+"&questionid="+qid);
				window.status = "";
			}
		}

		function OptionInSelect(id, select)
		{
			for (var i=0; i< select.options.length; i++) {
				if (select.options[i].value == id) return true;
			}
			return false;
		}

		function ProcessData(data)
		{
			var rel = document.getElementById("related_category_questions")
			var related_to_submit = document.getElementById('questionsrelated');
			var root = data.documentElement;
			var items = root.childNodes;
			var added=0;

			rel.options[0] = null;
			rel.options.length = 0;

			for (i = 0; i < items.length; i++) {
				var text = '';
				var value = '';
				for (j = 0; j < items[i].attributes.length; j++) {
					switch (items[i].attributes[j].nodeName) {
						case 'text':
							text = items[i].attributes[j].value;
							break;
						case 'id':
							value = items[i].attributes[j].value;
							break;
					}
				}


				// Only add questions to our list of questions in the category
				// if the question is not already in our list. This covers both
				// the case of loading up questions from the database and
				// browsing to another category with the same question.
				if (!OptionInSelect(value, related_to_submit)) {
					rel.options[added] = new Option(text, value);
					added++;
				}
			}
			rel.options.length = added;
			req=null;
		}

		function ToggleExpiryDate(Status)
		{
			if(Status)
			{
				document.getElementById("endday").disabled = false;
				document.getElementById("endmonth").disabled = false;
				document.getElementById("endyear").disabled = false;

				document.getElementById("endtime").disabled = false;

				document.getElementById("tdExpiryDate").disabled = false;
			}
			else
			{
				document.getElementById("endday").disabled = true;
				document.getElementById("endmonth").disabled = true;
				document.getElementById("endyear").disabled = true;

				document.getElementById("endtime").disabled = true;

				document.getElementById("tdExpiryDate").disabled = true;
			}
		}

		function ValidateForm(callback) {
			returnValue = callback();

			if (window.event) {
				window.event.returnValue = returnValue;
			} else {
				return returnValue;
			}
		}

	</script>

<!--	<form name="frmPreview" action="" id="frmPreview">
	<input type="hidden" name="q" value="">
	<input type="hidden" name="a" value="">
	</form>-->
	<form action="index.php?ToDo=%%GLOBAL_FormAction%%" enctype="multipart/form-data" name="frmAddQuestion" method="post" accept-charset="%%GLOBAL_charset%%" onsubmit="return ValidateForm(CheckAddQuestionForm);">
	<input id="questionid" type="hidden" name="questionid" value="%%GLOBAL_QuestId%%" />
	<input type="hidden" name="sQuestId" value="%%GLOBAL_SubmittedQuestId%%" />
	<input type="hidden" name="lastupdated" id="lastupdated" value="%%GLOBAL_LastUpdated%%" />

	<table class="OuterPanel" cellspacing="0" cellpadding="0" border="0">
	<tr>
		<td class="Heading1">%%GLOBAL_Title%%</td>
	</tr>
	<tr>
		<td class="Intro">
			<div>%%GLOBAL_Intro%%</div>
			<span id="Message"> %%GLOBAL_Message%% </span>
			<div style="float:left;">
				<input type="submit" name="SubmitButton1" value="%%LNG_SaveAndExit%%" class="FormButton Field100"  style="float:left;"/>
				<input type="submit" name="SubmitEditButton1" value="%%LNG_SaveAndKeepEditing%%" class="FormButton Field120" style="display:%%GLOBAL_DisplayKeepEditing%%;float:left;"/>
				<input type="button" name="CancelButton1" value="%%LNG_Cancel%%" class="FormButton Field80" onclick="ConfirmCancel()">
			</div>
		</td>
	</tr>
	<tr>
		<td>
			<ul id="tabnav">
				<li><a href="#" class="active" id="tab0" onclick="ShowTab(0)">%%LNG_QuestionContent%%</a></li>
				<li><a href="#" id="tab1" onclick="ShowTab(1)">%%LNG_QuestionAdvanced%%</a></li>
			</ul>
		</td>
	</tr>
	<tr>
		<td>
			<br />
			<div id="div0" style="background-color: #F9F9F9;">
				<table class="Panel">
				<tr>
					<td class="Heading2" colspan="2">%%LNG_NewQuestionDetails%%</td>
				</tr>
				<tr>
					<td class="FieldLabel">
						<span class="Required">*</span>&nbsp;%%LNG_QuestionTitle%%:
					</td>
					<td>
						<input type="text" name="title" id="title" class="Field500" value="%%GLOBAL_QuestionTitle%%">
						<img onmouseout="HideHelp(this)" onmouseover="ShowHelp(this, '%%LNG_QuestionTitle%%', '%%LNG_QuestionTitleHelp%%')" src="images/help.gif" width="24" height="16" border="0" alt="help">
					</td>
				</tr>
				<tr>
					<td class="FieldLabel">
						<span class="Required">*</span>&nbsp;%%LNG_QuestionCategory%%:
					</td>
					<td valign="top">
						<select size="10" name="category[]" id="category" class="Field500" style="height:115px" multiple onclick="$('#category').find('option').filter('[class=cat_selected]').each(function() {this.selected = true;});" >
							%%GLOBAL_CategoryOptions%%
						</select>
						<img onmouseout="HideHelp(this)" onmouseover="ShowHelp(this, '%%LNG_QuestionCategory%%', '%%LNG_QuestionCategoryHelp%%')" src="images/help.gif" width="24" height="16" border="0" alt="help" align="top" />
					</td>
				</tr>
				%%Panel.QuestionStatus%%
				<tr>
					<td class="FieldLabel">
						&nbsp;&nbsp;&nbsp;%%LNG_QuestionVisible%%:
					</td>
					<td class="Field">
						<input type="checkbox" name="visible" %%GLOBAL_CheckVisible%% value="ON" %%GLOBAL_DisableVisible%% id="chkvis">
						<label for="chkvis">%%LNG_QuestionVisibleYes%%</label>
						<img onMouseOut="HideHelp(this)" onMouseOver="ShowHelp(this, '%%LNG_QuestionVisible%%', '%%LNG_QuestionVisibleHelp%%')" src="images/help.gif" width="24" height="16" border="0" alt="help">
					</td>
				</tr>
				<tr>
					<td class="FieldLabel">
						&nbsp;&nbsp;&nbsp;%%LNG_QuestionsFeatured%%
					</td>
					<td>
<input type="checkbox" name="featured" %%GLOBAL_CheckFeatured%% value="1" %%GLOBAL_DisableFeatured%% id="chkfeatured">
						<label for="chkfeatured">%%LNG_DisableFeaturedYes%%</label>
						<img onMouseOut="HideHelp(this)" onMouseOver="ShowHelp(this, '%%LNG_QuestionsFeatured%%', '%%LNG_QuestionsFeaturedHelp%%')" src="images/help.gif" width="24" height="16" border="0" alt="help">					</td>
				</tr>
				</table>

				<table class="Panel">
				<tr>
					<td class="Heading2" colspan="2">%%LNG_NewQuestionContent%%</td>
				</tr>
				<tr>
					<td class="FieldLabel">
						<span class="Required">*</span>&nbsp;%%LNG_QuestionAnswer%%:
					</td>
					<td>
						%%GLOBAL_WYSIWYG%%
						<span id="tt3"></span>
					</td>
				</tr>
				<tr>
					<td class="FieldLabel">
						&nbsp;&nbsp;&nbsp;%%LNG_metaKeywords%%:
					</td>
					<td>
						<input type="text" name="metakeywords" class="Field500" value="%%GLOBAL_MetaKeywords%%" maxlength="250">
						<img onmouseout="HideHelp(this)" onmouseover="ShowHelp(this, '%%LNG_metaKeywords%%', '%%LNG_metaKeywordsHelp%%')" src="images/help.gif" width="24" height="16" border="0" alt="help" />
					</td>
				</tr>
				<tr>
					<td class="FieldLabel">
						&nbsp;&nbsp;&nbsp;%%LNG_metaDescription%%:
					</td>
					<td class="Field">
						<textarea name="metadescription" class="Field500">%%GLOBAL_MetaDescription%%</textarea>
						<img onmouseout="HideHelp(this)" onmouseover="ShowHelp(this, '%%LNG_metaDescription%%', '%%LNG_metaDescriptionHelp%%')" src="images/help.gif" width="24" height="16" border="0" alt="help">
					</td>
				</tr>
				</table>
				
				<table border="0" cellpadding="2" class="Panel" style="display: %%GLOBAL_CFDisplay%%;">
					<tr>
						<td class="Heading2" colspan="2">%%LNG_CustomFields%%</td>
					</tr>
					%%GLOBAL_CustomFields%%
				</table>

				<table class="Panel">
				<tr>
					<td class="Heading2" colspan="2">%%LNG_QuestionAttachments%%</td>
				</tr>
				<tr>
					<td class="FieldLabel">
						&nbsp;&nbsp;&nbsp;%%LNG_QuestionAttachment%%:
					</td>
					<td align="left">
						<input type="file" name="attachment[]" class="Field">
						<img onmouseout="HideHelp(this)" onmouseover="ShowHelp(this, '%%LNG_QuestionAttachment%%', '%%LNG_QuestionAttachmentHelp%%')" src="images/help.gif" width="24" height="16" border="0" alt="help">
					</td>
				</tr>
				<tr id="trMoreAttachments">
					<td class="FieldLabel">
						&nbsp;
					</td>
					<td>
						<a href="javascript:void(0)" onclick="ShowMoreAttachments()">%%LNG_MoreAttachments%%</a>
					</td>
				</tr>
				<tr id="trAttachments" style="display:none">
					<td class="FieldLabel">
						&nbsp;
					</td>
					<td>
						<input type="file" name="attachment[]" class="Field500"><br />
						<input type="file" name="attachment[]" class="Field500"><br />
						<input type="file" name="attachment[]" class="Field500"><br />
						<input type="file" name="attachment[]" class="Field500">
					</td>
				</tr>
				%%GLOBAL_ExistingAttachments%%
				<tr>
					<td>&nbsp;</td>
				</tr>
				</table>
				
			</div>

			<div id="div1" style="display: none">
				<table class="Panel">
				<tr>
					<td class="Heading2" colspan=2>%%LNG_DateAndDisplay%%</td>
				</tr>
				<tr>
					<td class="FieldLabel">
						&nbsp;&nbsp;&nbsp;%%LNG_ArticleStartDate%%:
					</td>
					<td>
						<select name="startday" id="startday" class="Field">
							%%GLOBAL_StartDayOptions%%
						</select>
						<select name="startmonth" id="startmonth" class="Field">
							%%GLOBAL_StartMonthOptions%%
						</select>
						<select name="startyear" id="startyear" class="Field">
							%%GLOBAL_StartYearOptions%%
						</select>
						&nbsp;&nbsp;

						<select id="starttime" name="starttime" size="1" class="Field">
						%%GLOBAL_StartTimeList%%
						</select>

						<img onMouseOut="HideHelp(this)" onMouseOver="ShowHelp(this, '%%LNG_ArticleStartDate%%', '%%LNG_ArticleStartDateHelp%%')" src="images/help.gif" width="24" height="16" border="0">
					</td>
				</tr>
				<tr>
					<td class="FieldLabel">
						&nbsp;&nbsp;&nbsp;%%LNG_ArticleExpiry%%:
					</td>
					<td>
						<input onclick="ToggleExpiryDate(this.checked)" type="checkbox" name="expires" value="on" id="expires" %%GLOBAL_DoesExpire%%>
						<label for="expires">%%LNG_YesExpires%%</label>
						</select>
						<img onMouseOut="HideHelp(this)" onMouseOver="ShowHelp(this, '%%LNG_ArticleExpiry%%', '%%LNG_ArticleExpiryHelp%%')" src="images/help.gif" width="24" height="16" border="0">
					</td>
				</tr>
				<tr>
					<td class="FieldLabel" id="tdExpiryDate">
						&nbsp;&nbsp;&nbsp;%%LNG_ArticleExpiryDate%%:
					</td>
					<td>
						<img src="images/nodejoin.gif" width="20" height="20">
						<select %%GLOBAL_ExpireDateDisabled%% name="endday" id="endday" class="Field">
							%%GLOBAL_EndDayOptions%%
						</select>
						<select %%GLOBAL_ExpireDateDisabled%% name="endmonth" id="endmonth" class="Field">
							%%GLOBAL_EndMonthOptions%%
						</select>
						<select %%GLOBAL_ExpireDateDisabled%% name="endyear" id="endyear" class="Field">
							%%GLOBAL_EndYearOptions%%
						</select>
							&nbsp;&nbsp;

						<select id="endtime" name="endtime" size="1" class="Field">
						%%GLOBAL_EndTimeList%%
						</select>

						<img onmouseout="HideHelp(this);" onmouseover="ShowHelp(this, '%%LNG_ArticleExpiry%%', '%%LNG_ArticleEndDateHelp%%')" src="images/help.gif" width="24" height="16" border="0">
					</td>
				</tr>
				<tr>
					<td class="FieldLabel">
						&nbsp;&nbsp;&nbsp;%%LNG_QuestionSortOrder%%:
					</td>
					<td>
						<input type="text" name="sortorder" class="Field50" value="%%GLOBAL_SortOrder%%">
						<img onMouseOut="HideHelp(this)" onMouseOver="ShowHelp(this, '%%LNG_QuestionSortOrder%%', '%%LNG_QuestionSortOrderHelp%%')" src="images/help.gif" width="24" height="16" border="0" alt="help">
					</td>
				</tr>
				</table>

				<table class="Panel">
				<tr>
					<td class="Heading2" colspan="2">%%LNG_QuestionRelatedTitle%%</td>
				</tr>
				<tr>
					<td class="FieldLabel">
						&nbsp;&nbsp; %%LNG_QuestionRelated%%:
					</td>
					<td>
						<div>
							<input onclick="ToggleRelatedQuestions(this.checked)" type="checkbox" name="detectrelated" id="detectrelated" value="1" %%GLOBAL_DetectRelated%%> <label for="detectrelated">%%LNG_YesDetectRelatedQuestions%%</label>
							<img onmouseout="HideHelp(this)" onMouseOver="ShowHelp(this, '%%LNG_QuestionDetectRelated%%', '%%LNG_QuestionDetectRelatedHelp%%')" src="images/help.gif" width="24" height="16" border="0" alt="help">
						</div>

						<br clear="all" />

						<div id="related_category_cont">
							<select name="related_category" id="related_category" class="Field500" onchange="GetQuestions(this)">
								<option selected value="0">%%LNG_SelectACategory%%</option>
								%%GLOBAL_RelatedCategoryOptions%%
							</select>

							<img onmouseout="HideHelp(this)" onmouseover="ShowHelp(this, '%%LNG_QuestionRelated%%', '%%LNG_QuestionRelatedHelp%%')" src="images/help.gif" width="24" height="16" border="0" alt="help" align="top">

							<br clear="all" />

							<select size="5" name="related_category_questions" id="related_category_questions" class="Field500" ondblclick="javascript: MoveBetweenSelects(this, 'questionsrelated');">
							</select>
							<div>%%LNG_RelatedQuestionDoubleClickToAdd%%</div>
							<select size="5" name="questionsrelated[]" id="questionsrelated" class="Field500" multiple="multiple" ondblclick="javascript: MoveBetweenSelects(this, 'related_category_questions');">
								%%GLOBAL_RelatedQuestions%%
							</select>
							<div>%%LNG_RelatedQuestionDoubleClickToRemove%%</div>

						</div>
					</td>
				</tr>
				</table>

				<!--<img onmouseout="HideHelp(this)" onmouseover="ShowHelp(this, '%%LNG_CustomFields%%', '%%LNG_CustomFieldsHelp%%')" src="images/help.gif" width="24" height="16" border="0" alt="help" />-->
				%%Panel.QuestionMiscellaneous%%
				%%Panel.QuestionEmailSubmitter%%

				%%Panel.UserGroupsCategoryArticle%%

			</div>
		</td>
	</tr>
	<tr>
		<td style="padding-left: 190px">
			<br />
				<input type="submit" name="SubmitButton2" value="%%LNG_SaveAndExit%%" class="FormButton Field100"  style="float:left;"/>
				<input type="submit" name="SubmitEditButton2" value="%%LNG_SaveAndKeepEditing%%" class="FormButton Field120" style="display:%%GLOBAL_DisplayKeepEditing%%;float:left;"/>
				<input type="button" name="CancelButton2" value="%%LNG_Cancel%%" class="FormButton Field80" onclick="ConfirmCancel()">
		</td>
	</tr>


	<tr>
		<td class="Gap"></td>
	</tr>
	</table>

	<script type="text/javascript">
	//ShowTab(0);
	</script>

	</form>

	<script>
		ToggleExpiryDate(document.getElementById("expires").checked);
		ToggleRelatedQuestions();
	</script>

</div>