<div id="admissionModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">×</button>
                <h3>My Profile</h3>
            </div>
            <div class="modal-body">
                <?php $this->load->view('admin/applicant_list_info/applicant_form_preview'); ?>
            </div>
            <div class="modal-footer"> 
                <a href="#" class="btn" data-dismiss="modal">Back</a>
                <input type="submit" class="btn btn-primary" id="admission_form_submit" value="Submit">
            </div>
        </div>
    </div>
</div>
<!--<script src="<?php //echo base_url();                                                                                                                                         ?>assets/js/plugins/datapicker/bootstrap-datepicker.js"></script>-->

<script src="<?php echo base_url(); ?>assets/js/plugins/jquery-ui/jquery-ui.min.js"></script>
<script src="<?php echo base_url(); ?>assets/keyboard/keyboard.js"></script>
<script src="<?php echo base_url(); ?>assets/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/jquery.validate.js"></script>
<script>
    $.validator.addMethod("isNIDValid", function(value) {
        var NidValid = false;
        var UserNID = value;
        if (UserNID.length == 0 || UserNID.length == 13 || UserNID.length == 17)
        {
            NidValid = true;
        }
        return NidValid;
    }, 'National ID Not Valid');
    $.validator.addMethod("isMoblieValid", function(value) {
        var MobileValid = false;
        var UserMobile = value;
        if (UserMobile.length == 0 || UserMobile.length == 11)
        {
            MobileValid = true;
        }
        return MobileValid;
    }, 'Mobile number not valid');

    $.validator.addMethod('filesize', function (value, element, param) {

        return this.optional(element) || (element.files[0].size <= param)
    }, 'File size must be less than {0}');


    $("#admission_form").validate({
        rules: {

           DEGREE_ID: {required:true},
           PROGRAM_ID: {required:true},
           FULL_NAME: {required:true},
           EMAIL: {required:true,email: true},
           MOBILE_NO: {required:true},
           DATE_OF_BIRTH: {required:true},
           FULL_NAME_BN: {required:true},
           NATIONALITY: {required:true},
           photo: {required: true, filesize: 102400},
           signature: {required:true},
           RELIGION_ID: {required:true},
           MARITAL_STATUS: {required:true},
           FATHER_NAME: {required:true},
           MOTHER_NAME: {required:true},
           FATHER_EMAIL: {email: true},
           MOTHER_EMAIL: {email: true},
           PLACE_OF_BIRTH: {required:true},
           NATIONAL_ID: {number:true, isNIDValid:true},
           BIRTH_CERTIFICATE: {number:true},
           HEIGHT_FEET: {number:true},
           WEIGHT_KG: {number:true},              
           FATHER_PHN: {number:true,isMoblieValid:true},
           MOTHER_PHN: {number:true,isMoblieValid:true},
           LOCAL_GAR_PHN: {number:true,isMoblieValid:true},
           MARITAL_STATUS: {required:true},
           ANNUAL_INCOME: {number:true,required:true},
           DIVISION_ID: {required:true},
           DISTRICT_ID: {required:true},
           THANA_ID: {required:true},
           POLICE_STATION_ID: {required:true},
           UNION_ID: {required:true},
           VILLAGE: {required:true},       
           P_DIVISION_ID: {required:true},
           P_DISTRICT_ID: {required:true},
           P_THANA_ID: {required:true},
           P_POLICE_STATION_ID: {required:true},
           P_UNION_ID: {required:true},
           P_VILLAGE: {required:true},
           SCHOLARSHIP_DESC: {required:true},
           EXPELLED_DESC: {required:true},
           ARRESTED_DESC: {required:true},
           CONVICTED_DESC: {required:true},
           APPLY_SEMESTER: {required:true},
           APPLY_YEAR: {number:true,required:true},
           SBLN_ROLL_NO: {number:true,required:true},
           'EXAM_NAME[1]': {required:true},
           'PASSING_YEAR[1]': {number:true,required:true,maxlength: 4,minlength: 4},
           'BOARD[1]': {required:true},
           'GROUP[1]': {required:true},
           'GPA[1]': {number:true,required:true},
           'GPAWA[1]': {number:true,required:true},
           'INSTITUTE[1]': {required:true},

           'EXAM_NAME[2]': {required:true},
           'PASSING_YEAR[2]': {number:true,required:true,maxlength: 4,minlength: 4},
           'BOARD[2]': {required:true},
           'GROUP[2]': {required:true},
           'GPA[2]': {number:true,required:true},
           'GPAWA[2]': {number:true,required:true},
           'INSTITUTE[2]': {required:true},

           'EXAM_NAME[3]': {required:true},
           'PASSING_YEAR[3]': {number:true,required:true,maxlength: 4,minlength: 4},
           'BOARD[3]': {required:true},
           'GROUP[3]': {required:true},
           'GPA[3]': {number:true,required:true},
           'GPAWA[3]': {number:true,required:true},
           'INSTITUTE[3]': {required:true},




       },
       messages: {  
           FULL_NAME_BN: "Bangla name required",
           photo: "Photo required",
           signature: "Signature required",
           NATIONALITY: "Nationality required",
           RELIGION_ID: "Religion required",
           MARITAL_STATUS: "Marital status required",
           FATHER_NAME: "Father name required",
           MOTHER_NAME: "Mother name required",      
           PLACE_OF_BIRTH: "Place of birth field is required",
           NATIONAL_ID: "Required valid national ID",
           BIRTH_CERTIFICATE: "Required valid birth certificate no",
           MARITAL_STATUS: "Marital status required",
           HEIGHT_FEET: "Number only",
           WEIGHT_KG: "Number only",
       }
   });

    /*    $("#admission_form").validate({debug: true});
    $("#admission_form").valid();*/

    $('#admission_form_submit').on('click', function (e) {
        $("#admission_form").submit();
        $('#admissionModal').modal('hide');
    });

    $('#admission_form_btn').on('click',function(){

      if($("#admission_form").valid()) {
            //personal information 
                     
            $("#P_FULL_NAME").text($("#FULL_NAME").val());             
            $("#P_MOBILE_NO").text($("#MOBILE_NO").val());             
            $("#P_EMAIL").text($("#EMAIL").val());             
            $("#P_DATE_OF_BIRTH").text($("#datepicker").val());             
            $("#P_FULL_NAME_BN").text($("#FULL_NAME_BN").val());
            $("#P_PLACE_OF_BIRTH").text($("#PLACE_OF_BIRTH").val());
            //$("#P_GENDER").text($('input[name=GENDER]:checked').val());
            $("#P_GENDER").text($("input[name=GENDER]:checked").attr("data-value"));
            var blood_group = $("#BLOOD_GRP option:selected").text() == "-Select-" ? '' : $("#BLOOD_GRP option:selected").text();
            $("#P_BLOOD_GROUP").text(blood_group);          
              var program_id = $("#PROGRAM_ID option:selected").text() == "-Select-" ? '' : $("#PROGRAM_ID option:selected").text();
            $("#P_PROGRAM_ID").text(program_id);
            var marital_status = $("#MARITAL_STATUS option:selected").text() == "-Select-" ? '' : $("#MARITAL_STATUS option:selected").text();
            $("#P_MARITAL_STATUS").text(marital_status);
            var religion = $("#RELIGION_ID option:selected").text() == "-Select-" ? '' : $("#RELIGION_ID option:selected").text();
            $("#P_RELIGION_ID").text(religion);
            $("#P_BIRTH_CERTIFICATE").text($("#BIRTH_CERTIFICATE").val());
            $("#P_NATIONAL_ID").text($("#NATIONAL_ID").val());
            $("#P_HEIGHT_FEET").text($("#HEIGHT_FEET").val());
            $("#P_HEIGHT_CM").text($("#HEIGHT_CM").val());
            $("#P_WEIGHT_KG").text($("#WEIGHT_KG").val());
            $("#P_WEIGHT_LBS").text($("#WEIGHT_LBS").val());


           //parents information
           $("#P_MOTHER_NAME").text($("#MOTHER_NAME").val());
           $("#P_MOTHER_PHN").text($("#MOTHER_PHN").val());
           $("#P_MOTHER_EMAIL").text($("#MOTHER_EMAIL").val());
           $("#P_MOTHER_WORK_ADDRESS").text($("#MOTHER_WORK_ADDRESS").val());
           var mother_ocu = $("#MOTHER_OCU option:selected").text() == "-Select-" ? '' : $("#MOTHER_OCU option:selected").text();
           $("#P_MOTHER_OCU").text(mother_ocu);

           $("#P_FATHER_NAME").text($("#FATHER_NAME").val());
           $("#P_FATHER_PHN").text($("#FATHER_PHN").val());
           $("#P_FATHER_EMAIL").text($("#FATHER_EMAIL").val());
           $("#P_FATHER_WORK_ADRESS").text($("#FATHER_WORK_ADRESS").val());
           var father_ocu = $("#FATHER_OCU option:selected").text() == "-Select-" ? '' : $("#FATHER_OCU option:selected").text();
           $("#P_FATHER_OCU").text(father_ocu);

           //local guardian
           var local_emergency_guardian=$('input[name=local_emergency_guardian]:checked', '#admission_form').val();
          // alert(local_emergency_guardian);
          if($("#DEGREE_ID").val() == 4){
            $("#preview_post_graduate_tr").show();
            
            }else{
            $("#preview_post_graduate_tr").hide();    
            }         
         if(local_emergency_guardian == 'F'){
            $("#local_guardian_div").show();
            $("#local_guardian_val").html("Father");
            $("#others_gurdian_info").hide();
        }

        if(local_emergency_guardian == 'M'){
            $("#local_guardian_div").show();
            $("#local_guardian_val").html(" Mother");
            $("#others_gurdian_info").hide();
        }

        if(local_emergency_guardian == 'O'){
            $("#others_gurdian_info").show();
            $("#local_guardian_div").hide();
            
            
            $("#P_LOCAL_GAR_NAME").text($("#LOCAL_GAR_NAME").val());
            $("#P_LOCAL_GAR_ADDRESS").text($("#LOCAL_GAR_ADDRESS").val());
            $("#P_LOCAL_GAR_PHN").text($("#LOCAL_GAR_PHN").val());
            $("#P_LOCAL_GAR_RELATION").text($("#LOCAL_GAR_RELATION option:selected").text());
        }

           //present address
           $("#Pr_DIVISION_ID").text($("#DIVISION_ID option:selected").text());
           $("#Pr_DISTRICT_ID").text($("#DISTRICT_ID option:selected").text());
           $("#Pr_POLICE_STATION_ID").text($("#POLICE_STATION_ID option:selected").text());
           $("#Pr_POST_OFFICE_ID").text($("#POST_OFFICE_ID option:selected").text());
           $("#Pr_THANA_ID").text($("#THANA_ID option:selected").text());
           $("#Pr_UNION_ID").text($("#UNION_ID option:selected").text());
           $("#Pr_VILLAGE_WARD").text($("#VILLAGE").val());
           
           var same_as_present=$('input[name=same_as_present]:checked', '#admission_form').val()

           if(same_as_present =='NO'){
               //permanent address
               $("#Pr_P_DIVISION_ID").text($("#P_DIVISION_ID option:selected").text());
               $("#Pr_P_DISTRICT_ID").text($("#P_DISTRICT_ID option:selected").text());
               $("#Pr_P_POLICE_STATION_ID").text($("#P_POLICE_STATION_ID option:selected").text());
               $("#Pr_P_POST_OFFICE_ID").text($("#P_POST_OFFICE_ID option:selected").text());
               $("#Pr_P_THANA_ID").text($("#P_THANA_ID option:selected").text());
               $("#Pr_P_UNION_ID").text($("#P_UNION_ID option:selected").text());
               $("#Pr_P_VILLAGE_WARD").text($("#P_VILLAGE").val());
           }else{
            $("#Pr_P_DIVISION_ID").text($("#DIVISION_ID option:selected").text());
            $("#Pr_P_DISTRICT_ID").text($("#DISTRICT_ID option:selected").text());
            $("#Pr_P_POLICE_STATION_ID").text($("#POLICE_STATION_ID option:selected").text());
            $("#Pr_P_POST_OFFICE_ID").text($("#POST_OFFICE_ID option:selected").text());
            $("#Pr_P_THANA_ID").text($("#THANA_ID option:selected").text());
            $("#Pr_P_UNION_ID").text($("#UNION_ID option:selected").text());
            $("#Pr_P_VILLAGE_WARD").text($("#VILLAGE").val());
        }


           //academic information 
           $("#P_EXAM_NAME_S").text($("#EXAM_NAME_S option:selected").text());
           $("#P_PASSING_YEAR_S").text($("#PASSING_YEAR_S").val());
           $("#P_BOARD_S").text($("#BOARD_S option:selected").text());
           $("#P_GROUP_S").text($("#GROUP_S option:selected").text());
           $("#P_GPA_S").text($("#GPA_S").val());
           $("#P_GPAWA_S").text($("#GPAWA_S").val());
           $("#P_INSTITUTE_S").text($("#INSTITUTE_S").val());

           $("#P_EXAM_NAME_H").text($("#EXAM_NAME_H option:selected").text());
           $("#P_PASSING_YEAR_H").text($("#PASSING_YEAR_H").val());
           $("#P_BOARD_H").text($("#BOARD_H option:selected").text());
           $("#P_GROUP_H").text($("#GROUP_H option:selected").text());
           $("#P_GPA_H").text($("#GPA_H").val());
           $("#P_GPAWA_H").text($("#GPAWA_H").val());
           $("#P_INSTITUTE_H").text($("#INSTITUTE_H").val());

           $("#P_EXAM_NAME_G").text($("#EXAM_NAME_G option:selected").text());
           $("#P_PASSING_YEAR_G").text($("#PASSING_YEAR_G").val());
           $("#P_BOARD_G").text($("#BOARD_G option:selected").text());
           $("#P_GROUP_G").text($("#GROUP_G option:selected").text());
           $("#P_GPA_G").text($("#GPA_G").val());
           $("#P_GPAWA_G").text($("#GPAWA_G").val());
           $("#P_INSTITUTE_G").text($("#INSTITUTE_G").val());

            //others information
            $("#P_ANNUAL_INCOME").text($("#ANNUAL_INCOME").val());
            $("#P_SCHOLARSHIP").text($("input[name='SCHOLARSHIP']:checked").val());
            $("#P_SCHOLARSHIP_DESC").text($("#SCHOLARSHIP_DESC").val());
            $("#P_EXPELLED").text($("input[name='EXPELLED']:checked").val());
            $("#P_EXPELLED_DESC").text($("#EXPELLED_DESC").val());
            $("#P_ARRESTED").text($("input[name='ARRESTED']:checked").val());
            $("#P_ARRESTED_DESC").text($("#ARRESTED_DESC").val());
            $("#P_CONVICTED").text($("input[name='CONVICTED']:checked").val());
            $("#P_CONVICTED_DESC").text($("#CONVICTED_DESC").val());
            $("#P_APPLY_BEFORE").text($("input[name='APPLY_BEFORE']:checked").val());
            $("#P_APPLY_SEMESTER").text($("#APPLY_SEMESTER").val());
            $("#P_APPLY_YEAR").text($("#APPLY_YEAR").val());
            $("#P_SIBLING_EXIST").text($("input[name='SIBLING_EXIST']:checked").val());
            $("#P_SBLN_ROLL_NO").text($("#SBLN_ROLL_NO").val());

            $('#admissionModal').modal({
                show: true
            });

        }else{

        }
    });

    //This function  is use for student image preview before upload
    function upload_img(input) {
        var fileTypes = ['jpg', 'jpeg', 'png', 'gif'];
        if (input.files && input.files[0]) {
        var extension = input.files[0].name.split('.').pop().toLowerCase(),  //file extension from input file
        isSuccess = fileTypes.indexOf(extension) > -1;
        var fsize = $('#propic')[0].files[0].size;
        if (isSuccess) {
            var reader = new FileReader();
            reader.onload = function (e) {
                var image = new Image();
                image.src = reader.result;

                image.onload = function () {
                     
                        $('#img_id').attr('src', e.target.result);
                        $('#p_img_id').attr('src', e.target.result);

                   
                };
            }
            reader.readAsDataURL(input.files[0]);
        }else{
            alert("This file type does not support");
        }
    }
}     
    //This function  is use for student image preview before upload
    function upload_img_sig(input) {
        var fileTypes = ['jpg', 'jpeg', 'png', 'gif'];
        if (input.files && input.files[0]) {
            var extension = input.files[0].name.split('.').pop().toLowerCase(),  //file extension from input file
            isSuccess = fileTypes.indexOf(extension) > -1;
            var fsize = $('#sigpic')[0].files[0].size;
            if (isSuccess) {
                var reader = new FileReader();
                reader.onload = function (e) {
                    var image = new Image();
                    image.src = reader.result;

                    image.onload = function () {
                         
                            $('#sig_id').attr('src', e.target.result);
                            $('#p_sig_id').attr('src', e.target.result);
                         
                    };
                }
                reader.readAsDataURL(input.files[0]);
            } else {
                alert("This file type does not support");
            }
        }
    }

    $(document).on("click", ".same_as_present", function () {
      var same_as_present = $('input[name=same_as_present]:checked').val();

      if(same_as_present == 'YES'){
        $('#permanent_address').find('input, textarea, button, select').attr('disabled',true);
        $('#permanent_address').find('select').val('');
        $('#permanent_address').find('input').val('');
    }else{
        $('#permanent_address').find('input, textarea, button, select').attr('disabled',false);
    }

});
    $(document).on("change", "#DIVISION_ID", function () {
        $("#THANA_ID").val("");
        $("#POLICE_STATION_ID").val("");
        $("#POST_OFFICE_ID").val("");
        $("#UNION_ID").val("");
        var DIVISION_ID = $(this).val();

        $.ajax({
            type: 'POST',
            url: '<?php echo site_url()?>/common/dis_by_div_id',
            data: {DIVISION_ID: DIVISION_ID},
            success: function (data) {
                $("#DISTRICT_ID").html(data)
            }
        });
    });    
    $(document).on("change", "#DEGREE_ID", function () {

        var DEGREE_ID = $(this).val();

        $.ajax({
            type: 'POST',
            url: '<?php echo site_url()?>/common/program_by_degree_id',
            data: {DEGREE_ID: DEGREE_ID},
            success: function (data) {
                $("#PROGRAM_ID").html(data);
                if(DEGREE_ID == 3 || DEGREE_ID == 5){
                    $("#posgraduate_div").toggle();    
                }else{
                    $("#posgraduate_div").show();
                }
                
            }
        });
    });
    $(document).on("change", "#DISTRICT_ID", function () {
        $("#THANA_ID").val("");
        $("#POLICE_STATION_ID").val("");
        $("#POST_OFFICE_ID").val("");
        $("#UNION_ID").val("");
        var DISTRICT_ID = $(this).val();
        $.ajax({
            type: 'POST',
            url: '<?php echo site_url()?>/common/up_thana_by_dis_id',
            data: {DISTRICT_ID: DISTRICT_ID},
            success: function (data) {
                $("#THANA_ID").html(data)
            }
        });

    });
    $(document).on("change", "#THANA_ID", function () {
        var THANA_ID = $(this).val();
        $.ajax({
            type: 'POST',
            url: '<?php echo site_url()?>/common/union_by_thana_id',
            data: {THANA_ID: THANA_ID},
            success: function (data) {
                $("#UNION_ID").html(data)
            }
        });
        $.ajax({
            type: 'POST',
            url: '<?php echo site_url()?>/common/police_station_by_thana_id',
            data: {THANA_ID: THANA_ID},
            success: function (data) {
                $("#POLICE_STATION_ID").html(data)
            }
        });
        $.ajax({
            type: 'POST',
            url: '<?php echo site_url()?>/common/post_office_by_thana_id',
            data: {THANA_ID: THANA_ID},
            success: function (data) {
                $("#POST_OFFICE_ID").html(data)
            }
        });
    });
    $(document).on("change", "#P_DIVISION_ID", function () {
        $("#P_THANA_ID").val("");
        $("#P_POLICE_STATION_ID").val("");
        $("#P_POST_OFFICE_ID").val("");
        $("#P_UNION_ID").val("");
        var DIVISION_ID = $(this).val();

        $.ajax({
            type: 'POST',
            url: '<?php echo site_url()?>/common/dis_by_div_id',
            data: {DIVISION_ID: DIVISION_ID},
            success: function (data) {
                $("#P_DISTRICT_ID").html(data)
            }
        });
    });
    $(document).on("change", "#P_DISTRICT_ID", function () {
        $("#P_THANA_ID").val("");
        $("#P_POLICE_STATION_ID").val("");
        $("#P_POST_OFFICE_ID").val("");
        $("#P_UNION_ID").val("");
        var DISTRICT_ID = $(this).val();
        $.ajax({
            type: 'POST',
            url: '<?php echo site_url()?>/common/up_thana_by_dis_id',
            data: {DISTRICT_ID: DISTRICT_ID},
            success: function (data) {
                $("#P_THANA_ID").html(data)
            }
        });

    });
    $(document).on("change", "#P_THANA_ID", function () {
        var THANA_ID = $(this).val();
        $.ajax({
            type: 'POST',
            url: '<?php echo site_url()?>/common/union_by_thana_id',
            data: {THANA_ID: THANA_ID},
            success: function (data) {
                $("#P_UNION_ID").html(data)
            }
        });
        $.ajax({
            type: 'POST',
            url: '<?php echo site_url()?>/common/police_station_by_thana_id',
            data: {THANA_ID: THANA_ID},
            success: function (data) {
                $("#P_POLICE_STATION_ID").html(data)
            }
        });
        $.ajax({
            type: 'POST',
            url: '<?php echo site_url()?>/common/post_office_by_thana_id',
            data: {THANA_ID: THANA_ID},
            success: function (data) {
                $("#P_POST_OFFICE_ID").html(data)
            }
        });
    });
    $(document).on("click", ".local_emergency_guardian", function () {
        var is_local = $(this).val();
        if (is_local == 'O') {
            $('#local_guardian').show();
            $('#finance_guardian').show();
        } else {
            $('#local_guardian').hide();
            $('#finance_guardian').hide();
        }
    }); 
    $(document).on('click', '#siblin', function () {
        if ($('input[name="SIBLING_EXIST"]:checked').val() == "YES") {
            $('.sibId').show();
        } else {
            $('.sibId').hide();
        }
    });
    $(document).on('click', '#scholarship_id', function () {
        if ($('input[name="SCHOLARSHIP"]:checked').val() == "YES") {
            $('.scholarships').show();
        } else {
            $('.scholarships').hide();
        }
    });
    $(document).on('click', '#expelled_id', function () {
        if ($('input[name="EXPELLED"]:checked').val() == "YES") {
            $('.expelled_div').show();
        } else {
            $('.expelled_div').hide();
        }
    });
    $(document).on('click', '#arrested_id', function () {
        if ($('input[name="ARRESTED"]:checked').val() == "YES") {
            $('.arrested_div').show();
        } else {
            $('.arrested_div').hide();
        }
    });
    $(document).on('click', '#convicted_id', function () {
        if ($('input[name="CONVICTED"]:checked').val() == "YES") {
            $('.convicted_div').show();
        } else {
            $('.convicted_div').hide();
        }
    });
    $(document).on('click', '#apply_before_id', function () {
        if ($('input[name="APPLY_BEFORE"]:checked').val() == "YES") {
            $('.apply_before_div').show();
        } else {
            $('.apply_before_div').hide();
        }
    });

    $('#WEIGHT_KG').on('blur', function () {
        var pound = parseFloat("2.20462");
        var total = ($(this).val() * pound);
        var n = total.toFixed(2);
        $("#WEIGHT_LBS").val(n);

    });
    $('#WEIGHT_LBS').on('blur', function () {
        var kg = parseFloat("0.453592");
        var total = ($(this).val() * kg);
        var n = total.toFixed(2);
        $("#WEIGHT_KG").val(n)
    });
    $('#HEIGHT_FEET').on('blur', function () {
        var cm = parseFloat("30.48");
        var total = ($(this).val() * cm);
        var n = total.toFixed(2);
        $("#HEIGHT_CM").val(n);

    });
    $('#HEIGHT_CM').on('blur', function () {
        var ft = parseFloat("0.0328084");
        var total = ($(this).val() * ft);
        var n = total.toFixed(2);
        $("#HEIGHT_FEET").val(n)
    });
 $( function() {
        $( "#datepicker" ).datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'dd-mm-yy' ,
            yearRange: '1980:2000'
      });
    } );

</script>
