﻿function AddNewFolder(title, c_id, p_id) {
    if(!title.match(/[%=/\\&*:<>?|]/) && title + '' != ''){
    $.getJSON("/Management/AddFolder/" + escape(title) + "?c_id=" + c_id + "&p_id=" + p_id,
        function(data) {
            if (data.id > 0) {
                $("#folderPrepend").before("<div class='filePlaceholder' id='folderPlaceholder_" + data.id + "'><div class='closer' title='Remove folder' onclick=\"DeleteFolder(" + data.id + ",'" + data.title.replace("'","\\'") + "','" + c_id +"','no files or folders.');return false;\">X</div><a href='/Management/Files/" + data.id + "?c_id=" + c_id + "'><img src='/Content/Images/folder_80.jpg' alt='" + data.title + "' />" + data.title + "</a></div>");
                $("#noMessage").hide();
            }
        });
        }
        else{$('#folderErrorMessage').show();}

    }

    function DeleteFile(f_id, f_name, f_token) {
        var conf = confirm("Are you sure you wish to delete the file '" + f_name + "'?");
        if (conf) {
            $.getJSON("/Management/DeleteFile/" + f_id + "?t=" + f_token,
            function(data) {
                if (data.success == true) {
                    $("#filePlaceholder_" + f_id).remove();
                }
            });
        }
    }

    function DeleteFolder(f_id, f_name, c_id,count) {
        var conf = confirm("Are you sure you wish to delete the folder '" + f_name + "'?\r\nThis folder contains " + count + " ");
        if (conf) {
            $.getJSON("/Management/DeleteFolder/" + f_id + "?c_id=" + c_id,
            function(data) {
                if (data.success == true) {
                    $("#folderPlaceholder_" + f_id).remove();
                }
            });
        }
    }
    
    function ConfDeleteCompany(){
        var conf = confirm('Are you sure you want to delete this company? This will delete all files and cannot be undone');
        return conf;
    }