<%
Response.Buffer = EW_RESPONSE_BUFFER
%>
<!--#include file="ewcfg11.asp"-->
<!--#include file="gjcinfo.asp"-->
<!--#include file="zlogininfo.asp"-->
<!--#include file="aspfn11.asp"-->
<!--#include file="md5.asp"-->
<!--#include file="userfn11.asp"-->
<% Session.Timeout = 900 %>
<% Call ew_Header(False, EW_CHARSET) %>
<%

' Define page object
Dim gjc_list
Set gjc_list = New cgjc_list
Set Page = gjc_list

' Page init processing
gjc_list.Page_Init()

' Page main processing
gjc_list.Page_Main()

' Global Page Rendering event (in userfn*.asp)
Page_Rendering()

' Page Rendering event
gjc_list.Page_Render()
%>
<!--#include file="header.asp"-->
<% If gjc.Export = "" Then %>
<script type="text/javascript">
// Page object
var gjc_list = new ew_Page("gjc_list");
gjc_list.PageID = "list"; // Page ID
var EW_PAGE_ID = gjc_list.PageID; // For backward compatibility
// Form object
var fgjclist = new ew_Form("fgjclist");
fgjclist.FormKeyCountName = '<%= gjc_list.FormKeyCountName %>';
// Validate form
fgjclist.Validate = function() {
	if (!this.ValidateRequired)
		return true; // Ignore validation
	var $ = jQuery, fobj = this.GetForm(), $fobj = $(fobj);
	this.PostAutoSuggest();
	if ($fobj.find("#a_confirm").val() == "F")
		return true;
	var elm, felm, uelm, addcnt = 0;
	var $k = $fobj.find("#" + this.FormKeyCountName); // Get key_count
	var rowcnt = ($k[0]) ? parseInt($k.val(), 10) : 1;
	var startcnt = (rowcnt == 0) ? 0 : 1; // Check rowcnt == 0 => Inline-Add
	var gridinsert = $fobj.find("#a_list").val() == "gridinsert";
	for (var i = startcnt; i <= rowcnt; i++) {
		var infix = ($k[0]) ? String(i) : "";
		$fobj.data("rowindex", infix);
		var checkrow = (gridinsert) ? !this.EmptyRow(infix) : true;
		if (checkrow) {
			addcnt++;
			// Set up row object
			ew_ElementsToRow(fobj);
			// Fire Form_CustomValidate event
			if (!this.Form_CustomValidate(fobj))
				return false;
		} // End Grid Add checking
	}
	if (gridinsert && addcnt == 0) { // No row added
		alert(ewLanguage.Phrase("NoAddRecord"));
		return false;
	}
	return true;
}
// Check empty row
fgjclist.EmptyRow = function(infix) {
	var fobj = this.Form;
	if (ew_ValueChanged(fobj, infix, "gjc_1", false)) return false;
	if (ew_ValueChanged(fobj, infix, "urls", false)) return false;
	return true;
}
// Form_CustomValidate event
fgjclist.Form_CustomValidate = 
 function(fobj) { // DO NOT CHANGE THIS LINE!
 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
// Use JavaScript validation or not
<% If EW_CLIENT_VALIDATE Then %>
fgjclist.ValidateRequired = true; // Use JavaScript validation
<% Else %>
fgjclist.ValidateRequired = false; // No JavaScript validation
<% End If %>
// Dynamic selection lists
// Form object for search
</script>
<script type="text/javascript">
// Write your client script here, no need to add script tags.
</script>
<% End If %>
<% If gjc.Export = "" Then %>
<% Breadcrumb.Render() %>
<% End If %>
<% If gjc_list.ExportOptions.Visible Then %>
<div class="ewListExportOptions"><% gjc_list.ExportOptions.Render "body", "", "", "", "", "" %></div>
<% End If %>
<% If (gjc.Export = "") Or (EW_EXPORT_MASTER_RECORD And gjc.Export = "print") Then %>
<% End If %>
<%
If gjc.CurrentAction = "gridadd" Then
	gjc.CurrentFilter = "0=1"
End If

' Load recordset
Set gjc_list.Recordset = gjc_list.LoadRecordset()
If gjc.CurrentAction = "gridadd" Then
	gjc_list.StartRec = 1
	gjc_list.DisplayRecs = gjc.GridAddRowCount
	gjc_list.TotalRecs = gjc_list.DisplayRecs
	gjc_list.StopRec = gjc_list.DisplayRecs
Else
	gjc_list.TotalRecs = gjc_list.Recordset.RecordCount
	gjc_list.StartRec = 1
	If gjc_list.DisplayRecs <= 0 Then ' Display all records
		gjc_list.DisplayRecs = gjc_list.TotalRecs
	End If
	If Not (gjc.ExportAll And gjc.Export <> "") Then
		gjc_list.SetUpStartRec() ' Set up start record position
	End If
End If
gjc_list.RenderOtherOptions()
%>
<% gjc_list.ShowPageHeader() %>
<% gjc_list.ShowMessage %>
<table class="ewGrid"><tr><td class="ewGridContent">
<% If gjc.Export = "" Then %>
<div class="ewGridUpperPanel">
<% If gjc.CurrentAction <> "gridadd" And gjc.CurrentAction <> "gridedit" Then %>
<form name="ewPagerForm" class="ewForm form-inline" action="<%= ew_CurrentPage %>">
<table class="ewPager">
<tr><td>
<% If Not IsObject(gjc_list.Pager) Then Set gjc_list.Pager = ew_NewPrevNextPager(gjc_list.StartRec, gjc_list.DisplayRecs, gjc_list.TotalRecs) %>
<% If gjc_list.Pager.RecordCount > 0 Then %>
<table class="ewStdTable"><tbody><tr><td>
	<%= Language.Phrase("Page") %>&nbsp;
<div class="input-prepend input-append">
<!--first page button-->
	<% If gjc_list.Pager.FirstButton.Enabled Then %>
	<a class="btn btn-small" href="<%= gjc_list.PageUrl %>start=<%= gjc_list.Pager.FirstButton.Start %>"><i class="icon-step-backward"></i></a>
	<% Else %>
	<a class="btn btn-small disabled"><i class="icon-step-backward"></i></a>
	<% End If %>
<!--previous page button-->
	<% If gjc_list.Pager.PrevButton.Enabled Then %>
	<a class="btn btn-small" href="<%= gjc_list.PageUrl %>start=<%= gjc_list.Pager.PrevButton.Start %>"><i class="icon-prev"></i></a>
	<% Else %>
	<a class="btn btn-small disabled"><i class="icon-prev"></i></a>
	<% End If %>
<!--current page number-->
	<input class="input-mini" type="text" name="<%= EW_TABLE_PAGE_NO %>" value="<%= gjc_list.Pager.CurrentPage %>">
<!--next page button-->
	<% If gjc_list.Pager.NextButton.Enabled Then %>
	<a class="btn btn-small" href="<%= gjc_list.PageUrl %>start=<%= gjc_list.Pager.NextButton.Start %>"><i class="icon-play"></i></a>
	<% Else %>
	<a class="btn btn-small disabled"><i class="icon-play"></i></a>
	<% End If %>
<!--last page button-->
	<% If gjc_list.Pager.LastButton.Enabled Then %>
	<a class="btn btn-small" href="<%= gjc_list.PageUrl %>start=<%= gjc_list.Pager.LastButton.Start %>"><i class="icon-step-forward"></i></a>
	<% Else %>
	<a class="btn btn-small disabled"><i class="icon-step-forward"></i></a>
	<% End If %>
</div>
	&nbsp;<%= Language.Phrase("of") %>&nbsp;<%= gjc_list.Pager.PageCount %>
</td>
<td>
	&nbsp;&nbsp;&nbsp;&nbsp;
	<%= Language.Phrase("Record") %>&nbsp;<%= gjc_list.Pager.FromIndex %>&nbsp;<%= Language.Phrase("To") %>&nbsp;<%= gjc_list.Pager.ToIndex %>&nbsp;<%= Language.Phrase("Of") %>&nbsp;<%= gjc_list.Pager.RecordCount %>
</td>
</tr></tbody></table>
<% Else %>
	<% If Security.CanList Then %>
	<% If gjc_list.SearchWhere = "0=101" Then %>
	<p><%= Language.Phrase("EnterSearchCriteria") %></p>
	<% Else %>
	<p><%= Language.Phrase("NoRecord") %></p>
	<% End If %>
	<% Else %>
	<p><%= Language.Phrase("NoPermission") %></p>
	<% End If %>
<% End If %>
</td>
<% If gjc_list.TotalRecs > 0 Then %>
<td>
	&nbsp;&nbsp;&nbsp;&nbsp;
<input type="hidden" name="t" value="gjc">
<select name="<%= EW_TABLE_REC_PER_PAGE %>" class="input-small" onchange="this.form.submit();">
<option value="20"<% If gjc_list.DisplayRecs = 20 Then %> selected="selected"<% End If %>>20</option>
<option value="30"<% If gjc_list.DisplayRecs = 30 Then %> selected="selected"<% End If %>>30</option>
<option value="40"<% If gjc_list.DisplayRecs = 40 Then %> selected="selected"<% End If %>>40</option>
<option value="ALL"<% If gjc.RecordsPerPage = -1 Then %> selected="selected"<% End If %>><%= Language.Phrase("AllRecords") %></option>
</select>
</td>
<% End If %>
</tr></table>
</form>
<% End If %>
<div class="ewListOtherOptions">
<%
	gjc_list.AddEditOptions.Render "body", "", "", "", "", ""
	gjc_list.DetailOptions.Render "body", "", "", "", "", ""
	gjc_list.ActionOptions.Render "body", "", "", "", "", ""
%>
</div>
</div>
<% End If %>
<form name="fgjclist" id="fgjclist" class="ewForm form-inline" action="<%= ew_CurrentPage %>" method="post">
<input type="hidden" name="t" value="gjc">
<div id="gmp_gjc" class="ewGridMiddlePanel">
<% If gjc_list.TotalRecs > 0 Or gjc.CurrentAction = "add" Or gjc.CurrentAction = "copy" Then %>
<table id="tbl_gjclist" class="ewTable ewTableSeparate">
<%= gjc.TableCustomInnerHtml %>
<thead><!-- Table header -->
	<tr class="ewTableHeader">
<%
Call gjc_list.RenderListOptions()

' Render list options (header, left)
gjc_list.ListOptions.Render "header", "left", "", "", "", ""
%>
<% If gjc.id.Visible Then ' id %>
	<% If gjc.SortUrl(gjc.id) = "" Then %>
		<td><div id="elh_gjc_id" class="gjc_id"><div class="ewTableHeaderCaption"><%= gjc.id.FldCaption %></div></div></td>
	<% Else %>
		<td><div class="ewPointer" onclick="ew_Sort(event,'<%= gjc.SortUrl(gjc.id) %>',1);"><div id="elh_gjc_id" class="gjc_id">
			<div class="ewTableHeaderBtn"><span class="ewTableHeaderCaption"><%= gjc.id.FldCaption %></span><span class="ewTableHeaderSort"><% If gjc.id.Sort = "ASC" Then %><span class="caret ewSortUp"></span><% ElseIf gjc.id.Sort = "DESC" Then %><span class="caret"></span><% End If %></span></div>
        </div></div></td>
	<% End If %>
<% End If %>		
<% If gjc.gjc_1.Visible Then ' gjc %>
	<% If gjc.SortUrl(gjc.gjc_1) = "" Then %>
		<td><div id="elh_gjc_gjc_1" class="gjc_gjc_1"><div class="ewTableHeaderCaption"><%= gjc.gjc_1.FldCaption %></div></div></td>
	<% Else %>
		<td><div class="ewPointer" onclick="ew_Sort(event,'<%= gjc.SortUrl(gjc.gjc_1) %>',1);"><div id="elh_gjc_gjc_1" class="gjc_gjc_1">
			<div class="ewTableHeaderBtn"><span class="ewTableHeaderCaption"><%= gjc.gjc_1.FldCaption %></span><span class="ewTableHeaderSort"><% If gjc.gjc_1.Sort = "ASC" Then %><span class="caret ewSortUp"></span><% ElseIf gjc.gjc_1.Sort = "DESC" Then %><span class="caret"></span><% End If %></span></div>
        </div></div></td>
	<% End If %>
<% End If %>		
<% If gjc.urls.Visible Then ' urls %>
	<% If gjc.SortUrl(gjc.urls) = "" Then %>
		<td><div id="elh_gjc_urls" class="gjc_urls"><div class="ewTableHeaderCaption"><%= gjc.urls.FldCaption %></div></div></td>
	<% Else %>
		<td><div class="ewPointer" onclick="ew_Sort(event,'<%= gjc.SortUrl(gjc.urls) %>',1);"><div id="elh_gjc_urls" class="gjc_urls">
			<div class="ewTableHeaderBtn"><span class="ewTableHeaderCaption"><%= gjc.urls.FldCaption %></span><span class="ewTableHeaderSort"><% If gjc.urls.Sort = "ASC" Then %><span class="caret ewSortUp"></span><% ElseIf gjc.urls.Sort = "DESC" Then %><span class="caret"></span><% End If %></span></div>
        </div></div></td>
	<% End If %>
<% End If %>		
<%

' Render list options (header, right)
gjc_list.ListOptions.Render "header", "right", "", "", "", ""
%>
	</tr>
</thead>
<tbody><!-- Table body -->
<%
	If gjc.CurrentAction = "add" Or gjc.CurrentAction = "copy" Then
		gjc_list.RowIndex = 0
		gjc_list.KeyCount = gjc_list.RowIndex
		If gjc.CurrentAction = "add" Then
			Call gjc_list.LoadDefaultValues()
		End If
		If gjc.EventCancelled Then ' Insert failed
			Call gjc_list.RestoreFormValues() ' Restore form values
		End If

		' Set row properties
		Call gjc.ResetAttrs()
		gjc.RowAttrs.AddAttributes Array(Array("data-rowindex", 0), Array("id", "r0_gjc"), Array("data-rowtype", EW_ROWTYPE_ADD))
		gjc.RowType = EW_ROWTYPE_ADD

		' Render row
		Call gjc_list.RenderRow()

		' Render list options
		Call gjc_list.RenderListOptions()
		gjc_list.StartRowCnt = 0
%>
	<tr<%= gjc.RowAttributes %>>
<%

' Render list options (body, left)
gjc_list.ListOptions.Render "body", "left", gjc_list.RowCnt, "", "", ""
%>
	<% If gjc.id.Visible Then ' id %>
		<td>
<input type="hidden" data-field="x_id" name="o<%= gjc_list.RowIndex %>_id" id="o<%= gjc_list.RowIndex %>_id" value="<%= Server.HTMLEncode(gjc.id.OldValue&"") %>">
</td>
	<% End If %>
	<% If gjc.gjc_1.Visible Then ' gjc %>
		<td>
<span id="el<%= gjc_list.RowCnt %>_gjc_gjc_1" class="control-group gjc_gjc_1">
<input type="text" data-field="x_gjc_1" name="x<%= gjc_list.RowIndex %>_gjc_1" id="x<%= gjc_list.RowIndex %>_gjc_1" size="30" maxlength="50" placeholder="<%= gjc.gjc_1.PlaceHolder %>" value="<%= gjc.gjc_1.EditValue %>"<%= gjc.gjc_1.EditAttributes %>>
</span>
<input type="hidden" data-field="x_gjc_1" name="o<%= gjc_list.RowIndex %>_gjc_1" id="o<%= gjc_list.RowIndex %>_gjc_1" value="<%= Server.HTMLEncode(gjc.gjc_1.OldValue&"") %>">
</td>
	<% End If %>
	<% If gjc.urls.Visible Then ' urls %>
		<td>
<span id="el<%= gjc_list.RowCnt %>_gjc_urls" class="control-group gjc_urls">
<input type="text" data-field="x_urls" name="x<%= gjc_list.RowIndex %>_urls" id="x<%= gjc_list.RowIndex %>_urls" size="30" maxlength="50" placeholder="<%= gjc.urls.PlaceHolder %>" value="<%= gjc.urls.EditValue %>"<%= gjc.urls.EditAttributes %>>
</span>
<input type="hidden" data-field="x_urls" name="o<%= gjc_list.RowIndex %>_urls" id="o<%= gjc_list.RowIndex %>_urls" value="<%= Server.HTMLEncode(gjc.urls.OldValue&"") %>">
</td>
	<% End If %>
<%

' Render list options (body, right)
gjc_list.ListOptions.Render "body", "right", gjc_list.RowCnt, "", "", ""
%>
<script type="text/javascript">
fgjclist.UpdateOpts(<%= gjc_list.RowIndex %>);
</script>
	</tr>
<%
End If
%>
<%
If (gjc.ExportAll And gjc.Export <> "") Then
	gjc_list.StopRec = gjc_list.TotalRecs
Else

	' Set the last record to display
	If gjc_list.TotalRecs > gjc_list.StartRec + gjc_list.DisplayRecs - 1 Then
		gjc_list.StopRec = gjc_list.StartRec + gjc_list.DisplayRecs - 1
	Else
		gjc_list.StopRec = gjc_list.TotalRecs
	End If
End If

' Restore number of post back records
If IsObject(ObjForm) And Not (ObjForm Is Nothing) Then
	ObjForm.Index = -1
	If ObjForm.HasValue(gjc_list.FormKeyCountName) And (gjc.CurrentAction = "gridadd" Or gjc.CurrentAction = "gridedit" Or gjc.CurrentAction = "F") Then
		gjc_list.KeyCount = ObjForm.GetValue(gjc_list.FormKeyCountName)
		gjc_list.StopRec = gjc_list.StartRec + gjc_list.KeyCount - 1
	End If
End If

' Move to first record
gjc_list.RecCnt = gjc_list.StartRec - 1
If Not gjc_list.Recordset.Eof Then
	gjc_list.Recordset.MoveFirst
	If gjc_list.StartRec > 1 Then gjc_list.Recordset.Move gjc_list.StartRec - 1
ElseIf Not gjc.AllowAddDeleteRow And gjc_list.StopRec = 0 Then
	gjc_list.StopRec = gjc.GridAddRowCount
End If

' Initialize Aggregate
gjc.RowType = EW_ROWTYPE_AGGREGATEINIT
Call gjc.ResetAttrs()
Call gjc_list.RenderRow()
gjc_list.RowCnt = 0
If gjc.CurrentAction = "gridadd" Then gjc_list.RowIndex = 0
If gjc.CurrentAction = "gridedit" Then gjc_list.RowIndex = 0

' Output date rows
Do While CLng(gjc_list.RecCnt) < CLng(gjc_list.StopRec)
	gjc_list.RecCnt = gjc_list.RecCnt + 1
	If CLng(gjc_list.RecCnt) >= CLng(gjc_list.StartRec) Then
		gjc_list.RowCnt = gjc_list.RowCnt + 1
		If gjc.CurrentAction = "gridadd" Or gjc.CurrentAction = "gridedit" Or gjc.CurrentAction = "F" Then
			gjc_list.RowIndex = gjc_list.RowIndex + 1
			ObjForm.Index = gjc_list.RowIndex
			If ObjForm.HasValue(gjc_list.FormActionName) Then
				gjc_list.RowAction = ObjForm.GetValue(gjc_list.FormActionName) & ""
			ElseIf gjc.CurrentAction = "gridadd" Then
				gjc_list.RowAction = "insert"
			Else
				gjc_list.RowAction = ""
			End If
		End If

	' Set up key count
	gjc_list.KeyCount = gjc_list.RowIndex
	Call gjc.ResetAttrs()
	gjc.CssClass = ""
	If gjc.CurrentAction = "gridadd" Then
		Call gjc_list.LoadDefaultValues() ' Load default values
	Else
		Call gjc_list.LoadRowValues(gjc_list.Recordset) ' Load row values
	End If
	gjc.RowType = EW_ROWTYPE_VIEW ' Render view
	If gjc.CurrentAction = "gridadd" Then ' Grid add
		gjc.RowType = EW_ROWTYPE_ADD ' Render add
	End If
	If gjc.CurrentAction = "gridadd" And gjc.EventCancelled Then ' Insert failed
		If Not ObjForm.HasValue("k_blankrow") Then
			Call gjc_list.RestoreCurrentRowFormValues(gjc_list.RowIndex) ' Restore form values
		End If
	End If
	If gjc.CurrentAction = "gridedit" Then ' Grid edit
		If gjc.EventCancelled Then ' Update failed
			Call gjc_list.RestoreCurrentRowFormValues(gjc_list.RowIndex) ' Restore form values
		End If
		If gjc_list.RowAction = "insert" Then
			gjc.RowType = EW_ROWTYPE_ADD ' Render add
		Else
			gjc.RowType = EW_ROWTYPE_EDIT ' Render edit
		End If
	End If
	If gjc.RowType = EW_ROWTYPE_EDIT Then ' Edit row
		gjc_list.EditRowCnt = gjc_list.EditRowCnt + 1
	End If

	' Set up row id / data-rowindex
	gjc.RowAttrs.AddAttributes Array(Array("data-rowindex", gjc_list.RowCnt), Array("id", "r" & gjc_list.RowCnt & "_gjc"), Array("data-rowtype", gjc.RowType))

	' Render row
	Call gjc_list.RenderRow()

	' Render list options
	Call gjc_list.RenderListOptions()

	' Skip delete row / empty row for confirm page
	If gjc_list.RowAction <> "delete" And gjc_list.RowAction <> "insertdelete" And Not (gjc_list.RowAction = "insert" And gjc.CurrentAction = "F" And gjc_list.EmptyRow()) Then
%>
	<tr<%= gjc.RowAttributes %>>
<%

' Render list options (body, left)
gjc_list.ListOptions.Render "body", "left", gjc_list.RowCnt, "", "", ""
%>
	<% If gjc.id.Visible Then ' id %>
		<td<%= gjc.id.CellAttributes %>>
<% If gjc.RowType = EW_ROWTYPE_ADD Then ' Add Record %>
<input type="hidden" data-field="x_id" name="o<%= gjc_list.RowIndex %>_id" id="o<%= gjc_list.RowIndex %>_id" value="<%= Server.HTMLEncode(gjc.id.OldValue&"") %>">
<% End If %>
<% If gjc.RowType = EW_ROWTYPE_EDIT Then ' Edit Record %>
<span id="el<%= gjc_list.RowCnt %>_gjc_id" class="control-group gjc_id">
<span<%= gjc.id.ViewAttributes %>>
<%= gjc.id.EditValue %>
</span>
</span>
<input type="hidden" data-field="x_id" name="x<%= gjc_list.RowIndex %>_id" id="x<%= gjc_list.RowIndex %>_id" value="<%= Server.HTMLEncode(gjc.id.CurrentValue&"") %>">
<% End If %>
<% If gjc.RowType = EW_ROWTYPE_VIEW Then ' View Record %>
<span<%= gjc.id.ViewAttributes %>>
<%= gjc.id.ListViewValue %>
</span>
<% End If %>
<a id="<%= gjc_list.PageObjName & "_row_" & gjc_list.RowCnt %>"></a></td>
	<% End If %>
	<% If gjc.gjc_1.Visible Then ' gjc %>
		<td<%= gjc.gjc_1.CellAttributes %>>
<% If gjc.RowType = EW_ROWTYPE_ADD Then ' Add Record %>
<span id="el<%= gjc_list.RowCnt %>_gjc_gjc_1" class="control-group gjc_gjc_1">
<input type="text" data-field="x_gjc_1" name="x<%= gjc_list.RowIndex %>_gjc_1" id="x<%= gjc_list.RowIndex %>_gjc_1" size="30" maxlength="50" placeholder="<%= gjc.gjc_1.PlaceHolder %>" value="<%= gjc.gjc_1.EditValue %>"<%= gjc.gjc_1.EditAttributes %>>
</span>
<input type="hidden" data-field="x_gjc_1" name="o<%= gjc_list.RowIndex %>_gjc_1" id="o<%= gjc_list.RowIndex %>_gjc_1" value="<%= Server.HTMLEncode(gjc.gjc_1.OldValue&"") %>">
<% End If %>
<% If gjc.RowType = EW_ROWTYPE_EDIT Then ' Edit Record %>
<span id="el<%= gjc_list.RowCnt %>_gjc_gjc_1" class="control-group gjc_gjc_1">
<input type="text" data-field="x_gjc_1" name="x<%= gjc_list.RowIndex %>_gjc_1" id="x<%= gjc_list.RowIndex %>_gjc_1" size="30" maxlength="50" placeholder="<%= gjc.gjc_1.PlaceHolder %>" value="<%= gjc.gjc_1.EditValue %>"<%= gjc.gjc_1.EditAttributes %>>
</span>
<% End If %>
<% If gjc.RowType = EW_ROWTYPE_VIEW Then ' View Record %>
<span<%= gjc.gjc_1.ViewAttributes %>>
<%= gjc.gjc_1.ListViewValue %>
</span>
<% End If %>
</td>
	<% End If %>
	<% If gjc.urls.Visible Then ' urls %>
		<td<%= gjc.urls.CellAttributes %>>
<% If gjc.RowType = EW_ROWTYPE_ADD Then ' Add Record %>
<span id="el<%= gjc_list.RowCnt %>_gjc_urls" class="control-group gjc_urls">
<input type="text" data-field="x_urls" name="x<%= gjc_list.RowIndex %>_urls" id="x<%= gjc_list.RowIndex %>_urls" size="30" maxlength="50" placeholder="<%= gjc.urls.PlaceHolder %>" value="<%= gjc.urls.EditValue %>"<%= gjc.urls.EditAttributes %>>
</span>
<input type="hidden" data-field="x_urls" name="o<%= gjc_list.RowIndex %>_urls" id="o<%= gjc_list.RowIndex %>_urls" value="<%= Server.HTMLEncode(gjc.urls.OldValue&"") %>">
<% End If %>
<% If gjc.RowType = EW_ROWTYPE_EDIT Then ' Edit Record %>
<span id="el<%= gjc_list.RowCnt %>_gjc_urls" class="control-group gjc_urls">
<input type="text" data-field="x_urls" name="x<%= gjc_list.RowIndex %>_urls" id="x<%= gjc_list.RowIndex %>_urls" size="30" maxlength="50" placeholder="<%= gjc.urls.PlaceHolder %>" value="<%= gjc.urls.EditValue %>"<%= gjc.urls.EditAttributes %>>
</span>
<% End If %>
<% If gjc.RowType = EW_ROWTYPE_VIEW Then ' View Record %>
<span<%= gjc.urls.ViewAttributes %>>
<%= gjc.urls.ListViewValue %>
</span>
<% End If %>
</td>
	<% End If %>
<%

' Render list options (body, right)
gjc_list.ListOptions.Render "body", "right", gjc_list.RowCnt, "", "", ""
%>
	</tr>
<% If gjc.RowType = EW_ROWTYPE_ADD Or gjc.RowType = EW_ROWTYPE_EDIT Then %>
<script type="text/javascript">
fgjclist.UpdateOpts(<%= gjc_list.RowIndex %>);
</script>
<% End If %>
<%
	End If
	End If ' End delete row checking
	If gjc.CurrentAction <> "gridadd" Then
		If Not gjc_list.Recordset.Eof Then gjc_list.Recordset.MoveNext()
	End If
Loop
%>
<%
	If gjc.CurrentAction = "gridadd" Or gjc.CurrentAction = "gridedit" Then
		gjc_list.RowIndex = "$rowindex$"
		gjc_list.LoadDefaultValues()

		' Set row properties
		Call gjc.ResetAttrs()
		gjc.RowAttrs.AddAttributes Array(Array("data-rowindex", gjc_list.RowIndex), Array("id", "r0_gjc"), Array("data-rowtype", EW_ROWTYPE_ADD))
		gjc.RowAttrs.UpdateAttribute "class", "ewTemplate"
		gjc.RowType = EW_ROWTYPE_ADD

		' Render row
		Call gjc_list.RenderRow()

		' Render list options
		Call gjc_list.RenderListOptions()
		gjc_list.StartRowCnt = 0
%>
	<tr<%= gjc.RowAttributes %>>
<%

' Render list options (body, left)
gjc_list.ListOptions.Render "body", "left", gjc_list.RowIndex, "", "", ""
%>
	<% If gjc.id.Visible Then ' id %>
		<td>
<input type="hidden" data-field="x_id" name="o<%= gjc_list.RowIndex %>_id" id="o<%= gjc_list.RowIndex %>_id" value="<%= Server.HTMLEncode(gjc.id.OldValue&"") %>">
</td>
	<% End If %>
	<% If gjc.gjc_1.Visible Then ' gjc %>
		<td>
<span id="el$rowindex$_gjc_gjc_1" class="control-group gjc_gjc_1">
<input type="text" data-field="x_gjc_1" name="x<%= gjc_list.RowIndex %>_gjc_1" id="x<%= gjc_list.RowIndex %>_gjc_1" size="30" maxlength="50" placeholder="<%= gjc.gjc_1.PlaceHolder %>" value="<%= gjc.gjc_1.EditValue %>"<%= gjc.gjc_1.EditAttributes %>>
</span>
<input type="hidden" data-field="x_gjc_1" name="o<%= gjc_list.RowIndex %>_gjc_1" id="o<%= gjc_list.RowIndex %>_gjc_1" value="<%= Server.HTMLEncode(gjc.gjc_1.OldValue&"") %>">
</td>
	<% End If %>
	<% If gjc.urls.Visible Then ' urls %>
		<td>
<span id="el$rowindex$_gjc_urls" class="control-group gjc_urls">
<input type="text" data-field="x_urls" name="x<%= gjc_list.RowIndex %>_urls" id="x<%= gjc_list.RowIndex %>_urls" size="30" maxlength="50" placeholder="<%= gjc.urls.PlaceHolder %>" value="<%= gjc.urls.EditValue %>"<%= gjc.urls.EditAttributes %>>
</span>
<input type="hidden" data-field="x_urls" name="o<%= gjc_list.RowIndex %>_urls" id="o<%= gjc_list.RowIndex %>_urls" value="<%= Server.HTMLEncode(gjc.urls.OldValue&"") %>">
</td>
	<% End If %>
<%

' Render list options (body, right)
gjc_list.ListOptions.Render "body", "right", gjc_list.RowCnt, "", "", ""
%>
<script type="text/javascript">
fgjclist.UpdateOpts(<%= gjc_list.RowIndex %>);
</script>
	</tr>
<%
End If
%>
</tbody>
</table>
<% End If %>
<% If gjc.CurrentAction = "add" Or gjc.CurrentAction = "copy" Then %>
<input type="hidden" name="<%= gjc_list.FormKeyCountName %>" id="<%= gjc_list.FormKeyCountName %>" value="<%= gjc_list.KeyCount %>">
<% End If %>
<% If gjc.CurrentAction = "gridadd" Then %>
<input type="hidden" name="a_list" id="a_list" value="gridinsert">
<input type="hidden" name="<%= gjc_list.FormKeyCountName %>" id="<%= gjc_list.FormKeyCountName %>" value="<%= gjc_list.KeyCount %>">
<%= gjc_list.MultiSelectKey %>
<% End If %>
<% If gjc.CurrentAction = "gridedit" Then %>
<input type="hidden" name="a_list" id="a_list" value="gridupdate">
<input type="hidden" name="<%= gjc_list.FormKeyCountName %>" id="<%= gjc_list.FormKeyCountName %>" value="<%= gjc_list.KeyCount %>">
<%= gjc_list.MultiSelectKey %>
<% End If %>
<% If gjc.CurrentAction = "" Then %>
<input type="hidden" name="a_list" id="a_list" value="">
<% End If %>
</div>
</form>
<%

' Close recordset and connection
gjc_list.Recordset.Close
Set gjc_list.Recordset = Nothing
%>
<% If gjc_list.TotalRecs > 0 Then %>
<% If gjc.Export = "" Then %>
<div class="ewGridLowerPanel">
<% If gjc.CurrentAction <> "gridadd" And gjc.CurrentAction <> "gridedit" Then %>
<form name="ewPagerForm" class="ewForm form-inline" action="<%= ew_CurrentPage %>">
<table class="ewPager">
<tr><td>
<% If Not IsObject(gjc_list.Pager) Then Set gjc_list.Pager = ew_NewPrevNextPager(gjc_list.StartRec, gjc_list.DisplayRecs, gjc_list.TotalRecs) %>
<% If gjc_list.Pager.RecordCount > 0 Then %>
<table class="ewStdTable"><tbody><tr><td>
	<%= Language.Phrase("Page") %>&nbsp;
<div class="input-prepend input-append">
<!--first page button-->
	<% If gjc_list.Pager.FirstButton.Enabled Then %>
	<a class="btn btn-small" href="<%= gjc_list.PageUrl %>start=<%= gjc_list.Pager.FirstButton.Start %>"><i class="icon-step-backward"></i></a>
	<% Else %>
	<a class="btn btn-small disabled"><i class="icon-step-backward"></i></a>
	<% End If %>
<!--previous page button-->
	<% If gjc_list.Pager.PrevButton.Enabled Then %>
	<a class="btn btn-small" href="<%= gjc_list.PageUrl %>start=<%= gjc_list.Pager.PrevButton.Start %>"><i class="icon-prev"></i></a>
	<% Else %>
	<a class="btn btn-small disabled"><i class="icon-prev"></i></a>
	<% End If %>
<!--current page number-->
	<input class="input-mini" type="text" name="<%= EW_TABLE_PAGE_NO %>" value="<%= gjc_list.Pager.CurrentPage %>">
<!--next page button-->
	<% If gjc_list.Pager.NextButton.Enabled Then %>
	<a class="btn btn-small" href="<%= gjc_list.PageUrl %>start=<%= gjc_list.Pager.NextButton.Start %>"><i class="icon-play"></i></a>
	<% Else %>
	<a class="btn btn-small disabled"><i class="icon-play"></i></a>
	<% End If %>
<!--last page button-->
	<% If gjc_list.Pager.LastButton.Enabled Then %>
	<a class="btn btn-small" href="<%= gjc_list.PageUrl %>start=<%= gjc_list.Pager.LastButton.Start %>"><i class="icon-step-forward"></i></a>
	<% Else %>
	<a class="btn btn-small disabled"><i class="icon-step-forward"></i></a>
	<% End If %>
</div>
	&nbsp;<%= Language.Phrase("of") %>&nbsp;<%= gjc_list.Pager.PageCount %>
</td>
<td>
	&nbsp;&nbsp;&nbsp;&nbsp;
	<%= Language.Phrase("Record") %>&nbsp;<%= gjc_list.Pager.FromIndex %>&nbsp;<%= Language.Phrase("To") %>&nbsp;<%= gjc_list.Pager.ToIndex %>&nbsp;<%= Language.Phrase("Of") %>&nbsp;<%= gjc_list.Pager.RecordCount %>
</td>
</tr></tbody></table>
<% Else %>
	<% If Security.CanList Then %>
	<% If gjc_list.SearchWhere = "0=101" Then %>
	<p><%= Language.Phrase("EnterSearchCriteria") %></p>
	<% Else %>
	<p><%= Language.Phrase("NoRecord") %></p>
	<% End If %>
	<% Else %>
	<p><%= Language.Phrase("NoPermission") %></p>
	<% End If %>
<% End If %>
</td>
<% If gjc_list.TotalRecs > 0 Then %>
<td>
	&nbsp;&nbsp;&nbsp;&nbsp;
<input type="hidden" name="t" value="gjc">
<select name="<%= EW_TABLE_REC_PER_PAGE %>" class="input-small" onchange="this.form.submit();">
<option value="20"<% If gjc_list.DisplayRecs = 20 Then %> selected="selected"<% End If %>>20</option>
<option value="30"<% If gjc_list.DisplayRecs = 30 Then %> selected="selected"<% End If %>>30</option>
<option value="40"<% If gjc_list.DisplayRecs = 40 Then %> selected="selected"<% End If %>>40</option>
<option value="ALL"<% If gjc.RecordsPerPage = -1 Then %> selected="selected"<% End If %>><%= Language.Phrase("AllRecords") %></option>
</select>
</td>
<% End If %>
</tr></table>
</form>
<% End If %>
<div class="ewListOtherOptions">
<%
	gjc_list.AddEditOptions.Render "body", "bottom", "", "", "", ""
	gjc_list.DetailOptions.Render "body", "bottom", "", "", "", ""
	gjc_list.ActionOptions.Render "body", "bottom", "", "", "", ""
%>
</div>
</div>
<% End If %>
<% End If %>
</td></tr></table>
<% If gjc.Export = "" Then %>
<script type="text/javascript">
fgjclist.Init();
<% If EW_MOBILE_REFLOW And ew_IsMobile() Then %>
ew_Reflow();
<% End If %>
</script>
<% End If %>
<%
gjc_list.ShowPageFooter()
If EW_DEBUG_ENABLED Then Response.Write ew_DebugMsg()
%>
<% If gjc.Export = "" Then %>
<script type="text/javascript">
// Write your table-specific startup script here
// document.write("page loaded");
</script>
<% End If %>
<!--#include file="footer.asp"-->
<%

' Drop page object
Set gjc_list = Nothing
%>
<%

' -----------------------------------------------------------------
' Page Class
'
Class cgjc_list

	' Page ID
	Public Property Get PageID()
		PageID = "list"
	End Property

	' Project ID
	Public Property Get ProjectID()
		ProjectID = "{A697AD8C-67CB-4820-BF4F-84306CDBBEE7}"
	End Property

	' Table Name
	Public Property Get TableName()
		TableName = "gjc"
	End Property

	' Page Object Name
	Public Property Get PageObjName()
		PageObjName = "gjc_list"
	End Property

	' Grid form hidden field names
	Dim FormName
	Dim FormActionName
	Dim FormKeyName
	Dim FormOldKeyName
	Dim FormBlankRowName
	Dim FormKeyCountName

	' Page Name
	Public Property Get PageName()
		PageName = ew_CurrentPage()
	End Property

	' Page Url
	Public Property Get PageUrl()
		PageUrl = ew_CurrentPage() & "?"
		If gjc.UseTokenInUrl Then PageUrl = PageUrl & "t=" & gjc.TableVar & "&" ' add page token
	End Property

	' Common urls
	Dim AddUrl
	Dim EditUrl
	Dim CopyUrl
	Dim DeleteUrl
	Dim ViewUrl
	Dim ListUrl

	' Export urls
	Dim ExportPrintUrl
	Dim ExportHtmlUrl
	Dim ExportExcelUrl
	Dim ExportWordUrl
	Dim ExportXmlUrl
	Dim ExportCsvUrl
	Dim ExportPdfUrl

	' Inline urls
	Dim InlineAddUrl
	Dim InlineCopyUrl
	Dim InlineEditUrl
	Dim GridAddUrl
	Dim GridEditUrl
	Dim MultiDeleteUrl
	Dim MultiUpdateUrl

	' Message
	Public Property Get Message()
		Message = Session(EW_SESSION_MESSAGE)
	End Property

	Public Property Let Message(v)
		Dim msg
		msg = Session(EW_SESSION_MESSAGE)
		Call ew_AddMessage(msg, v)
		Session(EW_SESSION_MESSAGE) = msg
	End Property

	Public Property Get FailureMessage()
		FailureMessage = Session(EW_SESSION_FAILURE_MESSAGE)
	End Property

	Public Property Let FailureMessage(v)
		Dim msg
		msg = Session(EW_SESSION_FAILURE_MESSAGE)
		Call ew_AddMessage(msg, v)
		Session(EW_SESSION_FAILURE_MESSAGE) = msg
	End Property

	Public Property Get SuccessMessage()
		SuccessMessage = Session(EW_SESSION_SUCCESS_MESSAGE)
	End Property

	Public Property Let SuccessMessage(v)
		Dim msg
		msg = Session(EW_SESSION_SUCCESS_MESSAGE)
		Call ew_AddMessage(msg, v)
		Session(EW_SESSION_SUCCESS_MESSAGE) = msg
	End Property

	Public Property Get WarningMessage()
		WarningMessage = Session(EW_SESSION_WARNING_MESSAGE)
	End Property

	Public Property Let WarningMessage(v)
		Dim msg
		msg = Session(EW_SESSION_WARNING_MESSAGE)
		Call ew_AddMessage(msg, v)
		Session(EW_SESSION_WARNING_MESSAGE) = msg
	End Property

	' Show Message
	Public Sub ShowMessage()
		Dim hidden, html, sMessage
		hidden = False
		html = ""

		' Message
		sMessage = Message
		Call Message_Showing(sMessage, "")
		If sMessage <> "" Then ' Message in Session, display
			If Not hidden Then sMessage = "<button type=""button"" class=""close"" data-dismiss=""alert"">&times;</button>" & sMessage
			html = html & "<div class=""alert alert-success ewSuccess"">" & sMessage & "</div>"
			Session(EW_SESSION_MESSAGE) = "" ' Clear message in Session
		End If

		' Warning message
		Dim sWarningMessage
		sWarningMessage = WarningMessage
		Call Message_Showing(sWarningMessage, "warning")
		If sWarningMessage <> "" Then ' Message in Session, display
			If Not hidden Then sWarningMessage = "<button type=""button"" class=""close"" data-dismiss=""alert"">&times;</button>" & sWarningMessage
			html = html & "<div class=""alert alert-warning ewWarning"">" & sWarningMessage & "</div>"
			Session(EW_SESSION_WARNING_MESSAGE) = "" ' Clear message in Session
		End If

		' Success message
		Dim sSuccessMessage
		sSuccessMessage = SuccessMessage
		Call Message_Showing(sSuccessMessage, "success")
		If sSuccessMessage <> "" Then ' Message in Session, display
			If Not hidden Then sSuccessMessage = "<button type=""button"" class=""close"" data-dismiss=""alert"">&times;</button>" & sSuccessMessage
			html = html & "<div class=""alert alert-success ewSuccess"">" & sSuccessMessage & "</div>"
			Session(EW_SESSION_SUCCESS_MESSAGE) = "" ' Clear message in Session
		End If

		' Failure message
		Dim sErrorMessage
		sErrorMessage = FailureMessage
		Call Message_Showing(sErrorMessage, "failure")
		If sErrorMessage <> "" Then ' Message in Session, display
			If Not hidden Then sErrorMessage = "<button type=""button"" class=""close"" data-dismiss=""alert"">&times;</button>" & sErrorMessage
			html = html & "<div class=""alert alert-error ewError"">" & sErrorMessage & "</div>"
			Session(EW_SESSION_FAILURE_MESSAGE) = "" ' Clear message in Session
		End If
		Response.Write "<table class=""ewStdTable""><tr><td><div class=""ewMessageDialog""" & ew_IIf(hidden, " style=""display: none;""", "") & ">" & html & "</div></td></tr></table>"
	End Sub
	Dim PageHeader
	Dim PageFooter

	' Show Page Header
	Public Sub ShowPageHeader()
		Dim sHeader
		sHeader = PageHeader
		Call Page_DataRendering(sHeader)
		If sHeader <> "" Then ' Header exists, display
			Response.Write "<p>" & sHeader & "</p>"
		End If
	End Sub

	' Show Page Footer
	Public Sub ShowPageFooter()
		Dim sFooter
		sFooter = PageFooter
		Call Page_DataRendered(sFooter)
		If sFooter <> "" Then ' Footer exists, display
			Response.Write "<p>" & sFooter & "</p>"
		End If
	End Sub

	' -----------------------
	'  Validate Page request
	'
	Public Function IsPageRequest()
		If gjc.UseTokenInUrl Then
			IsPageRequest = False
			If Not (ObjForm Is Nothing) Then
				IsPageRequest = (gjc.TableVar = ObjForm.GetValue("t"))
			End If
			If Request.QueryString("t").Count > 0 Then
				IsPageRequest = (gjc.TableVar = Request.QueryString("t"))
			End If
		Else
			IsPageRequest = True
		End If
	End Function

	' -----------------------------------------------------------------
	'  Class initialize
	'  - init objects
	'  - open ADO connection
	'
	Private Sub Class_Initialize()
		If IsEmpty(StartTimer) Then StartTimer = Timer ' Init start time

		' Grid form hidden field names
		FormName = "fgjclist"
		FormActionName = "k_action"
		FormKeyName = "k_key"
		FormOldKeyName = "k_oldkey"
		FormBlankRowName = "k_blankrow"
		FormKeyCountName = "key_count"

		' Initialize language object
		If IsEmpty(Language) Then
			Set Language = New cLanguage
			Call Language.LoadPhrases()
		End If

		' Initialize table object
		If IsEmpty(gjc) Then Set gjc = New cgjc
		Set Table = gjc

		' Initialize urls
		ExportPrintUrl = PageUrl & "export=print"
		ExportExcelUrl = PageUrl & "export=excel"
		ExportWordUrl = PageUrl & "export=word"
		ExportHtmlUrl = PageUrl & "export=html"
		ExportXmlUrl = PageUrl & "export=xml"
		ExportCsvUrl = PageUrl & "export=csv"
		ExportPdfUrl = PageUrl & "export=pdf"
		AddUrl = "gjcadd.asp"
		InlineAddUrl = PageUrl & "a=add"
		GridAddUrl = PageUrl & "a=gridadd"
		GridEditUrl = PageUrl & "a=gridedit"
		MultiDeleteUrl = "gjcdelete.asp"
		MultiUpdateUrl = "gjcupdate.asp"

		' Initialize other table object
		If IsEmpty(zlogin) Then Set zlogin = New czlogin

		' Initialize form object
		Set ObjForm = Nothing

		' Intialize page id (for backward compatibility)
		EW_PAGE_ID = "list"

		' Initialize table name (for backward compatibility)
		EW_TABLE_NAME = "gjc"

		' Open connection to the database
		If IsEmpty(Conn) Then Call ew_Connect()

		' List options
		Set ListOptions = New cListOptions
		ListOptions.TableVar = gjc.TableVar

		' Export options
		Set ExportOptions = New cListOptions
		ExportOptions.TableVar = gjc.TableVar
		ExportOptions.Tag = "div"
		ExportOptions.TagClassName = "ewExportOption"

		' Other options
		Set AddEditOptions = New cListOptions
		AddEditOptions.Tag = "div"
		AddEditOptions.TagClassName = "ewAddEditOption"
		Set DetailOptions = New cListOptions
		DetailOptions.Tag = "div"
		DetailOptions.TagClassName = "ewDetailOption"
		Set ActionOptions = New cListOptions
		ActionOptions.Tag = "div"
		ActionOptions.TagClassName = "ewActionOption"
	End Sub

	' -----------------------------------------------------------------
	'  Subroutine Page_Init
	'  - called before page main
	'  - check Security
	'  - set up response header
	'  - call page load events
	'
	Sub Page_Init()
		Set Security = New cAdvancedSecurity
		If Not Security.IsLoggedIn() Then Call Security.AutoLogin()
		If Not Security.IsLoggedIn() Then
			Call Security.SaveLastUrl()
			Call Page_Terminate("login.asp")
		End If

		' Table Permission loading event
		Call Security.TablePermission_Loading()
		Call Security.LoadCurrentUserLevel(ProjectID & TableName)

		' Table Permission loaded event
		Call Security.TablePermission_Loaded()
		If Not Security.IsLoggedIn() Then
			Call Security.SaveLastUrl()
			Call Page_Terminate("login.asp")
		End If
		If Not Security.CanList Then
			Call Security.SaveLastUrl()
			Call Page_Terminate("login.asp")
		End If

		' Create form object
		'If Request.ServerVariables("HTTP_CONTENT_TYPE") = "application/x-www-form-urlencoded" Then

			Set ObjForm = New cFormObj

		'Else
		'	Set ObjForm = ew_GetUploadObj()
		'End If
		' Get export parameters

		If Request.QueryString("export").Count > 0 Then
			gjc.Export = Request.QueryString("export")
		ElseIf Request.ServerVariables("HTTP_CONTENT_TYPE") = "application/x-www-form-urlencoded" Then
			If Request.Form("exporttype").Count > 0 Then
				gjc.Export = Request.Form("exporttype")
			End If
		Else
			gjc.ExportReturnUrl = ew_CurrentUrl()
		End If
		gsExport = gjc.Export ' Get export parameter, used in header
		gsExportFile = gjc.TableVar ' Get export file, used in header
		Dim Charset ' Charset used in header
		If EW_CHARSET <> "" Then
			Charset = ";charset=" & EW_CHARSET
		Else
			Charset = ""
		End If
		If gjc.Export = "excel" Then
			Response.ContentType = "application/vnd.ms-excel" & Charset
			Response.AddHeader "Content-Disposition", "attachment; filename=" & gsExportFile & ".xls"
		End If
		If gjc.Export = "word" Then
			Response.ContentType = "application/vnd.ms-word" & Charset
			Response.AddHeader "Content-Disposition", "attachment; filename=" & gsExportFile & ".doc"
		End If
		gjc.CurrentAction = ew_IIf(Request.QueryString("a").Count > 0, Request.QueryString("a") & "", ObjForm.GetValue("a_list") & "") ' Set up current action

		' Get grid add count
		Dim gridaddcnt
		gridaddcnt = Request.QueryString(EW_TABLE_GRID_ADD_ROW_COUNT)
		If IsNumeric(gridaddcnt) Then
			If gridaddcnt > 0 Then
				gjc.GridAddRowCount = gridaddcnt
			End If
		End If

		' Set up list options
		SetupListOptions()

		' Setup export options
		SetupExportOptions()
		gjc.id.Visible = Not gjc.IsAdd() And Not gjc.IsCopy() And Not gjc.IsGridAdd()

		' Global page loading event (in userfn7.asp)
		Page_Loading()

		' Page load event, used in current page
		Page_Load()

		' Setup other options
		SetupOtherOptions()

		' Set "checkbox" visible
		If UBound(gjc.CustomActions.CustomArray) >= 0 Then
			ListOptions.GetItem("checkbox").Visible = True
		End If

		'??? Update url if printer friendly for Pdf
		'???if ($this->PrinterFriendlyForPdf)
		'???	$this->ExportOptions->Items["pdf"]->Body = str_replace($this->ExportPdfUrl, $this->ExportPrintUrl . "&pdf=1", $this->ExportOptions->Items["pdf"]->Body);

	End Sub

	' -----------------------------------------------------------------
	'  Class terminate
	'  - clean up page object
	'
	Private Sub Class_Terminate()
		Call Page_Terminate("")
	End Sub

	' -----------------------------------------------------------------
	'  Subroutine Page_Terminate
	'  - called when exit page
	'  - clean up ADO connection and objects
	'  - if url specified, redirect to url
	'
	Sub Page_Terminate(url)

		' Page unload event, used in current page
		Call Page_Unload()

		'???if ($this->Export == "print" && @$_GET["pdf"] == "1") { // Printer friendly version and with pdf=1 in URL parameters
		'???	$pdf = new cExportPdf($GLOBALS["Table"]);
		'???	$pdf->Text = ob_get_contents(); // Set the content as the HTML of current page (printer friendly version)
		'???	ob_end_clean();
		'???	$pdf->Export();
		'???}
		' Global page unloaded event (in userfn60.asp)

		Call Page_Unloaded()
		Dim sRedirectUrl
		sReDirectUrl = url
		Call Page_Redirecting(sReDirectUrl)
		If Not (Conn Is Nothing) Then Conn.Close ' Close Connection
		Set Conn = Nothing
		Set Security = Nothing
		Set gjc = Nothing
		Set ListOptions = Nothing
		Set ObjForm = Nothing

		' Go to url if specified
		If sReDirectUrl <> "" Then
			If Response.Buffer Then Response.Clear
			Response.Redirect sReDirectUrl
		End If
	End Sub

	'
	'  Subroutine Page_Terminate (End)
	' ----------------------------------------

	Dim ListOptions ' List options
	Dim ExportOptions ' Export options
	Dim AddEditOptions ' Other options (add edit)
	Dim DetailOptions ' Other options (detail)
	Dim ActionOptions ' Other options (action)
	Dim DisplayRecs ' Number of display records
	Dim StartRec, StopRec, TotalRecs, RecRange
	Dim SearchWhere
	Dim RecCnt
	Dim EditRowCnt
	Dim StartRowCnt
	Dim RowCnt, RowIndex
	Dim Attrs
	Dim RecPerRow, ColCnt
	Dim KeyCount
	Dim RowAction
	Dim RowOldKey ' Row old key (for copy)
	Dim DbMasterFilter, DbDetailFilter
	Dim MasterRecordExists
	Dim MultiSelectKey
	Dim Command
	Dim RestoreSearch
	Dim Recordset, OldRecordset

	' -----------------------------------------------------------------
	' Page main processing
	'
	Sub Page_Main()
		DisplayRecs = 20
		RecRange = 10
		RecCnt = 0 ' Record count
		KeyCount = 0 ' Key count
		StartRowCnt = 1

		' Search filters
		Dim sSrchAdvanced, sSrchBasic, sFilter
		sSrchAdvanced = "" ' Advanced search filter
		sSrchBasic = "" ' Basic search filter
		SearchWhere = "" ' Search where clause
		sFilter = ""

		' Restore search
		RestoreSearch = False

		' Get command
		Command = LCase(Request.QueryString("cmd")&"")

		' Master/Detail
		DbMasterFilter = "" ' Master filter
		DbDetailFilter = "" ' Detail filter
		If IsPageRequest Then ' Validate request

			' Process custom action first
			ProcessCustomAction()

			' Set up records per page dynamically
			SetUpDisplayRecs()

			' Handle reset command
			ResetCmd()

			' Set up Breadcrumb
			SetupBreadcrumb()

			' Check QueryString parameters
			If Request.QueryString("a").Count > 0 Then
				gjc.CurrentAction = Request.QueryString("a")

				' Clear inline mode
				If gjc.CurrentAction = "cancel" Then
					ClearInlineMode()
				End If

				' Switch to grid edit mode
				If gjc.CurrentAction = "gridedit" Then
					GridEditMode()
				End If

				' Switch to inline add mode
				If gjc.CurrentAction = "add" Or gjc.CurrentAction = "copy" Then
					InlineAddMode()
				End If

				' Switch to grid add mode
				If gjc.CurrentAction = "gridadd" Then
					GridAddMode()
				End If
			Else
				If ObjForm.GetValue("a_list")&"" <> "" Then
					gjc.CurrentAction = ObjForm.GetValue("a_list") ' Get action

					' Grid Update
					If (gjc.CurrentAction = "gridupdate" Or gjc.CurrentAction = "gridoverwrite") And Session(EW_SESSION_INLINE_MODE) = "gridedit" Then
						If ValidateGridForm() Then
							GridUpdate()
						Else
							FailureMessage = gsFormError
							gjc.EventCancelled = True
							gjc.CurrentAction = "gridedit" ' Stay in Grid Edit mode
						End If
					End If

					' Insert Inline
					If gjc.CurrentAction = "insert" And Session(EW_SESSION_INLINE_MODE) = "add" Then
						InlineInsert()
					End If

					' Grid Insert
					If gjc.CurrentAction = "gridinsert" And Session(EW_SESSION_INLINE_MODE) = "gridadd" Then
						If ValidateGridForm() Then
							GridInsert()
						Else
							FailureMessage = gsFormError
							gjc.EventCancelled = True
							gjc.CurrentAction = "gridadd" ' Stay in Grid Add mode
						End If
					End If
				End If
			End If

			' Hide list options
			If gjc.Export <> "" Then
				Call ListOptions.HideAllOptions(Array("sequence"))
				ListOptions.UseDropDownButton = False ' Disable drop down button
				ListOptions.UseButtonGroup = False ' Disable button group
			ElseIf gjc.CurrentAction = "gridadd" Or gjc.CurrentAction = "gridedit" Then
				Call ListOptions.HideAllOptions(Array())
				ListOptions.UseDropDownButton = False ' Disable drop down button
				ListOptions.UseButtonGroup = False ' Disable button group
			End If

			' Hide export options
			If gjc.Export <> "" Or gjc.CurrentAction <> "" Then
				ExportOptions.HideAllOptions(Array())
			End If

			' Hide other options
			If gjc.Export <> "" Then
				AddEditOptions.HideAllOptions(Array())
				DetailOptions.HideAllOptions(Array())
				ActionOptions.HideAllOptions(Array())
			End If

			' Show grid delete link for grid add / grid edit
			If gjc.AllowAddDeleteRow Then
				If gjc.CurrentAction = "gridadd" Or gjc.CurrentAction = "gridedit" Then
					ListOptions.GetItem("griddelete").Visible = True
				End If
			End If

			' Set Up Sorting Order
			SetUpSortOrder()
		End If ' End Validate Request

		' Restore display records
		If gjc.RecordsPerPage <> "" Then
			DisplayRecs = gjc.RecordsPerPage ' Restore from Session
		Else
			DisplayRecs = 20 ' Load default
		End If

		' Load Sorting Order
		LoadSortOrder()
		sFilter = ""
		If Not Security.CanList Then
			sFilter = "(0=1)" ' Filter all records
		End If
		Call ew_AddFilter(sFilter, DbDetailFilter)
		Call ew_AddFilter(sFilter, SearchWhere)

		' Set up filter in Session
		gjc.SessionWhere = sFilter
		gjc.CurrentFilter = ""

		' Export Data only
		If ew_InArray(gjc.Export, Array("html","word","excel","xml","csv","email","pdf")) Then
			ExportData()
			Call Page_Terminate("") ' Terminate response
			Response.End
		End If
	End Sub

	' -----------------------------------------------------------------
	' Set up number of records displayed per page
	'
	Sub SetUpDisplayRecs()
		Dim sWrk
		sWrk = Request.QueryString(EW_TABLE_REC_PER_PAGE)
		If sWrk <> "" Then
			If IsNumeric(sWrk) Then
				DisplayRecs = CInt(sWrk)
			Else
				If LCase(sWrk) = "all" Then ' Display all records
					DisplayRecs = -1
				Else
					DisplayRecs = 20 ' Non-numeric, load default
				End If
			End If
			gjc.RecordsPerPage = DisplayRecs ' Save to Session

			' Reset start position
			StartRec = 1
			gjc.StartRecordNumber = StartRec
		End If
	End Sub

	' -----------------------------------------------------------------
	'  Exit out of inline mode
	'
	Sub ClearInlineMode()
		gjc.LastAction = gjc.CurrentAction ' Save last action
		gjc.CurrentAction = "" ' Clear action
		Session(EW_SESSION_INLINE_MODE) = "" ' Clear inline mode
	End Sub

	' -----------------------------------------------------------------
	' Switch to Grid Add Mode
	'
	Sub GridAddMode()
		Session(EW_SESSION_INLINE_MODE) = "gridadd" ' Enabled grid add
	End Sub

	' -----------------------------------------------------------------
	' Switch to Grid Edit Mode
	'
	Sub GridEditMode()
		Session(EW_SESSION_INLINE_MODE) = "gridedit" ' Enabled grid edit
	End Sub

	' -----------------------------------------------------------------
	' Switch to Inline Add Mode
	'
	Sub InlineAddMode()
		If Not Security.CanAdd Then Call Page_Terminate("login.asp") ' Return to login page
		gjc.CurrentAction = "add"
		Session(EW_SESSION_INLINE_MODE) = "add" ' Enabled inline add
	End Sub

	' -----------------------------------------------------------------
	' Peform update to inline add/copy record
	'
	Sub InlineInsert()
		Call LoadOldRecord() ' Load old recordset
		ObjForm.Index = 0
		Call LoadFormValues() ' Get form values

		' Validate Form
		If Not ValidateForm() Then
			FailureMessage = gsFormError ' Set validation error message
			gjc.EventCancelled = True ' Set event cancelled
			gjc.CurrentAction = "add" ' Stay in add mode
			Exit Sub
		End If
		gjc.SendEmail = True ' Send email on add success
		If AddRow(OldRecordset) Then ' Add record
			SuccessMessage = Language.Phrase("AddSuccess") ' Set add success message
			Call ClearInlineMode() ' Clear inline add mode
		Else ' Add failed
			gjc.EventCancelled = True ' Set event cancelled
			gjc.CurrentAction = "add" ' Stay in add mode
		End If
	End Sub

	' -----------------------------------------------------------------
	' Peform update to grid
	'
	Function GridUpdate()
		Dim rowindex
		Dim bGridUpdate
		Dim sKey, sThisKey
		Dim Rs, RsOld, RsNew, sSql
		rowindex = 1
		bGridUpdate = True

		' Begin transaction
		Conn.BeginTrans

		' Get old recordset
		gjc.CurrentFilter  = BuildKeyFilter()
		sSql = gjc.SQL
		Set Rs = Server.CreateObject("ADODB.Recordset")
		Rs.CursorLocation = EW_CURSORLOCATION
		Rs.Open sSql, Conn, 1, EW_RECORDSET_LOCKTYPE
		Set RsOld = ew_CloneRs(Rs)
		sKey = ""

		' Update row index and get row key
		Dim rowcnt
		ObjForm.Index = -1
		rowcnt = ObjForm.GetValue(FormKeyCountName)
		If rowcnt = "" Or Not IsNumeric(rowcnt) Then
			rowcnt = 0
		End If

		' Update all rows based on key
		Dim rowkey, rowaction
		For rowindex = 1 to rowcnt
			ObjForm.Index = rowindex
			rowkey = ObjForm.GetValue(FormKeyName) & ""
			rowaction = ObjForm.GetValue(FormActionName) & ""

			' Load all values & keys
			If rowaction <> "insertdelete" Then ' Skip insert then deleted rows
				Call LoadFormValues() ' Get form values
				If rowaction = "" Or rowaction = "edit" Or rowaction = "delete" Then
					bGridUpdate = SetupKeyValues(rowkey) ' Set up key values
				Else
					bGridUpdate = True
				End If

				' Skip empty row
				If rowaction = "insert" And EmptyRow() Then

					' No action required
				' Validate form and insert/update/delete record

				ElseIf bGridUpdate Then
					If rowaction = "delete" Then
						gjc.CurrentFilter = gjc.KeyFilter
						bGridUpdate = DeleteRows() ' Delete this row
					ElseIf Not ValidateForm() Then
						bGridUpdate = False ' Form error, reset action
						FailureMessage = gsFormError
					Else
						If rowaction = "insert" Then
							bGridUpdate = AddRow(Null) ' Insert this row
						Else
							If rowkey <> "" Then
								gjc.SendEmail = False ' Do not send email on update success
								bGridUpdate = EditRow() ' Update this row
							End If
						End If ' End update
					End If
				End If
				If bGridUpdate Then
					If sKey <> "" Then sKey = sKey & ", "
					sKey = sKey & rowkey
				Else
					Exit For
				End If
			End If
		Next
		If bGridUpdate Then
			Conn.CommitTrans ' Commit transaction

			' Get new recordset
			Set Rs = Conn.Execute(sSql)
			Set RsNew = ew_CloneRs(Rs)
			SuccessMessage = Language.Phrase("UpdateSuccess") ' Set update success message
			Call ClearInlineMode() ' Clear inline edit mode
		Else
			Conn.RollbackTrans ' Rollback transaction
			If FailureMessage = "" Then
				FailureMessage = Language.Phrase("UpdateFailed") ' Set update failed message
			End If
			gjc.EventCancelled = True ' Set event cancelled
			gjc.CurrentAction = "gridedit" ' Stay in gridedit mode
		End If
		Set Rs = Nothing
		Set RsOld = Nothing
		Set RsNew = Nothing
		GridUpdate = bGridUpdate
	End Function

	' -----------------------------------------------------------------
	'  Build filter for all keys
	'
	Function BuildKeyFilter()
		Dim rowindex, sThisKey
		Dim sKey
		Dim sWrkFilter, sFilter
		sWrkFilter = ""

		' Update row index and get row key
		rowindex = 1
		ObjForm.Index = rowindex
		sThisKey = ObjForm.GetValue("k_key") & ""
		Do While (sThisKey <> "")
			If SetupKeyValues(sThisKey) Then
				sFilter = gjc.KeyFilter
				If sWrkFilter <> "" Then sWrkFilter = sWrkFilter & " OR "
				sWrkFilter = sWrkFilter & sFilter
			Else
				sWrkFilter = "0=1"
				Exit Do
			End If

			' Update row index and get row key
			rowindex = rowindex + 1 ' Next row
			ObjForm.Index = rowindex
			sThisKey = ObjForm.GetValue("k_key") & ""
		Loop
		BuildKeyFilter = sWrkFilter
	End Function

	' -----------------------------------------------------------------
	' Set up key values
	'
	Function SetupKeyValues(key)
		Dim arrKeyFlds
		arrKeyFlds = Split(key&"", EW_COMPOSITE_KEY_SEPARATOR)
		If UBound(arrKeyFlds) >= 0 Then
			gjc.id.FormValue = arrKeyFlds(0)
			If Not IsNumeric(gjc.id.FormValue) Then
				SetupKeyValues = False
				Exit Function
			End If
		End If
		SetupKeyValues = True
	End Function

	' Grid Insert
	' Peform insert to grid
	Function GridInsert()
		Dim addcnt
		Dim rowindex, rowcnt
		Dim bGridInsert
		Dim sSql, sWrkFilter, sFilter, sKey, sThisKey
		Dim Rs, RsNew
		rowindex = 1
		bGridInsert = False

		' Begin transaction
		Conn.BeginTrans

		' Init key filter
		sWrkFilter = ""
		addcnt = 0
		sKey = ""

		' Get row count
		ObjForm.Index = -1
		rowcnt = ObjForm.GetValue(FormKeyCountName) & ""
		If rowcnt = "" Or Not IsNumeric(rowcnt) Then rowcnt = 0

		' Insert all rows
		For rowindex = 1 to rowcnt

			' Load current row values
			ObjForm.Index = rowindex
			Dim rowaction
			rowaction = ObjForm.GetValue(FormActionName) & ""
			If rowaction = "" Or rowaction = "insert" Then
				Call LoadFormValues() ' Get form values
				If Not EmptyRow() Then
					addcnt = addcnt + 1
					gjc.SendEmail = False ' Do not send email on insert success

					' Validate Form
					If Not ValidateForm() Then
						bGridInsert = False ' Form error, reset action
						FailureMessage = gsFormError
					Else
						bGridInsert = AddRow(Null) ' Insert this row
					End If
					If bGridInsert Then
						If sKey <> "" Then sKey = sKey & EW_COMPOSITE_KEY_SEPARATOR
						sKey = sKey & gjc.id.CurrentValue

						' Add filter for this record
						sFilter = gjc.KeyFilter
						If sWrkFilter <> "" Then sWrkFilter = sWrkFilter & " OR "
						sWrkFilter = sWrkFilter & sFilter
					Else
						Exit For
					End If
				End If
			End If
		Next
		If addcnt = 0 Then ' No record inserted
			FailureMessage = Language.Phrase("NoAddRecord")
			bGridInsert = False
		End If
		If bGridInsert Then
			Conn.CommitTrans ' Commit transaction

			' Get new recordset
			gjc.CurrentFilter  = sWrkFilter
			sSql = gjc.SQL
			Set Rs = Conn.Execute(sSql)
			Set RsNew = ew_CloneRs(Rs)
			SuccessMessage = Language.Phrase("InsertSuccess") ' Set insert success message
			Call ClearInlineMode() ' Clear grid add mode
		Else
			Conn.RollbackTrans ' Rollback transaction
			If FailureMessage = "" Then
				FailureMessage = Language.Phrase("InsertFailed") ' Set insert failed message
			End If
			gjc.EventCancelled = True ' Set event cancelled
			gjc.CurrentAction = "gridadd" ' Stay in gridadd mode
		End If
		Set Rs = Nothing
		Set RsNew = Nothing
		GridInsert = bGridInsert
	End Function

	' Check if empty row
	Function EmptyRow()
		EmptyRow = True
		If Not ObjForm Is Nothing Then
			If EmptyRow And ObjForm.HasValue("x_gjc_1") And ObjForm.HasValue("o_gjc_1") Then EmptyRow = (gjc.gjc_1.CurrentValue&"" = gjc.gjc_1.OldValue&"")
			If EmptyRow And ObjForm.HasValue("x_urls") And ObjForm.HasValue("o_urls") Then EmptyRow = (gjc.urls.CurrentValue&"" = gjc.urls.OldValue&"")
		End If
	End Function

	' Validate grid form
	Function ValidateGridForm()
		Dim rowindex, rowcnt, rowaction

		' Get row count
		ObjForm.Index = -1
		rowcnt = ObjForm.GetValue(FormKeyCountName) & ""
		If rowcnt = "" Or Not IsNumeric(rowcnt) Then
			rowcnt = 0
		End If

		' Validate all records
		ValidateGridForm = True
		For rowindex = 1 to rowcnt

			' Load current row values
			ObjForm.Index = rowindex
			rowaction = ObjForm.GetValue(FormActionName) & ""
			If rowaction <> "delete" And rowaction <> "insertdelete" Then
				LoadFormValues() ' Get form values
				If rowaction = "insert" And EmptyRow() Then

					' Ignore
				ElseIf Not ValidateForm() Then
					ValidateGridForm = False
					Exit For
				End If
			End If
		Next
	End Function

	' Restore form values for current row
	Sub RestoreCurrentRowFormValues(idx)

		' Get row based on current index
		ObjForm.Index = idx
		Call LoadFormValues() ' Load form values
	End Sub

	' -----------------------------------------------------------------
	' Set up Sort parameters based on Sort Links clicked
	'
	Sub SetUpSortOrder()
		Dim sOrderBy
		Dim sSortField, sLastSort, sThisSort
		Dim bCtrl

		' Check for an Order parameter
		If Request.QueryString("order").Count > 0 Then
			gjc.CurrentOrder = Request.QueryString("order")
			gjc.CurrentOrderType = Request.QueryString("ordertype")

			' Field id
			Call gjc.UpdateSort(gjc.id)

			' Field gjc
			Call gjc.UpdateSort(gjc.gjc_1)

			' Field urls
			Call gjc.UpdateSort(gjc.urls)
			gjc.StartRecordNumber = 1 ' Reset start position
		End If
	End Sub

	' -----------------------------------------------------------------
	' Load Sort Order parameters
	'
	Sub LoadSortOrder()
		Dim sOrderBy
		sOrderBy = gjc.SessionOrderBy ' Get order by from Session
		If sOrderBy = "" Then
			If gjc.SqlOrderBy <> "" Then
				sOrderBy = gjc.SqlOrderBy
				gjc.SessionOrderBy = sOrderBy
			End If
		End If
	End Sub

	' -----------------------------------------------------------------
	' Reset command based on querystring parameter cmd=
	' - RESET: reset search parameters
	' - RESETALL: reset search & master/detail parameters
	' - RESETSORT: reset sort parameters
	'
	Sub ResetCmd()

		' Check if reset command
		If Left(Command,5) = "reset" Then

			' Reset Sort Criteria
			If Command = "resetsort" Then
				Dim sOrderBy
				sOrderBy = ""
				gjc.SessionOrderBy = sOrderBy
				gjc.id.Sort = ""
				gjc.gjc_1.Sort = ""
				gjc.urls.Sort = ""
			End If

			' Reset start position
			StartRec = 1
			gjc.StartRecordNumber = StartRec
		End If
	End Sub

	' Set up list options
	Sub SetupListOptions()
		Dim item

		' Grid delete
		If gjc.AllowAddDeleteRow Then
			ListOptions.Add("griddelete")
			Set item = ListOptions.GetItem("griddelete")
			item.CssStyle = "white-space: nowrap;"
			item.OnLeft = False
			item.Visible = False ' Default hidden
		End If

		' Add group option item
		ListOptions.Add(ListOptions.GroupOptionName)
		Set item = ListOptions.GetItem(ListOptions.GroupOptionName)
		item.Body = ""
		item.OnLeft = False
		item.Visible = False

		' View
		ListOptions.Add("view")
		Set item = ListOptions.GetItem("view")
		item.CssStyle = "white-space: nowrap;"
		item.Visible = Security.CanView
		item.OnLeft = False

		' Edit
		ListOptions.Add("edit")
		Set item = ListOptions.GetItem("edit")
		item.CssStyle = "white-space: nowrap;"
		item.Visible = Security.CanEdit
		item.OnLeft = False

		' Copy
		ListOptions.Add("copy")
		Set item = ListOptions.GetItem("copy")
		item.CssStyle = "white-space: nowrap;"
		item.Visible = Security.CanAdd
		item.OnLeft = False

		' Checkbox
		ListOptions.Add("checkbox")
		Set item = ListOptions.GetItem("checkbox")
		item.Visible = Security.CanDelete
		item.OnLeft = False
		item.Header = "<label class=""checkbox""><input type=""checkbox"" name=""key"" id=""key"" onclick=""ew_SelectAllKey(this);""></label>"
		item.ShowInDropDown = False
		item.ShowInButtonGroup = False

		' Drop down button for ListOptions
		ListOptions.UseDropDownButton = False
		ListOptions.DropDownButtonPhrase = Language.Phrase("ButtonListOptions")
		ListOptions.UseButtonGroup = False
		ListOptions.ButtonClass = "btn-small" ' Class for button group
		Call ListOptions_Load()

		' Set up group item visibility
		ListOptions.GetItem(ListOptions.GroupOptionName).Visible = ListOptions.GroupOptionVisible
	End Sub

	' Render list options
	Sub RenderListOptions()
		Dim item, links
		ListOptions.LoadDefault()

		' Set up row action and key
		If IsNumeric(RowIndex) And gjc.CurrentMode <> "view" Then
			Dim ActionName, OldKeyName, KeyName, BlankRowName
			ObjForm.Index = RowIndex
			ActionName = Replace(FormActionName, "k_", "k" & RowIndex & "_")
			OldKeyName = Replace(FormOldKeyName, "k_", "k" & RowIndex & "_")
			KeyName = Replace(FormKeyName, "k_", "k" & RowIndex & "_")
			BlankRowName = Replace(FormBlankRowName, "k_", "k" & RowIndex & "_")
			If RowAction <> "" Then
				MultiSelectKey = MultiSelectKey & "<input type=""hidden"" name=""" & ActionName & """ id=""" & ActionName & """ value=""" & RowAction & """>"
			End If
			If RowAction = "delete" Then
				Dim sKey
				sKey = ObjForm.GetValue(FormKeyName) & ""
				Call SetupKeyValues(sKey)
			End If
			If RowAction = "insert" And gjc.CurrentAction = "F" And EmptyRow() Then
				MultiSelectKey = MultiSelectKey & "<input type=""hidden"" name=""" & BlankRowName & """ id=""" & BlankRowName & """ value=""1"">"
			End If
		End If

		' Grid delete
		If gjc.AllowAddDeleteRow Then
			If gjc.CurrentAction = "gridadd" Or gjc.CurrentAction = "gridedit" Then
				ListOptions.UseButtonGroup = True ' Use button group for grid delete button
				ListOptions.UseImageAndText = True ' Use image and text for grid delete button
				Set item = ListOptions.GetItem("griddelete")
				If Not Security.CanDelete() And IsNumeric(RowIndex) And (RowAction = "" Or RowAction = "edit") Then ' Do not allow delete existing record
					item.Body = "&nbsp;"
				Else
					item.Body = "<a class=""ewGridLink ewGridDelete"" data-caption=""" & ew_HtmlTitle(Language.Phrase("DeleteLink")) & """ href=""javascript:void(0);"" onclick=""ew_DeleteGridRow(this, " & RowIndex & ");"">" & Language.Phrase("DeleteLink") & "</a>"
				End If
			End If
		End If
		If (gjc.CurrentAction = "add" Or gjc.CurrentAction = "copy") And gjc.RowType = EW_ROWTYPE_ADD Then ' Inline Add / Copy
			ListOptions.CustomItem = "copy" ' Show copy column only
			Set item = ListOptions.GetItem("copy")
			item.Body = "<div" & ew_IIf(item.OnLeft, " style=""text-align: right""", "") & ">" & _
				"<a class=""ewGridLink ewInlineInsert"" data-caption=""" & ew_HtmlTitle(Language.Phrase("InsertLink")) & """ href="""" onclick=""return ewForms(this).Submit();"">" & Language.Phrase("InsertLink") & "</a>&nbsp;" & _
				"<a class=""ewGridLink ewInlineCancel"" data-caption=""" & ew_HtmlTitle(Language.Phrase("CancelLink")) & """ href=""" & PageUrl & "a=cancel"">" & Language.Phrase("CancelLink") & "</a>" & _
				"<input type=""hidden"" name=""a_list"" id=""a_list"" value=""insert""></div>"
			Exit Sub
		End If
		If Security.CanView Then
			ListOptions.GetItem("view").Body = "<a class=""ewRowLink ewView"" data-caption=""" & ew_HtmlTitle(Language.Phrase("ViewLink")) & """ href=""" & ew_HtmlEncode(ViewUrl) & """>" & Language.Phrase("ViewLink") & "</a>"
		Else
			ListOptions.GetItem("view").Body = ""
		End If
		Set item = ListOptions.GetItem("edit")
		If Security.CanEdit Then
			item.Body = "<a class=""ewRowLink ewEdit"" data-caption=""" & ew_HtmlTitle(Language.Phrase("EditLink")) & """ href=""" & ew_HtmlEncode(EditUrl) & """>" & Language.Phrase("EditLink") & "</a>"
		Else
			item.Body = ""
		End If
		Set item = ListOptions.GetItem("copy")
		If Security.CanAdd Then
			item.Body = "<a class=""ewRowLink ewCopy"" data-caption=""" & ew_HtmlTitle(Language.Phrase("CopyLink")) & """ href=""" & ew_HtmlEncode(CopyUrl) & """>" & Language.Phrase("CopyLink") & "</a>"
		Else
			item.Body = ""
		End If
		ListOptions.GetItem("checkbox").Body = "<label class=""checkbox""><input type=""checkbox"" name=""key_m"" value=""" & ew_HtmlEncode(gjc.id.CurrentValue) & """ onclick='ew_ClickMultiCheckbox(event, this);'></label>"
		If gjc.CurrentAction = "gridedit" And RowIndex <> "" And IsNumeric(RowIndex) Then
			MultiSelectKey = MultiSelectKey & "<input type=""hidden"" name=""" & KeyName & """ id=""" & KeyName & """ value=""" & gjc.id.CurrentValue & """>"
		End If
		Call RenderListOptionsExt()
		Call ListOptions_Rendered()
	End Sub

	' Set up other options
	Sub SetupOtherOptions()
		Dim opt, item, DetailTableLink, ar, i
		Set opt = AddEditOptions

		' Add
		Call opt.Add("add")
		Set item = opt.GetItem("add")
		item.Body = "<a class=""ewAddEdit ewAdd"" href=""" & ew_HtmlEncode(AddUrl) & """>" & Language.Phrase("AddLink") & "</a>"
		item.Visible = (AddUrl <> "" And Security.CanAdd)

		' Inline Add
		Call opt.Add("inlineadd")
		Set item = opt.GetItem("inlineadd")
		item.Body = "<a class=""ewAddEdit ewInlineAdd"" href=""" & ew_HtmlEncode(InlineAddUrl) & """>" & Language.Phrase("InlineAddLink") & "</a>"
		item.Visible = (InlineAddUrl <> "" And Security.CanAdd)
		Call opt.Add("gridadd")
		Set item = opt.GetItem("gridadd")
		item.Body = "<a class=""ewAddEdit ewGridAdd"" href=""" & ew_HtmlEncode(GridAddUrl) & """>" & Language.Phrase("GridAddLink") & "</a>"
		item.Visible = (GridAddUrl <> "" And Security.CanAdd)

		' Add grid edit
		Set opt = AddEditOptions
		Call opt.Add("gridedit")
		Set item = opt.GetItem("gridedit")
		item.Body = "<a class=""ewAddEdit ewGridEdit"" href=""" & ew_HtmlEncode(GridEditUrl) & """>" & Language.Phrase("GridEditLink") & "</a>"
		item.Visible = (GridEditUrl <> "" And Security.CanEdit)
		Set opt = ActionOptions

		' Add multi delete
		Call opt.Add("multidelete")
		Set item = opt.GetItem("multidelete")
		item.Body = "<a class=""ewAction ewMultiDelete"" href="""" onclick=""ew_SubmitSelected(document.fgjclist, '" & MultiDeleteUrl & "', ewLanguage.Phrase('DeleteMultiConfirmMsg'));return false;"">" & Language.Phrase("DeleteSelectedLink") & "</a>"
		item.Visible = (Security.CanDelete)

		' Set up options default
		Set opt = AddEditOptions
		opt.DropDownButtonPhrase = Language.Phrase("ButtonAddEdit")
		opt.UseDropDownButton = False
		opt.UseButtonGroup = True
		opt.ButtonClass = "btn-small" ' Class for button group
		Call opt.Add(opt.GroupOptionName)
		Set item = opt.GetItem(opt.GroupOptionName)
		item.Body = ""
		item.Visible = False
		Set opt = DetailOptions
		opt.DropDownButtonPhrase = Language.Phrase("ButtonDetails")
		opt.UseDropDownButton = False
		opt.UseButtonGroup = True
		opt.ButtonClass = "btn-small" ' Class for button group
		Call opt.Add(opt.GroupOptionName)
		Set item = opt.GetItem(opt.GroupOptionName)
		item.Body = ""
		item.Visible = False
		Set opt = ActionOptions
		opt.DropDownButtonPhrase = Language.Phrase("ButtonActions")
		opt.UseDropDownButton = False
		opt.UseButtonGroup = True
		opt.ButtonClass = "btn-small" ' Class for button group
		Call opt.Add(opt.GroupOptionName)
		Set item = opt.GetItem(opt.GroupOptionName)
		item.Body = ""
		item.Visible = False
	End Sub

	' Render other options
	Sub RenderOtherOptions()
		Dim opt, item, i, Action, Name
		If gjc.CurrentAction <> "gridadd" And gjc.CurrentAction <> "gridedit" Then ' Not grid add/edit mode
			Set opt = ActionOptions
			For i = 0 to UBound(gjc.CustomActions.CustomArray)
				Action = gjc.CustomActions.CustomArray(i)(0)
				Name = gjc.CustomActions.CustomArray(i)(1)

				' Add custom action
				Call opt.Add("custom_" & Action)
				Set item = opt.GetItem("custom_" & Action)
				item.Body = "<a class=""ewAction ewCustomAction"" href="""" onclick=""ew_SubmitSelected(document.fgjclist, '" & ew_CurrentUrl & "', null, '" & Action & "');return false;"">" & Name & "</a>"
			Next

			' Hide grid edit, multi-delete and multi-update
			If TotalRecs <= 0 Then
				Set opt = AddEditOptions
				Set item = opt.GetItem("gridedit")
				If (Not item Is Nothing) Then item.Visible = False
				Set opt = ActionOptions
				Set item = opt.GetItem("multidelete")
				If (Not item Is Nothing) Then item.Visible = False
				Set item = opt.GetItem("multiupdate")
				If (Not item Is Nothing) Then item.Visible = False
			End If
		Else ' Grid add/edit mode

			' Hide all options first
			AddEditOptions.HideAllOptions(Array())
			DetailOptions.HideAllOptions(Array())
			ActionOptions.HideAllOptions(Array())
			If gjc.CurrentAction = "gridadd" Then
				If gjc.AllowAddDeleteRow Then

					' Add add blank row
					Set opt = AddEditOptions
					opt.UseDropDownButton = False
					opt.UseImageAndText = True
					Call opt.Add("addblankrow")
					Set item = opt.GetItem("addblankrow")
					item.Body = "<a class=""ewAddEdit ewAddBlankRow"" data-caption=""" & ew_HtmlTitle(Language.Phrase("AddBlankRow")) & """ href=""javascript:void(0);"" onclick=""ew_AddGridRow(this);"">" & Language.Phrase("AddBlankRow") & "</a>"
					item.Visible = Security.CanAdd
				End If
				Set opt = ActionOptions
				opt.UseDropDownButton = False
				opt.UseImageAndText = True

				' Add grid insert
				Call opt.Add("gridinsert")
				Set item = opt.GetItem("gridinsert")
				item.Body = "<a class=""ewAction ewGridInsert"" data-caption=""" & ew_HtmlTitle(Language.Phrase("GridInsertLink")) & """ href="""" onclick=""return ewForms(this).Submit();"">" & Language.Phrase("GridInsertLink") & "</a>"

				' Add grid cancel
				Call opt.Add("gridcancel")
				Set item = opt.GetItem("gridcancel")
				item.Body = "<a class=""ewAction ewGridCancel"" data-caption=""" & ew_HtmlTitle(Language.Phrase("GridCancelLink")) & """ href=""" & PageUrl & "a=cancel"">" & Language.Phrase("GridCancelLink") & "</a>"
			End If
			If gjc.CurrentAction = "gridedit" Then
				If gjc.AllowAddDeleteRow Then

					' Add add blank row
					Set opt = AddEditOptions
					opt.UseDropDownButton = False
					opt.UseImageAndText = True
					Call opt.Add("addblankrow")
					Set item = opt.GetItem("addblankrow")
					item.Body = "<a class=""ewAddEdit ewAddBlankRow"" data-caption=""" & ew_HtmlTitle(Language.Phrase("AddBlankRow")) & """ href=""javascript:void(0);"" onclick=""ew_AddGridRow(this);"">" & Language.Phrase("AddBlankRow") & "</a>"
					item.Visible = Security.CanAdd
				End If
				Set opt = ActionOptions
				opt.UseDropDownButton = False
				opt.UseImageAndText = True
					Call opt.Add("gridsave")
					Set item = opt.GetItem("gridsave")
					item.Body = "<a class=""ewAction ewGridSave"" data-caption=""" & ew_HtmlTitle(Language.Phrase("GridSaveLink")) & """ href="""" onclick=""return ewForms(this).Submit();"">" & Language.Phrase("GridSaveLink") & "</a>"
					Call opt.Add("gridcancel")
					Set item = opt.GetItem("gridcancel")
					item.Body = "<a class=""ewAction ewGridCancel"" data-caption=""" & ew_HtmlTitle(Language.Phrase("GridCancelLink")) & """ href=""" & PageUrl & "a=cancel"">" & Language.Phrase("GridCancelLink") & "</a>"
			End If
		End If
	End Sub

	' Process custom action
	Sub ProcessCustomAction()
		Dim sFilter, sSql, UserAction, Processed
		sFilter = gjc.GetKeyFilter
		UserAction = Request.Form("useraction") & ""
		Processed = False
		If sFilter <> "" And UserAction <> "" Then
			gjc.CurrentFilter = sFilter
			sSql = gjc.SQL
			Conn.BeginTrans

			' Load recordset
			Dim Rs
			Set Rs = ew_LoadRecordset(sSql)
			If Not Rs.Eof Then Rs.MoveFirst

			' Call row custom action event
			Do While Not Rs.Eof
				Processed = Row_CustomAction(UserAction, Rs)
				If Not Processed Then
					Exit Do
				Else
					Rs.MoveNext
				End If
			Loop
			Rs.Close
			Set Rs = Nothing
			If Processed Then
				Conn.CommitTrans ' Commit the changes
				If SuccessMessage = "" Then
					SuccessMessage = Replace(Language.Phrase("CustomActionCompleted"), "%s", UserAction) ' Set up success message
				End If
			Else
				Conn.RollbackTrans ' Rollback transaction

				' Set up error message
				If SuccessMessage <> "" Or FailureMessage <> "" Then

					' Use the message, do nothing
				ElseIf gjc.CancelMessage <> "" Then
					FailureMessage = gjc.CancelMessage
					gjc.CancelMessage = ""
				Else
					FailureMessage = Replace(Language.Phrase("CustomActionCancelled"), "%s", UserAction)
				End If
			End If
		End If
	End Sub

	Function RenderListOptionsExt()
	End Function
	Dim Pager

	' -----------------------------------------------------------------
	' Set up Starting Record parameters based on Pager Navigation
	'
	Sub SetUpStartRec()
		Dim PageNo

		' Exit if DisplayRecs = 0
		If DisplayRecs = 0 Then Exit Sub
		If IsPageRequest Then ' Validate request

			' Check for a START parameter
			If Request.QueryString(EW_TABLE_START_REC).Count > 0 Then
				StartRec = Request.QueryString(EW_TABLE_START_REC)
				gjc.StartRecordNumber = StartRec
			ElseIf Request.QueryString(EW_TABLE_PAGE_NO).Count > 0 Then
				PageNo = Request.QueryString(EW_TABLE_PAGE_NO)
				If IsNumeric(PageNo) Then
					StartRec = (PageNo-1)*DisplayRecs+1
					If StartRec <= 0 Then
						StartRec = 1
					ElseIf StartRec >= ((TotalRecs-1)\DisplayRecs)*DisplayRecs+1 Then
						StartRec = ((TotalRecs-1)\DisplayRecs)*DisplayRecs+1
					End If
					gjc.StartRecordNumber = StartRec
				End If
			End If
		End If
		StartRec = gjc.StartRecordNumber

		' Check if correct start record counter
		If Not IsNumeric(StartRec) Or StartRec = "" Then ' Avoid invalid start record counter
			StartRec = 1 ' Reset start record counter
			gjc.StartRecordNumber = StartRec
		ElseIf CLng(StartRec) > CLng(TotalRecs) Then ' Avoid starting record > total records
			StartRec = ((TotalRecs-1)\DisplayRecs)*DisplayRecs+1 ' Point to last page first record
			gjc.StartRecordNumber = StartRec
		ElseIf (StartRec-1) Mod DisplayRecs <> 0 Then
			StartRec = ((StartRec-1)\DisplayRecs)*DisplayRecs+1 ' Point to page boundary
			gjc.StartRecordNumber = StartRec
		End If
	End Sub

	' -----------------------------------------------------------------
	' Load default values
	'
	Function LoadDefaultValues()
		gjc.id.CurrentValue = Null
		gjc.id.OldValue = gjc.id.CurrentValue
		gjc.gjc_1.CurrentValue = Null
		gjc.gjc_1.OldValue = gjc.gjc_1.CurrentValue
		gjc.urls.CurrentValue = Null
		gjc.urls.OldValue = gjc.urls.CurrentValue
	End Function

	' -----------------------------------------------------------------
	' Load form values
	'
	Function LoadFormValues()

		' Load values from form
		If Not gjc.id.FldIsDetailKey And gjc.CurrentAction <> "gridadd" And gjc.CurrentAction <> "add" Then gjc.id.FormValue = ObjForm.GetValue("x_id")
		If Not gjc.gjc_1.FldIsDetailKey Then gjc.gjc_1.FormValue = ObjForm.GetValue("x_gjc_1")
		gjc.gjc_1.OldValue = ObjForm.GetValue("o_gjc_1")
		If Not gjc.urls.FldIsDetailKey Then gjc.urls.FormValue = ObjForm.GetValue("x_urls")
		gjc.urls.OldValue = ObjForm.GetValue("o_urls")
	End Function

	' -----------------------------------------------------------------
	' Restore form values
	'
	Function RestoreFormValues()
		If gjc.CurrentAction <> "gridadd" And gjc.CurrentAction <> "add" Then gjc.id.CurrentValue = gjc.id.FormValue
		gjc.gjc_1.CurrentValue = gjc.gjc_1.FormValue
		gjc.urls.CurrentValue = gjc.urls.FormValue
	End Function

	' -----------------------------------------------------------------
	' Load recordset
	'
	Function LoadRecordset()

		' Call Recordset Selecting event
		Dim sFilter
		sFilter = gjc.CurrentFilter
		Call gjc.Recordset_Selecting(sFilter)
		gjc.CurrentFilter = sFilter

		' Load list page sql
		Dim sSql
		sSql = gjc.ListSQL
		Call ew_SetDebugMsg("LoadRecordset: " & sSql) ' Show SQL for debugging

		' Load recordset
		Dim RsRecordset
		Set RsRecordset = ew_LoadRecordset(sSql)

		' Call Recordset Selected event
		Call gjc.Recordset_Selected(RsRecordset)
		Set LoadRecordset = RsRecordset
	End Function

	' -----------------------------------------------------------------
	' Load row based on key values
	'
	Function LoadRow()
		Dim RsRow, sSql, sFilter
		sFilter = gjc.KeyFilter

		' Call Row Selecting event
		Call gjc.Row_Selecting(sFilter)

		' Load sql based on filter
		gjc.CurrentFilter = sFilter
		sSql = gjc.SQL
		Call ew_SetDebugMsg("LoadRow: " & sSql) ' Show SQL for debugging
		Set RsRow = ew_LoadRow(sSql)
		If RsRow.Eof Then
			LoadRow = False
		Else
			LoadRow = True
			RsRow.MoveFirst
			Call LoadRowValues(RsRow) ' Load row values
		End If
		RsRow.Close
		Set RsRow = Nothing
	End Function

	' -----------------------------------------------------------------
	' Load row values from recordset
	'
	Sub LoadRowValues(RsRow)
		Dim sDetailFilter
		If Not EW_DEBUG_ENABLED Then On Error Resume Next
		If RsRow.Eof Then Exit Sub

		' Call Row Selected event
		Call gjc.Row_Selected(RsRow)
		gjc.id.DbValue = RsRow("id")
		gjc.gjc_1.DbValue = RsRow("gjc")
		gjc.urls.DbValue = RsRow("urls")
	End Sub

	' Load DbValue from recordset
	Sub LoadDbValues(Rs)
		If Not EW_DEBUG_ENABLED Then On Error Resume Next
		If Rs.Eof Then Exit Sub
		gjc.id.m_DbValue = Rs("id")
		gjc.gjc_1.m_DbValue = Rs("gjc")
		gjc.urls.m_DbValue = Rs("urls")
	End Sub

	' Load old record
	Function LoadOldRecord()

		' Load key values from Session
		Dim bValidKey
		bValidKey = True
		If gjc.GetKey("id")&"" <> "" Then
			gjc.id.CurrentValue = gjc.GetKey("id") ' id
		Else
			bValidKey = False
		End If

		' Load old recordset
		If bValidKey Then
			gjc.CurrentFilter = gjc.KeyFilter
			Dim sSql
			sSql = gjc.SQL
			Set OldRecordset = ew_LoadRecordset(sSql)
			Call LoadRowValues(OldRecordset) ' Load row values
		Else
			OldRecordset = Null
		End If
		LoadOldRecord = bValidKey
	End Function

	' -----------------------------------------------------------------
	' Render row values based on field settings
	'
	Sub RenderRow()

		' Initialize urls
		ViewUrl = gjc.ViewUrl("")
		EditUrl = gjc.EditUrl("")
		InlineEditUrl = gjc.InlineEditUrl
		CopyUrl = gjc.CopyUrl("")
		InlineCopyUrl = gjc.InlineCopyUrl
		DeleteUrl = gjc.DeleteUrl

		' Call Row Rendering event
		Call gjc.Row_Rendering()

		' ---------------------------------------
		'  Common render codes for all row types
		' ---------------------------------------
		' id
		' gjc
		' urls
		' -----------
		'  View  Row
		' -----------

		If gjc.RowType = EW_ROWTYPE_VIEW Then ' View row

			' id
			gjc.id.ViewValue = gjc.id.CurrentValue
			gjc.id.ViewCustomAttributes = ""

			' gjc
			gjc.gjc_1.ViewValue = gjc.gjc_1.CurrentValue
			gjc.gjc_1.ViewCustomAttributes = ""

			' urls
			gjc.urls.ViewValue = gjc.urls.CurrentValue
			gjc.urls.ViewCustomAttributes = ""

			' View refer script
			' id

			gjc.id.LinkCustomAttributes = ""
			gjc.id.HrefValue = ""
			gjc.id.TooltipValue = ""

			' gjc
			gjc.gjc_1.LinkCustomAttributes = ""
			gjc.gjc_1.HrefValue = ""
			gjc.gjc_1.TooltipValue = ""

			' urls
			gjc.urls.LinkCustomAttributes = ""
			gjc.urls.HrefValue = ""
			gjc.urls.TooltipValue = ""

		' ---------
		'  Add Row
		' ---------

		ElseIf gjc.RowType = EW_ROWTYPE_ADD Then ' Add row

			' id
			' gjc

			gjc.gjc_1.EditCustomAttributes = ""
			gjc.gjc_1.EditValue = ew_HtmlEncode(gjc.gjc_1.CurrentValue)
			gjc.gjc_1.PlaceHolder = ew_HtmlEncode(ew_RemoveHtml(gjc.gjc_1.FldCaption))

			' urls
			gjc.urls.EditCustomAttributes = ""
			gjc.urls.EditValue = ew_HtmlEncode(gjc.urls.CurrentValue)
			gjc.urls.PlaceHolder = ew_HtmlEncode(ew_RemoveHtml(gjc.urls.FldCaption))

			' Edit refer script
			' id

			gjc.id.HrefValue = ""

			' gjc
			gjc.gjc_1.HrefValue = ""

			' urls
			gjc.urls.HrefValue = ""

		' ----------
		'  Edit Row
		' ----------

		ElseIf gjc.RowType = EW_ROWTYPE_EDIT Then ' Edit row

			' id
			gjc.id.EditCustomAttributes = ""
			gjc.id.EditValue = gjc.id.CurrentValue
			gjc.id.ViewCustomAttributes = ""

			' gjc
			gjc.gjc_1.EditCustomAttributes = ""
			gjc.gjc_1.EditValue = ew_HtmlEncode(gjc.gjc_1.CurrentValue)
			gjc.gjc_1.PlaceHolder = ew_HtmlEncode(ew_RemoveHtml(gjc.gjc_1.FldCaption))

			' urls
			gjc.urls.EditCustomAttributes = ""
			gjc.urls.EditValue = ew_HtmlEncode(gjc.urls.CurrentValue)
			gjc.urls.PlaceHolder = ew_HtmlEncode(ew_RemoveHtml(gjc.urls.FldCaption))

			' Edit refer script
			' id

			gjc.id.HrefValue = ""

			' gjc
			gjc.gjc_1.HrefValue = ""

			' urls
			gjc.urls.HrefValue = ""
		End If
		If gjc.RowType = EW_ROWTYPE_ADD Or gjc.RowType = EW_ROWTYPE_EDIT Or gjc.RowType = EW_ROWTYPE_SEARCH Then ' Add / Edit / Search row
			Call gjc.SetupFieldTitles()
		End If

		' Call Row Rendered event
		If gjc.RowType <> EW_ROWTYPE_AGGREGATEINIT Then
			Call gjc.Row_Rendered()
		End If
	End Sub

	' -----------------------------------------------------------------
	' Validate form
	'
	Function ValidateForm()

		' Initialize
		gsFormError = ""

		' Check if validation required
		If Not EW_SERVER_VALIDATE Then
			ValidateForm = (gsFormError = "")
			Exit Function
		End If

		' Return validate result
		ValidateForm = (gsFormError = "")

		' Call Form Custom Validate event
		Dim sFormCustomError
		sFormCustomError = ""
		ValidateForm = ValidateForm And Form_CustomValidate(sFormCustomError)
		If sFormCustomError <> "" Then
			Call ew_AddMessage(gsFormError, sFormCustomError)
		End If
	End Function

	'
	' Delete records based on current filter
	'
	Function DeleteRows()
		If Not EW_DEBUG_ENABLED Then On Error Resume Next
		Dim sKey, sThisKey, sKeyFld, arKeyFlds
		Dim sSql, RsDelete
		Dim RsOld, RsDetail
		DeleteRows = True
		sSql = gjc.SQL
		If Not Security.CanDelete Then
			FailureMessage = Language.Phrase("NoDeletePermission") ' No delete permission
			DeleteRows = False
			Exit Function
		End If
		Set RsDelete = Server.CreateObject("ADODB.Recordset")
		RsDelete.CursorLocation = EW_CURSORLOCATION
		RsDelete.Open sSql, Conn, 1, EW_RECORDSET_LOCKTYPE
		If Err.Number <> 0 Then
			FailureMessage = Err.Description
			RsDelete.Close
			Set RsDelete = Nothing
			DeleteRows = False
			Exit Function
		ElseIf RsDelete.Eof Then
			FailureMessage = Language.Phrase("NoRecord") ' No record found
			RsDelete.Close
			Set RsDelete = Nothing
			DeleteRows = False
			Exit Function
		End If

		' Clone old recordset object
		Set RsOld = ew_CloneRs(RsDelete)

		' Call row deleting event
		If DeleteRows Then
			RsDelete.MoveFirst
			Do While Not RsDelete.Eof
				DeleteRows = gjc.Row_Deleting(RsDelete)
				If Not DeleteRows Then Exit Do
				RsDelete.MoveNext
			Loop
			RsDelete.MoveFirst
		End If
		If DeleteRows Then
			sKey = ""
			RsDelete.MoveFirst
			Do While Not RsDelete.Eof
				sThisKey = ""
				If sThisKey <> "" Then sThisKey = sThisKey & EW_COMPOSITE_KEY_SEPARATOR
				sThisKey = sThisKey & RsDelete("id")
				Call LoadDbValues(RsDelete)
				If DeleteRows Then
					RsDelete.Delete
				End If
				If Err.Number <> 0 Or Not DeleteRows Then
					If Err.Description <> "" Then FailureMessage = Err.Description ' Set up error message
					DeleteRows = False
					Exit Do
				End If
				If sKey <> "" Then sKey = sKey & ", "
				sKey = sKey & sThisKey
				RsDelete.MoveNext
			Loop
		Else

			' Set up error message
			If SuccessMessage <> "" Or FailureMessage <> "" Then

				' Use the message, do nothing
			ElseIf gjc.CancelMessage <> "" Then
				FailureMessage = gjc.CancelMessage
				gjc.CancelMessage = ""
			Else
				FailureMessage = Language.Phrase("DeleteCancelled")
			End If
		End If
		If DeleteRows Then
		Else
		End If
		RsDelete.Close
		Set RsDelete = Nothing

		' Call row deleting event
		If DeleteRows Then
			RsOld.MoveFirst
			Do While Not RsOld.Eof
				Call gjc.Row_Deleted(RsOld)
				RsOld.MoveNext
			Loop
		End If
		RsOld.Close
		Set RsOld = Nothing
	End Function

	' -----------------------------------------------------------------
	' Update record based on key values
	'
	Function EditRow()
		If Not EW_DEBUG_ENABLED Then On Error Resume Next
		Dim Rs, sSql, sFilter
		Dim RsChk, sSqlChk, sFilterChk
		Dim bUpdateRow
		Dim RsOld, RsNew
		Dim sIdxErrMsg

		' Clear any previous errors
		Err.Clear
		sFilter = gjc.KeyFilter
		gjc.CurrentFilter  = sFilter
		sSql = gjc.SQL
		Set Rs = Server.CreateObject("ADODB.Recordset")
		Rs.CursorLocation = EW_CURSORLOCATION
		Rs.Open sSql, Conn, 1, EW_RECORDSET_LOCKTYPE
		If Err.Number <> 0 Then
			Message = Err.Description
			Rs.Close
			Set Rs = Nothing
			EditRow = False
			Exit Function
		End If

		' Clone old recordset object
		Set RsOld = ew_CloneRs(Rs)
		Call LoadDbValues(RsOld)
		If Rs.Eof Then
			EditRow = False ' Update Failed
		Else

			' Field gjc
			Call gjc.gjc_1.SetDbValue(Rs, gjc.gjc_1.CurrentValue, Null, gjc.gjc_1.ReadOnly)

			' Field urls
			Call gjc.urls.SetDbValue(Rs, gjc.urls.CurrentValue, Null, gjc.urls.ReadOnly)

			' Check recordset update error
			If Err.Number <> 0 Then
				FailureMessage = Err.Description
				Rs.Close
				Set Rs = Nothing
				EditRow = False
				Exit Function
			End If

			' Call Row Updating event
			bUpdateRow = gjc.Row_Updating(RsOld, Rs)
			If bUpdateRow Then

				' Clone new recordset object
				Set RsNew = ew_CloneRs(Rs)
				EditRow = True
				If EditRow Then
					Rs.Update
				End If
				If Err.Number <> 0 Or Not EditRow Then
					If Err.Description <> "" Then FailureMessage = Err.Description
					EditRow = False
				Else
					EditRow = True
				End If
				If EditRow Then
				End If
			Else
				Rs.CancelUpdate

				' Set up error message
				If SuccessMessage <> "" Or FailureMessage <> "" Then

					' Use the message, do nothing
				ElseIf gjc.CancelMessage <> "" Then
					FailureMessage = gjc.CancelMessage
					gjc.CancelMessage = ""
				Else
					FailureMessage = Language.Phrase("UpdateCancelled")
				End If
				EditRow = False
			End If
		End If

		' Call Row Updated event
		If EditRow Then
			Call gjc.Row_Updated(RsOld, RsNew)
		End If
		Rs.Close
		Set Rs = Nothing
		If IsObject(RsOld) Then
			RsOld.Close
			Set RsOld = Nothing
		End If
		If IsObject(RsNew) Then
			RsNew.Close
			Set RsNew = Nothing
		End If
	End Function

	' -----------------------------------------------------------------
	' Add record
	'
	Function AddRow(RsOld)
		If Not EW_DEBUG_ENABLED Then On Error Resume Next
		Dim Rs, sSql, sFilter
		Dim RsNew
		Dim bInsertRow
		Dim RsChk
		Dim sIdxErrMsg

		' Clear any previous errors
		Err.Clear
		Dim RsMaster, sMasterUserIdMsg, sMasterFilter, bCheckMasterRecord

		' Load db values from rsold
		If Not IsNull(RsOld) Then
			Call LoadDbValues(RsOld)
		End If

		' Add new record
		sFilter = "(0 = 1)"
		gjc.CurrentFilter = sFilter
		sSql = gjc.SQL
		Set Rs = Server.CreateObject("ADODB.Recordset")
		Rs.CursorLocation = EW_CURSORLOCATION
		Rs.Open sSql, Conn, 1, EW_RECORDSET_LOCKTYPE
		Rs.AddNew
		If Err.Number <> 0 Then
			Message = Err.Description
			Rs.Close
			Set Rs = Nothing
			AddRow = False
			Exit Function
		End If

		' Field gjc
		Call gjc.gjc_1.SetDbValue(Rs, gjc.gjc_1.CurrentValue, Null, False)

		' Field urls
		Call gjc.urls.SetDbValue(Rs, gjc.urls.CurrentValue, Null, False)

		' Check recordset update error
		If Err.Number <> 0 Then
			FailureMessage = Err.Description
			Rs.Close
			Set Rs = Nothing
			AddRow = False
			Exit Function
		End If

		' Call Row Inserting event
		bInsertRow = gjc.Row_Inserting(RsOld, Rs)
		If bInsertRow Then

			' Clone new recordset object
			Set RsNew = ew_CloneRs(Rs)
			Rs.Update
			If Err.Number <> 0 Then
				FailureMessage = Err.Description
				AddRow = False
			Else
				AddRow = True
			End If
			If AddRow Then
			End If
		Else
			Rs.CancelUpdate

			' Set up error message
			If SuccessMessage <> "" Or FailureMessage <> "" Then

				' Use the message, do nothing
			ElseIf gjc.CancelMessage <> "" Then
				FailureMessage = gjc.CancelMessage
				gjc.CancelMessage = ""
			Else
				FailureMessage = Language.Phrase("InsertCancelled")
			End If
			AddRow = False
		End If
		Rs.Close
		Set Rs = Nothing
		If AddRow Then
			gjc.id.DbValue = RsNew("id")
		End If
		If AddRow Then

			' Call Row Inserted event
			Call gjc.Row_Inserted(RsOld, RsNew)
		End If
		If IsObject(RsNew) Then
			RsNew.Close
			Set RsNew = Nothing
		End If
	End Function

	' Set up export options
	Sub SetupExportOptions()
		Dim item

		' Printer friendly
		ExportOptions.Add("print")
		Set item = ExportOptions.GetItem("print")
		item.Body = "<a href=""" & ExportPrintUrl & """ class=""ewExportLink ewPrint"" data-caption=""" & ew_HtmlEncode(Language.Phrase("PrinterFriendlyText")) & """>" & Language.Phrase("PrinterFriendly") & "</a>"
		item.Visible = True

		' Export to Excel
		ExportOptions.Add("excel")
		Set item = ExportOptions.GetItem("excel")
		item.Body = "<a href=""" & ExportExcelUrl & """ class=""ewExportLink ewExcel"" data-caption=""" & ew_HtmlEncode(Language.Phrase("ExportToExcelText")) & """>" & Language.Phrase("ExportToExcel") & "</a>"
		item.Visible = True

		' Export to Word
		ExportOptions.Add("word")
		Set item = ExportOptions.GetItem("word")
		item.Body = "<a href=""" & ExportWordUrl & """ class=""ewExportLink ewWord"" data-caption=""" & ew_HtmlEncode(Language.Phrase("ExportToWordText")) & """>" & Language.Phrase("ExportToWord") & "</a>"
		item.Visible = True

		' Export to Html
		ExportOptions.Add("html")
		Set item = ExportOptions.GetItem("html")
		item.Body = "<a href=""" & ExportHtmlUrl & """ class=""ewExportLink ewHtml"" data-caption=""" & ew_HtmlEncode(Language.Phrase("ExportToHtmlText")) & """>" & Language.Phrase("ExportToHtml") & "</a>"
		item.Visible = False

		' Export to Xml
		ExportOptions.Add("xml")
		Set item = ExportOptions.GetItem("xml")
		item.Body = "<a href=""" & ExportXmlUrl & """ class=""ewExportLink ewXml"" data-caption=""" & ew_HtmlEncode(Language.Phrase("ExportToXmlText")) & """>" & Language.Phrase("ExportToXml") & "</a>"
		item.Visible = False

		' Export to Csv
		ExportOptions.Add("csv")
		Set item = ExportOptions.GetItem("csv")
		item.Body = "<a href=""" & ExportCsvUrl & """ class=""ewExportLink ewCsv"" data-caption=""" & ew_HtmlEncode(Language.Phrase("ExportToCsvText")) & """>" & Language.Phrase("ExportToCsv") & "</a>"
		item.Visible = False

		' Export to Pdf
		ExportOptions.Add("pdf")
		Set item = ExportOptions.GetItem("pdf")
		item.Body = "<a href=""" & ExportPdfUrl & """ class=""ewExportLink ewPdf"" data-caption=""" & ew_HtmlEncode(Language.Phrase("ExportToPDFText")) & """>" & Language.Phrase("ExportToPDF") & "</a>"
		item.Visible = False

		' Export to Email
		ExportOptions.Add("email")
		Set item = ExportOptions.GetItem("email")
		item.Body = "<a id=""emf_gjc"" href=""javascript:void(0);"" class=""ewExportLink ewEmail"" data-caption=""" & Language.Phrase("ExportToEmailText") & """  onclick=""ew_EmailDialogShow({lnk:'emf_gjc',hdr:ewLanguage.Phrase('ExportToEmail'),f:document.fgjclist,sel:false});"">" & Language.Phrase("ExportToEmail") & "</a>"
		item.Visible = False

		' Drop down button for export
		ExportOptions.UseDropDownButton = False
		ExportOptions.DropDownButtonPhrase = Language.Phrase("ButtonExport")

		' Add group option item
		ExportOptions.Add(ExportOptions.GroupOptionName)
		Set item = ExportOptions.GetItem(ExportOptions.GroupOptionName)
		item.Body = ""
		item.Visible = False
	End Sub

	' -----------------------------------------------------------------
	' Export data in HTML/CSV/Word/Excel/XML/Email format
	'
	Sub ExportData()
		Dim XmlDoc
		Dim ExportDoc
		Dim ExportStyle

		' Default export style
		ExportStyle = "h"

		' Load recordset
		Set Rs = LoadRecordset()
		TotalRecs = Rs.RecordCount
		StartRec = 1

		' Export all
		If gjc.ExportAll Then
			StopRec = TotalRecs

			' Set script timeout
			If EW_EXPORT_ALL_TIME_LIMIT > 0 Then
				Server.ScriptTimeout = EW_EXPORT_ALL_TIME_LIMIT
			End If

		' Export 1 page only
		Else
			SetUpStartRec() ' Set Up Start Record Position

			' Set the last record to display
			If DisplayRecs <= 0 Then
				StopRec = TotalRecs
			Else
				StopRec = StartRec + DisplayRecs - 1
			End If
		End If
		If gjc.Export = "xml" Then
			Set XmlDoc = New cXMLDocument
		Else
			Set ExportDoc = New cExportDocument
			Set ExportDoc.Table = gjc
			Call ExportDoc.ChangeStyle("h")
		End If
		Dim ParentTable
		ParentTable = ""
		If gjc.Export = "xml" Then
			Call gjc.ExportXmlDocument(XmlDoc, (ParentTable <> ""), rs, StartRec, StopRec, "")
		Else
			Dim sHeader
			sHeader = PageHeader
			Call Page_DataRendering(sHeader)
			ExportDoc.Text = ExportDoc.Text & sHeader
			Call gjc.ExportDocument(ExportDoc, rs, StartRec, StopRec, "")
			Dim sFooter
			sFooter = PageFooter
			Call Page_DataRendered(sFooter)
			ExportDoc.Text = ExportDoc.Text & sFooter
		End If

		' Close recordset and connection
		Rs.Close
		Set Rs = Nothing

		' Export header and footer
		If gjc.Export <> "xml" Then
			Call ExportDoc.ExportHeaderAndFooter()
		End If
		If gjc.Export = "xml" Then
			XmlDoc.Output
			Set XmlDoc = Nothing
		Else
			If gjc.Export = "email" Then
				Response.Write ExportEmail(ExportDoc.Text)
			ElseIf gjc.Export = "pdf" Then
				Call ExportPdf(ExportDoc.Text)
			Else
				Response.Write ExportDoc.Text
			End If
			Set ExportDoc = Nothing
		End If
	End Sub

	' Set up Breadcrumb
	Sub SetupBreadcrumb()
		Dim PageId, url
		Set Breadcrumb = New cBreadcrumb
		url = ew_CurrentUrl
		url = ew_RegExReplace("\?cmd=reset(all){0,1}$", url, "") ' Remove cmd=reset / cmd=resetall
		Call Breadcrumb.Add("list", gjc.TableVar, url, gjc.TableVar, True)
	End Sub

	Sub ExportPdf(html)
		Response.Write html
	End Sub

	' Page Load event
	Sub Page_Load()

		'Response.Write "Page Load"
	End Sub

	' Page Unload event
	Sub Page_Unload()

		'Response.Write "Page Unload"
	End Sub

	' Page Redirecting event
	Sub Page_Redirecting(url)

		'url = newurl
	End Sub

	' Message Showing event
	' typ = ""|"success"|"failure"|"warning"
	Sub Message_Showing(msg, typ)

		' Example:
		'If typ = "success" Then
		'	msg = "your success message"
		'ElseIf typ = "failure" Then
		'	msg = "your failure message"
		'ElseIf typ = "warning" Then
		'	msg = "your warning message"
		'Else
		'	msg = "your message"
		'End If

	End Sub

	' Page Render event
	Sub Page_Render()

		'Response.Write "Page Render"
	End Sub

	' Page Data Rendering event
	Sub Page_DataRendering(header)

		' Example:
		'header = "your header"

	End Sub

	' Page Data Rendered event
	Sub Page_DataRendered(footer)

		' Example:
		'footer = "your footer"

	End Sub

	' Form Custom Validate event
	Function Form_CustomValidate(CustomError)

		'Return error message in CustomError
		Form_CustomValidate = True
	End Function

	' ListOptions Load event
	Sub ListOptions_Load()

		'Example: 
		' Dim opt
		' Set opt = ListOptions.Add("new")
		' opt.OnLeft = True ' Link on left
		' opt.MoveTo 0 ' Move to first column

	End Sub

	' ListOptions Rendered event
	Sub ListOptions_Rendered()

		'Example: 
		'ListOptions.GetItem("new").Body = "xxx"

	End Sub

	' Row Custom Action event
	Function Row_CustomAction(action, rs)

		' Return False to abort
		Row_CustomAction = True
	End Function
End Class
%>
