
var viewer = null;

function doWindow(name,url,width,height,sbars)
{
	window.open(url, name, 'width=' + width + ',height=' + height + ',' + getPosition(width, height) + ',resizable=no,scrollbars=' + ((sbars) ? 'yes': 'no') + ',status=1');
	
	return false;
}

function closeWindow(refresh)
{
	if(refresh && window.opener.refreshPage != null)
		window.opener.refreshPage();
	
	window.close();
}

function getPosition(width, height)
{
	var winTop 		= (screen.height - height) / 2;
	var	winLeft 	= (screen.width - width) / 2;
	
	return "screenX=" + winLeft + ",left=" + winLeft + ",screenY=" + winTop + ",top=" + winTop;
}

function refreshPage()
{
	window.location.reload();
}

function doViewer(url,width,height)
{
	if(viewer != null)
		viewer.close();
	
	viewer = window.open(url, "viewer", 'width=' + width + ',height=' + height + ',' + getPosition(width, height) + ',resizable=yes,scrollbars=auto,status=0');
	
	return false;
}

function doPageTask(task)
{
	if(window[task] != null)
		return window[task]();
	
	return true;
}

function toggleDiv( id, show )
{
  var elem, vis;
  
  if( document.getElementById ) // this is the way the standards work
	elem = document.getElementById( id );
  else if( document.all ) // this is the way old msie versions work
	elem = document.all[id];
  else if( document.layers ) // this is the way nn4 works
	elem = document.layers[id];

  vis = elem.style;
  
  // if the style.display value is blank we try to figure it out here
  if(vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
	vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';

  vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';
}

function showDiv( id, vis )
{
  var elem = null;
  
  if( document.getElementById ) // this is the way the standards work
	elem = document.getElementById( id );
  else if( document.all ) // this is the way old msie versions work
	elem = document.all[id];
  else if( document.layers ) // this is the way nn4 works
	elem = document.layers[id];
  
  if(elem)
  {
	  var s = elem.style;
	  s.display = (!vis) ? 'none' : 'block';
  }
  
  return elem;
}

