﻿var isMozilla = navigator.appName == "Netscape" && (navigator.userAgent.toLowerCase().indexOf("firefox") != -1);
var isOpera = navigator.appName == "Opera";

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

function showSpModalDialogByURLWithParentRefresh(url) {
    var options = {
        url: url,
        allowMaximize: false,
        dialogReturnValueCallback: function (r) { if (r != null && (r == 1 || r.result == 1)) { window.location.reload(); } }
    };
    showSpModalDialog(options);
}

function showSpModalDialogByURL(url) {
    var options = {
        url: url,
        allowMaximize: false
    };
    showSpModalDialog(options);
}


function showSpModalDialog(options) {
    SP.SOD.executeOrDelayUntilScriptLoaded(function () { showSpModalDialogWhenScriptLoaded(options) }, 'sp.ui.dialog.js');
}


function showSpModalDialogWhenScriptLoaded(options) {
    SP.Res.dialogLoadingText = "Загрузка...";
    SP.Res.dialogLoading = "";
    SP.Res.defaultDialogTitle = "";

    var dialog = SP.UI.ModalDialog.showModalDialog(options);
    $(dialog.get_frameElement()).attr('allowtransparency', 'true');
    $('iframe')[0].style.display = 'none';
    if ($('iframe').length == 3)
        $('iframe')[1].style.display = 'none';
}

function correctDialogSize() {


    if (isMozilla || isOpera) {
        window.setTimeout(function () {
            var width = $('.contOv').width();
            $(parent.document.body).find('.ms-dlgFrameContainer').width(width);
            $(parent.document.body).find('.ms-dlgFrame').width(width);
            $(parent.document.body).find('.ms-dlgTitle').width(width);
        }, 50);
    }



}
