
// --------------------------------------------------
//  Check first five characters of a string
// --------------------------------------------------
// FUNCTION source()
//   -- used to check if referrer is web site or local file ("http:" or "file:")
//
function source(str) {
  newStr = "" ;
  for (j=0; j < 5 ; j++) {
    c=str.charAt(j) ;
    newStr += c ;
  }
  return newStr ;
}



// ------------
//  Write links
// ------------

// ------------------------------------------------ 
// FUNCTION write_local_localnet()
//   -- write link for localnet local page (localnet image on C)
//
function write_local_localnet() {
  anchor = "" ; 
  document.write("\<a href=\"file:///c:/ddrive/steve/yo.yo/www/localnet/public_html/") ; 
  return anchor ; 
}

// ------------------------------------------------ 
// FUNCTION write_local_docsteve()
//   -- write link for docsteve local page (docsteve image on C)
//
function write_local_docsteve() {
  anchor = "" ; 
  document.write("\<a href=\"file:///c:/ddrive/steve/yo.yo/www/docsteve/www/") ; 
  return anchor ; 
}

// -------------------------------------------------------
// FUNCTION write_uri_localnet()
//   -- write link for localnet remote page ( localnet.com/~docsteve/ )
//
function write_uri_localnet() {
  anchor = "" ; 
  document.write("\<a href=\"http://members.localnet.com/~docsteve/") ;
  return anchor ; 
}

// --------------------------------------------
// FUNCTION write_uri_docsteve()
//   -- Write link for docsteve remote page ( docsteve.com )
//
//
function write_uri_docsteve() {
  anchor = "" ; 
  document.write("\<a href=\"http://www.docsteve.com/") ;
  return anchor ; 
}



// --------------------------------------------------------------------------
// define two functions to check for and return screen data: height & width
// --------------------------------------------------------------------------

// -----------------------
// FUNCTION inner_width()
//   -- used in margin and border functions 
//      (may also be used stand-alone)
//
function inner_width() {
  if (document.body.clientWidth)
    return (document.body.clientWidth) ;              // Works in Mozilla 1.4 and IE 6.0 but not in NS 4.78
  else if (window.innerWidth)
    return (window.innerWidth) ;                      // Works in Mozilla 1.4 and NS 4.78 but not in IE 6.0
  else if (document.documentElement.clientWidth)
    return (document.documentElement.clientWidth) ;   // Generally resolves to zero, but odd browsers may populate it
  else
    return (0); 
}

// ------------------------
// FUNCTION inner_height()
//   -- used in menu functions 
//      (may also be used stand-alone)
//
function inner_height() {
  if (document.body.clientHeight)
    return (document.body.clientHeight) ;              // Works in Mozilla 1.4 and IE 6.0 but not in NS 4.78
  else if (window.innerHeight)
    return (window.innerHeight) ;                      // Works in Mozilla 1.4 and NS 4.78 but not in IE 6.0
  else if (document.documentElement.clientHeight)
    return (document.documentElement.clientHeight) ;   // Generally resolves to zero, but odd browsers may populate it
  else
    return (0); 
}



// --------------------------------------------------
//  Set margins or borders
// --------------------------------------------------
// FUNCTION write_margin_div_tag()
// FUNCTION write_border_div_tag()
// FUNCTION write_mar_bord_div_tag()
//  -- alternative versions
//  -- use with a non-script div element as a backup 
//     (each function closes a presumed preceeding open div)
//
// -----------------------
// main function: margins
//
function write_margin_div_tag() {
  // compute margin: allow for at least two percent margin in all cases 
  // set desired content area width as constant (replace 600)
  mar = (((inner_width()-600)/2)/inner_width())* 100 
  if (mar < 2) { mar=2 } 
  // create left/right margin variable (allow .5-em margin top/bottom)
  abc = 'margin: .5em ' + mar + '%'
  // write html -- first close the "non-script" element, then write the new formatting element
  document.write("\</div>\<div style=\"" + abc + "\"> ") 
}

// -----------------------
// main function: borders
//
function write_border_div_tag() {
  // compute border: allow for at least two percent border in all cases 
  // set desired content area width as constant (replace 600)
  bor = ((inner_width()-600)/2)
  if (bor < 2) { bor=2 } 
  // create left/right border variable (allow .5-em margin top/bottom)
  abc = 'border-top: .5em ; border-left: ' + bor + 'px solid white ; border-bottom: .5em ; border-right: ' + bor + 'px solid white' ; 
  // write html -- first close the "non-script" element, then write the new formatting element
  document.write("\</div>\<div style=\"" + abc + "\"> ") 
}

// ------------------------------------------------------------------
// main function: margin with border outline and padding from border
//
function write_mar_bord_div_tag() {
  // compute border: allow for at least two percent border in all cases 
  // set desired content area width as constant (replace 650)
  mar = (((inner_width()-650)/2)/inner_width())* 100 
  if (mar < 2) { mar=2 } 
  // create left/right margin variable (allow .5-em margin top/bottom)
  abc = 'border: .5em solid #ffe7ad ; margin: .5em ' + mar + '% ; padding: 0 1em' ; 
  // write html -- first close the "non-script" element, then write the new formatting element
  document.write("\</div>\<div style=\"" + abc + "\"> ") 
}



// -----------------------------------------------------
//  Clock
// -----------------------------------------------------
// FUNCTION get_browser()
// FUNCTION print_time()
// FUNCTION calculate_time()
//   -- requires all three functions
//   -- appears to require placement in body, not head
//
// ---------------------------------
// Code Segment One: Detect browser 
function get_browser() {
  function version_major() { 
    var radix = 10 ; 
    var v_m = parseInt (navigator.appVersion,radix) ; 
    return (v_m) ;
  }
  if (version_major() > 3) { 
    if (navigator.appName == "Microsoft Internet Explorer" || version_major() >4) { run = 1 } 
    else { run = 0 }
  }
  return (run) ; 
}
//
// ----------------------------------
// Code Segment Two: Write html code 
//
function print_time() {
  if (get_browser()) {
    document.writeln("\<span")
    document.writeln("  id=\"clock\"")
    document.writeln("  style=\"position:absolute;left:5px;top:5px;color:#993300;font-weight:bold;font-size:10pt\">00:00:00 a.m. (-00:00)\</span>")
  }
}
//
// -------------------------------------
// Code Segment Three: Time calculation
//
function calculate_time()  {
  var time = new Date() ;
  var hours = time.getHours() ;
  var minutes = time.getMinutes() ;
  var seconds = time.getSeconds() ;
  var tzo = time.getTimezoneOffset() ; 
  var timesuffix = "a.m.";
  if (hours > 11) { timesuffix = "p.m." }
  if (hours > 12) { hours = hours - 12 } 
  if (hours == 0) { hours = 12 }
  if (hours < 10) { hours = "0" + hours }
  if (minutes < 10) { minutes = "0" + minutes; }
  if (seconds < 10) { seconds = "0" + seconds; }
  tzo /= 60 ; 
  if (tzo <= 9) tzo = "0" + tzo ;
  if (run) { 
    var clock_print = document.getElementById('clock') 
    clock_print.innerHTML = hours + ":" + minutes + ":" + seconds + " " + timesuffix + " (-" + tzo + ":00)" 
    setTimeout("calculate_time()", 1000);
  }
}
//



// -----------------------------------------------------
// Special Indents & Borders
// -----------------------------------------------------
// FUNCTION spec_indent_1_compute()
// FUNCTION spec_indent_1_open()
// FUNCTION spec_indent_1_close()
//   -- used with HTML Symbols page
//   -- open the segment with open function 
//   -- close with close function :)
//
function spec_indent_1_compute() {
  var column = new Object(); 
  column.raw = screen.width
  column.text=100*(600/column.raw);
  if (column.text > 95.0) {column.text = 95.0} else
  if (column.text < 50.0) {column.text = 50.0} 
  return (column.text)
} 
function spec_indent_1_open()  { 
  var column = new Object(); 
  column.StartString="<table summary=\"provide white background for text\" align=\"center\" width=\"" + spec_indent_1_compute() + "%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td width=\"2%\" bgcolor=\"#ffffff\">&nbsp;<\/td><td bgcolor=\"#ffffff\" colspan=\"2\" id=\"Std\" width=\"96%\">" ;
  return(column.StartString) }
function spec_indent_1_close() {
  var column = new Object(); 
  column.EndString="<\/td><td width=\"2%\" bgcolor=\"#ffffff\">&nbsp;<\/td><\/tr><\/table>"; 
  return(column.EndString) }
//



// ---------------------------------------------
// Print date on page
// ---------------------------------------------
// FUNCTION put_date()
//
function put_date() {
  var monthNames = new Array(12);
  monthNames[0] = "January";
  monthNames[1] = "February";
  monthNames[2] = "March";
  monthNames[3] = "April";
  monthNames[4] = "May";
  monthNames[5] = "June";
  monthNames[6] = "July";
  monthNames[7] = "August";
  monthNames[8] = "September";
  monthNames[9] = "October";
  monthNames[10] = "November";
  monthNames[11] = "December";

  var now   = new Date();
  var month = now.getMonth();
  var date  = now.getDate();
  var year  = now.getYear();
  if (year < 2000) { year += 1900 }

  document.write(" \<span style=\"position:absolute;left:5px;top:20px;color:#993300;font-weight:bold;font-size:10pt\">")
  document.write( monthNames[month] + " " + date + ", " + year );
  document.write(" \</span>")
}
//



//----------------------------------
// Menu Bar for Home Page
//----------------------------------
// FUNCTION menu()
//
function menu() {
  var aspect_ratio = 0 ; 
  var pt1 = 1 ; 
  var pt2 = 12 ; 
  var spacer = "     " ; 
  var clss =  "         " ; 
  if (inner_width() >= 750) {
    if (inner_width() >= 1000)     {pt1 = 20 ; pt2 = 20 ; spacer = "       " ; clss = 'class=\"menu1\"'}
    else if (inner_width() >= 960) {pt1 = 20 ; pt2 = 20 ; spacer = "\<br />" ; clss = 'class=\"menu1\"'}
    else if (inner_width() >= 820) {pt1 = 16 ; pt2 = 16 ; spacer = "\<br />" ; clss = 'class=\"menu1\"'}
    else if (inner_width() >= 790) {pt1 = 14 ; pt2 = 14 ; spacer = "\<br />" ; clss = 'class=\"menu1\"'} 
    else if (inner_width() >= 775) {pt1 =  1 ; pt2 = 14 ; spacer = "\<br />" ; clss = 'class=\"menu2\"'} 
    else                           {pt1 =  1 ; pt2 = 12 ; spacer = "\<br />" ; clss = ''} 

    aspect_ratio = inner_width()/inner_height() ; 

    document.write("\<div class=\"side_index\" style=\"font-size:" + pt2 + "pt \">")
    document.write("  \<span style=\"font-size:" + pt1 + "pt\">&#183;\</span>\<span style=\"font-style:italic\"><a " + clss + "style=\"white-space:nowrap\" href=\"TechNotes/index.html\" tabindex=\"1\">Technical\</a>\</span>\<br />")
    document.write("  \<span style=\"font-size:" + pt1 + "pt\">&#183;\</span>\<span style=\"font-style:italic\"><a " + clss + "style=\"white-space:nowrap\" href=\"Samples/index.html\" tabindex=\"2\">Samples\</a>\</span>\<br />")
    document.write("  \<span style=\"font-size:" + pt1 + "pt\">&#183;\</span>\<span style=\"font-style:italic\"><a " + clss + "style=\"white-space:nowrap\" href=\"Design/index.html\" tabindex=\"3\">Design\</a>\</span>\<br />")
    document.write("  \<span style=\"font-size:" + pt1 + "pt\">&#183;\</span>\<span style=\"font-style:italic\"><a " + clss + "style=\"white-space:nowrap\" href=\"Utilities/index.html\" tabindex=\"4\">Utilities\</a>\</span>\<br />")
    document.write("  \<span style=\"font-size:" + pt1 + "pt\">&#183;\</span>\<span style=\"font-style:italic\"><a " + clss + "style=\"white-space:nowrap\" href=\"contacts.shtml\" tabindex=\"5\">Contacts</a>\</span>\<br /><br />")

    if (inner_height() > 440) {
      document.write("  \<span style=\"font-size:" + pt1 + "pt\">&#183;\</span>\<span style=\"font-style:italic\">")
      if (source(document.URL) == "file:") { 
        document.write(write_local_localnet() ) ;  
      } 
      else { 
        document.write(write_uri_localnet() ) ;
      }
      document.write("index.html\" tabindex=\"6\">Doc Steve\</a>\</span>"); 

      if (inner_height() > 520)  {
        if (aspect_ratio > 1.4) {
          pt3 = pt1 - 5 ; 
          document.write("\<div style=\"font-size:" + pt3 + "pt;text-indent:.5em\">\<i>\<b>Steve's " + spacer + " personal page\</b>\</i></div>") 
        }
      }
    }
    document.write("\</div>")
  }
}
//



//----------------------------------
// Round-off number value
//----------------------------------
// FUNCTION roundOff(value, precision)
//
function roundOff(value, precision) {
  value = "" + value //convert value to string
  precision = parseInt(precision);

  var whole = "" + Math.round(value * Math.pow(10, precision));

  var decPoint = whole.length - precision;

  if(decPoint != 0) {
    result = whole.substring(0, decPoint);
    result += ".";
    result += whole.substring(decPoint, whole.length);
  }
  else { result = whole; }
  return result;
}
//


