///////////////////////////////////////////////////////////////////////////
// file:  		openwindow.js
// functions: 	openwindow(page)
//			ow_size(h,w)
//			ow_height(h)
//			ow_width(w)
//		   	Fdelay(Fwindow)
//			Fwin()
//
// modifications: 1.0 initial openwindow.js
//			1.1 added functions to resize window
//				ow_size(h,w)
//				ow_height(h)
//				ow_width(w)
//			1.2 added the ability to IE and Netscape window forward. This required 
//				two additional functions for IE:
//		   			Fdelay(Fwindow)
//					Fwin()
//			1.3 set a maximum size of the window based on navigator function
//
// purpose:		This is a generic function that allows a user to inline inside html a function
//			to open a window. The window can be opened with the following call:
//				href='javascript:openwindow("/path_to_file/file.html");'
//
//			You must also include the following line before the </HEAD> tag,
//			this will add the openwindow functions to your source:
//				<SCRIPT LANGUAGE="JavaScript" SRC="/scripts/openwindow.js"></SCRIPT>
//
//			Optionally, you can also put in the following inline functions to set
//			the width, height or both for the openwindow size. 
//			To set the height only, use:
//				href='javascript:ow_height(h);openwindow("/path to file/file.html");'
//
//			to set the width only, use:
//				href='javascript:ow_width(h);openwindow("/path to file/file.html");'
//
//			to set the height and width, use:
//				href='javascript:ow_size(w,h);openwindow("/path to file/file.html");'
//
// notes:		You should supply a close button in the file.html, this should be done
//			using the following image: /images/Buttons/close.gif
//			The scrap of code you will need to make this work is as follows:
//
// 			<a href="javascript:window.close();">
//			   <img src="/images/buttons/close.gif" width="92" height="20" border="0" alt="close window">
//                </a>
//
//			This will add the button to the form and create the javascript to close the window.
//
///////////////////////////////////////////////////////////////////////////
//
var openwin_h         = 225;
var openwin_w         = 440;
var openwin_h_default = openwin_h;
var openwin_w_default = openwin_w;
var openwin_min       = 50;
var openwind_page     = "";
var Fwindows = new Array();
var Ftargets = new Array();

function ow_size(ow_w, ow_h)
{
	openwin_h = ow_h;
	openwin_w = ow_w;
}
function ow_height(ow_h)
{
	openwin_h = ow_h;
}
function ow_width(ow_w)
{
	openwin_w = ow_w;
}

function openwindow(page,target)
{
  Fwindow = "";
	openwin_page = page;	
	openwin_target = target;	
  if (openwin_target == null) openwin_target = "feature";

  for (count = 0; count < Ftargets.length; count++) {
    if (Ftargets[count] == openwin_target) {
      Fwindow = Fwindows[count];
      break;
    }
  }

//
// check size of window to make sure it is at least minumum, if not set it to default value
//
var  	nav_app_version = navigator.appVersion;
var  	nav_version = nav_app_version.substring(0,2);

	if (openwin_h<openwin_min)
	{
		openwin_h = openwin_h_default;
	}
	if (openwin_w<openwin_min)
	{
		openwin_w = openwin_w_default;
	}
	if (nav_version >= 4)
	{
		if (openwin_h>screen.availHeight)
		{
//	      	alert("version = " + nav_version);
			openwin_h = screen.availHeight - 30;
		}
		if (openwin_w>screen.availWidth)
		{
			openwin_w = screen.availWidth - 30;
		}
	}
	else
	{
		if (openwin_h>=600)
		{
			openwin_h=575;
		}
		if (openwin_w>=800)
		{
			openwin_w = 775;
		}
	}
//
// openwindow for ie and for netscape
//
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		if ((typeof Fwindow) == "undefined" || Fwindow == "")
		{
			Fwin();
      Fwindows[count] = Fwindow;
      Ftargets[count] = openwin_target;
		}
		else
		{
			if(Fwindow.closed)
			{
				Fwin();
			}
			else
			{
//
//				If window is open and it is ie, close window and reopen window. This 
//				works around focus bug. Also, need to build in delay since window is
//				sometimes opening quicker than closing (w/ result of no window showing)
//
				Fdelay(Fwindow);
				Fwindow.close();
			}
		}	
	}
	else 
	{
		Fwindow = window.open(openwin_page,openwin_target,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+openwin_w+",height="+openwin_h+",left=10,right=10");
		Fwindow.focus();
		openwin_h = openwin_h_default;
		openwin_w = openwin_w_default;
	}
}
function Fdelay(Fwindow)
{
	if(!Fwindow.closed)
	{
		setTimeout("Fdelay(Fwindow);", 5);
	}
	else
	{
		Fwin();
	}
}
function Fwin()
{
	Fwindow = window.open(openwin_page,openwin_target,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+openwin_w+",height="+openwin_h+",left=10,right=10");
	openwin_h = openwin_h_default;
	openwin_w = openwin_w_default;
}
