/* utility.js, //_script	
 * Website Utilities
 * JavaScript 1.2
 * (c)2001 Network Design Consulting.  All rights reserved.
 * -----------------------------------------------------------------
 * 1.0.0  12/07/2001  rmg  created at NetDCon.com
 * -----------------------------------------------------------------
 * This script provides a variety of small semi-useful functions
 * See comments above each function for further details.
 * ----------------------------------------------------------------- */
/* Detect client's browser software and version
   Tested with:
      Netscape Navigator   - versions 4.7x through 6.x
      MS Internet Explorer - versions 4.0 through 6.x
      Opera Web Browser - version 5.x                                */
function cli(dflag) {
// Check for Object Modelling -----------------
   var cli_dom = (document.getElementById)? true : false;
   var cli_id = "zz"
// Look for Opera versions --------------------
   var cli_op = (window.opera)? true : false;
   if (cli_op) {
      if (cli_dom) {
         var cli_op5 = true;
         var cli_id = "op5";
      } 
      else {
         var cli_id = "op4";
      }
   }
// Look for Netscape versions -----------------
   var cli_ns = (window.outerWidth)? true : false;
   if (cli_ns) {
      if (cli_dom) {
      var cli_ns6 = true;
      var cli_id = "ns6";
      }
      else {
        var cli_ns4 = true;
        var cli_id = "ns4";
      }
   }
// Look for IE versions -----------------------
   var cli_ie = (document.all)? true : false;
   if (cli_ie) {
      if (cli_dom) {
         var cli_ie = true;
         var cli_id = "ie6";
      }
      else {
         var cli_ie4 = true;
         var cli_id = "ie4";
      }
   }
   if (dflag > 0) {
     document.write("Browser: " + cli_id);
   }
}
// Set display info -------------------------------------------
function ckr(clisr) {
   clisr = 1
   if (screen.width <= 800) clisr = 0;
   if (screen.width > 800)  clisr = 1;
   if (screen.width > 1152) clisr = 2;
   return [clisr];
}
// Write display info ---------------
function ckp() {
   clisr = 1
   if (screen.width <= 801) clisr = 0;
   if (screen.width > 801)  clisr = 1;
   if (screen.width > 1152) clisr = 2;
   document.write(clisr);
   return;
}
/* -----------------------------------------------------------------
   Output default frameset based on user's screen resolution                  */
function dfs() {
   clisr = ckr();
   if (clisr == 0) hhead = 66; wsnav = 80;
   if (clisr == 1) hhead = 96; wsnav = 116;
   if (clisr == 2) hhead = 106; wsnav = 128;
   document.writeln("<frameset rows=\"" + hhead + ",*\" border=\"0\">");
   document.writeln("  <frame name=\"head\" scrolling=\"no\" src=\"head.cfm\">");
   document.writeln("  <frameset cols=\"" + wsnav + ",*\" border=\"0\">");
   document.writeln("    <frame name=\"snav\" scrolling=\"no\" src=\"snav.cfm\">");
   document.writeln("    <frame name=\"info\" scrolling=\"auto\" src=\"home.cfm\">");
   document.writeln("  </frameset>")
   document.writeln("</frameset>")
}
/* -----------------------------------------------------------------
   Embed CSS based on user's screen resolution                       */
function dscss() {
   clisr = ckr();
   document.writeln("<link rel=\"stylesheet\" href=\"_css/main-r" + clisr + ".css\">");
   return;
 }
/* -----------------------------------------------------------------
   Select artwork based on user's screen resolution                  */
function dlogo() {
   clisr = ckr();
   document.writeln("<img src=\"_media/art-r" + clisr + "/logo-ZZ.jpg\">");
   return;
 }
/* -----------------------------------------------------------------    
   Print a Date/Time-sensitive greeting to the client                */
function hullo() {
  rightnow = new Date();
  righthour = rightnow.getHours();
  if (righthour < 12) {
     greeting = "Good Morning,";
  }
  else if (righthour < 18) {
     greeting = "Good Afternoon,";
  }
  else {
     greeting = "Good Evening,";
  }
  document.write(greeting);
}
// Dynamic Clock ----------------------------------------------
function clock() {
  if (!document.layers && !document.all) return;
    var digital = new Date();
    var hours = digital.getHours();
    var minutes = digital.getMinutes();
    var seconds = digital.getSeconds();
    var amOrPm = "AM";
  if (hours > 11) amOrPm = "PM";
  if (hours > 12) hours = hours - 12;
  if (hours == 0) hours = 12;
  if (minutes <= 9) minutes = "0" + minutes;
  if (seconds <= 9) seconds = "0" + seconds;
  dispTime = hours + ":" + minutes + ":" + seconds + " " + amOrPm;
  if (document.layers) {
    document.layers.pendule.document.write(dispTime);
    document.layers.pendule.document.close();
  }
  else
    if (document.all)
      pendule.innerHTML = dispTime;
      setTimeout("clock()", 1000);
  }

// Basic Inquiry Form validation ------------------------------ 
function CheckRequired() {
   if (document.inqy.inqyfnam.value=='') {
      alert('Name - (empty required field)');
      document.inqy.inqyfnam.focus();
      return false;
   }
   if (document.inqy.inqysubj.value=='') {
      alert('Subject - (empty required field)');
      document.inqy.inqysubj.focus();
      return false;
   }
   if (!IsEmailValid(document.inqy.inqymail.value)) {
      alert('Email - (empty or appears invalid)');
      document.inqy.inqymail.focus();
      return false;
   }
}

function IsEmailValid(sEmail) {
   var EmailOk  = true;
   var AtSym    = sEmail.indexOf('@');
   var Period   = sEmail.lastIndexOf('.');
   var Space    = sEmail.indexOf(' ');
   var Length   = sEmail.length - 1;   // Array is from 0 to length-1
   if (sEmail=='') {
      return false;
   }
   if ((AtSym < 1) ||                     // '@' cannot be in first position
      (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
      (Period == Length ) ||             // Must be atleast one valid char after '.'
      (Space  != -1))                    // No empty spaces permitted
   {
      EmailOk = false;
   }
   return EmailOk;
}

function CheckPassword() {
   if (document.forms[0].Password2.value!=document.forms[0].Password.value) {
      alert('Passwords do not match.');
      document.forms[0].Password.focus();
      return false;
   }
   else {
      return true;
   }
}
