// TRINPsite, 56.14.2-65.36.5, JS/BodyFnct.js at TRINP = www.trinp.org

/*
This JS file is only used by old HTML files.
Up-to-date HTML files make use of HeadObjs.js, which, in turn,
refers to other external files, such as BodyObjs.js. 
*/

//==================================================
// This function to be executed within the HEAD tags

function write_HeadO()
 {
  var localI=document.URL.toLowerCase().indexOf("/~ftptr025/")

  if (localI==-1) localI=document.URL.toLowerCase().indexOf("\\~ftptr025\\")
  if (localI>-1)
document.write('<base href="http://www.trinp.org/',document.URL.substring(localI+11),'">');
 }

write_HeadO()

// added on 61.33.1
//==================================================

function SnifF()  // this function to be discontinued
{ sniffO() }
function sniffO()  // this function to replace SnifF()
{
 var agtS = navigator.userAgent.toLowerCase();
 var appVerS=navigator.appVersion;
 var majorI = parseInt(appVerS);
 var ieT = (agtS.indexOf("msie")!=-1);
 var navT = ((agtS.indexOf("mozilla")!=-1) && (agtS.indexOf("spoofer")==-1)
  && (agtS.indexOf("compatible")==-1) && (agtS.indexOf("opera")==-1)
  && (agtS.indexOf("webtv")==-1));

 IE4UpT = (ieT && (majorI>=4));
 Nav4UpT = ( navT && (majorI>=4));
 Nav5UpT = ( navT && (majorI>=5));  // for Netscape 6 and 7
 majorI=appVerS.indexOf("MSIE ");
 majorI=parseInt(appVerS.substring(majorI+5))
 IE8UpT = (ieT && (majorI>=8));
}

function Get_PathS()
 {
  var urlS=document.URL.toLowerCase(); var endS='';
  var n=0;
  PathS=''; TRINPathS=''  // global variables

  for (n=0;n<urlS.length;n++)
  { if (urlS.charAt(n)=="\\")
     urlS=urlS.substring(0,n)+"/"+urlS.substring(n+1) };
  if ((urlS.indexOf('http://')>-1) || (urlS.indexOf('www.')>-1))
    { PathS='http://www.trinp.org/' }
   else
   {
    n=urlS.length-1
    while (n>-1)
    {
     endS=urlS.substring(n);
     if (endS.indexOf('/trinp/')>-1)
       { PathS=urlS.substring(0,n+1)+'TRINP/'; n=-1 }
         // (TRIN)PathS works only if using TRINP directory
      else { n-- }
    } 
    if (PathS=='')
     alert('JavaScript links such as those in the floating menus will only '+
           'work for files in the top directory, because of a change in '+
           'the off-line directory structure or name(s). (Make sure all '+
           'TRINPsite files and subdirectories are in a top directory '+
           'called "TRINP".)'); 
   }
  TRINPathS=PathS  // used for TRINPsite files shared with other sites,
                   // where PathS has a different value
 }

function Get_FileChar()
 {
  fileC="0";
  if ((document.URL.indexOf("MNI")>0) || (document.URL.indexOf("mni")>0))
   { if (document.URL.indexOf(".HTM")>0) fileC="8"; else fileC="3" };
  if (fileC=="0") // 'else' again does not work with Netscape 4.51!
   { if (document.URL.indexOf(".HTM")>0) fileC="6"; else fileC="1" };
 }

function CopyrightF(S) // parameter S not (yet) used
 {
  AlertS = "The initials MVVM stand for M. Vincent van Mechelen, "+
"the letters ASWW stand for (the number of years) after the Second World War. "+
"For more information click on 'Stichting DNI Foundation' at the bottom "+
"and on the (Metric) date at the top of this page."
  alert(AlertS)
 }

function withoutVarO(S)  // added on 64.52.6, from BodyObjs.js
{
 var N=S.indexOf('?');

 if (N>0) S=S.substring(0,N);
 N=S.indexOf('#');
 if (N>0) S=S.substring(0,N);

 return S
}

//===start source code for StatWind(T)===
/*
Copyright (C) 53-56 ASWW, M. Vincent van Mechelen. All Rights Reserved.
This script may be re-used for non-commercial puposes, if credit is
given to the author and to TRINPsite in the source code.
*/

function Greg_to_Metr(yChrEI,mGregI,dGregI)
{
 this.year=yChrEI-1945;
 if (mGregI==1) add_days=10;    if (mGregI==2) add_days=41;
 if (mGregI==3) add_days=69;    if (mGregI==4) add_days=100;
 if (mGregI==5) add_days=130;   if (mGregI==6) add_days=161;
 if (mGregI==7) add_days=191;   if (mGregI==8) add_days=222;
 if (mGregI==9) add_days=253;   if (mGregI==10) add_days=283;
 if (mGregI==11) add_days=314;
 if (mGregI==12)
  { if (dGregI<22) yr_day=344+dGregI;
     else { this.year=this.year+1; yr_day=dGregI-21 }
  }
  else  yr_day=dGregI+add_days;

 this.day=0;
 if (yChrEI%4==0)  // Gregorian leap year
  { if (yr_day>69 && mGregI>2)
     { yr_day=yr_day+1;
       if (yr_day==366) { this.week=52; this.day=8 }
     }
  }

 if (yr_day==183) { this.week=26; this.day=8 };
 if (this.day==0)
 { if (yr_day>182) yr_day=yr_day-1;
   this.day=1+((yr_day-1)%7);
   this.week=1+((yr_day-this.day)/7) }

 this.month=Math.floor((this.week+3)/4);
}
function two_digitS(number)
{
 numberS=number;
 if (number<10) numberS="0"+numberS
 return(numberS)
}
function TodayF()
{
 today=new Date();
 yChrE=today.getYear();
 if (yChrE<2000)
 { if (yChrE>99) yChrE=yChrE+1900;
    else yChrE=yChrE+2000 }
 mGreg=today.getMonth()+1; dGreg=today.getDate();
 Today= new Greg_to_Metr(yChrE,mGreg,dGreg);
 yNow=Today.year;
 mNow=Today.month; month_noS=two_digitS(mNow);
 wNow=Today.week; week_noS=two_digitS(wNow);
 dNow=Today.day;
}

function StatWind(T)
{
 TodayF();
 beginS="Today's date is ";
 dateS=yNow+"."+week_noS+"."+dNow;
 endS="";
  if ((week_noS=="01")&&(dNow==1)) endS=".  HAPPY NEW YEAR!"
// if (T)
   window.defaultStatus=beginS+dateS+endS;
//  else document.write(dateS);
}
//===end source code for StatWind(T)===

//===start source code for MenuF()===

 function Get_Variables()
 {
  if (Nav4UpT)
   { topS = ".top="; lftS = ".left="; docS = "document."; stlS = "";
     xS = "window.pageXOffset"; yS = "window.pageYOffset";
     x_inner = eval("window.innerWidth") - 116;
//     eval(docS + "HeadRight" + stlS + ".width=116")
   }
   else
   { topS=".pixelTop="; lftS=".pixelLeft="; docS="document.all.";
     stlS=".style";
     xS = "document.documentElement.scrollLeft";
     yS = "document.documentElement.scrollTop";
     x_inner = eval("document.body.clientWidth") - 100 }
  x0=eval(xS); y0=eval(yS);
  objectL="HeadLeft"; objectR = "HeadRight"
 }

 function Locate_Boxes()
 {
  if ((Nav4UpT) || (eval(yS)>0)) ydiff = y0 - eval(yS);
   else ydiff = y0 - eval("document.body.scrollTop");
    // for browsers for which 'documentElement' is always 0 or undefined
  if (ydiff<0) ydiff = ydiff-5; else ydiff = ydiff+4;
  if ((ydiff < -1) || (ydiff >1))
   { movey = Math.round(ydiff/10); y0 = y0 - movey };

  if (moveLefT) eval(docS + objectL + stlS + topS + y0);
   else eval(docS + objectL + stlS + topS + 0);
  eval(docS + objectL + stlS + lftS + 0);
  if (moveRighT) eval(docS + objectR + stlS + topS + y0);
   else eval(docS + objectR + stlS + topS + 0);
  eval(docS + objectR + stlS + lftS + (x0 + x_inner));

  setTimeout("Locate_Boxes()", 10);
 }

 function MenuF(S) // no use is made (yet) of the (string) parameter
 {
  var topS=""; var lftS=""; var docS=""; var stlS="";
  var xS=""; var yS=""; var x0=0; var y0=0; var ydiff=0; var movey=0;
  moveLefT=true; moveRighT=true;

  Get_Variables(); Locate_Boxes();
 }

 function Turn_Menu(lefT,onT) // 'false, false'='right off'
 {
  var SideS="Left"; if (!lefT) SideS="Right";
  var VisS="Menu"; var HidS="Head";
  if (!onT) { VisS="Head"; HidS="Menu" }
  eval(docS + HidS+SideS + stlS + ".visibility='hidden'");
  eval(docS + VisS+SideS + stlS + ".visibility='visible'");
  if (lefT) objectL=VisS+"Left";
   else { objectR=VisS+"Right"; if (Nav4UpT)
           eval(docS + objectR + stlS + ".width=116") }
 }
function turnMenuL(T) { Turn_Menu(true,T) }  // for use in onmouseover="..." & onmouseout="...";
function turnMenuR(T) { Turn_Menu(false,T) }  // otherwise error message when using VBScript too

 function Switch_Move(SideS)
 {
  if (SideS=="Left")
   { if (moveLefT) moveLefT=false; else moveLefT=true };
  if (SideS=="Right")
   { if (moveRighT) moveRighT=false; else moveRighT=true };
 }

//===end source code for MenuF(S)===

//===start source code for Load_Images() and Show_Pic(S,T)===

function Load_ImgTopC()
 {
  AdTopC_On = new Image(156,78);
  AdTopC_On.src = PathS+"Graf/Ad/ArrTopC"+fileC+".gif";
  AdTopC_Off = new Image(156,78);
  AdTopC_Off.src = PathS+"Graf/Ad/NewTopC"+fileC+".gif";
 }
function Load_ImgBotL()
 {
  AdBotL_On = new Image(200,100);
  AdBotL_On.src = PathS+"Graf/Ad/ArrBotL"+fileC+".gif";
  AdBotL_Off = new Image(200,100);
  AdBotL_Off.src = PathS+"Graf/Ad/NewBotL"+fileC+".gif";
 }
function Load_ImgBotR()
 {
  AdBotR_On = new Image(200,100);
  AdBotR_On.src = PathS+"Graf/Ad/ArrBotR"+fileC+".gif";
  AdBotR_Off = new Image(200,100);
  AdBotR_Off.src = PathS+"Graf/Ad/NewBotR"+fileC+".gif";
 }
function Load_Images()
 {
 Load_ImgTopC(); Load_ImgBotL(); Load_ImgBotR();
 }

function Show_Pic(plaS,onT)
{
 var addrS="";
 if (plaS.length==5) plaS=plaS.substring(0,4); 
                     // new plaS value does not have a fileC at end anymore!
 if (plaS=="TopC") { OnS=AdTopC_On.src; OffS=AdTopC_Off.src }
 if (plaS=="BotL") { OnS=AdBotL_On.src; OffS=AdBotL_Off.src }
 if (plaS=="BotR") { OnS=AdBotR_On.src; OffS=AdBotR_Off.src }
                      // place of picture in image table depends on browser!
 for (n=0; n<document.images.length; n++)
 { addrS=document.images[n].src; lI=addrS.length;
   addrS=addrS.substring(lI-9);
   if (addrS==plaS+fileC+".gif")
    { if (onT) document.images[n].src=OnS;
       else document.images[n].src=OffS;
      break }
 }
}
function showPicTC(T) { Show_Pic('TopC',T) }  // for use in onmouseover="..." &
function showPicBL(T) { Show_Pic('BotL',T) }  // onmouseout="..."; otherwise error
function showPicBR(T) { Show_Pic('BotR',T) }  // message when using VBScript too

//===end source code for Load_Images() and Show_Pic(S,T)===

//===start source code for CheckSrc()===
function CheckSrc()
 {
  var LinkSrcS=document.referrer.toLowerCase();

  if (LinkSrcS.indexOf("retecool.com")!=-1)
   location.replace("http://www.trinp.org/Info/Repl/Retecool.HTM");
 }
//===end source code for CheckSrc()===

function determine_DimensiO()
{  // global total structure variables (also in BodyFnct.js)
 var searchS=document.location.search;
 var I=-1;
 var hypoReS="0000";
 printWidN=640;  // (IE 640-650; Ff 670-720, see below)
   // min 600, max 1003-252-1=750
   // for this width the document will be printed in the middle on an A4
   // With iframes Ff will add (invisible) stuff from the iframes column;
   // therefore page too much to the left (with extra width on the right)
   // Screen resolutions: 640x480, 800x600, 848x480, 1024x768 & larger;
   // real width 1024 will be read as 1024 by Ff,
   // as 1004 by IE6 and as 1020 by IE8
 hypoResolutioN=0;  // hypothetical resolution width (0, if not given)
 displayWidN=640;
   // display width = print width for real resolution of '1024' (1003-1007)
 windoWidthN=(2*displayWidN)+52  // ideally (display+16+display+20+16)
 readT=false;  // default value for quiet reading
 prinT=false;  // default value for printing
 iFrameT=true;  // one or more iframes by default
 puzzlT=false;  // by default not a puzzle (with always one iframe)

 if (Nav4UpT) { printWidN=670; displayWidN=670 }
   // centering only without iframes on screen
   // for XP system 720 pixels instead of 670

 if (searchS.indexOf('readT=true')>0)
  { readT=true; iFrameT=false }
 if (searchS.indexOf('prinT=true')>0)
  { prinT=true; iFrameT=false; hypoResolutioN=printWidN }

 if (searchS.indexOf('iFrameT=false')>0) iFrameT=false;
  else { if (searchS.indexOf('iFrameT=true')>0) iFrameT=true }
 I=searchS.indexOf('hypoReS=');
 if (I>0) 
   { hypoReS=searchS.substring(I+8,I+12);
     if ((hypoReS.length<3) || ((hypoReS.length==3) && (hypoReS<"600")))
      hypoReS="600";
        // needed because using ENTER key (instead of OK)
        // when entering new figures may give impossible values
     if (hypoReS.charAt(0)=="0") hypoReS=hypoReS.substring(1);
     hypoResolutioN=parseInt(hypoReS);
   }

 if (Nav4UpT) windoWidthN = eval("window.innerWidth")-20;
    // 17-20 for scrollbar at right; otherwise scrollbar at bottom
  else
   { windoWidthN = eval("document.body.clientWidth")-4;
     if (IE8UpT) windoWidthN=windoWidthN-13 }

 if (hypoResolutioN==0) hypoResolutioN=windoWidthN;
 if (hypoResolutioN<600) hypoResolutioN=600;
 if (readT && (hypoResolutioN>900)) hypoResolutioN=900;
 if (hypoResolutioN<printWidN) displayWidN=hypoResolutioN;
 if (hypoResolutioN>1050)
  {
   if (hypoResolutioN<1301)
     displayWidN=650+Math.ceil((hypoResolutioN-1050)/50)*50;
    else displayWidN=900;  // max display width: 100+50+600+150
  }
}

function InsLoad(S) // here variables not global for whole document!
{
 var verS=S;

 if (verS<"65346") hearT=false;
   // heart-of-the-matter option introduced with F7 format ("65346")
 if (verS<"59481") { readT=false; prinT=false }
   // reading and printing options introduced on 64.42.5 (under F6="59481")
 if (verS<"58111") { iFrameT=false; puzzlT=false }
   // inline frame(s) introduced on 60.40.7 (under F6="59481")
   // but backwards compatible with rainbow objects of F4="58111" 

 StatWind(true) // for Metric date and/or message in status window
 SnifF();

 if ((verS>"56156") && !prinT && (IE4UpT || Nav4UpT)) MenuF(S);
}

function InsUnLd(S) {  }

function OutsLoad(S) // here variables may be global for whole document
{
 var urlS=document.URL.toLowerCase();
 var x_inner=0;
 contacT=true;  // this old file does not use new HeadObjs.js
 iFrameT=false;  // may be made true below
 allFrameT=true  // default values for iframe(s)

 CheckSrc() // visitors from wrong sources are redirected
 SnifF(); Get_PathS(); Get_FileChar();

 if ((urlS.indexOf('http://www.trinp.org')>-1) || (PathS.indexOf('/TRINP/')>-1)) 
  {
   if (Nav4UpT) x_inner = eval("window.innerWidth");
    else  x_inner = eval("document.body.clientWidth");
   if (x_inner>900) iFrameT=true
  }
   // added on 61.31.5, because error message without new BodyObjs.js

 Load_Images() // for 3 interactive top and bottom images in threefold
}

function OutsUnLd(S) {  }

//Copyright 56-65 aSWW, M.Vincent van Mechelen, DNI Foundation
