﻿// JScript File

function OnLawListUserSelect(ctrl) {
    if (ctrl.options[ctrl.selectedIndex].value.length > 0) {
        var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
        Notisum.WebServices.LawList.GetLawListUserAssignmentString(ctrl.options[ctrl.selectedIndex].value, lawListId.value, OnLawListUserSelectSuccess);
    }
}
function OnLawListUserSelectSuccess(result) {
    if (result == '[FAIL]') {
        DeselectAllLawListDocuments();
    }
    else {
        if (result.length > 0) {
            var array = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawListDocumentsArray');
            array.value = result;
            PopuplateSelectedLawListDocuments();
        }
        else
            DeselectAllLawListDocuments();
    }
}

function OpenUserGroupDialog(nodeId, listId, ownerId, prefix) {
    var processWin = document.getElementById('processWindow3');
    if (processWin == null)
        processWin = window.parent.document.getElementById('processWindow3');

    if (processWin) {
        processWin.style.display = 'inline';
    }

    var relGroup = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_groupToReload');
    if (relGroup)
        relGroup.value = prefix;
    var selnode = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedAcceptNode');
    selnode.value = nodeId;
    var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_userGroupInfoContainer');
    panel.innerHTML = '';
    var editPopup = $find('editUserGroupPopupBehavior');
    editPopup.show();

    Notisum.WebServices.LawList.GetDocumentAcceptUsersSelection(nodeId, listId, ownerId, OnUserGroupDataSuccess);
}

function ResetDocumentUserSettings() {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSERESETUSERSMSG1').value)) {
        var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_userGroupInfoContainer');
        panel.innerHTML = '';

        var selnode = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedAcceptNode');
        var array = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedDocumentUsersArray');
        array.value = '';

        var processWin = document.getElementById('processWindow3');
        if (processWin == null)
            processWin = window.parent.document.getElementById('processWindow3');

        if (processWin) {
            processWin.style.display = 'inline';
        }

        Notisum.WebServices.LawList.ResetDocumentAcceptUserSelection(selnode.value, OnResetUsersSuccess);
    }
}

function OnResetUsersSuccess(result) {
    CloseUserDialog();
}

function OnUserGroupDataSuccess(result) {
    var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_userGroupInfoContainer');
    panel.innerHTML = result;
    var processWin = document.getElementById('processWindow3');
    if (processWin == null)
        processWin = window.parent.document.getElementById('processWindow3');

    if (processWin) {
        processWin.style.display = 'none';
    }
    checkAllSelectedUserItems();
}

function checkAllSelectedUserItems() {
    var userItems = document.getElementsByName("user_item");

    if (userItems) {
        for (var i = 0; i < userItems.length; i++) {
            var control = userItems.item(i);
            if (control.checked == true && control.disabled == false) {
                AppendUserToArray(control);
            }
        }
    }
}

function setCheckBoxValue(checkBoxId) {
    var chk = document.getElementById(checkBoxId);

    if (chk.value == 0)
        chk.value = 1;
    else
        chk.value = 0;
}

function ApplyUserSettings() {
    var struct = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_userGroupStructure');
    var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_userGroupInfoContainer');

    //alert(panel.innerHTML);

    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSESAVEUSERSETTINGSMSG1').value)) {
        struct.value = panel.innerHTML;
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$ApplyUserGroupSettingsExecutor', '');
    }
}

function CloseUserDialog() {
    var selnode = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedAcceptNode');
    selnode.value = '';

    var editPopup = $find('editUserGroupPopupBehavior');
    editPopup.hide();

    var array = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedDocumentUsersArray');
    array.value = '';
}

function OpenFlagDialog(nodeId, listId) {
    var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');

    if (selectedLaw)
        selectedLaw.value = nodeId;

    var flagPopup = $find('flagAcceptPopupBehavior');
    flagPopup.show();
}

function RemoveUnhandledFlag(flagId, nodeId) {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEDELETEFLAGMSG1').value)) {
        var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');

        if (selectedLaw)
            selectedLaw.value = nodeId;

        Notisum.WebServices.LawList.RemoveUnHandledFlag(flagId, OnReopenFlagSuccess);
    }
}

function ApplyFlag() {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSECREATEMESSAGEMSG1').value)) {
        var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
        var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
        var comment = document.getElementById('AcceptCommentText');

        var requireComments = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_requireAcceptComments');
        if (requireComments && comment) {
            if (requireComments.value == '1' && comment.value.length == 0) {
                alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEREQUIRECOMMENTMSG1').value);
            }
            else {
                var flagPopup = $find('flagAcceptPopupBehavior');
                flagPopup.hide();

                Notisum.WebServices.LawList.CreateAcceptFlag(selectedLaw.value, lawListId.value, comment.value, OnCreateFlagSuccess);

                selectedLaw.value = '';
                comment.value = '';
            }
        }
        else {
            var flagPopup = $find('flagAcceptPopupBehavior');
            flagPopup.hide();

            var commentText = '';
            if (comment == null)
                commentText = '';
            else {
                commentText = comment.value;
                comment.value = '';
            }
            Notisum.WebServices.LawList.CreateAcceptFlag(selectedLaw.value, lawListId.value, commentText, OnCreateFlagSuccess);

            selectedLaw.value = '';
        }
    }
}

function OnCreateFlagSuccess(result) {
    if (result == '[FAIL]')
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSECREATEMESSAGEERR1').value);
    else
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$ReloadDocumentGroupExecutor', '');
}

function CloseFlagDialog() {
    var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
    if (selectedLaw)
        selectedLaw.value = '';
    var flagPopup = $find('flagAcceptPopupBehavior');
    flagPopup.hide();
}

function ReopenFlag(id, nodeId) {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSERECALLMSG1').value)) {
        var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
        var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
        selectedLaw.value = nodeId;
        Notisum.WebServices.LawList.ReopenAcceptFlag(lawListId.value, id, OnReopenFlagSuccess);
    }
}

function OnReopenFlagSuccess(result) {
    if (result == '[FAIL]')
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEACTIONERR1').value);
    else {
        var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_flagListContainer');
        panel.innerHTML = '';
        var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
        var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');

        Notisum.WebServices.LawList.GetNodeAcceptFlags(selectedLaw.value, lawListId.value, OnGetFlagListSuccess);
    }
}

function ExecuteFlag(id, nodeId) {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSESENDMESSAGEMSG1').value));
    {
        var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
        selectedLaw.value = nodeId;
        var owner = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_ownerPr');
        var waitDlg = $find('LawListWaitDialogPopupBehavior');
        waitDlg.show();
        Notisum.WebServices.LawList.ExecuteFlag(id, owner.value, OnExecuteFlagOnlySuccess, OnExecuteFlagError);
    }
}

function OnExecuteFlagOnlySuccess(result) {
    var waitDlg = $find('LawListWaitDialogPopupBehavior');
    waitDlg.hide();

    if (result == '[FAIL]') {
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSESENDMESSAGEERR1').value);
    }
    else {
        var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_flagListContainer');
        panel.innerHTML = '';
        var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
        var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');

        Notisum.WebServices.LawList.GetNodeAcceptFlags(selectedLaw.value, lawListId.value, OnGetFlagListSuccess);

        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEMESSAGESENTMSG1').value);

    }
}

function OpenAcceptCommentDialog(id, nodeId) {
    var processWin = document.getElementById('processWindow5');
    if (processWin == null)
        processWin = window.parent.document.getElementById('processWindow5');

    if (processWin) {
        processWin.style.display = 'inline';
    }

    var selectedFlag = document.getElementById('selectedFlag');
    selectedFlag.value = id;

    var flagPopup = $find('flagCommentEditPopupBehavior');
    flagPopup.show();

    Notisum.WebServices.LawList.GetFlagComment(id, OnOpenAcceptCommentDialog);
}

function OnOpenAcceptCommentDialog(result) {
    var comment = document.getElementById('flagEditComment');
    comment.value = result;
    var processWin = document.getElementById('processWindow5');
    if (processWin == null)
        processWin = window.parent.document.getElementById('processWindow5');

    if (processWin) {
        processWin.style.display = 'none';
    }
}

function CloseFlagCommentEditDialog() {
    var comment = document.getElementById('flagEditComment');
    comment.value = '';
    var selectedFlag = document.getElementById('selectedFlag');
    selectedFlag.value = '0';
    var flagPopup = $find('flagCommentEditPopupBehavior');
    flagPopup.hide();
}

function CloseFlagWithComment() {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSECLOSEMESSAGEMSG1').value)) {
        var selectedFlag = document.getElementById('selectedFlag');
        var comment = document.getElementById('flagEditComment');

        var commentStr = '';

        commentStr = comment.value;

        if (selectedFlag == null) {
            alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEACTIONERR1').value);
        }
        else {
            var requireComments = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_requireAcceptComments');
            if (requireComments) {
                if (requireComments.value == '1' && commentStr.length == 0) {
                    alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEREQUIRECOMMENTMSG1').value);
                }
                else {
                    var flagPopup = $find('flagCommentEditPopupBehavior');
                    flagPopup.hide();
                    Notisum.WebServices.LawList.CloseAcceptFlag(selectedFlag.value, comment.value, OnReopenFlagSuccess);
                    CloseFlagCommentEditDialog();
                }
            }
            else {
                var flagPopup = $find('flagCommentEditPopupBehavior');
                flagPopup.hide();
                Notisum.WebServices.LawList.CloseAcceptFlag(selectedFlag.value, comment.value, OnReopenFlagSuccess);
                CloseFlagCommentEditDialog();
            }
        }
    }
}

function CloseFlag(id, nodeId) {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSECLOSEMESSAGEMSG1').value)) {
        var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
        selectedLaw.value = nodeId;
        var allowComments = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_allowAcceptComments');

        if (allowComments.value == '1') {
            OpenAcceptCommentDialog(id, nodeId);
        }
        else
            Notisum.WebServices.LawList.CloseAcceptFlag(id, '', OnReopenFlagSuccess);
    }
}

function OpenFlagListDialog(nodeId, listId) {
    var processWin = document.getElementById('processWindow4');
    if (processWin == null)
        processWin = window.parent.document.getElementById('processWindow4');

    if (processWin) {
        processWin.style.display = 'inline';
    }
    var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_flagListContainer');
    panel.innerHTML = '';

    var flagPopup = $find('flagListPopupBehavior');
    flagPopup.show();

    Notisum.WebServices.LawList.GetNodeAcceptFlags(nodeId, listId, OnGetFlagListSuccess);
}

function OnGetFlagListSuccess(result) {
    if (result == '[FAIL]')
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEFETCHMESSAGEERR1').value);
    else {
        var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_flagListContainer');
        panel.innerHTML = result;
        var processWin = document.getElementById('processWindow4');
        if (processWin == null)
            processWin = window.parent.document.getElementById('processWindow4');

        if (processWin) {
            processWin.style.display = 'none';
        }
    }
}

function CloseFlagListDialog() {
    var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_flagListContainer');
    panel.innerHTML = '';
    var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
    selectedLaw.value = 0;
    var flagPopup = $find('flagListPopupBehavior');
    flagPopup.hide();
    __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$ReloadDocumentGroupExecutor', '');
}

function ApplyFlagAndClose() {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSESAVECLOSEMESSAGEMSG1').value));
    {
        var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
        var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
        var comment = document.getElementById('AcceptCommentText');

        var requireComments = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_requireAcceptComments');
        if (requireComments && comment) {
            if (requireComments.value == '1' && comment.value.length == 0) {
                alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEREQUIRECOMMENTMSG1').value);
            }
            else {
                var flagPopup = $find('flagAcceptPopupBehavior');
                flagPopup.hide();

                Notisum.WebServices.LawList.CreateAcceptFlag(selectedLaw.value, lawListId.value, comment.value, OnCreateFlagAndCloseSuccess);

                selectedLaw.value = '';
                comment.value = '';
            }
        }
        else {
            var flagPopup = $find('flagAcceptPopupBehavior');
            flagPopup.hide();

            var commentText = '';
            if (comment == null)
                commentText = '';
            else {
                commentText = comment.value;
                comment.value = '';
            }

            Notisum.WebServices.LawList.CreateAcceptFlag(selectedLaw.value, lawListId.value, commentText, OnCreateFlagAndCloseSuccess);

            selectedLaw.value = '';
        }
    }
}

function OnCreateFlagAndCloseSuccess(result) {
    if (result == '[FAIL]')
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSECREATEMESSAGEERR1').value);
    else {
        Notisum.WebServices.LawList.CloseAcceptFlag(result, '', OnCreateAndCloseSuccess);
    }
}

function OnCreateAndCloseSuccess(result) {
    if (result == '[FAIL]')
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSECLOSEMESSAGEERR1').value);
    else {
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$ReloadDocumentGroupExecutor', '');
    }
}

function ApplyFlagAndSend() {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSESENDMESSAGEMSG1').value));
    {
        var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
        var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
        var comment = document.getElementById('AcceptCommentText');

        var requireComments = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_requireAcceptComments');
        if (requireComments && comment) {
            if (requireComments.value == '1' && comment.value.length == 0) {
                alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEREQUIRECOMMENTMSG1').value);
            }
            else {
                var flagPopup = $find('flagAcceptPopupBehavior');
                flagPopup.hide();

                Notisum.WebServices.LawList.CreateAcceptFlag(selectedLaw.value, lawListId.value, comment.value, OnCreateFlagAndSendSuccess);

                selectedLaw.value = '';
                comment.value = '';
            }
        }
        else {
            var flagPopup = $find('flagAcceptPopupBehavior');
            flagPopup.hide();

            var commentText = '';
            if (comment == null)
                commentText = '';
            else {
                commentText = comment.value;
                comment.value = '';
            }

            Notisum.WebServices.LawList.CreateAcceptFlag(selectedLaw.value, lawListId.value, commentText, OnCreateFlagAndSendSuccess);

            selectedLaw.value = '';
        }
    }
}

function OnCreateFlagAndSendSuccess(result) {
    if (result == '[FAIL]')
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSECREATEMESSAGEERR1').value);
    else
        ExecuteDocumentFlag(result);
}

function ExecuteDocumentFlag(flagId) {
    var owner = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_ownerPr');
    var waitDlg = $find('LawListWaitDialogPopupBehavior');
    waitDlg.show();

    Notisum.WebServices.LawList.ExecuteFlag(flagId, owner.value, OnExecuteFlagSuccess, OnExecuteFlagError);
}

function OnExecuteFlagError(result) {
    var waitDlg = $find('LawListWaitDialogPopupBehavior');
    waitDlg.hide();

    alert(result);
}

function OnExecuteFlagSuccess(result) {
    var waitDlg = $find('LawListWaitDialogPopupBehavior');
    waitDlg.hide();

    if (result == '[FAIL]') {
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSESENDMESSAGEERR1').value);
    }
    else {
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEMESSAGESENTMSG1').value);
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$ReloadDocumentGroupExecutor', '');
    }
}

function UserAcceptFlag(userFlagId, flagId, listNodeId, regId) {
    var allowComments = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_allowAcceptComments');
    var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
    selectedLaw.value = listNodeId;

    if (allowComments.value == "1") {
        var selectedFlag = document.getElementById('selectedFlag');
        selectedFlag.value = flagId;
        // open comment dialog
        OpenUserAcceptCommentDialog(userFlagId, regId);
    }
    else {
        // Accept directly 
        AcceptSelectedUserFlag(userFlagId, '', regId, flagId);
    }
}

function AcceptSelectedUserFlag(userFlagId, comment, userId, flagId) {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEACCEPTMSG2').value)) {
        Notisum.WebServices.LawList.CloseUserFlag(userFlagId, comment, userId, flagId, OnAcceptSelectedUserFlag);
    }
}

function AcceptFlagWithComment() {
    var userComment = document.getElementById('UserCommentText');
    var currentUser = document.getElementById('currentUser');
    var selectedUserFlag = document.getElementById('selectedUserFlag');
    var selectedFlag = document.getElementById('selectedFlag');

    var requireComments = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_requireAcceptComments');

    if (requireComments) {
        if (requireComments.value == '1' && userComment.value.length == 0) {
            alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEREQUIRECOMMENTMSG1').value);
        }
        else {
            AcceptSelectedUserFlag(selectedUserFlag.value, userComment.value, currentUser.value, selectedFlag.value);

            var flagPopup = $find('userAcceptCommentDialogPopupBehavior');
            flagPopup.hide();

            selectedUserFlag.value = 0;
            userComment.value = '';
        }
    }
    else {
        AcceptSelectedUserFlag(selectedUserFlag.value, userComment.value, currentUser.value, selectedFlag.value);

        var flagPopup = $find('userAcceptCommentDialogPopupBehavior');
        flagPopup.hide();

        selectedUserFlag.value = 0;
    }
}

function CloseUserCommentDialog() {
    var flagPopup = $find('userAcceptCommentDialogPopupBehavior');
    flagPopup.hide();

    var selectedUserFlag = document.getElementById('selectedUserFlag');
    var currentUser = document.getElementById('currentUser');
    var userComment = document.getElementById('UserCommentText');
    userComment.value = '';

    selectedUserFlag.value = 0;
    currentUser.value = 0;
}

function OnAcceptSelectedUserFlag(result) {
    if (result == '[FAIL]')
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEACTIONERR1').value);
    {
        var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
        var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
        var currentUser = document.getElementById('currentUser');

        if (parentLawListId > 0) {
            Notisum.WebServices.LawList.GetNodeAcceptFlagsByUser(parentLawListId, selectedLaw.value, currentUser.value, OnOpenUserAccept);
        }
        else {
            Notisum.WebServices.LawList.GetNodeAcceptFlagsByUser(lawListId.value, selectedLaw.value, currentUser.value, OnOpenUserAccept);
        }
    }
}

function OpenUserAcceptCommentDialog(userFlagId, userId, nodeId) {
    var selectedUserFlag = document.getElementById('selectedUserFlag');
    var currentUser = document.getElementById('currentUser');

    selectedUserFlag.value = userFlagId;
    currentUser.value = userId;

    var flagPopup = $find('userAcceptCommentDialogPopupBehavior');
    flagPopup.show();
}

function OpenUserAccept(nodeId, rId) {
    var processWin = document.getElementById('processWindow6');
    if (processWin == null)
        processWin = window.parent.document.getElementById('processWindow6');

    if (processWin) {
        processWin.style.display = 'inline';
    }

    var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
    var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
    selectedLaw.value = nodeId;

    var currentUser = document.getElementById('currentUser');
    currentUser.value = rId;

    var flagPopup = $find('userAcceptFlagPopupBehavior');
    flagPopup.show();

    Notisum.WebServices.LawList.GetNodeAcceptFlagsByUser(lawListId.value, nodeId, rId, OnOpenUserAccept);
}

var parentLawListId = 0;
function OpenUserAcceptNested(listId, nodeId, rId) {
    parentLawListId = listId;
    var processWin = document.getElementById('processWindow6');
    if (processWin == null)
        processWin = window.parent.document.getElementById('processWindow6');

    if (processWin) {
        processWin.style.display = 'inline';
    }
    
    var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
    selectedLaw.value = nodeId;

    var currentUser = document.getElementById('currentUser');
    currentUser.value = rId;

    var flagPopup = $find('userAcceptFlagPopupBehavior');
    flagPopup.show();

    Notisum.WebServices.LawList.GetNodeAcceptFlagsByUser(listId, nodeId, rId, OnOpenUserAccept);
}

function OnOpenUserAccept(result) {
    var processWin = document.getElementById('processWindow6');
    if (processWin == null)
        processWin = window.parent.document.getElementById('processWindow6');

    if (processWin) {
        processWin.style.display = 'none';
    }

    if (result == '[FAIL]')
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEACTIONERR1').value);
    {
        if (result.length > 0) {
            var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_userAcceptListContainer');
            panel.innerHTML = result;
        }
    }
}

function CloseUserAcceptDialog() {
    var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_userAcceptListContainer');
    panel.innerHTML = '';
    var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
    selectedLaw.value = 0;
    var currentUser = document.getElementById('currentUser');
    currentUser.value = 0;
    var selectedFlag = document.getElementById('selectedFlag');
    selectedFlag.vaue = 0;
    var userComment = document.getElementById('UserCommentText');
    userComment.value = '';

    var flagPopup = $find('userAcceptFlagPopupBehavior');
    flagPopup.hide();

    __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$ReloadDocumentGroupExecutor', '');
}

function OpenUpdateFlag(id, nodeId) {
    var selectedFlag = document.getElementById('selectedFlag');
    selectedFlag.value = id;
    var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
    selectedLaw.value = nodeId;

    var flagPopup = $find('UpdateCommentDialogPopupBehavior');
    flagPopup.show();

    Notisum.WebServices.LawList.GetFlagComment(id, OnOpenUpdateFlagDialog);
}

function OnOpenUpdateFlagDialog(result) {
    var comment = document.getElementById('UpdateFlagCommentText');
    if (result == '[FAIL]')
        result = '';
    comment.value = result;
}

function CloseFlagUpdateDialog() {
    var flagPopup = $find('UpdateCommentDialogPopupBehavior');
    flagPopup.hide();
    var comment = document.getElementById('UpdateFlagCommentText');
    comment.value = '';
    var selectedFlag = document.getElementById('selectedFlag');
    selectedFlag.value = '0';
}

function UpdateFlagComment() {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEUPDATEMESSAGEMSG1').value)) {
        var selectedFlag = document.getElementById('selectedFlag');
        var comment = document.getElementById('UpdateFlagCommentText');

        Notisum.WebServices.LawList.UpdateAcceptFlag(selectedFlag.value, comment.value, OnReopenFlagSuccess);
        CloseFlagUpdateDialog();
    }
}  
function AssignDocumentArrayToUser() {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEREBINDUSERDOCUMENTS').value)) {
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$assignUserToDocumentsExecutor', '');
    }
}

function ViewItemMenu(obj) {
    obj.className = 'rnListItemMenuSelected';

    var div = document.getElementById('d' + obj.id);

    var curleft = curtop = 0;

    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop

        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }

    if (div) {
        div.style.display = 'inline-block';
        div.style.top = curtop + 17;
    }
}

function HideItemMenu(obj) {
    obj.className = 'rnListItemMenu';
    var div = document.getElementById('d' + obj.id);

    if (div) {
        div.style.display = 'none';
    }
}

function deleteDocument(listNodeId, prefix) {
    var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
    var relGroup = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_groupToReload');

    selectedLaw.value = listNodeId;

    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEREMOVEDOCUMENTMSG1').value)) {
        relGroup.value = prefix;
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$DeleteDocumentExecutor', '');
    }
}

function selectLaw(RefShort) {
    var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
    var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');

    selectedLaw.value = RefShort;

    if (lawListId.value != '') {
        if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEADDDOCUMENTMSG1').value)) {
            __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$AddDocumentExecutor', '');
        }
    }
}

function acceptNewDocument(id, prefix) {
    var acceptNode = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_acceptNode');
    var relGroup = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_groupToReload');
    acceptNode.value = id;
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEACCEPTMSG3').value)) {
        relGroup.value = prefix;
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$AcceptNodeExecutor', '');
    }
}

function acceptChange(id, prefix) {
    var acceptNode = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_acceptNode');
    var relGroup = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_groupToReload');
    acceptNode.value = id;
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEACCEPTMSG1').value)) {
        relGroup.value = prefix;
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$AcceptNodeExecutor', '');
    }
}

function acceptAll() {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEACCEPTALLMSG1').value)) {
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$AcceptAllDocumentsExecutor', '');
    }
}

function OpenChangeDialog(refShort) {
    var processWin = document.getElementById('processWindow');
    if (processWin == null)
        processWin = window.parent.document.getElementById('processWindow');

    if (processWin) {
        processWin.style.display = 'inline';
    }
    var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_lawChangesPanelInfoContainer');
    panel.innerHTML = '';
    var lawChangesPopup = $find('lawChangesPopupBehavior');
    lawChangesPopup.show();
    Notisum.WebServices.LawList.GetChangeListings(refShort, OnChangeDataSuccess);
}

function OnChangeDataSuccess(result) {
    var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_lawChangesPanelInfoContainer');
    panel.innerHTML = result;
    var processWin = document.getElementById('processWindow');
    if (processWin == null)
        processWin = window.parent.document.getElementById('processWindow');

    if (processWin) {
        processWin.style.display = 'none';
    }
}

function CloseChangesDialog() {
    var lawChangesPopup = $find('lawChangesPopupBehavior');
    lawChangesPopup.hide();
}

function OpenEditDialog(nodeId, listId, prefix) {
    var processWin = document.getElementById('processWindow2');
    if (processWin == null)
        processWin = window.parent.document.getElementById('processWindow2');

    if (processWin) {
        processWin.style.display = 'inline';
    }
    var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_documentEditPanelInfoContainer');
    panel.innerHTML = '';
    var relGroup = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_groupToReload');
    if (relGroup)
        relGroup.value = prefix;
    var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
    if (selectedLaw)
        selectedLaw.value = nodeId;
    var editPopup = $find('editDocumentPopupBehavior');
    editPopup.show();
    Notisum.WebServices.LawList.GetDocumentEditStructure(nodeId, listId, OnEditDataSuccess);
}

function OnEditDataSuccess(result) {
    var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_documentEditPanelInfoContainer');
    panel.innerHTML = result;
    var processWin = document.getElementById('processWindow2');
    if (processWin == null)
        processWin = window.parent.document.getElementById('processWindow2');

    if (processWin) {
        processWin.style.display = 'none';
    }
}

function CloseEditDialog() {
    var relGroup = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_groupToReload');
    if (relGroup)
        relGroup.value = '';
    var selectedLaw = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLaw');
    if (selectedLaw)
        selectedLaw.value = '';
    var editPopup = $find('editDocumentPopupBehavior');
    editPopup.hide();
}

function ApplyChanges() {
    var bete = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_bete');
    var dokn = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_dokn');
    var komm = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_komm');
    var erub = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_erub');
    var ekat = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_ekat');
    var etyp = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_etyp');
    var erub_sel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_erub_sel');
    var ekat_sel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_ekat_sel');
    var etyp_sel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_etyp_sel');
    var pave = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_pave');
    var sutv = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_sutv');
    var kupp = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_kupp');
    var udir = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_udir');
    var ansv = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_ansv');
    var index = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_index');
    var eg6 = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_eg6');
    var eg7 = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_eg7');
    var eg8 = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_inp_eg8');

    var doc_title_sig = document.getElementById('DocumentNodeTitleSignature');
    var doc_title = document.getElementById('DocumentNodeTitle');
    var doc_komm = document.getElementById('DocumentNodeComment');
    var doc_erub = document.getElementById('DocumentNodeCustomHeader');
    var doc_ekat = document.getElementById('DocumentNodeCustomCategory');
    var doc_etyp = document.getElementById('DocumentNodeCustomType');
    var doc_erub_sel = document.getElementById('DocumentNodeCustomHeaderSelect');
    var doc_ekat_sel = document.getElementById('DocumentNodeCustomCategorySelect');
    var doc_etyp_sel = document.getElementById('DocumentNodeCustomTypeSelect');
    var doc_pave = document.getElementById('DocumentNodeInfluence');
    var doc_sutv = document.getElementById('DocumentNodeEvaluation');
    var doc_kupp = document.getElementById('DocumentNodeFullFillment');
    var doc_udir = document.getElementById('DocumentNodeHowToFullFill');
    var doc_ansv = document.getElementById('DocumentNodeResponsible');
    var doc_index = document.getElementById('DocumentNodeIndex');
    var doc_eg6 = document.getElementById('DocumentNodeEg6');
    var doc_eg7 = document.getElementById('DocumentNodeEg7');
    var doc_eg8 = document.getElementById('DocumentNodeEg8');

    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSESAVEDOCUMENTMSG1').value)) {
        if (doc_title_sig)
            dokn.value = doc_title_sig.value;
        if (doc_title)
            dokn.value = doc_title.value;
        if (doc_komm)
            komm.value = doc_komm.value;
        if (doc_erub)
            erub.value = doc_erub.value;
        if (doc_ekat)
            ekat.value = doc_ekat.value;
        if (doc_etyp)
            etyp.value = doc_etyp.value;
        if (doc_erub_sel)
            erub_sel.value = doc_erub_sel.value;
        if (doc_ekat_sel)
            ekat_sel.value = doc_ekat_sel.value;
        if (doc_etyp_sel)
            etyp_sel.value = doc_etyp_sel.value;
        if (doc_pave)
            pave.value = doc_pave.value;
        if (doc_sutv)
            sutv.value = doc_sutv.value;
        if (doc_kupp)
            kupp.value = doc_kupp.value;
        if (doc_udir)
            udir.value = doc_udir.value;
        if (doc_ansv)
            ansv.value = doc_ansv.value;
        if (doc_index)
            index.value = doc_index.value;
        if (doc_eg6)
            eg6.value = doc_eg6.value;
        if (doc_eg7)
            eg7.value = doc_eg7.value;
        if (doc_eg8)
            eg8.value = doc_eg8.value;

        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$ApplyDocumentSettingsExecutor', '');
    }
}

function SelectLawList(id) {
    var listId = id.options[id.selectedIndex].value;
    window.location = 'Wide.aspx?pageid=114&listid=' + listId;
}

function UpdateInheritance() {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEINHERITLISTMSG1').value)) {
        var waitDlg = $find('LawListWaitDialogPopupBehavior');
        waitDlg.show();
        var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
        Notisum.WebServices.LawList.UpdateInheritance(lawListId.value, OnUpdateInheritanceSuccess);
    }
}

function OnUpdateInheritanceSuccess(result) {
    var waitDlg = $find('LawListWaitDialogPopupBehavior');
    waitDlg.hide();
    if (result == '[FAIL]') {
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEACTIONERR1').value);
    }
    else {
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEINHERITLISTSUCCESSMSG1').value);
        // do postback to update entire list. 
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$UpdateInheritanceExecutor', '');
    }
}
function selectAllGroupDocuments(prefix) {
    var ctrls = new Array();
    ctrls = document.getElementsByName('item_select');

    if (ctrls) {
        for (var i = 0; i < ctrls.length; i++) {
            var control = ctrls.item(i);

            if (control.attributes.getNamedItem("Id").nodeValue.indexOf('_' + prefix + '_') > 1) {
                if (control.checked == true)
                    control.checked = false;
                else
                    control.checked = true;

                AppendLawListDocumentToArray(control);
            }
        }
    }
}
function PopuplateSelectedLawListDocuments() {
    var ctrls = new Array();
    ctrls = document.getElementsByName('item_select');

    if (ctrls) {
        for (var i = 0; i < ctrls.length; i++) {
            var c = ctrls.item(i);
            c.checked = IsLawListDocumentInArray(c.value);
        }
        //HighLightAddArray(); 
    }
}
function AppendLawListDocumentToArray(control) {
    var array = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawListDocumentsArray');

    if (array) {
        if (control.checked == true) {
            // Add to array
            array.value = array.value + control.value + ',';
        }
        else {
            // Remove from array
            array.value = array.value.replace(control.value + ',', '');
        }
        //HighLightAddArray(); 
    }
}
function IsLawListDocumentInArray(listNodeId) {
    var array = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawListDocumentsArray');

    if (array) {
        if (array.value.indexOf(listNodeId) > -1)
            return true;
        else
            return false;
    }
    else
        return false;
}
function CollectSelectedDocuments() {
    var ctrls = new Array();
    ctrls = document.getElementsByName('item_select');

    if (ctrls) {
        var selArray = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawListDocumentsArray');
        selArray.value = '';
        for (var i = 0; i < ctrls.length; i++) {
            var control = ctrls.item(i);
            if (control.checked == true)
                selArray.value = selArray.value + control.attributes.getNamedItem("id").nodeValue + ',';
        }
    }
}
function SelectAllLawListDocuments() {
    var ctrls = new Array();
    ctrls = document.getElementsByName('item_select');

    var array = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawListDocumentsArray');
    var isSelected = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_IsAllLawListDocumentsSelected');

    if (array) {
        if (ctrls) {
            if (isSelected.value == '0') {
                array.value = '';
                isSelected.value = '1';
            }
            else
                isSelected.value = '0';
            for (var i = 0; i < ctrls.length; i++) {
                var control = ctrls.item(i);

                if (isSelected.value == '1') {
                    // Add to array
                    array.value = array.value + control.value + ',';
                    control.checked = true;
                }
                else {
                    // Remove from array
                    control.checked = false;
                    array.value = array.value.replace(control.value + ',', '');
                }
            }
            //HighLightAddArray(); 
        }
    }
}
function DeselectAllLawListDocuments() {
    var ctrls = new Array();
    ctrls = document.getElementsByName('item_select');

    var array = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawListDocumentsArray');
    var isSelected = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_IsAllLawListDocumentsSelected');

    if (array) {
        if (ctrls) {
            isSelected.value = '0';
            array.value = '';

            for (var i = 0; i < ctrls.length; i++) {
                var control = ctrls.item(i);
                control.checked = false;
            }
            //HighLightAddArray(); 
        }
    }
}
function deleteSelectedDocuments() {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEDELETESELECTEDDOCUMENTS').value)) {
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$deleteSelectedLawListDocumentsExecutor', '');
    }
}
function copySelectedDocuments() {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSECOPYSELECTEDDOCUMENTS').value)) {
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$copySelectedLawListDocumentsExecutor', '');
    }
}
function inheritSelectedDocumentsToUser() {
    if (confirm('Är du säker på att du vill koppla dokumenten till vald användare på nytt?')) {
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$copySelectedLawListDocumentsAndInheritExecutor', '');
    }
}
function AppendUserToArray(control) {
    var array = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedDocumentUsersArray');

    if (array) {
        if (control.checked == true) {
            // Add to array
            array.value = array.value + control.value + ',';
        }
        else {
            // Remove from array
            array.value = array.value.replace(control.value + ',', '');
        }
    }
}
function MoveCopyList(action) {
    var actionInp = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_MoveCopyListAction');
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSECOPYMOVEMSG').value)) {
        actionInp.value = action;
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$MoveCopyListExecutor', '');
    }
}
function setCustomInformation() {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSESETCUSTOMTEXT').value)) {
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$SetCustomInfoExecutor', '');
    }
}
function removeCustomInformation() {
    if (confirm(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEREMOVECUSTOMTEXT').value)) {
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$RemoveCustomInfoExecutor', '');
    }
}
var replaceRefShort = '';
var noConnection = 1;
function AddReplacementDocument(refshort, nodeId) {
    var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_addReplacmentDocumentDescription');
    panel.innerHTML = '';
    var q = document.getElementById('checkIfDocumentExistsQuery');
    q.value = '';
    noConnection = 1;
    var status = document.getElementById('addReplacementDocumentManuallySearchStatus');
    status.innerText = status.textContent = '';
    replaceRefShort = refshort;
    document.getElementById('replaceDocument').value = nodeId;
    Notisum.WebServices.LawList.CheckDocumentToReplace(refshort, OnAddReplacementDocumentSuccess);
}
function OnAddReplacementDocumentSuccess(result) {
    var manAdd = document.getElementById('addReplacementDocumentManually');
    manAdd.style.display = 'none';
    if (result == '[FAIL]') {
        alert('Ett fel inträffade, kontakta Notisums kundtjänst.');
    }
    else {
        if (result == '[NOTEXIST]') {
            alert('Ett fel inträffade, kontakta Notisums kundtjänst.');
        }
        else {
            if (result == '[NOCONNECTION]') {
                alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_RESPONSEADDREPLACEMENTERR').value);
                manAdd.style.display = 'inline';
                var repPopup = $find('addReplacmentDocumentPopupBehavior');
                repPopup.show();                
            }
            else {
                noConnection = 0;
                var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_addReplacmentDocumentDescription');
                var a = new Array();
                a = result.split(';');
                panel.innerHTML = 'Dokumentet har ersats med ' + a[1].replace('[', '').replace(']', '') + ', vill du lägga till det nya dokumentet i laglistan?';
                document.getElementById('replaceWithDocument').value = a[0].replace('[', '').replace(']', '');
                var repPopup = $find('addReplacmentDocumentPopupBehavior');
                repPopup.show();
            }
        }
    }
}
function checkIfDocumentExists() {
    var status = document.getElementById('addReplacementDocumentManuallySearchStatus');
    status.innerText = status.textContent = '';
    noConnection = 1; 
    var q = document.getElementById('checkIfDocumentExistsQuery');
    if (q) {
        if (q.value == '') {
            alert('Det finns ingen beteckning att söka på, kontrollera och försök igen.');
        }
        else {
            Notisum.WebServices.LawList.CheckIfExists(q.value, replaceRefShort, OnCheckIfExistsSuccess);   
        }
    }    
}
function OnCheckIfExistsSuccess(result) {
    if (result == '[FAIL]') {
        alert('Ett fel inträffade, kontakta Notisums kundtjänst.');
    }
    else {
        if (result == '[NOTEXIST]') {
            alert('Kunde inte hitta något dokument med angiven beteckning, kontrollera informationen och försök igen.');           
        }
        else {
            var status = document.getElementById('addReplacementDocumentManuallySearchStatus');
            status.innerText = status.textContent = 'OK';
            noConnection = 0;
            var a = new Array();
            a = result.split(';');
            document.getElementById('replaceWithDocument').value = a[0].replace('[', '').replace(']', '');                        
        }        
    }
}
function CloseAddReplacementDialog() {
    var repPopup = $find('addReplacmentDocumentPopupBehavior');
    repPopup.hide();
}
function AddDocumentReplacement() {
    if (noConnection == 0) {
        var replaceWith = document.getElementById('replaceWithDocument');
        var replace = document.getElementById('replaceDocument');
        var copyInfo = document.getElementById('chkReplaceDocumentInfo');
        var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
        //alert(replaceWith.value + ' ' + replace.value + ' ' + copyInfo.checked + ' ' + lawListId.value);
        Notisum.WebServices.LawList.AddReplacementDocument(replace.value, replaceWith.value, copyInfo.checked, lawListId.value, OnAddDocumentReplacementSuccess);
    }
    else {
        alert('Det finns inget verifierat dokument att ersätta med, kontrollera och försök igen.');    
    }
}
function OnAddDocumentReplacementSuccess(result) {
    CloseAddReplacementDialog();
    if (result == '[FAIL]') {
        alert('Ett fel inträffade och dokumentet kunde inte läggas till i laglistan, kontakta Notisums kundtjänst.');
    }
    else {
        if (result == '[SUCCESS]') {
            alert('Dokumentet har lagts till i laglistan som nu kommer att laddas om.');
            __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$UpdateInheritanceExecutor', '');
        }
        else {
            alert(result);
        }
    }
}
function InputCheck(inp, max, lbl) {
    //alert(inp.value.length + ' - ' + max);
    if (inp.value.length >= max) {
        inp.value = inp.value.substring(0, max);
        alert('Fältet kan inte innehålla mer än '+max+' tecken.');
    }
}

    function ExecuteClientSearch()
    {
        var directMsg = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_GenericFindDocumentControl_directAddMsgContainer');
        if(directMsg) 
            directMsg.style.display = 'none'; 
        var query = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_GenericFindDocumentControl_SearchString');
        if(query.value.length > 0){ 
            var proc = document.getElementById('searchProcess');
            proc.style.display = 'inline';   
            Notisum.WebServices.Document.SearchSimple(query.value, OnSearchComplete, OnSearchFail);
       } 
    } 

    function ExecuteClientSearchNoAdd()
    {
        var query = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_GenericFindDocumentControl_SearchString');
        var proc = document.getElementById('searchProcess');
        proc.style.display = 'none';   
        Notisum.WebServices.Document.SearchSimple(query.value, OnSearchCompleteNoAdd, OnSearchFail);
    } 
    
    function executeState()
    {
        var query = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_GenericFindDocumentControl_SearchString');

        if(query.value.length > 0)
            ExecuteClientSearch();
    } 

    function OnSearchFail(result)
    {
        var proc = document.getElementById('searchProcess');
        proc.style.display = 'none';
        alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_GenericFindDocumentControl_RESPONSESEARCHERR1').value+' \n\n' + result);
    } 

    function OnSearchComplete(result)
    {
        if(result == '[NODOCS]')
        {
            alert(document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_GenericFindDocumentControl_RESPONSESEARCHERR1').value);
        } 
        else
        {             
            if(result.substr(0,11) == "[DIRECTADD]")
            {
                var proc = document.getElementById('searchProcess');
                proc.style.display = 'none';  
                var arr = result.split(',');
                var add = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_GenericFindDocumentControl_directAddShortRef'); 
                add.value = arr[arr.length - 1];
                __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$GenericFindDocumentControl$DirectAddExecutor',''); 
            }
            else
            {
                var proc = document.getElementById('searchProcess');
                proc.style.display = 'none';   
                var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_GenericFindDocumentControl_searchResultContainer'); 
                panel.innerHTML = result; 
            }  
        }  
    } 

    function OnSearchCompleteNoAdd(result)
    {
        if(result == '[NODOCS]')
        {
            //alert('Ett fel inträffade och sökningen genomfördes inte som den skulle. Försök igen och om felet återkommer kontakta Notisum kundtjänst.');
        } 
        else
        {             
            if(result.substr(0,11) == "[DIRECTADD]")
            {
                var proc = document.getElementById('searchProcess');
                proc.style.display = 'none';  
            }
            else
            {
                var proc = document.getElementById('searchProcess');
                proc.style.display = 'none';   
                var panel = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_GenericFindDocumentControl_searchResultContainer'); 
                panel.innerHTML = result; 
            }  
        }  
    }     
function editNodeLink(linkId)
{
    var selUrl = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedUrlId');
    selUrl.value = linkId; 
    __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$SelectLinkExecutor','');
}

function removeNodeLink(linkId)
{
    var selUrl = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedUrlId');
    selUrl.value = linkId; 
    if (confirm('Är du säker på att du vill ta bort denna länk?'))
    {
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$RemoveLinkExecutor','');
    }   
}

function editNodeComment(commentId)
{
    var selCom = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedCommentId');
    selCom.value = commentId; 
    __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$SelectCommentExecutor','');
}

function removeNodeComment(commentId)
{
    var selCom = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedCommentId');
    selCom.value = commentId; 
    if (confirm('Är du säker på att du vill ta bort denna kommentar?'))
    {
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$RemoveCommentExecutor','')
    }  
}

function saveListNode()
{
    if (confirm('Är du säker på att du vill ändra inställningarna för detta dokument?'))
    {
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$SaveDocumentExecutor','');
    } 
}

function saveReturnListNode()
{
    if (confirm('Är du säker på att du vill ändra inställningarna för detta dokument?'))
    {
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$SaveReturnExecutor','');
    } 
}

function saveList()
{
    if (confirm('Är du säker på att du vill ändra inställningarna för denna lista?'))
    {
        __doPostBack('_ctl0$ContentPlaceHolder$GenericLayout$GenericBodyLayout$DynamicContentControl$_ctl0$SaveListExecutor','');
    } 
}
   
function resetAllValues()
{
    if (confirm('Är du säker på att du vill återställa alla inställningarna för utskrift, åtgärden kan inte ångras?'))
    {
        __doPostBack('_ctl0$ContentPlaceHolder$GenericLayout$GenericBodyLayout$DynamicContentControl$_ctl0$ResetPrintValuesExecutor','');
    }        
}
   
function saveReturnList()
{
    if (confirm('Är du säker på att du vill ändra inställningarna för denna lista?'))
    {
        __doPostBack('_ctl0$ContentPlaceHolder$GenericLayout$GenericBodyLayout$DynamicContentControl$_ctl0$SaveReturnExecutor','');
    } 
}

function saveListAsNew()
{
    if (confirm('En ny laglista kommer att skapas, vill du fortsätta?'))
    {
        __doPostBack('_ctl0$ContentPlaceHolder$GenericLayout$GenericBodyLayout$DynamicContentControl$_ctl0$SaveListExecutor','');
    } 
}

function deleteList()
{
    if(confirm('Är du säker på att du vill ta bort denna lista?'))
    {  
        __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericBodyLayout$DynamicContentControl$_ctl0$DeleteListExecutor','');
    }     
}

function saveColumns()
{
    if(confirm('Är du säker på att du till spara kolumninställningarna?'))
    {  
        __doPostBack('_ctl0$ContentPlaceHolder$GenericLayout$GenericBodyLayout$DynamicContentControl$_ctl0$SaveColumns','');
    }         
}

function saveColumnsAndReturn()
{
    if(confirm('Är du säker på att du till spara kolumninställningarna?'))
    {  
        __doPostBack('_ctl0$ContentPlaceHolder$GenericLayout$GenericBodyLayout$DynamicContentControl$_ctl0$SaveReturnColumns','');
    }         
}

function restoreColumns()
{
    if(confirm('Alla kolumner kommer att återställas till orginalnamnenmen. Vill du fortsätta?'))
    {  
        __doPostBack('_ctl0$ContentPlaceHolder$GenericLayout$GenericBodyLayout$DynamicContentControl$_ctl0$RestoreColumns','');
    }         
}

function AddDocumentToLawList2()
{
    if(confirm('Är du säker på att du vill lägga till dokumentet i vald lista?'))
    {                             
        var executor = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericRightPaneLayout_LoggedInUser_AddToLawListExecutor');
       
        if (executor != null)
             __doPostBack('_ctl0$ContentPlaceHolder$GenericLayout$GenericRightPaneLayout$LoggedInUser$AddToLawListExecutor','');
                     
        if (executor == null)
        { 
            executor = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericRightPaneLayout_LoggedInUser_AddToLawListExecutor');
           
            if (executor != null)
                __doPostBack('_ctl0$ContentPlaceHolder$WideLayout$GenericRightPaneLayout$LoggedInUser$AddToLawListExecutor','');                   
        }             
            
        if (executor == null)
        { 
            executor = document.getElementById('_ctl0_ContentPlaceHolder_GenericRightPaneLayout_LoggedInUser_AddToLawListExecutor');

            if (executor != null)
                __doPostBack('_ctl0$ContentPlaceHolder$GenericRightPaneLayout$LoggedInUser$AddToLawListExecutor','');                                      
        }                                          
    }         
}

function AddDocumentToLawList()
{
    var selectedDoc = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericRightPaneLayout_LoggedInUser_selectedDocumentToAdd');
    if (selectedDoc == null)
        selectedDoc = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericRightPaneLayout_LoggedInUser_selectedDocumentToAdd');  
    if (selectedDoc == null)
        selectedDoc = document.getElementById('_ctl0_ContentPlaceHolder_GenericRightPaneLayout_LoggedInUser_selectedDocumentToAdd');  

    var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericRightPaneLayout_LoggedInUser_MyAvailableLawLists');
    if (lawListId == null)
        lawListId = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericRightPaneLayout_LoggedInUser_MyAvailableLawLists');
    if (lawListId == null)
       lawListId = document.getElementById('_ctl0_ContentPlaceHolder_GenericRightPaneLayout_LoggedInUser_MyAvailableLawLists');    
          
    Notisum.WebServices.LawList.AddDocumentToLawList(selectedDoc.value, lawListId.value, OnAddDocumentSucceeded, OnFail);
}

function AddArrayToLawListExt()
{
    var array = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericRightPaneLayout_LoggedInUser_selectedDocumentsArray');
    if (array == null)
        array =  document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericRightPaneLayout_LoggedInUser_selectedDocumentsArray');
    if (array == null)
        array = document.getElementById('_ctl0_ContentPlaceHolder_GenericRightPaneLayout_LoggedInUser_selectedDocumentsArray');

    var lawListId = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericRightPaneLayout_LoggedInUser_MyAvailableLawLists2');
    if (lawListId == null)
        lawListId = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericRightPaneLayout_LoggedInUser_MyAvailableLawLists2');
    if (lawListId == null)
       lawListId = document.getElementById('_ctl0_ContentPlaceHolder_GenericRightPaneLayout_LoggedInUser_MyAvailableLawLists2');      
 
    Notisum.WebServices.LawList.AddArrayToLawList(array.value, lawListId.value, OnAddArraySucceeded, OnFail);
    DeselectAll();
}

function OnAddArraySucceeded(result)
{
    if(result != '[SUCCESS]')
   {         
        alert('Ett fel inträffade och dokumenten kunde inte läggs till i din laglista. Prova igen och om felet återkommer så kontakta Notisum Kundtjänst.\n\nFel : '+result);
   } 
   else
   {
        alert('Dokumenten har lagts till i din laglista.');       
        CloseAddArrayToLawListExt(); 
   }
}

function OnAddDocumentSucceeded(result)
{
    if(result != '[SUCCESS]')
   {         
        alert('Ett fel inträffade och dokumentet kunde inte läggs till i din laglista. Prova igen och om felet återkommer så kontakta Notisum Kundtjänst.\n\nFel : '+result);
   } 
   else
   {
        alert('Dokumentet har lagts till i din laglista.');       
        CloseAddToLawListExt(); 
   }
}

function OnFail(result)
{
    alert('Ett fel inträffade och dokumentet kunde inte läggs till i din laglista. Prova igen och om felet återkommer så kontakta Notisum Kundtjänst.\n\nFel : '+result);
    CloseAddToLawListExt(); 
    CloseAddArrayToLawListExt(); 
}

function CloseAddToLawListExt()
{
    var AddToLawListPopup = $find('programmaticModalPopupBehavior5');
    AddToLawListPopup.hide(); 
} 

function CloseAddArrayToLawListExt()
{
    var AddToLawListPopup = $find('programmaticModalPopupBehavior8');
    AddToLawListPopup.hide(); 
} 

function ShowPrinterOptions()
{
    var ShowPrinterOptionsPopup = $find('programmaticModalPopupBehavior6');
    ShowPrinterOptionsPopup.show(); 
}

function ClosePrinterOptions()
{
    var ShowPrinterOptionsPopup = $find('programmaticModalPopupBehavior6');
    ShowPrinterOptionsPopup.hide(); 
}

function executePrint(c,o)
{
   var selection1 = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericRightPaneLayout_LoggedInUser_printOptions_0');
   var selection2 = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericRightPaneLayout_LoggedInUser_printOptions_1');
   var selection3 = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericRightPaneLayout_LoggedInUser_printOptions_2');
   
   ClosePrinterOptions();
   if (selection2.checked == true) {
       generateExcelXml(c, o);
   }   
   if (selection3.checked == true)
   {        
        window.print(); 
   }
   if (selection1.checked == true)
   {
        generatePdf(c,o);
   }
}  

function printToPdf(c,o)
{
   if(confirm('Om några inställningar har ändrats för laglistan så måste du se till att dessa har sparats först. \r\nVill du fortsätta?'))
   {
        generatePdf(c,o);
   } 
}

function generateExcelXml(c, o) {
    var waitDlg = $find('programmaticModalPopupBehavior7');
    waitDlg.show();

    var l = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
    if (l == null)
        l = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawListId');

    Notisum.WebServices.LawList.PrintToExcelXml(l.value, o, c, OnPrintSuccess);        
}

function generatePdf(c,o)
{
    var waitDlg = $find('programmaticModalPopupBehavior7');
    waitDlg.show();     
    var l = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawList');
    if (l == null)
        l = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_selectedLawListId');

    Notisum.WebServices.LawList.PrintToPdf(l.value,o,c,OnPrintSuccess,OnPrintFail);
}

function ClosePDFClientLinkDlg() {
    var waitDlg = $find('programmaticModalPopupBehavior7');
    waitDlg.hide();
    var waitRow = document.getElementById("WaitRow");
    var linkRow = document.getElementById("LinkRow");
    var anchor = document.getElementById("PDFClientLink");

    waitRow.style.display = 'inline';
    linkRow.style.display = 'none';    
}

function OnPrintSuccess(result) {

    var outPut = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_pdfOutputMode');
    if (outPut == null)
        outPut = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_pdfOutputMode');
    var outputMode = outPut.value;

    if (result == '[FAIL]')
    {
        alert('Ett fel inträffade och laglistan skrevs inte ut. Prova igen och om felet återkommer så kontakta Notisum Kundtjänst.');
        var waitDlg = $find('programmaticModalPopupBehavior7');
        waitDlg.hide();
    }
    else
    {
        var waitDlg = $find('programmaticModalPopupBehavior7');

        if (outputMode == 1) {
            waitDlg.hide();
            var pdfWin = window.open(result, "pdf");
            if (!pdfWin.opener) {
                pdfWin.opener = self;
            }
            pdfWin.focus()
        }
        else {
            var waitRow = document.getElementById("WaitRow");
            var linkRow = document.getElementById("LinkRow");
            var anchor = document.getElementById("PDFClientLink");

            anchor.href = result;
            waitRow.style.display = 'none';
            linkRow.style.display = 'inline';
        }
    }    
}

function OnPrintFail(result)
{
    var waitDlg = $find('programmaticModalPopupBehavior7');
    waitDlg.hide();    

    alert('Ett fel inträffade och laglistan skrevs inte ut. Prova igen och om felet återkommer så kontakta Notisum Kundtjänst.');
}
