<!--
/*
  Common JScript Routines.
  Copyright PAC & VNA 2000-2004

  Use:
  Put this in the <head>:
  <SCRIPT type='text/javascript' language='JavaScript' SRC='../JScripts/JScriptCommonLib.js'></SCRIPT>

*/

var WinChild; // global child

// Write out error
function Error2Screen (objError)
{
 document.write ("<p>(+1)---JavaScript Error Dump--v");
 var nCnt = 0;
 document.write ("<br>(+2)Typeof error object is: " + typeof(objError) + ".");
 // Output depends on error object
 switch (typeof(objError))
 { 
   case "object": // true error object
    for (var member in objError)
    { 
      document.write ("<br>(+3)" + ++nCnt + ") " + member + ": " + objError[member]);
    }
    break;
   default:
    // error string/number
    if (nCnt == 0)
    {
      document.write ("<br>(+3)" + objError );
    } 
    break;
 }
 document.write ("<br>(+4)---Error Dump--^<p>");
 return true;
}

// Script Accessible?
function bCommonLibAlive()
{
  return true;
}

// Change Title on Page
function bNewTitle
(
 sNewTitle // string to use
)
{
 document.title = sNewTitle;
}

// Function closes a non-frames browser window
function CloseWindow 
(
  linkText,  // hyperlink text
  CursorTip  // mouse-over tip
)
/*
   Purpose: Closes window when user clicks hyperlink text
     Notes: Accomplishes same as following HTML:
      <a href="javascript:window.close()" title="Cursor Tip">Close Window</a>
   Returns: nothing
    History: PAC 2000 Aug 18 Consolidated existing function into this lib.

*/
{
  linkText = (linkText == null) ? "Close Window" : linkText;
  CursorTip = (CursorTip == null) ? "Close&nbsp;this&nbsp;Window" : CursorTip;
  document.write("<a href='javascript:top.close()' title=" 
                    + CursorTip + ">" + linkText + "</a>");
}    

// Function opens a new browser window for images, resizes to fit image
function OpenResizeWindow
(
 image_name, // image file name
 win_name, // unique name for id, does not show, MUST NOT HAVE SPACES
 win_title // title bar
) 
/*
  Purpose: Takes image filename and window name, opens new window resized to image.
    Notes: Global var WinChild at top of this file.
           Replaces OpenWindow().
  Returns: nothing
  History: Aug. 12/13, 2003
           Feb. 17, 2009: now uses title bar string as alternate image text
*/
{
  if (WinChild != null) {WinChild.close();}
  WinChild = window.open("",win_name,"top=0,left=0,scrollbars,resizable")
  WinChild.document.write("<HTML><HEAD></HEAD><BODY>")
  WinChild.document.write("<img border='0' alt='" + win_title + "' src='" + image_name   + "' onLoad='javascript:window.resizeTo(Math.min(this.width+50,screen.width),Math.min(this.height+65, screen.height));return false;'>");
  WinChild.document.write("</BODY></HTML>")
  WinChild.document.title = win_title;
  WinChild.focus();
}

// Function opens a new browser window
function OpenWindow
(
  file,       // document file name
  unique,     // unique name for id, does not show, MUST NOT HAVE SPACES
  parameters  // optional parameters to set
)
/* 
  Purpose: Will open browser with file and bring it to front. 
    Notes: Allowed parameters: 
              toolbar, location, directories, status, menubar, scrollbars, 
              resizable, width=x, height=x
              
           Common usage examples:
           1) Simple
            a) Put this in the <body>:
           <a href="sample.htm" target="_blank" onclick="OpenWindow('sample.htm','unique_nm','width=540,height=480,scrollbars,resizable');return false;">Target Text</a>

           2) Complicated 
            a) Put this in the <body>:            
           <SCRIPT><!-- execute this if JS is enabled:
             document.write('<a href="javascript:OpenWindow(\'http://sample.htm\',\'unique_nm\',
                            \'width=300,height=200,scrollbars,resizable\');">');
           // else execute the following --></SCRIPT>
           <NOSCRIPT> 
             <a href="test%20text.htm" title="Non-Java Click" target="_blank">
           </NOSCRIPT>
           Target Text</a> <!-- In any case the target text is needed -->
  Returns: nothing
  History: PAC 2000 Aug 18 Consolidated existing function into this lib.
*/
{
  parameters = (parameters == null) ? "resizable" : parameters;
  WinObj = window.open(file, unique, parameters);  // open browser
  WinObj.focus();                           // bring to top
}


// -->
