<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Check.aspx.vb" Inherits="LHSurvey.Check" %>

<!DOCTYPE html>
<%@ Register TagPrefix="uc1" TagName="SecNav" Src="SecNav.ascx" %>
<%@ Register TagPrefix="uc1" TagName="Footer" Src="~/Footer.ascx" %>

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <title>Annual Survey - Ohio Health Insurance Business</title>
    <link href="style.css" type="text/css" rel="stylesheet" />
    <script src="Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui-1.11.2.min.js" type="text/javascript"></script>
    <link href="Content/jquery-ui.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" style="padding-top: 15px" method="post" runat="server">
        <asp:HiddenField ID="hdnEmailId" runat="server" />
        <div style="align-content: center;">
            <uc1:SecNav ID="SecNav" runat="server" ContactPage="True"></uc1:SecNav>
        </div>
        <div style="margin: 0 auto; background-color: #ffffff; width: 750px">
            <div style="margin: 0 auto; border-spacing: 0px; padding: 0px; width: 669px;" class="FrmTable">
                <div class="FrmTitleBackGrnd" style="font-weight: bold; color: #000000;">
                    Annual Report of Ohio Health Insurance Business (LHSurvey) - Company Selection
                </div>
                <div class="FrmBackGrnd" style="margin: 5px;">
                    <div style="padding-top: 15px; padding-left: 5px; padding-bottom: 15px;">
                        Below is the list of companies for which you are authorized to report. Please select one company.
                    </div>
                    <div style="display: table-row; width: 689px; padding-left: 5px; padding-bottom: 15px;">
                        <asp:Label ID="lblErrorMain" runat="server" Text=""></asp:Label>
                        <asp:Label ID="lblNoCompanies" runat="server" ForeColor="#1A3C8E" Font-Bold="true" Text=""></asp:Label>
                    </div>
                    <fieldset style="border: 0 none;">
                        <legend style="display: none;">Company Selection</legend>
                        <div style="display: table-row; width: 669px; padding-left: 5px;">
                            <asp:Repeater ID="dlOrgs" runat="server" EnableViewState="false">
                                <HeaderTemplate>
                                    <table>
                                        <tr>
                                            <th style="padding-right: 20px; width: 20px; border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #A0C3DF;">Select
                                            </th>
                                            <th style="width: 500px; text-align: left; border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #A0C3DF;">Company Name
                                            </th>
                                            <th style="width: 100px; text-align: left; padding-left: 30px; border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #A0C3DF;">NAIC Number
                                            </th>
                                        </tr>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <tr>
                                        <td style="padding: 10px; width: 75px;">
                                            <input type="radio" id="rb_companyid" onclick="javascript: radioChanged(this);" name="rblcompanyid" value='<%# Eval("CompanyId") %>' title="RadioButton" />
                                        </td>
                                        <td style="text-align: left; width: 500px;">
                                            <asp:Label ID="lbl_ComapnyName" runat="server" Text='<%# Eval("OrgName")%>'></asp:Label>

                                        </td>
                                        <td style="padding-left: 30px; width: 150px;">
                                            <asp:Label ID="lbl_NaicId" runat="server" Text='<%# Eval("NAICId")%>'></asp:Label>

                                        </td>
                                    </tr>
                                </ItemTemplate>
                                <FooterTemplate>
                                    </table>
                                </FooterTemplate>
                            </asp:Repeater>
                        </div>
                    </fieldset>
                    <div style="width: 669px; text-align: center">
                        <asp:Button ID="btnYes" runat="server" Text="Continue" Enabled="false" TabIndex="1" />&nbsp;                                                                        
                                                                            <asp:HiddenField ID="hdn_companyid" runat="server" />
                        <asp:HiddenField ID="hdn_companyname" runat="server" />
                        <asp:HiddenField ID="hdn_NaicId" runat="server" />
                    </div>
                    <div style="padding-top: 20px; padding-left: 5px; padding-bottom: 10px;">
                        <p style="color: #C21807">
                            If you no longer report business for a company to which you have an affiliation, please send an email to: <a href="mailto:<%=hdnEmailId.Value%>"><%=hdnEmailId.Value%></a>
                        </p>
                    </div>
                </div>
                <div style="padding-left: 5px; text-align: left; padding-top: 5px;">
                    <asp:Label ID="Label1" runat="server" Style="z-index: 130; top: 0px; text-align: left; left: 1px;"
                        Text="Do you need additional company affiliations? Click the <br> button to the right to submit a request."
                        Font-Bold="True"></asp:Label><span style="padding-left: 185px;" />
                    <input type="button" value="Request Additional Affiliations" onclick="ShowDialog();" />
                </div>
            </div>
            <div id="Open-dialog" class="frmlabel" style="display: none;" title="Annual Report of Ohio Health Insurance Business (LHSurvey) - Request Additional Company Affiliations">
                <p class="frmfields">
                    In the box below, please enter company NAIC IDs, separated by commas. Then click the submit button.<br />
                    Please allow up to 48 hours to process 
                        affiliation requests.
                </p>
                <p class="frmfields">*All fields are required.</p>

                <label class="frmfields" style="padding-left: 10px">Company NAIC IDs: </label>
                <span class="Required">*</span>
                <input class="frmfields" type="text" id="txtNaicids" style="margin: 0px; width: 494px;" />
                <p class="frmfields" style="padding-top: 20px">Please enter your contact information in case there is a question about your affiliation request.</p>
                <label class="frmfields" style="padding-left: 10px">Phone number:  </label>
                <span class="Required">*</span>
                <input class="frmfields" type="text" id="txtphoneno" style="margin: 0px; width: 150px;" />
                <label class="frmfields" style="padding-left: 30px">Email Address:  </label>
                <span class="Required">*</span>
                <input class="frmfields" type="email" id="txtemail" placeholder="Enter email only" style="margin: 0px; width: 321px;" />
                <div style="margin-top: 40px">
                    <p id="sucesslbl" class="frmfields" style="display: none;">
                        <label style="color: #4CAF50">Your Request has been sent. Please wait 24 - 48 hours.</label>
                    </p>
                    <p id="lblmailfailure" class="frmfields" style="display: none;">
                        <label style="color: #f1041e">There was a problem sending your request. Please try later.</label>
                    </p>
                    <p id="requiredtag" class="frmfields" style="display: none; color: red">*All fields are required.</p>
                </div>
                <p class="frmfields" style="padding-top: 10px">If you no longer report business for a company to which you have an affiliation, please send an email to <a href="mailto:<%=hdnEmailId.Value%>"><%=hdnEmailId.Value%></a> </p>
            </div>
            <div id="alertdialog" style="display: none" title="Incorrect NAIC number(s)"></div>
        </div>
        <div style="margin-top: 15px;">
            <uc1:Footer ID="Footer" runat="server" />
        </div>
    </form>
</body>
</html>


<script type="text/javascript">

    function radioChanged(rblcompanyid) {

        var allspans = $(rblcompanyid).closest("tr").find("span");

        document.getElementById("<%= btnYes.ClientID %>").disabled = false;
        document.getElementById("<%= hdn_companyid.ClientId%>").value = rblcompanyid.value;
        document.getElementById("<%= hdn_companyname.ClientId%>").value = allspans[0].innerHTML;
        document.getElementById("<%= hdn_NaicId.ClientId%>").value = allspans[1].innerHTML;
    };
    //$('#btnYes').click(function () {
    //    //find the invalid field
    //    $('#myform').find(':invalid').first()
    //    //find it's parent tab and show it
    //    .parents('.tab-pane').show();
    //});

    function ShowDialog() {
        $("#Open-dialog").dialog({
            bgiframe: true,
            height: 450,
            width: 805,
            modal: true,
            buttons: {
                "Submit Affiliation Request": function () {
                    var naicids = document.getElementById("txtNaicids").value;
                    var phno = document.getElementById("txtphoneno").value;
                    var email = document.getElementById("txtemail").value;
                    if (phno.length <= 0) {
                        $("#requiredtag").show();
                    }
                    else if (email.length <= 0) {
                        $("#requiredtag").show();
                    }
                    else {
                        $("#requiredtag").hide();

                        $.ajax({
                            type: 'POST',
                            url: 'check.aspx/CompanyAffiliationRequest',
                            data: JSON.stringify({ "naicids": naicids, "phno": phno, "email": email }),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (msg) {
                                if (msg.d.indexOf('invalid') !== -1) {
                                    LhdSurveyStatusDialog(msg.d, "Incorrect NAIC number(s)");
                                } else if (msg.d.indexOf('24') !== -1) {
                                    $("#sucesslbl").show();
                                    document.getElementById("txtNaicids").value = "";
                                    document.getElementById("txtphoneno").value = "";
                                    document.getElementById("txtemail").value = "";
                                    $(":button:contains('Submit')").attr('disabled', true).addClass("ui-state-disabled");
                                }
                                else {
                                    $("#lblmailfailure").show();

                                }
                            },
                            error: function () {
                                alert("Error! Try again...");
                            }
                        });
                    }
                },
                Close: function () {
                    document.getElementById("txtNaicids").value = "";
                    document.getElementById("txtphoneno").value = "";
                    document.getElementById("txtemail").value = "";
                    $("#sucesslbl").hide();
                    $("#lblmailfailure").hide();
                    $(this).dialog('close');
                }
            },
            open: function (event, ui) {
                $(":button:contains('Submit')").attr('disabled', true).addClass("ui-state-disabled");
            },
        });

    };

    $("#txtNaicids").on("keyup change blur", function () {
        if ($("#txtNaicids").val().length > 0) {
            $(".ui-dialog-buttonset button:contains('Submit')").attr('disabled', false).removeClass("ui-state-disabled");
        }
        else {
            $(".ui-dialog-buttonset button:contains('Submit')").attr('disabled', true).addClass("ui-state-disabled");
        }
    });
    function LhdSurveyStatusDialog(msg, titleText) {
        // var dialog = $("<div>" + msg + "<div>");
        $('#alertdialog').dialog({
            modal: true,
            width: 550,
            resizable: false,
            open: function () {
                $(this).html(msg);
            },
            buttons: {
                OK: function () {
                    $(this).dialog("close");
                }
            }
        });
        $('#alertdialog').next().find('.ui-dialog-buttonset').prepend("<span style='float: center;margin-right: 50px; padding-top: 10px;color: red'>Please correct the issues and try again</span>");

    };
</script>
