if (document.all)
{
	navigator.userAgent.toLowerCase().indexOf('msie 5') != -1 ? is_ie5 = true : is_ie5 = false;
	is_ie = true;
	is_moz1_6 = false;
	is_mozilla = false;
	is_ns4 = false;
}
else if (document.getElementById)
{
	navigator.userAgent.toLowerCase().match('mozilla.*rv[:]1\.6.*gecko') ? is_moz1_6 = true : is_moz1_6 = false;
	is_ie = false;
	is_ie5 = false;
	is_mozilla = true;
	is_ns4 = false;
}
else if (document.layers)
{
	is_ie = false;
	is_ie5 = false
	is_moz1_6 = false;
	is_mozilla = false;
	is_ns4 = true;
}

/* for form submission with enter key */
/*
document.onkeypress = processKey;

function processKey(e)
{
  if(null == e)
    e = window.event ;
  if(e.keyCode == 13)  {
    submitform();
  }
}
*/

function submitenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
   	submitform();
   	return false;
   }
	else
   return true;
}

/*
</SCRIPT>


<FORM ACTION="../cgi-bin/mycgi.pl">
name:     <INPUT NAME=realname SIZE=15><BR>
password: <INPUT NAME=password TYPE=PASSWORD SIZE=10
           onKeyPress="return submitenter(this,event)"><BR>
<INPUT TYPE=SUBMIT VALUE="Log In">
</FORM>
*/

/* for confirmation before deletion of records */
function confirmDelete(delUrl) {
  if (confirm("Are you sure you want to delete?")) {
    document.location = delUrl;
  }
}

function confirmDeleteBool()
{
    var agree=confirm("Are you sure you wish to delete this entry?");
    if (agree)
        return true;
    else
        return false;
}

/* for list tables */
function rowOverEffect(object)
{
 	if (object.className == 'dblistrow1')
 		object.className = 'dblistrowover1';
	else
		object.className = 'dblistrowover2';
}

function rowOutEffect(object)
{
 	if (object.className == 'dblistrowover1')
  		object.className = 'dblistrow1';
	else
		object.className = 'dblistrow2';
}

/* for collapsable content */
function ToggleImage(id, state)
{
	element = document.getElementById(id);
	if(state == 0) {
		element.src = '/lims/images/collapse.gif';
	} else {
		element.src = '/lims/images/expand.gif';
	}
}

function ToggleDisplay(id) {
	element = document.getElementById(id);
	if(element.style.display == 'none') {
		element.style.display = '';
		ToggleImage(id + 'img', 0)
	} else {
		element.style.display = 'none';
		ToggleImage(id + 'img', 1)
	}
}

// works only correctly in Mozilla/FF and Konqueror
function openWindowCentered2(_url, _windowName, _width, _height, _status)
{
	windowWidth = getWindowOuterWidth();
	windowHeight = getWindowOuterHeight();

	positionLeft = (windowWidth/2)-(_width/2)+getWindowLeft();
	positionTop  = (windowHeight/2)-(_height/2)+getWindowTop();

	windowID = window.open(_url, _windowName, "width=" + _width + ",height=" + _height + 
		",screenX=" + positionLeft + ",left=" + positionLeft + ",screenY=" + positionTop + ",top=" + positionTop +
		",location=no,menubar=no,directories=no,toolbar=no,scrollbars=yes,resizable=yes,status="+_status);
	
	return windowID;
}

function openWindowCentered(_url, _windowName, _width, _height)
{
	return openWindowCentered2(_url, _windowName, _width, _height, 'no');
}

function openUrl(url)
{
	window.location = url;
}

// return the left position of the window
function getWindowLeft()
{
	if(is_mozilla)
	{
		return window.screenX;
	}
	else
	{
		return window.screenLeft;
	}
}

// return the left position of the window
function getWindowTop()
{
	if(is_mozilla)
	{
		return window.screenY;
	}
	else
	{
		//alert(window.screenTop);
		return window.screenTop-90;
	}
}



// get the outerWidth of the browser window. For IE we simply return the innerWidth
function getWindowInnerWidth()
{
	if (is_mozilla)
	{
		return window.innerWidth;
	}
	else
	{
		// works only after the body has parsed
		//return document.body.offsetWidth;
		return document.body.clientWidth;
		//return document.documentElement.clientWidth;
	}
}

// get the outerHeight of the browser window. For IE we simply return the innerHeight
function getWindowInnerHeight()
{
	if (is_mozilla)
	{
		return window.innerHeight;
	}
	else
	{
		// works only after the body has parsed
		//return document.body.offsetHeight;
		//return document.body.clientHeight;
		return document.documentElement.clientHeight;
	}
}

// get the outerWidth of the browser window. For IE we simply return the innerWidth
function getWindowOuterWidth()
{
	if (is_mozilla)
	{
		return window.outerWidth;
	}
	else
	{
		return getWindowInnerWidth();
	}
}

// get the outerHeight of the browser window. For IE we simply return the innerHeight
function getWindowOuterHeight()
{
	if (is_mozilla)
	{
		return window.outerHeight;
	}
	else
	{
		return getWindowInnerHeight();
	}
}
