<!--

// Offset for screen re-positioning. This is calculated on the standard size
// of a windows title bar.
var screenOffset = 30;

var popupHandle;

function displayCalendar(strurl, evnt) {
  displayPopup(1, strurl, 'Calendar', 245, 220, evnt);
}

function closePopup() {
  if(popupHandle != null && !popupHandle.closed) popupHandle.close();
}

function displayPopup(position, url, name, height, width, evnt) {
  // position=1 POPUP: makes screen display up and/or left, down and/or right 
  // depending on where cursor falls and size of window to open
  // position=2 CENTER: makes screen fall in center
  var properties = "toolbar = 0, location = 0, height = " + height;
  properties = properties + ", width=" + width;
  var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;

  screenY = document.body.offsetHeight;
  screenX = window.screen.availWidth;

  if(position == 1)	{ // if POPUP not CENTER
    cursorX = evnt.screenX;
    cursorY = evnt.screenY;
    padAmtX = 10;
    padAmtY = 10;
    if((cursorY + height + padAmtY) > screenY) {
      // make sizes a negative number to move left/up
      padAmtY = (-30) + (height * -1);
      // if up or to left, make 30 as padding amount
    }
    if((cursorX + width + padAmtX) > screenX)	{
      padAmtX = (-30) + (width * -1);	
      // if up or to left, make 30 as padding amount
    }
    leftprop = cursorX + padAmtX;
    topprop = cursorY + padAmtY;
  }
  else{
  
    leftvar = (screenX - width) / 2;
    rightvar = (screenY - height) / 2;
    leftprop = leftvar;
    topprop = rightvar;
  }
  
  if(evnt != null) {
    properties = properties + ", left = " + leftprop;
    properties = properties + ", top = " + topprop;
  }

  closePopup();
  popupHandle = open(url,name,properties);
}

/*
 * Opens a new window with the provided parmaeters
 *
 * width: How wide the window should be (eg. 400)
 * height: How high the window should be (eg. 500)
 * strurl: URL for the contents of the window (eg. 'page.htm')
 * winName: Name to put in the window's title bar (eg. 'New Window')
 * scrollb: 'yes' for scroll bars, 'no' for no scroll bars
 */
function openWindow(width,height,strurl,winName,scrollb) {
    x = getPosition(width, top.window.screenLeft - screenOffset, screen.AvailWidth);
    y = getPosition(height, top.window.screenTop - screenOffset, screen.AvailHeight);
    
	window.open(strurl, winName, 'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',scrollbars='+scrollb);
}

/*
 * Determine the best position for a co-ordinate of a popup window
 *
 * size: The size of the constraint (eg. width or height of the popup)
 * position: Where the co-ordinate is to be placed
 * max: Maximum available position for that co-ordinate
 *
 * Returns: Best position for the popup window
 */
function getPosition(size, position, max) {
    posMax = position + size;
    if (posMax > max) {
        position -= (posMax - max) + (screenOffset * 2);        
    }
    
    if (position < 0) {
        position = screenOffset;
    }
    
    return position;
}


//// OPEN WINDOW CENTER OF SCREEN
function centerWindow(width,height,strurl,winName,scrollbars) {
    x = (640 - width)/2, y = (480 - height)/2;

///////////////////////////////////////////////
//	strurl = 'page.htm'
//	winName = 'WindowName'
//	width = 400
//	height = 190
//	scrollbars = 'yes'
///////////////////////////////////////////////

    if (screen) {
        y = (screen.availHeight - height)/2;
        x = (screen.availWidth - width)/2;
    }
    
    if (screen.availWidth > 1800) { 
	x = ((screen.availWidth/2) - width)/2; 
    } 
	window.open(strurl,winName,'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',scrollbars='+scrollbars);	
}


//// OPEN WINDOW CENTER OF SCREEN
function HelpWindow(strurl) {
	
///////////////////////////////////////////////
	width = 600
	height = 450
//	strurl = 'page.htm'
	winName = 'Help'
	scrollbars = 'yes'	
///////////////////////////////////////////////
	
    x = (640 - width)/2, y = (480 - height)/2;

    if (screen) {
        y = (screen.availHeight - height)/2;
        x = (screen.availWidth - width)/2;
    }
    
    if (screen.availWidth > 1800) { 
	x = ((screen.availWidth/2) - width)/2; 
    } 
	window.open(strurl,winName,'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',scrollbars='+scrollbars);	

}

//-->