
window.customConfirm = function(msg, okCallback, cancelCallback) {

    var confirmHtml = '<div class="modal confirm fade" id="modal-confirm" tabindex="-1" role="dialog" aria-hidden="false">' +
        '<div class="modal-dialog">' +
        '<div class="modal-body">' +
        '<div class="cont">' + msg +'</div>' +
        '</div>' +
        '<div class="modal-footer">' +
        '<div class="cont">' +
        '<a href="#" class="cancel" id="modal-confirm-cancel">CANCEL</a>' +
        '<input type="submit" value="Ok" class="button" id="modal-confirm-ok">' +
        '</div>' +
        '</div>' +
        '</div>' +
        '</div>';

    var okCallbackWrap = function(e){
        e.preventDefault();
        if (okCallback) okCallback();
        $('#modal-confirm').modal('hide');
    };

    var cancelCallbackWrap = function(e){
        e.preventDefault();
        if (cancelCallback) cancelCallback();
        $('#modal-confirm').modal('hide');
    };

    var removeCallback = function(){
        document.getElementById('modal-confirm-ok').removeEventListener("click", okCallbackWrap , false);
        document.getElementById('modal-confirm-cancel').removeEventListener("click", cancelCallbackWrap , false);
    };

    document.body.insertAdjacentHTML('beforeEnd', confirmHtml);
    removeCallback();
    document.getElementById('modal-confirm-ok').addEventListener("click", okCallbackWrap , false);
    document.getElementById('modal-confirm-cancel').addEventListener("click", cancelCallbackWrap , false);

    $('#modal-confirm').on('hidden.bs.modal', function(){
        removeCallback();
        document.body.removeChild(document.getElementById('modal-confirm'));
    });

    $('#modal-confirm').modal();

};

window.customAlert = function(msg) {

    var confirmHtml = '<div class="modal confirm fade" id="modal-alert" tabindex="-1" role="dialog" aria-hidden="false">' +
        '<div class="modal-dialog">' +
        '<div class="modal-body">' +
        '<div class="cont">' + msg +'</div>' +
        '</div>' +
        '<div class="modal-footer">' +
        '<div class="cont">' +
        '<input type="submit" value="Ok" class="button" data-dismiss="modal">' +
        '</div>' +
        '</div>' +
        '</div>' +
        '</div>';

    document.body.insertAdjacentHTML('beforeEnd', confirmHtml);

    $('#modal-alert').on('hidden.bs.modal', function(){
        document.body.removeChild(document.getElementById('modal-alert'));
    });

    $('#modal-alert').modal();

};



window.customCopyLink = function(copylink) {


    var copyToClipboard = function(str) {
        var el = document.createElement('textarea');
        el.classList.add('can-copy');
        el.value = str;
        document.body.appendChild(el);
        el.select();
        document.execCommand('copy');
        document.body.removeChild(el);
        $('#modal-copylink').modal('hide');
        window.customAlert('Link is copied to the clipboard');
    };

    copyToClipboard(copylink);

};