
$("body").on("click", "#emmaplayvideo", function() {
    var video = $(".myVideo").get(0);

    if (video.paused) {
        video.play();
    } else {
        video.pause();
    }
});

$("body").on("change", "#dateofbirth", function() {

    var dob = new Date($(this).val());
    var today = new Date();
    var age = today.getFullYear() - dob.getFullYear();
    var m = today.getMonth() - dob.getMonth();
    if (m < 0 || (m === 0 && today.getDate() < dob.getDate())) {
        age--;
    }

    $("#age").val(+ age + " years");
});

$("body").on("click", "#submitbornagaindetails", function() {
    
    var firstname = $("#firstname").val();
    var middlename = $("#middlename").val();
    var lastname = $("#lastname").val();
    var gender = $("#gender").val();
    var dateofbirth = $("#dateofbirth").val();
    var age = $("#age").val();
    var maritalstatus = $("#maritalstatus").val();
    var phonenumber = $("#phonenumber").val();
    var emailaddress = $("#emailaddress").val();
    var homeaddress = $("#address").val();


    if(firstname == '' || firstname == 'NULL'){
        $("#firstname").css('border', '2px solid red');

    }else if(middlename == '' || middlename == 'NULL'){

        $("#firstname").css('border', '2px solid green');
        $("#middlename").css('border', '2px solid red');

    }else if(lastname == '' || lastname == 'NULL'){

        $("#firstname").css('border', '2px solid green');
        $("#middlename").css('border', '2px solid green');
        $("#lastname").css('border', '2px solid red');
        
    }else if(gender == '' || gender == 'NULL'){

        $("#firstname").css('border', '2px solid green');
        $("#middlename").css('border', '2px solid green');
        $("#lastname").css('border', '2px solid green');
        $("#gender").css('border', '2px solid red');

    }else if(dateofbirth == '' || dateofbirth == 'NULL'){

        $("#firstname").css('border', '2px solid green');
        $("#middlename").css('border', '2px solid green');
        $("#lastname").css('border', '2px solid green');
        $("#gender").css('border', '2px solid green');
        $("#dateofbirth").css('border', '2px solid red');

    }else if(age == '' || age == 'NULL'){

        $("#firstname").css('border', '2px solid green');
        $("#middlename").css('border', '2px solid green');
        $("#lastname").css('border', '2px solid green');
        $("#gender").css('border', '2px solid green');
        $("#dateofbirth").css('border', '2px solid green');
        $("#age").css('border', '2px solid red');

    }else if(maritalstatus == '' || maritalstatus == 'NULL'){

        $("#firstname").css('border', '2px solid green');
        $("#middlename").css('border', '2px solid green');
        $("#lastname").css('border', '2px solid green');
        $("#gender").css('border', '2px solid green');
        $("#dateofbirth").css('border', '2px solid green');
        $("#age").css('border', '2px solid green');
        $("#maritalstatus").css('border', '2px solid red');

    }else if(phonenumber == '' || phonenumber == 'NULL'){

        $("#firstname").css('border', '2px solid green');
        $("#middlename").css('border', '2px solid green');
        $("#lastname").css('border', '2px solid green');
        $("#gender").css('border', '2px solid green');
        $("#dateofbirth").css('border', '2px solid green');
        $("#age").css('border', '2px solid green');
        $("#maritalstatus").css('border', '2px solid green');
        $("#phonenumber").css('border', '2px solid red');

    }else if(emailaddress == '' || emailaddress == 'NULL'){

        $("#firstname").css('border', '2px solid green');
        $("#middlename").css('border', '2px solid green');
        $("#lastname").css('border', '2px solid green');
        $("#gender").css('border', '2px solid green');
        $("#dateofbirth").css('border', '2px solid green');
        $("#age").css('border', '2px solid green');
        $("#maritalstatus").css('border', '2px solid green');
        $("#phonenumber").css('border', '2px solid green');
        $("#emailaddress").css('border', '2px solid red');


    }else if(homeaddress == '' || homeaddress == 'NULL'){

        $("#firstname").css('border', '2px solid green');
        $("#middlename").css('border', '2px solid green');
        $("#lastname").css('border', '2px solid green');
        $("#gender").css('border', '2px solid green');
        $("#dateofbirth").css('border', '2px solid green');
        $("#age").css('border', '2px solid green');
        $("#maritalstatus").css('border', '2px solid green');
        $("#phonenumber").css('border', '2px solid green');
        $("#emailaddress").css('border', '2px solid green');
        $("#address").css('border', '2px solid red');

    }else{

        $("#firstname").css('border', '2px solid green');
        $("#middlename").css('border', '2px solid green');
        $("#lastname").css('border', '2px solid green');
        $("#gender").css('border', '2px solid green');
        $("#dateofbirth").css('border', '2px solid green');
        $("#age").css('border', '2px solid green');
        $("#maritalstatus").css('border', '2px solid green');
        $("#phonenumber").css('border', '2px solid green');
        $("#emailaddress").css('border', '2px solid green');
        $("#address").css('border', '2px solid green');

        $.ajax({
            type:'POST',
            url:'../controller/scripts/bornagain/insertbornagain.php',
            data:{
                firstname: firstname,
                middlename: middlename,
                lastname: lastname,
                gender: gender,
                dateofbirth: dateofbirth,
                age: age,
                maritalstatus: maritalstatus,
                phonenumber: phonenumber,
                emailaddress: emailaddress,
                homeaddress: homeaddress
            },
            success:function(result){
                if(result == 1){
                    alert('Details Submitted Successfully');
                }else{
                    alert('Details Already Exists');
                }
            }
        })
    }
});