// Globale Definitionen
var default_width = 50;
var default_height = 50;
var rahmen_w = 50;
var rahmen_h = 50;


function newWindow (url) {
	if (showFenster) closeAll();
	if(!showFenster || showFenster.closed == true)
		showFenster = window.open(url,"NeuesFenster","width=650, height=275, scrollbars=yes, status=yes, resizable=yes, menubar=no, toolbar=no");
	return false;
}

isLoad = false;

function fitWinDownload(breite, hoehe, w)
{
	if(isLoad) return;
    isLoad = true;
    
    w.resizeTo(breite, hoehe);
    var size = getWinSize(w)

	var wImg = breite;
    var hImg = hoehe;

    if (wImg>750) {
    	wimg = 750;
    }
    
    if (hImg>400) {
    	hImg = 400;
    }
    
    w.resizeBy((wImg - size.w + 100), (hImg - size.h + 200));
    w.focus();
}///////////////////////////////////////////////////////////
// showBild(a, name) - die Hauptfunktion.
function showBild(a, name)
{
    a.target = "BildFenster";

    // Das Fenster öffnen
    isLoad = false;
    if(!showFenster || showFenster.closed == true)
    showFenster = popUp('dummy.htm', 'BildFenster', default_width, default_height);

    showFenster.document.open('text/html');
    showFenster.document.write( getHTML(a.href, name) );
    showFenster.document.close();
    showFenster.focus();
    return false;
}
///////////////////////////////////////////////////////////
// fitWin(Image, window) - wird aus dem Popup aufgerufen.


function fitWin(i, w)
{
    
	if(isLoad) return;
	
	isLoad = true;
	var imgW = i.width;
	var imgH = i.height;
	
    if(imgW > 750)
    	imgW = 750;
    if(imgH > 600)
    	imgH = 600;

    w.resizeTo(imgW, imgH);
    var size = getWinSize(w)

//    w.resizeBy(imgW - size.w + rahmen_w, imgH - size.h + rahmen_h + 50);
    w.resizeBy(rahmen_w, rahmen_h + 50);
    w.focus();
}

function ChangeImage (source) {
	parent.window.location.href = source;
	return false;
}

/////////////////////////////////////////////////////////////////////
// getHTML(bild, titel, farbe)
function getHTML(src, title, bgcolor)
{
    var body = !(typeof window.opera != 'undefined' || typeof document.layers != 'undefined' );

    if(!title) title = '-';
    if(!bgcolor) bgcolor = '#FFFFFF';

    return '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">\n' +
    '<HTML>\n<HEAD>\n' +
    '<TITLE>' + 'Details' + '</TITLE>\n' +
    '<STYLE type="text/css">\n' +
    'body{\nmargin:0;padding:0;'+
    'background-color:' + bgcolor + ';\n}\n'+
    '</STYLE>\n' + '</HEAD>\n' +
    '<body ' + (body ? 'onload="opener.fitWin(document.images[0], window);"' : '') +
    '>\n' +
    '<div align="center"><img src="' + src +
    '" align="center"' +
    ' alt="' +
    '" border=0 ' + (!body ? 'onload="opener.fitWin(this, window);"' : '' ) + ' onmousedown="window.close();" onClick="window.close();"></div><br><div align="center">'+
    '</div>' +
    '\n</body>\n</html>\n';
}
/////////////////////////////////////////////////////////////////////
// Ein popup öffnen
function popUp(url, name, w, h)
{
    var tmp = new Array();
    tmp[tmp.length] = 'resizable=yes';
    tmp[tmp.length] = 'scrollbars=yes';
    if(w) tmp[tmp.length] = 'width=' + w;
    if(h) tmp[tmp.length] = 'height=' + h;

    return window.open(url, name, tmp.join(','));
}

function getWinSize(w)
{
    if(!w) w = window;
    var size = {w:0, h:0};

    size.w = w.innerWidth ? w.innerWidth : w.document.body.offsetWidth;
    size.h = w.innerHeight ? w.innerHeight : w.document.body.offsetHeight;
    return size;
}
/////////////////////////////////////////////////////////////////////
// Alle Fenster schliessen
function closeAll()
{
    if(showFenster && !showFenster.closed) showFenster.close();
}
var showFenster = null;
var showImage = null;
/////////////////////////////////////////////////////////////////////
// ... und am schluss alle Fenster schliessen.
//window.onunload = closeAll;
