var GWinMsgInfo;


void function PosAtMouse(AControl)
{
  AControl.style.left = event.x + document.body.scrollLeft;
  AControl.style.top = event.y + document.body.scrollTop;
}


void function PosRelativeToMouse(AControl, ARelativeX, ARelativeY)
{
  AControl.style.left = event.x + document.body.scrollLeft + ARelativeX;
  AControl.style.top = event.y + document.body.scrollTop + ARelativeY;

}


void function ShowAtMouse(AControl)
{
  AControl.style.display = '';
  PosAtMouse(AControl);
}


void function ShowRelativeToMouse(AControl, ARelativeX, ARelativeY)
{
  AControl.style.display = '';
  PosRelativeToMouse(AControl, ARelativeX, ARelativeY);
}


void function CenterInWindowClientArea(AControl, ARelativeToScrollPos)
{

  VCenterInWindowClientArea(AControl, ARelativeToScrollPos);
  HCenterInWindowClientArea(AControl);

}


void function VCenterInWindowClientArea(AControl, ARelativeToScrollPos)
{
  var iClientHeight;
  var iCtrlHeight = StrToInt(AControl.style.height);
  
  if (window.innerHeight)
    iClientHeight = window.innerHeight;
  else if (document.documentElement && document.documentElement.clientHeight)
    iClientHeight = document.documentElement.clientHeight
  else if (document.body.clientHeight)
    iClientHeight = document.body.clientHeight
  else
    iClientHeight = screen.availHeight;

  if (ARelativeToScrollPos)
    AControl.style.top = document.body.scrollTop + ((Math.round(iClientHeight / 2)) - (Math.round(iCtrlHeight / 2)));
  else
    AControl.style.top = (Math.round(iClientHeight / 2)) - (Math.round(iCtrlHeight / 2));
    
}         //VCenterInWindowClientArea()


void function HCenterInWindowClientArea(AControl)
{

  var iClientWidth;
  var iCtrlWidth = StrToInt(AControl.style.width);
  
  if (window.innerWidth)
    iClientWidth = window.innerWidth;
  else if (document.documentElement && document.documentElement.clientWidth)
    iClientWidth = document.documentElement.clientWidth
  else if (document.body.clientWidth)
    iClientWidth = document.body.clientWidth
  else
    iClientWidth = screen.availWidth;

  AControl.style.left = (Math.round(iClientWidth / 2)) - (Math.round(iCtrlWidth / 2));

}         //HCenterInWindowClientArea()



void function MsgInfo(ATitle, AMessage)
{

  //-----------------------------------------------------------------------
  // This function is still under construction; please do not use at this
  //  time.
  //-----------------------------------------------------------------------

  var wl = new WinLauncher();
  
  function GetMarkUp()
  {
    var Result = '';
    
    Result = '<title>' + ATitle + '</title>' + CrLf();
    Result += '<body style="background-color: blue; color: white; font-weight: bold; margin: 0px;">' + CrLf();
    Result += '<table style="height: 85%; width: 100%" border=1 cellspacing=0 cellpadding=0>' + CrLf();
    Result += '<tr><td style="background-color: silver; font-family: tahoma; font-size: 9pt; font-weight: bold; padding: 4px; overflow: scroll; width: 100%; text-align: center" >';
    Result += AMessage + '</td></tr></table>' + CrLf();
    Result += '<div style="height: 15%; background-color: black">' + CrLf();
    Result += 'Hello';
    Result += '</div>' + CrLf();
    Result += '</body>';
    
    return Result;
  
  }       //GetMarkUp()
  
  with (wl)
  {
    Height = 225;
    Width = 400;
    ShowScrollBars = false;
  }  

  if (GWinMsgInfo)
    if (! GWinMsgInfo.closed)
      GWinMsgInfo.close();
    
  GWinMsgInfo = wl.LaunchNamedWindow('', 'winMsgInfo');
  
  if (ATitle == '')
    ATitle = 'Information';
    
  GWinMsgInfo.document.write(GetMarkUp());
  
}         //MsgInfo()


//WinLauncher Class
//Spawns New Window via LaunchWindow() and LaunchNamedWindow()
function WinLauncher() {
		
	this.GetWindowFeatures = GetWindowFeatures;
	this.LaunchWindow = LaunchWindow;
	this.LaunchNamedWindow = LaunchNamedWindow;
	
	this.Left = -1;
	this.Top = -1;
	this.Height = -1;
	this.Width = -1;
	this.Resizable = true;
	this.ShowStatus = false;
	this.ShowMenuBar = false;
	this.ShowToolBar = false;
	this.ShowScrollBars = true;
		
	function LaunchNamedWindow(AUrl, AWindowName)
	{
	  var Result;
	  
		Result = window.open(AUrl, AWindowName, this.GetWindowFeatures());

		if (Result)
		{
		  try
		  {
		    Result.focus();
		  }
		  catch(e)
		  {
		  }
		  
		  if (this.Width > -1 && this.Height > -1)
		    Result.resizeTo(this.Width, this.Height);
		}
		  
		return Result;
		
	}			//End of LaunchNamedWindow()
	
	
	function LaunchWindow(AUrl)
	{
	  var Result;

		Result = window.open(AUrl, "", this.GetWindowFeatures());
		
		if (Result)
		{
		  Result.focus();
		  if (this.Width > -1 && this.Height > -1)
		    Result.resizeTo(this.Width, this.Height);
		}
		  
		return Result;
		
	}					//End of LaunchWindow()

	
	function AddWindowFeature(AFeatureString, ANewFeature) {
	
		if (AFeatureString == "")
			return ANewFeature
		else
			return AFeatureString + "," + ANewFeature;
			 
	}				//End of AddWindowFeature()
	
	
	function GetWindowFeatures() {
		var sResult;
		var x, y;

				if (this.Left > -1)
					sResult = "left=" + this.Left + 'px'
				else
				if (this.Width > -1)		//Center Horizontally on screen. Assume Origin of 0.
				{
				
				  with (window.screen)
				    x = (availWidth / 2) - (this.Width / 2);
				    
					if (x < 0)
						x = 0;
					sResult = "left=" + x + 'px';
				}
				else
					sResult = "";
					
				if (this.Top > -1)
					sResult = AddWindowFeature(sResult, "top=" + this.Top + 'px')
				else
				if (this.Height > -1)
				{
				  with (window.screen)
				    y = (availHeight / 2) - (this.Height / 2);
				    
				  //with (window.screen)
				    //y = 370;
				    
				  //alert(this.Height);
				    
			    
					if (y < 0)
						y = 0;
					sResult = AddWindowFeature(sResult, "top=" + y + 'px');
				}

				if (this.Height > -1)
					sResult = AddWindowFeature(sResult, "Height=" + this.Height + 'px');
					
				if (this.Width > -1)
					sResult = AddWindowFeature(sResult, "Width=" + this.Width + 'px');

				if (this.Resizable)
					sResult = AddWindowFeature(sResult, "resizable=yes")
				else
					sResult = AddWindowFeature(sResult, "resizable=no");
										
				if (this.ShowStatus)
					sResult = AddWindowFeature(sResult, "status=yes")
				else
					sResult = AddWindowFeature(sResult, "status=no");
					
				if (this.ShowToolBar)
					sResult = AddWindowFeature(sResult, "toolbar=yes")
				else
					sResult = AddWindowFeature(sResult, "toolbar=no");
					
				if (this.ShowMenuBar)
					sResult = AddWindowFeature(sResult, "menubar=yes")
				else
					sResult = AddWindowFeature(sResult, "menubar=no");
					
			  if (this.ShowScrollBars)
				  sResult = AddWindowFeature(sResult, "scrollbars=yes")
				else
				  sResult = AddWindowFeature(sResult, "scrollbars=no");

			return sResult;
					
	}				//End of GetWindowFeatures()
}				//End of WinLauncher Class	


function OpenWindow(AUrl) 
{
	var wl = new WinLauncher;
        
	wl.ShowStatus = true;
	return wl.LaunchWindow(AUrl);

}					//OpenWindow()


function OpenWindowMax(AUrl) 
{
	var wl = new WinLauncher;
       
	wl.ShowStatus = true;
	wl.Width = screen.availWidth;
	wl.Height = screen.availHeight;
	return wl.LaunchWindow(AUrl);

}					//OpenWindowMax()


function OpenWindowMax75(AUrl, AWindowName, AShowToolbar, AShowMenubar)
{
  var wl = new WinLauncher;
        
	wl.ShowStatus = true;
	if (AShowToolbar)
	  wl.ShowToobar = true;
	if (AShowMenubar)
	  wl.ShowMenubar = true;
	  
	wl.Width = screen.availWidth * 0.75;
	wl.Height = screen.availHeight * 0.75;
	
	if (AWindowName > '')
	  return wl.LaunchNamedWindow(AUrl, AWindowName)
	else
	  return wl.LaunchWindow(AUrl);

}					//OpenWindowMax75()


void function OpenDocumentMax75(ADocumentPath, AWindowCaption, AWindowName)
{
  //Conceptually the same as OpenWindowMax75() but circumvents the problems which occur
  // when opening a PDF by inserting the document into an iframe.
  // The advantage is that an already open window can be named and brought to the front
  // when called. The disadvantage is that the iframe is re-written and the docment retrieved
  // with each call to the function.
  var wl = new WinLauncher;
  var win;
  var sHtml;

	wl.ShowToolBar = true;
	wl.Width = screen.availWidth * 0.75;
	wl.Height = screen.availHeight * 0.75;
	
	if (AWindowCaption)
	  sHtml = '<title>' + AWindowCaption + '</title>';
	  
	sHtml += '<iframe height="100%" width="100%" src="' + ADocumentPath + '"></iframe>';
	
	if (AWindowName)
	  win = wl.LaunchNamedWindow('', AWindowName)
	else
	  win = wl.LaunchWindow('');	  
	
	win.document.open();
	win.document.write(sHtml);
	win.document.close();

}         //OpenDocumentMax75()


void function CloseWindow(ARefreshOpener)
{

  if (window.opener)
  {
    if (ARefreshOpener)
      window.opener.location.href = window.opener.location.href;
    window.opener.focus();
    window.close();
  }
  else
    window.close();

}     //CloseWindow()


function IsWindowOffscreen(AWindow)
{

  if (AWindow.screenLeft > AWindow.screen.width)
    return true
  else
    return AWindow.screenTop > AWindow.screen.height;
    
}       //IsWindowOffscreen()


function GetSearchValues()
{
  var Result = new Object();
  var i;
  var iPos;
  var sQuery = location.search.substring(1);
  var arVariables = sQuery.split('&');
  
  function AddValue(ANameValueString, iDelimiterPos)
  {
    var sArgName = ANameValueString.substring(0, iDelimiterPos);
    var sValue = ANameValueString.substring(iDelimiterPos + 1);
    
    Result[sArgName] = decodeURIComponent(sValue);
  
  }         //GetValue()
  
  
  for (i = 0; i < arVariables.length; i++)
  {
    iPos = arVariables[i].indexOf('=');
    if (iPos == -1)
      continue
    else
      AddValue(arVariables[i], iPos);
  }
  
  return Result;

}           //GetSearchValues()

     
