// JavaScript Document
// Call from <head>

// Test to see if we are in the root, or in a subdirectory, remember for later so we can find the BG image.
// Fiddle - all my subdirectories end with a year date, eg seychelles1990, so look for a date in the last 4 chars
var slfilename=document.URL;
// Replace any backslashes with forwardslashes (file:// not http://:):
rExp = /\\/g;
slfilename=slfilename.replace(rExp,"/");

//Are we online?
var bonline=(slfilename.substring(0,4)=="http");

ii=(slfilename.lastIndexOf("/",slfilename.length));
var slpathfrac=slfilename.substring((ii-4),ii);		// extract last 4 chars of whatever is in front of the filename

// If a year here, we are in a subdir
var slresult="";
if ((slpathfrac>"1949") && (slpathfrac<"2050"))	slresult="../";		// ...while I'm alive
//alert ("'" + slresult + "'")


//Detects if the page is trapped inside someone else's frames, and automatically breaks out:
if (window!= top) top.location.href=location.href;

/*
... re-uses the previous slfilename contents.
*/
ii=(slfilename.lastIndexOf(".",slfilename.length));
slfilename=slfilename.substring(0,ii);

ii=(slfilename.lastIndexOf("/",slfilename.length));
slfilename=slfilename.substring(ii+1,slfilename.length);

//alert(slfilename);
// If online set domain name:
var slprefix=slresult;
if (bonline) slprefix="http://www.dunbankin.com/";

//Checks to see if not on dunbankin.com or .co.uk, and diverts to proper domain.
if ((bonline) && (location.href.indexOf("www.dunbankin.co") == -1) && (slfilename!= "query") && (slfilename!="mailinglistform4") && (slfilename!="maillistack")) //whatuseek search engine page, mailing list page on secure server.
   {
      var splitString = document.URL.split("/")
      var path=slprefix //.substring(0,(slprefix.length-1));  //strip off the trailing "/"
      for (ii=3; ii<(splitString.length); ii++)              // reassemble URL
           {
//             if ((splitString[ii] != "dunbankin") && (splitString[ii] != "")) 	// because of homepages.plus.net/dunbankin/index.htm etc
             if ((splitString[ii] != "jpdljd") && (splitString[ii] != "")) // because of homepages.plus.net/jpdljd/index.htm etc

               {
               	 path+= splitString[ii];
               	 if (splitString[ii].indexOf(".") == -1)
               	   {path+= "/";}
               }
           };
//         {path+="/" + splitString[ii];}
//     alert("We've moved!  Our new address is '" + slprefix + "'.\n\nClick 'OK' to transfer to:\n" + path + "\n...and don't forget to bookmark the new page!");
     location.href=path;
   };

//Around Xmas overwrite the regular styleheet with an Xmas BODY style instead:
var datevar= new Date();
var date = datevar.getDate();
var month = datevar.getMonth() + 1;

//alert(slresult);

if ((month==12 && date>10)||(month==1 && date<7))
    {
    document.write ('<style type="text/css"> body {background: #ffffff url(' + slresult + 'xmas_images/cabin4.jpg) no-repeat center center fixed;} </style>');
    }
