/******************************************************************************
 *
 *                   INDIGEN SOLUTIONS CODE PROPERTY
 *       The present javascript code is property of Indigen Solutions. This 
 *     code can only be used inside Internet/Intranet web sites located on 
 *  *web servers*, as the outcome of a licensed Indigen Solutions application 
 *  only. Any unauthorized use, reverse-engineering, alteration, transmission, 
 * transformation, facsimile, or copying of any means (electronic or not) is 
 *     strictly prohibited and will be prosecuted. Removal of the present 
 *              copyright notice is strictly prohibited
 *         Copyright (c) 2004 Indigen Solutions. All Rights Reserved.
 *
 * RCS Id                       $Id: admin.js,v 1.18 2006/07/01 06:45:51 jerome Exp $
 * RCS Revision                 $Revision: 1.18 $
 * RCS Check in date            $Date: 2006/07/01 06:45:51 $
 * 
 ******************************************************************************/

/**
 * @todo
 *   rename myEditorButtons
 *   (OK) rename language
 */

/* Globals. */

var myEditorButtons = new Array();
var _taskLoggingFrameLoaded = false;

/* Functions. */

function getObjectContentLink(objid, language) {
  return "m=6&h=" + myHistoryThreadid + "&l=" + myLanguage + "&x=objectcontent&i=" + objid;
}

function getObjectWorkflowLink(objid, language) {
  return "m=6&h=" + myHistoryThreadid + "&l=" + myLanguage + "&x=objectworkflow&i=" + objid;
}

function getObjectActionLink(objid, workflow, action) {
  var link = ( ( workflow ) ?  getObjectWorkflowLink(objid) : getObjectContentLink(objid) );
  return link + "&a=" + action + "&n=" + myNextLink;
}

function getObjectPermissionsLink(objid) {
  return "m=6&h=" + myHistoryThreadid + "&l=" + myLanguage + "&x=objectpermissions&i=" + objid;
}

function getObjectControlPermissionsLink(objid) {
  return "m=6&h=" + myHistoryThreadid + "&l=" + myLanguage + "&x=objpermcontrol&i=" + objid;
}

function getObjectDeleteLink(objid) {
  return "m=6&h=" + myHistoryThreadid + "&l=" + myLanguage + "&x=objectdelete&i=" + objid;
}

function getPopulationContentLink(name) {
  return "m=6&h=" + myHistoryThreadid + "&l=" + myLanguage + "&x=population&name=" + name;
}

function getUserContentLink(login) {
  return "m=6&h=" + myHistoryThreadid + "&l=" + myLanguage + "&x=user&login=" + login;
}

function getLoadDataLink(name) {
  return "m=6&h=" + myHistoryThreadid + "&l=" + myLanguage + "&x=data.load&name=" + name;
}

function addEditorButton(name, action, handler, test) {
  var index = myEditorButtons.length;
  myEditorButtons[index] = {index:index, name:name, action:action, handler:handler, test:test};
}

function initTaskLoggingFrame(redirect) {
  var iframe = document.getElementById("taskLoggingFrame");
  if ( iframe ) {
    var loaded = false;
    var onload = function() {
      _taskLoggingFrameLoaded = true;
      iframe.contentWindow.document.body.scroll = "auto";
      iframe.contentWindow.scrollTo(0, iframe.contentWindow.document.body.scrollHeight);
      if ( iframe.contentWindow.TASK_REDIRECT )
	document.location.href = iframe.contentWindow.TASK_REDIRECT;
      else if ( redirect )
	document.location.href = redirect;
      else
	alert(locale_get("task_endexec"));
    };
    util_attachEventHandlerToElement(iframe, "load", onload);
    _taskLoggingFrameScroll();
  } else
    setTimeout("initTaskLoggingFrame()", 10);
}

function _taskLoggingFrameScroll() {
  var iframe = document.getElementById("taskLoggingFrame");
  if ( iframe && iframe.contentWindow && iframe.contentWindow.document && iframe.contentWindow.document.body )
    iframe.contentWindow.scrollTo(0, iframe.contentWindow.document.body.scrollHeight);
  if ( !_taskLoggingFrameLoaded )
    setTimeout('_taskLoggingFrameScroll()', 20);
}

