$('#error').hide(1000);

console.log();

  
firstname = false;
middlename = false;
lastname = false;
email_address = false;
phone = false;
gender = false;
date_of_birth = false;
account_type = false;
address = false;
postal_code = false;
state = false;
country = false;
currency = false;
password = false;
confirm_password = false;
account_pin = false;

$('input[name="firstname"]').keyup(function() {
    check_firstname();
});
 
$('input[name="middlename"]').keyup(function() {
    check_middlename();
});
 
$('input[name="lastname"]').keyup(function() {
    check_lastname();
});
 
$('input[name="email_address"]').keyup(function() {
    check_email_address();
});
 
$('input[name="phone"]').keyup(function() {
    check_phone();
});
 
$('select[name="gender"]').change(function() {
    check_gender();
});
 
$('input[name="date_of_birth"]').on('input', function() {
    check_date_of_birth();
});
 
$('select[name="account_type"]').change(function() {
    check_account_type();
});
 
$('input[name="address"]').keyup(function() {
    check_address();
});
 
$('input[name="postal_code"]').keyup(function() {
    check_postal_code();
});
 
$('input[name="state"]').keyup(function() {
    check_state();
});
 
$('select[name="country"]').change(function() {
    check_country();
});
 
$('select[name="currency"]').change(function() {
    check_currency();
});
 
$('input[name="password"]').keyup(function() {
    check_password();
});
 
$('input[name="confirm_password"]').keyup(function() {
    check_confirm_password();
});
 
$('input[name="account_pin"]').keyup(function() {
    check_account_pin();
});

// $('input[type="checkbox"]').keyup(function() {
//     check_checkbox();
// });


function check_firstname()
{
var pattern = /^[a-z A-Z]+$/;
var Profession = $('input[name="firstname"]').val();
if (pattern.test(Profession) && Profession !== '') {
$('#error').hide(1000);
$('input[name="firstname"]').css('border', '2px solid lightgreen');
    if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
}else{
$('input[name="firstname"]').css('border','2px solid red');
firstname = true;
}
}


function check_middlename()
{
var pattern = /^[a-z A-Z]+$/;
var Profession = $('input[name="middlename"]').val();
if (pattern.test(Profession) && Profession !== '') {
$('#error').hide(1000);
$('input[name="middlename"]').css('border', '2px solid lightgreen');
    if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
}else{
$('input[name="middlename"]').css('border','2px solid red');
middlename = true;
}
}

function check_lastname()
{
var pattern = /^[a-z A-Z]+$/;
var Profession = $('input[name="lastname"]').val();
if (pattern.test(Profession) && Profession !== '') {
$('#error').hide(1000);
$('input[name="lastname"]').css('border', '2px solid lightgreen');
    if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
}else{
$('input[name="lastname"]').css('border','2px solid red');
lastname = true;
}
}

function check_email_address() {
var email = $('input[name="email_address"]').val();
var indexat = email.indexOf("@");
var indexdot = email.indexOf(".");

if(indexat < 1 || (indexdot-indexat) < 2)
{
$('input[name="email_address"]').css ('border', '2px solid #d90000');
}else{
$('input[name="email_address"]').css('border','2px solid #34F458');
    if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
email_address = true;
}
}

function check_phone()
{
var pattern = /^[0-9]+$/;
var phone_num = $('input[name="phone"]').val();
if (pattern.test(phone_num) && phone_num !== '') {
$('input[name="phone"]').css('border', '2px solid #34F458');
    if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
}else{
$('input[name="phone"]').css('border','2px solid #F90A0A');
phone = true;
}
}


function check_gender()
{

  var selectedOption = $('select[name="gender"]').val();
  if (selectedOption === "Male" || selectedOption === "Female" ) {
    $('select[name="gender"]').css('border','2px solid #34F458');
            if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
} else {
    $('select[name="gender"]').css('border','2px solid #F90A0A');
}
}

function check_date_of_birth()
{
    var dob = $('input[name="date_of_birth"]').val();
    if (dob !== '') {
    $('input[name="date_of_birth"]').css('border', '2px solid #34F458');
        if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
    }else{
    $('input[name="date_of_birth"]').css('border','2px solid #F90A0A');
    date_of_birth = true;
    }
}

function check_account_type()
{
    var selectedOption = $('select[name="account_type"]').val();
    if ($.trim(selectedOption) !== null) {
      $('select[name="account_type"]').css('border','2px solid #34F458');
               if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
  } else {
      $('select[name="account_type"]').css('border','2px solid #F90A0A');
  }
}

function check_address()
{
    var dob = $('input[name="address"]').val();
    if (dob !== '') {
    $('input[name="address"]').css('border', '2px solid #34F458');
        if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
    }else{
    $('input[name="address"]').css('border','2px solid #F90A0A');
    address = true;
    }
}

function check_postal_code()
{
    var dob = $('input[name="postal_code"]').val();
    if (dob !== '') {
    $('input[name="postal_code"]').css('border', '2px solid #34F458');
        if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
    }else{
    $('input[name="postal_code"]').css('border','2px solid #F90A0A');
    postal_code = true;
    }
}


 
function check_state()
{
    var dob = $('input[name="state"]').val();
    if (dob !== '') {
    $('input[name="state"]').css('border', '2px solid #34F458');
        if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
    }else{
    $('input[name="state"]').css('border','2px solid #F90A0A');
    state = true;
    }
}

 
function check_country()
{
    var selectedOption = $('select[name="country"]').val();
    if ($.trim(selectedOption) !== null) {
      $('select[name="country"]').css('border','2px solid #34F458');
      if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
  } else {
      $('select[name="country"]').css('border','2px solid #F90A0A');
  }
}

 
function check_currency()
{
    var selectedOption = $('select[name="currency"]').val();
    if ($.trim(selectedOption) !== null) {
      $('select[name="currency"]').css('border','2px solid #34F458');
               if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
  } else {
      $('select[name="currency"]').css('border','2px solid #F90A0A');
  }
}

function check_password()
{
var password_len = $('input[name="password"]').val().length;
if (password_len <= 8) {
$('input[name="password"]').css('border','2px solid #F90A0A');
}else{
$('input[name="password"]').css('border','2px solid #34F458');
    if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
password = true;
}
if ($('input[name="password"]').val() !== $('input[name="confirm_password"]').val()) {
    $('input[name="confirm_password"]').css('border','2px solid #F90A0A');
    $('input[name="password"]').css('border','2px solid #F90A0A');

}else{
    $('input[name="confirm_password"]').css('border','2px solid #34F458');
    $('input[name="password"]').css('border','2px solid #34F458');
}
}

function check_confirm_password()
{
var password_len = $('input[name="confirm_password"]').val().length;
if (password_len <= 8) {
$('input[name="confirm_password"]').css('border','2px solid #F90A0A');
}else{
$('input[name="confirm_password"]').css('border','2px solid #34F458');
    if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
confirm_password = true;
}
if ($('input[name="password"]').val() !== $('input[name="confirm_password"]').val()) {
    $('input[name="confirm_password"]').css('border','2px solid #F90A0A');
    $('input[name="password"]').css('border','2px solid #F90A0A');

}else{
    $('input[name="confirm_password"]').css('border','2px solid #34F458');
    $('input[name="password"]').css('border','2px solid #34F458');
}
}

function check_account_pin()
{
    var dob = $('input[name="account_pin"]').val();
    if (dob !== '') {
    $('input[name="account_pin"]').css('border', '2px solid #34F458');
        if (window.message1) {
        window.message1.hide();
        $('#btn').attr('disabled', false);

    }
    }else{
    $('input[name="account_pin"]').css('border','2px solid #F90A0A');
    account_pin = true;
    }
}

function check_checkbox()
{
var dob = $('input[type="checkbox"]').prop('checked');
if (dob) {
$('input[type="checkbox"]').css('border', '2px solid #34F458');
if (window.message1) {
window.message1.hide();
$('#btn').attr('disabled', false);

}
}else{
$('input[type="checkbox"]').css('border','2px solid #F90A0A');
}
}

