// -*-java-*-
//
// bildfenster.js
//
// Part of Sternenfall (http://www.sternenfall.de).
//
// Copyright 2005
// 
////////
// Author: Andreas Spindler
// $Writestamp: 2006-05-29 13:33:06 SpindleA$
//

function bildfenster__blank(bildUrl,w,h) 
{
    /* Show image in anonymous window. */
    var scrollen="no";
    w=(1*w)+20;
    h=(1*h)+30;
    if(w>800) {
        scrollen="yes";
        w=800; h=(1*h)+20;
    }
    if(h>600) {
        scrollen="yes";
        h=600; w=(1*w)+20;
    }
    argumente="width="+w+",height="+h+",left=0,top=0,location=no,menubar=no,resizable="+scrollen+",scrollbars="+scrollen+",status=no,toolbar=no";
    window.open(bildUrl,"_blank",argumente);
}

function pdffenster(path)
{
    var initstr = 
        'toolbar=0,directories=0,status=0,menubar=0,'+
        'scrollbars=1,resizable=1';
    /* Open a new window. In general users don't view a PDF file as being the
       same environment as a website, i.e. don't remember to push the "back"
       button to get back to our site. */
    var bf = window.open( path, '_blank', initstr );
    bf.focus();
    return false;
}

function htmlfenster(path,h)
{
    var initstr = 
        'toolbar=0,width=600,height='+h+',directories=0,status=0,menubar=0,'+
        'scrollbars=1,resizable=1';
    var f = window.open( path, '_blank', initstr );
    f.focus();
    return false;
}


function bildfenster(autor,path,descr,winname) 
{
    /* Show image in named window. */
    /* The user can open a window and move it around on the screen.  If
       clicking again on the same image, the popup window already showing it
       gets recycled. */
    var img = new Image; img.src = path;
    var em = 12;                // wie Geviertstrichbreite
    var offs = 8 * em;
    var W = img.width + 2 * em; // einmal links + rechts
    var H = img.height + 6 * em; // einmal oben, fünfmal unten (Raum für Text)
    var maxW = screen.width - offs;
    var maxH = screen.height - offs;
    var scroll = '0';
    var tip = 
        'Datei: '+path+', '+W+'x'+H+'.\n\n' +
        'Klicken Sie auf das Bild um das Fenster zu schließen.';

    if( W > maxW ) {
        W = maxW; scroll = '1';
    }
    if( H > maxH ) {
        H = maxH; scroll = '1';
    }
    
    var initstr = 
        'width='+W+',height='+H+',toolbar=0,directories=0,status=0,menubar=0,'+
        'scrollbars='+scroll+',resizable='+scroll;
    var bf = window.open( '', winname, initstr );
    var myHTML =
        '<HTML><HEAD><TITLE>' + autor + ' - Bild</TITLE></HEAD><BODY STYLE="overflow:hidden" BGCOLOR="#FFFFFF" ONLOAD="top.window.focus()">' +
        '</BODY></HTML>';
    var myBody =
        '<A HREF="#" ONCLICK="self.close();return false;">' +
        "<P STYLE='border:#AAAAAA 1px solid; background: #EEEEEE; margin:0; padding:3px;'" + 
        ' ID="bild"><IMG TITLE="' + tip + '" BORDER="0" ALT="" SRC="' + path + '"></A><BR>' + descr + 
        '</P>';

    /* HTML schreiben. */
    /* TODO: Die Methode document.clear funktioniert nicht.  HTML text wird
       doppelt geschrieben, wenn das Fenster reused wird.  Manche Browser
       könnten damit ein Problem haben! Lösung: leere Datei bildrahmen.html
       erzeugen und dann die Tags TITLE und BODY über innerHTML-Attribut
       setzen?! */
    bf.document.clear();
    bf.document.write( myHTML );
    bf.document.body.innerHTML = myBody;
    bf.focus();

    if( W==maxW || H==maxH ) {
        bf.moveTo(10,10);
    } else if( W==maxW ) {
        bf.moveTo(10,100);
    } else if( H==maxH ) {
        bf.moveTo(100,10);
    } else {
        // centered
        bf.moveTo( (maxW-W)/2, (maxH-H)/2 );
    }

    return false;
}

function open_popup_image(path)
{
    /* Special, frameless window (like some tooltip, click outside to
       close). */
    var puw = window.createPopup();
    var img = new Image; img.src = path;
    var W = img.width;
    var H = img.height;
    var X = 100; // screen.width / 2 -  W / 2;
    var Y = 100; // screen.height / 2 - H / 2;
    var pbd = puw.document.body;
    pbd.style.backgroundColor = "white";
    pbd.style.border = "solid black 2px";
    pbd.innerHTML = "<P STYLE='position:absolute; text-align:center; width:" + W + " height:" + H + "'><IMG SRC='" + path + "'></P>";
    puw.show( X, Y, W, H, document.body );
}
