// ***********************************************************************
// * FILE HEADER:                                                        *
// ***********************************************************************
// * Filename:  galleries.inc                                            *
// * Owner:     Martin Francis                                           *
// * Created:   29/10/2002 (MF)                                          *
// * Revised:   08/08/2005 (MF)                                          *
// ***********************************************************************

revised =	"08/08/2005";

// Calling parameters:
// http://127.0.0.1/wireless/data/sets/?mode=thumbs&maker=drw
// http://www.classaxe.com/wireless/data/sets/?mode=thumbs&maker=drw&file=uk_drw_table_type3(1)&makername=Derwent

// ***********************************************************************
// * OBJECT LIST:                                                        *
// ***********************************************************************
//  O =		CONTRIBUTER(abr,country,location,name)
//		  Returns object with properties: {abr,country,location,name}
//
//  O =		MAKER(name)
//		  Returns object with properties: {name,abr,count}
//
//  O =		REGION(countries,name,sty,description)
//		  Returns object with properties: {[countries],name,sty,description}
//
//  O =		SPEC(sn,hwd,notes,devices,collection) {
//		  Returns object with properties: {collection,devices,hwd,notes,photoCount,sn}

// ***********************************************************************
// * FUNCTION LIST:                                                      *
// ***********************************************************************
//  Other than sort functions, functions are defined in alphabetical order.
//
//  I =		sortByMake(a,b)
//  I =		sortByModel(a,b)
//  I =		sortMakers(a,b)
//  I =		sortRegionsCount(a,b)
//
//  VOID =	begin()
//                Provides initial contents for both frames prior to processing of set list.
//                Triggers processing of set list and patience dialog by means of onLoad() event
//
//  VOID =	centerPopup(popup,width,height)
//		  Centres the given popup window for the available screensize
//
//  S =		flagChart(region)
//                Returns HTML flag chart showing numbers of sets from each region
//                shown for the specified selection criteria
//
//  VOID =	list()
//		  Updates the selection criteria based on the setting of form fields
//                Writes the HTML for the thumbnails.
//
//  S =		makerList(cols)
//                Returns HTML chart of cols columns width, listing numbers of sets
//                shown for the specified selection criteria
//
//  VOID =	thumbnails()
//		  Updates the selection criteria based on the setting of form fields
//                Writes the HTML for the thumbnails.
//

// ************************************
// * Inline code:                     *
// ************************************
isLocal = (document.URL.match(/file/)=='file');
  


// ************************************
// * Object Constructors              *
// ************************************
function CONTRIBUTER(abr,country,location,name,lbl) {
  this.abr =		abr;
  this.country =	country;
  this.location =	location;
  this.name =		name;
  this.lbl =		lbl;
}

function MAKER(name) {
  this.name =		name;
  this.abr =		"";
  this.count =		0;
}

function REGION(countries,name,sty,description) {
  this.countries =	countries.split(",");
  this.name =		name;
  this.sty =		sty;
  this.description =	description;
  this.count =		0;
}

function OPTION(text,value,css) {
  this.text =		text;
  this.value =		value;
  this.css =		css;
}

function SET(file) {
  this.file =		file;
  this.country =	file.substr(0,2);
  this.maker =		maker[file.substr(3,3)].name;
  this.name =		file.substr(7).toUpperCase().replace(/_/g," ");
  this.photoCount =	0;
}

function SPEC(sn,hwd,notes,devices,collection) {
  this.collection =	collection;
  this.devices =	devices;
  this.hwd =		hwd;
  this.notes =		notes;
  this.photoCount =	0;
  this.sn =		sn;
}




// ************************************
// * General functions                *
// ************************************
function round(what) {
  return Math.round(20*what)/20;
}



// ************************************
// * Sort Functions                   *
// ************************************
// Since list arrives sorted by region, don't bother to do it again.
function sortByMake(a,b) {
  var anew =	((maker[a.substr(3,3)]) ? (maker[a.substr(3,3)].name + a.substr(6)): (a.substr(3)));
  var bnew =	((maker[b.substr(3,3)]) ? (maker[b.substr(3,3)].name + b.substr(6)): (b.substr(3)));
  if (anew < bnew) return -1;
  if (anew > bnew) return 1;
  return 0;
}

function sortByModel(a,b) {
  var anew = a.substr(6);
  var bnew = b.substr(6);
  if (anew < bnew) return -1;
  if (anew > bnew) return 1;
  return 0;
}

function sortMakers(a,b) {
  var anew = a.name;
  var bnew = b.name
  if (anew < bnew) return -1;
  if (anew > bnew) return 1;
  return 0;
}

function sortRegionsCount(a,b) {
  var anew = a.count;
  var bnew = b.count
  if (anew > bnew) return -1;
  if (anew < bnew) return 1;
  return 0;
}



// ************************************
// * begin()                          *
// ************************************
function begin() {
  var out =	 writeHead()
		+"<body background='../images/wallpaper.gif'>\n"
		+"<big><b><u>Worldwide Vintage Wireless Gallery</u> - &copy;"
		+" <a href='mailto:martin@classaxe.com?subject=Radio%20Gallery'>Martin Francis</a> "+revised+"</b></big><br>\n"
		+"This system uses <b>'Popup' windows</b> to display data. If this text is still visible "
		+"after loading, disable any Advert blocking software you may be running for this site, and try again.</b>"
		+"</body></html>\n";
  top.title.document.write(out);
  top.title.document.close();

  var out =	 "<html>\n<head>\n"
		+"<style>\n body { font-family: Arial, sans-serif;border: 1; margin: 5;}\n</style>\n</head>\n\n"
		+"<body background='../images/wallpaper.gif' onLoad='top.patience(\"Building menus...<br>Please wait\")'>"
		+"<h3><u>Help</u></h3>"
		+"<p><ul>"
		+"<li><p align='justify'><b><u>Results Area</u></b><br>"
		+"Make your selection then click on the 'Go' button above - no, <b><i>not</i></b> the one on the browser, the one in the Worldwide Vintage Wireless Gallery selection area above (you may need to scroll right to see this).</p></li>"
		+"<li><p align='justify'><b><u>Contributing photographs or data to this gallery</u>:</b><br>"
		+"This has never been easier - click <a href='../articles/contributing/' target='_blank'><b>here</b></a> for details on what is needed.</p></li>"

		+"<li><p align='justify'><b><u>Advanced URL Parameter Options</u>: <font color='#ff0000'>(Does not work from CD version of the site)</font></b><br>"
		+"You can preset all aspects of this gallery by including extra parameters in the "
		+"URL that you use to call it with.</p>"
		+"<p align='justify'>If you have submitted sets in your collection to this gallery, you might like to provide quick links from your own "
		+"site or by means of links in an email message to enable visitors to see all of your featured sets at a glance.</p>"
		+"<p align='justify'>Move your mouse over each link in turn and see the URLs shown at the bottom of the browser to see how each link is defined.</p>\n"
		+"<p><b>Examples of Preset Options:</b><ul><b>"
		+"<li><a href='./?mode=thumbs&maker=mur&region=uk&collection=mf' target='_blank'>Thumbs > Murphy > UK > Collection MF</a></li>"
		+"<li><a href='./?mode=details&region=de' target='_blank'>Details > All Makers > Germany > All Collections</a></li>"
		+"<li><a href='./?mode=list&maker=mar&collection=ay' target='_blank'>List > Marconi > All Regions > Collection AY</a></li>"
		+"<li><a href='./?mode=names' target='_blank'>Names > All Makers > All Regions > All Collections</a></li>"
		+"</b></ul></p>\n"
		+"<p>You can also make a window popup immediately:<ul>"
		+"<li><b><a href='./?mode=thumbs&collection=mf&image=uk_gwl_ad65_copy' target='_blank'>Thumbs > All Makers > All Regions > Collection MF</a></b> (With featured set in popup window)</li>"
		+"</b></ul></p></li></ul></p>\n"
		+"</body></html>\n";
  top.main.document.write(out);
  top.main.document.close();
}


// ************************************
// * centerPopup()                    *
// ************************************
function centerPopup(popup,width,height) {
  if (popup.screen){
    var x = (screen.availWidth-width)/2;
    var y = (screen.availHeight-height)/2;
    popup.moveTo(x,y);
  }
}


// ************************************
// * flagChart()                      *
// ************************************
function flagChart(region) {
  var out=new Array(); var n=0;
  out[n++] =	 "    <table border='1' cellspacing='0' cellpadding='1' bgcolor='#ffffff' width='140'>\n"
		+"      <tr>\n"
		+"        <th><b>Countries<b></th>\n"
		+"      </tr>\n";
  var regionList = new Array(),j=0;
  for (i in regions) {
    if (regions[i].count>0) {
      regionList[j++]=regions[i];
    }
  }
  regionList.sort(sortRegionsCount)
  for (var i=0;i<regionList.length;i++) {
    out[n++] =	 "      <tr>\n"
		+"        <td><table cellpadding='0' cellspacing='0' border='0' width='100%'>\n"
		+"          <tr>\n"
		+"            <td align='baseline'><img src='../images/flag_"+regionList[i].countries[0]+".gif' border='1'>"
		+"<img src='../images/spacer.gif' width='10'>"
		+regionList[i].name+"</td>\n"
		+"            <td align='right'><b><i>"+regionList[i].count+"</i></b></td>\n"
		+"          </tr>\n"
		+"        </table></td>\n"
		+"      </tr>\n"
  }
  out[n++]	= "    </table>\n";
  return out.join("");
}


// ************************************
// * list()                           *
// ************************************
function list() {
  var collection =	top.title.document.form.collection.options[top.title.document.form.collection.selectedIndex].value;
  var from =		top.title.document.form.region.options[top.title.document.form.region.selectedIndex].value;
  var make =		top.title.document.form.make.options[top.title.document.form.make.selectedIndex].value;
  var order =		top.title.document.form.order.options[top.title.document.form.order.selectedIndex].value;
  photoCount =		update(from,make,order,collection);
  var title =	"List > "+maker[make].name+" > "+regions[from].description+" > "
		+((collection=="all")?("All Collections"):("Collection "+collection.toUpperCase()));

  var out =	new Array;
  var n =	0;
  out[n++] =	 "<html>\n<head>\n<title>"+title+"</title>\n"
		+"<style>\n body { font-family: Arial, sans-serif;font-size: 8pt; border: 0; margin: 5;}\n"
		+" td       { font-family: Arial; font-size: 8pt; }\n"
		+" th	{ font-family: Arial; font-size: 10pt; background-color: rgb(255,255,220); text-align: left; }"
		+"</style>\n<\/head>\n\n"
		+"<body background='../images/wallpaper.gif'>"
		+"<h3><u>"+title+"</u><br>\n";

  if (!photoCount) {
    out[n++] =	"</u><br><small><i>No sets matched.</i></small></h3>\n</body></html>\n";
  }
  else {
    out[n++] =	 "<small><i>"+photoCount+" photograph"+((photoCount>1)?("s"):(""))
		+" of "+setList.length+" set"+((setList.length>1)?("s"):(""))+"</i></small></h3>"
		+"<table cellspacing='0' cellpadding='0'>\n"
		+"  <tr>\n"
		+"    <td valign='top' width='100%' bgcolor='#ffffff'>"+makerList(5)+"</td>\n"
		+"    <td><img src='../images/spacer.gif' width='10'></td>\n"
		+"    <td valign='top'>\n"+flagChart(from)+"</td>\n"
		+"  </tr>\n"
		+"</table>\n"
		+"<img src='../images/spacer.gif' height='10'>\n"
		+"<table border='1' cellpadding='0' cellspacing='0' width='100%'>\n"
		+"<tr>\n"
		+"<td><table border='0' cellspacing='0' cellpadding='1' bgcolor='#ffffff' width='100%'>\n";

    var row =	3;  // Number of sets to place on each row
    var filesPerRow=Math.ceil(setList.length/row);

    for (var i=0;i<filesPerRow;i++){
      out[n++] =	"<tr>\n";
      for (var j=0;j<row;j++) {
        var setList_set=setList[i+(j*filesPerRow)];
        if (setList_set!=null) {
          out[n++] =	"<td width='33%'><nobr><img src='../images/flag_"
          out[n++] =	setList_set.country+".gif' border='1' alt='"+regions[setList_set.country].name+"'> ";
          if (setList_set.photoCount==1) {
            out[n++] =	"<a href='javascript:top.popup(\""+setList_set.file+"\")'>";
            out[n++] =	setList_set.maker+" "+setList_set.name+"</a>";
          }
          else {
            out[n++] =	"<a href='javascript:top.popup(\""+setList_set.file+"(1)\")'>";
            out[n++] =	setList_set.maker+" "+setList_set.name+"</a>";
            for (var pic=1; pic<setList_set.photoCount; pic++) {
              out[n++] =	" <a href='javascript:top.popup(\""+setList_set.file+"("+(1+pic)+")\")'>";
              out[n++] =	"<i>("+(1+pic)+")</i></a>";
            }
          }
          out[n++] =	"</nobr></td>"
        }
       else
         out[n++] =	"<td>&nbsp;</td>";
      }
      out[n++] =	"</tr>\n";
    }
    out[n++] =	 "</table></td></tr></table>"
		+"Unless otherwise stated, all images Copyright &copy; <a href='mailto:martin@classaxe.com'>"
		+"Martin Francis</a> 2001, 2002, 2003, 2004, 2005</body></html>";
  }
  top.main.document.open();
  top.main.document.write(out.join(""));
  top.main.document.close();
}



// ************************************
// * makerList()                      *
// ************************************
function makerList(cols) {
  for (n in maker)    { maker[n].count = 0; }			// Zero counts for each maker
  for (n in regions)  { regions[n].count = 0; }			// Zero counts for each region
  for (var n=0;n<setList.length;n++) {				// Get maker abr from each file
    var makerAbr = (setList[n].file).substr(3,3);			// Extract maker code from filename
    if (! maker[makerAbr])					// If new maker...
      maker[makerAbr] = new MAKER(makerAbr.toUpperCase()+" (Check Code)");// ...add new object to maker array
    maker[makerAbr].count++ ;					// Increment sets count for the maker
    regions[(setList[n].file).substr(0,2)].count++ ; 		// Increment regions count for the maker
  }
  var makerList = new Array(); var n=0;
  for (x in maker) {						// Loop through maker objects
    if (maker[x].count > 0) {					// If maker is represented...
      makerList[n++] =	"    <td width='"+100/cols+"%'>"+	// Create a new entry for it in the list
			"<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n"+
			"      <tr>\n"+
			"        <td>"+maker[x].name+"</td>\n"+
			"        <td align='right'><i><b>"+maker[x].count+"</b></i></td>\n"+
			"      </tr>"+
			"    </table>\n"+
			"  </tr>\n";
    }
  }
  makerList.sort();
  var out=new Array() ; var n=0;				// Initialised an array to hold output for list
  out[n++] = "<table border='1' cellspacing='0' cellpadding='1' bgcolor='#ffffff' width='100%'>";
  out[n++] = "  <tr>\n    <th colspan='"+(cols)+"'>Makers: ("+makerList.length+" represented)</th>\  </tr>\n";
  var makersPerRow = Math.ceil(makerList.length/cols);		// Calculate number of makers per column, based on width in rows.
  for (var i=0;i<makersPerRow;i++) {				// Loop through rows
    out[n++] = "  <tr>\n";					// Write row header
    for (var j=0;j<cols;j++) {					// Loop through columns
      out[n++]=makerList[i+(j*makersPerRow)];			// Select correct list entry and write it
    }
    out[n++] = "  </tr>\n";					// Close row
  }
  out[n++] = "</table>\n";
  return out.join("");						// Return output to callee
}


// ************************************
// * names()                          *
// ************************************
function names() {
  var collection =	top.title.document.form.collection.options[top.title.document.form.collection.selectedIndex].value;
  var from =	top.title.document.form.region.options[top.title.document.form.region.selectedIndex].value;
  var make =	top.title.document.form.make.options[top.title.document.form.make.selectedIndex].value;
  var order =	top.title.document.form.order.options[top.title.document.form.order.selectedIndex].value;
  photoCount =	update(from,make,order,collection);
  var title =	"Names > "+maker[make].name+" > "+regions[from].description+" > "
		+((collection=="all")?("All Collections"):("Collection "+collection.toUpperCase()));

  var out =		new Array();
  var n =		0;

  out[n++] =	 "<html>\n<head>\n<title>"+title+"</title>\n"
		+"<style>\n body { font-family: Arial, sans-serif;font-size: 8pt; border: 0; margin: 5;}\n"
		+" td       { font-family: Arial; font-size: 8pt; }\n"
		+" th	{ font-family: Arial; font-size: 10pt; background-color: rgb(255,255,220); text-align: left; }"
		+"</style>\n</head>\n\n"
		+"<body background='../images/wallpaper.gif'>"
		+"<h3><u>"+title+"</u></h3><br>\n";


  if (!photoCount) {
    out[n++] =	"<br><small><i>No sets matched.</i></small></h3>\n</body></html>\n";
  }
  else {
    temp_makerList =	new Array();
    makerCount =	0;
    out[n++] =		"<ul>\n";
    for (var i=0; i<setList.length; i++) {
      if (!temp_makerList[setList[i].maker]) {
        temp_makerList[setList[i].maker]=true;
        makerCount++;
      }
      out[n++] =	 "<li>"+setList[i].maker+" "+setList[i].name+" ("+regions[setList[i].country].name+") - "
      			+setList[i].photoCount+" photo"+((setList[i].photoCount>1)?("s"):(""))+"</li>\n";
    }
    out[n++] =		 "</ul><h3>(" + photoCount + " photos of " + setList.length + " sets by " + makerCount+" makers)</h3>\n"
			+"</body></html>";
  }
  top.main.document.open();
  top.main.document.write(out.join(""));
  top.main.document.close();
}


// ************************************
// * thumbnails()                     *
// ************************************
function thumbnails() {
  var collection =	top.title.document.form.collection.options[top.title.document.form.collection.selectedIndex].value;
  var from=top.title.document.form.region.options[top.title.document.form.region.selectedIndex].value;
  var make=top.title.document.form.make.options[top.title.document.form.make.selectedIndex].value;
  var order=top.title.document.form.order.options[top.title.document.form.order.selectedIndex].value;
  status="";
  if ((make=='...')&&(from=='all')&&(collection=='all')&&(totalNum>100)) {
    if (confirm("WARNING\nthere are "+totalNum+ " photos in this category -\ndo you really want to see them all?")) {
      alert('TIP\nIf your connection is slow and your web browser gives up half way\nthrough (marking the remaining images as "broken", try refreshing -\nyou will not lose the images you already loaded but should gain\nthose that were not.\n\nAnd please be patient!');
      var photoCount = update(from,make,order,collection);
    }
    else {
      alert("Operation cancelled - very wise!");
      setList="";
      status = "<br>\n(Operation was cancelled)";
    }
  }
  else {
    photoCount = update(from,make,order,collection);
  }

  var title =	"Thumbs > "+maker[make].name+" > "+regions[from].description+" > "
		+((collection=="all")?("All Collections"):("Collection "+collection.toUpperCase()));


  var out =new Array; var n=0;
  out[n++] =	"<html>\n<head>\n<title>"+title+"</title>\n"
		+"<style>\n body { font-family: Arial, sans-serif;font-size: 8pt; border: 0; margin: 5;}\n"
		+" a.noline { text-decoration: none; }\n"
		+" td   { font-family: Arial; font-size: 8pt; }\n"
		+" th	{ font-family: Arial; font-size: 10pt; background-color: rgb(255,255,220); text-align: left; }"
		+"</style>\n<\/head>\n\n"
		+"<body background='../images/wallpaper.gif'>"
		+"<h3><u>"+title+"</u><br>\n";

  if (!photoCount) {
    out[n++]="<small><i>No sets listed"+status+".</i></small></h3>\n";
    out[n++]="</body></html>\n";
  }
  else {
    var row=6;  // Number of diagrams to place on each row
    out[n++] =	 "Click on any photo to view details.<br>\n"
		+"<small><i>Total Photographs: "+photoCount+"</i></small></u></h3>\n"
		+"<table cellspacing='0' cellpadding='0'>\n"
		+"  <tr>\n"
		+"    <td valign='top' width='100%' bgcolor='#ffffff'>"+makerList(5)+"</td>\n"
		+"    <td><img src='../images/spacer.gif' width='10'></td>\n"
		+"    <td valign='top'>\n"+flagChart(from)+"\n    </td>\n"
		+"  </tr>\n"
		+"</table>\n"
		+"<img src='../images/spacer.gif' height='10'>\n"
		+"<table border='1' cellspacing='0' cellpadding='0' bgcolor='#ffffdd'>\n";
    
    for (var i=0; i<(setList.length/row); i++) {
      out[n++]="  <tr>\n";
      for (var j=0;j<row;j++) {
        if(((i*row)+j)<setList.length) {
          var set = setList[(i*row)+j];

          var filename	= "<img src='../images/flag_"+set.country+".gif' border='1' "+
              		  "alt='"+regions[set.country].name+"'> "+
                          set.maker+"<br>\n"+set.name;

          out[n++] =	 "    <td align='center' valign='top' width='"+100/row+"%'>"
			+"<a href='javascript:top.popup(\""+set.file
			+((set.photoCount>1)?("(1)"):(""))+"\")'>"
			+"<img src='../sets_thm/"+set.file
			+((set.photoCount>1)?("(1)"):(""))
			+".jpg' name='"+set.file.replace(/\-/ig,"_")+"' border='1'></a><br>\n"
			+filename+" ";

          for (var k=0; k<set.photoCount; k++) {
            var corrected = set.file.replace(/\-/ig,"_");
            out[n++] =	((set.photoCount>1)?
			 ( "<script language='javascript' type='text/javascript'>"
			  +"img_"+corrected+"_"+(1+k)+" = new Image();\n"
			  +"img_"+corrected+"_"+(1+k)+".src=\"../sets_thm/"+set.file+"("+(1+k)+").jpg\";"
			  +"</script>"
			  +"<a class='noline' href='javascript:top.popup(\""+set.file
			  +((set.photoCount>1)?("("+(1+k)+")"):(""))+"\")' "
			  +"onmouseover='document."+corrected+".src=img_"+corrected+"_"+(1+k)+".src;return true;' "
			  +"onmouseout='document."+corrected+".src=img_"+corrected+"_1.src;return true;'>\n"
			  +"[<b>"+(1+k)+"</b>]</a>"):("")
			  +"")
          }           
          out[n++] =	"</td>\n";
        }
        else {
          out[n++] =	"    <td>&nbsp;</td>\n";
        }
      }
      out[n++] =	"  </tr>\n";
    }
    out[n++] =	 "</table>\n"
		+"<small><i>Total Photographs: "+files.length+"</i></small><br>Unless otherwise stated, all images Copyright &copy; <a href='mailto:martin@classaxe.com'>"
		+"Martin Francis</a> 2001, 2002, 2003, 2004, 2005</body></html>";
  }
  top.main.document.open();
  top.main.document.write(out.join(""));
  top.main.document.close();
}



// ************************************
// * writeHead()                      *
// ************************************
function writeHead() {
  out =	 "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\">"
	+"<html>\n<head>\n"
	+"<META http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252 (Western Europe)\">"
	+"<title>Worldwide Vintage Wireless Gallery</title>\n"
	+"<style>\n body { font-family: Arial, sans-serif;font-size: 10pt; border: 1; margin: 5;}\n"
	+" h1       { font-family: Arial; font-size: 16pt; }\n"
	+" option.a { font-family: courier; background-color: rgb(200,255,200);}\n"
	+" option.b { font-family: courier; background-color: rgb(255,255,200);}\n"
	+" option.c { font-family: courier; background-color: rgb(200,255,255);}\n"
	+" option.d { font-family: courier; background-color: rgb(255,200,200);}\n"
	+" option.x { font-family: courier; background-color: rgb(200,200,200);}\n"
	+" select   { font-family: courier; font-size: 8pt;}\n"
	+" input.a  { font-size: 8pt; font-weight: bold;background-color: rgb(204,204,204); width: 60px;}\n"
	+"</style>\n</head>\n\n"
  return out;
}



// ************************************
// * patience()                       *
// ************************************
function patience(msg) {
  var x=200, y=40;
  PleaseWait=window.open('','PleaseWait', 'width='+x+',height='+y+',resizable=0,scrollbars=0,menubar=0,location=0,toolbar=0,closebutton=0');
  var out =	new Array;
  var n =	0;
  out[n++] =	 writeHead()
		+"<body background='../images/wallpaper.gif'>\n"
		+"<table height='100%' width='100%' cellpadding='0' cellspacing='0' border='0'>\n"
		+"<tr><td height='34%' valign='top'><big><u>Radio Gallery</u></big></td></tr>\n"
		+"<tr><td height='33%' ><i>"+msg+"</i></td></tr>\n"
		+"<tr><td  height='33%' align='center'><img src='../images/progress.gif' height='10' width='140' border='1' bordercolor='black'></td></tr>\n"
		+"</table></body></html>\n";

  PleaseWait.focus();PleaseWait.document.write(out.join(""));PleaseWait.document.close();
  setTimeout("top.initialise()",250);
}
  

// ************************************
// * initialise()                     *
// ************************************
function initialise() {
// 1) Read entire list
// 2) Add any new makers if required, keeping count of each set made
// 3) Effectively delete any maker with no sets

// Detect mode:
  if (!document.URL.match(/mode=/i)) {
    var load_mode='';
  }
  else {
    var load_mode=document.URL.match(/mode\=[a-zA-Z]+/i)[0].replace(/mode\=/i,"");
  }

// Detect maker:
  if (!document.URL.match(/maker/i)) {
    var load_maker='';
  }
  else {
    var load_maker=document.URL.match(/maker\=[a-zA-Z]+/i)[0].replace(/maker\=/i,"").toLowerCase();
  }

// Detect region:
  if (!document.URL.match(/region/i)) {
    var load_region='';
  }
  else {
    var load_region=document.URL.match(/region\=[a-zA-Z]+/i)[0].replace(/region\=/i,"").toLowerCase();
  }

// Detect Collection:
  if (!document.URL.match(/collection=/i)) {
    var load_collection='';
  }
  else {
    var load_collection=document.URL.match(/collection\=[a-zA-Z0-9]+/i)[0].replace(/collection\=/i,"").toLowerCase();
  }

// Detect Image:
  if (!document.URL.match(/image=/i)) {
    var load_image='';
  }
  else {
    var load_image=document.URL.match(/image\=[a-zA-Z0-9\_\(\)]+/i)[0].replace(/image\=/i,"").toLowerCase();
  }


  var files = items().split(',');
  for (var n=0;n<files.length;n++) {				// Get maker abr from each file
    var makerAbr = (files[n]).substr(3,3);			// Extract maker code from filename
    if (! top.maker[makerAbr])					// If new maker...
      top.maker[makerAbr] = new top.MAKER(makerAbr.toUpperCase()+" (Check Code)");// ...add new object to maker array
    top.maker[makerAbr].count++ ;					// Increment sets count for the maker
  }
  maker['...']		= new MAKER(" All Makers");
  maker['...'].abr	= "...";
  maker['...'].count	= files.length;

  totalNum		= files.length;
  var makerList	= new Array();

  var i	= 0;
  for (n in maker) {
    if (maker[n].count>0) {
      makerList[i]		= maker[n];
      makerList[i++].abr	= n;
    }
  }
  makerList.sort(sortMakers);


  var modeList = new Array();
  var i=0;
  modeList[i++] = new OPTION("Thumbs","top.thumbnails()","a");
  modeList[i++] = new OPTION("Details","top.setsDetails()","b");
  modeList[i++] = new OPTION("List","top.list()","c");
  modeList[i++] = new OPTION("Names","top.names()","d");

  var collectionList = new Array();
  for (var i=0; i<contributer.length; i++) {
    collectionList[i] = new OPTION(contributer[i].lbl,contributer[i].abr,"a");
  }

    
  var out =	new Array; var n=0;
  
  out[n++] =	 writeHead()
		+"<body background='../images/wallpaper.gif'>\n"
		+"<form name='form'><big><b><u>Worldwide Vintage Wireless Gallery</u> - &copy;"
		+" <a href='mailto:martin@classaxe.com?subject=Radio%20Gallery'>Martin Francis</a> "+revised+"</b></big><br>\n"
		+"<img src='../images/spacer.gif' height='4'><br>\n"
		+"<table cellpadding='0' cellspacing='0' border='1'>\n"
		+"  <tr>\n"
		+"    <td nowrap><table cellpadding='0' cellspacing='0' border='0' bgcolor='#c0c0c0'>\n"
		+"      <tr>\n"
		+"        <td><nobr><img src='../images/tool_left_edge.gif' width='10' height='26'></td>\n"
		+"        <td><b>Show</b>&nbsp;</td>\n"
		+"        <td><select name='mode'>\n";

  for (var i=0; i<modeList.length; i++) {
    out[n++] =	 "<option value='"+modeList[i].value+"' class='"+modeList[i].css+"'"
		+((load_mode==modeList[i].text.toLowerCase())?(" selected"):(""))
		+">"+modeList[i].text+"</option>\n";
  }

  out[n++] =     "</select></td>\n"
		+"        <td><img src='../images/spacer.gif' width='5'></td>\n"
		+"        <td><select name='make'>";

  for (var i=0;i<makerList.length;i++) {
    var spaces =	"..........................";
    var countChars =	(""+makerList[i].count).length;
    var labelChars =	(makerList[i].name).length;
    var label =		makerList[i].name + spaces.substr(countChars+labelChars)+makerList[i].count;
    out[n++] =		"          <option value='"+makerList[i].abr+"'"
    if (load_maker == makerList[i].abr) {
      out[n++] =	" selected";
    }
    if (makerList[i].abr == "...") {
      out[n++] =	" class='a'";
    }
    out[n++] =		">"+label+"</option>\n";
  }

  out[n++]=	 "        </select></td>\n"
		+"        <td><img src='../images/spacer.gif' width='5'></td>\n"
		+"        <td><select name='region'>\n";
  for (var i in regions) {
    out[n++]=	 "          <option value='"+i+"' class='"+regions[i].sty+"'"
		+((load_region==i)?(" selected"):(""))
		+">"+regions[i].name+"</option>\n";
  }

  out[n++]=	 "        </select></td>\n"
		+"        <td><img src='../images/spacer.gif' width='5'></td>\n"
		+"        <td><select name='collection'>\n";
  for (var i=0; i<collectionList.length; i++) {
    out[n++] =	 "           <option value='"+collectionList[i].value+"' class='"
		+((collectionList[i].value == "all")?("a"):("b"))
		+"'"+((load_collection==collectionList[i].value)?(" selected"):(""))
		+">"+collectionList[i].text+"</option>\n";
  }
  out[n++] =	 "</select></td>\n"
		+"        <td><img src='../images/spacer.gif' width='5'></td>\n"
		+"        <td><select name='order'>\n"
		+"          <option value='top.sortByRegion' class='a'>By Region</option>\n"
		+"          <option value='top.sortByMake' class='b'>By Maker</option>\n"
		+"          <option value='top.sortByModel' class='c'>By Model</option>\n"
		+"        </select></td>\n"
		+"        <td><img src='../images/spacer.gif' width='5'></td>\n"
		+"        <td><input type='button' onClick='eval(document.form.mode.options[document.form.mode.selectedIndex].value)' value='Go'></td>\n"
		+"        <td><img src='../images/tool_separator.gif'></td>\n"
		+"        <td><a href='javascript:if (window.print) { parent.main.window.focus(); parent.main.window.print(); }else alert(\"This browser does not directly support this.\nPlease use the print button on your browser.\");' "
		+"onmouseover='window.status=\"Print search results\";return true;' "
		+"onmouseout='window.status=\"\";return true;'>"
		+"<img name='prt' src='../images/tool_print.gif' border='0' alt='Print this form'></a>"
		+"</td>\n"
		+"        <td><img src='../images/tool_separator.gif'></td>\n"
		+"        <td><a href='../' target='_blank' "
		+"onmouseover='window.status=\"Go to the Home Page\";return true;' "
		+"onmouseout='window.status=\"\";return true;'>"
		+"<img name='home' src='../images/tool_home.gif' border='0' alt='Home Page'></a>"
		+"</td>\n"
		+"        <td><img src='../images/tool_separator.gif'></td>\n"
		+"        <td><a href='http://www.bvws.org.uk' target='_blank' "
		+"onmouseover='window.status=\"British Vintage Wireless Society Home Page\";return true;' "
		+"onmouseout='window.status=\"\";return true;'>"
		+"<img name='home' src='../images/tool_bvws.gif' border='0' alt='BVWS Home Page'></a>"
		+"        <td><img src='../images/tool_right_edge.gif'></td>\n"
		+"      </tr>\n"
		+"    </table></td>\n"
		+"  </tr>\n"
		+"</table>\n"
		+"</body>\n</html>\n";

  top.title.document.write(out.join(""));
  top.title.document.close();
  PleaseWait.close();

  if (load_mode == 'thumbs') {
    top.thumbnails();
    top.main.document.close();
  }
  if (load_mode == 'details') {
    top.setsDetails();
    top.main.document.close();
  }
  if (load_mode == 'list') {
    top.list();
    top.main.document.close();
  }
  if (load_mode == 'names') {
    top.names();
    top.main.document.close();
  }
  if (load_image!='') {
    top.popup(load_image);
    top.main.document.close();
  }
  return;
}


// ************************************
// * popup()                          *
// ************************************
function popup(file){
  file.replace(/([^\.]+)/ig,"$1");			// Strip off .jpg in case anyone didn't read the instructions properly
  var data =   	file.replace(/([^(]+).{0,}/ig,"$1");	// Strip off (n) if present as a graphic sequence ID for data
  var handle = 	file.replace(/\(|\)|\-/g,"");		// Make window handle work even if set has - in name
  var makername = maker[file.substr(3,3)].name;		// Look up maker name

  var Details =	window.open('',handle,'width=700,height=500,resizable=1,menubar=0,location=0,scrollbars=1,toolbar=0,status=1');

  var inches =	details[data].hwd.split("x");
  inches[0] =	round(inches[0]/2.54);
  inches[1] =	round(inches[1]/2.54);
  inches[2] =	round(inches[2]/2.54);
  inches =	inches.join("x");
  if (inches=="NaNxNaNxNaN") inches = "?x?x?";

  var out=new Array(); var n=0;
  out[n++] =	 "<head><title>Details for "+makername+" "+file.substr(7)+"</title>"
		+"<style>\n"
		+"  body	{ font-family: Arial; }\n"
		+"  td.a	{ font-family: Arial; font-size = 10pt; background-color: rgb(255,255,255); vertical-align: top; }\n"
		+"  td.b	{ font-family: Arial; font-size = 12pt; background-color: rgb(255,255,255); vertical-align: top; }\n"
		+"  td.tool	{ background-color: rgb(192,192,192); font-size = 10pt; }\n"
		+"  th	{ font-family: Arial; font-size: 10pt; background-color: rgb(255,255,220); text-align: left; }\n"
		+"  input.a { font-size: 8pt; font-weight: bold;background-color: rgb(204,204,204); width: 50px; }\n"
		+"</style>\n"
		+"</head>\n"
		+"<body background='../images/wallpaper.gif'>"
		+"<form><b><img src='../images/flag_"+file.substr(0,2)+".gif' border='1' alt='"+regions[file.substr(0,2)].name+"'> "+makername+" "+file.substr(7).toUpperCase()+"</b><br>"
		+"<table cellpadding='0' cellspacing='0' border='1'>\n"
		+"  <tr>\n"
		+"    <td><table cellpadding='0' cellspacing='0' border='0' bgcolor='#c0c0c0'>\n"
		+"      <tr>\n"
		+"        <td class='tool'><img src='../images/tool_left_edge.gif'></td>\n"
		+"        <td class='tool'><a href='javascript:if (window.print) { window.print(); }else alert(\"This browser does not directly support this.\nPlease use the print button on your browser.\");' onmouseover='window.status=\"Print this screen\";return true;' onmouseout='window.status=\"\";return true;'><img name='prt' src='../images/tool_print.gif' border='0' alt='Print this screen'></a></td>\n"
		+"        <td class='tool'><img src='../images/spacer.gif' width='5'></td>\n"
		+"        <td class='tool'><input type='button' name='close' value='Close' onclick='self.window.close();'></td>\n"
		+"        <td class='tool'><img src='../images/tool_right_edge.gif'></td>\n"
		+"      </tr>\n"
		+"    </table></td>\n"
		+"  </tr>\n"
		+"</table>\n"
		+"<table cellpadding='0' border='0' cellspacing='0' width='100%'>\n"
		+"  <tr>\n"
		+"    <td><table cellpadding='0' border='0' cellspacing='0'>\n"
		+"      <tr>\n"
		+"        <td><img src='../images/spacer.gif' height='5'></td>\n"
		+"      </tr>\n"
		+"    </table></td>\n"
		+"  </tr>\n"
		+"  <tr>\n"
		+"    <td width='100%'><table cellpadding='2' cellspacing='0' border='1' bordercolor='black' background='' bgcolor='#ffffff'>\n"
		+"      <tr>\n"
		+"        <th><a href='#abbreviations'>Power, Bands, Notes</a></th><th>H/W/D</th><th>Devices</th><th>Sn:</th><th><a href='#collections'>Collection</a></th>\n"
		+"      </tr>\n"
		+"      <tr>\n"
		+"        <td class='a'>"+top.details[data].notes+"&nbsp;</td>\n"
		+"        <td class='a' align='right'><nobr><font color='#208020'>"+details[data].hwd+" cm</font></nobr><br>"
		+"<nobr><font color='red'>"+inches+" in</font></nobr></td>\n"
		+"        <td class='a'>"+details[data].devices+"&nbsp;</td>\n"
		+"        <td class='a'>"+details[data].sn+"&nbsp;</td>\n"
		+"        <td class='a'>"+details[data].collection.toUpperCase()+"&nbsp;</td>\n"
		+"      </tr>\n"
		+"    </table></td>\n"
		+"  </tr>\n";

  if (details[data].photoCount>1) {
    out[n++] =	 "  <tr>\n"
		+"    <td><img src='../images/spacer.gif' height='5'></td>\n"
		+"  </tr>\n"
		+"  <tr>\n"
		+"    <td><table cellpadding='2' cellspacing='0' border='0'>\n"
		+"      <tr>\n";

    for (var i=0; i<details[data].photoCount; i++) {
      var current = (file==(data+"("+(1+i)+")"));
      out[n++] = "        <td>"
		+"<script language='javascript' type='text/javascript'>"
		+"k"+i+" = new Image(); k"+i+".src='"+data+"("+(1+i)+").jpg';\n"
		+"</script>"
		+"<a href=\"javascript:var pop=window.open('"+data+"("+(1+i)+").jpg','photo','width=600,height=400,resizable=1,menubar=0,location=0,scrollbars=1,toolbar=0,status=1')\" "
		+"onmouseover='document.picture.src=k"+i+".src; window.status=\"Open in a new window - avoids distortions with old Netscape browsers\";return true;' "
		+"onmouseout='window.status=\"\";return true;'>"
		+"<img src='../sets_thm/"+data+"("+(1+i)+").jpg' border='1' bordercolor='black' alt='Open in a new window - avoids distortions with old Netscape browsers'></a></td>\n";
    }
    out[n++] =	 "      </tr>"
		+"    </table></td>\n"
		+"  </tr>\n";
  }


  out[n++] =	 "  <tr>\n"
		+"    <td><img src='../images/spacer.gif' height='5'></td>\n"
		+"  </tr>\n"
		+"  <tr>\n"
		+"    <td><img src='"+file+".jpg' border='1' bordercolor='black' name='picture'></td>\n"
		+"  </tr>"
		+"  <tr>\n"
		+"    <td><img src='../images/spacer.gif' height='10'><hr width='50%' height='1' color='black'><img src='../images/spacer.gif' height='10'></td>\n"
		+"  </tr>\n";

  var currentContributer =	new Array();
  var cc=0;
  for (var i=0; i<contributer.length; i++) {
    if (details[data].collection.indexOf(contributer[i].abr)!=-1) {
      currentContributer[cc++] =	contributer[i];
    }
  }


  out[n++] =	 "  <tr>\n"
		+"    <td><a name='collections'></a><table cellpadding='2' cellspacing='0' border='1' bordercolor='black' background='' bgcolor='#ffffff'>\n"
		+"      <tr>\n"
		+"        <th colspan='"+ currentContributer.length+"'>Collections:</th>\n"
		+"      </tr>\n"
		+"      <tr>\n";
  
  for (var i=0; i<currentContributer.length; i++) {
    out[n++] =	 "        <td class='b'><small>"
		+"<img src='../images/flag_" + currentContributer[i].country + ".gif' border='1'> "
		+"<b>" +currentContributer[i].abr.toUpperCase() + " = " + currentContributer[i].name + "</b>"
		+((currentContributer[i].location.length)?(", " + currentContributer[i].location):(""))
		+"</small></td>\n";
  }

  out[n++] =	"      </tr>\n"
		+"    </table></td>\n"
		+"  </tr>\n"
		+"  <tr>\n"
		+"    <td><img src='../images/spacer.gif' height='10'><hr width='50%' height='1' color='black'><img src='../images/spacer.gif' height='10'></td>\n"
		+"  </tr>\n"
		+"  <tr>\n"
		+"    <td><a name='abbreviations'></a><table cellpadding='2' cellspacing='0' border='1' bordercolor='black' background='' bgcolor='#ffffff'>\n"
		+"      <tr>\n"
		+"        <th colspan='2'>Abreviations:</th>\n"
		+"      </tr>\n"
		+"      <tr>\n"
		+"        <td class='a'>POWER</td>\n"
		+"        <td class='a'><small><b>AC:</b> = AC Mains, <b>AC/DC:</b> = AC or DC Mains, <b>DC:</b> = DC Mains, <b>B:</b> = Battery</small></td>\n"
		+"      </tr>\n"
		+"      <tr>\n"
		+"        <td class='a'>WAVEBANDS</td>\n"
		+"        <td class='a'><small><b>BC</b> = Broadcast band (equiv = MW in UK), <b>TB</b> Trawler Band (around 1.6-1.8MHz), <b>(n)PS</b> = (n) x Tuning pre-sets</small></td>"
		+"      </tr>\n"
		+"      <tr>\n"
		+"        <td class='a'>PHONO</td>\n"
		+"        <td class='a'><small><b>A1</b> = Single speed automatic turntable, <b>M3</b> = Three speed manual turntable, <b>PU:</b> = Gram pickup socket</small></td>"
		+"      </tr>\n"
		+"      <tr>\n"
		+"        <td class='a'>DEVICES</td>\n"
		+"        <td class='a'><small><b>MR</b> = Metal Rectifier, <b>TI</b> = Tuning Indicator</small></td>"
		+"      </tr>\n"
		+"      <tr>\n"
		+"        <td class='a'>OTHER</td>\n"
		+"        <td class='a'><small><b>IF</b> = Intermediate Frequency</small></td>"
		+"      </tr>\n"
		+"    </table></td>\n"
		+"  </tr>\n"
		+"</table></form>"
		+"<small>All images except where specifically stated in notes are &copy; <a href='mailto:martin@classaxe.com'>Martin Francis</a> 2001, 2002, 2003</small></body></html>"

  Details.focus();
  Details.document.write(out.join(""));
  Details.document.close();
 }


// ************************************
// * setDetails()                     *
// ************************************
function setsDetails() {
  var collection =	top.title.document.form.collection.options[top.title.document.form.collection.selectedIndex].value;
  var from =		top.title.document.form.region.options[top.title.document.form.region.selectedIndex].value;
  var make =		top.title.document.form.make.options[top.title.document.form.make.selectedIndex].value;
  var order =		top.title.document.form.order.options[top.title.document.form.order.selectedIndex].value;
  photoCount =		update(from,make,order,collection);
  var title =	"Details > "+maker[make].name+" > "+regions[from].description+" > "
		+((collection=="all")?("All Collections"):("Collection "+collection.toUpperCase()));


  var out =new Array; var n=0;
  out[n++] =	"<html>\n<head>\n<title>"+title+"</title>\n"
		+"<style>\n body { font-family: Arial, sans-serif;font-size: 8pt; border: 0; margin: 5;}\n"
		+" td       { font-family: Arial; font-size: 8pt; }\n"
		+" th	{ font-family: Arial; font-size: 10pt; background-color: rgb(255,255,220); text-align: left; }"
		+"</style>\n<\/head>\n\n"
		+"<body background='../images/wallpaper.gif'>"
		+"<h3><u>"+title+"</u><br>\n";

  if (!photoCount) {
    out[n++]="<small><i>No sets listed.</i></small></h3>\n";
    out[n++]="</body></html>\n";
  }
  else {
    out[n++] =	 "<small><i>"+photoCount+" photograph"+((photoCount>1)?("s"):(""))
		+" of "+setList.length+" set"+((setList.length>1)?("s"):(""))+"</i></small></h3>"
		+"<table cellspacing='0' cellpadding='0'>\n"
		+"  <tr>\n"
		+"    <td valign='top' width='100%' bgcolor='#ffffff'>"+makerList(5)+"</td>\n"
		+"    <td><img src='../images/spacer.gif' width='10'></td>\n"
		+"    <td valign='top'>\n"+flagChart(from)+"</td>\n"
		+"  </tr>\n"
		+"</table>\n"
		+"<img src='../images/spacer.gif' height='10'>\n"
		+"<table border='1' cellpadding='1' cellspacing='0' width='100%' bgcolor='white'>\n"
		+"<tr>\n"
		+"<th colspan='2'>Set</th>\n"
		+"<th>Details</th>\n"
		+"<th>HxWxD (cm)</th>\n"
		+"<th>Devices</th>\n"
		+"<th>Serial(s)</th>\n"
		+"<th>Collection</th>\n"
		+"</tr>\n"
		+"<tr>\n";

    for (var i=0;i<setList.length;i++) {
      var setList_set=setList[i];
        if (setList_set!=null) {
          out[n++] =	 "<td valign='top'><nobr><img src='../images/flag_"
			+setList_set.country+".gif' border='1' alt='"+regions[setList_set.country].name+"'></td>"
			+"<td valign='top' nowrap>";
          if (setList_set.photoCount==1) {
            out[n++] =	 "<a href='javascript:top.popup(\""+setList_set.file+"\")'>"
			+setList_set.maker+" "+setList_set.name+"</a>";
          }
          else {
            out[n++] =	"<a href='javascript:top.popup(\""+setList_set.file+"(1)\")'>"
			+setList_set.maker+" "+setList_set.name+"</a>";
            for (var pic=0; pic<setList_set.photoCount; pic++) {
              out[n++] = " <a href='javascript:top.popup(\""+setList_set.file+"("+(1+pic)+")\")'>"
			+"["+(1+pic)+"]</a>";
            }
          }
          out[n++] =	"</nobr></td>";

          if (details[setList_set['file']]) {
          out[n++] = 	 "<td valign='top'>"+details[setList_set.file].notes+"&nbsp;</td>\n"
			+"<td valign='top'>"+details[setList_set.file].hwd+"&nbsp;</td>\n"
			+"<td valign='top'>"+details[setList_set.file].devices+"&nbsp;</td>\n"
			+"<td valign='top'>"+details[setList_set.file].sn+"&nbsp;</td>\n"
			+"<td valign='top'>"+details[setList_set.file].collection.toUpperCase()+"&nbsp;</td>\n";
        }
        else {
          out[n++] = "<td valign='top' colspan='5'><font color='red'>No details for set "+setList_set['file']+"</td>\n"
        }
      }
      out[n++] = "</tr>\n";
    }
    out[n++] =	 "</table></td></tr></table>"
		+"Unless otherwise stated, all images Copyright &copy; <a href='mailto:martin@classaxe.com'>"
		+"Martin Francis</a> 2001, 2002, 2003</body></html>";
  }
  top.main.document.open();
  top.main.document.write(out.join(""));
  top.main.document.close();
}

// ************************************
// * update()                         *
// ************************************
function update(region,maker,order,collection){
  var REXP_region = new RegExp("\\b\("+regions[region].countries.join("|")+"\)_\[^\,\]\+","ig");
  var REXP_maker = new RegExp("\\b\[a-z\]\{2\}_\("+maker+"\)_\[^\,\]\+","ig");

  files = ((order=="top.sortByRegion")?(items()):(items().split(",").sort(eval(order)).join(",")));
  files = files.match(REXP_maker);
  files	= ((files)?(files.join(",")):(""));

  files = files.match(REXP_region);
  files	= ((files)?(files.join(",")):(""));
  files=files.split(",");

  var photoCount = 0
  if (files!='') {
    var setList_assoc =	new Array();
    for (var i=0; i<files.length; i++) {
      file =	files[i].replace(/\(.\)/ig,"");

      if ((collection == "all") || (details[file] && details[file].collection && details[file].collection.match(new RegExp(collection,"ig")))) {
        if (!setList_assoc[file]) {
          if(typeof (details[file]) == 'undefined') {
            alert(file + " has no description. Please contact the site author martin@classaxe.com");
          }
          else {
            details[file].photoCount=0;
            setList_assoc[file] =	new top.SET(file);
          }
        }
        setList_assoc[file].photoCount++;
        details[file].photoCount++;
        photoCount++;
      }
    }
  }
  setList =		new Array();
  var n =		0;
  for (i in setList_assoc) {
    setList[n++] =	setList_assoc[i];
  }
  return photoCount
}

