/*
 * File   : $Source: /CVS_DATA/Generic/Generic_V3_4_0/WebRoot/script/general.js,v $
 * Date   : $Date: 2008/12/01 08:36:01 $
 * Version: $Revision: 1.1 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (C) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * Returns the form that contains the control with the given id.
 */
function getFormForId(id) {
        return document.getElementById(id).form;
}

/*
 * Opens a new page in the right frame.
 * It also shows the loading screen during loading
 */
function openPage(url) {
    target = isFramed() ? parent.admin_content : this;
    if (!isFramed()) {
       if (parent.parent.admin_content) {
           target = parent.parent.admin_content;
       }
    }
    openPageIn(url, target);
}

/*
 * Opens a new page in the given target frame.
 * It also shows the loading screen during loading
 */
function openPageIn(url, target) {
    loadingOn();
    target.location.href = url;
}

/*
 * Sets the current displayed context help.
 * It only works if framed.
 */
function setContextHelp(contextHelp) {
    try {
        parent.admin_menu.setInternalContextHelp(contextHelp);
    } catch(e) {
        try {
             parent.parent.admin_menu.setInternalContextHelp(contextHelp);
        } catch (e1) { }
    }
}

/*
 * Sets the default context help.
 * It only works if framed.
 */
function setContext(defaultContext) {
    if (defaultContext) {
        parent.defContextHelp = defaultContext;
    }
    setContextHelp();
}

/*
 * Returns the default context help.
 * It only works if framed.
 */
function getContext() {
    return parent.defContextHelp;
}

/*
 * Sets the active item in the menu frame.
 * It only works if framed.
 */
function setActiveItemByName(name) {
    try {
        return parent.admin_menu.setActiveItem(name);
    } catch (e) {
        try {
             parent.parent.admin_menu.setActiveItem(name);
        } catch (e1) { }
    }
}

/*
 * Shows the context help.
 * If framed, it will be shown in the menu frame;
 * if not, as a help ballon.
 * The obj_id argument should be the id of a div tag,
 * which contains the help text.
 */
function sMH(obj_id) {
   try {
      if (!isFramed() && !parent.parent.admin_content) {
         showHelp(obj_id);
      } else {
         try {
            var writezone = document.getElementById('help' + obj_id);
            context = writezone.firstChild.nodeValue;
         } catch(e) {
            context = obj_id;
         }
         setContextHelp(context);
      }
   } catch(e) {
      // ignore
   }
}

/*
 * Hides the context help.
 * If framed, it will be shown in the menu frame;
 * if not, as a help ballon.
 * The obj_id argument should be the id of a div tag,
 * which contains the help text.
 */
function hMH(obj_id) {
   try {
      if (!isFramed() && !parent.parent.admin_content) {
         hideHelp(obj_id);
      } else {
         setContextHelp('');
      }
   } catch(e) {
      // ignore
   }
}

/*
 * Shows the context help when having one helptext for several buttons.
 * If framed, it will be shown in the menu frame;
 * if not, as a help ballon.
 * The obj_id argument should be the id of a div tag, where the ballon while be displayed.
 * The help_id argument should be the id of a div tag, which contains the help text.
 */
function sMHS(obj_id, help_id) {
   try {
      if (!isFramed() && !parent.parent.admin_content) {
         showHelpX(obj_id, help_id);
      } else {
         try {
            var writezone = document.getElementById('help' + help_id);
            context = writezone.firstChild.nodeValue;
         } catch(e) {
            context = obj_id;
         }
         setContextHelp(context);
      }
   } catch(e) {
      // ignore
   }
}


/*
 * Submits a form, showing the loading screen during loading.
 */
function submitForm(theForm) {
    loadingOn();
    theForm.submit();
    return true;
}

/*
 * Checks is we are working in the admin-view framed environment.
 */
function isFramed() {
    return parent.admin_content && parent.admin_menu;
}


