/*
 *   Coding Domain scripting functions: Default implementations
 *
 *   Copyright (c) 2001 Diederik van der Boor - All Rights Reserved
 *   http://www.codingdomain.com
 *   webmaster@codingdomain.com
 */


// ----------------------------------------------------------------------
// Settings

var DEFAULT_NAME = "index.html";
var DEFAULT_TEXT = "Go to the page under this hyperlink";
var DEFAULT_JS   = "Execute JavaScript";
var DEFAULT_IMG  = "Preview Screenshot";
var ENTER_STATUS = "You have entered the coding domain";




// ----------------------------------------------------------------------
// Status text

var A  = 0;           // Don't change!
var SA = new Array(); // The status array


// This array will be used to determine what text should
// be displayed in the status bar. There are three different
// 'detail levels' wherein a text can be displayed
//
// a. Only the page                                    (like http://www.you.com/pages  OR /pages  OR  /pages/  OR  /pages/index.html)
// b. The path with one parameter of the query string  (like /cgi-bin/script.cgi?id=34)
// c. The path with all parameters of the query string (like /cgi-bin/script.cgi?id=34&language=en)
// d. Evenrything, including the # for internal links  (like /pages/toc.html#top  OR  /cgi-bin/forum.cgi?topic=345#post33)
//
//
// The LOCAL site address, like http://www.you.com/
// will not be used, can should be left out.


SA[A++]=  'cgi-perl'                                    ;SA[A++]= 'CGI Programming with Perl'
SA[A++]=  'cgi-perl/articles'                           ;SA[A++]= 'Articles about CGI Programming in Perl'
SA[A++]=  'cgi-perl/articles/cgiinfo.html'              ;SA[A++]= 'What does a CGI Script?'
SA[A++]=  'cgi-perl/articles/install.html'              ;SA[A++]= 'Help Installing a Perl CGI Script'
SA[A++]=  'cgi-perl/articles/install.html#top'          ;SA[A++]= 'Back to the top'
SA[A++]=  'cgi-perl/articles/install.html#upload'       ;SA[A++]= 'Help Uploading a Perl CGI Script'
SA[A++]=  'cgi-perl/articles/install.html#chmod'        ;SA[A++]= 'Help About File Permissions'
SA[A++]=  'cgi-perl/articles/install.html#chmodset'     ;SA[A++]= 'Help Changing the Permissions of a Perl CGI Script'
SA[A++]=  'cgi-perl/articles/install.html#chmodavail'   ;SA[A++]= 'Find out Available Permissions'
SA[A++]=  'cgi-perl/articles/install.html#chmodcommon'  ;SA[A++]= 'List of Commonly Used File Permissions'
SA[A++]=  'cgi-perl/articles/install.html#errors'       ;SA[A++]= 'Actions to take when you receive an errorpage'
SA[A++]=  'cgi-perl/articles/install.html#other'        ;SA[A++]= 'Other Questions Related to Installing Perl Scripts'
SA[A++]=  'cgi-perl/downloads'                          ;SA[A++]= 'CGI-Perl Downloads'
SA[A++]=  'cgi-perl/downloads/x-mailform'               ;SA[A++]= 'X-Mailfrom form mail script'
SA[A++]=  'cgi-perl/downloads/x-mailform/listing.html'  ;SA[A++]= 'Online Listing'
SA[A++]=  'cgi-perl/downloads/x-forum'                            ;SA[A++]= 'X-Forum Discussion Forum Script'
SA[A++]=  'cgi-perl/downloads/x-forum/newpass.html'               ;SA[A++]= 'Password Generator'
SA[A++]=  'cgi-perl/downloads/x-forum/rate.html'                  ;SA[A++]= 'Rating'
SA[A++]=  'cgi-perl/downloads/x-forum/install'                    ;SA[A++]= 'X-Forum Installing Tutorial'
SA[A++]=  'cgi-perl/downloads/x-forum/install/filestruct.html'    ;SA[A++]= 'X-Forum Installing Tutorial: File Structure'
SA[A++]=  'cgi-perl/downloads/x-forum/install/activate.html'      ;SA[A++]= 'X-Forum Installing Tutorial: Activating the Forum'
SA[A++]=  'perl'                                        ;SA[A++]= 'Programming in Perl'
SA[A++]=  'perl/explainregexp.html'                     ;SA[A++]= 'Regular Expression Explainer'
SA[A++]=  'perl/articles'                               ;SA[A++]= 'Perl Articles'
SA[A++]=  'perl/articles/hugeoverview.html'             ;SA[A++]= 'Huge Overview of Perl programming'
SA[A++]=  'perl/articles/perlstyle.html'                ;SA[A++]= 'Perl Programming Style Issues'
SA[A++]=  'perl/articles/whyoop.html'                   ;SA[A++]= 'Why using OOP?'
SA[A++]=  'perl/tutorial'                               ;SA[A++]= 'Tutorial of Perl'
SA[A++]=  'perl/tutorial/dirs.html'                     ;SA[A++]= 'Browsing through directories in Perl'
SA[A++]=  'perl/tutotial/files.html'                    ;SA[A++]= 'Working with files in Perl'
SA[A++]=  'perl/tutorial/oop'                           ;SA[A++]= 'OOP: Employee Sample'
SA[A++]=  'perl/tutorial/oop/apl.html'                  ;SA[A++]= 'OOP Employee: Apl.pl'
SA[A++]=  'perl/tutorial/oop/employee.html'             ;SA[A++]= 'OOP Employee: Employee.pm'
SA[A++]=  'perl/downloads'                              ;SA[A++]= 'Perl Downloads'
SA[A++]=  'perl/downloads/x-modules'                    ;SA[A++]= 'Coding Domain Modules'
SA[A++]=  'perl/downloads/x-modules/cgi_errortrap.html' ;SA[A++]= 'CGI::ErrorTrap'
SA[A++]=  'perl/downloads/x-modules/cgi_location.html'  ;SA[A++]= 'CGI::Location'
SA[A++]=  'perl/downloads/x-modules/cgi_template.html'  ;SA[A++]= 'CGI::Template'
SA[A++]=  'perl/downloads/x-modules/file_plainio.html'  ;SA[A++]= 'File::PlainIO'
SA[A++]=  'perl/downloads/x-modules/html_escapeascii.html'  ;SA[A++]= 'HTML::EscapeASCII'
SA[A++]=  'perl/downloads/x-modules/inet_mailer.html'   ;SA[A++]= 'INet::Mailer'
SA[A++]=  'perl/downloads/x-modules/test_input.html'    ;SA[A++]= 'Test::Input'
SA[A++]=  'perl/downloads/x-modules/test_ipaddress.html';SA[A++]= 'Test::IPAddress'
SA[A++]=  'perl/downloads/x-modules/time_text.html'     ;SA[A++]= 'Time::Text'
SA[A++]=  'perl/downloads/x-modules/time_zones.html'    ;SA[A++]= 'Time::Zones'
SA[A++]=  'perl/samples'                                ;SA[A++]= 'Sample Perl Programs'
SA[A++]=  'perl/samples/classdiagram.html'              ;SA[A++]= 'Generate a classdiagram of Java files using RegExps'
SA[A++]=  'perl/samples/logremove.html'                 ;SA[A++]= 'Removing files from a log file'
SA[A++]=  'vb'                                          ;SA[A++]= 'Visual Basic Programming'
SA[A++]=  'vb/downloads'                                ;SA[A++]= 'Visual Basic Downloads'
SA[A++]=  'vb/downloads/carrier'                        ;SA[A++]= 'VB Carrier Game'
SA[A++]=  'vb/downloads/win32api'                       ;SA[A++]= 'Windows 32 API Downloads'
SA[A++]=  'vb/downloads/win32api/sampleapps.html'       ;SA[A++]= 'Download Sample Applications using API\'s'
SA[A++]=  'vb/downloads/win32api/x-dlls'                ;SA[A++]= 'The Extra DLL\'s'
SA[A++]=  'vb/downloads/win32api/x-dlls/sampleapps.html';SA[A++]= 'Download Sample Applications using the Extra DLL\'s'
SA[A++]=  'vb/downloads/win32api/x-dlls/sampleapps.html#vbocxsample-coolbar'  ;SA[A++]= 'Download Coolbar Control Files and Sample Project'
SA[A++]=  'vb/win32api'                                 ;SA[A++]= 'Programming with the 32 bits API'
SA[A++]=  'vb/win32api/datatypes.html'                  ;SA[A++]= 'Data type conversions from VB to C'
SA[A++]=  'vb/win32api/samples'                         ;SA[A++]= 'Win32API Samples'
SA[A++]=  'vb/win32api/paramnotes.html'                 ;SA[A++]= 'Notes to passing parameters to API\'s'
SA[A++]=  'vb/win32api/samples/simple.html'             ;SA[A++]= 'A Simple API Sample Call'
SA[A++]=  'vb/win32api/samples/anytype.html'            ;SA[A++]= 'Passing any data type to an API function'
SA[A++]=  'vb/win32api/samples/buffers.html'            ;SA[A++]= 'Working with buffers for API functions'
SA[A++]=  'vb/win32api/samples/callback.html'           ;SA[A++]= 'Passing a function address to an API function'
SA[A++]=  'vb/win32api/samples/structure.html'          ;SA[A++]= 'Working with structures for API functions'
SA[A++]=  'cgi-bin/x-download.cgi'                      ;SA[A++]= 'Download Page'
SA[A++]=  'cgi-bin/x-download.cgi?id=xforum'            ;SA[A++]= 'Get the X-Forum Discussion Forum Script'
SA[A++]=  'cgi-bin/x-forum.cgi'                         ;SA[A++]= 'Discussion Forum'
SA[A++]=  'cgi-bin/x-forum.cgi?show=about'              ;SA[A++]= 'Discussion Forum: About'
SA[A++]=  'cgi-bin/x-forum.cgi?show=addmember'          ;SA[A++]= 'Discussion Forum: Sign up'
SA[A++]=  'cgi-bin/x-forum.cgi?show=addpost'            ;SA[A++]= 'Discussion Forum: Post reply'
SA[A++]=  'cgi-bin/x-forum.cgi?show=compose'            ;SA[A++]= 'Discussion Forum: Compose private message'
SA[A++]=  'cgi-bin/x-forum.cgi?show=delpost'            ;SA[A++]= 'Discussion Forum: Delete message'
SA[A++]=  'cgi-bin/x-forum.cgi?show=delmessage'         ;SA[A++]= 'Discussion Forum: Delete private message'
SA[A++]=  'cgi-bin/x-forum.cgi?show=deltopic'           ;SA[A++]= 'Discussion Forum: Delete topic'
SA[A++]=  'cgi-bin/x-forum.cgi?show=editmember'         ;SA[A++]= 'Discussion Forum: Edit profile'
SA[A++]=  'cgi-bin/x-forum.cgi?show=editpost'           ;SA[A++]= 'Discussion Forum: Edit message'
SA[A++]=  'cgi-bin/x-forum.cgi?show=iconlist'           ;SA[A++]= 'Discussion Forum: Avator list'
SA[A++]=  'cgi-bin/x-forum.cgi?show=help'               ;SA[A++]= 'Discussion Forum: Help'
SA[A++]=  'cgi-bin/x-forum.cgi?show=locktopic'          ;SA[A++]= 'Discussion Forum: Lock topic'
SA[A++]=  'cgi-bin/x-forum.cgi?show=login'              ;SA[A++]= 'Discussion Forum: Login'
SA[A++]=  'cgi-bin/x-forum.cgi?show=logintest'          ;SA[A++]= 'Logging in'
SA[A++]=  'cgi-bin/x-forum.cgi?show=logout'             ;SA[A++]= 'Discussion Forum: Logout'
SA[A++]=  'cgi-bin/x-forum.cgi?show=member'             ;SA[A++]= 'Discussion Forum: Member profile'
SA[A++]=  'cgi-bin/x-forum.cgi?show=member&member=admin';SA[A++]= 'Discussion Forum: Profile information of the administrator'
SA[A++]=  'cgi-bin/x-forum.cgi?show=memberlist'         ;SA[A++]= 'Discussion Forum: Memberlist'
SA[A++]=  'cgi-bin/x-forum.cgi?show=messages'           ;SA[A++]= 'Discussion Forum: Private messages'
SA[A++]=  'cgi-bin/x-forum.cgi?show=movetopic'          ;SA[A++]= 'Discussion Forum: Move topic'
SA[A++]=  'cgi-bin/x-forum.cgi?show=sticktopic'         ;SA[A++]= 'Discussion Forum: Sticky topic'
SA[A++]=  'cgi-bin/x-forum.cgi?show=subject'            ;SA[A++]= 'Discussion Forum: Topic list'
SA[A++]=  'cgi-bin/x-forum.cgi?show=topic'              ;SA[A++]= 'Discussion Forum: Topic messages'
SA[A++]=  'ui-pages/intro.shtml'                        ;SA[A++]= 'Home Introduction Page'
SA[A++]=  'ui-pages/email.html'                         ;SA[A++]= 'Contact us'
SA[A++]=  'ui-pages/download.html'                      ;SA[A++]= 'Downloads'
SA[A++]=  'ui-pages/bugreport.html'                     ;SA[A++]= 'Bugreport'
SA[A++]=  'ui-pages/bugreport2.html'                    ;SA[A++]= 'Bugreport'
SA[A++]=  'ui-pages/xf-intro.html'                      ;SA[A++]= 'Introduction to the Discussion Forum'
SA[A++]=  'ui-pages/xf-intro.html#top'                  ;SA[A++]= 'Back to the top'
SA[A++]=  'ui-pages/xf-intro.html#useof'                ;SA[A++]= 'The use of a forum'
SA[A++]=  'ui-pages/xf-intro.html#moderate'             ;SA[A++]= 'Moderating the forum'
SA[A++]=  'ui-pages/xf-intro.html#rules'                ;SA[A++]= 'Rules that apply to the forum'
SA[A++]=  'ui-pages/xf-intro.html#starttips'            ;SA[A++]= 'Tips for beginners'
SA[A++]=  'ui-pages/xf-intro.html#forumtips'            ;SA[A++]= 'Cool forum tips'
SA[A++]=  'javascript:history.go(-1)'                   ;SA[A++]= 'Go back to the previous page'
SA[A++]=  'javascript:history.back()'                   ;SA[A++]= 'Go back to the previous page'




// ----------------------------------------------------------------------

var TOP_FILE = GetSiteLocation();


// Get a text into the status bar
var StatusText = GetStatusFileName(self.location.href, false);
if(StatusText && StatusText != DEFAULT_TEXT)
{
  window.defaultStatus = ENTER_STATUS + "  [" + StatusText + "]";
}



// ----------------------------------------------------------------------

var ST_TIMEOUT;
function ST(Link) // StatusText, sort in for easy implement in onMouseOver= code
{
  clearTimeout(ST_TIMEOUT);
  ST_TIMEOUT = null;
  top.status = GetStatusFileName(Link.href, true, true);
  return true;
}

function CS()   // ClearStatus, sort in for easy implement in onMouseOut= code
{
  clearTimeout(ST_TIMEOUT);
  ST_TIMEOUT = setTimeout("ClearStatus2()", 3000);
  return true;
}

function ClearStatus2()
{
  clearTimeout(ST_TIMEOUT);
  ST_TIMEOUT = null;
  top.status = '';
}


// ----------------------------------------------------------------------
// Website name

function GetDirPath(URL)
{
  return unescape(URL.substring(0, URL.lastIndexOf("/") + 1));
}

function GetSiteLocation()
{
  var PROT = (window.location.protocol || "http:");
  var SITE = PROT + "\/\/" + (window.location.host || '') + "/";
  if (SITE == PROT + "\/\/\/") { SITE = GetDirPath(window.location.href); }
  return SITE
}



// ----------------------------------------------------------------------
// Path Conversions

function StripFileName(URL)
{
  return unescape(URL.substring(0, URL.lastIndexOf("/")));
}


function ConvertFileName(URL, UseHash)
{
  // Remove the top file name
  if(TOP_FILE == URL.substring(0, TOP_FILE.length))
  {
    URL = URL.substring(TOP_FILE.length, URL.length);
  }

  // Remove the default name (index.html) at the end
  if(URL.substring(URL.length - DEFAULT_NAME.length, DEFAULT_NAME.length) == DEFAULT_NAME)
  {
    URL = URL.substring(0, URL.length - DEFAULT_NAME.length);
  }

  // Remove the hash?
  if(! UseHash)
  {
    var Pos = URL.indexOf('#');
    if(Pos != -1) { URL = URL.substring(0, Pos); }
  }

  // Remove the / at the end
  if(URL.substring(URL.length-1, URL.length) == '/')
  {
    URL = URL.substring(0, URL.length - 1);
  }

  return unescape(URL);
}




// ----------------------------------------------------------------------
// Display Text for the status bar


function GetStatusFileName(URL, After, UseHash)
{
  return GetStatusFileText(ConvertFileName(URL, UseHash), After);
}


function GetStatusFileText(StatusPath, After)
{
  var IsJavaScript = false;
  var IsImage      = false;

  if(After != null)
  {
    if('javascript:' == StatusPath.substring(0, 11))
    {
      After = false;
      IsJavaScript = true;
    }
    else if('mailto:' == StatusPath.substring(0, 7))
    {
      var Pos = StatusPath.indexOf('?');
      if(Pos != -1) { StatusPath = StatusPath.substring(7, Pos); }
      else          { StatusPath = StatusPath.substring(7, StatusPath.length); }
      return "E-mail directly to " + unescape(StatusPath);
    }
    else if(('.jpg' == StatusPath.substr(StatusPath.length - 4))
         || ('.gif' == StatusPath.substr(StatusPath.length - 4))
         || ('.pgn' == StatusPath.substr(StatusPath.length - 4))
         || ('.ico' == StatusPath.substr(StatusPath.length - 4))
         || ('.bmp' == StatusPath.substr(StatusPath.length - 4)))
    {
      IsImage = true;
    }
  }

  // Remove the hash (#)
  var StatusNoHash = StatusPath;
  var HashPos = StatusPath.indexOf('#');
  if(HashPos > -1)
  {
    StatusNoHash = StatusPath.substr(0, HashPos);
  }

  // Remove the query string (?name=value)
  var StatusNoQuery = StatusNoHash;
  var StatusParam1  = StatusNoHash;
  var QueryPos = StatusNoQuery.indexOf('?');
  if(QueryPos > -1)
  {
    var Param2Pos = StatusNoHash.indexOf('&', QueryPos);
    if(Param2Pos > -1)
    {
      StatusParam1 = StatusNoHash.substr(0, Param2Pos);
    }
    StatusNoQuery = StatusNoHash.substr(0, QueryPos);
  }



  // Find a text
  var ArrayIndex = null;
  for(var I = 0; I < SA.length; I+=2)
  {
    if     (SA[I] == StatusNoQuery) { ArrayIndex = I+1; }         // There might be a more detailled message
    else if(SA[I] == StatusParam1)  { ArrayIndex = I+1; }         // There might be a more detailled message
    else if(SA[I] == StatusNoHash)  { ArrayIndex = I+1; }         // There might be a more detailled message
    if     (SA[I] == StatusPath)    { ArrayIndex = I+1; break; }  // Message (maybe with a #)
  }

  if(ArrayIndex != null) { return SA[ArrayIndex] + (After ? "  [" + unescape(StatusPath) + "]" : '') }
  if(IsJavaScript)       { return DEFAULT_JS     + (After ? "  [" + unescape(StatusPath) + "]" : '') }
  if(IsImage)            { return DEFAULT_IMG    + (After ? "  [" + unescape(StatusPath) + "]" : '') }
  if(After      != null) { return DEFAULT_TEXT   + (After ? "  [" + unescape(StatusPath) + "]" : '') }
  return null;
}


// ----------------------------------------------------------------------






//      Now some extra functions that are website-dependent
//      i.e. I won't use them in this form at a different website







// ----------------------------------------------------------------------
// Tree level function (like the &print_treelevel_HTML() routine in x-forum)
// The tree level is based on the path of the current file.
// like /programming/visualbasic/tips/index.html

var IMAGE_URLPATH = '/x-images';

function TreeLevelHTML()
{
  var THIS_PATH = ConvertFileName(self.location.href, 0);
  if(THIS_PATH == 'gui-pages') { return; }

  document.writeln('    <B><NOBR>');
  document.writeln('      <IMG src="' + IMAGE_URLPATH + '/folders/folder_closed.gif" width="16" height="16"> <A href="/ui-pages/intro.shtml" onMouseOver="return ST(this)" onMouseOut="return CS()">Coding Domain: Home</A><BR>');
  if(THIS_PATH)
  {
    var URL = '';
    var Path = THIS_PATH.split('/');
    var N = 0;
    for(var I = 0; I < Path.length; I++)
    {
      if(Path[I] != '')
      {
        URL += Path[I];
        if(Path[I] != 'ui-pages' && Path[I] != 'cgi-bin' && Path[I] != DEFAULT_NAME)
        {
          Text = GetStatusFileText(URL, 0, 0);
          if(! THIS_PATH) { Type = 'closed' }
          if(I == Path.length-1) { Type = 'open'; }
          else                   { Type = 'closed'; }
          if(N > 0) { document.write('<IMG src="' + IMAGE_URLPATH + '/treelevel/nonode.gif" width="' + (16 * N) + '" height="16">'); }
          document.writeln('<IMG src="' + IMAGE_URLPATH + '/treelevel/lastnode.gif" width="16" height="16"> <IMG src="' + IMAGE_URLPATH + '/folders/folder_' + Type + '.gif" width="16" height="16"> <A href="/' + URL + '" onMouseOver="return ST(this)" onMouseOut="return CS()">' + Text + '</A><BR>');
          N++;
        }
        URL += '/'; // For next loop
      }
    }
  }
  document.writeln('    </NOBR></B><BR><BR>');
}



// ----------------------------------------------------------------------
// Last Modified HTML

function LastModifiedHTML()
{
  // document.lastModified is the date/time the file was re-uploaded off course.
  document.writeln('    <BR><BR><P><FONT size="1" color="#999999">Last Modifications Applied at ' + document.lastModified + '</FONT></P>');
}


