<div id='NewLeadsFormContainer'>



</div>

<br><br><br>

<script>


    $('#usernumber').keyup(function () {
        checkifUserExists();
        SRegistrationValidateALLinputs();
    });


    function NewLeadsvalidateForm() {
        let fullname = $('#NewLeadsFullname').val();
        let mobile = $('#NewLeadsmobile').val();
        let landline = $('#NewLeadslandline').val();
        let email = $('#NewLeadsemail').val();
        let preferreddate = $('#NewLeadspreferreddate').val();
        let preferredsite = $('#NewLeadsPreferredSite').val();
        if (!fullname || !mobile || !email) { return false; }
        if (!hasValidMobileFormat(mobile)) { return false; }
        if (!isValidEmail(email)) { return false; }
        return { fullname: fullname, mobile: mobile, landline: landline, email: email, preferred_date: preferreddate, preferred_site: preferredsite };
    }

    function TrytoSubmitNewLead() {
        let ValidateData = NewLeadsvalidateForm();
        if (!ValidateData) {
            ModalQuickDismiss('Invalid/Incomplete', 'The following are required<br><br>Fullname<br>11 Digits Mobile Number<br>Correct Email<br><br>Please Input the following properly if not done so. Thank you.');
            return false;
        }

        console.log(ValidateData);
        request.type('POST').data(ValidateData).url('/NewLeads/Form/submit').fromVarCache(false).success((response) => {
            console.log(response);
            if (response['success'] === true) {
                ModalQuickDismiss('Success', 'New Lead Created', 'NewLeadsModalSuccess', modaltohide = '', function () {
                    ButtonGo('ViewLeadDetails', response['data']);

                });
            }
            else if (response['success'] === true) {
                ModalQuickDismiss('Error', 'Unable to Submit. Try Again Later', 'NewPropertysModalError');
            }

        }).error((errorstring) => {
            ModalQuickDismiss('Error', 'An Error Occured<br>' + errorstring + '<br><br>Please Try Again Later');
        }).go()


    }



    if (typeof request === 'undefined') {
        var request = new RequestData(false);
        var requestWHash = new RequestData(true);
    }

    $(document).ready(function () {
        requestWHash.type('POST').url('/NewLeads/Form/PreferredSitesOption').fromVarCache(true).success((response) => {
            UIReplaceCurrentOptionsSelect('NewLeadsPreferredSite', response);
        }).go();
    });



    ReusableUIElements.NewLeadsGenerateUI();
    changeTopbarTitle('New Lead');
</script>