var exwindow = null, theImage=null, theCaption=null, theLeg=null;

function popfigure(imgfile, caption, leg)
{   var ct, qs;
    theImage=imgfile;  theCaption=caption; theLeg=leg;
    if ( exwindow == null || exwindow.closed ) 
    {   ct = doc_content1();
        qs = "content="+encodeURIComponent(ct);
        exwindow=window.open("figuretemp.html?"+qs, "WDPfigure", 
	  "scrollbars=yes,resizable=yes,width=500,height=375,alwaysRaised=yes");
    }
    else doc_content();
    exwindow.focus();
}

function doc_content1()
{   var fcode = '<h2>' + theCaption + '</h2><p><br /></p>' +
            '<p>' + imgcode(theImage) + '</p>' +
            '<p style="font-family: Courier"><br /><br />' +
            theLeg + '</p>';
    return fcode;
}

function doc_content()
{   var fcode = doc_content1();
    var node = exwindow.document.getElementById('fc');
    node.innerHTML=fcode;
}

function imgcode(imgfile)
{    if ( typeof(imgfile) == "string" )
     {  return '<img src="' + imgfile +'" alt="img">';
     }
     else
     {  var str = '<img src="' + imgfile[0] + '" alt="img">';
        var sep = false;
        for ( i=1; i < imgfile.length; i++)
        { if ( imgfile[i] )
	  {   str += (sep ? "<br /><br />" 
	            : '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;') +
	          '<img src="' + imgfile[i] + '" alt="img">';
	      sep = false;
          }
	  else
	     sep = true;
        }
	// window.alert(str);
	return str;
     }
}
