/**
 * Alliance Software Content Management System
 *
 * @copyright Copyright &copy; 2004, Alliance Software
 * No unauthorised use without the express written permission
 * of Alliance Software
 *
 * @package core
 *
 */

/**
 * Add a function to the window.onload event
 */
function addLoadEvent(func){
  var oldonload = window.onload;
  if (typeof window.onload != 'function'){
	window.onload = func;
  } else {
	window.onload = function(){
	  oldonload();
	  func();
	}
  }
}

/**
 * Add a function to the window.onresize event
 */
function addResizeEvent(func){
  var oldonresize = window.onresize;
  if (typeof window.onresize != 'function'){
	window.onresize = func;
  } else {
	window.onresize = function(){
	  oldonresize();
	  func();
	}
  }
}

/** Display a popup window showing a specific URL */
function showWindow(url,name,width,height){
	var options = "width="+width+",height="+height+",status=yes,toolbar=no,"
		+"directories=no,menubar=no,location=no,resizable=yes,scrollbars=yes,"
		+"left=100,top=100";
	var hwnd = open(url, name, options);
}

/** Post form to a popup window */
function submitFormToWindow(formName,name,width,height){
	var options = "width="+width+",height="+height+",status=yes,toolbar=no,"
		+"directories=no,menubar=no,location=no,resizable=yes,scrollbars=yes,"
		+"left=100,top=100";
	var hwnd = open("", name, options);
	var a = window.setTimeout("document."+formName+".submit();", 500);
	// Set focus to window
	setTimeout('setFocus(\''+name+'\')', 500);
}

/** Set focus to a named window */
function setFocus(name){
	hwnd = open('', name);
	hwnd.focus();
}

/** Return an object */
function getObject(objectId) {
	// cross-browser function to get an object's style object given its id
	if(document.getElementById && document.getElementById(objectId)) {
		// W3C DOM
		return document.getElementById(objectId);
	} else if (document.all && document.all[objectId]) {
		// MSIE 4 DOM
		return document.all[objectId];
	} else if (document.layers && document.layers[objectId]) {
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
	} else {
		return false;
	}
}

/** Return the style of an object */
function getStyleObject(objectId) {
	var object = getObject(objectId);
	if (false != object) {
		return object.style;
	}
	return false;
}

/**
 * Switch a layer between hidden and type
 * NOTE: type = '' returns it to default type
 */
function toggleLayer(wLayer, type){
	if ('undefined' == typeof(type)) { type = ''; }
	var s = getStyleObject(wLayer);
	if (false != s) {
		s.display=(s.display=='none')?type:'none';
	}
}
/** specifically show a layer */
function showLayer(wLayer, type){
	if ('undefined' == typeof(type)) { type = ''; }
	var s = getStyleObject(wLayer);
	if (false != s) {
		s.display=type;
	}
}
/** specifically hide a layer */
function hideLayer(wLayer){
	var s = getStyleObject(wLayer);
	if (false != s) {
		s.display='none';
	}
}
