/* general.js */
/* letzte Korrektur: 2009-07-05 */
/* einbauen: DHTML Secondary Windows 105 <<<<<<<< */
/* schließe alle childwindows bei Verlassen des parent_windows */

/* <script type="text/javascript" src="../js/general.js"></script> */
/* <script language="Javascript" type="text/javascript> . . . </script> */

/* alert("general.js geladen"); */

var screen_width = screen.width;
var screen_height = screen.height;
// screen.width = absolut verfügbare Breite des Anwenderbildschirms in Pixeln
// alert ("screen_width x screen_height :" + screen_width + " x " + screen_height);
// var screen_w = screen.availWidth;
// var screen_h = screen.availHeight;
var winFeatures = "menubar=yes,resizable=yes,scrollbars=yes,status=yes";

function getElementPosition(elemID) {
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
	 return {left:offsetLeft, top:offsetTop};
}


// openClose durch show_hide ersetzen !
function openClose(theID) {
	if (document.getElementById(theID).style.display == "block") { 
		document.getElementById(theID).style.display = "none";
	}
   else {
   	document.getElementById(theID).style.display = "block";
	}
}

function show_hide(containerID) {
	var textID = containerID + '_text';
	var container = document.getElementById(containerID);

	var oldIcon = container.firstChild;
	var newIcon = document.createElement('IMG');

	if (document.getElementById(textID).style.display == "block") { 
		document.getElementById(textID).style.display = "none";
		source = "/_scripts/styles/show.gif"
		newIcon.setAttribute("src",source); 
		container.replaceChild(newIcon, oldIcon);
	}
   else {
   	document.getElementById(textID).style.display = "block";
		source = "/_scripts/styles/hide.gif"
		newIcon.setAttribute("src",source); 
		container.replaceChild(newIcon, oldIcon);
	}
}

	
function resizeWin(elemID) {
	if (elemID == "resize") {
		var offsetTrail = document.getElementById(elemID);
		var offsetTop = offsetTrail.offsetTop;
	
	 // Browserabfrage !
	 
	 // Höhe der Navigationsleisten in Firefox + IE = 115 pixel, Basisleiste 25 pixel
	 // funktioniert in Firefox und IE
	 // offsetTop = offsetTop + 150;
	 window.resizeTo(1000,(offsetTop+150));
    
	 // besser: (funktioniert in Firefox, nicht jedoch in IE !)
	 // window.innerHeight = offsetTop;
	}
	else {
		if (elemID == "screenheight") {
			window.moveTo(100,20);
			window.resizeTo(1000,screen.height-50);
		}
	}
}


function blankFrame(frameName,bg_color) {
  var content = "<html><body bgcolor=" + bg_color +"></body></html>"; 
  top.frames[frameName].document.write(content);
  top.frames[frameName].document.close();
}

function loadIntoFrame(url,frameName) {
// abfragen ob bereits geladen!
	top.frames[frameName].location.href = url;
}

function write2newWin(url,winName,content,winFeatures) {
	 // alert("fc write2newWin: " + " // url: "+url + " // winName: "+winName + " // content: "+content);
	//	definierte Fensterposition; Fenster nach Laden abhängig vom Inhalt beschneiden!
	// wird winFeatures nicht übergeben, werden die Werte der vordefinierten Variablen (s.o.) verwendet!
	// alert("winFeatures" + winFeatures);

	newWindow = window.open(url,winName,winFeatures);
	if (content) { newWindow.document.write(content); }
   newWindow.document.close();
	newWindow.focus();
}


// var newWindow;
function _newWin(url,winName,winAttributes) {
// winName = '_self' > Datei wird in das aufrufende Fenster geladen
// wenn winAttributes = '' wird Fenster ohne Attributes geöffnet!
	if (newWindow) { alert(newWindow.name + " - " + winName); }
	// subwindow bereits geöffnet? 
	if (!newWindow || newWindow.closed) {
		newWindow = window.open(url,winName,winAttributes);
	} else {
		// Name des geöffneten Fensters ungleich dem Namen des neuen Subwindows?
		if (newWindow.name != winName) {
			newWindow = window.open(url,winName,winAttributes);
		} else {
			newWindow.focus();
		}
	}
}


var newWindow;
function newWin(url,winName,winAttributes) {
// < < vgl. function _newWin < < cf. Goodman 6.5
// wenn winAttributes = '' wird Fenster ohne Attributes geöffnet!
	if (newWindow) { alert(newWindow.name + " - " + winName); }
	// subwindow bereits geöffnet? 
	if (!newWindow || newWindow.closed) {
		newWindow = window.open(url,winName,winAttributes);
	} else {
		// Name des geöffneten Fensters ungleich dem Namen des neuen Subwindows?
		// Problem: Namen der übrigen bereits geöffneten Fenster nicht ansteuerbar!?
		// derzeit werden "ältere" Fenster erneut geladen!
		if (newWindow.name != winName) {
			newWindow = window.open(url,winName,winAttributes);
			newWindow.focus();
		} else {
			newWindow.focus();
		}
	}
}

function checkInputWin(ms_code,winContent) {
	var newWindow;
	var docname = ms_code;
	var win_width = screen.width*2/3;
	var win_height = screen.height/3;
	var winposX = (parseInt(screen_width)-parseInt(win_width))/2;
	var winposY = 5;
	var winSize = "width="+win_width+",height="+win_height;
  var winPos = "screenX="+winposX+",screenY="+winposY;     // NN
  winPos += "left="+winposX+",top="+winposY+"\"";          // MSIE

	newWindow = window.open("",docname,winFeatures + ", " + winSize + ", " + winPos);
  newWindow.document.write(winContent);
	newWindow.document.close();
	newWindow.focus();
}

function toggleText(id_element,id_caption,text_caption) {
// id_element = ID of element to hide or show
/* Übergabe eines EINZIGEN Paramters (id_element) berücksichtigen! */
	if (document.getElementById(id_element).style.display == "none") {
		document.getElementById(id_element).style.display = "";
		document.getElementById(id_caption).firstChild.nodeValue=text_caption + " verstecken";
	}
	else {
		document.getElementById(id_element).style.display = "none";
		document.getElementById(id_caption).firstChild.nodeValue=text_caption +" anzeigen";			
	}
}

	
/*	function toggleLayer(id) {
		if (document.getElementById(id).style.display == "none") {
			document.getElementById(id).style.display = "";
		}
		else {
			document.getElementById(id).style.display = "none";
		}
	}
*/
function replWmNav(tabNr) {
	// tabNr = Nummer des angeklickten tabs
	// // alert("übergebene TabNr: " + tabNr);
	// hervorgehobenen tab auf normal setzen
	// zählt ALLE li-Elemente des Dokuments; = 4 !
	// funktioniert nur korrekt bei 3 Elementen
	// // alert("Anzahl Tabs: " + document.getElementsByTagName("li").length);
	for (i=1;i<document.getElementsByTagName("li").length;i++) {
		id = "tab"+i;
		// // alert("Tab: " + id);
		if (document.getElementById(id).getAttribute('class') == "hl_tab") {
			document.getElementById(id).setAttribute("class", "tab");
			break;
		}
	}
	// angeklickten tab hervorheben:
	id = "tab"+tabNr;
	document.getElementById(id).setAttribute("class", "hl_tab");	// itemNr = Nummer des gedrückten Tabs
}

function loadImg(path,fileName,img_width,img_height,caption) {
	// alert ("imgbase:"+imgbase + " subdir_img:"+subdir_img + " refnr:"+refnr + " img_width:"+img_width + " img_height:"+img_height);
	var newWindow;
	var fileName = fileName;
	var docname = path + fileName + ".jpg";
  // alert(docname); exit();
	var win_width = parseInt(img_width)+100;
	var win_height = parseInt(img_height)+350; 
	//  var winposX = parseInt(screen_width)-parseInt(win_width)-parseInt(img_width);
  // var winposY = 30;
	var winSize = "width="+win_width+",height="+win_height;
	winposX = winposX+15; winposY = winposY+15;
	if ((winposY+win_height) > (screen_height-100)) {
		winposY = 15;
	}
	var winPos = "screenX="+winposX+",screenY="+winposY;     // NN
	winPos += ",left="+winposX+",top="+winposY+"\"";          // MSIE

	newWindow = window.open("","",winFeatures + ", " + winSize + ", " + winPos);
	var destination = "loadWmarkImg.php?refnr_wm=" + refnr + "";
	// alert("destination: " + destination); 
	newWindow.location.href = destination;
	/*
      var newContent = "<html><head><title>" + refnr + "</title></head>\n";
	newContent += "<body><strong>" + refnr + "</strong>\n";
	newContent += "<img src='" + docname + "' name='" + refnr + "'>\n";
	newContent += "</body></html>";
	newWindow.document.write(newContent);
       */
	newWindow.document.close();
	newWindow.focus();
}	

function newImgWin(path,filename,header,typeOfSize,img_ws,img_hs,img_wb,img_hb) {
	// Aufruf: <a onclick="newImgWin('../../_HEBRAICA/imgjpg/AT5000/', 'AT5000-300_VDS-Abklatsch-gespiegelt.jpg', 'Klosterneuburg OSA, Cod.&nbsp;300, Vorderdeckel-Spiegel', 755, 1035, 2516, 3451)">VDS-Abklatsch, gespiegelt</a>
	var newWindow;
	//// alert("screen_width: " + screen_width + "screen_height: " + screen_height);
	//// alert("typeOfSize: " + typeOfSize + "Pfad alt: " + path);
	
	// falls path auf imgjpg100 endet, lösche diesen Teilstring 
	var pos = path.indexOf('imgjpg100/')
	if (pos > 0) { path = path.substr(0,pos); }
	//// alert("Pfad neu: " + path);
		
	// ----------- Fenstereigenschaften ------------------------------
	var win_width = 0;
	var win_height = 0; 
	if (typeOfSize == 1) { // Originalgröße
		win_width = screen_width;
		win_height = screen_height;
	}
	if (typeOfSize == 2) { // "WWW"-Größe
		win_width = parseInt(img_ws)+50;
		win_height = parseInt(img_hs)+100; 
	}
	var winSize = "width="+win_width+",height="+win_height;
	// alert("winSize: " + winSize);

	var winposX = 0; var winposY = 0;
	var winPos = "screenX="+winposX+",screenY="+winposY;     // NN
	winPos += ",left="+winposX+",top="+winposY+"\"";          // MSIE
	//// alert("winPos: " + winPos);	

	var winAttributes = winFeatures + ", " + winSize + ", " + winPos;
	//// alert(winAttributes);
	
	// ------------------- Aufruf neues Fenster ---------------------
	var docname = filename; // wird derzeit nicht gebraucht
	//// alert(filename);
	
	// newWindow = window.open('','',winFeatures + ", " + winSize + ", " + winPos); // ok, Fenstner bleiben jedoch bestehen!
	// newWindow = window.open('','xxx',winFeatures + ", " + winSize + ", " + winPos); // nur EIN Fenster, Größe verändert sich jedoch nicht!
	newWindow = window.open('','xxx',winFeatures + ", " + winSize + ", " + winPos); // URI, Fenstername, Fenstereigenschaften
	// winSize bei Vergrößerung des Fensters ohne Effekt, daher:
	window.resizeTo(win_width,win_height);
	
	// ------------------- Inhalt in Fenster schreiben ---------------------
	//	var destination = "loadWmarkImg.php?refnr_wm=" + refnr + "";
	// alert("destination: " + destination); 
	//	newWindow.location.href = destination;

	var newContent = '';
	var path_imgSize1 = path + 'imgjpg100/';
	var path_imgSize2 = path;
   
   newContent = "<html><head><title>" + header + "</title>\n";
	newContent += "<script type=\"text/javascript\" src=\"../js/general.js\"></script></head>\n";
	newContent += "<body><center><table border='1'>\n";
	newContent += "<tr><td>&nbsp;&nbsp;&nbsp;<strong>" + header + "</strong>\n";
	
	// Aufruf kleines Bild, Link auf großes Bild
	if  (typeOfSize == 2) {
		var img_path = path_imgSize2;
		var new_typeOfSize = 1;
		var path_onClick = path_imgSize1;
		var icon = '../../_scripts/styles/lupe_plus.gif';
	}
	// Aufruf großes Bild, Link auf kleines Bild
		else if (typeOfSize == 1) {
		var img_path = path_imgSize1;
		var new_typeOfSize = 2;
		var path_onClick = path_imgSize2;
		var icon = '../../_scripts/styles/lupe_minus.gif';
	}
	newContent += "<a onClick=\"newImgWin('" + path_onClick + "', '" + filename + "', '" + header + "', " + new_typeOfSize + ", " + img_ws + ", " + img_hs + ", " + img_wb + ", " + img_hb + ");\">\n";
	newContent += "&nbsp;&nbsp;&nbsp;<img src='" + icon + "' width='17' height='17'></a>\n"; 
	newContent += "</td></tr>\n";
	
	newContent += "<tr><td colspan='2'><img src='" + img_path + filename + "' name='" + header + "'></td></tr>\n";
	newContent += "<tr><td colspan='2'>Copyright . . .</tr></td>\n";
	newContent += "</table></center></body></html>";
	
	newWindow.document.write(newContent);
	newWindow.document.close();
	newWindow.focus();
}	// newImgWin - 2006-08-05


// var newWindow;
function _newWin(url,winName,winAttributes) {
// cf. Goodmann 6.5
// wenn winAttributes = '' wird Fenster ohne Attributes geöffnet!
	if (!newWindow || newWindow.closed) {
		newWindow = window.open(url,winName,winAttributes);
		newWindow.focus();
	} else {
		// Fenster bereits geöffnet !
		newWindow.focus();
	}
}

