﻿function OpenWorkflowChangeRequest(id, formMode, radWindowClientId, refreshClientId) {

    var targetLoc = "/CMSModules/Workflow/Pages/ShowChangeRequest.aspx?id=" + id + "&formMode=" + formMode + "&refreshBtnId=" + refreshClientId;
    var windId = 'WfWindow' + id;
    wfWindow = window.open(targetLoc, windId, 'width=735,height=400,location=0,menubar=0,scrollbars=1,status=0,toolbar=0,resizable=0');
    wfWindow.focus(); 
    return false;
}
function CloseWorkflowChangeRequest(radWindowClientId) 
{
    window.close();
}
function OnApprove(linkBtn, actionPanelClientId, commentStatusFieldId, workflowActionTypeFieldId) 
{
    HideComment(commentStatusFieldId);
    var actionPanelClientId = '#' + actionPanelClientId;
    $(actionPanelClientId).slideDown();
    $(actionPanelClientId).data('SlideStatus', 'down');
    $get(workflowActionTypeFieldId).value = 'Approve';
    HighlightAction(linkBtn);
    return false;
}
function OnReject(linkBtn, actionPanelClientId, commentStatusFieldId, workflowActionTypeFieldId) 
{
    ShowComment(commentStatusFieldId, false);
    var actionPanelClientId = '#' + actionPanelClientId;
    $(actionPanelClientId).slideDown();
    $(actionPanelClientId).data('SlideStatus', 'down');
    $get(workflowActionTypeFieldId).value = 'Reject';
    HighlightAction(linkBtn);
    return false;
}
function OnCancel(linkBtn, actionPanelClientId, commentStatusFieldId, workflowActionTypeFieldId) 
{
    ShowComment(commentStatusFieldId, false);
    var actionPanelClientId = '#' + actionPanelClientId;
    $(actionPanelClientId).slideDown();
    $(actionPanelClientId).data('SlideStatus', 'down');
    HighlightAction(linkBtn);
    $get(workflowActionTypeFieldId).value = 'Cancel';
    return false;
}
function HighlightAction(linkBtn, wfActionType) 
{
    UnHighlightActions();
    $(linkBtn).attr('class', 'activeWfAction');
}
function UnHighlightActions()
{
    $('#wfActionList a').each(function(i) 
    {
        this.className = '';
    });
}
function ShowComment(commentStatusFieldId, showHideComment) 
{
    $('#commentTextbox').css('display', 'block');
    $('#makeCommentOption').css('display', 'none');
    $get(commentStatusFieldId).value = 'visible';

    if (showHideComment) 
    {
        $('#closeCommentOption').css('display', 'block');
    }
}
function HideComment(commentStatusFieldId) 
{
    $('#commentTextbox').css('display', 'none');
    $('#makeCommentOption').css('display', 'block');
    $('#closeCommentOption').css('display', 'none');
    $get(commentStatusFieldId).value = 'hidden';
}
function CancelAction(actionPanelClientId) 
{
    var actionPanelClientId = '#' + actionPanelClientId;
    $(actionPanelClientId).slideUp('normal', function() { UnHighlightActions(); });
    $(actionPanelClientId).data('SlideStatus', 'up');
    return false;
}
function OnConfirm(wfActionType, commentClientId, commentRequiredReject, commentRequiredCancel) 
{
    var valid = true;
    switch (wfActionType) 
    {
        case 'Reject':

            var comment = $find(commentClientId).get_element().value;
            if (commentRequiredReject && comment.length < 1) 
            {
                valid = false;
                alert('Please enter a comment');
                $find(commentClientId).focus();
            }
            break;

        case 'Cancel':

            var comment = $find(commentClientId).get_element().value;
            if (commentRequiredCancel && comment.length < 1) 
            {
                valid = false;
                alert('Please enter a comment');
                $find(commentClientId).focus();
            }
            break;
    }
    return valid;
}
