$(document).ready(function() {
    checkSessionStat();
});
function checkSessionStat(){
    var status = sessionStorage.getItem("alert_status");
    var message = sessionStorage.getItem("alert_message");
    if(status == "success"){
        successAlert(message);
        sessionStorage.removeItem("alert_status");
        sessionStorage.removeItem("alert_message");
    } else if(status == "failed"){
        errorAlert(message);
        sessionStorage.removeItem("alert_status");
        sessionStorage.removeItem("alert_message");
    }
}
function validateFormDocument(){
    var filename = $("#input-filename").val();
    var file = $("#input-file").val();
    var oFile = document.getElementById("input-file").files[0];
    var allowedExtensions =  /(.doc|\.docx|\.pdf|\.jpg|\.jpeg|\.png|\.gif)$/i;

    if(filename != ""){
        $("#error-filename").html("");
        $("#error-filename").hide();
    } else {
        $("#error-filename").show();
        $("#error-filename").html("<i class='fa fa-warning'></i> This field is required.");
        $("#input-filename").focus();
        return false;
    }
    if(file != ""){
        if (!allowedExtensions.exec(file)){
            $("#error-file").show();
            $("#error-file").html("<i class='fa fa-warning'></i> Allowed file format is pdf, doc, docx, jpg, jpeg, png, gif.");
            $("#input-file").focus();
            return false;
        } else {
            if(oFile.size < 10485760){ // 2 MiB for bytes.
                $("#error-file").html("");
                $("#error-file").hide();
            } else {
                $("#error-file").show();
                $("#error-file").html("<i class='fa fa-warning'></i> Max upload file size is 10Mb.");
                $("#input-file").focus();
                return false;
            }
        }
    } else {
        $("#error-file").show();
        $("#error-file").html("<i class='fa fa-warning'></i> This field is required.");
        $("#input-file").focus();
        return false;
    }
    return true;
};
function confirmRemove(docid,title){
    var url_page = $("#input-pageurl").val();
    var poid = $("#input-poid").val();

    var redir_url = url_page+"?action=delete&poid="+poid+"&docid="+docid;
    console.log(redir_url);
    swal({
        title: "Are you sure to delete?",
        text: "You will delete "+title,
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Remove ! ",
        cancelButtonText: "Cancel !",
        closeOnConfirm: true,
        closeOnCancel: true
    },
    function (isConfirm) {
        if (isConfirm) {
            win_loader('open');
            window.location.href = redir_url;
        } else {
            win_loader('close');
            //nothing
        }
    });
}
$(document).ready(function() {
    $(".fancyboxdoc").fancybox({
        padding : 0
    });
});