/*==================================================================================================

FILE : /rsc/js/review-functions.js

CREATED : 20 January 2004

LAST MODIFIED : $Revision: 1.9 $ ($Date: 2005/01/13 00:11:53 $ by $Author: whedley $)

AUTHOR : Warren Hedley

DESCRIPTION : This stylesheet may be loaded by query pages that display author-entered data to make
  functions used during the peer-review process available to the user.

==================================================================================================*/

/**
 * The window options used for the popup review window.
 */
var RF_WINDOW_OPTIONS = 'toolbar=no,location=no,directories=no,menubar=no,status,' +
    'scrollbars,resizable,width=700,height=600';


/**
 * This is called when a reviewer decides to reject the author's data. It sets the 'no comment'
 * value to 0 (although this is actually irrelevant for rejections) and sets the form's target
 * to mpPeerReviewWindow so that form submission will cause a new window to be opened.
 */
function rfSetReject(formId) {
  document.forms[formId].nc.value = '0';
  document.forms[formId].target = 'mpPeerReviewWindow';
}


/**
 * This is called when the reviewer decides to accept the author's data with a comment. It sets
 * the 'no comment' value to 0 and sets the form's target to mpPeerReviewWindow so that form
 * submission will cause a new window to be opened.
 */
function rfSetAcceptWithComment(formId) {
  document.forms[formId].nc.value = '0';
  document.forms[formId].target = 'mpPeerReviewWindow';
}


/**
 * This is called when the reviewer decides to accept the author's data without a comment. It sets
 * the 'no comment' value to 1 and sets the form's target to _self so that form submission will
 * not cause a new window to be opened.
 */
function rfSetAcceptWithNoComment(formId) {
  document.forms[formId].nc.value = '1';
  document.forms[formId].target = '_self';
}


/**
 * This is called when a reviewer submits a review form in a review banner. It should receive
 * as an argument the target of the form. If the target is mpPeerReviewWindow then it opens a
 * a new window into which the content generated as a result of form submission will be rendered.
 */
function rfProcessReviewSubmission(target) {
  if (target == 'mpPeerReviewWindow') {
    rfOpenReviewWindow();
  }
}


/**
 * This is called when we want to open a window to display the review item editor or history
 * display. It opens a window with a target of mpPeerReviewWindow and with the options specified
 * in the constant at the top of this file. The target of the link or form should be
 * mpPeerReviewWindow which will cause the new page to be rendered into the new window.
 */
function rfOpenReviewWindow() {
  var newWin = window.open('', 'mpPeerReviewWindow', RF_WINDOW_OPTIONS);
  newWin.focus();
  if ( newWin.opener ==  null ) {
    newWin.opener = self;
  }
}


/**
 * This is called when a user attempts to delete data with which an active review item is
 * associated. It alerts them to the fact that they must process the active review item before
 * they can delete the data.
 */
function rfReviewableDataNeedsComment() {
  var msg = '';
  msg += 'You must reply to the peer review comments associated with these data before you can ';
  msg += 'delete it. Click on the review status icon to enter comments.';
  alert(msg);
}
