// PC version
// constants
// find domain
var mydom1=document.domain
var mydom2="."+mydom1
alert(mydom2)
var thumbdir="http://www.arcticphoto2.co.uk/new3/search/thumbs/"
var previewdir="http://www.arcticphoto2.co.uk/eddy/"
var previewdira="http://www.arcticphoto2.co.uk/eddy/"
var previewdirb="http://www.arcticphoto2.co.uk/eddy/"
var imagedir = "/new3/images/"
var backgrd = "/new3/images/flakes1.gif"
var cgidir = "http://www.arcticphoto2.co.uk/cgi-bin/search3/"
var jsdir="/new3/search/"

var who2
var diag=0
var diag2=0
//get browser
   var browser = navigator.appName;
   var Nav = (browser == "Netscape");
   var IE = (browser == "Microsoft Internet Explorer");
   var plat= navigator.platform;
//---------------------------------------------------------------------------
// Error Handling
window.onerror = myOnError
msgArray = new Array()
urlArray = new Array()
lnoArray = new Array()
function myOnError(msg, url, lno) {
alert(msg)
   msgArray[msgArray.length] = msg
alert(url)
   urlArray[urlArray.length] = url
alert(lno)
   lnoArray[lnoArray.length] = lno
   return true
}
function displayErrors() {
   win2=window.open('','window2','scrollbars=yes')
   win2.document.writeln('<B>Error Report</B><P>')
alert(msgArray.length)
   for (var i=0; i < msgArray.length; i++) {
      win2.document.writeln('<B>Error in file:</B> ' + urlArray[i] + '<BR>')
      win2.document.writeln('<B>Line number:</B> ' + lnoArray[i] + '<BR>')
      win2.document.writeln('<B>Message:</B> ' + msgArray[i] + '<P>')
   }
   win2.document.close()
}

//-------------------------------------------------------------------------------
// 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" : "");
   domain=mydom1
   var c1 = getCookie(name)
   document.cookie = curCookie;
   var c1 = getCookie(name)
   var c2 = value
   if (c1 != c2) {
      setCookie2(name,"abcde",now,"/",mydom2)
      deleteCookie(name,"/",mydom2)
      var c1 = getCookie(name)
      if (c1 != value) {
//         alert("still wrong "+c1+" c2 "+c2)
      }
   }
}
function setCookie2(name, value, expires, path, domain, secure) { 
   var curCookie = name + "=" + escape(value) + 
      ((expires) ? "; expires=" + expires.toGMTString() : "") + 
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
   domain=mydom2
   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);
//--------------------------------------------------------
function discard(mypic,box,panel) {
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// box will hold the cookie name with the list of pictures
// for the lightbox
if (diag2==1){
   alert("   mypic "+mypic+" box "+box+" side "+panel)
}
   var saw = getCookie(box);
   var p= saw.split("#");
   var n = p.length;
   var saw2 ="";  
   var gap = "";
   for(var i=0; i < p.length; i++) {
      if (p[i].match(mypic)){
// discards is list of pictures in lightbox
         var t=getCookie("discards");
         if (!t) {
            t=""
            var sep=""
         } else {
            var sep="#";
         }
// need to check if mypic already in list
         if (t.match(mypic)) {
         } else {
            t += sep+p[i]
            setCookie("discards",t,now,"/")
         }
      } else {
         saw2 += gap+p[i];
         gap="#";
      }
   }
   setCookie(box,saw2,now,"/")
// need to know if to change right hand panel, panel=type1 if from lightbox preview
   if (panel=="type1"){
      var numf=document.light.numf.value
      if (numf==1){
         alert("No pictures Left")
         setCookie("mainrhs",box,now,'/')
         checkwinlr("right")
      } else {
         var np=document.preview2.np.value
         var ns=document.preview2.ns.value
         var nf=document.preview2.nf.value
         var box=document.light.thisbox.value
         setCookie("autoleftright","ok",now,'/')
         if (np!=1){
            np=np-1
         }
         if (nf!=1){
            nf=nf-1
         }
         makebox2()
         another(np,ns,nf,box)
      }
   } else {
      checkwinlr(panel)
   }
}
// end of discard
//--------------------------------------------------------
function undiscard(mypic) {
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// Restore picture to box in lightbox cookie
   var saw = getCookie("discards");
   var p= saw.split("#");
   var n = p.length;
   var saw2 ="";  
   var gap = "";
   for(var i=0; i < p.length; i++) {
      if (p[i].match(mypic)){
// throw is list of discards
// b will hold the cookie name with the list of pictures for the lightbox
         var box = getCookie("box");
         if (!box) {
            alert ("Lightbox not set")
            box = "main"
         }
         var t=getCookie(box);
         if (!t) {
            t=""
            var sep=""
         } else {
            var sep="#";
         }
         t += sep+p[i]
         setCookie(box,t,now,"/")
      } else {
         saw2 += gap+p[i];
         gap="#";
      }
   }
   setCookie("discards",saw2,now,"/")
// need to know if to change right hand panel if doing a search not in supergal
         var ww=window.location
       ww=ww+"abc"
         if(ww.match("supergal")){
         } else {
            checkwinlr("right")
       }
}
//---------------------------------------------------------------------------
//function winclose(box){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// Change the cookie that keeps track of whether a lightbox is open
//   var b = box + "han"
//   setCookie(b,"no",now,"/")
//}
//---------------------------------------------------------------------------
function movepic(mypic,box){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// box will hold the cookie name with the list of pictures
// for the lightbox
// non popup version
   if (diag2==1){
      alert("movepic")
   }
   var saw = getCookie(box);
// p has list of pictures in source box
   var p= saw.split("#");
   var n = p.length;
   var saw2 ="";  
   var gap = "";
// get target box details
   box2=getCookie("box")
   for(var i=0; i < p.length; i++) {
      if (p[i].match(mypic)){
// box2 is list of pictures in lightbox
         var t=getCookie(box2);
         if (!t) {
            t=""
            var sep=""
         } else {
            var sep="#";
         }
// need to check if mypic already in list
         if (t.match(mypic)) {
         } else {
            t += sep+p[i]
            setCookie(box2,t,now,"/")
         }
      } else {
         saw2 += gap+p[i];
         gap="#";
      }
   }
   setCookie(box,saw2,now,"/")
// redo lefthand panel 
   checkwinlr("right")
}
// end of movepic
//----------------------------------------------------------------

function resetwin(box){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// reset all open windows, box should be name of current window but is
// undefined if called from boxes.htm
// new non popup version
   var boxes=getCookie("boxes")
   if (diag2==1){ 
      alert("resetwin "+boxes)
   }
   p = boxes.split("#")
   if (!box){
      for(var i=0; i < p.length; i++) {
         checkwin(p[i])
      }
      if(box != "discards"){
         checkwin("discards")
      }
      checkwin("boxman")
   } else {
      for(var i=0; i < p.length; i++) {
         if (p[i] != box){
            checkwin(p[i])
         }
      }
      if(box != "discards"){
         checkwin("discards")
      }
      checkwin("boxman")
//      makewin3(box)
   }
}
//-----------------------------------------------------------------
function checkwin(box){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// check and reset windows
   if (diag2==1){
      alert("checkwin "+box)
   }
   var b = box + "han"
   var c = getCookie(b)
   if (!c){
   } else {
      if (c == "no"){
      } else {
         if (box == "discards"){
//            makewin4('discards')
         } else if(box == "boxman"){
//            boxman2()
         } else {
//            makewin4(box)
         }
      }
   }
}
//-----------------------------------------------------------------
function checkwinlr(panel){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// reset left and right frames
   var rhs =getCookie("mainrhs")
   if (diag2==1){
      alert("checkwinlr "+panel+" "+rhs)
   }
   setCookie("autoleftright",panel,now,'/')
// new righthand side if rhs not set to polarsearch
   if (panel=="left") {
// updating from left
      if (rhs != "polarsearch"){
         makewin2(rhs)
      } else {
// no need to do right so just do left
         setCookie("autoleftright","ok",now,'/')
         makebox2()
      }
//      makebox2()
   } else {
// updating from right
      makebox2()
//      if (rhs != "polarsearch"){
//         makewin2(rhs)
//      }
   }
}
//----------------------------------------------------------------
//Add a Lightbox
function newbox(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// no popup version
   var b = prompt("Please enter the name for the Lightbox. Please use a single short word:", "");
   if (!b) {
   } else {
// check for spaces and brackets
      var nameok="yes"
      var l = b.length
      for (var i =0;i<l;i++){
         var buc = b.substring(i,i+1)
         buc = buc.toLowerCase()
         if ( buc == "(" || buc == ")"){
            buc = "brackets"
            alert("You cannot use "+buc+" in the Lightbox name. You used - \""+b+"\". Please try again just using letters and\/or numbers")
            nameok = "no"
         } else if ( "abcdefghijklmnopqrstuvwxyz1234567890".match(buc) ) {
         } else {
            if (buc == " ") {
               buc = "spaces"
            } else if (buc == "(") {
               buc = "brackets"
            }
            alert("You cannot use "+buc+" in the Lightbox name. You used - \""+b+"\". Please try again just using letters and\/or numbers")
            nameok = "no"
         }
      }
      if (nameok == "yes") { 
         b=b.toLowerCase()
         var buc = b.substring(0,1)
         buc = buc.toUpperCase()
         var l = b.length
         buc += b.substring(1,l)
// Check if name in use
         var boxes=getCookie("boxes")
// test
        if (diag==1){
          alert("newbox "+boxes)
       }
// split boxes into seperate items
         var bo = boxes.split("#")
         l = bo.length
         var nameok="yes"
         for (var i =0;i<l;i++){
            if (bo[i]==b){
// Already in use
               alert("You already have a slde box called "+buc+". Please try again.")
               nameok="no"
            }
         }
      }
      if (nameok == "yes"){
         boxes += "#"+b
         setCookie("boxes",boxes,now,"/")
         setCookie(b,"",now,"/")
         var bhan = b + "han"
         setCookie(bhan,"no",now,"/")
// Check if new box is to be selected box
         if(confirm("Do you want to make the "+buc+" Lightbox the active lightbox to receive pictures?")){
            setCookie("box",b,now,"/")
         } else {
            var box = getCookie("box")
            var buc = box.substring(0,1)
            buc = buc.toUpperCase()
            var l = box.length
            buc += box.substring(1,l)
            alert("Main Lightbox is still "+buc)
         }
//         var   box=getCookie("box");
//         document.light.D1.options.length=0
//         var bo = boxes.split("#")
//         var l = bo.length
//         for (i=0;i < l;i++){
//            if (bo[i]==box){
//               var s = i;
//            }
// adding selected box
//            document.light.D1.options[i] = new Option(bo[i],bo[i]);
//         }
//         document.light.D1.options[s].selected=true
//         resetwin()
//         self.focus()
      }
   }
// need to know if to change panels if doing a search not in supergal
   var ww=window.location
   ww=ww+"abc"
   if(ww.match("supergal")){
     updatesel()
   } else {
      checkwinlr("left")
   } 
}
// end of newbox
//-----------------------------------------------------------------------------
function newbox2(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// no popup version
   var b = prompt("Please enter the name for the Lightbox. Please use a single short word:", "");
   if (!b) {
   } else {
// check for spaces and brackets
      var nameok="yes"
      var l = b.length
      for (var i =0;i<l;i++){
         var buc = b.substring(i,i+1)
         buc = buc.toLowerCase()
         if ( buc == "(" || buc == ")"){
            buc = "brackets"
            alert("You cannot use "+buc+" in the Lightbox name. You used - \""+b+"\". Please try again just using letters and\/or numbers")
            nameok = "no"
         } else if ( "abcdefghijklmnopqrstuvwxyz1234567890".match(buc) ) {
         } else {
            if (buc == " ") {
               buc = "spaces"
            } else if (buc == "(") {
               buc = "brackets"
            }
            alert("You cannot use "+buc+" in the Lightbox name. You used - \""+b+"\". Please try again just using letters and\/or numbers")
            nameok = "no"
         }
      }
      if (nameok == "yes") {  
         var boxes=getCookie("boxes");
         if (diag==1){
           alert("newbox2 "+boxes)
         }
         b=b.toLowerCase();
         var buc = b.substring(0,1)
         buc = buc.toUpperCase()
         var l = b.length
         buc += b.substring(1,l)
// Check if name in use
//         var boxes=getCookie("boxes")
// split boxes into seperate items
         var bo = boxes.split("#")
         l = bo.length
         for (var i =0;i<l;i++){
            if (bo[i]==b){
// Already in use
               alert("You already have a slde box called "+buc+". Please try again.")
               nameok="no"
            }
         }
      }
      if (nameok == "yes"){
         boxes += "#"+b;
         setCookie("boxes",boxes,now,"/");
         setCookie(b,"",now,"/");
         var bhan = b + "han"
         setCookie(bhan,"no",now,"/")
         var buc = b.substring(0,1)
         buc = buc.toUpperCase()
         var l = b.length
         buc += b.substring(1,l)
         if(confirm("Do you want to make the "+buc+" Lightbox the active lightbox to receive pictures?")){
            setCookie("box",b,now,"/")
         } else {
            var box = getCookie("box")
            buc = box.substring(0,1)
            buc = buc.toUpperCase()
            var l = box.length
            buc += box.substring(1,l)
            alert("Main Lightbox is still "+buc)
         }
// need to know if to change right hand panel
      checkwinlr("right")
      }
   }
}
// end of newbox2
//------------------------------------------------------------------------------
function updatesel(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// read in boxes and split into seperate items
//var a = document.cookie
// check if new user
newuser();
var   boxes=getCookie("boxes");
var   box=getCookie("box");
var bo = boxes.split("#")
var l = bo.length
document.light.D1.options.length=0
for (i=0;i < l;i++){
   if (bo[i]==box){
      var s = i;
   }
// adding selected box
   document.light.D1.options[i] = new Option(bo[i],bo[i]);
}
document.light.D1.options[s].selected=true
var   box = getCookie("box");
   if (!box) {
      alert ("Lightbox not set")
      box="main"
   } 
   var buc = box.substring(0,1)
   buc = buc.toUpperCase()
   var l = box.length
   buc += box.substring(1,l)
//   document.light.openbox.value="Open "+buc+" Lightbox"
}
//------------------------------------------------------------------------------

function whichbox(element) {
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// non pup version
// just deaks with changes to right hand panel
   for (var i = 0 ; i < document.light.D1.length; i++){
      if (document.light.D1[i].selected){
         var b = document.light.D1[i].value
      }
   }
//save lightbox name in cookie box
   box = getCookie("box");
   if (!box) {
      alert ("Lightbox not set")
   } else {
      box = b
      setCookie("box",box,now,"/");
   }
//   checkwin("boxman")
//   document.light.openbox.value="Open "+buc+" Lightbox"
// need to know if to change right hand panel
   var rhs =getCookie("mainrhs")
   if (diag2==1){
      alert(rhs)
   }
// new righthand side if rhs not set to polarsearch
   if (rhs != "polarsearch"){
      makewin2(rhs)
   }
   makebox2()
//   resetwin()
//   var buc = box.substring(0,1)
//   buc = buc.toUpperCase()
//   var l = box.length
//   buc += box.substring(1,l)
//   self.focus()
}
//------------------------------------------------------------------

function whichbox2(element) {
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// non popup version. Only used by RHS
   for (var i = 0 ; i < document.light.E1.length; i++){
      if (document.light.E1[i].selected){
         var b = document.light.E1[i].text
      }
   }
//save lightbox name in cookie box
   box = getCookie("box");
   if (!box) {
      alert ("Lightbox not set")
   } else {
      box = b
      setCookie("box",box,now,"/");
   }
// need to know if to change right hand panel
   var rhs =getCookie("mainrhs")
   if (diag2==1){
      alert("whichbox3 change in rhs window, source is "+rhs+" new master "+b)
   }
// new righthand side if rhs not set to polarsearch
// change left before right
   makebox2()
   if (rhs != "polarsearch"){
      makewin2(rhs)
   }
}
// end of whichbox2
//------------------------------------------------------------------

function whichbox3(element,a) {
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// non popup version. Only used by RHS
   for (var i = 0 ; i < document.light.E1.length; i++){
      if (document.light.E1[i].selected){
         var b = document.light.E1[i].text
      }
   }
//save lightbox name in cookie box
   var box = getCookie("box");
   if (!box) {
      alert ("Lightbox not set")
   } else {
      var box2 = box
      box = b
      setCookie("box",box,now,"/");
   }
// need to know if to change right hand panel
   var rhs =getCookie("mainrhs")
   if (diag2==1){
      alert("whichbox3 change in rhs window, source is "+rhs+" new master "+b)
      alert(rhs)
   }
// new righthand side if rhs not set to polarsearch
// change left before right
   checkwinlr("right")
   if (diag2==1){
      alert ("finished whichbox3 "+a+" "+b)
   }
//   resetwin(a)
}
//-----------------------------------------------------------------

function closebox(box){

// Copyright Keith Robinson ccaakwr@ucl.ac.uk

   winclose(box)

   self.close()

}
//-------------------------------------------------------------
function makewin2(b){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// new version to avoid pop-ups
   if (!b) {
      if (diag2==1){
         alert("reading cookie")
     }
     box = getCookie("box");
   } else {
      box = b
   }
   if (diag2==1){
      alert("makewin2 b="+box)
   }
   if (!box) {
      alert ("Lightbox not set")
      box = "main"
   }
// cookie windows handles no longer used
//   var h = getCookie(box+"han")
//   if (!h || h != "yes"){
//      var a=window.open(jsdir+"patient.htm",box+"bcp","height=450,width=630,menubar=yes,toolbar=no,location=no,scrollbars=yes,resizable=yes")
//   } else {
//      var a=window.open("",box+"bcp")
//      a=window.open("",box+"bcp")
//   }

//   a.close
// new cookie to hold contents of right hand panel
   document.light.action="http://www.arcticphoto2.co.uk/cgi-bin/search3/newlightbx2.pl"
//
   setCookie("mainrhs",box,now,"/")
   if (diag2==1){
      alert("makewin2 opening "+box)
   }
   document.light.target = "main"
   document.light.thisbox.value=box
//   setCookie(box+"han","yes",now,"/")
//   a.focus()
// get main cookie
   var ccc=getCookie(box)
   document.light.submit()
}
//-------------------------------------------------------------

function makewin3(box){

// Copyright Keith Robinson ccaakwr@ucl.ac.uk

// update the current window

   document.light.target = "_self"

   document.light.thisbox.value=box

   document.light.submit()
   
}

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

function makewin4(b){

// Copyright Keith Robinson ccaakwr@ucl.ac.uk

// same as makewin 2 but with focus

   if (!b) {

      box = getCookie("box");

   } else {

      box = b

   }

   if (!box) {
      alert ("Lightbox not set")
      box = "main"
   }
   var h = getCookie(box+"han")
   if (!h || h != "yes"){

      var a=window.open(jsdir+"patient.htm",box+"bcp","height=450,width=630,menubar=yes,toolbar=no,location=no,scrollbars=yes,resizable=yes")

   } else {

      var a=window.open("",box+"bcp")

      a=window.open("",box+"bcp")

   }

//   a.close

   document.light.target = box+"bcp"

   document.light.thisbox.value=box

   setCookie(box+"han","yes",now,"/")

//   a.focus()

   document.light.submit()

}

//-------------------------------------------------------------
function boxman2(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// new version avoids pop-ups
// uses main rather than window handles
//   var h = getCookie("boxmanhan")
//   if (!h || h != "yes"){
//      var man=window.open(jsdir+"patient.htm","boxmanagerbcp","height=450,width=630,menubar=yes,toolbar=no,location=no,scrollbars=yes,resizable=yes", statusbar="yes")
//   } else {
//      var man=window.open("","boxmanagerbcp")
//      man=window.open("","boxmanagerbcp")
//   }
// new cookie to hold contents of right hand panel
   setCookie("mainrhs","boxmanager",now,"/")
   document.light.action="http://www.arcticphoto2.co.uk/cgi-bin/search3/newlightbx2.pl"
   document.light.target = "main"
   document.light.thisbox.value="boxmanager"
//   man.focus()
//   setCookie("boxmanhan","yes",now,"/")
   document.light.submit()
}
//------------------------------------------------------------
// function preview(mypic,mycap,w,h,who,nums) {
function preview(mypic,mycap3,nums) {
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// nums added 14-10-2001
// addpic added 23-12-2001, also check for picture in lightbox
// Modified for Mozilla and Netscape 7 - 18-10-2002
// modified to have image folder as part of mycap3, added before caption, after photographer
   var q=mycap3.split("@")
   var l = q.length
   var w  = q[2] - 0
   var h  = q[3] - 0
   var who = q[4]
   var mycap= q[6]
   var imagedir=q[5]
   previewdira="http://www.arcticphoto2.co.uk/eddy/"+imagedir+"images/"
   previewdirb="http://www.arcticphoto2.co.uk/eddy/"+imagedir+"images/"
   if (diag2==1){
      alert(previewdira)
   }
   var d= "\',\'"+q[0]+"@"+q[1]+"@"+w+","+h+"@"+who+"@"
// allow for low screen res
   if (h <= w) {
// landscape
      var w2 = w+75
      var h2 = h+330
   } else {
      var w2 = w+400
      var h2 = h+140
   }
   var sh = screen.height
   if (sh < 750) {
// small screen
      w2=w2*.9
      h2=h2*.8
      if (h2 >= 620){
         h2=570
      }
   }
// Preview goes into main window
//   var f = 'height='+h2+',width='+w2+',toolbar=no,location=no,scrollbars=yes,resizable=yes'
//   var f = 'height='+h2+',width='+w2+',toolbar=no,location=no,scrollbars=no,resizable=yes'
//   f += ' ,left=10,top=0'
   var mypic2 = mypic.toUpperCase()
//   var a=window.open("",self,f)
//   top.frames[1].document.open();
//   top.frames[1].document.open();
   var b = "<html>\n<head>\n<title>Preview</title>\n"
   b += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n"
   b += "<link href=../new3/search//%22/eddy/arcticphoto1.css/%22 rel=\"stylesheet\" type=\"text/css\">\n"
   b += "<link href=../new3/search//%22/eddy/makebox.css/%22 rel=\"stylesheet\" type=\"text/css\">\n"
   b += "<script LANGUAGE=\"JavaScript\" src=../new3/search//%22%22+jsdir+%22polar.js/%22>\n";
   b += "</script>\n";
   b += "</head>\n";
   b += "<body link=\"#0066FF\" vlink=\"#0066FF\" alink=\"#0066FF\" background=../new3/search//%22%22+ backgrd + "\">\n"
//   b += "preview by javascript preview "+h+" "+w+"\n"
   if (h <= w+50) {
// landscape
// use small preview on small screen
// Different sections for IE or Netscape and Mozilla
      if (IE) {
         b += "<center>\n"
         b += "<script language=\"JavaScript\">\n"
         b += "<!--\n"
         b += "var sh = screen.height\n"
         b += "if (sh < 750) {\n"
         b += "var s =\"<img src=\\\"" + previewdirb + mypic+".jpg\\\" border=\\\"0\\\" >\"\n"
         b += "} else {\n"
         b += "var s =\"<img src=\\\"" + previewdira + mypic+".jpg\\\" border=\\\"0\\\" width=\\\""+w+"\\\" height=\\\""+h+"\\\">\"\n"
         b += "}\n"
         b += "var whichwindow=\"preview\"\n"
         b += "document.write(s)\n"
         b += "// -->\n"
         b += "</script>\n"
      } else {
         b += "<script language=\"JavaScript\">\n"
         b += "<!--\n"
// deal with Firefox window placement and refresh problems
         var ls=getCookie("lasttime")
         b += "setCookie(\"lasttime\",\""+ls+"\",now,\"/\")\n"
         window.scrollTo(0,0)
//
         b += "var whichwindow=\"preview\"\n"
         b += "// -->\n"
         b += "</script>\n"
         b += "<center>\n"
         var sh = screen.height
         if (sh < 750) {
            var s ="<img src=\"" + previewdirb + mypic+".jpg\" border=\"0\" >"
         } else {
            var s ="<img src=\"" + previewdira + mypic+".jpg\" border=\"0\" width=\""+w+"\" height=\""+h+"\">"
         }
         b += s
      }
// End
     var tabwid = w+50;
      b += "<table width=\""+tabwid+"\">\n"
      b += "<td align=\"right\" width=\"100\" valign=\"top\"><strong>"+mypic2+":</strong></td>\n"
      b += "<td align=\"left\">"+mycap+"</td>\n"
      b += "</tr>\n"
      b += "</table>\n"
// Add rollover button for add image to lightbox
// check for image being in lightbox
      var match=""
      var boxes = getCookie("boxes")
      if (diag2==1){
         alert("preview "+boxes)
     }
      var bo = boxes.split("#")
      var l = bo.length
      for (i=0;i < l;i++){
         var box = bo[i]
         var c = getCookie(box)
         if (!c) {
         } else {
// split into pictures
            var p= c.split("#");
            var n = p.length;
            for(var j=0; j < p.length; j++) {
               var q=p[j].split("@")
// check if mypic in list of images
               if (q[0] == mypic){
               var buc = box.substr(0,1)
               buc = buc.toUpperCase()
               var l2 = box.length
               buc += box.substr(1,l2-1)
               match=buc
               }
            }
         }
      }
      if (match == 0) {
         b += "<form name=\"light\"\n";
         b += "method=\"get\" action=\"http://www.arcticphoto2.co.uk/cgi-bin/search3/makebox.pl\">\n";
         b += "<input type=\"hidden\" name=\"thisbox\" value=\"boxmanager\">\n";
         b += "<a onMouseOut=\"MM_swapImgRestore2()\"\n"
         b += "onMouseOver=\"MM_swapImage2(\'a"+mypic+"\',\'\',\'/eddy/images/addpic2.gif\',1)\"\n"
         b += "href=\"javascript:addpic(\'"+mypic+d+mycap+"\')\">\n"
         b += "<img src=\"/eddy/images/addpic1.gif\" alt=\"Click to add picture to light box\"\n"
         b += " border=\"0\" name=\"a"+mypic+"\"\n"
         b += " width=\"156\" height=\"21\"></a></form>\n"
      } else {
         b += "<img src=../new3/search//%22/eddy/images/added.gif/%22 alt=\"Picture already in "+match+" Light Box\"\n"
         b += " border=\"0\" name=\"a"+mypic+"\" width=\"156\" height=\"21\">\n"
      }
// end of button
      b += "</center>\n"
      b += "<p align=\"center\">© \n"
      photograher(who)
      b += who2
      b += "</p>\n"
//add form next preview
      b += "<form METHOD=\"GET\" ACTION=../new3/search//%22%22+cgidir+%22newanother.pl/%22 name=\"nextprev\" >\n"
// add hidden elements for form elements in next form
      b += "<input type=\"hidden\" name=\"keywords\" size=\"50\" value=\""+keys1+"\">\n";
      b += "<input type=\"hidden\" name=\"type\" value=\""+type1+"\">\n";
      b += "<input type=\"hidden\" name=\"keywords2\" value=\""+keys2+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"type2\" VALUE=\""+type2+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"numf\" VALUE=\""+numf+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"nums\" VALUE=\""+nums+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"nextpic\" VALUE=\"xxxx\">\n";
      if (show == "ON") {
         b += "<input type=\"hidden\" name=\"show\" value=\"ON\"> \n";
      }
// add buttons for slide show, modified to rollover
      b += "<table border=\"0\" align=\"center\"><tr>\n";
      if (nums != 1) {
         b += "<td width=\"14\" valign=\"middle\"><img src=../new3/search//%22/eddy/images/flake-t.gif/%22 width=\"14\" height=\"12\"></td>\n";
         b += "<td width=\"75\" valign=\"middle\"><a  href=\"javascript:nextpreview('previous')\"><strong>Previous</strong>  </a></td>\n";
         var bxtra1 = "<td>&nbsp;</td><td>&nbsp;</td>"
      } else {
         var bxtra1=""
      }
      b += "<td valign=\"middle\">This is picture "+nums+" of "+numf+"  </td>\n";
      if (nums != numf) {
         b += "<td width=\"14\" valign=\"middle\"><img src=../new3/search//%22/eddy/images/flake-t.gif/%22 width=\"14\" height=\"12\"></td>\n";
         b += "<td width=\"34\" valign=\"middle\"><a  href=\"javascript:nextpreview('next')\"><strong>Next</strong></a></td>\n";
         var bxtra2 = "<td>&nbsp;</td><td>&nbsp;</td>"
      } else {
         var bxtra2 = ""
      }
      b += "</tr><tr>"+bxtra1+"<td><div align=\"center\"><a href=\"javascript:lastsearch()\"><strong>Return to Search</strong></a></div></td>"+bxtra2+"\n";
      b += "</table>\n";
      b += "</form>\n"
      b += "<hr width=\"50%\">\n"
      b += "<form METHOD=\"GET\" ACTION=../new3/search//%22%22+cgidir+%22newpreview.pl/%22 name=\"showkeywords\">\n"
// add hidden elements for form elements in next form
      b += "<input type=\"hidden\" name=\"keywords\" size=\"50\" value=\""+keys1+"\">\n";
      b += "<input type=\"hidden\" name=\"type\" value=\""+type1+"\">\n";
      b += "<input type=\"hidden\" name=\"keywords2\" value=\""+keys2+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"type2\" VALUE=\""+type2+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"numf\" VALUE=\""+numf+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"nums\" VALUE=\""+nums+"\">\n";
      if (show == "ON") {
         b += "<input type=\"hidden\" name=\"show\" value=\"ON\"> \n";
      }
      b += "<input type=\"hidden\" name=\"picture\" value=\""+mypic2+"\">\n";
      b += "<table align=\"center\"><tr>\n"
      b += "<td width=\"14\" valign=\"middle\"><img src=../new3/search//%22/eddy/images/flake-t.gif/%22 width=\"14\" height=\"12\"></td>\n"
      b += "<td valign=\"middle\"><a href=\"javascript:showkeywords()\"><strong>Show Keywords for this Picture</strong></a>\n"
      b += "</td></tr></table>\n"
//
      b += "<div align=\"center\"><center><p>Use the button above to start a search<br>\n"
      b += "based apon the keywords for this picture</p>\n"
      b += "</center></div>\n"
      b += "</form>\n"
//      b += "</td>\n"
   } else {
// portrait
      b += "<table colspan=\"2\" cellspacing=\"5\">\n"
      b += "<tr><td>\n"
// use small preview on small screen
// Different sections for IE or Netscape and Mozilla
      if (IE) {
         b += "<script language=\"JavaScript\"><!--\n"
         b += "var sh = screen.height\n"
         b += "if (sh < 750) {\n"
         b += "var s =\"<img src=\\\"" + previewdirb + mypic+".jpg\\\" border=\\\"0\\\" ></td>\"\n"
         b += "} else {\n"
         b += "var s =\"<img src=\\\"" + previewdira + mypic+".jpg\\\" border=\\\"0\\\" width=\\\""+w+"\\\" height=\\\""+h+"\\\">\"\n"
         b += "}\n"
         b += "document.write(s)\n"
         b += "var whichwindow=\"preview\"\n"
         b += "// -->\n"
         b += "</script>\n"
      } else {
         b += "<script language=\"JavaScript\"><!--\n"
// deal with Firefox window placement and refresh problems
         var ls=getCookie("lasttime")
         b += "setCookie(\"lasttime\",\""+ls+"\",now,\"/\")\n"
         window.scrollTo(0,0)
//
         b += "var whichwindow=\"preview\"\n"
         b += "// -->\n"
         b += "</script>\n"
         b += "<center>\n"
         var sh = screen.height
         if (sh < 750) {
            var s ="<img src=\"" + previewdirb + mypic+".jpg\" border=\"0\" >"
         } else {
            var s ="<img src=\"" + previewdira + mypic+".jpg\" border=\"0\" width=\""+w+"\" height=\""+h+"\">"
         }
         b += s
      }
// end
      b += "<td align=\"center\"><p><strong>"+mypic2+":</strong></p><div align=\"left\">\n"
      b += mycap+"</div>\n"
// Add rollover button to add image to lightbox
// check for image being in lightbox
      var match=""
      var boxes = getCookie("boxes")
      if (diag2==1){
         alert("preview "+boxes)
      }
      var bo = boxes.split("#")
      var l = bo.length
      for (i=0;i < l;i++){
         var box = bo[i]
         var c = getCookie(box)
         if (!c) {
         } else {
// split into pictures
            var p= c.split("#");
            var n = p.length;
            for(var j=0; j < p.length; j++) {
               var q=p[j].split("@")
// check if mypic in list of images
               if (q[0] == mypic){
               var buc = box.substr(0,1)
               buc = buc.toUpperCase()
               var l2 = box.length
               buc += box.substr(1,l2-1)
               match=buc
               }
            }
         }
      }
//      b += "<center>\n"
      if (match == 0) {
         b += "<form name=\"light\"\n";
         b += "method=\"get\" action=\"http://www.arcticphoto2.co.uk/cgi-bin/search3/makebox.pl\">\n";
         b += "<input type=\"hidden\" name=\"thisbox\" value=\"boxmanager\">\n";
         b += "<a onMouseOut=\"MM_swapImgRestore2()\"\n"
         b += "onMouseOver=\"MM_swapImage2(\'a"+mypic+"\',\'\',\'/eddy/images/addpic2.gif\',1)\"\n"
         b += "href=\"javascript:addpic(\'"+mypic+d+mycap+"\')\">\n"
         b += "<img src=\"/eddy/images/addpic1.gif\" alt=\"Click to add picture to light box\"\n"
         b += " border=\"0\" name=\"a"+mypic+"\"\n"
         b += " width=\"156\" height=\"21\"></a></form>\n"
      } else {
         b += "<img src=../new3/search//%22/eddy/images/added.gif/%22 alt=\"Picture already in "+match+" Light Box\"\n"
         b += " border=\"0\" name=\"a"+mypic+"\" width=\"156\" height=\"21\">\n"
      }
// end of button
      b += "<p align=\"center\">© \n"
      photograher(who)
      b += who2
      b += "</p>\n"
      b += "<br>\n"
//add form next preview
      b += "<form METHOD=\"GET\" ACTION=../new3/search//%22%22+cgidir+%22newanother.pl/%22 name=\"nextprev\" >\n"
// add hidden elements for form elements in next form
      b += "<input type=\"hidden\" name=\"keywords\" size=\"50\" value=\""+keys1+"\">\n";
      b += "<input type=\"hidden\" name=\"type\" value=\""+type1+"\">\n";
      b += "<input type=\"hidden\" name=\"keywords2\" value=\""+keys2+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"type2\" VALUE=\""+type2+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"numf\" VALUE=\""+numf+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"nums\" VALUE=\""+nums+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"nextpic\" VALUE=\"xxxx\">\n";
      if (show == "ON") {
         b += "<input type=\"hidden\" name=\"show\" value=\"ON\"> \n";
      }
// add buttons for slide show, modified to text rollover
      b += "<table border=\"0\" align=\"center\"><tr>\n";
      if (nums != 1) {
         b += "<td width=\"14\" valign=\"middle\"><img src=../new3/search//%22/eddy/images/flake-t.gif/%22 width=\"14\" height=\"12\"></td>\n";
         b += "<td width=\"75\" valign=\"middle\"><a  href=\"javascript:nextpreview('previous')\"> <strong>Previous</strong>  </a></td>\n";
         var bxtra1 = "<td>&nbsp;</td><td>&nbsp;</td>"
      } else {
         var bxtra1 = ""
      }
      b += "<td valign=\"middle\">This is picture "+nums+" of "+numf+"  </td>\n";
      if (nums != numf) {
         b += "<td width=\"14\" valign=\"middle\"><img src=../new3/search//%22/images/flake-t.gif/%22 width=\"14\" height=\"12\"></td>\n";
         b += "<td width=\"34\" valign=\"middle\"><a  href=\"javascript:nextpreview('next')\"><strong>Next</strong></a></td>\n";
         var bxtra2 = "<td>&nbsp;</td><td>&nbsp;</td>"
      } else {
         var bxtra2 = ""
      }
      b += "</tr><tr>"+bxtra1+"<td><div align=\"center\"><a href=\"javascript:lastsearch()\"><strong>Return to Search</strong></a></div></td>"+bxtra2+"\n";
      b += "</table>\n";
      b += "</form>\n"
      b += "<hr width=\"50%\">\n"
      b += "<form METHOD=\"GET\" ACTION=../new3/search//%22%22+cgidir+%22newpreview.pl/%22 name=\"showkeywords\">\n"
// add hidden elements for form elements in next form
      b += "<input type=\"hidden\" name=\"keywords\" size=\"50\" value=\""+keys1+"\">\n";
      b += "<input type=\"hidden\" name=\"type\" value=\""+type1+"\">\n";
      b += "<input type=\"hidden\" name=\"keywords2\" value=\""+keys2+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"type2\" VALUE=\""+type2+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"numf\" VALUE=\""+numf+"\">\n";
      b += "<input TYPE=\"hidden\" NAME=\"nums\" VALUE=\""+nums+"\">\n";
      if (show == "ON") {
         b += "<input type=\"hidden\" name=\"show\" value=\"ON\"> \n";
      }
      b += "<input type=\"hidden\" name=\"picture\" value=\""+mypic2+"\">\n";
      b += "<table><tr>\n"
      b += "<td width=\"14\" valign=\"middle\"><img src=../new3/search//%22/images/flake-t.gif/%22 width=\"14\" height=\"12\"></td>\n"
      b += "<td valign=\"middle\"><a href=\"javascript:showkeywords()\"><strong>Show Keywords for this Picture</strong></a>\n"
      b += "</td></tr></table>\n"
      b += "<div align=\"center\"><center><p>Use the button above to start a search<br>\n"
      b += "based apon the keywords for this picture</p>\n"
      b += "</center></div>\n"
      b += "</form>\n"
      b += "</td>\n"
      b += "</tr>\n"
      b += "</table>\n"
   }
   b += "</body>\n"
   b += "</html>\n"
//   top.frames[1].document.open
//   top.frames[1].document.open
//   top.frames[1].document.write(b);
//   top.frames[1].document.close();
   document.open
   document.write(b);
   document.close();
//   a.focus();
//   a.resizeTo(w2,h2);
}
//------------------------------------------------------------
function preview2(mypic,mycap,w,h,who,imagefold,nums,numf,box) {
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// nums and numf added 28-12-2001
// allow for low screen res
// new version to avoid pop-ups
// now done in perl by preview2.pl
   document.preview2.mypic.value=mypic
   document.preview2.mycap.value=mycap
   document.preview2.w.value=w
   document.preview2.h.value=h
   document.preview2.who.value=who
   document.preview2.nums.value=nums
   document.preview2.numf.value=numf
   document.preview2.box.value=box
   var sh = screen.height
   document.preview2.sh.value=sh
// modified to have foldef for picture passed as a parameter, imagefold
//   previewdira="http://www.arcticphoto2.co.uk/eddy/"+imagefold+"images/"
//   previewdirb="http://www.arcticphoto2.co.uk/eddy/"+imagefold+"images/"
   document.preview2.imagefold.value=imagefold
   document.preview2.submit()
}
//------------------------------------------------------------
function preview2a(mypic,mycap,w,h,who,imagefold,nums,numf,box) {
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// nums and numf added 28-12-2001
// allow for low screen res
// new version to avoid pop-upds
// now done in perl by preview2.pl
// same as preview2 but called from lightbox window so the form is called light rather than preview2
   document.light.mypic.value=mypic
   document.light.mycap.value=mycap
   document.light.w.value=w
   document.light.h.value=h
   document.light.who.value=who
   document.light.nums.value=nums
   document.light.numf.value=numf
   document.light.box.value=box
   var sh = screen.height
   document.light.sh.value=sh
// modified to have foldef for picture passed as a parameter, imagefold
//   previewdira="http://www.arcticphoto2.co.uk/eddy/"+imagefold+"images/"
//   previewdirb="http://www.arcticphoto2.co.uk/eddy/"+imagefold+"images/"
   document.light.imagefold.value=imagefold
   document.light.action="/cgi-bin/search3/preview2.pl"
   document.light.submit()
}
//------------------------------------------------------------

function another(np,nums,numf,box){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// Javascript version of another 28-12-2001
// box will hold the cookie name with the list of pictures
// for the lightbox
// new version to avoid popups
// Now done in perl to avoid Firefox refresh problems
   var saw = getCookie(box);
   var p= saw.split("#");
// sort p
   p.sort()
   var n = p.length;
   var c = p[np-1].split("@")
//mypic,mycap,w,h,who,nums,numf,box needed as in preview2
   var mypic = c[0]
   var who = c[4]
   var c2 = c[3].split(",")
   var w = c2[0]-0
   var h = c2[1]-0
   var imagefold = c[5]
   var mycap = c[6]
   nums=np
// put value into form and submit
   document.preview2.mypic.value=mypic
   document.preview2.mycap.value=mycap
   document.preview2.w.value=w
   document.preview2.h.value=h
   document.preview2.who.value=who
   document.preview2.nums.value=nums
   document.preview2.numf.value=numf
   document.preview2.box.value=box
   var sh = screen.height
   document.preview2.imagefold.value=imagefold
   document.preview2.sh.value=sh
//   setCookie(box+"han","yes",now,"/")
//   a.focus()
// get main cookie
//   var ccc=getCookie(box)
   document.preview2.submit()
}
//------------------------------------------------------------

function photograher(who){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
   who2="Edward Parker\n"
}
//------------------------------------------------------------
function register(mypic,mycap3,ns){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// has to pass on ns to server
   var q=mycap3.split("@")
   var l = q.length
   var w  = q[2] - 0
   var h  = q[3] - 0
   var who = q[4]
   var mycap= q[5]
//
   var c = mypic+"@"+mycap+"@"+w+"@"+h+"@"+who

   var p = getCookie("preview")

   if (p=="Yes") {

      preview(mypic,mycap3,ns)

   } else {

      setCookie("previewpic",c,now,"/")

      if (h <= w) {

         var w2 = w+50

         var h2 = h+300

      } else {

         var w2 = w+350

         var h2 = h+75

      }

      var f = 'height='+h2+',width='+w2+',toolbar=no,location=no,scrollbars=yes,resizable=yes'

      f += ' ,left=10,top=10'

      var a=window.open("" + jsdir + "register.htm","reviewbcp",f)

      var a=window.open("" + jsdir + "register.htm","reviewbcp",f)

   }

}
//------------------------------------------------------------
function addpic(mypic,mycap) {
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// mycap has image folder name
   var i = 0
   if ((c=MM_findObj("a"+mypic))!=null){
   } else {
      alert("object not found")
   }
// b will hold the cookie name with the list of pictures for the lightbox
   var cook = document.cookie
   var csize = cook.length
   var savecap = getCookie("savecap")
   if (!savecap) {
      savecap = "yes"
   }
   if (csize >= 3900) {
      if (savecap=="yes") {
         var msg = "You have reached the limit of the numbers of pictures"
         msg += " you can have have in your lightboxes. You have the choice of"
         msg += " switching to working without picture captions which will allow"
         msg += " you to have many more pictures."
         alert(msg)
         msg = "Do you wish to switch?"
         if(confirm(msg)){
            removecap()
         } else {
            alert("You will not be able to add new pictures untill you have removed")
         }
      } else { 
         var msg = "You have reached the limit of the numbers of pictures"
         msg += " you can have have in your lightboxes. Even without saving captions"
         msg += " you have now reached a point where adding further pictures will"
         msg += " cause you to loose others you have selected. Before you can add"
         msg += " any more pictures you will have to discards some others and then empty"
         msg += " the Discards Lightbox."
         alert(msg)
      }
   } else {
      var box = getCookie("box");
      if (diag2==1){
        alert("addpic box "+box);
     }
      if (!box) {
         alert ("Lightbox not set")
         box = "main"
      }
      saw = getCookie(box);
      if (!saw) {
      saw="";
      var sep=""
      } else {
         var sep= "#";
      }
// need to check if mypic already in list, need to check list in cookie
//      if (c.src.match("added.gif")) {
      var match=""
      var mboxes = getCookie("boxes")
      if (diag2==1){
         alert("addpic "+mboxes)
      }
      var mbo = mboxes.split("#")
      var ml = mbo.length
      mbo[ml]="discards"
      ml += 1
      for (mi=0;mi < ml;mi++){
         var mbox = mbo[mi]
         var mc = getCookie(mbox)
         if (!mc) {
         } else {
// split into pictures
            var mp= mc.split("#");
            var mn = mp.length;
            for(var mj=0; mj < mn; mj++) {
               var mq=mp[mj].split("@")
// check if mypic in list of images
               if (mq[0] == mypic){
                  var mbuc = mbox.substr(0,1)
                  mbuc = mbuc.toUpperCase()
                  var ml2 = mbox.length
                  mbuc += mbox.substr(1,ml2-1)
                  match=mbuc
               }
            }
         }
      }
      if (match != ""){
         if (match=="Discards") {
            alert("The picture is in the "+match+" lightbox.It is being moved back into "+box)
            c.src =imagedir+"added.gif"
            c.alt ="Picture moved to "+box+" Lightbox"
// move image back to lightbox box
            if (diag==1)
               {alert(mypic)
            }
            undiscard(mypic);
         } else {
            alert("The picture has already been added to the "+match+" lightbox")
            c.src =imagedir+"added.gif"
            c.alt ="Picture already in "+match+ " Lightbox"
         }
      } else {
         if (savecap=="no") {
// still need to keep the size information and folder location for eddy
            var q=mycap.split("@")
            var l = q.length
            saw=saw+sep+mypic+"@"
            for (var j = 0;j< q.length-1;j++){
               saw += q[j]+"@"
            }
         } else {
            saw=saw+sep+mypic+"@"+mycap
         }
         setCookie(box,saw,now,"/");
         var a = c.alt
// Change button to show lightbox
         box = getCookie("box");
         if (!box) {
            alert ("Lightbox not set")
         } else {
            var buc = box.substr(0,1)
            buc = buc.toUpperCase()
            var l = box.length
            buc += box.substr(1,l-1)
            c.alt ="Added to "+buc+ " Lightbox"
            c.src =imagedir+"added.gif"
         }
// update left-hand pane if doing a search not in supergal
         var ww=window.location
       ww=ww+"abc"
         if(ww.match("supergal")){
         } else {
           makebox2()
       }
      } 
      window.focus()
   }
}
// end of addpic
//--------------------------------------------------------------------

function addpic2(mypic,mycap) {

// Copyright Keith Robinson ccaakwr@ucl.ac.uk

// b will hold the cookie name with the list of pictures for the lightbox

   var box = getCookie("box");

   var savecap = getCookie("savecap")

   if (!savecap) {

      savecap = "yes"

   }

   if (!box) {

      alert ("Lightbox not set")

      box = "main"

   }

   saw = getCookie(box);

   if (!saw) {

      saw="";

      var sep=""

   } else {

      var sep= "#";

   }

// need to check if mypic already in list, need to check list in cookie
// if (c.src.match("added.gif")) {
   var match=""
   var mboxes = getCookie("boxes")
   if (diag==1){
      alert("addpic2 "+mboxes)
   }
   var mbo = mboxes.split("#")
   var ml = mbo.length
   mbo[ml]="discards"
   ml += 1
   for (mi=0;mi < ml;mi++){
      var mbox = mbo[mi]

      var mc = getCookie(mbox)

      if (!mc) {

      } else {

// split into pictures

         var mp= mc.split("#");

         var mn = mp.length;

         for(var mj=0; mj < mn; mj++) {

            var mq=mp[mj].split("@")

// check if mypic in list of images

            if (mq[0] == mypic){

            var mbuc = mbox.substr(0,1)

            mbuc = mbuc.toUpperCase()

            var ml2 = mbox.length

            mbuc += mbox.substr(1,ml2-1)

            match=mbuc

            }

         }

      }

   }

   if (match != ""){

      alert("The picture has already been added to a lightbox")

      c.src =imagedir+"added.gif"

      c.alt ="Picture already in "+match+ " Lightbox"

   } else {

      if (savecap=="no"){

// replace caption by single blank

         var q=mycap.split("@")

         var nq = q.length

         newp = q[0]+"@"

// replace caption by a single blank

         q[nq-1]=" "

         for ( var jp = 1; jp < nq;jp++){

            newp += q[jp]+"@"

         }

         saw=saw+sep+mypic+"@"+newp

      } else {

         saw=saw+sep+mypic+"@"+mycap

      }

      setCookie(box,saw,now,"/");

      var a = c.value

// Change button to show lightbox

      box = getCookie("box");

      if (!box) {

         alert ("Lightbox not set")

      } else {

         var buc = box.substr(0,1)

         buc = buc.toUpperCase()

         var l = box.length

         buc += box.substr(1,l-1)

         c.alt ="Added to "+buc+ " Lightbox"

         c.src =imagedir+"added.gif"

     }

//PC Version

     checkwin(box)

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

   } 

   window.focus()

}

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

function chkbut(){

// Copyright Keith Robinson ccaakwr@ucl.ac.uk

var x = 1

if (x==1) {

   } else {

// get list of boxes
   var boxes=getCookie("boxes")
   if (diag==1){
      alert("chkbut "+boxes)
   }
   if (!boxes) {
   } else {

   var bo = boxes.split("#")

   l = bo.length   

   bo[l]="discards"

   var sets = new Array()

   var labs = new Array()

   var s = -1

   for (var i = 0;i< bo.length;i++){

// read in pictures in lightbox

      var c = getCookie(bo[i])

      if (!c) {

      } else {

         s += 1

         var p= c.split("#");

         var n = p.length;

         for (var j=0;j<n;j++){

            var pic=p[j].split("@")

            var x=pic[0].replace(/-/g,"")

// add picture to array

            if (!sets[s]) {

               sets[s] = x+"#"

               buc = bo[i].substring(0,1)

               buc = buc.toUpperCase()

               var m = bo[i].length

               buc += bo[i].substr(1,m)

               labs[s] = "Picture in "+buc +" Box"

            } else {

               sets[s] += x+"#"

            }

         }

      }

   }

   s = sets.length

   var a = document.images.length

   for (var i = 0 ;i<a;i++){

      var b = document.images[i].src

      var b1 = document.images[i].name

      var b3 = /added.gif/i

      var b4 = /addpic.jpg/i

      if (b3.test(b) || b4.test(b)){

         for (j=0;j<s;j++){

            if (sets[j].match(b1)){

               document.images[i].alt=labs[j]

               document.images[i].src=imagedir+"added.gif" 

            }

         }

      }

   }

   }

}

}

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

function removecap(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
   setCookie("savecap","no",now,"/")   
   var boxes = getCookie("boxes")
   if (diag2==1){
      alert("removecap "+boxes)
   }
   var bo = boxes.split("#")

   var l = bo.length

   for (i=0;i < l;i++){

      var box = bo[i]

      var c = getCookie(box)

      var newc = ""

      sep =""

      if (!c) {

         alert("No Pictures in "+box+" Lightbox")

      } else {

// split into pictures

         var p= c.split("#");

// sort p 

         p.sort()

         var n = p.length;

         for(var j=0; j < p.length; j++) {

            var q=p[j].split("@")

// check for missing thumbnail

            if (q[1]=="x"){

               newc += sep+p[j]

               sep = "#"

            } else {

// check for thumbnail size

               var nq = q.length

               newp = q[0]+"@"

// replace caption by a single blank

               q[nq-1]=" "

               for ( var jp = 1; jp < nq;jp++){

                  newp += q[jp]+"@"

               }

               newc += sep + newp

               sep = "#"

            }   

         }

         var msg = box +"\nbefore \n"+c

         msg += "\nafter \n"+newc

         setCookie(box,newc,now,"/")

      } 

   }

}

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

function MM_swapImage2() { //v3.0
   var i,j=0,x,a=MM_swapImage2.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;
         }
         if (x.src.match("added.gif")) {
         } else {
            x.src=a[i+2];
         }
      }
   }
}
function MM_swapImgRestore2() { //v3.0
   var i,x,a=document.MM_sr; 
   for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) {
      if (x.src.match("added.gif")) {
      } else {
         x.src=x.oSrc;
      }
   }
}
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_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_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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 empty_box(box){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
   var quest = "Click OK to empty the lightbox. All the "
   quest += "pictures will be removed. Click Cancel to stop this operation"
   if(confirm(quest)){
      if (box == "discards") {
         setCookie(box,"",now,"/");
//         checkwin("boxman")
//         checkwin(box)
         checkwinlr("right")
      } else {
         quest = "You have the choice of moving all the pictures to "
         quest += "the Discards Lightbox or throwing the selection away."
         quest += "Click OK to move all the pictures to the "
         quest += "Discards Lighbox. Click Cancel for NO - I want "
         quest += "to throw away this selection."
         if(confirm(quest)){
            var saw = getCookie(box);
            var p= saw.split("#");
            var n = p.length;
            var saw2 ="";  
            var gap = "";
// discards is list of pictures in lightbox
            var t=getCookie("discards");
            if (!t) {
               t=""
               var sep=""
            } else {
               var sep="#";
            }
            for(var i=0; i < n; i++) {
// need to check if mypic already in list
               if (t.match(p[i])) {
               } else {
                  t += sep+p[i]
                  sep="#"
               }
            }
            setCookie("discards",t,now,"/")
            setCookie(box,"",now,"/");
// PC Version
            checkwin("discards")
            checkwin("boxman")
            makewin3(box)
         } else {
            setCookie(box,"",now,"/");
            checkwin("boxman")
            checkwin(box)
         }
          checkwinlr("left")
      }
   }
}
//------------------------------------------------------------------------
function deletebox(bb){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// new version fo non popup
// only one window so no need to worry about it being open else where
//   var c =getCookie("boxmanhan")
   var box = bb
//   var b = box + "han"
//   var c = getCookie(b)
//   if (c == "yes") {
//   } 
// window closed - ok to carry on
      var quest = "Click OK to delete the lightbox. All the "
      quest += "pictures will be removed and the lightbox removed from "
      quest += "your set of lightboxes. Click Cancel to stop this "
      quest += "operation and keep the lightbox."
      if(confirm(quest)){
// Check if there are any pictures
         var c = getCookie(box)
         if (!c) {
// No pictures to worry about so box can just be deleted
        } else {
            quest = "You have the choice of moving all the pictures to "
            quest += "the Discards Lightbox or throwing the selection away. "
            quest += "Click OK to move all the pictures to the "
            quest += "Discards Lighbox. Click Cancel for NO - I want "
            quest += "to throw away this selection."
            if(confirm(quest)){
               var saw = getCookie(box);
               var p= saw.split("#");
               var n = p.length;
               var saw2 ="";  
               var gap = "";
// discards is list of pictures in lightbox
               var t=getCookie("discards");
               if (!t) {
                  t=""
                  var sep=""
               } else {
                  var sep="#";
               }
               for(var i=0; i < n; i++) {
// need to check if mypic already in list
                  if (t.match(p[i])) {
                  } else {
                     t += sep+p[i]
                     sep="#"
                  }
               }
               setCookie("discards",t,now,"/")
               checkwin("discards")
               setCookie(box,"",now,"/");
            } else {
               setCookie(box,"",now,"/");
            }
         }
         deleteCookie(box,"/")
         var active = getCookie("box")
         if (active == box) {
            alert("Active Lightbox is now Main")
            setCookie("box","main",now,"/")
            makebox2()
         }
         var boxes = getCookie("boxes")
         if (diag2==1){
            alert("deletebox "+boxes)
         }
         var bo = boxes.split("#")
         var l = bo.length
         var sep = ""
         boxes = ""
         for (i=0;i < l;i++){
            if (bo[i] == box) {
            } else {
               boxes += sep+bo[i];
               sep="#"
            }
         }
         setCookie("boxes",boxes,now,"/");
         resetwin("boxman")
      }
// refresh right and lefthand pains
   var rhs =getCookie("mainrhs")
   if (diag2==1){
      alert(rhs)
   }
// new righthand side if rhs not set to polarsearch
// set it to main
   if (rhs != "polarsearch"){
      makewin2(rhs)
   }
}
// end of deletebox
//---------------------------------------------------------------
function request(b){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
   box = b
   setCookie("requestpics",box,now,"/")
   var a=window.open(jsdir+"request.htm")
}
//---------------------------------------------------------------
function qwikstart(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
   var keywords=document.qwikstart.keywords.value
   setCookie("keywords",keywords,now,"/")
   deleteCookie("firsttimer")
// which type, always use 1
   setCookie("type","type1",now,"/")
// use correct platform
//   var plat= navigator.platform;
//   var mac= (plat=="MacPPC")
//   if (mac || Nav) {
      a=window.open("/qindex.htm","_self")
//   } else {
//     a=window.open("/qindex2n.htm","_self")
//   } 
}
//----------------------------------------------------------
function qwikstart2(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
   var keywords=document.gallery.keywords.value
   setCookie("keywords",keywords,now,"/")
   deleteCookie("firsttimer")
   var backgal=document.gallery.backgal.value
   setCookie("backgal",backgal,now,"/")
   var type=document.gallery.type.value
   if (!type) {
      setCookie("type","type1",now,"/")
   } else {
      setCookie("type",type,now,"/")
   }
// use correct platform
//   var plat= navigator.platform;
//   var mac= (plat=="MacPPC")
//    if (mac || Nav) {
      a=window.open("/qindex.htm","_self")
//   } else {
//     a=window.open("/qindex2n.htm","_self")
//   } 
}
//---------------------------------------------------------------
function qwikstart3(keywrd){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// used by keyword pages
keywrd="\""+keywrd+"\""
   setCookie("keywords",keywrd,now,"/")
   deleteCookie("firsttimer")
   setCookie("type","type1",now,"/")
      a=window.open("/qindex.htm","_self")
}

//----------------------------------------------------------
function addkey(S) {
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
   var i = S.options.length
   for (var i = 0 ; i < S.options.length; i++){
      if ( S.options[i].selected){
         var b =  S.options[i].value
      }
   }
   if (b != S.options[0].value) {
      var a = document.form1.keywords.value
      l = a.length
      if (a.match(b)){
         alert ("All ready there")
      } else {
         if (b.match(" ")){
            b = "\""+b+"\""
         }
         if (l==0) {
            a = b
         } else {
            a = a+" "+b
         }
         document.form1.keywords.value=a
      }
   }
}
//--------------------------------------------------------------------
function addback2gal(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// get back gallery cookie
   var backgal=getCookie("backgal")
   if (!backgal) {
      var s = ""
   } else {
      var s = "<center><p><a href=../new3/search//%22/%22+backgal+%22/%22 target=\"_top\">Back to Galleries</a></p></center>\n"
      document.writeln(s)
   }
}
//--------------------------------------------------------------------
function nextpreview(nxpic){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
   document.nextprev.nextpic.value=nxpic
   document.nextprev.submit()
}
//--------------------------------------------------------------------
function nextgroup(grp){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
   document.nextset.nextgrp.value=grp
   document.nextset.submit()
}
//--------------------------------------------------------------------
function showkeywords(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
   document.showkeywords.submit()
}
//--------------------------------------------------------------------
function startsearch(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
   document.dosearch.submit()
}
//-----------------------------------------------------------------------------------------
function checkEnter(e){ //e is event object passed from function invocation
   var characterCode //literal character code will be stored in this variable

   if(e && e.which){ //if which property of event object is supported (NN4)
      e = e
      characterCode = e.which //character code is contained in NN4's which property
   } else {
      e = event
      characterCode = e.keyCode //character code is contained in IE's keyCode property
   }
   if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
      document.dosearch.submit() //submit the form
      return false 
   } else {
      return true 
   }
}
//--------------------------------------------------------------------
function refreshgal(){
// Modified 19-6-2005 so boxes is only found once
   var boxes = getCookie("boxes")
   if (diag==1){
      alert("refreshgal "+boxes)
   }
   if (!boxes){
      newuser()
      boxes="main";
   }
   var bo = boxes.split("#")
   var l = bo.length
   var numimages=document.images.length
   for (var i=0; i < numimages;i++){
      var n = document.images[i].name
      var m = n.charAt(0)
      if (m=="a"){
         var match=""
         for (ii=0;ii < l;ii++){
            var box = bo[ii]
            var c = getCookie(box)
            if (!c) { 
            } else {
// split into pictures
               var p= c.split("#");
               for(var j=0; j < p.length; j++) {
                  var q=p[j].split("@")
// check if mypic in list of images
                  if ("a"+q[0] == n){
                     var buc = box.substr(0,1)
                     buc = buc.toUpperCase()
                     var l2 = box.length
                     buc += box.substr(1,l2-1)
                     match=buc
                     document.images[i].src="/eddy/images/added.gif"
                     document.images[i].alt="Added to "+match
                  }
               }
            }
         }
      }
   }
}
//------------------------------------------------------------------------------
function updatesel2(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// read in boxes and split into seperate items
//var a = document.cookie
   var   boxes=getCookie("boxes");
   if (diag2==1){ 
   alert("updatesel2 "+boxes)
   }
   var   box=getCookie("box");
   var bo = boxes.split("#")
   var l = bo.length
//top.frames[0].light.D1.options.length=0
//document.light.D1.options.length=0
   for (i=0;i < l;i++){
      if (bo[i]==box){
         var s = i;
      }
// adding selected box
//   top.frames[0].light.D1.options[i] = new Option(bo[i],bo[i]);
//   document.light.D1.options[i] = new Option(bo[i],bo[i]);
      light.D1.options[i] = new Option(bo[i],bo[i]);
   }
//document.light.D1.options[s].selected=true
   light.D1.options[s].selected=true
   var   box = getCookie("box");
   if (!box) {
      alert ("Lightbox not set")
      box="main"
   } 
   var buc = box.substring(0,1)
   buc = buc.toUpperCase()
   var l = box.length
   buc += box.substring(1,l)
//      top.frames[0].light.openbox.value="Open "+buc+" Lightbox"
}
//------------------------------------------------------------------------------
function lastsearch(){
var ls = getCookie("lasttime")
   setCookie("mainrhs","polarsearch",now,"/")
   top.frames[1].location=ls
}
//------------------------------------------------------------------------------
function lastset(){
var ls = getCookie("lastsg")
   win2=window.open(ls,"_top")
}
//------------------------------------------------------------------------------
function makebox2(){
// Copyright Keith Robinson ccaakwr@ucl.ac.uk
// Use perl to make left hand frame
   box = getCookie("box");
   if (!box) {
// maybe newuser
      newuser()
      alert ("Lightbox not set")
      box = "main"
   }
   if (diag2==1){
      alert("makebox2 "+ box)
   }
   document.light.action="http://www.arcticphoto2.co.uk/cgi-bin/search3/makebox.pl"
   document.light.target = "left"
   document.light.thisbox.value=box
   document.light.submit()
}
//------------------------------------------------------------------------------
function autopanel(){
   var rhs =getCookie("mainrhs")
   var autoleftright=getCookie("autoleftright")
   setCookie("autoleftright","ok",now,'/')
   if (autoleftright=="right"){
      if (rhs != "polarsearch"){
         makewin2(rhs)
      }
   } else if(autoleftright=="left") {
       makebox2()
   }
}
//------------------------------------------------------------------------------
function gohome(){
// replaces use of home.htm to change to welcome screen
// not needed any more as we only have one home page
//var w = getCookie("welcome")
//if (!w) {
//   var n = (Math.round((Math.random()*21)+0))
//} else {
//   var n = w
//}
//s += n+"/index.htm"
s = "http://www.arcticphoto2.co.uk/eddy/index.htm"
win2=window.open(s,"_top")
}
//------------------------------------------------------------------------------
function menuFix() {
   var sfEls = document.getElementById("nav").getElementsByTagName("LI");
   for (var i=0; i<sfEls.length; i++) {
      sfEls[i].onmouseover=function() {
      this.className+=(this.className.length>0? " ": "") + "sfhover";
      }
      // event added to keep menu items from disappearing
      sfEls[i].onMouseDown=function() {
      this.className+=(this.className.length>0? " ": "") + "sfhover";
      }
      // event added to keep menu items from disappearing
      sfEls[i].onMouseUp=function() {
      this.className+=(this.className.length>0? " ": "") + "sfhover";
      }
      sfEls[i].onmouseout=function() {
      this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
      }
   }
}
//----------------------------------------------------------------------------------------
function sglightbx() {
var w=window.location
setCookie("lastsg",w,now,"/")
window.location="/eddy/search-sg.htm"
}
//-----------------------------------------------------------------------------------------
function sgboxman() {
var w=window.location
setCookie("lastsg",w,now,"/")
window.location="/eddy/search-sg2.htm"
}
//----------------------------------------------------------------------------------------
function returnlightbx(a) {
setCookie("showbox",a,now,"/")
var w=window.location
setCookie("lasttime",w,now,"/")
window.location="/eddy/search-lb.htm"
}
//-----------------------------------------------------------------------------------------
function newuser() {
   var boxes=getCookie("boxes")
   if (diag==1) {
      alert("new user report "+boxes)
   }
   if (!boxes) {
      alert("setting new user in polar.js")
      if (diag==1) {
        alert("New user")
     }
      boxes="main";
      setCookie("boxes",boxes,now,"/");
      setCookie("box",boxes,now,"/");
      setCookie("main","",now,"/")
      deleteCookie("main","/")
      setCookie("discards","",now,"/")
      deleteCookie("discards","/")
      var firsttimer="yes"
   } else {
      if (diag==1) {
        alert("old user")
     }
   }
}
