
// ------------ Main Function to open up the DIV and display the calendar ----------

function showOverlay( inputField, overlayName, offsetX, offsetY ) 
{
// ----- get the current position & add our position offset -----

	var pos  = findPos( inputField )
	var xpos = pos.left + offsetX
	var ypos = pos.top  + offsetY

	if ( ( navigator.userAgent.indexOf("MSIE") != -1 ) &&
	     ( navigator.userAgent.indexOf("MSIE 7.0") == -1 ) )
		hideSelects( xpos, ypos )

// ----- Move the DIV to the correct position and show it -----

	var oObj = document.getElementById( overlayName );
  
  oObj.style.left       = xpos + "px"
	oObj.style.top        = ypos + "px"
	oObj.style.visibility = "visible"
	oObj.style.display    = "block"
}

function chooseItem(changeField, itemSelected)
{
  document.getElementById(changeField).value = itemSelected.value
	itemSelected.style.display = "none"
}

// ------------ Function to close up the DIV and update the input field ----------

function hideOverlay( overlayName )
{
  document.getElementById( overlayName ).style.visibility = "hidden"
	showSelects()
}

// ------------ Find our current position ---------

function findPos( obj ) 
{
  var left = obj.offsetLeft
  var top  = obj.offsetTop

	while (obj.offsetParent != null) 
	{
		obj = obj.offsetParent 
		left += obj.offsetLeft
		top += obj.offsetTop
	}
	return {left:left, top:top}
}

// --------- Hide any selects below us - IE Bug Fix ------

function hideSelects( x, y )
{
	var sObj = document.getElementsByTagName("select")

	for (i=0 ; i<sObj.length ; i++)
	{
		pos = findPos( sObj[i] )
		if (( pos.left >= x ) && ( pos.top >= y ))
			sObj[i].style.display = "none"
	}
}

// --------- Show the hidden selects - IE Bug Fix ----------

function showSelects()
{
  var sObj = document.getElementsByTagName("select")

  for (i=0 ; i<sObj.length ; i++)
      sObj[i].style.display = ""
}

