/* Minification failed. Returning unminified contents.
(1,1): run-time error CSS1019: Unexpected token, found '$'
(1,2): run-time error CSS1019: Unexpected token, found '('
(1,3): run-time error CSS1019: Unexpected token, found '".custom-file-input"'
(1,23): run-time error CSS1019: Unexpected token, found ')'
(1,25): run-time error CSS1030: Expected identifier, found 'on('
(1,25): run-time error CSS1019: Unexpected token, found 'on('
(1,28): run-time error CSS1019: Unexpected token, found '"change"'
(1,36): run-time error CSS1019: Unexpected token, found ','
(1,47): run-time error CSS1031: Expected selector, found '('
(1,47): run-time error CSS1025: Expected comma or open brace, found '('
(4,2): run-time error CSS1019: Unexpected token, found ')'
(6,16): run-time error CSS1031: Expected selector, found '='
(6,16): run-time error CSS1025: Expected comma or open brace, found '='
(7,16): run-time error CSS1031: Expected selector, found '='
(7,16): run-time error CSS1025: Expected comma or open brace, found '='
(8,17): run-time error CSS1031: Expected selector, found '='
(8,17): run-time error CSS1025: Expected comma or open brace, found '='
(9,14): run-time error CSS1031: Expected selector, found '='
(9,14): run-time error CSS1025: Expected comma or open brace, found '='
(10,16): run-time error CSS1031: Expected selector, found '='
(10,16): run-time error CSS1025: Expected comma or open brace, found '='
(11,18): run-time error CSS1031: Expected selector, found '='
(11,18): run-time error CSS1025: Expected comma or open brace, found '='
(12,17): run-time error CSS1031: Expected selector, found '='
(12,17): run-time error CSS1025: Expected comma or open brace, found '='
(15,10): run-time error CSS1031: Expected selector, found 'validateFName('
(15,10): run-time error CSS1025: Expected comma or open brace, found 'validateFName('
(29,10): run-time error CSS1031: Expected selector, found 'validateLName('
(29,10): run-time error CSS1025: Expected comma or open brace, found 'validateLName('
(43,10): run-time error CSS1031: Expected selector, found 'validateGender('
(43,10): run-time error CSS1025: Expected comma or open brace, found 'validateGender('
(53,10): run-time error CSS1031: Expected selector, found 'validateAge('
(53,10): run-time error CSS1025: Expected comma or open brace, found 'validateAge('
(63,10): run-time error CSS1031: Expected selector, found 'validatePhone('
(63,10): run-time error CSS1025: Expected comma or open brace, found 'validatePhone('
(81,10): run-time error CSS1031: Expected selector, found 'validateAddress('
(81,10): run-time error CSS1025: Expected comma or open brace, found 'validateAddress('
(92,10): run-time error CSS1031: Expected selector, found 'validateForm('
(92,10): run-time error CSS1025: Expected comma or open brace, found 'validateForm('
(110,10): run-time error CSS1031: Expected selector, found 'saveDetails('
(110,10): run-time error CSS1025: Expected comma or open brace, found 'saveDetails('
 */
$(".custom-file-input").on("change", function () {
    var fileName = $(this).val().split("\\").pop();
    $(this).siblings(".custom-file-label").addClass("selected").html(fileName);
});

var fnameError = document.getElementById('fname-error');
var lnameError = document.getElementById('lname-error');
var genderError = document.getElementById('gender-error');
var ageError = document.getElementById('age-error');
var phoneError = document.getElementById('phone-error');
var addressError = document.getElementById('address-error');
var submitError = document.getElementById('submit-error');


function validateFName() {

    var name = document.getElementById('txtFirstName').value;

    if (name.length == 0) {
        fnameError.innerHTML = 'FirstName is required';
        return false;


    }
    fnameError.innerHTML = '';
    return true;
}

function validateLName() {

    var name = document.getElementById('txtLastName').value;

    if (name.length == 0) {
        lnameError.innerHTML = 'LastName is required';
        return false;
    }

    lnameError.innerHTML = '';
    return true;
}


function validateGender() {
    var gender = document.getElementById('sltGender').value;

    if (gender == '-1') {
        genderError.innerHTML = 'Gender is required';
        return false;
    }
    genderError.innerHTML = '';
    return true;
}
function validateAge() {
    var age = document.getElementById('txtAge').value;

    if (age.length == 0) {
        ageError.innerHTML = 'Age is required';
        return false;
    }
    ageError.innerHTML = '';
    return true;
}
function validatePhone() {
    var phone = document.getElementById('txtMobile').value;

    if (phone.length == 0) {
        phoneError.innerHTML = 'Phone no is required';
        return false;
    }
    if (phone.length !== 10) {
        phoneError.innerHTML = 'Phone no. should be 10 digits';
        return false;
    }
    if (!phone.match(/^[0-9]{10}$/)) {
        phoneError.innerHTML = 'Phone no. is required';
        return false;
    }
    phoneError.innerHTML = '';
    return true;
}
function validateAddress() {
    var address = document.getElementById('txtAddress').value;

    if (address.length == 0) {
        addressError.innerHTML = 'Address is required';
        return false;
    }
    addressError.innerHTML = '';
    return true;
}

function validateForm() {
    if (!validateFName() || !validateLName() || !validateGender() || !validateAge() || !validatePhone() || !validateAddress()) {
        return false;
    }
    else {

        saveDetails();


        swal(
            'Success',
            'Submitted Successfully',
            'success'
        )

    }
}

function saveDetails() {

    var FName = $('#txtFirstName').val();
    var LName = $('#txtLastName').val();
    var Gender = $('#sltGender').val();
    var Mobile = $('#txtMobile').val();
    var Email = $('#txtEmail').val();
    var Address = $('#txtAddress').val();
    var FileDocument = $('#customFile')[0].files[0];
    var Message = $('#txtMessage').val();
    var PersonAge = $('#txtAge').val();

    var formData = new FormData();
    formData.append("FirstName", FName);
    formData.append("LastName", LName);
    formData.append("Gender", Gender);
    formData.append("Mobile", Mobile);
    formData.append("Email", Email);
    formData.append("Address", Address);
    formData.append("File", FileDocument);
    formData.append("Message", Message);
    formData.append("age", PersonAge);

    $.ajax({
        url: '/send-enquiry',
        type: 'POST',
        data: formData,
        processData: false,
        contentType: false,
        success: function (response) {
            if (response === true) {
                $('#txtFirstName').val('');
                $('#txtLastName').val('');
                $('#sltGender').val('');
                $('#txtMobile').val('');
                $('#txtEmail').val('');
                $('#txtAddress').val('');
                $('#customFile')[0].files[0];
                $('#txtMessage').val('');
                $('#txtAge').val('');
            }
        },
        error: function (xhr, status, error) {
            // Handle error response
     
        }
    });
}
