<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
	<script language="javascript">
	// var tname = new Array();
	 var tname='';
     function fun1(name)
     {
        var fname;
       tname = tname+','+name;
       var templateName = document.getElementById("deleteData");
       templateName.value = tname;
     }
     
     function fun2()
     {
       alert("record deleted"); 
       //location.href="createAssociation.form";
       return document.location="letterGenerate.form";
     }
     
    </script>
  <smvc:form id="associationForm" action="createAssociation.form">
  	<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
 	   <table border="0" width="70%" valign="bottom" align="center" class="dialogBox" cellpadding="4">
 	                <tr>
			      	    <td colspan="3" align="center"  class="dialogTitle"><b>Letter Administration</b></td>
			        </tr>
			         <tr>
			   			<td align="center"><b>Letter Template </b></td>
			   			<td align="center"><b>Query to use</b></td>
			   			<td></td>
			   		</tr>
			          <c:forEach var="qfm" items="${templateQueryList.queryAssociationMap}" varStatus="s">
			        	 <tr align="center">
		      				 <td align="left"><c:out value="${qfm.key}"/></td>
				   		  	  <td>
				   		  	     <select name="template_name" path="template_name" id="<c:out value="${s.count}"/>" >
			      			       <option value="select"> </option>
			      			          <c:forEach var="qdata" items="${templateQueryList.queryAssociationList}">
				   		 		         <c:if test="${qfm.key==qdata.template_name}">
				   		 		               <c:set var="flag" value="false"/>
				   		 		               	  <c:forEach var="qfm1" items="${qfm.value}">
				   		 		               	    <c:choose>
				   		 		               	     <c:when test="${qfm1.description==qdata.query_name}">
				   		 		               	         <option value="<c:out value="${qfm1.description},${qfm1.id},${qfm.key}"/>" selected ="<c:out value="${qdata.query_name}"/>"><c:out value="${qfm1.description}"/></option>
				   		 		               	      </c:when>
				   		 		               	     <c:otherwise>
				   		 		               	        <option value="<c:out value="${qfm1.description}"/>,<c:out value="${qfm1.id}"/>,<c:out value="${qfm.key}"/>"><c:out value="${qfm1.description}"/></option>
				   		 		               	     </c:otherwise>
				   		 		               	     </c:choose>
				   		 		               	   </c:forEach>	
									         </c:if>
									    </c:forEach>
										   <c:if test="${flag==true}">
									  		   	<c:forEach var="qfm1" items="${qfm.value}">
					      			                <option value="<c:out value="${qfm1.description},${qfm1.id},${qfm.key}"/>"><c:out value="${qfm1.description}"/></option>
										       </c:forEach>	
									   </c:if>
									    <c:set var="flag" value="true"/>
							     </select>
				   		  	  </td>
				   		  	  <td><input type="checkbox" name="cbox" id="cbox" onclick="fun1('<c:out value="${qfm.key}"/>');"/></td>
				   		  	</tr> 
      			  	  	</c:forEach>   
      	                <tr>
					       <td align="right">
			                   <input type="button" value="Back" onclick="document.location='letterGenerate.form'"/>
			                   <smvc:hidden path="actionHint" id="dispatchMethod"/>
			                   <smvc:hidden path="deleteData" id="deleteData"/>
			               </td>
						   <td align="left">
						       <input type="submit" name="button1"  value="Save"/>
						   </td>
						   <td align="center">
						       <input type="submit" name="button1"  value="Delete" onclick="dispatch('delete')"/>
						   </td>
					  </tr>
	               </table>
	               <br/>
	               <table class="dialogBox" cellpadding="4">
	               <tr>
	               <td valign="top">
	               <img src="../images/16x16/information.png"/>
	               </td>
	               <td>
	               Letters are produced by combining a template document with data from a query.<br/><br/>
	               To add letter templates, place them in this folder: <br/>
	               <a href='file://<c:out value="${emdt.patientFilesUrl }"/>/templates/' target="_blank"><img src="../images/16x16/folder.png" border="0" alt="folder"/> <c:out value="${emdt.patientFilesUrl }"/>/templates/</a> <br/><br/>
	               To create or edit queries, use the <a href="queries.jsp">Query Builder</a><br/>
	               </td>
	               </tr>
	               </table>
			       
	  </smvc:form>
