/***************************************************************
* function popup
*          - this will open a popup window display up and/or left, 
*            down and/or right relative to the position that event
*            has occurred. 
*   
* example usage 
*          - onClick=" return popup('filename.cfm',event, 400, 300)"
*             where width = 400 and height = 300.
*
***************************************************************/

var popupHandle;

function popup(url,evnt, w, h, not_resize) {

var properties, ptop, pleft, pwidth, pheight ;
var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;

width   = w;
height  = h;

/* put this back in for production */

properties = "toolbar = 0, location = 0, height = " + height + ", width=" + width;
if (not_resize == "YES")
{
  properties = properties + ", resizable=no, scrollbars=no";
}
else
{
  properties = properties + ", resizable=yes, scrollbars=yes";
}


/* use this for debug only */
/*
properties = "status=yes, scrollbars=yes, dirctories=yes, dependent=yes, toolbar = yes, location = yes, resizable=yes"  
           + ", height = " + height + ", width=" + width;
*/
if(navigator.appName == "Microsoft Internet Explorer") {

   screenY = document.body.offsetHeight;
   screenX = window.screen.availWidth;
}
else {

   screenY = window.outerHeight
   screenX = window.outerWidth
}
   if(evnt){
   	cursorX = evnt.screenX;
   	cursorY = evnt.screenY;
   }else{
   	cursorX = 0;
   	cursorY = 0;
   }
   
   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
   }
   if(navigator.appName == "Microsoft Internet Explorer") {
      leftprop = cursorX + padAmtX;
      topprop = cursorY + padAmtY;
   }
   else {
      leftprop = (cursorX - pageXOffset + padAmtX);
      topprop = (cursorY - pageYOffset + padAmtY);
      
   }

if(evnt != null) {

    properties = properties + ", left = " + leftprop;
    properties = properties + ", top = " + topprop;
}
closePopup();
popupHandle = open(url,'popup',properties);
}

function popup_scroll(url,evnt, w, h) {

var properties, ptop, pleft, pwidth, pheight ;
var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;

width   = w;
height  = h;

/* put this back in for production */

properties = "toolbar = 0, location = 0,"  
           + ", height = " + height + ", width=" + width
		   + ", scrollbars=1";


/* use this for debug only */

properties = "menubar=yes, status=yes, scrollbars=yes, dirctories=yes, "
		   + "dependent=yes, toolbar=yes, location=yes, resizable=yes"  
           + ", height = " + height + ", width=" + width;

if(navigator.appName == "Microsoft Internet Explorer") {

   screenY = document.body.offsetHeight;
   screenX = window.screen.availWidth;
}
else {

   screenY = window.outerHeight
   screenX = window.outerWidth
}
   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
   }
   if(navigator.appName == "Microsoft Internet Explorer") {
      leftprop = cursorX + padAmtX;
      topprop = cursorY + padAmtY;
   }
   else {
      leftprop = (cursorX - pageXOffset + padAmtX);
      topprop = (cursorY - pageYOffset + padAmtY);
   }

if(evnt != null) {

    properties = properties + ", left = " + leftprop;
    properties = properties + ", top = " + topprop;
}
closePopup();
popupHandle = open(url,'popup',properties);
}


function closePopup() {
if(popupHandle != null && !popupHandle.closed) popupHandle.close();
}

/***************************************************************
* function targetopener
*          - this will close the popup window and refresh the 
*            main window. 
*   
* example usage 
*          - onClick=" return targetopener(this,true)"
*            where this is a url, and true sets closeme to true
***************************************************************/
function targetopener(mylink, closeme, closeonly)
{
  if (! (window.focus && window.opener))return true;
  window.opener.focus();
  if (! closeonly)window.opener.location.href=mylink;
  if (closeme)window.close();
  return false;
}


