var nWin = ""

/*-------------------------------------------------
SHOW POP UP

This function generates a new pop-up window based
on the referenced arguments. If any pop-up window
is currently open, it closes that window and opens
the requested window.
-------------------------------------------------*/
function showPopUp(URL, Name, Height, Width, Top, Left, Status, Toolbar, Menubar, Location, Resizable, Scrollbars)
	{
	if (nWin == "")
		{
		nWin = window.open(URL, Name, "height=" + Height + ",width=" + Width 
			+ ",top=" + Top + ",left=" + Left + ",status=" + Status 
			+ ",toolbar=" + Toolbar + ",menubar=" + Menubar
			+ ",location=" + Location + ",resizable=" + Resizable + ",scrollbars=" + Scrollbars)
		nWin.opener = window
		}
	else
		{
		CloseNWin()
		showPopUp(URL, Name, Height, Width, Top, Left, Status, Toolbar, Menubar, Location, Resizable, Scrollbars)
		}	
	}
	
/*-------------------------------------------------
CENTER HORIZONTAL/VERTICAL

These functions return the Left and Top values,
respectively, for centering a pop-up window on the
current screen.
-------------------------------------------------*/
function CenterHorz(width)
	{
	return((screen.width - width) / 2)
	}
	
function CenterVert(height)
	{
	return((screen.height - height) / 2)
	}
	
/*-------------------------------------------------
POP-UP CALLS

The following functions make the calls to the
SHOWPOPUP() function for their respective pop-up
windows.
-------------------------------------------------*/

var CurrentCalcValue = ""
var UserDate = ""
var ReturnEl = ""

function showCalc_DHTML(elName)
	{
	if (isIE())
		{
		el = document.forms["JSForm"].elements[elName]
		ReturnEl = elName
		CurrentCalcValue = el.value
		height = 222
		width = 221
		showPopUp("objects/js_calc_dhtml.htm",
					 "JS_Calc_DHTML",
					 height,
					 width,
					 100,
					 100,
					 "no",
					 "no",
					 "no",
					 "no",
					 "no",
					 "no")
		}
	}
    
function showCalc_HTM(elName)
	{
	height = 220
	width = 210
	el = document.forms["JSForm"].elements[elName]
	CurrentCalcValue = el.value
	ReturnEl = el
	showPopUp("objects/js_calc_htm.htm",
				 "JS_Calc_HTM",
				 height,
				 width,
				 100,
				 100,
				 "no",
				 "no",
				 "no",
				 "no",
				 "no",
				 "no")
	}
	
function showCal_DHTML(elName)
	{
	if (isIE())
		{
		height = 174
		width = 245
		UserDate = document.forms["JSForm"].elements[elName].value
		ReturnEl = elName
		showPopUp("objects/cal_dhtml.htm",
				 "Cal_DHTML",
				 height,
				 width,
				 100,
				 100,
				 "no",
				 "no",
				 "no",
				 "no",
				 "no",
				 "no")
		}
	}
	
function showCal_HTM(elName)
	{
	height = 170
	width = 245
	el = document.forms["JSForm"].elements[elName]
	UserDate = new Date(el.value)
	if (isNaN(UserDate)) UserDate = new Date()
	ReturnEl = el
	showPopUp("",
			 "Cal_HTM",
			 height,
			 width,
			 100,
			 100,
			 "no",
			 "no",
			 "no",
			 "no",
			 "no",
			 "no")
	datNow = new Date(document.forms["JSForm"].elements[elName].value)
	if (isNaN(datNow)) datNow = new Date()
	doCalendar(datNow)
	}
	
function isIE()
	{
	if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4)
		return(true)
	else
		{
		msg = "The Javascript Object you've selected requires Microsoft Internet "
			+ "Explorer version 4.0 or later to run. We have detected that your "
			+ "browser does not conform with this specification. Please select a "
			+ "different Javascript Object."
		alert(msg)
		}
	}
	
function showNotes(TopicID)
	{
	width = 300
	if (TopicID == 1)
		{
		height = 500
		scrollbars = "yes"
		}
	else
		{
		height = 320
		scrollbars = "no"
		}
	showPopUp("popups/js_notes.asp?TopicID=" + TopicID,
			 "Notes",
			 height,
			 width,
			 100,
			 100,
			 "no",
			 "no",
			 "no",
			 "no",
			 "no",
			 scrollbars)
	}
	
function showAgreement()
	{
	height = 400
	width = 400
	showPopUp("popups/agreement.asp",
				 "Agreement",
				 height,
				 width,
				 100,
				 100,
				 "no",
				 "no",
				 "no",
				 "no",
				 "no",
				 "no")
	}
	
function CloseNWin()
   {
   if (nWin != "")
      {
      nWin.close()
      nWin = ""
      }
   }
   
function CloseWindow()
	{
	opener.nWin = ""
	window.close()
	}
	
function displayError(msg1, rFocus)
	{
	msg = "You must " + msg1 + " before continuing. Please try again."
	alert(msg)
	if (rFocus != null) rFocus.focus()
	return(false)
	}
	
function isValidEmail(Address)
	{
	if (Address.indexOf("@") == -1) return(false)
		
	extLen = Address.length - (Address.lastIndexOf(".") + 1)
	if (extLen < 2 || extLen > 4) return(false)
		
	return(true)
	}
	
function isValidPhone(Phone)
	{
	pRE = /^[0-9\(\)\-\.\/]{8,}$/
	return(pRE.test(Phone))
	}

function Trim(Str)
	{
	Str = LeftTrim(Str)
	return RightTrim(Str)
	}

function LeftTrim(Str)
	{
	for (i = 0; i < Str.length; i++)
		{
		if (Str.charAt(i) != " ")
			break
		}
	return Str.substring(i, Str.length)
	}
	
function RightTrim(Str)
	{
	for (i = Str.length - 1; i >= 0; i--)
		{
		if (Str.charAt(i) != " ")
			break
		}
	return Str.substring(0, i + 1)
	}

