 </script>
 <!--- no security --->
 <cfquery name="ctPermitType" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
-	select * from ctpermit_type
+	select permit_type from ctpermit_type order by permit_type
+</cfquery>
+<cfquery name="ctPermitRegulation" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
+	select permit_regulation from ctpermit_regulation order by permit_regulation
 </cfquery>
 <cfif #action# is "nothing">
 <cfoutput>

		 			onchange="getAgent('contact_agent_id','ContactAgent','newPermit',this.value); return false;"
			  		onKeyUp="return noenter();">

			  	<label for="issued_Date">Issued Date</label>
				<input type="datetime" id="issued_date" name="issued_date" value="#dateformat(issued_Date,"yyyy-mm-dd")#">

			  	<label for="renewed_date">Renewed Date</label>
			  	<input type="datetime" id="renewed_date" name="renewed_date" value="#dateformat(renewed_Date,"yyyy-mm-dd")#">


			  	<label for="exp_date">Expiration Date</label>
			  	<input type="datetime" id="exp_date" name="exp_date" value="#dateformat(exp_Date,"yyyy-mm-dd")#">

			  	<label for="permit_remarks">Remarks</label>
			  	<textarea name="permit_remarks" class="largetextarea">#permit_remarks#</textarea>

			  	<table width="100%">
					<tr>

	Something bad happened. You didn't pass this form a permit_id. Go back and try again.<cfabort>
</cfif>
<cfquery name="permitInfo" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
	select
		permit.permit_id,
		issued_Date,
		exp_Date,
		permit_Num,
		permit_remarks
	from
		permit
	where
		permit_id=#permit_id#
</cfquery>
<table border width="100%">
	<tr>
		<td width="50%"  valign="top">
			<form name="editPermit" action="Permit.cfm" method="post">
				<input type="hidden" name="action" value="saveChanges">
				<input type="hidden" name="permit_id" value="#permit_id#">

				<p>The Basics</p>

				<label for="permit_Num">Permit Number</label>
			  	<input type="text" name="permit_Num" value="#permit_Num#">

				<label for="issued_Date">Issued Date</label>
				<input type="datetime" id="issued_date" name="issued_date" value="#dateformat(issued_Date,"yyyy-mm-dd")#">

			  	<label for="exp_date">Expiration Date</label>
			  	<input type="datetime" id="exp_date" name="exp_date" value="#dateformat(exp_Date,"yyyy-mm-dd")#">

				<label for="permit_remarks">Remarks</label>
			  	<textarea name="permit_remarks" class="largetextarea">#permit_remarks#</textarea>

				<p>
					Type & Regulation
				</p>

				<cfquery name="permitType" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
					select * from permit_type where permit_id=#permit_id#
				</cfquery>
				<table border>
					<tr>
						<th>Permit Type</th>
						<th>Regulation</th>
					</tr>
					<cfloop query="permitType">
						<tr>
							<td>
								<select name="permit_type_#permit_type_id#" size="1">
									<option value=""></option>
									<cfloop query="ctPermitType">
										<option <cfif #ctPermitType.permit_type# is "#permitType.permit_type#"> selected </cfif>value = "#ctPermitType.permit_type#">#ctPermitType.permit_type#</option>
									</cfloop>
								</select>
							</td>
							<td>

								<select name="permit_regulation_#permit_type_id#" size="1">
									<option value=""></option>
									<cfloop query="ctPermitRegulation">
										<option <cfif #ctPermitRegulation.permit_type# is "#permitType.permit_regulation#"> selected </cfif>
										value = "#ctPermitRegulation.permit_type#">#ctPermitRegulation.permit_type#</option>
									</cfloop>
								</select>
							</td>
						</tr>

					</cfloop>

				</table>


				<label for="permit_Type">Permit Type</label>
				<select name="permit_Type" size="1">
