<%@ Page Title="" Language="C#" MasterPageFile="~/MasterFile/TimeCheck.master" AutoEventWireup="true" CodeFile="TA_UI_Master_EmployeeContractorAdd.aspx.cs" Inherits="Masters_TA_UI_Master_EmployeeContractorAdd" %>

<asp:Content ID="Content1" ContentPlaceHolderID="BodyContentPH" runat="Server">
    <div class="content-header">
        <h1 style="background-image: url('../dist/img/contractor.png'); background-repeat: no-repeat; padding-left: 35px">
            <asp:Label ID="lbl_HeaderContractor" runat="server"></asp:Label>
        </h1>
        <asp:SiteMapPath ID="site" runat="server" CssClass="breadcrumb">
            <NodeStyle CssClass="active" />
        </asp:SiteMapPath>
    </div>
    <div class="content">
        <div class="inr-ftr">
            <div class="row">
                <div class="col-sm-12">
                    <div class="pull-right">
                        <h6>
                            <span style="color: Red">|</span><span style="padding-left: 10px; padding-right: 10px"><asp:Label
                                ID="lbl_IndicatesMandatoryFields" runat="server"></asp:Label>
                                (3 No.)</span>
                        </h6>
                    </div>
                </div>
                <div class="clearfix">
                </div>
            </div>
        </div>
        <div class="emp-filter">
            <div class="form-horizontal">
                <div class="row">
                    <div class="col-md-12">
                        <div class="row form-group">
                            <div class="col-md-2">
                                <asp:Label ID="lbl_ContractorID" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-3">
                                <asp:TextBox onpaste="return true" ID="txt_ContractorID" runat="server" CssClass="form-control man-dat "
                                    MaxLength="50"></asp:TextBox>
                                <%--<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txt_ContractorID"
                                    ErrorMessage="Enter Contractor ID" SetFocusOnError="True" Display="None" ValidationGroup="vgContractorAdd"></asp:RequiredFieldValidator>--%>
                            </div>

                            <div class="col-md-2">

                                <asp:Label ID="lbl_ContractorName" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-3">


                                <asp:TextBox onpaste="return true" ID="txt_ContractorName" runat="server" CssClass="form-control man-dat"
                                    MaxLength="250" onkeypress="return validateName(event);"></asp:TextBox>

<%--                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txt_ContractorName"
                                    ErrorMessage="Enter Contractor Name" SetFocusOnError="True" Display="None" ValidationGroup="vgContractorAdd"></asp:RequiredFieldValidator>--%>
                            </div>

                        </div>

                        <div class="row form-group">
                            <div class="col-md-2">
                                <asp:Label ID="lbl_EmailID" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-3">
                                <asp:TextBox onpaste="return true" ID="txt_EmailID" runat="server" CssClass="form-control "
                                    MaxLength="100" Onblur="validateEmailID();"></asp:TextBox>
                                <%-- <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txt_EmailID"
                                    ErrorMessage="Enter Contractor Email ID" SetFocusOnError="True" Display="None" ValidationGroup="vgGradeAdd"></asp:RequiredFieldValidator>--%>
                            </div>
                            <div class="col-md-2">
                                <asp:Label ID="lbl_Mobileno" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-3">
                                <%-- <asp:TextBox onpaste="return true" ID="txt_Mobileno" runat="server" CssClass="form-control man-dat"
                                    MaxLength="15" onDrop="return false;" onkeyup="return assignValue(event,this,'Phone')"
                                    onkeypress="return checkPhone(event)"></asp:TextBox>--%>
                                <asp:TextBox onpaste="return true" ID="txt_Mobileno" runat="server" CssClass="form-control man-dat"
                                    MaxLength="15" onDrop="return false;" onkeyup="return assignValue(event,this,'Mobile')"
                                    onkeypress="return checkPhone(event)" Onblur="return ValidateMobileNumber();"></asp:TextBox>

                               <%-- <asp:TextBox onpaste="return true" ID="txt_Mobileno" runat="server" CssClass="form-control man-dat"
                                    MaxLength="15" onDrop="return false;" onkeypress="return checkPhone(event)"></asp:TextBox>--%>

                                <%--<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txt_Mobileno"
                                    ErrorMessage="Mobile Number" SetFocusOnError="True" Display="None" ValidationGroup="vgGradeAdd"></asp:RequiredFieldValidator>--%>

                                <%--  <asp:RegularExpressionValidator  ID="RequiredFieldValidator5"   runat="server"  ControlToValidate="txt_Mobileno"   ValidationExpression="^\d{10,15}$"    ErrorMessage="Phone number must be between 10 and 15 digits" ForeColor="Red"   Display="None" 
                                ValidationGroup="vgGradeAdd" /> --%>
                            </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-md-2">
                                <asp:Label ID="lbl_ContactorAddress" runat="server"></asp:Label><font color="#FF0000">
                                </font>
                            </div>
                            <div class="col-md-3">
                                <asp:TextBox onpaste="return true" ID="txt_ContactorAddress" runat="server" CssClass="form-control"
                                    MaxLength="255" onkeypress="return acceptAddress(event,this)" onkeyup="return chkMaxLen(event,this,225,MaxLength);"
                                    TextMode="MultiLine" Style="resize: none"></asp:TextBox>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-10">
                                <div class="pull-right-button">
                                    <asp:LinkButton ID="btn_add" CssClass="btn save-btn fa-floppy-o" runat="server" 
                                         OnClientClick="return Validation();" OnClick="btn_add_Click" />
                                    <asp:LinkButton ID="btn_Cancel" CssClass="btn save-btn fa-angle-left" runat="server"
                                        OnClick="btn_Cancel_Click" CausesValidation="false" />
                                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
                                        ShowSummary="False" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script type="text/javascript">

            var MaxLength = "Maximum length is ";
            function MaxLengthh(maxLength) {
                MaxLength = maxLength;
            }

            function Validation() {
                debugger;
                var ContractorId = document.getElementById('<%= txt_ContractorID.ClientID %>').value;
                var ContractorName = document.getElementById('<%= txt_ContractorName.ClientID %>').value;
                var MobileNo = document.getElementById('<%= txt_Mobileno.ClientID %>').value;

                if (ContractorId == "")
                {
                    alert('Enter Contractor ID');
                    document.getElementById('<%= txt_ContractorID.ClientID %>').focus();
                    return false;
                }
                if (ContractorName == "") {
                    alert('Enter Contractor Name');
                    document.getElementById('<%= txt_ContractorName.ClientID %>').focus();
                    return false;
                }
                if (MobileNo == "") {
                    alert('Enter Mobile Number');
                    
                    return false;
                }
                return Save_Conf();
            }
            function Save_Conf() {
                //Alert_AreyousuretoDelete
                return confirm('Are you sure, to Save?');
            }
            var emailInput = document.getElementById('<%= txt_EmailID.ClientID %>');

            function validateEmailID() {
                debugger;
                // Correctly fetch the rendered textbox using ASP.NET client ID
                var emailInput = document.getElementById('<%= txt_EmailID.ClientID %>');
                if (!emailInput) return true; // Fail safely if not found

                var email = emailInput.value.trim();
                if (email !== "") {
                    // Regex to validate basic email structure
                    var exp = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
                    if (!exp.test(email)) {
                        alert('Enter Valid Email Id');

                        return false;
                    }
                }
                return true;
            }
            var ph;
            function assignValue(e, ctrl, val) {
                debugger;
                var keycode;
                if (window.event) keycode = window.event.keyCode;
                else if (e) keycode = e.which;
                else if (event) keycode = event.keyCode;
                else return true;
                ph = ctrl.value;
                if (ctrl.value.lastIndexOf("+") == 0 || ctrl.value.lastIndexOf("+") == -1) {
                }
                else {
                    ctrl.value = ph;
                    ctrl.focus();
                    alert(Entervalid + val + AlertNumber);
                    return false
                }
                if (!(keycode == 58 && e.value.indexOf(":") > -1)) {
                    if ((keycode == 40) || (keycode == 41) || (keycode == 43) || (keycode == 45) || (keycode >= 48 && keycode <= 57) || (keycode == 0) || (keycode == 8)) {
                        return true;
                    }
                    else {
                        return false;
                    }
                }
                else {
                    return false;
                }
                return true;
            }
            function checkPhone(e) {
                debugger;
                var keycode;
                if (window.event) keycode = window.event.keyCode;
                else if (e) keycode = e.which;
                else if (event) keycode = event.keyCode;
                else return true;

                if (!(keycode == 58 && e.value.indexOf(":") > -1)) {
                    if ((keycode == 40) || (keycode == 41) || (keycode == 43) || (keycode == 45) ||
                        (keycode >= 48 && keycode <= 57) || (keycode == 8) || (keycode == 0)) {
                        return true;
                    }
                    else {
                        return false;
                    }
                }
                else {
                    return false;
                }
                return true;
            }
            function ValidateMobileNumber() {
                var mobileNo = document.getElementById('<%= txt_Mobileno.ClientID %>').value;

              // Check if the mobile number length is between 10 and 15
              if (mobileNo.length < 10 || mobileNo.length > 15) {
                  alert('Mobile number must be between 10 and 15 digits.');
                  document.getElementById('<%= txt_Mobileno.ClientID %>').Focus();
                  return false; // prevent form submission if validation fails
              }

              // Optionally, check if the mobile number contains only digits
              var regex = /^[0-9]+$/;
              if (!regex.test(mobileNo)) {
                  alert('Mobile number should contain only digits.');
                  return false;
              }

              return true; // proceed with form submission if validation passes
          }

            function validateName(event) {
                var key = event.keyCode || event.which;
                var keyChar = String.fromCharCode(key);
                var regex = /^[A-Za-z\s]+$/;  // Only letters and spaces are allowed
                if (!regex.test(keyChar) && key !== 8) {  // Allow backspace
                    event.preventDefault();
                }
            }

            // Validate Contractor ID Field (Only Numbers Allowed)
            function validateNumber(event) {
                var key = event.keyCode || event.which;
                if (key < 48 || key > 57) {  // Numbers 0-9 only
                    event.preventDefault();
                }
            }

        </script>

    </div>
</asp:Content>


