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

FILE : /rsc/js/author_query_functions.js

CREATED : 27 September 2005

LAST MODIFIED : $Revision: 1.2 $ ($Date: 2005/09/28 17:03:38 $ by $Author: whedley $)

AUTHOR : Warren Hedley and Yuhong Ning

DESCRIPTION : This script file contains functions that are used by authors on the query sections
  of the Molecule Pages (and elsewhere). It only needs to be referenced when author tools (such
  as creation, editing, and deletion links) are available. It makes use of functions from
  molpages.js (functions starting with 'mp').

  All function names start with 'aq' to help avoid naming conflicts.

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

/**
 * Called from the state list to confirm that a state is to be deleted.
 */
function aqConfirmStateDeletion(uri) {
  if (confirm('Are you sure you want to delete this state?')) {
    mpOpenNewWindow(uri, 'deleteState');
  }
} // function aqConfirmStateDeletion()



/**
 * Called when the "create transition form" on the transition list page is submitted. This checks
 * that two states have been selected and always returns false (so that the user doesn't proceed
 * to the 'no javascript' page).
 */
function aqCreateTransition(baseUri) {
  if (document.createTransitionForm) {
    var startingStateId = document.createTransitionForm.initialState.value;
    var endingStateId = document.createTransitionForm.endState.value;

    if ( startingStateId == '' || endingStateId == '' ) {
      alert('Please select starting and ending states then click "Go".');
    } else if ( startingStateId == endingStateId) {
      alert('The starting and ending states must be different.');
    } else {
      mpOpenNewWindow(baseUri + '&initialState=' + startingStateId +
          '&endState=' + endingStateId, 'createTransition');
    }
  }
  return false;
} // function aqCreateTransition()



/**
 * Called from the transition list to confirm that a single transition is to be deleted.
 */
function aqConfirmTransitionDeletion(uri) {
  if (confirm('Are you sure you want to delete this transition?')) {
    mpOpenNewWindow(uri, 'deleteTransition');
  }
} // function aqConfirmTransitionDeletion()



/**
 * Called from the "create function" form on the function list page to check that a state has
 * been specified before allowing the user to enter function data.
 */
function aqCreateFunction(baseUri) {
  if (document.addFunctionForm) {
    var stateId = document.addFunctionForm.state_id.value;
    if (stateId == -1) {
      alert('Please select a state from the list and then click "Add Functional Data".');
    } else {
      mpOpenNewWindow(baseUri + '&state_id=' + stateId, 'createFunction');
    }
  }
  return false;
} // function aqCreateFunction()



/**
 * Called from the function list to confirm that a function is to be deleted.
 */
function aqConfirmFunctionDeletion(uri) {
  if (confirm('Are you sure you want to delete this function?')) {
    mpOpenNewWindow(uri, 'deleteFunction');
  }
} // function aqConfirmFunctionDeletion()



/**
 * Called from the function list to confirm that the enzyme function associated with an intrinsic
 * enzyme activity transition is to be deleted.
 */
function aqConfirmEnzymeFunctionDeletion(uri) {
  if (confirm('Are you sure you want to delete the specified enzyme function, which ' +
      'is associated with an intrinsic enzyme activity transition?')) {
    mpOpenNewWindow(uri, 'deleteTransition');
  }
} // function aqConfirmEnzymeFunctionDeletion()



/**
 * Called from the protein class list to confirm that a class is to be deleted.
 */
function aqConfirmClassDeletion(uri) {
  if (confirm('If you delete this class, any associated class states will also be deleted. ' +
      'Are you sure you want to delete this class?')) {
    mpOpenNewWindow(uri, 'deleteClass');
  }
} // function aqConfirmClassDeletion()
