/**
 * General Javascript Functions
 *
 * Developed by The Working Group Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * @version $Id: general.js,v 1.19 2005/06/24 22:37:54 dombort Exp $
 * @copyright Copyright (c) 2003-5 St. Christopher House
 * @package ClnCore
 * @subpackage System
 * @filesource
 */

/**
 * opens new window and manages focusing
 *
 * http://www.codestore.net/store.nsf/unid/DOMM-4PYJ3S?OpenDocument
 *
 * @access public
 * @return TBD
 */
popupWins = new Array();

function windowOpener(url, windowName, args) {
	/* ******************************
	the popupWins array stores an object reference for
	each separate window that is called, based upon
	the url attribute that is supplied as an argument
	*******************************/
	if ( typeof( popupWins[windowName] ) != "object" ){
		popupWins[windowName] = window.open(url,windowName,args);
	} else {
		if (!popupWins[windowName].closed){
			popupWins[windowName].location.href = url;
		} else {
			popupWins[windowName] = window.open(url,windowName,args);
		}
	}
	
	popupWins[windowName].focus();
}


/**
 * Wrapper for overlib - not being used right now
 *
 * @access public
 * @return TBD              
 */
function showMessage(koId) 
{
	//overlib(msg, STICKY);
	var helpWindow = 'help'+koId;
	
	over = getObjectById("overDiv");
	
	
	if (olNs4) {
		var lyr = o3_frame.document[helpWindow].document
		lyr.write(txt)
		lyr.close()
	} else if (typeof over.innerHTML != 'undefined') {
		if (olIe5 && isMac) over.innerHTML = '';
		over.innerHTML = txt;
	} else {
		range = o3_frame.document.createRange();
		range.setStartAfter(over);
		domfrag = range.createContextualFragment(txt);
		
		while (over.hasChildNodes()) {
			over.removeChild(over.lastChild);
		}
		
		over.appendChild(domfrag);
	}
	
	return;
}


/**
 * Opens a window for the help
 *
 * @access public
 * @return TBD            
 */
function showHelp(url) 
{
	if(!helpWindow || helpWindow && helpWindow.closed) {
		helpWindow = window.open(url, "HelpViewer", "width=640,height=480,top=20,left=20,toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes");
	} else {
		//helpWindow.location.reload();
		helpWindow.focus();
	}
}
// defines variable outside of function to make it global
var helpWindow = null;


/**
 * Gets object by Id (wrapper for dom variations in browsers)
 *
 * @access public
 * @return TBD              
 */
function getObjectById(id)
{
	var obj = false;
	if(document.getElementById){
		obj = document.getElementById(id);}
	else if(document.all){
		obj = document.all[id];}
	else if(document.layers){
		obj = document.layers[id];}
		
	return obj;
}


/**
 * toggles the bort's information drawer
 *
 * @access public
 * @return TBD
 */
function showHide(id,cleanUrlBase)
{
	//alert("function successfully called");
	
	obj = getObjectById(id);
	
	if(!obj) { return false; }
	if(obj.style.display == 'none'){
		obj.style.display = '';
		getObjectById("OpenButton"+id).src = cleanUrlBase+"images/close.gif";
	}
	else{
		obj.style.display = 'none';
		getObjectById("OpenButton"+id).src = cleanUrlBase+"images/open.gif";
		
		// redraw content to avoid bug - turned off because it's too flashy - dwc
		redrawParentElement('content');
	}	
}

function showHideByLink(id,cleanUrlBase,donotredraw)
{	
	obj = getObjectById(id);
	
	if(!obj) { return false; }
	if(obj.style.display == 'none'){
		obj.style.display = '';
			}
	else{
		obj.style.display = 'none';
				
		// redraw content to avoid bug - turned off because it's too flashy - dwc
		if(!donotredraw) redrawParentElement('content');
	}	
}

/**
 * Redraws the parent node, to force changes in the dom
 *
 * @access public
 * @return TBD             
 */
function redrawParentElement(thisId) {
	thisContent = getObjectById(thisId);
	thisContent.parentNode.replaceChild(thisContent, thisContent);
}


/**
 * Opens up a new window with the session manager in it
 *
 * @access public
 * @return TBD              
 */
function manageSessions(basePath) {
	if(!sessionWin || sessionWin && sessionWin.closed) {
		sessionWin = window.open(basePath + "lib/CLN/interfaces/SessionVars.php", "SessionManager", "width=640,height=480,top=20,right=20,toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes");
	} else {
		sessionWin.location.reload();
		sessionWin.focus();
	}	
}

// needs to be defined globally for manageSessions to work
var sessionWin = null;