
// --- Web Site Control Program ---

// --- Programming and Code Copyright Notice:
// Developed by LCC Enterprises, December, 2003
// Contains or may contain original and manual & auto generated
// HTML, JavaScript, CSS, and other programming code.
// ©2003 by LCC Enterprises.   All rights reserved.
// ---
// This installation under license for use by Pirrello Digital Imaging


// --- Web Site Copyright Notice:
// The actual rendering of this web site created by this code - 
// including design, layout, presentation, and content, and
// any and all commercial photography provided by Pirrello Digital Imaging
// used as images rendered in this web site
// is the property of Pirrello Digital Imaging.
// ©2003 by Pirrello Digital Imaging.   All rights reserved.


// --- Description:
// This the primary web site entrance control program.
// Its purpose is to test the client system and configuration to make certain the 
// client machine and browser will correctly render the web site content and be able
// to control navigation.  If so, then the program opens a new browser window that
// actually contains the web site content and navigational controls.

// --- Dependencies:
// This program requires that the following program files be preloaded before execution:
//     > BrowserDetectLite.js
//     > getipaddress.cgi (server-side script)

if (!((typeof(top.MainDoorCode) == "string") && (top.MainDoorCode == "lcc2004pdi"))) {
  top.location = "../index.htm";
  }

// -------------------------------------------------------------------------
// Define global variables:

// Debugger Switch
var $debug = false;

// Window Object for site sub-window
var pdiWndw;

// Call Browser detection information script and store data into brwser object
var brwsr     = new BrowserDetectLite();

// System Information variables
UserAgent     = navigator.userAgent;
AppName       = navigator.appName;
ScrAvlHeight  = screen.availHeight;
ScrAvlWidth   = screen.availWidth
ScrHeight     = screen.Height;
ScrWidth      = screen.Width;
ScrClrDepth   = screen.colorDepth;

// Browser Window location and size variables
var winLocX   = 0;      // Default for 800x600 display
var winLocY   = 0;      // Default for 800x600 display
var winHght   = 460;    // Default for IE4+ on Win-32 Sys
var winWidth  = 788;    // Default for IE4+ on Win-32 Sys 

// Other
var pdiWndwOpenedOK  = false;
var syssupported     = true;
var syswarning       = false;
var browsersupported = true;
var browserwarning   = false;
var displaysupported = true;
var displaywarning   = false;
var allsupported     = true;
var nowarnings       = true;
var webentranceOK    = true;
var indent           = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
var WC3DOM1          = false;
var WC3DOM2Event     = false;
var IEDOCALL         = false;


// -------------------------------------------------------------------------
// IP address of client
// -------------------------------------------------------------------------
  if (typeof extIPaddress == "undefined") {
    var extIPaddress = "(IP Address unavailable - you are probably not connected to the internet at present and are currently viewing this web site off-line)";
  }


// -------------------------------------------------------------------------
// Debug mode for the web site - helpful in determining browser interactions
// -------------------------------------------------------------------------
  if (parent.location.search == "?$debug=yes") {
    $debug = true;
  }


// -------------------------------------------------------------------------
// Collect System Information and check for compatibility Function
function checksysconfig () {

// debug message header

  if ($debug) {
    parent.cntlmsgFrame.document.writeln ("<hr><strong>General System and Browser Information:</strong><br>");
    parent.cntlmsgFrame.document.writeln (indent+"<em>Agent = </em>"+UserAgent+"<br>");
    parent.cntlmsgFrame.document.writeln (indent+"<em>IP Address = </em>"+extIPaddress+"<br>");   // Obtained from getipaddress.cgi
  }

// Platform check

  if (brwsr.isWin) {
    if (brwsr.isWin32) {
      if ($debug) {
        parent.cntlmsgFrame.document.writeln (indent+"<em>Operating System = </em>MS-Windows 32-Bit<br>");
      }
    }
    else {
      parent.cntlmsgFrame.document.writeln (indent+"<em>Operating System = </em>Obsolete or unknown Windows System (Not Supported)<br>");
      syssupported = false;
    }
  }
  else {
    if (brwsr.isMac) {
      if ($debug) {
        parent.cntlmsgFrame.document.writeln (indent+"<em>Operating System = </em>Macintosh<br>");
      }
    }
    else {
      if ($debug) {
        parent.cntlmsgFrame.document.writeln (indent+"<em>Operating System = </em>Unix, Linux, Sun, BSD, or other Unknown OS<br>");
      }
      var syswarning = true;
    }
  }

// Browser Check

  if ($debug) {
    parent.cntlmsgFrame.document.writeln (indent+"<em>Browser = </em>"+AppName+" V-"+brwsr.versionMinor+"<br>");
    parent.cntlmsgFrame.document.writeln (indent+"<em>Browser Signature(s) detected = </em>");
    if (brwsr.isGecko) {parent.cntlmsgFrame.document.writeln ("Gecko ");}
    if (brwsr.isMozilla) {parent.cntlmsgFrame.document.writeln ("Mozilla ");}
    if (brwsr.isNS) {parent.cntlmsgFrame.document.writeln ("Netscape ");}
    if (brwsr.isIE) {parent.cntlmsgFrame.document.writeln ("Internet Explorer ");}
    if (brwsr.isSafari) {parent.cntlmsgFrame.document.writeln ("Safari ");}
    if (brwsr.isOpera) {parent.cntlmsgFrame.document.writeln ("Opera ");}
    if (brwsr.isKonqueror) {parent.cntlmsgFrame.document.writeln ("Konqueror ");}
    if (brwsr.isIcab) {parent.cntlmsgFrame.document.writeln ("iCab ");}
    if (brwsr.isAol) {parent.cntlmsgFrame.document.writeln ("AOL ");}
    parent.cntlmsgFrame.document.writeln ("<br>");
    if (brwsr.isDOM1) {  
      WC3DOM1 = true;
    }
    if (brwsr.isDOM2Event) {  
      WC3DOM2Event = true;
    }
    if (document.all) {
      IEDOCALL = true;
    }
    parent.cntlmsgFrame.document.writeln (indent+"<em>W3C Dom1 Support = </em>"+WC3DOM1+"<br>");
    parent.cntlmsgFrame.document.writeln (indent+"<em>W3C Dom2 Event Support = </em>"+WC3DOM2Event+"<br>");
    parent.cntlmsgFrame.document.writeln (indent+"<em>IE DocAll Method Support = </em>"+IEDOCALL+"<br>");
    parent.cntlmsgFrame.document.writeln ("<br>");
  }
  if (brwsr.isIE) {
    if (!brwsr.isIE4up) {
      browsersupported = false;
      parent.cntlmsgFrame.document.writeln (indent+"<strong>ERROR: </strong>Obsolete version of Internet Explorer Browser detected - Upgrade to version 4 or higher required to access this site.<br>");
    }
    else {
      dummy = null;
    }
  }
  else {
    if (brwsr.isNS) {
      if (!brwsr.isNS6up) {
        browsersupported = false;
        parent.cntlmsgFrame.document.writeln (indent+"<strong>ERROR: </strong>Obsolete version of Netscape Browser detected - Upgrade to version 6 or higher required to access this site.<br>");      
      }
      else {
        dummy = null;
      }
    }
    else {
      browserwarning = true;
      // Put error handler here $$$$$$$$$$$$$$$$$$$$
    }
  }

  if ($debug) {
    parent.cntlmsgFrame.document.writeln ("<br><strong>Display Screen Information:</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(dimensions in pixels)<br>");
    parent.cntlmsgFrame.document.writeln (indent+"Avail. Width = "+ScrAvlWidth+",  Avail. Height = "+ScrAvlHeight+",  Total Width = "+ScrWidth+",  Total Height = "+ScrHeight+",  Color Depth (bits) = "+ScrClrDepth+"<hr>");
    parent.cntlmsgFrame.scrollBy(0, 500);
  }

// MY NOTE -------> add check and processing if these are undefined

  if (ScrAvlWidth < 800 || ScrAvlHeight < 570) {
    displaysupported = false;
  }
  else {
    dummy = null;
  }

  if (!(syssupported && browsersupported && displaysupported)) {
    allsupported = false;
  }
  if (syswarning || browserwarning || displaywarning) {
    nowarnings = false;
  }

  if (allsupported && nowarnings) {
    if ($debug) {
      parent.cntlmsgFrame.document.writeln ("<br><strong>System Checks Completed - All Okay.  Client system should be able to properly render this Web Site</strong><br><br>");
    }
    parent.cntlmsgFrame.scrollBy(0, 500);
  }

// Now all Error and Warning Messages

  if (!displaysupported) {
    webentranceOK = false;
    parent.cntlmsgFrame.document.writeln ("<strong>Monitor/Display Compatability Problem</strong><br>The current setting for your computer screen is less than what is needed to properly display the Pirrello Digital Imaging Web Site.<br>");
    parent.cntlmsgFrame.document.writeln ("This web site requires a minimum screen resolution of at least 800 x 600 with an available height of at least 570 pixels in order to contain a browser window large enough to properly display and navigate this site.<br>");
    parent.cntlmsgFrame.document.writeln ("In order to view this site you will first need to change the display settings on your computer to a screen resolution of at least 800 x 600. If you are using an older computer or monitor or are using a portable or hand-held device that does not support a display resolution of at least 800 x 600, you will need to view this web site on a different system.<br>");
    parent.cntlmsgFrame.document.writeln ("We apologize for any inconvenience this may cause you.");
    parent.cntlmsgFrame.document.scrollBy(0, 500);
    alert ("Display incompatability - Unable to render the requested web page on this computer - Read text in browser window for complete information ");
  }

//  Spare statement templates
//  parent.cntlmsgFrame.document.writeln ("<br>");


}


// -------------------------------------------------------------------------
// Set up Browser Window Parameters Function
function setupbrowsewinparms () {
  // Calculate Browser window location to place near center of user's screen
  winLocX = Math.floor((ScrAvlWidth - 800) / 2);
  winLocY = Math.floor((ScrAvlHeight - 600) / 2);
  if (winLocX < 0) {winLocX = 0}
  if (winLocY < 0) {winLocY = 0}
  // Calculate Precise Browser Window Height based on Browser Type and system
  if (brwsr.isWin) {                     // Windows
    if (brwsr.isIE) {                       // IE
      winHght   = 460;
      winWidth  = 788;
    }
    else {
      if (brwsr.isGecko) {                  // Netscape, Gecko, Firefox, Mozillo
        winHght   = 480;
        winWidth  = 788;
      }
      else {                                // Anything Else (default to largest screen in Win list)
        winHght   = 480;
        winWidth  = 788;
      }
    }
  }
  else {                                  // Mac
    if (brwsr.isMac) {
      if (brwsr.isIE) {                      // IE
        winHght   = 465;
        winWidth  = 768;
      }
      else {
        if (brwsr.isSafari) {                // Safari
          winHght   = 500;
          winWidth  = 788;
        }
        else {
          if (brwsr.isGecko) {               // Firefox, Mozilla
            winHght   = 485;
            winWidth  = 788;
          }
          else {                             // Anything Else (default to largest screen in Mac List)
            winHght   = 500;
            winWidth  = 788;
          }
        }
      }
    }
    else {                                // Not Windows or Mac
      winHght   = 500;
      winWidth  = 788;
    }
  }
}


// -------------------------------------------------------------------------
// Open Site Window Function
function opensitewndw () {
  var optsList, winlocStr, winsizeStr;
  winlocStr = "left=" + winLocX + ",top=" + winLocY + ",screenx=" + winLocX + ",screeny=" + winLocY;
  winsizeStr = "height=" + winHght + ",width=" + winWidth;
  optsList =  "menubar=yes,toolbar=no,status=yes,resizable=yes," + winsizeStr + "," + winlocStr;
  pdiWndw = window.open("../site/main.htm","pdiWndw",optsList);
}


// -------------------------------------------------------------------------
// ------------- Verify Site Window Exists Function
function vrfysitewndw () {
  // If the window exists and is open
  if (pdiWndw && !pdiWndw.closed) {
    pdiWndwOpenedOK = true;
    if (pdiWndw.opener == null) {pdiWndw.opener = self;}   // Support for older browsers for the opener property
    if ($debug) {
      parent.cntlmsgFrame.document.writeln ("<br>Site window reports it has opened and is now loading ...");
    }
    setTimeout("vrfySiteWndwRunning()", 5000); // Now verify if the window is actually running (Some 3rd party non-compliant Pop-up blockers actually get this far)
    if ($debug) {
      parent.cntlmsgFrame.document.writeln ("<br>Now attempting to confirm that window is actually running ...");
    }
  }
  else {
    window.top.name = "pdiWndwNP";  // Set the Window name to the no pop-up version to let the main site know it is okay to render in this window
    if ($debug) {
      parent.cntlmsgFrame.document.writeln ("<p align='center'><strong>Use of Pop-Up blocker detected and this site being blocked.  Cannot load site in new window.</strong></p>");
      parent.cntlmsgFrame.document.writeln ("<p align='center'><strong><font color='red'>Click Here to bring up site in this window</font></strong></p>");
    }
    else {
      setTimeout("top.location = 'main.htm'",1000);  // Bring up the site in this window after a second to allow the document in this window to close and processing to complete.
    }
  }
}


// -------------------------------------------------------------------------
// ------------- Verify Site Window is actually running and is not some phantom window that a non-compliant pop-up blocker won't let you see
function vrfySiteWndwRunning () {
  if ((typeof(pdiWndw.pdiWndwRunning) == "boolean") && (!pdiWndw.pdiWndwRunning)) {
    pdiWndw.close(); // close the phantom window to ensure it does not exist with the official site window name
    window.top.name = "pdiWndwNP";  // Set the Window name to the no pop-up version to let the main site know it is okay to render in this window
    if ($debug) {
      parent.cntlmsgFrame.document.writeln ("<br>No verification received from site window that it is actually running");
      parent.cntlmsgFrame.document.writeln ("<br>This would indicate client system is running a 3rd-party pop-up blocker that is <u>not</u> JavaScript 1.0+ compliant.</strong></p>");
      parent.cntlmsgFrame.document.writeln ("<p><strong>Site could not be rendered into the optimally designed intended window.</strong></p>");
      parent.cntlmsgFrame.document.writeln ("<p align='center'><strong><font color='red'>Click Here to bring up the web site in this window</font></strong></p><hr>");
    }
    else {
      setTimeout("top.location = 'main.htm'", 1000);  // Bring up the site in this window after a second to allow the document in this window to close and processing to complete.
    }
  }
  else {
    if ($debug) {
      parent.cntlmsgFrame.document.writeln ("<br>Site window reported it is opened and actually running.");
      parent.cntlmsgFrame.document.writeln ("<br>Pop-Up Windows seemed to be allowed for this web site");
      parent.cntlmsgFrame.document.writeln ("<br>You should be able to see this new window and this web site operating within it.</p>");
      parent.cntlmsgFrame.document.writeln ("<p><strong>Everything has checked out to be okay.<br>Nothing has been detected in this debug session to prevent proper and optimal rendering of this web site.</p><hr>");
    }
    else {
      setTimeout("go2welcomepage()", 5000);  // wait long enough for communications to complete between the 2 windows
    }
    // Following is in case the PDI window was already opened and remains open from a previous visit and the user reruns this control page either by a refresh or revisit
    pdiWndw.focus();  // This will bring the existing PDI window into front focus
    // !!! --- This designates completion of all conditional testing and normal operation of the site using the pop-up window  !!!
  }
  parent.cntlmsgFrame.document.writeln ("</BODY></HTML>");
  parent.cntlmsgFrame.document.close ();
  parent.cntlmsgFrame.scrollBy(0, 500);
}


// ------------- Go to the Welcome Page Function
function go2welcomepage () {
  window.top.location.replace("../welcome.htm");
}


// -------------------------------------------------------------------------
// System, Display, and Browser Test Main Function
function startsitenav () {
  window.top.name = " "; // This is to clear the window name in the event pop-ups were originally blocked and the site rendered in this window, and now in this session the user has decided to allow pop-ups for the site.
  parent.cntlmsgFrame.document.open ();
  parent.cntlmsgFrame.document.writeln ("<HTML><HEAD></HEAD><BODY>");
  parent.cntlmsgFrame.document.writeln ("<p><font size=2>");
  if ($debug) {
    parent.cntlmsgFrame.document.writeln ("<strong>Entering special debug mode for this web site ... </strong><br>");
    parent.cntlmsgFrame.document.writeln ("This mode is designed to help debug problems experienced with this web site.<br>");
    parent.cntlmsgFrame.document.writeln ("Checking system to confirm minimum site browsing requirements and prepare customization ...<br>");
  }
  checksysconfig ();
  if (webentranceOK) {
    if ($debug) {
    parent.cntlmsgFrame.document.writeln ("Continuing ...<br>Now configuring and sizing new browser window specific to your system ...<br>");
    }
    setupbrowsewinparms ();
    if ($debug) {
      parent.cntlmsgFrame.document.writeln ("Attempting to open site window near center of your screen ....<br>Verifying ....<br>");
      parent.cntlmsgFrame.scrollBy(0, 500);
    }
    setTimeout("opensitewndw ()", 1000);  // wait 1 second for pending communications on this window to complete before opening new window
    setTimeout("vrfysitewndw ()", 3000);  // wait 2 more seconds for new window to open before verifying it
  }
}


