<?php
require_once 'std_header.php';
 //require_once 'stdfunc01.php';
ini_set("display_errors", false);
error_reporting(E_ALL);

// var_dump(end(explode('/', $_SERVER['HTTP_REFERER'])));
// die():
// require_once './include/jquery.includes.php';
if($_POST)
{
    if(end(explode('/', $_SERVER['HTTP_REFERER'])) == 'edit_application.php')
    {
        $formtype = $_POST['formtype'];
    }
    else if(end(explode('/', $_SERVER['HTTP_REFERER'])) == 'terms.php')
    {
        $formtype = $_POST['formtype'];
    }    
    else if(end(explode('/', $_SERVER['HTTP_REFERER'])) == 'main_application.php')
    {
        $formtype = 'edit';
    }
}
else
{
    echo"<script>alertify.alert('SUMISHO ONLINE APPLICATION','Please accept the terms and conditions',function(){window.location='terms.php';}).set({'closable':false,'modal':true});</script>";
}
if(isset($_POST['event_action']) && trim($_POST['event_action']) =='upload')
{

    // echo "<pre>";
    // var_dump($_POST['fileselected']);
    // die();
    $xpersonal = $_POST['txt'];
    $xappcode = $xpersonal['appcode'];

    $xqry = "SELECT * FROM applicantfile WHERE appcode=?";
    $xstmt = $link_id->prepare($xqry);
    $xstmt->execute(array($xappcode));
    $rs = $xstmt->fetch();        
        
    if($_FILES['uploadedfile']['name'] == "")
    {
        $xrec_params =array();
        $xrec_params['emppic']= $_POST['profilepicture'];
        PDO_UpdateRecord($link_id,'applicantfile',$xrec_params,'appcode=?',array($xappcode),false);
    }
    else
    {
        $filename = $_FILES['uploadedfile']['name'];
        $ext = pathinfo($filename, PATHINFO_EXTENSION);
        $target_dir ="application/uploads";
        $target_file = $target_dir . "/PP-".$xappcode."-".$filename;

        if($target_file != $rs['emppic'])
        {
            if (move_uploaded_file($_FILES["uploadedfile"]["tmp_name"], $target_file))
            {
                $xpersonal['emppic']=$target_file;
            }

            $xrec_params =array();
            $xrec_params['emppic']= $xpersonal['emppic'];
            PDO_UpdateRecord($link_id,'applicantfile',$xrec_params,'appcode=?',array($xappcode),false);
        }
    }
}
    


    if( isset($_POST['attach_action']) && trim($_POST['attach_action'])== 'saveatt' )
    {
        $date = date('Y-m-d');
        $par = 'add';
        $recid2 = $_POST['xrecid'];
        $field = $_POST['field'];
        $arr_record = $_POST['field'];
        $arr_record['filepath'] =$_POST['filepath'];
        $arr_record['filename'] = $_FILES['attachfile']['name'];
        $arr_record['appcode'] =$xappcode;
        $arr_record['doccode'] = $_POST['doccode'];
        $arr_record['dte'] = $date;
        $arr_record['dsc'] = $_POST['description'];

        $xfield['dte']= 'Applicant Document Attach Date';
        $xfield['doccode']= 'Applicant Document Attach Code';
        $xfield['filename']= 'Applicant Document Attachment File';
        $xfield['dsc']= 'Applicant Document Attachment Description';
        
        $recid = $_POST['item_id'];
        $xusrcde1 = ($_SESSION[$xg_appkey]['usrcde']);
        $xfullname1 = ($_SESSION[$xg_appkey]['fullname']);
        $xtablename1 = 'applicantattachments';
        $xprogmodule1 = "Applicant Attachment";
        $xsuccess1 = true;
        $xwebpage1 = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
        
        $xbool=true;
        $xqry="SELECT * FROM applicantattachments";
        $xstmt=$link_id->prepare($xqry);
        $xstmt->execute();
        while($xrs=$xstmt->fetch())
        {
         //~ var_dump($recid2);
            if($arr_record['filename']==$xrs['filename'] && $recid2!=$xrs['recid'])
            {
                $xbool=false;
            }   
        }
        
        if($xbool)
        {
            if( $_POST['attachtype'] == 'add' )
            {   
                foreach ($_POST['attach'] as $key => $value)
                {
                    $filename = $_FILES['uploadedfile']['name'];
                    $ext = pathinfo($filename, PATHINFO_EXTENSION);
                    $target_dir ="application/employeeattachments";
                    $target_file = $target_dir . "/AT-".$xappcode."-".$filename;
                    if (move_uploaded_file($_FILES["uploadedfile"]["tmp_name"], $target_file))
                    {
                        $value['appcode'] = $xappcode;
                        $value['dte'] = $date;
                        $value['filename'] = $_FILES['attachfile']['name'][$key];
                        if($value['filename'] != '')
                        {
                            PDO_InsertRecord($link_id,'applicantattachments',$value,false);    
                        }
                    }
                    
                }
                $xaction1 = "Add";
                $xactivity1 = "Add Applicant Attachment";
                $xremarks1 = "Add Applicant Attachment : ".$arr_record['filename'];
                PDO_UserActivityLog($link_id, $xtablename1 , $xfullname1 , $xusrcde1 , $xactivity1 , $xremarks1, $xwebpage1, $xaction1, $xprogmodule1 , $xsuccess1,$xnewval,$xoldval,$xhead);       
            }
            else if($_POST['attachtype'] == 'edit')
            {
                foreach ($_POST['attach'] as $key => $value) {
                    $xrecid = $value['recid'];
                    unset($value['recid']);
                    // var_dump($value['dsc']);
                    $value['appcode'] = $xappcode;
                    $value['dte'] = $date;
                    $value['filename'] = $_FILES['attachfile']['name'][$key];
                    if($value['filename'] == '')
                    {       
                        unset($value['filename']);
                    }
                    PDO_UpdateRecord($link_id,'applicantattachments', $value,'recid=?', array($xrecid),false);
                };
            }
        }
        else
        {
            echo "<script>alertify.alert('This file already exist. Rename or upload other file!').set({'closable':false,'modal':true});</script>";
            //~ echo "<script>alert('This file already exist. Rename or upload other file');</script>";
        }

        
        echo "<script>refresh_page();</script>";
    }
?>


<!-- <head>
<title><?php echo $AppTitle; ?></title> -->

<!-- <script type='text/javascript' src="./javascript/jquery.scrollTo.min.js"></script> -->
<style>


input[type=text]
/*{
    text-transform: capitalize !important;
}*/
/*::-webkit-scrollbar {
    -webkit-appearance:unset !important;
}*/
body::-webkit-scrollbar {
    width: .7em;
}
body::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
}
 
body::-webkit-scrollbar-thumb {
  background-color: #00007f;
  outline: 1px solid slategrey;
}
body 
{
    overflow: unset !important;
}
table td {
    text-transform: uppercase;
    vertical-align: middle;
}
table tr td:not(:first-child) {
    text-align: right;
}
table td input
table td select {
    vertical-align: middle;
}
table.otherinfo tr td {
    text-align: left;
}

.cam_btn_con {
    width: 100%; height: 50px;
    background: #00128d;
    z-index: 100;
    cursor: pointer;

    position: absolute;
    top: 0; right: 0;
}
.cam_btn_con i {
    font-size: 43px;
    color: #ddd;
    float: left;
    margin: 3px 0 0 6px;
    vertical-align: middle;
}
.cam_btn_con label {
    float: left;
    color: #ddd;
    margin: 17px 0 0 7px;
    cursor: pointer;
}
.my_camera_con {
    width: 500px; height: 420px;
    z-index: 1200;
    background: #00128d;
    box-shadow: 0 2px 4px rgba(0,0,0,0.8);

    position: absolute;
    margin: 0 auto;
    top: 100px;
    left: 0; right: 0;
}
.my_camera_con #my_camera {
    width: 98%;
    margin: 60px auto 0;
    /*background: blue;*/
}
._close_btn {
    width: 40px; height: 40px;
    /*background: red;*/
    color: #fff;
    position: absolute;
    top: 10px; right: 10px;
}
._close_btn i {
    font-size: 41px;
    color: #fff;
    cursor: pointer;

    transition: all 0.3s;
}
._close_btn i:hover {
    color: #ddd;
}
.shot_btn {
    padding: 5px 12px;
    background: #fff;
    color: black !important;
    font-size: 12px;
    font-weight: 600;
    position: absolute;
    top: 21px;
    left: 10px;

    transition: all 0.3s;

    transform: scaleY(1.15);
}

#label_save {
    padding: 5px 12px;
    /*background: #fff;*/
    color: #fff !important;
    font-size: 12px;
    font-weight: 600;
    position: absolute;
    top: 21px;
    left: 10px;

    transition: all 0.3s;
    transform: scaleY(1.15);
}

#yes_btn {
    padding: 5px 12px;
    background: #fff;
    color: black !important;
    font-size: 12px;
    font-weight: 600;
    position: absolute;
    top: 21px;
    left: 140px;

    transition: all 0.3s;
    transform: scaleY(1.15);
}

#no_btn {
    padding: 5px 12px;
    background: #fff;
    color: black !important;
    font-size: 12px;
    font-weight: 600;
    position: absolute;
    top: 21px;
    left: 190px;

    transition: all 0.3s;
    transform: scaleY(1.15);
}

#t_s{
    display: none;
}

#label_loading
{
    display: none;
    margin:0 auto;

    color: #fff !important;
    width: 50%;
    font-weight: 600;

    position: absolute;
    left: 0;
    right: 0;
    top: 200px;
    font-size: 20px;
    text-align: center;
}

.shot_btn:hover,.save_yes_no_btn:hover {
    text-decoration: none;
    background: #ddd;
}

.save_yes_no
{
    display:none;
}

 .ui-datepicker-unselectable.ui-state-disabled span
 {
    background-color: #ffffff;
    color: #ffffff;
    display: none;
 }

</style>
    
<script type="text/javascript">
    var ctr= 0;
    var ctr1= 0;
    var ctr2= 0;
    var ctr3 = 0;
    var ctr4 = 0;
    var ctr5 = 0;
    var ctr6 = 0;
    var ctr7 = 0;
    var ctr8 = 0;
    var ctr9 = 0;
    var ctr10 = 0;
    var ctr11 = 0;
    var ctr12 = 0;
    var ctr13 = 0;
    var ctr14 = 0;
    var ctr15 = 0;

    jQuery(document).ready(function(){

        //show table with values
        jQuery('.hiddentable').each(function(){
            if(jQuery(this).find('tbody').find('tr').length == 0)
            {
                jQuery(this).hide();
            }    
        })
        // console.log(jQuery('.hiddentable').find('tbody').find('tr').length);
        

        jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            $("#height").inputmask({"mask": "9''9"});
            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });

        $('body').on('change','.val_sel_group',function()
        {

            var sel_group = $(this).data('sel_group');  
            
            $('select[data-sel_group="'+sel_group+'"] option').show();
            // console.log($('select[data-sel_group="'+sel_group+'"]').length);
            $('select[data-sel_group="'+sel_group+'"]').each(function()
            {
                $('select[data-sel_group="'+sel_group+'"] option[value="'+$(this).val()+'"]').hide();
                console.log($(this).val());
                $(this).val($(this).val());

            })
        })

        $("#fileuploadbtn").change(function() 
        {
            var sizeinbytes = document.getElementById('fileuploadbtn').files[0].size;

            var pause=0;

            if(sizeinbytes>=2000000)
            {
                alert('File is must be less than    !');
                return false 
            }
            
            var ext = $('#fileuploadbtn').val().split('.').pop().toLowerCase();
            if($.inArray(ext, ['png','jpg','jpeg']) == -1) 
            {
                alert('File type must be JPG or PNG');
                return false;
            }

            if( $("#fileuploadbtn")[0].files.length == 0 )
            {
                alert('No files selected');
                return false;
            }
            else
            {
                $('#via_webcam').val(0);
                $('#via_webcam_path').val("");

                var file = this.files[0];
                var reader = new FileReader();
                reader.onload = function(e)
                {
                    $('#img_cover_image').attr('src',e.target.result);
                };
                reader.readAsDataURL(file);
            }
        });

        jQuery('#cam_btn_con').click(function()
        {
            jQuery('.my_camera_con').show(500);
            jQuery('._menu_overlay').fadeIn(200);
            jQuery('body').css('overflow','hidden');
        });

        jQuery('._close_btn').click(function(){
            jQuery('.my_camera_con').hide(500,function()
                {
                    Webcam.reset();
                    Webcam.attach( '#my_camera' );

                    $('#t_s').hide();
                    $('.save_yes_no').hide();
                });
            jQuery('._menu_overlay').fadeOut(200);
            jQuery('body').css('overflow','auto');

        });

        jQuery('.af_fld').dbFldLen({
            link_id:'link_id',
            tablename:'applicantfile',
            ajaxPage:'db_field_length_checker_ajax.php'
        });

        jQuery('.ae_fld').dbFldLen({
            link_id:'link_id',
            tablename:'applicantextension',
            ajaxPage:'db_field_length_checker_ajax.php'
        });

        jQuery('.as_fld').dbFldLen({
            link_id:'link_id',
            tablename:'applicantfilesub',
            ajaxPage:'db_field_length_checker_ajax.php'
        });

        jQuery('.ar_fld').dbFldLen({
            link_id:'link_id',
            tablename:'appempreffile',
            ajaxPage:'db_field_length_checker_ajax.php'
        });



        
    });

    jQuery(window).load(function()
    {
    if(location.protocol == 'https:')
    {
        navigator.getMedia = ( navigator.webkitGetUserMedia || //use the proper vendor prefix
                   navigator.mozGetUserMedia ||
                   navigator.msGetUserMedia);

        if (navigator.getMedia) 
        { 
           navigator.getMedia({video:true}, function()
            {
                Webcam.set({
                    width: 480,
                    height: 340,
                    dest_width: 640,
                    dest_height: 480,
                    image_format: 'jpeg',
                    jpeg_quality: 90,
                    force_flash: false,
                    flip_horiz: true,
                    fps: 45
                });
            
                Webcam.attach( '#my_camera' );
                Webcam.on( 'live', function() {

                        jQuery('#t_s').show();   
                } );

                var camera_con=jQuery('#my_camera_con').detach();

                jQuery('#myform').append(camera_con);

                jQuery('#cam_btn_con').show();

            }, 
            function(e)
            {
                console.log(e);
            });
        } 
    }
    });


    function fileuploadclick()
    {
        $('#fileuploadbtn').click();
    }


    function resetpicclick()
    {
        $("#img_cover_image").attr('src','images/def_profilepic.png');
        jQuery('#profilepicture').val('images/def_profilepic.png');
        $('#fileuploadbtn').val("");
        $('#via_webcam_path').val("");
        $('#via_webcam').val(0);
    }

    function take_snapshot() 
    {
        Webcam.freeze();

        $('#t_s').hide();
        $('.save_yes_no').show();
    }

    function save_snapshot()
    {
        $('#my_camera').hide();
        Webcam.snap( function(data_uri) {
            $('.save_yes_no').hide();
            $('#label_loading').show();
            $('#img_cover_image').attr('src',"./images/progress.gif");
                // document.getElementById('my_result').innerHTML = '<img src="'+data_uri+'"/>';

            // var url='webcam_upload.php?webcam=yes&empcode='+$('#txtempcode').val()+"&par="+par;
            var url='proc_upload_cover.php?webcam=yes&empcode='+$('#hid_appcode').val()+"&par=app";
            Webcam.upload( data_uri, url, function(code, text) 
            {
                // Upload complete!
                // 'code' will be the HTTP response code from the server, e.g. 200
                // 'text' will be the raw response content
            } );

            Webcam.on( 'uploadComplete', function(code, upload_path) {
                // alert(text);
                // Upload complete!
                // 'code' will be the HTTP response code from the server, e.g. 200
                // 'text' will be the raw response content
                $('#via_webcam').val(1);
                $('#via_webcam_path').val(upload_path);
                $('#img_cover_image').attr('src',upload_path+"?" + new Date().getTime());
                $('#fileuploadbtn').val("");
                $('#label_loading').hide();
                $('#my_camera').show();

            } );
        } );

        Webcam.reset();
        Webcam.attach( '#my_camera' );
        $('#t_s').hide();
    }

    function cancel_snapshot()
    {
        Webcam.reset();
        Webcam.attach( '#my_camera' );

        $('#t_s').hide();
        $('.save_yes_no').hide();
    }

    function addRow()
    {   
        var row_limit = jQuery('#reference').data('row_limit');
        if(jQuery('#reference').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('Can only add 3 reference persons');
            return false;
        }
        var xparams ="&event_action=addrel&pctr="+ctr;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#reference').show();
                jQuery('#reference').append(res);
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });
                jQuery('.appref_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'appempreffile',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#reference').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function addSkill()
    {   
        ctr1++;
        var row_limit = jQuery('#skills').data('row_limit');
        if(jQuery('#skills').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('aa');
            return false;
        }
        var xparams =jQuery('#skills *').serialize()+"&event_action=addskill&pctr1="+ctr1;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#skills').show();
                jQuery('#skills').append(res);
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });
                jQuery('.appskill_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'applicantskills',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#skills').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }
    function addEduc()
    {   
        var row_limit = jQuery('#educ').data('row_limit');
        if(jQuery('#educ').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('aa');
            return false;
        }
        var xparams ="&event_action=addeduc&pctr2="+ctr2;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#educ').show();
                jQuery('#educ').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });
                jQuery('#educ').find('.val_sel_group').change();

                jQuery('.appeduc_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'applicantschool',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
                
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function addSiblings()
    {   
        var row_limit = jQuery('#siblings').data('row_limit');
        if(jQuery('#siblings').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('Can only add 5 siblings');
            return false;
        }
        var xparams ="&event_action=addsiblings&pctr="+ctr3;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#siblings').show();
                jQuery('#siblings').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });

                jQuery('.appsib_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'applicantsiblings',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });
                
                jQuery('#siblings').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function addChildren()
    {   
        var row_limit = jQuery('#children').data('row_limit');
        if(jQuery('#children').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('aa');
            return false;
        }
        var xparams ="&event_action=addchildren&pctr="+ctr4;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#children').show();
                jQuery('#children').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });

                jQuery('.appchild_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'applicantchildren',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#children').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function addGuardian()
    {   
        var row_limit = jQuery('#guardian').data('row_limit');
        if(jQuery('#GUARDIAN').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('aa');
            return false;
        }
        var xparams ="&event_action=addguardian&pctr="+ctr5;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#guardian').show();
                jQuery('#guardian').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });

                jQuery('.appguard_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'applicantotherrelations',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#guardian').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function addRelative()
    {   
        var row_limit = jQuery('#relatives').data('row_limit');
        if(jQuery('#relatives').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('Can only add 5 relatives');
            return false;
        }
        var xparams ="&event_action=addrelative&pctr="+ctr6;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#relatives').show();
                jQuery('#relatives').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });
                jQuery('.apprel_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'applicantrelincompfile',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#relatives').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function addLanguage()
    {   
        var row_limit = jQuery('#languages').data('row_limit');
        if(jQuery('#languages').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('Can only add 5 languages');
            return false;
        }
        var xparams ="&event_action=addlanguage&pctr="+ctr7;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {         
                jQuery('#languages').show();
                jQuery('#languages').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });

                jQuery('.applang_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'emplangfile',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#languages').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });

                // jQuery('.val_sel_group').change();          
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }
    function refresh_page()
    {   
        document.forms.myform.target = '_self';
        document.forms.myform.action = 'main_application.php';
        document.forms.myform.submit();
    }


    function addAward()
    {   
        var row_limit = jQuery('#awards').data('row_limit');
        if(jQuery('#awards').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('Can only add 5 awards');
            return false;
        }
        var xparams ="&event_action=addaward&pctr="+ctr8;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#awards').show();
                jQuery('#awards').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });

                jQuery('.appaward_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'applicantaward',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#awards').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function addCert()
    {   
        var row_limit = jQuery('#certifications').data('row_limit');
        if(jQuery('#certifications').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('Can only add 5 certifications');
            return false;
        }
        var xparams ="&event_action=addcert&pctr="+ctr9;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#certifications').show();
                jQuery('#certifications').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });

                jQuery('.appcert_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'applicantcertificate',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#certifications').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function addSem()
    {   
        var row_limit = jQuery('#seminars').data('row_limit');
        if(jQuery('#seminars').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('Can only add 5 seminars');
            return false;
        }
        var xparams ="&event_action=addsem&pctr="+ctr10;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#seminars').show();
                jQuery('#seminars').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });

                jQuery('.appsem_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'applicantseminar',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#seminars').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function addExp()
    {   
        var row_limit = jQuery('#experience').data('row_limit');
        if(jQuery('#experience').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('Can only add 5 work experiences');
            return false;
        }
        var xparams ="&event_action=addexp&pctr="+ctr11;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#experience').show();
                jQuery('#experience').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });

                jQuery('.appexp_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'applicantrecord',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#experience').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function addMem()
    {   
        var row_limit = jQuery('#membership').data('row_limit');
        if(jQuery('#membership').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('Can only add 5 memberships');
            return false;
        }
        var xparams ="&event_action=addmem&pctr="+ctr12;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#membership').show();
                jQuery('#membership').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });

                jQuery('.appmem_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'employeemembership',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#membership').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function addImmigration()
    {   
        var row_limit = jQuery('#immigration').data('row_limit');
        if(jQuery('#immigration').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('Can only add 2 documents');
            return false;
        }
        var xparams ="&event_action=addimmigration&pctr="+ctr13;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#immigration').show();
                jQuery('#immigration').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });

                jQuery('.appimmi_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'employeeimmigrationfile',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#immigration').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function addRequirement()
    {   
        var row_limit = jQuery('#requirements').data('row_limit');
        if(jQuery('#requirements').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('Can only add 5 requirements');
            return false;
        }
        var xparams ="&event_action=addrequirement&pctr="+ctr14;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#requirements').show();
                jQuery('#requirements').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });

                jQuery('.appreq_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'applicantrequirementsfile',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#requirements').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function addLicense()
    {   
        var row_limit = jQuery('#licenses').data('row_limit');
        if(jQuery('#licenses').find('tbody').find('tr').length+1 > row_limit)
        {
            alert('Can only add 5 licenses');
            return false;
        }
        var xparams ="&event_action=addlicense&pctr="+ctr15;
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                jQuery('#licenses').show();
                jQuery('#licenses').append(res);
                jQuery('.datepicker').datepicker({dateFormat:'mm-dd-yy'});
                $('.numeric').on('input', function (event) { 
                    this.value = this.value.replace(/[^0-9.]/g, '');
                });

                jQuery('.applic_fld').dbFldLen({
                    link_id:'link_id',
                    tablename:'applicantlicenses        ',
                    ajaxPage:'db_field_length_checker_ajax.php'
                });

                jQuery('#licenses').find('.val_sel_group').change();

                jQuery('.datepicker').datepicker({
                    dateFormat:'mm/dd/yy',
                    changeMonth: true,
                    changeYear: true
                });

            $.datepicker.setDefaults({
               dateFormat:'mm/dd/yy',
               changeMonth: true,
               changeYear: true
            })

             $('.numeric').on('input', function (event) 
             {
                this.value = this.value.replace(/[^0-9.]/g, '');
             });

            jQuery('.datepicker').inputmask({ alias: "mm/dd/yyyy"});

            jQuery('.datepicker').on('blur',function()
            {
                if(!isValidDate($(this).val()) && $(this).val()!="")
                {
                    $(this).val("");
                    alert('Invalid Date');
                }
            });
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function deleteRow(obj, tablename, recid)
    {       
            var xparams ="&event_action=deleteRow&ptablename="+tablename+"&precid="+recid;
            jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                alertify.confirm('Are you sure you want to delete this row?',function()
                {
                    // var tr=$(obj);
                    
                    // tr.remove(); 
                    var tablename = jQuery(obj).closest('table'); 
                    var tbody = jQuery(obj).closest('tbody');

                    jQuery(obj).closest('tr').remove();
                    
                    if(tbody.find('tr').length == 0)
                    {   
                        tablename.hide();
                    }

                })
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })  
    }

    function deleteAttach(obj, recid)
    {       
            var xparams ="&event_action=deleteAttach&precid="+recid;
            jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {                       
                alertify.confirm('Are you sure you want to delete this attachment?',function()
                {
                     
                    jQuery(obj).closest('input').empty();

                })
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })  
    }

    function get_age()
    {
        var dob = jQuery('#bday').val();
        dob = new Date(dob);
        // alert(dob);
        var today = new Date();
        var age = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
        jQuery('#age').val(age);
    }

    function get_agesibling()
    {
        var dob = jQuery('#siblingbday').val();
        dob = new Date(dob);
        // alert(dob);
        var today = new Date();
        var age = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
        jQuery('#siblingage').val(age);
    }

    function get_agechild()
    {
        var dob = jQuery('#childbday').val();
        dob = new Date(dob);
        // alert(dob);
        var today = new Date();
        var age = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
        jQuery('#childage').val(age);
    }

    //  function validate(){
    //     var isValid = true;
    //     jQuery('.required').each(function(key,val) {
    //     // console.log(key,val);
        

    //         if ($.trim($(this).val()) == ''||$.trim($(this).val()) == 00) {
    //             isValid = false;
    //             $(this).css({
    //                 "border": "1px solid red",
    //                 "background": "#FFCECE"
    //             });
    //         }
    //         else {
    //             $(this).css({
    //                 "border": "",
    //                 "background": ""
    //             });
    //         }
    //     });

    //     var xdate1 = new Date((jQuery('#datestart').val()));
    //     var xdate2 = new Date((jQuery('#dateend').val()));
    //     var xdate3 = new Date(jQuery('#yrgrad').val());
    //     var xtoday = new Date();

    //     if (isValid == false)
    //     {
    //         alert('Please Fill All fields');
    //         // document.myform.lname.focus();
    //     }
    //     else
    //     {
    //         if( xdate1.getTime() > xdate2.getTime() )
    //         { 
    //             alert('Educational Date End must be later than Date Start');
    //             jQuery('#datestart').css({
    //                 "border": "1px solid red",
    //                 "background": "#FFCECE"
    //             }),
    //             jQuery('#datestartend').css({
    //                 "border": "1px solid red",
    //                 "background": "#FFCECE"
    //             });

    //         }
    //         if( xtoday.getTime() <= xdate3.getTime())
    //         {
    //             alert('Year Graduated must be earlier than today');
    //             jQuery('#yrgrad').css({
    //                 "border": "1px solid red",
    //                 "background": "#FFCECE"
    //             });
    //         }
    //         else
    //         {
    //             save_click();
    //         }
    //     }
    // }
     
     function save_click()
    {
        // jQuery('#fileselected').val(document.getElementById('img_cover_image').getAttribute('src'));
        // var a = jQuery('#img_cover_image').attr("src");
        // jQuery('#profilepicture').attr("value", a);
        var xparams = jQuery('#myform *').serialize()+"&event_action=save";
        jQuery.ajax({
            url: 'main_application_ajax.php',
            type:'post',
            dataType:'json',
            data:xparams,
            success:function(res)
            {       
                if(res == "Record Saved!!")
                {
                    alert(res);
                    jQuery('#event_action').val('upload');
                    jQuery('#attach_action').val('saveatt');
                    jQuery("#btnadd").click();
                    document.forms.myform.target = '_self';
                    document.forms.myform.action ='main_application.php';
                    document.forms.myform.submit();
                }
                else
                {
                    alert(res);
                }
            },
            error:function(e)
            {
                console.log(e,'error');
            }
        })
    }

    function exit_click()
    {
        document.forms.myform.target = '_self';
        document.forms.myform.action ='index.php';
        document.forms.myform.submit();
        // return true;

    }

    function refresh_attachfile(par_name,par_file)
    {  
        
        var xpath = jQuery('#xcwd').val() + par_file.substring(1);
        console.log(par_name);
        document.getElementById('txt_filename').value= par_name;
    }
    
    function upload_attachfile()
    {
        // console.log(jQuery('#description').val());
        
        document.forms.myform.target = 'ifrmupload2';
        document.forms.myform.action = 'proc_asset_upload.php?par=employeeattachments';
        // document.forms.myform.method = 'get';
        document.forms.myform.submit();
    }
    function viewform(par)
    {
            console.log(par);
            jQuery("#btnadd").attr({
                "value": "Save",
                "onclick":"saveattach_click('"+par+"')"
            });
            jQuery("#btnexit").css("display", "");
            jQuery("#viewtable").css("display", "");

    }
    function saveattach_click(par)
    {
        console.log(par);
        jQuery('#xaction').val(par);
        document.forms.myform.xaction.value = par;
        console.log(jQuery('#xaction').val());
        document.forms.myform.attach_action.value = 'saveatt';
        document.forms.myform.target = '_self';
        document.forms.myform.action = 'main_application.php';
        document.forms.myform.submit();      
    }

    
</script>
<style>
fieldset { 
    margin-left: 10px;
    margin-right: 10px;
    padding-top: 0.35em;
    padding-bottom: 0.625em;
    padding-left: 0.75em;
    padding-right: 0.75em;
    /*border: 2px groove (internal value);*/
}
input[type=text]
/*{
    text-transform: capitalize !important;
}*/
/*::-webkit-scrollbar {
    -webkit-appearance:unset !important;
}*/
body::-webkit-scrollbar {
    width: .7em;
}
body::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
}
 
body::-webkit-scrollbar-thumb {
  background-color: #00007f;
  outline: 1px solid slategrey;
}
body 
{
    overflow: unset !important;
}
table td {
    text-transform: uppercase;
    vertical-align: middle;
}
table tr td:not(:first-child) {
    text-align: right;
}
table td input
table td select {
    vertical-align: middle;
}

</style>
<?php


if($formtype == 'add')
{
    $xdocnum = sysparlock('syspar','appcodedocnum', 'appdocnumlock');

    do{
        $xdocnum =  sysparlock('syspar','appcodedocnum', 'appdocnumlock');
    }

    while($xdocnum['islock']);

    lockunlock_docnum('syspar', 'appdocnumlock', 1);

    $next_docnum =  LNexts($xdocnum['appcodedocnum']);
    $xqry  = "UPDATE syspar SET appcodedocnum = ?";
    $stmt = $link_id->prepare($xqry);
    $stmt->execute(array($next_docnum));

    lockunlock_docnum('syspar', 'appdocnumlock', 0);

    $xappcode=$xdocnum['appcodedocnum'];
}
else
{
    $xappcode = $_POST['txt']['appcode'];
    $sql = "SELECT * FROM applicantfile WHERE appcode=?";
    $stmt = $link_id->prepare($sql);
    $stmt->execute(array($xappcode));
    $rs_app = $stmt->fetch();

    $sql1 = "SELECT * FROM applicantextension WHERE appcode=?";
    $stmt1 = $link_id->prepare($sql1);
    $stmt1->execute(array($xappcode));
    $rs_ext = $stmt1->fetch();

    $sql2 = "SELECT * FROM applicantfilesub WHERE appcode=?";
    $stmt2 = $link_id->prepare($sql2);
    $stmt2->execute(array($xappcode));
    $rs_sub = $stmt2->fetch();

// echo "<pre>";
//     var_dump($rs_ext);
//     die();
}

// var_dump($xappcode);

$disable="hidden";
$type="button";

    
        
?>
</head>

<body>
    
    <!-- <form name='myform' method='post' id='myform' > -->
        <div class='my_camera_con' style=" display:none" id="my_camera_con">
            <input type = "hidden" name = "attach_action" id = "attach_action" value="">
            <input type = "hidden" name = "formtype" id = "formtype" value="">
            <input type = "hidden" name = "fileselected" id = "fileselected" value="">

            <input type='hidden' name='xaction' id='xaction' value='' />

            <div id="my_camera"></div>
            <div id="my_result"></div>

            <label id='label_save' class="save_yes_no"> Save snapshot ? </label>

            <div id='label_loading'> Please wait while file is uploading... </div>

            <a href="javascript:void(save_snapshot())" id="yes_btn"  class="save_yes_no save_yes_no_btn">Yes</a>
            <a href="javascript:void(cancel_snapshot())" id="no_btn"  class="save_yes_no save_yes_no_btn">No</a>

            <div class='_close_btn'>
                <i class="fa fa-times-circle" aria-hidden="true"></i>
            </div>

            <a href="javascript:void(take_snapshot())" class="shot_btn" id="t_s">Take Snapshot</a>
        </div>

        <input type="hidden" name="img_action"></input>
        <input type="hidden" id="uploadstatus" value="0">
        <input type="hidden" id="via_webcam" name="via_webcam" value="0">
        <input type="hidden" id="via_webcam_path" name="via_webcam_path" value="">
        
        
           <center>
    <div style="width:30%;display:inline-block;">
        <div style="height:auto;border-radius:5px;width:200px;height:200px;overflow:hidden;">
            <div id="img-container" >
                <img id='img_cover_image' width='100%' height='100%' <?php if($formtype == 'add'){echo "src = 'images/def_profilepic.png'";}else{
                    echo "src='".$rs_app['emppic']."'";}?>
                style='width:100%;height:100%;overflow:hidden' title="Profile Picture" > <?php if($formtype== 'add'){echo "<input type='hidden' id='profilepicture' name='profilepicture' value='images/def_profilepic.png'>";}else{echo "<input type='hidden' id='profilepicture' name='profilepicture' value='".$rs_app['emppic']."'>";}?>
            </div>
        </div>
        <br>
        <center>
            <input type="button" value="Reset Picture" onclick="resetpicclick()" class="exit" style="height:30px">
            <input type="button" value="Upload" onclick="fileuploadclick()" class="save" style="height:30px">
            <input type="button" value="Webcam" class="save" style="height:30px;display:none;" id="cam_btn_con">
            <input accept=".jpg, .png, .jpeg, .bmp" type='file' name='uploadedfile' id="fileuploadbtn" style="display:none;" /><!-- class = 'class_disable' -->
        </center>
    </div>
<br>
<br>
<center>
<table width='90%' border=0  style='font-size:13px;font-weight:bold'>
	<tr>
	<td width='40px'>Position Applied 1 :</td>
	<td width='100px'>
		<select class='input required val_sel_group' data-db_col="first_prior" data-sel_group='pos_sel_grp' name='txtxt[first_prior]'>
            <?php
            $xfilter =  'OPEN';
               echo ListOption2_pdo($link_id,'jobvacancyfile','jobtitle','jobdsc',$rs_ext['first_prior'],"WHERE status =? ",array($xfilter),true);
            ?>
		</select>
	</td>
   <td width='100px'></td>
	<td width='100px' align='right'>Application Number : <b style='font-size:20px'><?php if($formtype =='add'){echo"AUTO GENERATED";}else{echo $xappcode;} ?></b>
        <input type='hidden' class='input' name='txt[appcode]' value='<?php echo $xappcode ?>'>
    </td>
	</tr>
    <tr>
    <td width='40px'>Position Applied 2 :</td>
    <td width='100px'>
        <select class='input required val_sel_group' data-db_col="second_prior" data-sel_group='pos_sel_grp' name='txtxt[second_prior]'>
            <?php
            $xfilter =  'OPEN';
               echo ListOption2_pdo($link_id,'jobvacancyfile','jobtitle','jobdsc',$rs_ext['second_prior'],"WHERE status =? ",array($xfilter),true);
            ?>
        </select >
    </td>
    </tr>
    <tr>
    <tr>
        <td></td>
    </tr>

    <td width='40px'>Position Applied 3 :</td>
    <td width='100px'>
        <select class='input required val_sel_group' data-db_col="third_prior" data-sel_group='pos_sel_grp' name='txtxt[third_prior]'>
           <?php
            $xfilter =  'OPEN';
               echo ListOption2_pdo($link_id,'jobvacancyfile','jobtitle','jobdsc',$rs_ext['third_prior'],"WHERE status =? ",array($xfilter),true);
            ?>
        </select>
    </td>
    </tr>
</table>
</center>
<br>
<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'><h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>PERSONAL DATA</h3>
</header>
</br>
</center>
<center>
    <div>
        <center><table  style="border:0px;width:95%;font-weight:bold;" class='hoverTable disabled_container'>
        <tr>
            	<td width="10%">Last Name : </td>
            	<td width="18%"><input type='text' class='input required af_fld' data-db_col="lname" name='txt[lname]' value="<?php echo $rs_app['lname']; ?>"></td>    
            	<td width="9%">First Name : </td>
            	<td width="15%"><input type='text' class='input required af_fld' data-db_col="fname" name='txt[fname]' value="<?php echo $rs_app['fname']; ?>"></td>
            	<td width="10%">Middle Name : </td>
            	<td width="15%"><input type='text' class='input required af_fld' data-db_col="mname" name='txt[mname]' value="<?php echo $rs_app['mname']; ?>"></td>
                <td width="8%">Nickname : </td>
                <td width="15%"><input type='text' class='input required af_fld' data-db_col="nickname" name='txt[nickname]' value="<?php echo $rs_app['nickname']; ?>"></td>
        	</tr>
        	<tr>
                <td>BIRTHDATE : </td>
                <td><input type='text' class='input required datepicker af_fld' data-db_col="birthdate" id='bday' name='txt[birthdate]' placeholder="mm/dd/yyyy" oninput='get_age()' value="<?php echo display_date($rs_app['birthdate']); ?>"></td>
            	<td>AGE : </td>
            	<td><input readonly class='input numeric af_fld' data-db_col="age" id='age' name='txt[age]' value="<?php echo $rs_app['age']; ?>"></td>
            	<td align="right">Gender :</td>
            	<td>
                    <?php

                    if(strtoupper($rs_app['sex']) == 'MALE')
                    {
                        $optionmale = 'selected'; 
                    }
                    else if(strtoupper($rs_app['sex']) == 'FEMALE')
                    {
                        $optionfemale = 'selected';
                    }

                    ?>
                    <select class='input required' data-db_col="sex" name='txt[sex]'>
                    <option></option>
                		<option <?php echo $optionmale; ?> value='male'>MALE</option>
                		<option <?php echo $optionfemale; ?> value='female'>FEMALE</option>
                   </select>
            	</td>
            	<td>Status : </td>
            	<td>
                   <select class='input required' data-db_col="civilstatus" name='txt[civilstatus]'>
                    <option></option>
                	<?php
                        $xcivilstat = array("SINGLE", "MARRIED", "WIDOWED");

                        for($i = 0; $i<count($xcivilstat); $i++)
                        {
                            $xstate = strtoupper($rs_app['civilstatus'])==$xcivilstat[$i] ? "selected":"";
                            echo "<option {$xstate}>{$xcivilstat[$i]}</option>";
                        }
                    ?>
                   </select>
            	</td>
        	</tr>
            <tr>
                <td>Birthplace : </td>
                <td><select class='input required' data-db_col="birth_prov" id='birthplace' name='txt[birth_prov]'>
                    <option hidden selected></option>
                <?php
                    ListOption_pdo($link_id,'provincefile','provcty',$rs_ext['placeofbirth'],'',$xfilter_pager_fields,false);
                ?>
                </select>
                </td>
                <td>City : </td>
                <td><select class='input required' data-db_col="citycde" id='birthplace' name='txt[citycde]'>
                    <option hidden selected></option>
                <?php
                    ListOption_pdo($link_id,'cityfile','citycde',$rs_app['citycde'],'',$xfilter_pager_fields,false);
                ?>
                </select>
                </td>
                <td>RELIGION:</td>
                <td>
                    <select name='txt[religion]' class=' input' data-db_col="religion" >
                        <option></option>
                        <?php
                            // ListOption_pdo($link_id,'religionfile','religion',$rs_app['religion'],'',$xfilter_pager_fields,false);
                            ListOption0_pdo($link_id,'religionfile','religion','religion',$rs_app['religion'],false);
                        ?>
                    </select>
                </td>
                <td >CITIZENSHIP:</td>
                <td id='fld2'>
                    <select name='txt[natcde]' class ='input class_disable input' data-db_col='natcde'>
                        <option></option>
                        <?php  
                        // ListOption_pdo($link_id,'nationalityfile', 'natcde', $rs_emp['natcde'],'',$xfilter_pager_fields); 
                        // ListOption_pdo($link_id,'nationalityfile','natcde','',$rs_app['natcde'],'',$xfilter_pager_fields);
                        ListOption0_pdo($link_id,'nationalityfile','natcde','natdsc',$rs_app['natcde'],false);

                        ?>
                    </select>
                </td>
            </tr>
            <tr align="left">
                <td>Height : </td>
                <td colspan="1"><input type='text' id='height' class='input required af_fld' data-db_col="height" name='txt[height]' style="width:18%;float: left" value="<?php echo $rs_app['height']; ?>"><label style="float: left;font-size: 15px;margin-top: 5px;">&nbsp;FT</label></td>
                <td>Weight :</td>
                <td><input type='text' id='weight' class='input required af_fld numeric' data-db_col="weight" name='txt[weight]' style="width: 60px;float: left" value="<?php echo $rs_app['weight']; ?>"><label style="float: left;font-size: 15px;margin-top: 5px;">&nbsp;lbs</label></td></td>
                <td>Blood Type : </td>
                <td>
                   <select class='input required' data-db_col="bloodtype" data-db_col="bloodtype" name='txtxt[bloodtype]'>
                    <option></option>
                    <?php
                        $xbloodtype = array("A", "B", "AB", "O");
                        for($i = 0; $i<count($xbloodtype); $i++)
                        {
                            $xstate = strtoupper($rs_ext['bloodtype'])==$xbloodtype[$i] ? "selected":"";
                            echo "<option {$xstate}>{$xbloodtype[$i]}</option>";
                        }
                    ?>
                   </select>
                </td>    
            </tr>
            <tr>
                <td colspan="1"></td>
                <td colspan="3"><br><center>Mailing Address</center><br></td>
                <td colspan="5"><br><center>Permanent Address</center><br></td>
            </tr>
            <tr>    
                <td>No.,Street,Brgy:</td>
                <td colspan="3"><input type="text" name="txt[empadd1]" class='input required af_fld' data-db_col="empadd1" value="<?php echo $rs_app['empadd1']; ?>"></td>
                <td>No.,Street,Brgy:</td>
                <td colspan="3"><input type="text" name="txt[empper_add1]" class='input required af_fld' data-db_col="empper_add1" value="<?php echo $rs_app['empper_add1']; ?>"></td>
            </tr>
            <tr>
                <td>Town / City:</td>
                <td colspan="3"><input type="text" name="txt[empadd3]" class='input required af_fld' data-db_col="empadd3" value="<?php echo $rs_app['empadd3']; ?>"></td>
                <td>Town / City:</td>
                <td colspan="3"><input type="text" name="txt[empper_add3]" class='input required af_fld' data-db_col="empper_add3" value="<?php echo $rs_app['empper_add3']; ?>"></td>
            </tr>
            <tr>
                <td>State / Province:</td>
                <td colspan="3"><SELECT name="txt[empadd2]" class='input required' data-db_col="empadd2" >
                    <option value="" hidden selected ></option>
                        <?php
                        // ListOption_pdo($link_id,'cityfile','citycde',$rs_app['empadd2'],'',$xfilter_pager_fields,false);
                        $xstmt_empadd3 = $link_id->prepare("SELECT prov FROM regionprovcityfile GROUP BY prov");
                        $xstmt_empadd3->execute();
                        while($xrs_empadd3 = $xstmt_empadd3->fetch())
                        {
                            $xselected = '';
                            $xprov = $xrs_empadd3['prov'];
                            if( $xprov == $rs_app['empadd2'] )
                            {
                                $xselected = 'selected';
                            }
                            echo "<option $xselected value='" . $xprov. "'>" . $xprov . "</option>";
                        }
                        ?>
                </SELECT></td>
                <td>State / Province:</td>
                <td colspan="3"><select name="txt[empper_add2]" class='input required' data-db_col="empper_add2">
                    <option value="" ></option>
                        <?php
                            $xstmt_empadd3 = $link_id->prepare("SELECT prov FROM regionprovcityfile GROUP BY prov");
                            $xstmt_empadd3->execute();
                            while($xrs_empadd3 = $xstmt_empadd3->fetch())
                            {
                                $xselected = '';
                                $xprov = $xrs_empadd3['prov'];
                                if( $xprov == $rs_app['empper_add2'] )
                                {
                                    $xselected = 'selected';
                                }
                                echo "<option $xselected value='" . $xprov. "'>" . $xprov . "</option>";
                            }
                            ?>
                </select></td>
            </tr>
            <tr>
                <td>Country:</td>
                <td colspan="3"><select name="txt[countrycde]" class='input required' data-db_col="countrycde">
                    <option value="" hidden selected></option>
                    <?php
                        ListOption_pdo($link_id,'countryfile','cntrycde',$rs_app['countrycde'],'',$xfilter_pager_fields,false);
                    ?>
                </select></td>
                <td>Country:</td>
                <td colspan="3"><select name="txt[per_countrycde]" class='input required' data-db_col="countrycde">
                <option value="" hidden selected></option>
                <?php
                    ListOption_pdo($link_id,'countryfile','cntrycde',$rs_app['countrycde'],'',$xfilter_pager_fields,false);
                ?>
                </select></td>
            </tr>
            <tr>
                <td>Area:</td>
                <td colspan="3"><select name="txt[arecde]" class='input required' data-db_col="arecde">
                    <option value="" hidden selected ></option>
                        <?php
                            ListOption_pdo($link_id,'areafile','arecde',$rs_app['arecde'],'',$xfilter_pager_fields,false);
                        ?>
                </select></td>
                <td>Area:</td>
                <td colspan="3"><select name="txt[per_arecde]" class='input required' data-db_col="per_arecde">
                    <option value="" hidden selected ></option>
                        <?php
                            ListOption_pdo($link_id,'areafile','arecde',$rs_app['arecde'],'',$xfilter_pager_fields,false);
                        ?>
                </select></td>
            </tr>

            <tr>
                <td colspan="1"></td>
                <td colspan="3"><br><center>Contact Address</center><br></td>
                <td colspan="4"><br><center>If Married</center><br></td>
            </tr>
            <tr>    
                <td>Mobile No:</td>
                <td colspan="3"><input type='text' maxlength='13' id='mobnum' class='input numeric af_fld' data-db_col="celnum" name='txt[celnum]' value="<?php echo $rs_app['celnum']; ?>"></td>
                <td>Date of Marriage:</td>
                <td colspan="3"><input type="text" name="txtxt[dateofmarriage]" class='input datepicker ae_fld' data-db_col="dateofmarriage" placeholder="mm/dd/yyyy" value="<?php echo display_date($rs_ext['dateofmarriage']); ?>"></td>
            </tr>
            <tr>
                <td>Telephone Number:</td>
                <td colspan="3"><input type='text' id='telno' maxlength="13" class='input numeric af_fld' data-db_col="tel" name='txt[tel]' value="<?php echo $rs_app['tel']; ?>"></td>
                <td>No. of Children:</td>
                <td><input type='text' id='nochld' maxlength="2" onkeydown="javascript: return event.keyCode == 69 ? false : true" class='input numeric ae_fld' data-db_col="noofchild" name='txtxt[noofchild]' value="<?php echo $rs_ext['noofchild']; ?>"></td>
            </tr>
            <tr>
                <td>Personal E-mail:</td>
                <td colspan="3"><input type="email" name="txt[email]" class='input required af_fld' data-db_col="email" value="<?php echo $rs_app['email']; ?>"></td>
            </tr>
            <tr>
                <td>Office E-mail:</td>
                <td colspan="3"><input type="email" name="txt[officeemail]" class='input af_fld' data-db_col="officeemail" value="<?php echo $rs_app['officeemail']; ?>"></td>
            </tr>
        </table>
    </div>
</center>


<br>

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>EMERGENCY CONTACT</h3>
</header>
</article>
<br>
            <center><table  style='width:95%' class='hoverTable disabled_container'>
            <tr align='center' style='background:#cccccc;font-weight:bold'>
                     <td><center>Name</td>
                     <td><center>Contact No.</td>
                     <td><center>Address</td>
                     <td><center>Relationship</td>
                </tr>
                <tr>
                    <td><input type='text' class='input af_fld' data-db_col="case_emer" name='txt[case_emer]' maxlength='50'/ value="<?php echo $rs_app['case_emer']; ?>"></td>
                    <td><input type='text' class='input numeric as_fld' data-db_col="empcontactrel1" id='emer_tel' onpaste='return false' name='txt[emer_tel]' maxlength='13' value='<?php echo $rs_app['emer_tel']?>'></td>
                    <td><input type='text' class='input af_fld' data-db_col="emer_add" name='txt[emer_add]' maxlength='200' value='<?php echo $rs_app['emer_add']?>'  class = 'txtbox'></td>
                    <td><input type='text' class='input as_fld' data-db_col="empcontactrel1" name='txtsub[empcontactrel1]' maxlength='30' value='<?php echo $rs_sub['empcontactrel1']?>'></td>
                </tr>
                 <tr>
                    <td><input type='text' class='input' name='txtsub[case_emer2]'  maxlength='50' value='<?php echo $rs_sub['case_emer2']?>'  class = 'input txtbox as_fld' data-db_col="case_emer2"></td>

                    <td><input type='text' name='txtsub[emer_tel2]' id='emer_tel2' onkeypress='return isNumberKey(event)' onpaste='return false' maxlength='13' value='<?php echo $rs_sub['emer_tel2']?>'  class = 'input txtbox as_fld' data-db_col="emer_tel2"></td>

                    <td><input type='text' name='txtsub[emer_add2]' maxlength='200' value='<?php echo $rs_empsub['emer_add2']?>'  class = 'input txtbox as_fld' data-db_col="emer_add2"></td>
                    <td><input type='text' name='txtsub[empcontactrel2]' maxlength='30' value='<?php echo $rs_sub['empcontactrel2']?>'  class = 'input txtbox as_fld' data-db_col="empcontactrel2"></td>
                </tr>
                 <tr>
                    <td><input type='text' name='txtsub[case_emer3]'  maxlength='50' value='<?php echo $rs_sub['case_emer3']?>'  class = 'input txtbox as_fld' data-db_col="case_emer3"></td>

                    <td><input type='text' name='txtsub[emer_tel3]' id='emer_tel3' onkeypress='return isNumberKey(event)' onpaste='return false' maxlength='13' value='<?php echo $rs_sub['emer_tel3']?>'  class = 'input txtbox as_fld' data-db_col="emer_tel3"></td>

                    <td><input type='text' name='txtsub[emer_add3]' maxlength='200' value='<?php echo $rs_sub['emer_add3']?>'  class = 'input txtbox as_fld' data-db_col="emer_add3"></td>

                    <td><input type='text'  name='txtsub[empcontactrel3]' maxlength='30' value='<?php echo $rs_sub['empcontactrel3']?>'  class = 'input txtbox as_fld' data-db_col="empcontactrel3"></td>
                </tr>
                
            </table><br>

<center><article class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>REFERENCE</h3>
</header>
</article> 
</center> 
<br>
<br>
    <input type="button" onclick='addRow()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>
<center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='reference' data-row_limit=3>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>FullName</th>
        <th><center>Relationship</th>
        <th><center>Address</th>
        <th><center>Contact No.</center></th>
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM appempreffile WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            // var_dump($xstmt->fetchAll());
            // die();
            $tablenameref = 'appempreffile';
            while($rs_rfrnce = $xstmt->fetch())
            {
                $groupkey = $rs_rfrnce['recid'];

                if($rs_rfrnce['refrel'] == 'Neighbor')
                {
                    $option1 = 'selected';
                }
                else if($rs_rfrnce['refrel'] == 'Schoolmate')
                {
                    $option2 = 'selected';
                }
                else if($rs_rfrnce['refrel'] == 'Close Relative')
                {
                    $option3 = 'selected';
                }
                else if($rs_rfrnce['refrel'] == 'Former Officemate')
                {
                    $option4 = 'selected';
                }

                $echoref.= "<tr>
                    <input type='hidden' class='recid' name='rel[".$groupkey."][recid]' value=".$rs_rfrnce['recid'].">
                    <td>
                        <input type='text' name='rel[".$groupkey."][fullname]' class='input required appref_fld' data-db_col='fullname' value=".$rs_rfrnce['fullname'].">
                    </td>
                    <td>
                        <select name='rel[".$groupkey."][refrel]' class='input required'>
                        <option ".$option1.">Neighbor</option>
                        <option ".$option2.">Schoolmate</option>
                        <option ".$option3.">Close Relative</option>
                        <option ".$option4.">Former Officemate</option>
                    </td>
                    <td>
                        <input type='text' name='rel[".$groupkey."][address]' class='input required appref_fld' data-db_col='address' value=".$rs_rfrnce['address'].">
                    </td>
                    <td>
                        <input type='text' maxlength='13' name='rel[".$groupkey."][connum]' class='input numeric appref_fld' data-db_col='connum' value=".$rs_rfrnce['connum'].">
                    </td>
                    <td>
                        <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenameref."','".$rs_rfrnce['recid']."')\">
                    </td>
                </tr>";  
            } 
            echo $echoref;
        }
        ?>
    </tbody>
    </table>



<center>    
    <br>

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>RELATIVES AND/OR FRIENDS EMPLOYED BY SUMISHO</h3>
</header>
</article> 
</center> 
<br>
<br>
    <input type="button" onclick='addRelative()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>
<center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='relatives' data-row_limit=5>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>FullName</th>
        <th><center>Relationship</th>
        <th><center>Position</th>
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM applicantrelincompfile WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            $tablenamerel = 'applicantrelincompfile';
            while($rs_rel = $xstmt->fetch())
            {
                $xopt_position = ListOption2_pdo($link_id,'positionfile2','poscode','posdesc',$rs_rel['poscode'],'',array(),false);
                $groupkey = microtime(true);
                $echorel.="<tr><input type='hidden' class='recid' name='relative[".$groupkey."][recid]' value=".$rs_rel['recid'].">
                        <td>
                            <input type='text' name='relative[".$groupkey."][fullname]' class='input required apprel_fld' data-db_col='fullname' value=".$rs_rel['fullname'].">
                        </td>
                        <td>
                            <input type='text' name='relative[".$groupkey."][relationship]' class='input required apprel_fld' data-db_col='relationship' value=".$rs_rel['relationship'].">
                        </td>
                        <td>
                            <select name='relative[".$groupkey."][poscode]' class='input required' >
                            ".$xopt_position."
                        </td>
                        <td>
                            <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenamerel."','".$rs_rel['recid']."')\">
                        </td>
                    </tr>";  
            } 
            echo $echorel;
        }
        ?>
    </tbody>
    </table>

<center>    
    <br>


<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>FATHER INFO</h3>
</header>
</article>
</br>
<center>

    <center><table  style='width:95%' class='hoverTable disabled_container'>
    <tr>
        <td>Father's Name: </td>
        <td><input type='text' name='txt[fathername]'  onpaste='return false' maxlength='30' class = 'input af_fld' data-db_col="fathername" value='<?php echo $rs_app['fathername']?>' /></td>
        <td><center>Occupation</td>
        <td><input type='text' name='txt[foccupation]'  onpaste='return false' maxlength='30' class = 'input af_fld' data-db_col="foccupation" value='<?php echo $rs_app['foccupation']?>'/></td>
    </tr>
    <tr>
        <td>Birthdate: </td>
        <td><input type='text' name='txtxt[fbirthdate]'  onpaste='return false' maxlength='30' class = 'input datepicker ae_fld' data-db_col="fbirthdate" placeholder="mm/dd/yyyy" value='<?php echo display_date($rs_ext['fbirthdate']) ?>'></td>
        <td><center>Business Address</td>
        <td><input type='text' name='txtxt[fbusinessadd]' value='<?php echo $rs_ext['fbusinessadd']?>' onpaste='return false' maxlength='30' class = 'input ae_fld' data-db_col="fbusinessadd" /></td>
    </tr>
    <tr>
        <td>Home Tel: </td>
        <td><input type='text' name='txtxt[ftelno]' value='<?php echo $rs_ext['ftelno']?>' maxlength='13' onpaste='return false' maxlength='30' class = 'input numeric ae_fld' data-db_col="ftelno" /></td>
        <td><center>Work Tel</td>
        <td><input type='text' name='txtxt[fwtelno]' value='<?php echo $rs_ext['fwtelno']?>' maxlength='13 onpaste='return false' maxlength='30' class = 'input numeric ae_fld' data-db_col="fwtelno" /></td>
    </tr>
    <tr>
        <td>Mobile: </td>
        <td><input type='text' name='txtxt[fmobile]' value='<?php echo $rs_ext['fmobile']?>' maxlength='13' onpaste='return false' maxlength='30' class = 'input numeric ae_fld' data-db_col="fmobile" /></td>
        <td><center>Email</td>
        <td><input type='text' name='txtxt[femail]' value='<?php echo $rs_ext['femail']?>' onpaste='return false' maxlength='30' class = 'input ae_fld' data-db_col="femail" /></td>
    </tr>
    <tr>
        <td>Religion: </td>
        <td><select name='txtxt[freligion]'  onpaste='return false' maxlength='30' class = 'input ae_fld' data-db_col="freligion" />
            <option></option>
            <?php ListOption0_pdo($link_id,'religionfile','religion','religion',$rs_ext['freligion'],false); ?>
        </select>
        </td>
        <td><center>Citizenship</td>
        <td><select name='txtxt[fcitizenship]'  onpaste='return false' maxlength='30' class = 'input ae_fld' data-db_col="fcitizenship" />
            <?php 
            echo ListOption2_pdo($link_id,'citizenshipfile','ctncode','ctndesc',$rs_ext['fcitizenship'],"WHERE subdrycde =?",array('SUMISHO'),true); ?>
        </select></td>
    </tr>
</table>
<br>

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>MOTHER INFO</h3>
</header>
</article>
</br>
<center>

    <center><table  style='width:95%' class='hoverTable disabled_container'>
    <tr>
        <td>Mother's Name: </td>
        <td><input type='text' name='txt[mothername]' value='<?php echo $rs_app['mothername']?>'  onpaste='return false' maxlength='30' class = 'input af_fld' data-db_col="mothername" /></td>
        <td><center>Occupation</td>
        <td><input type='text' name='txt[moccupation]' value='<?php echo $rs_app['moccupation']?>'  onpaste='return false' maxlength='30' class = 'input af_fld' data-db_col="moccupation" /></td>
    </tr>
    <tr>
        <td>Birthdate: </td>
        <td><input type='text' name='txtxt[mbirthdate]' value='<?php echo display_date($rs_ext['mbirthdate'])?>' onpaste='return false' maxlength='30' class = 'input datepicker ae_fld' data-db_col="mbirthdate"  placeholder="mm/dd/yyyy"/></td>
        <td><center>Business Address</td>
        <td><input type='text' name='txtxt[mbusinessadd]' value='<?php echo $rs_ext['mbusinessadd']?>' onpaste='return false' maxlength='30' class = 'input ae_fld' data-db_col="mbusinessadd"/></td>
    </tr>
    <tr>
        <td>Home Tel: </td>
        <td><input type='text' name='txtxt[mtelno]' value='<?php echo $rs_ext['mtelno']?>' maxlength='13' onpaste='return false' maxlength='30' class = 'input numeric ae_fld' data-db_col="mtelno" /></td>
        <td><center>Work Tel</td>
        <td><input type='text' name='txtxt[mwtelno]' value='<?php echo $rs_ext['mwtelno']?>' maxlength='13' onpaste='return false' maxlength='30' class = 'input numeric ae_fld' data-db_col="mwtelno"/></td>
    </tr>
    <tr>
        <td>Mobile: </td>
        <td><input type='text' name='txtxt[mmobile]' value='<?php echo $rs_ext['mmobile']?>' maxlength='13' onpaste='return false' maxlength='30' class = 'input numeric ae_fld' data-db_col="mmobile" /></td>
        <td><center>Email</td>
        <td><input type='text' name='txtxt[memail]' value='<?php echo $rs_ext['memail']?>' maxlength='13' onpaste='return false' maxlength='30' class = 'input ae_fld' data-db_col="memail" /></td>
    </tr>
    <tr>
        <td>Religion: </td>
        <td><select name='txtxt[mreligion]'  onpaste='return false' maxlength='30' class = 'input ae_fld' data-db_col="freligion" />
            <option></option>
            <?php ListOption0_pdo($link_id,'religionfile','religion','religion',$rs_app['mreligion'],false); ?>
        </select>
        </td>
        <td><center>Citizenship</td>
        <td><select name='txtxt[mcitizenship]'  onpaste='return false' maxlength='30' class = 'input ae_fld' data-db_col="fcitizenship" />
            <?php 
            echo ListOption2_pdo($link_id,'citizenshipfile','ctncode','ctndesc',$rs_ext[',mcitizenship'],"WHERE subdrycde =?",array('SUMISHO'),true); ?>
        </select></td>
    </tr>
</table>
<br>

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>SPOUSE INFO</h3>
</header>
</article>
</br>
<center>

    <center><table style='width:95%' class='hoverTable disabled_container'>
    <tr>
        <td>Spouse's Name: </td>
        <td><input type='text' name='txt[spousename]'  value='<?php echo $rs_app['spousename']?>' onpaste='return false' maxlength='30' class = 'input af_fld' data-db_col="spousename" /></td>
        <td><center>Occupation</td>
        <td><input type='text' name='txt[soccupation]' value='<?php echo $rs_app['soccupation']?>' onpaste='return false' maxlength='30' class = 'input af_fld' data-db_col="soccupation" /></td>
    </tr>
    <tr>
        <td>Address: </td>
        <td><input type='text' name='txtxt[saddress]' value='<?php echo $rs_ext['saddress']?>' onpaste='return false' maxlength='30' class = 'input ae_fld' data-db_col="saddress" /></td>
        <td><center>Telephone No.</td>
        <td><input type='text' name='txtxt[stelno]'  value='<?php echo $rs_ext['stelno']?>' maxlength="13" onpaste='return false' maxlength='30' class = 'input numeric ae_fld' data-db_col="stelno" /></td>
    </tr>
    <tr>
        <td>Work Tel: </td>
        <td><input type='text' name='txtxt[swtelno]' value='<?php echo $rs_ext['swtelno']?>' maxlength="13" onpaste='return false' maxlength='30' class = 'input numeric ae_fld' data-db_col="swtelno" /></td>
        <td><center>Mobile: </td>
        <td><input type='text' name='txtxt[smobile]' value='<?php echo $rs_ext['smobile']?>' maxlength="13" onpaste='return false' maxlength='30' class = 'input numeric ae_fld' data-db_col="smobile"/></td>
    </tr>
    <tr>
        <td>Email: </td>
        <td><input type='text' name='txtxt[semail]' value='<?php echo $rs_ext['semail']?>' onpaste='return false' maxlength='30' class = 'input ae_fld' data-db_col="semail" /></td>
        <td><center>Tin No: </td>
        <td><input type='text' name='txtxt[stin]' value='<?php echo $rs_ext['stin']?>' onpaste='return false' maxlength='30' class = 'input ae_fld' data-db_col="stin" /></td>
    </tr>
</table>

<br>

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>SIBLINGS</h3>
</header>

</center> 
<br>
<br>
    <input type="button" onclick='addSiblings()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>
<center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='siblings' data-row_limit=5>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>Name: </th>
        <th><center>Employment: </th>
        <th><center>Date of Birth: </th>
        <th><center>Gender: </center></th>
        <th><center>Age: </center></th>
        <th><center>Mental Incapacity: </center></th>
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM applicantsiblings WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            $tablenamesibling = 'applicantsiblings';
            while($rs_siblings = $xstmt->fetch())
            {

                if(strtoupper($rs_siblings['cgender']) == 'MALE')
                {
                    $optionmale = 'selected'; 
                }
                else if(strtoupper($rs_siblings['cgender']) == 'FEMALE')
                {
                    $optionfemale = 'selected';
                }

                    
                $groupkey = microtime(true);
                $echosiblings.="<tr>
                        <input type='hidden' class='recid' name='siblings[".$groupkey."][recid]' value=".$rs_siblings['recid'].">
                        <td>
                            <input type='text' name='siblings[".$groupkey."][cname]' class='input required appsib_fld' data-db_col='cname' value=".$rs_siblings['cname'].">
                        </td>
                        <td>
                            <input type='text' name='siblings[".$groupkey."][cemployement]' class='input appsib_fld' data-db_col='cemployement' value=".$rs_siblings['cemployement'].">
                        </td>
                        <td>
                            <input type='text' name='siblings[".$groupkey."][cbirthdate]' oninput='get_agesibling()' id='siblingbday' class='input datepicker required appsib_fld' data-db_col='cbirthdate' placeholder='mm/dd/yyyy' value=".display_date($rs_siblings['cbirthdate']).">
                        </td>
                        <td>
                            <select name='siblings[".$groupkey."][cgender]' class='input required'>
                            <option ".$optionmale.">Male</option>
                            <option ".$optionfemale.">Female</option>
                        </td>
                        <td>
                            <input type='text' maxlength='3' name='siblings[".$groupkey."][cage]' id='siblingage' class='input numeric required appsib_fld' data-db_col='cage' value=".$rs_siblings['cage'].">
                        </td>
                        <td>
                            <input type='text' name='siblings[".$groupkey."][menincapacity]' class='input numeric appsib_fld' data-db_col='menincapacity' value=".$rs_siblings['menincapacity'].">
                        </td>
                        <td>
                            <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenamesibling."','".$rs_siblings['recid']."')\">
                        </td>
                    </tr>";  
            } 
            echo $echosiblings;
        }
        ?>
    </tbody>
</table>    
</article> 
</div>

<center>    
    <br>
    <br>

    <center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
    <header style='background:#8e8e8e;'>
    <h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>CHILDREN</h3>
    </header>
    </article> 
    </center> 
    <br>
    <br>
        <input type="button" onclick='addChildren()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
        <br>
        <br>
    <center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='children' data-row_limit=5>
        <thead align='center' style='background:#cccccc;font-weight:bold'>
            <th><center>Name: </th>
            <th><center>Employment: </th>
            <th><center>Date of Birth: </th>
            <th><center>Gender: </center></th>
            <th><center>Age: </center></th>
            <th><center>Mental Incapacity: </center></th>
            <th></th>
        </thead>
        <tbody>
            <?php
            if($formtype =='edit')
            {
                $xqry = "SELECT * FROM applicantchildren WHERE appcode=?";
                $xstmt = $link_id->prepare($xqry);
                $xstmt->execute(array($xappcode));
                $tablenamechild = 'applicantchildren';
                while($rs_children = $xstmt->fetch())
                {

                    if(strtoupper($rs_children['cgender']) == 'MALE')
                    {
                        $optionmale = 'selected'; 
                    }
                    else if(strtoupper($rs_children['cgender']) == 'FEMALE')
                    {
                        $optionfemale = 'selected';
                    }

                        
                    $groupkey = microtime(true);
                    $echochild.="<tr>
                            <input type='hidden' class='recid' name='children[".$groupkey."][recid]' value=".$rs_children['recid'].">
                            <td>
                                <input type='text' name='children[".$groupkey."][cname]' class='input required appchild_fld' data-db_col='cname' value=".$rs_children['cname'].">
                            </td>
                            <td>
                                <input type='text' name='children[".$groupkey."][cemployement]' class='input appchild_fld' data-db_col='cemployement' value=".$rs_children['cemployement'].">
                            </td>
                            <td>
                                <input type='text' name='children[".$groupkey."][cbirthdate]' oninput='get_agechild()' id='childbday' class='input datepicker required appchild_fld' data-db_col='cbirthdate' placeholder='mm/dd/yyyy' value=".display_date($rs_children['cbirthdate']).">
                            </td>
                            <td>
                                <select name='children[".$groupkey."][cgender]' class='input required'>
                                <option ".$optionmale.">Male</option>
                                <option ".$optionfemale.">Female</option>
                            </td>
                            <td>
                                <input type='text' maxlength='3' name='children[".$groupkey."][cage]' id='childage' class='input numeric required appchild_fld' data-db_col='cage' value=".$rs_children['cage'].">
                            </td>
                            <td>
                                <input type='text' name='children[".$groupkey."][menincapacity]' class='input numeric appchild_fld' data-db_col='menincapacity' value=".$rs_children['menincapacity'].">
                            </td>
                            <td>
                                <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenamechild."','".$rs_children['recid']."')\">
                            </td>
                        </tr>";  
                } 
                echo $echochild;
            }
            ?>
        </tbody>
    </table>    
    </div>

    <center>    
        <br>
        <br>

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
    <header style='background:#8e8e8e;'>
    <h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>GUARDIAN / OTHERS</h3>
    </header>
    </article> 
    </center> 
    <br>
    <br>
        <input type="button" onclick='addGuardian()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
        <br>
        <br>
    <center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='guardian' data-row_limit=5>
        <thead align='center' style='background:#cccccc;font-weight:bold'>
            <th><center>Relationship: </th>
            <th><center>Name: </th>
            <th><center>Date of Birth: </th>
            <th><center>Address: </th>
            <th><center>Contact No.: </center></th>
            <th><center>Mental Incapacity: </center></th>
            <th><center>Description: </center></th>
            <th></th>
        </thead>
        <tbody>
            <?php
            if($formtype =='edit')
            {
                $xqry = "SELECT * FROM applicantotherrelations WHERE appcode=?";
                $xstmt = $link_id->prepare($xqry);
                $xstmt->execute(array($xappcode));
                $tablenameguardian = 'applicantotherrelations';
                while($rs_guardian = $xstmt->fetch())
                {

                    if(strtoupper($rs_guardian['reldsc']) == '1ST DEGREE')
                    {
                        $option1 = 'selected'; 
                    }
                    else if(strtoupper($rs_guardian['reldsc']) == '2ND DEGREE')
                    {
                        $option2 = 'selected';
                    }
                    else if(strtoupper($rs_guardian['reldsc']) == '3RD DEGREE')
                    {
                        $option3 = 'selected';
                    }
                    else if(strtoupper($rs_guardian['reldsc']) == '4TH DEGREE')
                    {
                        $option4 = 'selected';
                    }

                        
                    $groupkey = microtime(true);
                    $echoguardian.="<tr>
                            <input type='hidden' class='recid' name='guardian[".$groupkey."][recid]' value=".$rs_guardian['recid'].">
                            <td>
                                <input type='text' name='guardian[".$groupkey."][relationship]' class='input required appguard_fld' data-db_col='relationship' value=".$rs_guardian['relationship'].">
                            </td>
                            <td>
                                <input type='text' name='guardian[".$groupkey."][fullname]' class='input required appguard_fld' data-db_col='fullname' value=".$rs_guardian['fulllname'].">
                            </td>
                            <td>
                                <input type='text' name='guardian[".$groupkey."][cbirthdate]' id='guardianbday' class='input datepicker required appguard_fld' data-db_col='cbirthdate' placeholder='mm/dd/yyyy' value=".display_date($rs_guardian['cbirthdate']).">
                            </td>
                            <td>
                                <input type='text' name='guardian[".$groupkey."][address]' class='input required appguard_fld' data-db_col='address' value=".$rs_guardian['address'].">
                            </td>
                            <td>
                                <input type='text' maxlength='11' name='guardian[".$groupkey."][contactno]' class='input numeric required appguard_fld' data-db_col='contactno' value=".$rs_guardian['contactno'].">
                            </td>
                            <td>
                                <input type='text' name='guardian[".$groupkey."][menincapacity]' class='input required appguard_fld' data-db_col='menincapacity' value=".$rs_guardian['menincapacity'].">
                            </td>
                            <td>
                                <select name='guardian[".$groupkey."][reldsc]' class='input required' >
                                <option ".$option1.">1st Degree</option>
                                <option ".$option2.">2nd Degree</option>
                                <option ".$option3.">3rd Degree</option>
                                <option ".$option4.">4th Degree</option>
                            </td>
                            <td>
                                <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenameguardian."','".$rs_guardian['recid']."')\">
                            </td>
                        </tr>";  
                } 
                echo $echoguardian;
            }
            ?>
        </tbody>
    </table>    
    </div>

    <center>    
        <br>
        <br>    



<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>EDUCATIONAL BACKGROUND (HIGHEST EDUCATIONAL ATTAINMENT)</h3>
</header>
</article> 
</center> 
<br>
<br>
    <input type="button" onclick='addEduc()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>
<center><table style='width:95%' class='hiddentable hiddentable hoverTable disabled_container' id='educ' data-row_limit=5>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>Level / Degree</th>
        <th><center>School</th>
        <th><center>Major / Specialization</th>
        <th><center>GPA / SCORE</center></th>
        <th><center>START DATE</center></th>
        <th><center>END DATE</center></th>
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM applicantschool WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            $tablenameeduc = 'applicantschool';
            $groupkey = microtime(true);
            while($rs_educ = $xstmt->fetch())
            {
                $xopt_level = ListOption2_pdo($link_id,'educstatfile','statcode','statdesc',$rs_educ['schlevel'],'',array(),false);
                $xopt_school = ListOption2_pdo($link_id,'schoolfile','schcode','schdesc',$rs_educ['schcode'],'',array(),false);
                    
                
                $echoeduc.="<tr>
                            <input type='hidden' class='recid' name='educ[".$groupkey."][recid]' value=".$rs_educ['recid'].">
                            <td>
                                <select name='educ[".$groupkey."][schlevel]' class='input required'>
                                ".$xopt_level."
                                </select>
                            </td>
                            <td>
                                <select name='educ[".$groupkey."][schcode]' class='input required'>
                                ".$xopt_school."
                                </select>
                            </td>
                            <td>    
                                <input type='text' name='educ[".$groupkey."][schcourse]' class='input required appeduc_fld' data-db_col='schcourse' value=".$rs_educ['schcourse'].">
                            </td>
                            <td>
                                <input type='text' maxlength='3' name='educ[".$groupkey."][schave]' class='input numeric required appeduc_fld' data-db_col='schave' value=".$rs_educ['schave'].">
                            </td>
                            <td>
                                <input type='text' name='educ[".$groupkey."][strtdte]' id='datestart' class='input datepicker required appeduc_fld' data-db_col='strtdte' placeholder='mm/dd/yyyy' value=".display_date($rs_educ['strtdte']).">
                            </td>   
                            <td>
                                <input type='text' name='educ[".$groupkey."][enddte]' id='dateend' class='input datepicker required appeduc_fld' data-db_col='enddte' placeholder='mm/dd/yyyy' value=".display_date($rs_educ['enddte']).">
                            </td>
                            <td>
                                <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenameeduc."','".$rs_educ['recid']."')\">
                            </td>
                        </tr>";  
            } 
            echo $echoeduc;
        }
        ?>
    </tbody>
</table>    
</div>

<center>    
    <br>
    <br>

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>SKILLS</h3>
</header>
</article> 
</center> 
<br>
<br>
    <input type="button" onclick='addSkill()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>

<center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='skills' data-row_limit=3>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>Skill</th>
        <th><center>Years Of Experience</th>
        <th><center>Experience Level</th>
        <th><center>Proficiency Level</center></th>
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM applicantskills WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            $tablenameskill = 'applicantskills';
            // echo "<pre>";
            while($rs_skills = $xstmt->fetch())
            {   
                // var_dump($rs_skills);
                $xopt_skillfile = ListOption2_pdo($link_id,'skillfile','skillcode','skilldesc',$rs_skills['skillcode'],'',array(),false);
                $xopt_exp = ListOption2_pdo($link_id,'experiencelevelfile','explvlcde','explvldsc',$rs_skills['exlvl'],'',array(),false);
                $xopt_level = ListOption2_pdo($link_id,'levelfile','levelcde','leveldsc',$rs_skills['proflvl'],'',array(),false);
                    
                $groupkey = $rs_skills['recid'];
                $echoskill.="<tr>
                            <input type='hidden' class='recid' name='skill[".$groupkey."][recid]' value=".$rs_skills['recid'].">
                            <td>
                                <select name='skill[".$groupkey."][skillcode]' id='".$xctr1."' class='input required val_sel_group' data-sel_group='skill_sel_grp'>
                                ".$xopt_skillfile."
                                </select>
                            </td>
                            <td>
                                <input type='text' maxlength='2' name='skill[".$groupkey."][exyear]' class='input numeric required appskill_fld' data-db_col='exyear' value=".$rs_skills['exyear'].">
                            </td>
                            <td>
                                <select name='skill[".$groupkey."][exlvl]' class='input required'>
                                ".$xopt_exp."
                                </select>
                            </td>
                            <td>
                                <select name='skill[".$groupkey."][proflvl]' class='input required'>
                                ".$xopt_level."
                                </select>
                            </td>
                            <td>
                                <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=onclick=\"deleteRow(this,'".$tablenameskill."','".$rs_skills['recid']."')\">
                            </td>
                            <input type='hidden' readonly name='skill[".$groupkey."][priority]' class='input numeric required appskill_fld' data-db_col='priority' value=".$xctr1.">
                        </tr>";
            } 
            // die();
            echo $echoskill;
        }
        ?>
    </tbody>
</table>  
<br>
<!-- <th><center>Priority</center></th> -->
<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>LANGUAGES</h3>
</header>
</article> 
</center> 
<br>
<br>
    <input type="button" onclick='addLanguage()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>

<center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='languages' data-row_limit=5>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>Language</th>
        <th><center>Speak</th>
        <th><center>Read</th>
        <th><center>Write<center></th>
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM emplangfile WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            $tablenamelang = 'emplangfile';
            // echo "<pre>";
            while($rs_language = $xstmt->fetch())
            {   
                // var_dump($rs_skills);
                $xopt_language = ListOption2_pdo($link_id,'languagefile','langcode','langdesc',$rs_language['langcde'],'',array(),false);
                
                if($rs_language['langspeak'] == 'Fair')
                {
                    $optionspeak1 = 'selected';
                }
                else if($rs_language['langspeak'] == 'Good')
                {
                    $optionspeak2 = 'selected';
                }
                else if($rs_language['langspeak'] == 'Very Good')
                {
                    $optionspeak3 = 'selected';
                }

                if($rs_language['langread'] == 'Fair')
                {
                    $optionread1 = 'selected';
                }   
                else if($rs_language['langread'] == 'Good')
                {
                    $optionread2 = 'selected';
                }
                else if($rs_language['langread'] == 'Very Good')
                {
                    $optionread3 = 'selected';
                }

                if($rs_language['langwrite'] == 'Fair')
                {
                    $optionwrite1 = 'selected';
                }
                else if($rs_language['langwrite'] == 'Good')
                {   
                    $optionwrite2 = 'selected';
                }
                else if($rs_language['langwrite'] == 'Very Good')
                {
                    $optionwrite3 = 'selected';
                }

                $groupkey = $rs_language['recid'];
                $echolang.="<tr>
                            <input type='hidden' class='recid' name='language[".$groupkey."][recid]' value=".$rs_language['recid'].">
                            <td>
                                <select name='language[".$groupkey."][langcde]' class='input required val_sel_group' data-sel_group='lang_sel_grp'>
                                ".$xopt_language."
                                </select>
                            </td>
                            <td>
                                <select name='language[".$groupkey."][langspeak]' class='input required'>
                                <option ".$optionspeak1.">Fair</option>
                                <option ".$optionspeak2.">Good</option>
                                <option ".$optionspeak3.">Very Good</option>
                                </select>
                            </td>
                            <td>
                                <select name='language[".$groupkey."][langread]' class='input required'>
                                <option ".$optionread1.">Fair</option>
                                <option ".$optionread2.">Good</option>
                                <option ".$optionread3.">Very Good</option>
                                </select>
                            </td>
                            <td>
                                <select name='language[".$groupkey."][langwrite]' class='input required'>
                                <option ".$optionwrite1.">Fair</option>
                                <option ".$optionwrite2.">Good</option>
                                <option ".$optionwrite3.">Very Good</option>
                                </select>
                            </td>
                            <td>
                                <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenamelang."','".$rs_language['recid']."')\">
                            </td>
                        </tr>";
            } 
            // die();
            echo $echolang;
        }
        ?>
    </tbody>
</table>  
<br>
<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>AWARDS</h3>
</header>
</article> 
</center> 
<br>
<br>
    <input type="button" onclick='addAward()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>

<center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='awards' data-row_limit=5>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>Award: </th>
        <th><center>Date Issued: </th>
        <th><center>Issued by: </th>
        <th><center>External Awards / Others: <center></th>
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM applicantaward WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            $tablenameaward = 'applicantaward';
            // echo "<pre>";
            while($rs_award = $xstmt->fetch())
            {   
                // var_dump($rs_skills);
                $xopt_award = ListOption2_pdo($link_id,'awardfile','awardcode','awarddesc',$rs_award['awardcode'],'',array(),false);
                    
                $groupkey = $rs_award['recid'];
                $echoaward.="<tr>
                            <input type='hidden' class='recid' name='award[".$groupkey."][recid]' value=".$rs_award['recid'].">
                            <td>
                                <select name='award[".$groupkey."][awardcode]' class='input required val_sel_group' data-sel_group='award_sel_grp'>
                                ".$xopt_award."
                                </select>
                            </td>
                            <td>
                                <input type='text' name='award[".$groupkey."][awarddate]' class='input datepicker required appaward_fld' data-db_col='awarddate' placeholder='mm/dd/yyyy' value=".display_date($rs_award['awarddate']).">
                            </td>
                            <td>
                                <input type='text' name='award[".$groupkey."][awardissuedby]' class='input required appaward_fld' data-db_col='awardissuedby' value=".$rs_award['awardissuedby'].">
                            </td>
                            <td>
                                <input type='text' name='award[".$groupkey."][awardexternal]' class='input required appaward_fld' data-db_col='awardexternal' value=".$rs_award['awardexternal'].">
                            </td>
                            <td>
                                <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenameaward."','".$rs_award['recid']."')\">
                            </td>
                        </tr>";
            } 
            // die();
            echo $echoaward;
        }
        ?>
    </tbody>
</table>  
</div>

<center>    
    <br>  

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>Certifications</h3>
</header>
</article> 
</center> 
<br>
<br>
    <input type="button" onclick='addCert()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>

<center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='certifications' data-row_limit=5>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>Description: </th>
        <th><center>Score: </th>
        <th><center>Date Valid: </th>
        <th><center>Expiry Date: <center></th>
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM applicantcertificate WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            $tablenamecert = 'applicantcertificate';
            // echo "<pre>";
            while($rs_cert = $xstmt->fetch())
            {   
                $groupkey = $rs_cert['recid'];
                $echocert.="<tr>
                            <input type='hidden' class='recid' name='cert[".$groupkey."][recid]' value=".$rs_cert['recid'].">
                            <td>
                                <input type='text' name='cert[".$groupkey."][certdesc]' class='input required appcert_fld' data-db_col='certdesc' value=".$rs_cert['certdesc'].">
                            </td>
                            <td>
                                <input type='text' name='cert[".$groupkey."][score]' class='input required appcert_fld' data-db_col='score' value=".$rs_cert['score'].">
                            </td>
                            <td>
                                <input type='text' name='cert[".$groupkey."][datevalid]' class='input datepicker required appcert_fld' data-db_col='datevalid' placeholder='mm/dd/yyyy' value=".display_date($rs_cert['datevalid']).">
                            </td>
                            <td>
                                <input type='text' name='cert[".$groupkey."][expdate]' class='input datepicker required appcert_fld' data-db_col='expdate' placeholder='mm/dd/yyyy' value=".display_date($rs_cert['expdate']).">
                            <td>
                                <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenamecert."','".$rs_cert['recid']."')\">
                            </td>
                        </tr>";
            } 
            // die();
            echo $echocert;
        }
        ?>
    </tbody>
</table>  
</div>

<center>    
    <br>
    <br>  

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>SEMINARS/TRAININGS ATTENDED</h3>
</header>
</article> 
</center> 
<br>
<br>
    <input type="button" onclick='addSem()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>

<center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='seminars' data-row_limit=5>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>Description: </th>
        <th><center>Venue: </th>
        <th><center>Date From: </th>
        <th><center>End From: </th>
        <th><center>Cost: <center></th>
        <th><center>Paid By: <center></th>
        <th><center>Internal/External: <center></th>
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM applicantseminar WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            $tablenamesem = 'applicantseminar';
            // echo "<pre>";
            while($rs_seminar = $xstmt->fetch())
            {   
                $groupkey = $rs_seminar['recid'];
                $echoseminar.="<tr>
                            <input type='hidden' class='recid' name='sem[".$groupkey."][recid]' value=".$rs_seminar['recid'].">
                            <td>
                                <input type='text' name='sem[".$groupkey."][seminardesc]' class='input required appsem_fld' data-db_col='seminardesc' value=".$rs_seminar['seminardesc'].">
                            </td>
                            <td>
                                <input type='text' name='sem[".$groupkey."][semvenue]' class='input required appsem_fld' data-db_col='semvenue' value=".$rs_seminar['semvenue'].">
                            </td>
                            <td>
                                <input type='text' name='sem[".$groupkey."][strtdate]' class='input datepicker required appsem_fld' data-db_col='strtdate' placeholder='mm/dd/yyyy' value=".display_date($rs_seminar['strtdate']).">
                            </td>
                            <td>
                                <input type='text' name='sem[".$groupkey."][enddate]' class='input datepicker required appsem_fld' data-db_col='enddate' placeholder='mm/dd/yyyy' value=".display_date($rs_seminar['enddate']).">
                            </td>
                            <td>
                                <input type='text' name='sem[".$groupkey."][semcost]' class='input numeric required appsem_fld' data-db_col='semcost' value=".$rs_seminar['semcost'].">
                            </td>
                            <td>
                                <input type='text' name='sem[".$groupkey."][sempayby]' class='input required appsem_fld' data-db_col='sempayby' value=".$rs_seminar['sempayby'].">
                            </td>
                            <td>
                                <input type='text' name='sem[".$groupkey."][semtype]' class='input required appsem_fld' data-db_col='semtype' value=".$rs_seminar['semtype'].">
                            </td>
                            <td>
                                <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenamesem."','".$rs_seminar['recid']."')\">
                            </td>
                        </tr>";
            } 
            // die();
            echo $echoseminar;
        }
        ?>
    </tbody>
</table>  
</div>

<center>    
    <br>
    <br>  

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>WORK EXPERIENCE</h3>
</header>
</article> 
</center> 
<br>
<br>
    <input type="button" onclick='addExp()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>

<center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='experience' data-row_limit=5>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>Company: </th>
        <th><center>Job Title: </th>
        <th><center>From: </th>
        <th><center>To: </th>
        <th><center>Salary: <center></th>
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM applicantrecord WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            $tablenamework = 'applicantrecord';
            // echo "<pre>";
            while($rs_work = $xstmt->fetch())
            {   
                $groupkey = $rs_work['recid'];
                $echowork.="<tr>
                            <input type='hidden' class='recid' name='exp[".$groupkey."][recid]' value=".$rs_work['recid'].">
                            <td>
                                <input type='text' name='exp[".$groupkey."][comdsc]' class='input required appexp_fld' data-db_col='comdsc' value=".$rs_work['comdsc'].">
                            </td>
                            <td>
                                <input type='text' name='exp[".$groupkey."][firstpos]' class='input required appexp_fld' data-db_col='firstpos' value=".$rs_work['firstpos'].">
                            </td>
                            <td>
                                <input type='text' name='exp[".$groupkey."][datehired]' class='input datepicker required appexp_fld' data-db_col='datehired' placeholder='mm/dd/yyyy' value=".display_date($rs_work['datehired']).">
                            </td>
                            <td>
                                <input type='text' name='exp[".$groupkey."][dateterm]' class='input datepicker required appexp_fld' data-db_col='dateterm' placeholder='mm/dd/yyyy' value=".display_date($rs_work['dateterm']).">
                            </td>
                            <td>
                                <input type='text' name='exp[".$groupkey."][empsal]' class='input numeric required appexp_fld' data-db_col='empsal' value=".$rs_work['empsal'].">
                            </td>
                            <td>
                                <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenamework."','".$rs_work['recid']."')\">
                            </td>
                        </tr>";
            } 
            // die();
            echo $echowork;
        }
        ?>
    </tbody>
</table>  
</div>

<center>    
    <br>
    <br>

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>MEMBERSHIP</h3>
</header>
</article> 
</center> 
<br>
<br>
    <input type="button" onclick='addMem()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>

<center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='membership' data-row_limit=5>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>Type: </th>
        <th><center>No.: </th>
        <th><center>Date Start: </th>
        <th><center>Expiration Date: </th>
        <th><center>Paid by: <center></th>
        <th><center>Amount: <center></th>
        <th><center>Currency: <center></th>
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM employeemembership WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            $tablenamemember = 'employeemembership';
            // echo "<pre>";
            while($rs_member = $xstmt->fetch())
            {   
                if($rs_member['subpaidby'] == 'Company')
                {
                    $option1 = 'selected';
                }
                else if($rs_member['subpaidby'] == 'Employee')
                {
                    $option2 = 'selected';
                }

                $xopt_membership = ListOption2_pdo($link_id,'membershipfile','memdesc','memdesc',$rs_member['memdesc'],'',array(),false);
                $xopt_currency = ListOption2_pdo($link_id,'currencyfile','curcde','curdsc',$rs_member['currency'],'',array(),false);
                $groupkey = $rs_member['recid'];
                $echomember.="<tr>
                            <input type='hidden' class='recid' name='mem[".$groupkey."][recid]' value=".$rs_member['recid'].">
                            <td>
                                <Select name='mem[".$groupkey."][memdesc]' class='input required val_sel_group appmem_fld' data-db_col='memdesc' data-sel_group='mem_sel_grp'>
                                ".$xopt_membership."
                                </select>
                            </td>
                            <td>
                                <input type='text' name='mem[".$groupkey."][memno]' class='input numeric required appmem_fld' data-db_col='memno' value=".$rs_member['memno'].">
                            </td>
                            <td>
                                <input type='text' name='mem[".$groupkey."][subcomsdte]' class='input datepicker required appmem_fld' data-db_col='subcomsdte' placeholder='mm/dd/yyyy' value=".display_date($rs_member['subcomsdte']).">
                            </td>
                            <td>
                                <input type='text' name='mem[".$groupkey."][subrenewdte]' class='input datepicker required appmem_fld' data-db_col='subrenewdte' placeholder='mm/dd/yyyy' value=".display_date($rs_member['subrenewdte'])."
                            </td>
                            <td>
                                <Select name='mem[".$groupkey."][subpaidby]' class='input required'>
                                <option ".$option1.">Company</option>
                                <option ".$option2.">Employee</option>
                                </select>
                            </td>
                            <td>
                                <input type='text' name='mem[".$groupkey."][subamt]' class='input numeric required appmem_fld' data-db_col='subamt' value=".$rs_member['subamt'].">
                            </td>
                            <td>
                                <Select name='mem[".$groupkey."][currency]' class='input required'>
                                ".$xopt_currency."
                                </select>
                            </td>
                            <td>
                                <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenamemember."','".$rs_member['recid']."')\">
                            </td>
                        </tr>";
            } 
            // die();
            echo $echomember;
        }
        ?>
    </tbody>
</table>  
</div>

<center>    
    <br>
    <br>

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>IMMIGRATION</h3>
</header>
</article> 
</center> 
<br>
<br>
    <input type="button" onclick='addImmigration()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>

<center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='immigration' data-row_limit=2>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>Document: </th>
        <th><center>Number.:     </th>
        <th><center>Issued Date: </th>
        <th><center>Expiry Date: </th>
        <th><center>Eligible Status: <center></th>
        <th><center>Issued by: <center></th>
        <th><center>Eligible Review Date: <center></th>
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM employeeimmigrationfile WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            $tablenameimmi = 'employeeimmigrationfile';
            // echo "<pre>";
            while($rs_immigration = $xstmt->fetch())
            {   
                if($rs_member['subpaidby'] == 'Passport')
                {
                    $option1 = 'selected';
                }
                else if($rs_member['subpaidby'] == 'Visa')
                {
                    $option2 = 'selected';
                }

                $xopt_country = ListOption2_pdo($link_id,'countryfile','cntrycde','cntrydsc',$rs_immigration['issby'],'',array(),false);
                $groupkey = $rs_immigration['recid'];
                $echoimmi.="<tr>
                            <input type='hidden' class='recid' name='immi[".$groupkey."][recid]' value=".$rs_immigration['recid'].">
                            <td>
                                <Select name='immi[".$groupkey."][doctype]' class='input required val_sel_group' data-sel_group='immigration_sel_grp'>
                                <option ".$option1." value='Passport'>Passport</option>
                                <option ".$option2." value='Visa'>Visa</option>
                                </select>
                            </td>
                            <td>
                                <input type='text' name='immi[".$groupkey."][docnum]' class='input required appimmi_fld' data-db_col='docnum' value=".$rs_immigration['docnum'].">
                            </td>
                            <td>
                                <input type='text' name='immi[".$groupkey."][isdte]' class='input datepicker required appimmi_fld' data-db_col='isdte' placeholder='mm/dd/yyyy' value=".display_date($rs_immigration['isdte']).">
                            </td>
                            <td>
                                <input type='text' name='immi[".$groupkey."][expdte]' class='input datepicker required appimmi_fld' data-db_col='expdte' placeholder='mm/dd/yyyy' value=".display_date($rs_immigration['expdte']).">
                            </td>
                            <td>
                                <input type='text' name='immi[".$groupkey."][elgstat]' class='input required appimmi_fld' data-db_col='elgstat' value=".$rs_immigration['elgstat'].">
                            </td>
                            <td>
                                <Select name='immi[".$groupkey."][issby]' class='input val_sel_group' data-sel_group='by_sel_grp'>
                                ".$xopt_country."
                                </select>
                            </td>
                            <td>
                                <input type='text' name='immi[".$groupkey."][elgrevdte]' class='input datepicker appimmi_fld' data-db_col='elgrevdte' placeholder='mm/dd/yyyy' value=".display_date($rs_immigration['elgrevdte']).">
                            </td>
                            <td>
                                <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenameimmi."','".$rs_immigration['recid']."')\">
                            </td>
                        </tr>";
            } 
            // die();
            echo $echoimmi;
        }
        ?>
    </tbody>
</table>  
</div>

<center>    
    <br>
    <br>

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>REQUIREMENTS</h3>
</header>
</article> 
</center> 
<br>
<br>
    <input type="button" onclick='addRequirement()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>

<center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='requirements' data-row_limit=5>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>Requirement: </th>
        <th><center>Date Issued: </th>
        <th><center>Expiry Date: </th>  
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM applicantrequirementsfile WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            $tablenamereq = 'applicantrequirementsfile';
            // echo "<pre>";
            while($rs_requirements = $xstmt->fetch())
            {   
                $xopt_requirement = ListOption2_pdo($link_id,'requirementsnamefile','requirementcde','requirementname',$rs_requirements['requirement'],'',array(),false);
                $groupkey = $rs_requirements['recid'];
                $echoreq.="<tr>
                            <input type='hidden' class='recid' name='req[".$groupkey."][recid]' value=".$rs_requirements['recid'].">
                            <td>
                                <Select name='req[".$groupkey."][requirement]' class='input required val_sel_group' data-sel_group='req_sel_grp'>
                                ".$xopt_requirement."
                                </select>
                            </td>
                            <td>
                                <input type='text' name='req[".$groupkey."][dateissue]' class='input datepicker required appreq_fld' data-db_col='dateissue' placeholder='mm/dd/yyyy' value=".display_date($rs_requirements['dateissue']).">
                            </td>
                            <td>
                                <input type='text' name='req[".$groupkey."][dateexpire]' class='input datepicker required appreq_fld    ' data-db_col='dateexpire' placeholder='mm/dd/yyyy' value=".display_date($rs_requirements['dateexpire']).">
                            </td>
                            <td>
                                <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenamereq."','".$rs_requirements['recid']."')\">
                            </td>
                        </tr>";
            } 
            // die();
            echo $echoreq;
        }
        ?>
    </tbody>
</table>  
</div>

<center>    
    <br>
    <br>

<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>LICENSES</h3>
</header>
</article> 
</center> 
<br>
<br>
    <input type="button" onclick='addLicense()' class='save' Value="Add Record" style="height:30px;margin-right: 1100px;">
    <br>
    <br>

<center><table style='width:95%' class='hiddentable hoverTable disabled_container' id='licenses' data-row_limit=5>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>License Type: </th>
        <th><center>License No.: </th>
        <th><center>Date Issued: </th>
        <th><center>Expiry Date: </th>  
        <th><center>Place Issued: </th>  
        <th></th>
    </thead>
    <tbody>
        <?php
        if($formtype =='edit')
        {
            $xqry = "SELECT * FROM applicantlicenses WHERE appcode=?";
            $xstmt = $link_id->prepare($xqry);
            $xstmt->execute(array($xappcode));
            $tablenamelic = 'applicantlicenses';
            // echo "<pre>";
            while($rs_license = $xstmt->fetch())
            {   
                $xopt_license = ListOption2_pdo($link_id,'licensefile','licode','lidesc',$rs_license['licname'],'',array(),false);
                $groupkey = $rs_license['recid'];
                $echolicense.="<tr>
                            <input type='hidden' class='recid' name='lic[".$groupkey."][recid]' value=".$rs_license['recid'].">
                            <td>
                                <Select name='lic[".$groupkey."][licname]' class='input required val_sel_group' data-sel_group='lic_sel_grp'>
                                ".$xopt_license."
                                </select>
                            </td>
                            <td>
                                <input type='text' name='lic[".$groupkey."][licno]' class='input required applic_fld' data-db_col='licno' value=".$rs_license['licno'].">
                            </td>
                            <td>
                                <input type='text' name='lic[".$groupkey."][issdte]' class='input datepicker required applic_fld' data-db_col='issdte' placeholder='mm/dd/yyyy' value=".display_date($rs_license['issdte']).">
                            </td>
                            <td>
                                <input type='text' name='lic[".$groupkey."][expdte]' class='input datepicker required applic_fld' data-db_col='expdte' placeholder='mm/dd/yyyy' value=".display_date($rs_license['expdte']).">
                            </td>
                            <td>
                                <input type='text' name='lic[".$groupkey."][licplace]' class='input required applic_fld' data-db_col='licplace' value=".$rs_license['licplace'].">
                            </td>
                            <td>
                                <input type = 'button' value='Delete' class='exit' style='height:30px;width:100%;' onclick=\"deleteRow(this,'".$tablenamelic."','".$rs_license['recid']."')\">
                            </td>
                        </tr>";
            } 
            // die();
            echo $echolicense;
        }
        ?>
    </tbody>
</table>  
</div>
<center><article  class='pager-module' style = "height:40px;border:1px solid black;width:99%;margin-top:0px;border:1px solid #d8d8db;background:#8e8e8e;border-radius:.8em" id = "info">
<header style='background:#8e8e8e;'>
<h3 style='text-align:left;margin-left:5%;font-size:14px;font-weight:bold;color:white'>ATTACHMENTS</h3>
</header>
</article> 
</center> 
<center><table border="1" style='width:95%' class='hoverTable disabled_container' id='attachements'>
    <thead align='center' style='background:#cccccc;font-weight:bold'>
        <th><center>Document Type</th>
        <th><center>Filename</th>
        <th><center>Description</th>
        <th><center>Action</th>
    </thead>
    <tbody>
        <?php
        $xqry="SELECT * FROM documentfile";
        $xstmt=$link_id->prepare($xqry);
        $xstmt->execute();
        while($xrs = $xstmt->fetch())
        {   
            $attachments .= "<tr style = 'height:50px;border:1px solid black;'>
            <td style='width:250px;'>".$xrs['doccode']." (.doc maximum size:2MB)</td>";
            
            $xqry1='select * from applicantattachments where appcode=? AND doccode=?';
            $xstmt1=$link_id->prepare($xqry1);
            $xstmt1->execute(array($rs_app['appcode'], $xrs['doccode']));
            $xtableattach = 'applicantattachments';
            if($xrs1=$xstmt1->fetch())
            {
                $attachments .= "<td style='width:100px;'><center>".$xrs1['filename']."</center></td>";
                $attachments .= "<td style='width:100px;'><center><input type='text' style='height:40px;text-align:center;' name='attach[".$xrs['doccode']."][dsc]' value=".$xrs1['dsc']."></center></td>";

                $attachments .= "<input type='hidden' name='attachtype' value='edit'>";

                $attachments .= "<input type='hidden' name='attach[".$xrs['doccode']."][doccode]' value=".$xrs['doccode'].">
                <iframe src='' style='display:none;' name='ifrmupload2'  enctype='multipart/form-data' id='ifrmupload2'></iframe>
                <td style='width:100px;'><input type='file' name='attachfile[".$xrs['doccode']."]' id='attachfile' size='51' onchange='upload_attachfile()'>
                <input type = 'hidden' name='attach[".$xrs['doccode']."][filepath]' id='txt_filepath' maxlength='50'  value='application/employee_attachments/' readonly>";

                $attachments .= "<input type='hidden' name='attach[".$xrs['doccode']."][recid]' value=".$xrs1['recid'].">
                <input type='button' style='margin-right:70px;' value='Delete' onclick=\"deleteAttach(this, '".$xrs1['recid']."')\" class='exit'></td>";
                $attachments .= "</tr><br>"; 
            }
            else
            {
                $attachments .= "<td style='width:100px;'><center>".$xrs1['filename']."</center></td>";
                $attachments .= "<td style='width:100px;'><center><input type='text' style='height:40px;text-align:center;' name='attach[".$xrs['doccode']."][dsc]' value=".$xrs1['dsc']."></center></td>";

                $attachments .= "<input type='hidden' name='attachtype' value='add'>";

                $attachments .= "<input type='hidden' name='attach[".$xrs['doccode']."][doccode]' value=".$xrs['doccode'].">
                <iframe src='' style='display:none;' name='ifrmupload2'  enctype='multipart/form-data' id='ifrmupload2'></iframe>
                <td style='width:100px;'><input type='file' name='attachfile[".$xrs['doccode']."]' id='attachfile' size='51' onchange='upload_attachfile()'>
                <input type = 'hidden' name='attach[".$xrs['doccode']."][filepath]' id='txt_filepath' maxlength='50'  value='application/employee_attachments/' readonly>";
                $attachments .= "</tr><br>"; 
            }                                 
        }

        $attachments .= "</tbody></table>";
        echo $attachments;
        ?>  
        <br>
        </center>
        <input type='hidden' name='item_id2' id='txt_recid' value='<?php echo $xrecid2?>' />
        <input type='hidden' name='txttablename' value='<?php echo $xtablename?>' />
        <input type='hidden' name='txtprevpage' value='<?php echo $xprevpage?>' />
        <input type='hidden' name='txtfldcde' value='<?php echo $xcode?>' />
        <input type='hidden' name='txtflddsc' value='<?php echo $xdesc?>' />
        <input type='hidden' name='xcwd' id='xcwd' value='<?php echo getcwd() ?>' />
        <!-- <input type = "hidden" name = "attach_action" id = "attach_action"> -->
        
    </thead>
</table>  
</div>

<center>    
    <br>
    <br>

<table width='90%' border=0  style='font-size:13px;font-weight:bold'>
<tr>
    <td colspan='8' align='right'>
        <p style="margin-top:0px"><input type="<?php echo $type; ?>" value="Save" onclick='save_click()' class="save" style='width:90px;height:30px'>&nbsp;&nbsp;&nbsp;
                    <input type="button"  value="Cancel" class='exit' onclick='exit_click()' style='width:90px;height:30px'>
        </p>
    </td>
</tr>
</table>
</center>

<input type='hidden' name='event_action' id='event_action' value="" />
<input type='hidden' name='xpage_uri' id='xpage_uri' />

</form>

</body>
</html>
<?php

    $xrecid2 = trim($_POST['item_id2']);
    $xaction = trim($_POST['xaction']);
    // var_dump($xaction);
    if( isset($_POST['attach_action']) && trim($_POST['attach_action']) == 'delete' )
    {
      $xqry="SELECT * FROM applicantattachments where recid=?";
      $xstmt=$link_id->prepare($xqry);
      $xstmt->execute(array($_POST['item_id2']));
      $xrs=$xstmt->fetch();
      
      unlink($xrs['filepath'].$xrs['filename']); 
        $query  = "Delete FROM applicantattachments where recid=?";
        $stmt   = $link_id->prepare($query);
        $stmt->execute(array($_POST['item_id2']));
    }

    
 ?>