<%@ page language="VB" autoeventwireup="false" inherits="Manage_DeviceList, App_Web_irlhclvs" enableEventValidation="false" %>

<%@ Register TagPrefix="obout" Namespace="Obout.Grid" Assembly="obout_Grid_NET" %>
<%@ Register TagPrefix="obout" Namespace="OboutInc.Flyout2" Assembly="obout_Flyout2_NET" %>
<%@ Register TagPrefix="uctrl" Src="~/Header.ascx" TagName="header" %>
<%@ Register TagPrefix="owd" Namespace="OboutInc.Window" Assembly="obout_Window_NET" %>
<%@ Register TagPrefix="oem" Namespace="OboutInc.EasyMenu_Pro" Assembly="obout_EasyMenu_Pro" %>
<%@ Register TagPrefix="obout" Namespace="OboutInc.Combobox" Assembly="obout_Combobox_Net" %>
<script type="text/javascript">
    // Client-Side Events for Delete
    function OnBeforeDelete(record) {
        record.Error = '';
        document.getElementById("<%=Hdn_DeviceId.ClientID %>").value = record.DeviceId;
        document.getElementById("<%=Hdn_DeviceName.ClientID %>").value = record.DeviceSName;
        if (confirm("Are you sure you want to delete? "))
            return true;
        else
            return false;
    }

    function OnDelete(record) {
        alert(record.Error);
    }

    function OnInsert(record) {
        document.getElementById("<%=Lbl_InvalidError.ClientID %>").innerHTML = record.Error;
    }

    function isNumberKey(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

        return true;
    }
	
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <link href="../StyleSheet.css" rel="stylesheet" type="text/css" />

        <script type="text/javascript">
            function SelectDeselect(oCheckbox) {


                var oElement = oCheckbox.parentNode;
                while (oElement != null && oElement.nodeName != "TR") {
                    oElement = oElement.parentNode;
                }

                if (oElement != null) {
                    // oElement represents the row where the clicked      
                    // checkbox reside
                    var oContainer = oElement.parentNode;
                    var iRecordIndex = -1;
                    for (var i = 0; i < oContainer.childNodes.length; i++) {
                        if (oContainer.childNodes[i] == oElement) {
                            iRecordIndex = i;

                            break;
                        }
                    }

                    if (iRecordIndex != -1) {
                        if (oCheckbox.checked == true) {
                            // select the record
                            grid_Devices.selectRecord(iRecordIndex);
                        } else {
                            // deselect the record
                            grid_Devices.deselectRecord(iRecordIndex);
                        }
                    }
                }
            }

            function stopEventPropagation(e) {
                if (!e) { e = window.event; }
                if (!e) { return false; }
                e.cancelBubble = true;
                if (e.stopPropagation) { e.stopPropagation(); }
            }


            function assignEventsToCheckboxes() {

                var sRecordsIds = grid_Devices.getRecordsIds();

                if (sRecordsIds != null && sRecordsIds.length > 0) {

                    var arrRecordsIds = sRecordsIds.split(",");
                    for (var i = 0; i < arrRecordsIds.length; i++) {
                        var oRecord = document.getElementById(arrRecordsIds[i]);
                        oRecord.onmousedown = function (e) { stopEventPropagation(e); };
                        oRecord.onclick = function (e) { stopEventPropagation(e); };
                    }

                    // populate the previously checked checkboxes
                    var arrPageSelectedRecords = grid_Devices.PageSelectedRecords;

                    for (var i = 0; i < arrPageSelectedRecords.length; i++) {
                        var oCheckbox = document.getElementById("chk_grid_" + arrPageSelectedRecords[i].DeviceId);
                        oCheckbox.checked = true;
                    }

                    // enable the record selection feature by selecting the checkboxes
                    var arrCheckboxes = document.getElementsByTagName("INPUT");
                    for (var i = 0; i < arrCheckboxes.length; i++) {
                        if (arrCheckboxes[i].type == "checkbox" && arrCheckboxes[i].id.indexOf("chk_grid_") == 0) {
                            arrCheckboxes[i].onmousedown = function (e) { stopEventPropagation(e); };
                            arrCheckboxes[i].onclick = function (e) { SelectDeselect(this); stopEventPropagation(e); };
                        }
                    }
                }

            }

    </script>




</head>
<body onload="drp_connectionType_SelectIndexChanges();">
    <form id="form1" runat="server">
    <div>
        <uctrl:header ID="MyHeader" runat="server" />
        <table cellpadding="0" cellspacing="0" style="border-right: gray 1px solid; border-top: gray 1px solid;
            border-left: gray 1px solid; border-bottom: gray 1px solid;">
            <tr style="font-weight: bold; font-size: 14px; background-color: lightsteelblue;
                padding-left: 5px; padding-top: 3px; padding-bottom: 3px; color: white;">
                <td style="font-weight: bold; font-size: 14px; background-color: lightsteelblue;
                    padding: 5px; color: white; height: 27px;">
                    Devices List
                </td>
                <td align="right">
                    Auto Refresh Grid
                    <asp:DropDownList ID="ddlAutoRefresh" runat="server" AutoPostBack="false">
                        <asp:ListItem Value="10000">10</asp:ListItem>
                        <asp:ListItem Value="20000">20</asp:ListItem>
                        <asp:ListItem Value="30000">30</asp:ListItem>
                        <asp:ListItem Value="40000">40</asp:ListItem>
                        <asp:ListItem Value="50000">50</asp:ListItem>
                        <asp:ListItem Value="60000">60</asp:ListItem>
                    </asp:DropDownList>
                    &nbsp;<span style="font-size: x-small;">in&nbsp;Seconds&nbsp;</span>&nbsp; Location
                    &nbsp;<asp:DropDownList ID="drp_FilterLocation" runat="server" AutoPostBack="true">
                    </asp:DropDownList>
                    &nbsp; Page Size
                    <asp:TextBox ID="txtPageSize" runat="server" Onkeypress="return isNumberKey(event)"
                        Width="40" Text="100" />
                    &nbsp;
                    <input type="button" class="tdText" value="Refresh" onclick="grid_Devices.refresh()"
                        id="btn_Refresh" />
                    &nbsp; Select Command
                    <asp:DropDownList ID="ddlCommand" runat="server" Width="200">
                        <asp:ListItem>--Select--</asp:ListItem>
                        <asp:ListItem>Clear Logs From Device</asp:ListItem>
                        <asp:ListItem>Change Ip Address</asp:ListItem>
                        <asp:ListItem>Reset Transaction Stamp</asp:ListItem>
                        <asp:ListItem>Reset OpStamp</asp:ListItem>
                        <asp:ListItem>Upload Users To Device</asp:ListItem>
                        <asp:ListItem>Change Card Key</asp:ListItem>
                        <asp:ListItem>Restart Device</asp:ListItem>
                        <asp:ListItem>Change SubnetMask</asp:ListItem>
                        <asp:ListItem>Change GateWay</asp:ListItem>
                        <asp:ListItem>Change WebServerIP</asp:ListItem>
                        <asp:ListItem>Change WebServerPort</asp:ListItem>
                        <asp:ListItem>Delete Users From Device</asp:ListItem>
                        <asp:ListItem>Block Users From Device</asp:ListItem>
                        <asp:ListItem>UnBlock Users From Device</asp:ListItem>
                        <asp:ListItem>Enroll User FP</asp:ListItem>
                        <asp:ListItem>Unlock Door</asp:ListItem>
                        <asp:ListItem>Reset AttPhoto Stamp</asp:ListItem>
                    </asp:DropDownList>
                    <input id="btnExecuteCommand" type="button" onclick="ExecuteCommands();" value="Execute"
                        />
                </td>
            </tr>
            <tr style="background-color: lightsteelblue;">
                <td colspan="2">
                    <hr />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <div id="div_Employees">
                        <obout:Grid ID="grid_Devices" runat="server" CallbackMode="true" EnableRecordHover="true" AllowRecordSelection="true"
                            AllowMultiRecordSelection="True" KeepSelectedRecords="true" Serialize="true"
                            AllowPageSizeSelection="true" AllowFiltering="true" AutoGenerateColumns="false" FolderStyle="~/styles/grid/styles/premiere_blue"
                            AllowAddingRecords="true" ShowLoadingMessage="false" OnRebind="RebindGrid" AllowSorting="false" OnInsertCommand="InsertRecord"
                            OnDeleteCommand="DeleteRecord" GenerateRecordIds="true">
                            <ClientSideEvents OnClientInsert="OnInsert" OnBeforeClientDelete="OnBeforeDelete"
                                OnClientDelete="OnDelete" OnClientCallback="assignEventsToCheckboxes"  />
                            <TemplateSettings NewRecord_TemplateId="tplAddBtn" />
                            <Columns>
                                <obout:Column ID="Column2" DataField="DeviceId" Visible="False" Width="300" HeaderText="DeviceId"
                                    ConvertEmptyStringToNull="False" Index="0" />
                                <obout:Column ID="Column44" DataField="SerialNumber1" ReadOnly="True" HeaderText="Chk"
                                    Width="40" ConvertEmptyStringToNull="False" Index="1" TemplateId="TemplateWithCheckbox">
                                    <TemplateSettings TemplateId="TemplateWithCheckbox" />
                                </obout:Column>
                                <obout:Column ID="Column1" DataField="DeviceSName" SortOrder="Asc" Width="110" HeaderText="Device Name"
                                    ConvertEmptyStringToNull="False" Index="2" />
                                <obout:Column ID="Column3" DataField="DeviceFName" Visible="False" Width="350" HeaderText="DeviceFName"
                                    ConvertEmptyStringToNull="False" Index="3" />
                                <obout:Column ID="Column7" DataField="SerialNumber" Width="105" HeaderText="Serial No."
                                    ConvertEmptyStringToNull="False" Index="4" />
                                <obout:Column ID="Column8" DataField="DeviceDirection" Width="127" HeaderText="Device Direction"
                                    ConvertEmptyStringToNull="False" Index="5" />
                                <obout:Column ID="Column4" DataField="IpAddress" Visible="False" Width="300" HeaderText="IpAddress"
                                    ConvertEmptyStringToNull="False" Index="6" />
                                <obout:Column ID="Column5" DataField="ConnectionType" Visible="False" Width="300"
                                    HeaderText="ConnectionType" ConvertEmptyStringToNull="False" Index="7" />
                                <obout:Column ID="Column10" DataField="DeviceType" Visible="False" Width="130" HeaderText="DeviceType"
                                    ConvertEmptyStringToNull="False" Index="8">
                                </obout:Column>
                                <obout:Column ID="Column11" DataField="TransactionStamp" Width="85" HeaderText="T Stamp"
                                    ConvertEmptyStringToNull="False" Index="9" />
                                <obout:Column ID="Column9" DataField="OpStamp" Width="90" HeaderText="Op Stamp" ConvertEmptyStringToNull="False"
                                    Index="10" />
                                <obout:Column ID="Column13" DataField="TimeZone" Width="100" HeaderText="Time Zone"
                                    ConvertEmptyStringToNull="False" Index="11" />
                                <obout:Column ID="Column15" DataField="TimeOut" Visible="False" Width="120" HeaderText="TimeOut"
                                    ConvertEmptyStringToNull="False" Index="12" />
                                <obout:Column ID="Column14" DataField="DeviceLocation" Width="100" HeaderText="Location"
                                    ConvertEmptyStringToNull="False" Index="13">
                                </obout:Column>
                                <obout:Column ID="Column6" Width="130" HeaderText="Last Ping" DataField="LastPing"
                                    ConvertEmptyStringToNull="False" Index="14" TemplateId="LastPing_Template">
                                    <TemplateSettings TemplateId="LastPing_Template" />
                                </obout:Column>
                                <obout:Column ID="Column12" Width="100" HeaderText="Device Status" ConvertEmptyStringToNull="False"
                                    Index="15" TemplateId="DeviceStatus_Template">
                                    <TemplateSettings TemplateId="DeviceStatus_Template" />
                                </obout:Column>
                                <obout:Column ID="Column22" DataField="C3" Width="95" HeaderText="Validate Status"
                                    ConvertEmptyStringToNull="False" Index="16" />
                                <obout:Column Width="135" ConvertEmptyStringToNull="False" Index="17" TemplateId="tplViewUsersInDeviceBtn">
                                    <TemplateSettings TemplateId="tplViewUsersInDeviceBtn" />
                                </obout:Column>
                                <obout:Column HeaderText="Edit" Width="45" AllowEdit="True" AllowDelete="True" ConvertEmptyStringToNull="False"
                                    Index="18" TemplateId="tplEditBtn">
                                    <TemplateSettings TemplateId="tplEditBtn" />
                                </obout:Column>
                                <obout:Column HeaderText="Delete" Width="80" AllowDelete="True" ConvertEmptyStringToNull="False"
                                    Index="19" />
                                <obout:Column ID="Column20" DataField="MasterId" Visible="false" Width="300" HeaderText="MasterId"
                                    ConvertEmptyStringToNull="False" Index="20" />
                                <obout:Column ID="Column19" DataField="FaceDeviceType" Visible="false" Width="300"
                                    HeaderText="FaceDeviceType" ConvertEmptyStringToNull="False" Index="21" />
                                <obout:Column ID="Column21" DataField="DeviceActivationCode" Visible="False" Width="200"
                                    HeaderText="DeviceActivationCode" ConvertEmptyStringToNull="False" Index="22" />
                            </Columns>
                            <Templates>
                                <obout:GridTemplate runat="server" ID="tplEditBtn" ControlID="" ControlPropertyName="">
                                    <Template>
                                        <a href="javascript: //" id="grid_link_<%# Container.PageRecordIndex %>" onclick="attachFlyoutToLink(this,'Update')"
                                            class="ob_gAL">Edit</a>
                                    </Template>
                                </obout:GridTemplate>
                                <obout:GridTemplate runat="server" ID="tplAddBtn" ControlID="" ControlPropertyName="">
                                    <Template>
                                        <a href="javascript: //" id="btAdd" onclick="attachFlyoutToLink(this,'Add')" class="ob_gAL">
                                            <%#CheckPermissions("Add")%></a>
                                    </Template>
                                </obout:GridTemplate>
                                <obout:GridTemplate runat="server" ID="tplViewUsersInDeviceBtn" ControlID="" ControlPropertyName="">
                                    <Template>
                                        <asp:HyperLink runat="server" CssClass="ob_gAL" Style="cursor: hand;" Text="View Users In Device"
                                            NavigateUrl='<%# "~/Manage/DeviceUsers.aspx?DeviceId=" + Container.DataItem.Item("DeviceId")+"&DeviceSName=" + Container.DataItem.Item("DeviceSName")+"&SerialNumber=" + Container.DataItem.Item("SerialNumber")%>'
                                            ID="AA1" />
                                    </Template>
                                </obout:GridTemplate>
                                <obout:GridTemplate runat="server" ID="LastPing_Template">
                                    <Template>
                                        <%#ParseLastPing(Container.DataItem.Item("LastPing"))%>
                                    </Template>
                                </obout:GridTemplate>
                                <obout:GridTemplate runat="server" ID="DeviceStatus_Template">
                                    <Template>
                                        <asp:Label ID="Label1" runat="server" Text='<%#DeviceStatus(Container.DataItem.Item("LastPing"),Container.DataItem.Item("TimeOut"))%>'
                                            ForeColor='<%#ChangeColorOnDeviceStatusCheck(Container.DataItem("LastPing"),Container.DataItem("TimeOut")) %>'></asp:Label>
                                    </Template>
                                </obout:GridTemplate>
                                <obout:GridTemplate runat="server" ID="TemplateWithCheckbox">
                                    <Template>
                                            <input type="checkbox"   id="chk_grid_<%# Container.DataItem("DeviceId") %>" tooltip='<%# Container.Value %>' />
                                    </Template>
                                </obout:GridTemplate>

                            </Templates>
                        </obout:Grid>
                    </div>
                </td>
            </tr>
        </table>
        <oem:EasyMenu ID="EasyMenu1" runat="server" StyleFolder="~/styles/EasyMenu/Styles/vsnet"
            IconsFolder="MenuIcons" Width="210" UseIcons="true" 
            ShowEvent="ContextMenu" Align="Cursor">
            <Components>
                <oem:MenuItem ID="menuItem4" runat="server">
                    <a id="btn_ClearLogsFromDevice" style="width: 100%;" href="#" runat="server" onclick="return confirm('Are you sure you want to delete all the logs from device.')"
                        onserverclick="btn_ClearLogsFromDevice_onserverclick">Clear Logs From Device</a>
                </oem:MenuItem>
                <oem:MenuSeparator ID="menuSeparator2" InnerHtml="&amp;nbsp;" AllowsIcon="true">
                </oem:MenuSeparator>
                <oem:MenuItem ID="btn_ChangeIpAddress" runat="server" InnerHtml="Change Ip Address"
                    OnClientClick="Wnd_ChangeDeviceDetails_Open('Ip Address');">
                </oem:MenuItem>
                <oem:MenuSeparator ID="menuSeparator3" InnerHtml="&amp;nbsp;" AllowsIcon="true">
                </oem:MenuSeparator>
                <oem:MenuItem ID="menuItem3" runat="server">
                    <a id="btn_ResetTransactionStamp" style="width: 100%;" href="#" runat="server" onserverclick="btn_ResetTransactionStamp_onserverclick">
                        Reset Transaction Stamp</a>
                </oem:MenuItem>
                <oem:MenuSeparator ID="menuSeparator4" InnerHtml="&amp;nbsp;" AllowsIcon="true">
                </oem:MenuSeparator>
                <oem:MenuItem ID="menuItem5" runat="server">
                    <a id="btn_ResetOpStamp" href="#" style="width: 100%;" runat="server" onserverclick="btn_ResetOpStamp_onserverclick">
                        Reset OpStamp</a>
                </oem:MenuItem>
                <oem:MenuSeparator ID="menuSeparator5" InnerHtml="&amp;nbsp;" AllowsIcon="true">
                </oem:MenuSeparator>
                <oem:MenuItem ID="menuItem6" runat="server">
                    <a id="A1" href="#" runat="server" style="width: 100%;" onserverclick="btn_UploadUsersToDevice_onserverclick">
                        Upload Users To Device</a>
                </oem:MenuItem>
                <oem:MenuSeparator ID="menuSeparator6" InnerHtml="&amp;nbsp;" AllowsIcon="true">
                </oem:MenuSeparator>
                <oem:MenuItem ID="menuItem7" runat="server" InnerHtml="Change Card Key" OnClientClick="Wnd_ChangeDeviceDetails_Open('Card Key');">
                </oem:MenuItem>
                <oem:MenuSeparator ID="menuSeparator7" InnerHtml="&amp;nbsp;" AllowsIcon="true">
                </oem:MenuSeparator>
                <oem:MenuItem ID="menuItem8" runat="server">
                    <a id="btn_RestartDevice" href="#" style="width: 100%;" runat="server" onserverclick="btn_RestartDevice_onserverclick">
                        Restart Device</a>
                </oem:MenuItem>
                <oem:MenuSeparator ID="menuSeparator8" InnerHtml="&amp;nbsp;" AllowsIcon="true">
                </oem:MenuSeparator>
                <oem:MenuItem ID="menuItem9" runat="server" InnerHtml="Change SubnetMask" OnClientClick="Wnd_ChangeDeviceDetails_Open('SubnetMask');">
                </oem:MenuItem>
                <oem:MenuSeparator ID="menuSeparator9" InnerHtml="&amp;nbsp;" AllowsIcon="true">
                </oem:MenuSeparator>
                <oem:MenuItem ID="menuItem10" runat="server" InnerHtml="Change GateWay" OnClientClick="Wnd_ChangeDeviceDetails_Open('GateWay');">
                </oem:MenuItem>
                <oem:MenuSeparator ID="menuSeparator1" InnerHtml="&amp;nbsp;" AllowsIcon="true">
                </oem:MenuSeparator>
                <oem:MenuItem ID="menuItem1" runat="server" InnerHtml="Change WebServerIP" OnClientClick="Wnd_ChangeDeviceDetails_Open('WebServerIP');">
                </oem:MenuItem>
                <oem:MenuSeparator ID="menuSeparator10" InnerHtml="&amp;nbsp;" AllowsIcon="true">
                </oem:MenuSeparator>
                <oem:MenuItem ID="menuItem2" runat="server" InnerHtml="Change WebServerPort" OnClientClick="Wnd_ChangeDeviceDetails_Open('WebServerPort');">
                </oem:MenuItem>
                <oem:MenuSeparator ID="menuSeparator12" InnerHtml="&amp;nbsp;" AllowsIcon="true">
                </oem:MenuSeparator>
                <oem:MenuItem ID="menuItem11" runat="server">
                    <a id="A2" href="#" runat="server" style="width: 100%;" onserverclick="btn_DeleteUsersFromDevice_onserverclick">
                        Delete Users From Device</a>
                </oem:MenuItem>
                <oem:MenuSeparator ID="menuSeparator11" InnerHtml="&amp;nbsp;" AllowsIcon="true">
                </oem:MenuSeparator>
                <oem:MenuItem ID="menuItem12" runat="server">
                    <a id="A3" href="#" runat="server" style="width: 100%;" onserverclick="btn_BlockUsersFromDevice_onserverclick">
                        Block Users From Device</a>
                </oem:MenuItem>
                <oem:MenuSeparator ID="menuSeparator13" InnerHtml="&amp;nbsp;" AllowsIcon="true">
                </oem:MenuSeparator>
                <oem:MenuItem ID="menuItem13" runat="server">
                    <a id="A4" href="#" runat="server" style="width: 100%;" onserverclick="btn_UnblockUsersFromDevice_onserverclick">
                        Unblock Users From Device</a>
                </oem:MenuItem>
                <oem:MenuItem ID="menuItem14" runat="server">
                    <a id="A5" href="#" style="width: 100%;" runat="server" onserverclick="btn_UnlockDoor_onserverclick">
                        Unlock Door</a>
                </oem:MenuItem>
            </Components>
        </oem:EasyMenu>
        <obout:Flyout runat="server" ID="Flyout1" Align="left" Position="BOTTOM_left" CloseEvent="NONE"
            OpenEvent="NONE" DelayTime="500">
            <table class="rowEditTable">
                <tr>
                    <td>
                        <fieldset>
                            <legend>Device Information</legend>
                            <table>
                                <tr>
                                    <td style="font-weight: bold;">
                                        Device Name
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txt_DeviceFName" runat="server"></asp:TextBox>
                                    </td>
                                    <td style="font-weight: bold;">
                                        Short Name
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txt_DeviceShortName" runat="server"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-weight: bold;">
                                        Serial Number
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txt_SerialNo" runat="server"></asp:TextBox>
                                    </td>
                                    <td align="right">
                                        Connection Type
                                    </td>
                                    <td>
                                        <select id="drp_ConnectionType" runat="server" onchange="drp_connectionType_SelectIndexChanges();"
                                            style="width: 160px;">
                                            <option selected="selected">Tcp/IP</option>
                                            <option>USB</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-weight: bold;">
                                        Ip Address
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txt_IpAddress" runat="server"></asp:TextBox>
                                    </td>
                                    <td>
                                        Device Location
                                    </td>
                                    <td>
                                        <obout:Combobox Validate="false" ID="drp_Location" runat="server" CssClass="WebControls"
                                            FolderStyle="~/styles/default" Width="160" SelectedIndex="0">
                                        </obout:Combobox>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-weight: bold;">
                                        Time Zone
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txt_TimeZone" runat="server"></asp:TextBox>
                                    </td>
                                    <td style="font-weight: bold;">
                                        Time Out
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txt_TimeOut" runat="server" Width="130px"></asp:TextBox>&nbsp;Sec
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Device Direction
                                    </td>
                                    <td>
                                        <select id="drp_DeviceDiretion" runat="server" enableviewstate="true">
                                            <option selected="selected">In Device</option>
                                            <option>Out Device</option>
                                            <option>Alternate In/Out Device</option>
                                            <option>System Direction(In/Out) Device</option>
                                        </select>
                                    </td>
                                    <td>
                                        Face Device Type
                                    </td>
                                    <td colspan="3">
                                        <select id="drp_FaceDeviceType" runat="server" enableviewstate="true">
                                            <option selected="selected">Normal</option>
                                            <option>Android</option>
                                             <option>FaceTMP</option>
                                            <option>ExternalTMP</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-weight: bold;">
                                        Device Type
                                    </td>
                                    <td colspan="3">
                                        <asp:RadioButtonList ID="rbtn_DeviceType" runat="server" RepeatDirection="Horizontal">
                                            <asp:ListItem Selected="True">Attendance</asp:ListItem>
                                            <asp:ListItem>Canteen</asp:ListItem>
                                            <asp:ListItem>Access Control</asp:ListItem>
                                        </asp:RadioButtonList>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-weight: bold;">
                                        Device Activation Code
                                    </td>
                                    <td colspan="3">
                                         <asp:TextBox ID="txt_DeviceActivationCode" runat="server" Width="130px"></asp:TextBox>
                                    </td>
                                </tr>

                            </table>
                        </fieldset>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <input id="btn_Save" type="button" value="Save" onclick="javascript:btn_Save_onclick();" />&nbsp;&nbsp;&nbsp;&nbsp;<input
                            id="btn_Cancel" type="button" value="Close" onclick="javascript:closeFlyout();" />
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp; &nbsp; &nbsp;
                        <asp:Label runat="server" ForeColor="red" EnableViewState="false" ID="Lbl_InvalidError"></asp:Label>
                        <asp:HiddenField ID="Hdn_DeviceId" runat="server" />
                        <asp:HiddenField ID="Hdn_SerialNumber" runat="server" />
                        <asp:HiddenField ID="Hdn_DeviceName" runat="server" />
                    </td>
                </tr>
            </table>
        </obout:Flyout>
        <owd:Window ID="Wnd_ChangeDeviceDetails" runat="server" IsModal="true" Height="125"
            Width="380" StyleFolder="~/Styles/mainwindow/blue" Title="Change Device Details"
            VisibleOnLoad="false" ShowCloseButton="false" ShowStatusBar="False" Left="450"
            Top="120">
            <table class="rowEditTable" width="100%" height="100%">
                <tr>
                    <td>
                        <fieldset>
                            <table>
                                <tr>
                                    <td>
                                        <asp:CheckBox ID="chkSelected1" onclick="flip1(this,'0');" runat="server" Text="For Selected Devices" />
                                    </td>
                                    <td>
                                        <asp:CheckBox ID="chkAll1" onclick="flip1(this,'1');" runat="server" Text="For All Devices" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="lbl_ChangeName" runat="server" Text="Ip Address"></asp:Label>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txt_ChangeIpAddress" runat="server" Width="200px"></asp:TextBox>
                                    </td>
                                </tr>
                            </table>
                        </fieldset>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:HiddenField ID="hdn_DeviceComm" runat="server" />
                        <asp:Button ID="btn_SaveChange" runat="server" Text="Save" />&nbsp;<input id="btn_CancelSave"
                           onclick="CloseAndClearAll('Wnd_ChangeDeviceDetails');" type="button" value="Close" />&nbsp;&nbsp;
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lbl_Error" runat="server" EnableViewState="false"></asp:Label>
                    </td>
                </tr>
            </table>
        </owd:Window>

         &nbsp;
        <owd:Window ID="WndClearLogs" runat="server" IsModal="true" Height="120" Width="330"
            StyleFolder="~/Styles/mainwindow/blue" Title="Clear Logs From Device" VisibleOnLoad="false"
            ShowCloseButton="false" ShowStatusBar="False" Left="450" Top="120">
            <table class="rowEditTable" width="100%" height="100%">
                <tr>
                    <td>
                        <fieldset>
                            <table>
                                <tr>
                                    <td>
                                        <asp:CheckBox ID="chkSelected" onclick="flip(this,'0');" runat="server" Text="For Selected Devices" />
                                        &nbsp;&nbsp;
                                        <asp:CheckBox ID="chkAll" runat="server" onclick="flip(this,'1');" Text="For All Devices" />
                                    </td>
                                </tr>
                            </table>
                        </fieldset>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Button ID="btnOk" runat="server" Text="Ok" />&nbsp;<input id="btnClose" onclick="CloseAndClearAll('WndClearLogs');" 
                            type="button" value="Close" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label3" runat="server" EnableViewState="false"></asp:Label>
                    </td>
                </tr>
            </table>
        </owd:Window>
        &nbsp;
        <owd:Window ID="WndEnrollUser" runat="server" IsModal="true" Height="175" Width="330"
            StyleFolder="~/Styles/mainwindow/blue" Title="Clear Logs From Device" VisibleOnLoad="false"
            ShowCloseButton="false" ShowStatusBar="False" Left="450" Top="120">
            <table class="rowEditTable" width="100%" height="100%">
                <tr>
                    <td>
                        <fieldset>
                            <table>
                                <tr>
                                    <td colspan="2">
                                        <asp:CheckBox ID="CheckBox1" Checked="true" onclick="flip(this,'0');" runat="server"
                                            Text="For Selected Devices" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        User Device Code
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtDeviceCode" runat="server"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Finger Index Id
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtFingerId" Onkeypress="return isNumberKey(event)" runat="server"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                    <td>
                                        <asp:CheckBox ID="chkOverwrite" Text="Overwrite" runat="server" />
                                    </td>
                                </tr>
                            </table>
                        </fieldset>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Button ID="btnEnrollOk" runat="server" Text="Ok" />&nbsp;<input id="btnEnrollClose"
                             onclick="CloseAndClearAll('WndEnrollUser');" type="button" value="Close" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label2" runat="server" EnableViewState="false"></asp:Label>
                    </td>
                </tr>
            </table>
        </owd:Window>
        <asp:HiddenField ID="hidSelectedCommand" runat="server" />
         <div Style="display: none;">  <asp:Button ID="btnClearGridSelection" runat="server"  Text="Close" /></div>
        <asp:HiddenField ID="HiddenSelectedCommandWindow" runat="server" />

    </div>
    </form>
    <script type="text/javascript">
        document.getElementById("ob_drp_LocationContainer").style.zIndex = "99999";
    </script>
    <script runat="server">
        Function CheckPermissions(ByVal Action As String) As String
            If Not Session.Item("LoginUser") Is Nothing Then
                If CType(Session("LoginUser"), eBioServerLibrary.Data.Admin.User).PermissionNameList.Contains("DeviceManagement") Then
                    Return Action
                End If
                Return ""
            End If
        End Function
        
        Function ParseLastPing(ByVal LastCheckDate As String)
            Try
                If CDate(LastCheckDate) < CDate("1910-01-01") Then
                    Return ""
                Else
                    Return CDate(LastCheckDate).ToString("dd-MMM-yyyy HH:mm")
                End If
            Catch ex As Exception
                Return ""
            End Try
        End Function
        
        Function DeviceStatus(ByVal LastCheckDate As String, TimeOut As String)
            Try
                If TimeOut = "" Then
                    TimeOut = 300
                End If
            
                If DateDiff(DateInterval.Second, CDate(LastCheckDate), CDate(Now.ToString("dd-MMM-yyyy HH:mm:ss"))) > TimeOut Then
                    Return "offline"
                Else
                    Return "online"
                End If
                Return "offline"
            Catch ex As Exception
                Return "online"
            End Try
        End Function
        
        Function ChangeColorOnDeviceStatusCheck(ByVal LastCheckDate As String, TimeOut As String) As System.Drawing.Color
            Try
                If TimeOut = "" Then
                    TimeOut = 300
                End If
            
                If DateDiff(DateInterval.Second, CDate(LastCheckDate), CDate(Now.ToString("dd-MMM-yyyy HH:mm:ss"))) > TimeOut Then
                    Return Drawing.Color.Red
                Else
                    Return Drawing.Color.Green
                End If
                Return Drawing.Color.Red
            Catch ex As Exception
                Return Drawing.Color.Red
            End Try
        End Function
        
        
    </script>
    <script type="text/javascript">
	
    function flip(cb,strVal)
    {
         if (cb.checked)
         {
            if(strVal=='0')
            {
              document.getElementById('<%=chkAll.ClientID %>').checked=false;
            }
            else
            {
              document.getElementById('<%=chkSelected.ClientID %>').checked=false;
            }
         }
    }
        
        
    function flip1(cb,strVal)
    {
         if (cb.checked)
         {
            if(strVal=='0')
            {
              document.getElementById('<%=chkAll1.ClientID %>').checked=false;
            }
            else
            {
              document.getElementById('<%=chkSelected1.ClientID %>').checked=false;
            }
         }
    }    
    
    function AlertMessage()
    {
      var hidValue=document.getElementById('<%=hidSelectedCommand.ClientID %>').value;
      if(hidValue=='Clear Logs From Device')
      {
         return confirm('Are you sure you want to delete all the logs from device.');
      }
    }	 
    
    
    function ExecuteCommands()
    {
      var SelectedCommand=document.getElementById('<%=ddlCommand.ClientID %>').value;
      document.getElementById('<%=hidSelectedCommand.ClientID %>').value=SelectedCommand;
      
      if(SelectedCommand=='--Select--')
        {
          alert("Please select command");
        }
      else if(SelectedCommand=='Clear Logs From Device')
        {
          WndClearLogs.setTitle('Clear Logs From Device');
          WndClearLogs.Open();
          WndClearLogs.screenCenter();
        }
      else if(SelectedCommand=='Change Ip Address')
        {
          Wnd_ChangeDeviceDetails_Open('Ip Address');
        }  
      else if(SelectedCommand=='Reset Transaction Stamp')
        {
          WndClearLogs.setTitle('Reset Transaction Stamp');
          WndClearLogs.Open();
          WndClearLogs.screenCenter();
        }
      else if(SelectedCommand=='Reset OpStamp')
        {
          WndClearLogs.setTitle('Reset OpStamp');
          WndClearLogs.Open();
          WndClearLogs.screenCenter();
        }
      else if(SelectedCommand=='Reset AttPhoto Stamp')
        {
            WndClearLogs.setTitle('Reset AttPhoto Stamp');
            WndClearLogs.Open();
            WndClearLogs.screenCenter();
        }
      else if(SelectedCommand=='Change Card Key')
        {
          Wnd_ChangeDeviceDetails_Open('Card Key');
        }
      else if(SelectedCommand=='Restart Device')
        {
          WndClearLogs.setTitle('Restart Device');
          WndClearLogs.Open();
          WndClearLogs.screenCenter();
        }
      else if(SelectedCommand=='Change SubnetMask')
        {
          Wnd_ChangeDeviceDetails_Open('SubnetMask');
        }  
      else if(SelectedCommand=='Change GateWay')
        {
          Wnd_ChangeDeviceDetails_Open('GateWay');
        }  
       else if(SelectedCommand=='Change WebServerIP')
        {
          Wnd_ChangeDeviceDetails_Open('WebServerIP');
        }  
       else if(SelectedCommand=='Change WebServerPort')
        {
          Wnd_ChangeDeviceDetails_Open('WebServerPort');
        }
       else if(SelectedCommand=='Upload Users To Device')
        {
          WndClearLogs.setTitle('Upload Users To Device');
          WndClearLogs.Open();
          WndClearLogs.screenCenter();
        }
       else if(SelectedCommand=='Delete Users From Device')
        {
          WndClearLogs.setTitle('Delete Users To Device');
          WndClearLogs.Open();
          WndClearLogs.screenCenter();
        }        
        else if (SelectedCommand=='Block Users From Device')
        {
           WndClearLogs.setTitle('Block Users From Device');
           WndClearLogs.Open();
           WndClearLogs.screenCenter();
        }   
        else if (SelectedCommand=='UnBlock Users From Device')
        {
           WndClearLogs.setTitle('UnBlock Users From Device');
           WndClearLogs.Open();
           WndClearLogs.screenCenter();
        }   
        else if (SelectedCommand=='Enroll User FP')
        {
           WndEnrollUser.setTitle('Enroll User FP To Device');
           WndEnrollUser.Open();
           WndEnrollUser.screenCenter();
        }       
         else if(SelectedCommand=='Unlock Door')
        {
          WndClearLogs.setTitle('Unlock Door');
          WndClearLogs.Open();
          WndClearLogs.screenCenter();
        }
            
        
    }       
    
    
    function Wnd_ChangeDeviceDetails_Open(Action)
    {
        if(Action=='Ip Address')
        {
            document.getElementById('<%=lbl_ChangeName.ClientID %>').innerHTML='Ip Address';
            document.getElementById('<%=hdn_DeviceComm.ClientID %>').value='Ip Address';
            document.getElementById('<%=txt_ChangeIpAddress.ClientID %>').value=document.getElementById('<%=txt_IpAddress.ClientID %>').value;
        }
        else
        {
            document.getElementById('<%=txt_ChangeIpAddress.ClientID %>').value='';
            document.getElementById('<%=lbl_ChangeName.ClientID %>').innerHTML=Action;
            document.getElementById('<%=hdn_DeviceComm.ClientID %>').value=Action;
        }
        Wnd_ChangeDeviceDetails.Open();
        Wnd_ChangeDeviceDetails.screenCenter();
        return false;
    }
		    
		    function attachFlyoutToLink(oLink,Action)
		        {	
	                <%=Flyout1.getClientID()%>.AttachTo(oLink.id);		            		            
	                <%=Flyout1.getClientID()%>.Open();
	                clearFlyout();
	                if(Action=='Update')
	                {
	                    populateEditControls(oLink.id.toString().replace("grid_link_", ""));
	                }
		        }
		        
		        function GetSerialNumber(Sender)
		        {
		            var id=Sender.id;
		            document.getElementById('<%=Hdn_SerialNumber.ClientID %>').value=id.replace('lnkDevice_','')
		        }
		    
		    function closeFlyout() 
		        {
		            <%=Flyout1.getClientID()%>.Close();
		        }
		        
		        function drp_connectionType_SelectIndexChanges()
		        {
		            var ConnectionType=document.getElementById("<%=drp_ConnectionType.ClientID %>").value;
		            if(ConnectionType=='Tcp/IP')
		                document.getElementById("<%=txt_IpAddress.ClientID %>").disabled=false;
		            else
		                document.getElementById("<%=txt_IpAddress.ClientID %>").disabled=true;
		                
		                
		        }
		       
		    
		    function populateEditControls(iRecordIndex) 
		        {	
		            document.getElementById("<%=Hdn_DeviceId.ClientID%>").value =grid_Devices.Rows[iRecordIndex].Cells[0].Value;
		            document.getElementById("<%=txt_DeviceShortName.ClientID%>").value = grid_Devices.Rows[iRecordIndex].Cells[2].Value;
		            document.getElementById("<%=txt_DeviceFName.ClientID%>").value = grid_Devices.Rows[iRecordIndex].Cells[3].Value;
		            document.getElementById( "<%=txt_SerialNo.ClientID %>").value = grid_Devices.Rows[iRecordIndex].Cells[4].Value;
		        document.getElementById("ob_drp_LocationTextbox").value=grid_Devices.Rows[iRecordIndex].Cells[13].Value;
		            var Direction=grid_Devices.Rows[iRecordIndex].Cells[5].Value;
		            if(Direction=='in')
		                document.getElementById("<%=drp_DeviceDiretion.ClientID %>").value='In Device';
		            
		            else if(Direction=='out')
		                document.getElementById("<%=drp_DeviceDiretion.ClientID %>").value="Out Device"
		            
		            else if(Direction=='altinout')
		                document.getElementById("<%=drp_DeviceDiretion.ClientID %>").value="Alternate In/Out Device"
		            
		            else if(Direction=='inout')
		                document.getElementById("<%=drp_DeviceDiretion.ClientID %>").value="System Direction(In/Out) Device"
		                
		            document.getElementById("<%=txt_IpAddress.ClientID %>").value = grid_Devices.Rows[iRecordIndex].Cells[6].Value;
		            document.getElementById("<%=drp_ConnectionType.ClientID %>").value = grid_Devices.Rows[iRecordIndex].Cells[7].Value;
		            
		            var DeviceType=grid_Devices.Rows[iRecordIndex].Cells[8].Value;
                document.getElementById('<%=txt_TimeZone.ClientID %>').disabled=false; 
                document.getElementById('<%=txt_TimeOut.ClientID %>').disabled=false; 
                
		             document.getElementById("<%=txt_TimeZone.ClientID%>").value = grid_Devices.Rows[iRecordIndex].Cells[11].Value;
		             document.getElementById("<%=txt_TimeOut.ClientID%>").value = grid_Devices.Rows[iRecordIndex].Cells[12].Value;
                     document.getElementById("<%=drp_FaceDeviceType.ClientID %>").value = grid_Devices.Rows[iRecordIndex].Cells[21].Value;
		             
		            if(DeviceType=='Attendance')
                       document.getElementById("Flyout1_rbtn_DeviceType_0").checked=true;
		            
		            else if(DeviceType=='Canteen')
                       document.getElementById("Flyout1_rbtn_DeviceType_1").checked=true;
		            
		            else if(DeviceType=='Access Control')
                       document.getElementById("Flyout1_rbtn_DeviceType_2").checked=true;
		            drp_connectionType_SelectIndexChanges();
                    document.getElementById("<%=txt_DeviceActivationCode.ClientID%>").value = grid_Devices.Rows[iRecordIndex].Cells[22].Value;
                    
		        }
		   
		   
		      
		      
		       function btn_Save_onclick()
		        {
		            var oRecord = new Object();
	                oRecord.DeviceId =document.getElementById("<%=Hdn_DeviceId.ClientID %>").value ;
		        oRecord.Location=document.getElementById("ob_drp_LocationTextbox").value;
	                oRecord.Error='';
	                 if(document.getElementById("Flyout1_rbtn_DeviceType_0").checked ==  true)
		                    oRecord.ShiftType='Attendance';
		             else if(document.getElementById("Flyout1_rbtn_DeviceType_1").checked ==  true)
		                    oRecord.ShiftType='Canteen';
		             else if(document.getElementById("Flyout1_rbtn_DeviceType_2").checked ==  true)
		                    oRecord.ShiftType='Access Control';
	                grid_Devices.executeInsert(oRecord);
		        }
		    
            function clearFlyout() 
            {
		        document.getElementById("<%=txt_DeviceFName.ClientID%>").value = '';
		        document.getElementById("<%=txt_DeviceShortName.ClientID%>").value = '';
		        document.getElementById( "<%=txt_SerialNo.ClientID %>").value = '';
		        document.getElementById("<%=drp_DeviceDiretion.ClientID %>").selectedIndex=0;
		        document.getElementById("<%=drp_ConnectionType.ClientID %>").selectedIndex=0;
		        document.getElementById("<%=txt_IpAddress.ClientID %>").value = '';
		        document.getElementById("<%=Hdn_DeviceId.ClientID%>").value = '0';
		        document.getElementById("<%=Lbl_InvalidError.ClientID %>").innerHTML ='';
		        document.getElementById("<%=txt_TimeZone.ClientID%>").value = '330';
		        document.getElementById("<%=txt_TimeOut.ClientID%>").value = '300';
                document.getElementById('<%=txt_TimeZone.ClientID %>').disabled=true; 
                document.getElementById('<%=txt_TimeOut.ClientID %>').disabled=true; 
                document.getElementById("Flyout1_rbtn_DeviceType_0").checked=true;
                 document.getElementById("<%=drp_FaceDeviceType.ClientID %>").selectedIndex=0;
                 document.getElementById("<%=txt_DeviceActivationCode.ClientID%>").value='0';
		        drp_connectionType_SelectIndexChanges();
		        
		    }
		    
		    function RefreshDataGrid()
            {
                grid_Devices.refresh();
                window.setTimeout('RefreshDataGrid()', 15000);
            }

             function CloseAndClearAll(CommandWindowName)
    {
        document.getElementById("HiddenSelectedCommandWindow").value=CommandWindowName;
        document.getElementById("btnClearGridSelection").click();

     
    }



//                window.setTimeout('RefreshDataGrid()', 15000);
    </script>
    <script type="text/javascript">
        var tmp;
        function AuToRefreshGrid() {
            var SecondValue = document.getElementById("<%=ddlAutoRefresh.ClientID %>").value;
            tmp = setInterval("callitrept()", SecondValue);
        }
        function callitrept() {
            document.getElementById("btn_Refresh").click();
        }
    </script>

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

         var sDeselectRecordsIds = grid_Devices.getRecordsIds();
         if (sDeselectRecordsIds != null && sDeselectRecordsIds.length > 0) {
             var arrRecordsDeselectIds = sDeselectRecordsIds.split(",");
             for (var i = 0; i < arrRecordsDeselectIds.length; i++) {
                 grid_Devices.deselectRecord(i);

             }
         }
</script>

</body>
</html>
