var basedir="/"
var searchdir="http://www.thepolarcircle.com/search"
var cgiext=".pl"
// constants polar circle
var thumbdir1 = "http://www.thepolarcircle.com/search/"
var imagedir = "/images/"
var backgrd = "/images/flakes1.gif"
var cgidir = "http://www.thepolarcircle.com/cgi-bin/search/"
var jsdir="/js/"

//get browser
   var browser = navigator.appName;
   var Nav = (browser == "Netscape");
   var IE = (browser == "Microsoft Internet Explorer");

//------------------------------------------------------------
function lasttime() {
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
   var browser = navigator.appName;
   var Nav = (browser == "Netscape");
   var IE = (browser == "Microsoft Internet Explorer");
   var plat= navigator.platform;
   var mac= (plat=="MacPPC")
   var vers = navigator.appVersion
   var vers2 = parseInt(vers)
   var box = getCookie("box")
   var boxes=getCookie("boxes")
//alert(mac)
//mac=IE
//vers2=4
//var s=""
// Is user here for the first time?
   if (!box || !boxes){
      boxes="main";
      setCookie("boxes",boxes,now,"/");
      setCookie("box",boxes,now,"/");
      setCookie("main","",now,"/")
      deleteCookie("main","/")
      setCookie("discards","",now,"/")
      setCookie("boxmanhan","no",now,"/")
      setCookie("mainhan","no",now,"/")
      setCookie("savecap","yes",now,"/")
      setCookie("preview","",now,"/")
      deleteCookie("preview","/")
   } else {
      var bo = boxes.split("#")
      var l =bo.length
// Are there any discards
      var dis =getCookie("discards")
      if (!dis){
      } else {
            bo[l]="discards"
            l = l+1
      }
      if (l==1){
         s = "<img src=\"images/imagesearch/lasttime1.gif\" width=\"285\" height=\"45\">\n";
      } else {
         s = "<img src=\"images/imagesearch/lasttime2.gif\" width=\"285\" height=\"45\">\n";
      }
      s += "<form method=\"get\" name=\"light\" target=\"newwinbcp\"\n";
      s += "action=\""+cgidir+"lightbx2"+cgiext+"\">\n";
      s += "<input type=\"hidden\" name=\"thisbox\" value=\"boxmanager\">\n";
      s += "<center><table border=\"1\" cellpadding=\"5\"><tr align=\"center\">\n";
      var col = 0;
      for(var i=0; i < bo.length; i++) {
         col += 1;
         if (col == 3 ) {
// start new row
            col = 1;
            s += "</tr><tr align=\"center\">\n"
         }
// Add Lightbox Cell
         buc = bo[i].substr(0,1)
         buc = buc.toUpperCase()
         buc += bo[i].substr(1,bo[i].length)
//alert(buc)
         s += "<td><strong>"+buc+"</strong><br>"
// Are there any images in the lightbox
         var sl = getCookie(bo[i])
         document.writeln(s)
         s = ""
         if (!sl) {
            s += "No Pictures<br><br>";
            s += "<img src=\""+imagedir+"nopics.jpg\" ><br><br>\n"
         } else {
            var p= sl.split("#");
            var ns = p.length
            s += ns +" pictures<br>"
// get first picture and display it
            var d = 0
            for (var ins=0;ins<ns;ins++){
               var q=p[ins].split("@")
               if (q[1]!="x"){
                  d = ins
                  break
               }
            }
// p[i] contains picture name and caption
            var q=p[d].split("@")
// check for missing thumbnail
            if (q[1]=="x"){
// missing thumb
               s += "<img src=\""+imagedir+"nothumb.jpg\"><br>"
               s += q[2]+"<br>"+q[0]+"<br>\n"
               document.writeln(s)
               s = ""
            } else {
// get correct thumbnail for member
               thumbdir=thumbdir1 + "bc/thumbs/";
               if (q[4] == "BS"){
                  thumbdir=thumbdir1 + "bas/thumbs/";
               } else if (q[4] == "SP"){
                  thumbdir=thumbdir1 + "spri/thumbs/";
               } else if (q[4] == "JH"){
                  thumbdir=thumbdir1 + "jh/thumbs/";
               } else if (q[4] == "ME"){
                  thumbdir=thumbdir1 + "me/thumbs/";
               } else if (q[4] == "SW"){
                  thumbdir=thumbdir1 + "sw/thumbs/";
               }
               s += "<img src=\""+thumbdir
               s += q[0]
               s += "s.jpg\" width=\""+q[1]+"\" height\""+q[2] 
               s += "\" alt=\""+q[3]+"\"><br>"+q[0]+"<br>\n"
               document.writeln(s)
               s = ""
             }
          }
          s += "<input type=\"button\" value=\"Open Lightbox\" name=\""+bo[i]+"\" \n";
          s += "onClick=\"makewin2('"+bo[i]+"')\">\n";
          s += "</td>\n"
      }
      s += "</table></form>\n"
// End of Lightbox table
      document.writeln(s)
   }
//  Warning Section
   if (mac) {
      if (vers2 < 5 && IE) {
         s = "<table width=\"90%\" border=\"2\" cellpadding=\"10\" align=\"center\">\n"
         s += "<tr bgcolor=\"\#FF3333\">\n"
         s += "<td class=\"textsmall\">Whilst developing this search program we have become very aware of the\n"
         s += "differences between different web browsers running on different typres of computers.\n"
         s += "We have tried to address most of the problems we have come across but we\n"
         s += "have found Internet Explorer 4.5 running on a Macintosh very difficult to\n"
         s += "support. Code that works well under Netscape 4 and Internet Explorer 5.5\n"
         s += "fails to work using IE 4.5. If you are using IE version 4.5 or earlier you may have\n"
         s += "problems with some of the picture sorting facilities. The search engine will\n"
         s += "work correctly but selecting and sorting pictures may not. We suggest you\n"
         s += "upgrade to IE 5.5 to avoid these problems.</td>\n"
         s += "</tr>\n"
         s += "</table>\n"
         document.writeln(s)
      }
   }
}
//-----------------------------------------------------------------------------
function resetboxes(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
   var boxes=getCookie("boxes")
   if (!boxes) {
   } else {
// find all light boxes and zero them
      var bo = boxes.split("#")
      for(var i=0; i < bo.length; i++) {
         setCookie(bo[i],"",now,"/")
         deleteCookie(bo[i],"/")
// is box open
         var h = getCookie(bo[i]+"han")
         if (!h || h != "yes"){
         } else {
            kill_window(bo[i])
         }
         var c = document.cookie
      }
   }
   boxes="main";
   setCookie("boxes",boxes,now,"/");
   setCookie("box",boxes,now,"/");
   setCookie("main","",now,"/")
   deleteCookie("main","/")
   setCookie("discards","",now,"/")
   deleteCookie("discards","/")
   h = getCookie("discardshan")
   if (!h || h != "yes"){
   } else {
      kill_window("discards")
   }
   setCookie("discardshan","no",now,"/")
   h = getCookie("boxmanhan")
   if (!h || h != "yes"){
   } else {
      kill_window("boxmanager")
   }
   setCookie("boxmanhan","no",now,"/")
   setCookie("mainhan","no",now,"/")
   setCookie("savecap","yes",now,"/")
   setCookie("preview","",now,"/")
   deleteCookie("preview","/")
   var plat= navigator.platform;
//   alert("platform "+plat)
   var mac= (plat=="MacPPC")
//   alert(mac)
   if (mac || Nav) {
      window.location="03_image_search_m.htm"
   } else {
      window.location="03_image_search_s.htm"
   }
}
//-------------------------------------------------------------------
function carryon(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// Leave box content alone
   var boxes=getCookie("boxes")
// leave savecap alone
//setCookie("savecap","yes",now,"/")
   setCookie("preview","",now,"/")
   deleteCookie("preview","/")
   var plat= navigator.platform;
//   alert("platform "+plat)
   var mac= (plat=="MacPPC")
//   alert(mac)
   if (mac || Nav) {
      window.location="03_image_search_m.htm"
   } else {
      window.location="03_image_search_s.htm"
   }
}
//-------------------------------------------------------------------
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) { 
   var curCookie = name + "=" + escape(value) + 
      ((expires) ? "; expires=" + expires.toGMTString() : "") + 
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : ""); 
   document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) { 
   var dc = document.cookie; 
   var prefix = name + "="; 
   var begin = dc.indexOf("; " + prefix); 
   if (begin == -1) { 
      begin = dc.indexOf(prefix); 
      if (begin != 0) return null; 
   } else 
      begin += 2; 
   var end = document.cookie.indexOf(";", begin); 
   if (end == -1) 
      end = dc.length; 
   return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) { 
   if (getCookie(name)) { 
      document.cookie = name + "=" + 
      ((path) ? "; path=" + path : "") + 
      ((domain) ? "; domain=" + domain : "") + 
      "; expires=Thu, 01-Jan-70 00:00:01 GMT"; 
   }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) { 
   var base = new Date(0); 
   var skew = base.getTime(); 
   if (skew > 0) 
      date.setTime(date.getTime() - skew);
}
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
//change time to One hour ahead
//now.setTime(now.getTime() + 60 * 60 * 1000);
//---------------End of Cookie code -------------------

//---------------DreamWeaver Functions ----------------

//   MM_swapImgRestore  + version 2 which changes the rollover image
//   preloadImages
//   MM_preloadImages
//   MM_findObj
//   MM_swapImage
//   newImage
//   changeImages

var id
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage3() { //v3.0
  var i,j=0,x,a=MM_swapImage3.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
   var b =a[2].charAt(13)
   if (b=="n"){
      n+=1
      if (n==7) {
         n = 1
      }
      north="images/index/northmap"+n+".jpg"
      MM_preloadImages(north)
   } else {
      s+=1
      if (s==7) {
         s = 1
      }
      south="images/index/southmap"+s+".jpg"
      MM_preloadImages(south)
   }
}


var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		menu_08_over = newImage("images/menu_08-over.gif");
		menu_09_over = newImage("images/menu_09-over.gif");
		menu_10_over = newImage("images/menu_10-over.gif");
		menu_11_over = newImage("images/menu_11-over.gif");
		menu_12_over = newImage("images/menu_12-over.gif");
		menu_13_over = newImage("images/menu_13-over.gif");
		menu_14_over = newImage("images/menu_14-over.gif");
		menu_15_over = newImage("images/menu_15-over.gif");
		preloadFlag = true;
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}
//-----------------------------------------------------
