/**
 *  printerFriendly.js
 *
 */
 
//-----------------------------------------------------------------------|
// START GLOBALS
//-----------------------------------------------------------------------|

var PRINTER_FRIENDLY_WINDOW_NAME = "printerFriendlyWindow";
var PRINTER_FRIENDLY_DIV_ID = "content";

var POPUP_HTML = "popup.html";


var DEFAULT_WINDOW_JS_OPTIONS = "width=700,height=500,resizable=yes,scrollbars=yes";
var windowArray = new Array();
var windowIndexArray = new Array();
 
//-----------------------------------------------------------------------|
// END GLOBALS
//-----------------------------------------------------------------------|
  
//-----------------------------------------------------------------------|
// START FUNCTIONS
//-----------------------------------------------------------------------| 

/**
 *  Displays the content div in the popup. 
 */
function handlePrinterFriendlyPopup(anHtml)
{
    var valid = false;
    var theWindow = windowHelper(anHtml, PRINTER_FRIENDLY_WINDOW_NAME);
    if( theWindow != null )
    {
        theWindow.focus();
    }

    return theWindow;
}

function isNull(anObj)
{
    return ( !anObj || ( typeof(anObj) == 'undefined' ) || anObj == null );
}

function windowHelper(theAnchor,theWindowName)
{
  var theWindow = null;

  for (i=0; i<windowIndexArray.length; i++) {
     if (windowIndexArray[i] == theWindowName)
        theWindow = windowArray[i];
  }

  if ( isNull(theWindow) || theWindow.closed )
  {
     windowIndexArray[windowArray.length + 1] = theWindowName;
     windowArray[windowArray.length + 1] = window.open(theAnchor,theWindowName, DEFAULT_WINDOW_JS_OPTIONS);
  } else {
     theWindow.focus();
  }

  return theWindow;
}

//-----------------------------------------------------------------------|
// END FUNCTIONS
//-----------------------------------------------------------------------| 
