<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
	pagename	= "faq.asp"
	pageheader	= "Manage FAQ"
	pagetable	= "faq"
	pageobject  = "FAQ"
	candelete 	= True
	canadd		= True
	useeditor	= False
%>
<!--#include file="include/functions.asp"-->
<%
	GetOrder()
%>
<!--#include file="include/header.asp"-->
<% 	
	Select case action
		Case ""
			If OrderBy = "" Then 
				OrderBy = "fldOrder,fldQuestion"
			End If
			numrows = GetNumRecs(pagetable)
			OpenRS("SELECT id,fldQuestion,fldOrder FROM "&pagetable&" ORDER BY "&OrderBy&" "&SortBy)
%>
			<table width="550" border="0" cellpadding="0" cellspacing="0">
			 <tr> 
			  <td class="gridbox">
			   <table width="550" border="0" cellpadding="0" cellspacing="0" class="gridhead">
				<tr class="row1"> 
				 <td width="475" onClick="Redirect('<%=pagename%>?o=fldQuestion&s=<%=nsort%>');" onMouseOver="this.style.cursor='hand';">Question<%If torder="fldQuestion" Then Response.Write("<img src=""images/"&nsort&".gif"">")%></td>
				 <td width="75" onClick="Redirect('<%=pagename%>?o=fldOrder&s=<%=nsort%>');" onMouseOver="this.style.cursor='hand';">Order<%If torder="fldOrder" Then Response.Write("<img src=""images/"&nsort&".gif"">")%></td>
				</tr>
			   </table>
<%
			If Not rs.EOF Then
				x = 1
				Response.Write("<div class=""grid""><table width=""550"" border=""0"" cellpadding=""0"" cellspacing=""0"" class=""gridbody"">"&vbCrLf)
				Do While Not rs.EOF					
					Response.Write("<tr id=""row"&x&""" class=""row1"" onMouseOver=""RowOver(this);"" onMouseOut=""RowOut(this);"" onClick=""ChangeRow(this,"&numrows&","&rs("id")&");"">"&vbCrLf) 
					Response.Write("<td width=""475"">"&rs("fldQuestion")&"</td>"&vbCrLf)
					Response.Write("<td width=""75"">"&rs("fldOrder")&"</td>"&vbCrLf)
					Response.Write("</tr>"&vbCrLf)
					x = x + 1
					rs.MoveNext
				Loop
				Response.Write("</table></div>"&vbCrLf)
			End If		
%>
		      </td>
		     </tr>
		     <tr>
		      <td height="60" align="right" valign="top"> 
			   <table width="550" cellpadding="0" cellspacing="0">
			    <tr>
				 <td height="5" colspan="2"><img src="images/pixel.gif" height="5"></td>
				</tr>
			    <tr>
				 <td valign="top" align="left" width="202">
				 </td>
				 <td width="348" valign="top">
				  <form name="actionform" method="post" action="<%=pagename%>">
		           <input type="hidden" id="action" name="action" value="">
		           <input type="hidden" id="id" name="id" value="">
		           <input type="hidden" id="step" name="step"  value="1">
		           <%If canadd = True Then Response.Write("<input name=""button"" type=""button"" id=""button"" value=""Add"" onClick=""return DoAction('add');"">")%>
		           <input name="button" type="button" id="button" value="Edit" onClick="return DoAction('edit');">
		           <%If candelete = True Then Response.Write("<input name=""button"" type=""button"" id=""button"" value=""Delete"" onClick=""return DoAction('delete');"">")%>
		          </form>
				 </td>
				</tr>
			   </table>
		      </td>
		     </tr>
	        </table>
<%
			CloseRS()
	Case "add", "edit"
		If step = 1 Then
			If action = "edit" Then
				OpenRS("SELECT * FROM "&pagetable&" WHERE ID = "&id)
					If Not rs.EOF Then
						id = rs("ID")
						rQuestion = rs("fldQuestion")
						rAnswer = RemoveBreaks(rs("fldAnswer"))
						rOrder = rs("fldOrder")
					End If
				CloseRS()
			End If
%>
		   <form name="form" action="<%=pagename%>" method="post">
		    <input type="hidden" name="action" value="<%=action%>">
		    <input type="hidden" name="step" value="2">
		    <input type="hidden" name="id" value="<%=id%>">
			<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
			 <tr>
			            <td height="26" width="75">Question:</td>
			  <td width="425"><input name="question" id="question" type="text" value="<%=rQuestion%>" style="width:400px;"></td>
			 </tr>
			 <tr>
			            <td height="26">Answer:</td>
			  <td><textarea name="answer" rows="5" style="width:400px;"><%=rAnswer%></textarea></td>
			 </tr>
			 <tr>
			  <td height="26">Order:</td>
			  <td><input name="order" id="order" type="text" value="<%=rOrder%>" style="width:25px;"></td>
			 </tr>
			 <tr>
			  <td height="40"></td>
			  <td><input type="button" name="Button" value="Submit" onClick="return ValidateForm('<%=pagename%>');"> <input type="reset" name="Submit2" value="Reset"></td>
			 </tr>
			</table>
		   </form>
<%
			Else
				If action = "edit" Then
					sql = "UPDATE "&pagetable&" SET fldQuestion='"&Clean(Request("question"))&"',fldAnswer='"&Clean(Request("answer"))&"',fldOrder="&Clean(Request("order"))&" WHERE ID = " & id
					msg = pageobject & " has been edited."
				Else
					sql = "INSERT INTO "&pagetable&" (id,fldQuestion,fldAnswer,fldOrder) VALUES ('','"&Clean(Request("question"))&"','"&Clean(InsertBreaks(Request("answer")))&"',"&Clean(Request("order"))&")"
					msg = pageobject & " has been added."
				End If
				ExecRS(sql)
				Response.Redirect(pagename&"?msg="&Server.UrlEncode(msg))	
			End If
		Case "delete"
			If candelete = True Then
				DeleteRecord pagename,pagetable,pageobject,id
			End If
	End Select
%>		
<!--#include file="include/footer.asp"-->        