// This file contains a set of routines used in webs created by D+DD
// (c) 1998-01-12 Docu + Design Daube, Zürich
// updates
// 2001-12-28 added debug()
// 2002-08-17 added hidemail ()

/* navigation -----------------------------------------------------------------
	Purpose: Evaluate and jump to the previous, next and first file
					 of a sequence named abc00, abc01 ... abc77, abc78 (up to abc99).
					 The last file in the sequence must have a <title> ending
					 with a period "."
	Problem: See HTTP://www.fokolar-bewegung.ch/_scripts/ddd_specials.txt
	(C) 1999.. Docu + Design Daube, Zurich
	Credit:  Original idea by ScriptCity
*/ 
  var URL = unescape(location.href);
  var xstart = 0;
  var xend = URL.length;
  var digitOnePlace = URL.lastIndexOf('.') - 2;
  var digitTwoPlace = URL.lastIndexOf('.') - 1;
  var digitOne = URL.charAt(digitOnePlace);
  var digitTwo = URL.charAt(digitTwoPlace);
  var filePrefix = URL.substring(xstart,digitOnePlace);
  var suffixStart = URL.lastIndexOf('.');
  var fileSuffix = URL.substring(suffixStart,xend);
  var previousFileName = null;
  var nextFileName = null;
  var firstFileName = null;
  var dig1 = null; var dig2 = null;         // Opera 3.0, workaround
  dig1 = parseInt(digitOne); dig2 = parseInt(digitTwo);
  var islast= false;
  var ll= document.title.length;            // opera: value 1 to large
  var lix = document.title.lastIndexOf(".");// opera: value OK

  function previousFile() {
  // alert (document.title+", d1, d2= "+ dig1+","+ dig2);
    if (dig2 == 0 && dig1 == 0) { location.href = URL;
    } else {
      if (dig2 == 0) {
        dig2 = 9; dig1--;
      } else {
        dig2--;
      }
      previousFileName = filePrefix + dig1 + dig2 + fileSuffix;
      location.href = previousFileName;
    }
  }

  function nextFile() {
    if ((ll - 2)<= lix) islast = true;
    // alert (document.title+", ll,lix,islast= "+ dig1+","+ dig2+","+ ll+", "+lix+", "+ islast);
    if (islast) nextFileName = filePrefix + "00" + fileSuffix;
    else {
      if (dig2 == 9) {
        dig2 = 0; dig1++;
      } else {
        dig2++;
      }
      nextFileName = filePrefix + dig1 + dig2 + fileSuffix;
    }
    location.href = nextFileName;
  }

  function firstFile() {
    firstFileName = filePrefix + "00" + fileSuffix;
    location.href = firstFileName;
  }
  
/* hidemail -------------------------------------------------------------------
	Purpose: hide e-mail address from spam-robots
	Parameter 'what' may be left out when calling - will be "undefined" in the mail
*/
	function hidemail(name, address, what) {
		where = name + "@" + address;
		document.location = "mailto:" + where + "?subject=" + what;
	}

/* isoupdate () ----------------------------------------------------------------
	Purpose: generate lastModified date in ISO format
	Take special care of the strange behaviour of browsers:
		 year   1998, 1999, 2000, 2001
	Opera 3.x:  98,   99,  100,  101
	Opera 4.x:  98,   99,  100,  101
	NS/IE 4.x:  98,   99,    0,    1
	IE 5.x;   1998, 1999, 2000, 2001
*/  
  function isoupdate () {
    var indate=new Date(document.lastModified);
    var mm= 101+ indate.getMonth(); var mmm = mm.toString(10).substring(1);
    var dd= 100+ indate.getDate();  var ddd = dd.toString(10).substring(1);
    var yy= indate.getYear(); var year=yy.toString();
// debug ("Gotten len, year, mmm, ddd: \n"+indate.length +"  "+year+"-"+ mmm+"-"+ddd);
    if (year.length < 4) {
      if (year.length > 2)
        { year = yy + 1900; year=year.toString();}
      else {
        if (yy > 70) {
					year = yy + 1900; 
					year=year.toString();
				}
        else {
					year = yy + 2000; 
					year=year.toString();
			  }
      }
    }
    thedate=year+"-"+ mmm+"-"+ddd;
    return (thedate);
  }

/* debug (msg) ----------------------------------------------------------------
  Purpose: open a window the first time we are called,
           or after an existing console window has been closed.
  Usage:
           var _console = null;
           ...
           debug ("whatever you want to display");
*/
function debug(msg) {
  if ((_console == null) || (_console.closed)) {
    _console = window.open("","console","width=600,height=200,resizable");
    _console.document.open("text/plain");
  }
    _console.document.writeln(msg);
}

