//-------------------------------------------------------------------------
// Script.js
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
// Function: setfocus
//
// Set the focus to the first form element.
//-------------------------------------------------------------------------

function setFocus() {

    var finished = false;
    var index = 0;
    if (document.forms[0] != null)
    {       
      while ( finished == false ) 
      {
        if (document.forms[0].elements[index].type != 'hidden') 
        {
            document.forms[0].elements[index].focus();
            finished = true; 
        }

        index++;
      }
    }
}

//-------------------------------------------------------------------------
// Function: openNewWindow
//
// Pops up a new browser window containing the definitions page, and scrolls
//     to the correct spot
//-------------------------------------------------------------------------

function openDefWindow(inURL) {

    openNewWindow(inURL, 
           'def_win',
           'directories=no,location=no,menubar=no,scrollbars=yes,toolbar=no,status=no,resizable=yes', 
           'small');

}

//-------------------------------------------------------------------------
// Function: openNctEntryWindow
//
// Pops up a new browser window containing the NCT Entry screen
//-------------------------------------------------------------------------

function openNctEntryWindow(inURL) {

    openNewWindow(inURL, 
           '_blank',
           'directories=no,location=no,menubar=no,scrollbars=yes,toolbar=no,status=no,resizable=yes', 
           'medium');

}

//-------------------------------------------------------------------------
// Function: openDocWindow
//
// Pops up a new browser window containing a document, such as the 
// PRS Reference Guide.
//-------------------------------------------------------------------------

function openDocWindow(inURL) {

    openNewWindow(inURL, 
           '_blank',
           'directories=no,location=no,menubar=no,scrollbars=yes,toolbar=yes,status=no,resizable=yes', 
           'medium');

}

//-------------------------------------------------------------------------
// Function: openNewWindow
//
// Pops up a new browser window containing the definitions page, and scrolls
//     to the correct spot
//-------------------------------------------------------------------------

function openNewWindow(inURL, name, features, windowSize) {

    // Add check for browser capability
    var old_browser = true;
    if (window.screen != null) old_browser = false;

    if (features == "") {
        features = "toolbar=yes,directories=yes,location=1,status=yes,menubar=yes,scrollbars=yes,resizable=yes";
    }
    
    var height=250;
    var width=350;
    var screenHeight = 480;
    var screenWidth = 640;

   if(windowSize == 'small')
   {
       height = 150;
       width = 200;
   }
   if(windowSize == 'medium')
   {
       height = 300;
       width = 500;
   }



    if (window.screen != null)
    {
        screenHeight = window.screen.height;
        screenWidth = window.screen.width;
    }

    if (screenWidth > 640)
    {
        width = width + (screenWidth - 640)*.50;
    }

    if(screenHeight > 480)
    {
        height = height + (screenHeight - 480)*.50;
    }

    features += ",width=" + width + ",height=" + height;

    var docView = window.open (inURL, name, features);

    docView.focus();


}
