var IE = (document.all)
var NS6 = (document.getElementById&&!document.all)
var NS = (navigator.appName=="Netscape" && navigator.appVersion.charAt(0)=="4")

window.onload=window_onload; //timer.js used to call this but was removed so now is being called here (old comment: - removed b/c this is now beingcalled in timerbar.js)
window.onresize=window_onresize;
window.onscroll=window_onscroll;

//document.forms[0].onsubmit = validateInputText();

/**************************************************
*	This function check all text boxes for '<'
*	and replaces them with '< '
**************************************************/
function validateInputText() {

	var elementCount = document.forms[0].elements.length;
	var elements = document.forms[0].elements;
	
	// traverse all elements
	for(index = 0; index < elementCount; index ++) {
		// check if element is of type text or textbox
		if(elements[index].type == "text" || elements[index].type == "textarea") {
			// check if element contains '<'
			if (elements[index].value.indexOf("<") >= 0) {
				// add space after each '<'
				 elements[index].value = replaceTagChars(elements[index].value);
			}
		}
	} // end for 
} // end function validateInputText

/**************************************************
*	This function receives a string and returns it 
*	with a space inserted after each '<'
**************************************************/
function replaceTagChars(inString) {

	// get first position of bad character
	var pos = inString.indexOf("<")

	// loop while there exist bad characters
	while(pos >= 0) {
	
		// check if next position is a space
		if(inString.charAt(pos + 1) != " ") {
			// insert space after '<'
			inString = inString.substring(0, pos + 1) + " " + inString.substring(pos + 1, inString.length);			
		}

		// get next position of bad character
		var subStringPos = inString.substring(pos + 1, inString.length).indexOf("<");
		if (subStringPos >= 0) {pos += subStringPos + 1;} else {pos = -1;}
		
	} // end while

	// return string
	return inString;
	
} // end function replaceTagChars

function window_onresize() {
	SetBrowserWidth()
}

function window_onload() {
	SetBrowserWidth();
	SetScrollPosition();
	//progressBarInit(); - timer is no longer being called
	if (!IE) {
		try{
			calendarInit();
		}
		catch(exception){
			//did not have the calendar .js file on page
		}
	}
}

function window_onscroll() {
	document.forms[0].__SCROLLPOS.value = document.body.scrollTop
}

function SetBrowserWidth(){
	document.forms[0].__SCREENRESOLUTION.value = window.screen.width
	if (IE) {
		document.forms[0].__MYBROWSERWIDTH.value = document.body.clientWidth
	}
	if (NS||NS6) {
		//there is about a 7 pixel difference between IE and NS7
		document.forms[0].__MYBROWSERWIDTH.value = window.innerWidth - 7
	}
}

function SetScrollPosition(){
	var pos = parseInt(myScrollPos)
	if (pos > 0){
		document.body.scrollTop = pos;
	}
}	

function jsConfirm(msg){
	var rtn;
	rtn = window.confirm(msg); 
	//alert (ans);                       
	if (rtn==true) 
	{ 
		rtn=true;
	} 
	else 
	{ 
		rtn=false;
	} 
	return rtn;
}

var winModalWindow
 
function IgnoreEvents(e)
{
  return false
}
 

function popupPage(page, styles, NsStyles){
	var rtn;
	if (IE) 
	{
		rtn = window.showModalDialog(page,null,styles);
	}
	else
	{
	    window.top.captureEvents(Event.CLICK|Event.FOCUS|Event.MOUSEMOVE)
		window.top.onclick=IgnoreEvents
		window.top.onfocus=HandleFocus 
		window.top.onmousemove=HandleClose
		winModalWindow=window.open(page,'ModalChild',NsStyles)
		winModalWindow.focus()
	}		
	if (rtn==true) 
	{ 
		rtn=true;
	} 
	else 
	{ 
		rtn=false;
	} 
	return rtn;

}
function HandleClose()
{
  if (winModalWindow)
  {
    if (winModalWindow.closed)
    {
		window.top.focus();
		document.forms[0].submit();
    }
  }
}

function HandleFocus()
{
  if (winModalWindow)
  {
    if (!winModalWindow.closed)
    {
      winModalWindow.focus();
    }
    else
    {
      window.top.releaseEvents(Event.CLICK|Event.FOCUS|Event.MOUSEMOVE);
      window.top.onclick = "";
      
    }
  }
  return false
}
