/*
 © 2001 Struppi
 Mail: jstruebig@web.de
 URL: http://home.nexgo.de/struebig/js/popup_3.htm

 Beschreibung:
 -------------
 Ein Skript um ein Fenster in der Größe eines Bildes öffnen.

 Einbinden:
 ----------
 <script src="popup_3.js"></script>
 <A
    HREF="url_des_bildes"
    target="bild"
    onclick="return showBild(this, 'name_des_Bildes');"
 >
 <IMG SRC="url_des_kleinen_bildes">
 </A>

*/

///////////////////////////////////////////////////////////
// Globale Definitionen
var default_width = 500;
var default_height = 500;
var rahmen_w = 0;
var rahmen_h = 0;


///////////////////////////////////////////////////////////
// showBild(a, name) - die Hauptfunktion.

function showBild(a, name)
{
    if(!a.target) a.target = "Bild_Fenster";

    // Das Fenster öffnen
    if(!showFenster || showFenster.closed == true)
    showFenster = popUp("about:blank", a.target, default_width, default_height);

    var tmp = getHTML(a.href, name);

    //alert(tmp);
    showFenster.document.open('text/html');
    showFenster.document.write(getHTML(a.href, name));
    showFenster.document.close();
    showFenster.focus();
    return false;
}

function showBild1(a, name)
{
    if(!a.target) a.target = "Bild_Fenster";

    // Das Fenster öffnen
    if(!showFenster || showFenster.closed == true)
    showFenster = popUp("about:blank", a.target, default_width, default_height);

    var tmp = getHTML1(a.href, name);

    //alert(tmp);
    showFenster.document.open('text/html');
    showFenster.document.write(getHTML1(a.href, name));
    showFenster.document.close();
    showFenster.focus();
    return false;
}

function fitWin(i, w)
{
	var width = w.innerWidth ? w.innerWidth : w.document.body.offsetWidth;
	var height = w.innerHeight ? w.innerHeight : w.document.body.offsetHeight;
	
	//alert(i.width + "inner w:" + width + "-img.w:" + i.width + "\ninner.h: " + height + "\ni.height:" + i.height);
	
	w.resizeBy(i.width - width + rahmen_w, i.height - height + rahmen_h);
	
	w.focus();
    
}
/////////////////////////////////////////////////////////////////////
//
function getHTML(src, title, bgcolor)
{
    var body = (window.opera || document.layers) ? false : true;
    
    if(!title) title = 'kein Titel';
    if(!bgcolor) bgcolor = 'grey';
    return '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">\n' +
    '<HTML>\n<HEAD>\n' +
    '<TITLE>' + title + '</TITLE>\n' +
    '<STYLE type="text/css">\n' +
    'body{\nposition:absolute;top:0;left:0;text-align:center;margin:0px; padding:0px; background-color:' + bgcolor + ';\n}\n'+
    '</STYLE>\n' +
    '</HEAD>\n' +
    '<body ' + (body ? 'onload="opener.fitWin(document.images[0], window);"' : '') + '>\n' +
    '<a HREF="javaScript:self.close()"><img src="' + src + '" title="click to close" border=0 ' + (!body ? 'onload="opener.fitWin(this, window);"' : '' ) + '></a>' +
    '\n</body>\n</html>\n';
}

function getHTML1(src, title, bgcolor)
{
    var body = (window.opera || document.layers) ? false : true;
    
    if(!title) title = 'kein Titel';
    if(!bgcolor) bgcolor = 'grey';
    return '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">\n' +
    '<HTML>\n<HEAD>\n' +
    '<TITLE>' + title + '</TITLE>\n' +
    '<STYLE type="text/css">\n' +
    'body{\nposition:absolute;top:0;left:0;text-align:center;margin:0px; padding:0px; background-color:' + bgcolor + ';\n}\n'+
    '</STYLE>\n' +
    '</HEAD>\n' +
    '<body ' + (body ? 'onload="opener.fitWin(document.images[0], window);"' : '') + '>\n' +
    '<a HREF="http://tip-online.at/club/?mode=aktuell" title="aktueller tip" target="_blank"><img src="' + src + '"  title="aktueller tip" border=0 ' + (!body ? 'onload="opener.fitWin(this, window);"' : '' ) + '></a>' +
    '\n</body>\n</html>\n';
}

/////////////////////////////////////////////////////////////////////
// Ein popup öffnen
function popUp(url, name, w, h)
{
    var tmp = new Array();
    tmp[tmp.length] = 'resizable=yes, left=250,top=100';
    tmp[tmp.length] = 'scrollbars=no';
    if(w) tmp[tmp.length] = 'width=' + w;
    if(h) tmp[tmp.length] = 'height=' + h;
    return window.open(url, name, tmp.join(','));
}
/////////////////////////////////////////////////////////////////////
// FEHLER handling
function FEHLER()
{
    closeAll();

    var text = "Fehler !!!\n\n" +
    "Das Bild mit der URL:\n" + this.src + ".\n" +
    "konnte nicht geladen werden.";
    alert(text);
}
/////////////////////////////////////////////////////////////////////
// Alle Fenster schliessen
function closeAll()
{
    if(showFenster && !showFenster.closed) showFenster.close();
}
/////////////////////////////////////////////////////////////////////
// globale, nicht veränderbare Werte
var showFenster = null;

/////////////////////////////////////////////////////////////////////
// ... und am schluss alle Fenster schliessen.
window.onunload = closeAll;

