/* Action Functions */

function leave ( viewName ) {
  destination = "index.php?view="+viewName;
  document.actionForm.action = destination; 
  doAction('saveData', 'savestate');
} // END confirmSave


function warning ( warningName ) {
  switch (warningName) {
   case 'save' : {
    warningText = "You are about to overwrite all previously saved data with current work.";
   } break;
   case 'load' : {
    warningText = "You are about to overwrite all current work with previously saved data.";
   } break;
   case 'flush' : {
    warningText = "You are about to flush all current work and discard all changes since last save.";
   } break;
   case 'leave' : {
    warningText = "You are about to leave this page. Press OK to save changes.";
   } break;
   case 'convert' : {
    warningText = "You are about to overwrite all current work with data converted from a v1 installation."
   } break;
   case 'publish' : {
    warningText = "You are about to overwrite current production data with most previously saved data."
   } break;
   case 'saveform' : {
    warningText = "Do you wish to save this form?";
   } break;
   default : {
    warningText = "";
   } break;
  } // END switch
  warningText += " This process is irreversible.\n\nDo you wish to continue?";

  return (window.confirm(warningText));
} // END warning


function doAction ( actionName ) {
  if (arguments.length > 1) document.actionForm.args.value = arguments[1];
  document.actionForm.actionName.value = actionName;
  document.actionForm.submit();
  return true;
} // END doAction


function setCkbox ( ckboxID, value ) {
} // END setCkbox

function setValue ( inputID, value ) {
  if (document.getElementById(inputID))
    document.getElementById(inputID).value = value;    
} // END setValue

function gotoAnchor ( anchorID ) {
  if (document.getElementById(anchorID)) {
    window.scrollTo(0,document.getElementById(anchorID).offsetTop);
  } // END if
} // END gotoAnchor

function checkAccepted ( ) {
  acceptImg = document.getElementById('accept');
  declineImg = document.getElementById('decline');
  acceptedValue = document.actionForm.accepted.value;
  if ( !acceptedValue ) acceptedValue = 'visible';
  acceptImg.style.visibility  = ((acceptedValue == 'visible') ? 'visible' : 'hidden');
  declineImg.style.visibility = ((acceptedValue == 'visible') ? 'hidden' : 'visible');
} // END checkAccepted

function toggle ( toBeToggled ) {
  acceptImg  = document.getElementById('accept');
  declineImg = document.getElementById('decline');
  if ( acceptImg.style.visibility == declineImg.style.visibility ) {
    with ( document.getElementById(toBeToggled) ) {
      style.visibility = 'hidden';
    } // END with
  } // END if
  acceptImg.style.visibility  = ((  accept.style.visibility == 'visible' ) ? 'hidden' : 'visible');
  declineImg.style.visibility = (( decline.style.visibility == 'visible' ) ? 'hidden' : 'visible');
  document.getElementById('accepted').value = acceptImg.style.visibility;
} // END toggle
