// V 2.0 Detailbild anzeigen
function openDetail(img,sizeW,sizeH)
	{
	if(sizeW=='' || sizeH=='')
		{
		sizeW = 300;
		sizeH = 300;
		var resize = true;
		}

	l = screen.width/2-50;
	o = screen.height/2-150;
	windowOptions = 'width='+sizeW+',height='+sizeH+',left='+l+',top='+o+',status=1,scrollbars=0,resizable=1';
	Detailwindow=window.open('incl/blank.html','Detailwindow',windowOptions);
	Detailwindow.document.write('<html>'
	+'<head> '
	+'<title>'+img+'</title> '
	+'<'+'script language="javascript"'+'> '
	+'function resize() { '
	+'if(document.images[0]) { window.resizeTo(document.images[0].width+10,document.images[0].height+54); } '
	+'self.focus();'
	+'} '
	+'<'+'/script'+'>'
	+'</head>'
	+'<body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0" onLoad="javascript:resize();" onBlur="javascript:window.close();">'
//	+'<table border="0" cellspacing="0" cellpadding="0">'
//	+'<tr>'
//	+'<td valign="top"><img src="'+img+'" id="bigImage" border="0" onClick="JavaScript:window.close();"></td>'
	+'<img src="'+img+'" id="bigImage" border="0" onClick="JavaScript:window.close();">'
//	+'</tr>'
//	+'</table>'
	+'</body>'
	+'</html>');

	Detailwindow.document.close(); 
	}


// Druckansicht oeffnen
// @url = absolute URL der Quelldatei
// @w = (int) Breite des Druckfensters
// @h = (int) Hoehe des Druckfensters
function PrintWindow(url,w,h)
	{ // V1.0 copyright Grfaix21.de
	l = screen.width/2-50;
	t = screen.height/2-150;
	w = eval(w) + 16;
	options = "width="+w+",height="+h+",left="+l+",top="+t+",menubar=yes,resizable=yes,scrollbars=yes,status=yes";
	Druckwindow = window.open(url,'Details',options);
	Druckwindow.focus();
	}


// PHP-Kalender aufrufen
// @p1 = name des Eingabefeldes
// @p2 = Hinweis für den Benutzer
function calendar(p1, p2)
	{
	var calendarWindow = window.open("incl/calendar.php?form=" + p1 + "&show_info=" + p2, "Calendar", "width=280,height=250,status=no,resizable=no,top=200,left=300,dependent=yes,alwaysRaised=yes");
	calendarWindow.opener = window;
	calendarWindow.focus();
	}



// Position von Statuswerten verschieben
// @pos = die zu verändernde Position
// @direction = nach vorn oder nach hinten verschieben ('up' / 'down')
function changePos(pos,direction)
	{
	if(direction == 'UP')
		{ newPos = pos--; }
	else
		{ newPos = pos++; }
	
	// Alten Wert der neuen Position Zwischenspeichern
	tempValue = document.getElementById('position_'+pos).value;
	document.getElementById('position_'+pos).value = document.getElementById('position_'+newPos).value;
	document.getElementById('position_'+newPos).value = tempValue;
	}


// Funktion zum Errechnen der Summe von Feldern
// Bsp. fuer Feldname: id="Summe_2" (Name + Tiefstrich + Index)
// @fieldName = 1. Teil des Namens der betroffenen Felder
// @maxIndex = Anzahl der Felder
function calcSum(fieldName,maxIndex)
	{
	summe = 0;
	// Felder addieren
	for(i=0; i<maxIndex; i++)
		{
		wert = document.getElementById(fieldName+'_'+i).value.replace('.','').replace(',','.');
		// *1 = Bugfix um aus einem String eine Zahl zu basteln
		summe+= (wert*1);
		}
	// Ausgabe formatieren
	summe = CMM_number_format(summe,2,',','.');

	return summe;
	}


// spezielle Funktion zum Formatieren von Preisen
// Funktion wie PHP-Funktion number_format()
// @string = (int) Ausgangswert
// @precision = Nachkommastellen
// @decimal = Dezimal-Trennzeichen
// @thousands = Tausender-Trennzeichen
function CMM_number_format(string,precision,decimal,thousands)
	{
	string = string.toString();
	stringParts = string.split('.');
	// Wenn keine Nachkommastellen existieren
	if(!stringParts[1])
		{ stringParts[1] = '0'; }
	// Nachkommastellen kuerzen
	if(stringParts[1].length > precision)
		{
		// Runden (Komma hineinmogeln um Math.round() zu nutzen)
		stringParts[1] = stringParts[1].substr(0,precision)+'.'+stringParts[1].substr(precision);
		stringParts[1] = Math.round(stringParts[1]);
		}
	// Nachkommastellen ergaenzen
	if(stringParts[1].length < precision)
		{
		stringPartsLength = stringParts[1].length;
		for(i=stringPartsLength; i<precision; i++)
			{ stringParts[1] = stringParts[1] + '0'; }
		}
	// Tausender-Trennzeichen
	thousandsPos = stringParts[0].length;
	while(thousandsPos > 0)
		{
		thousandsPos = thousandsPos-3;
		if(thousandsPos > 0)
			{ stringParts[0] = stringParts[0].substr(0,thousandsPos) + thousands + stringParts[0].substr(thousandsPos,stringParts[0].length-thousandsPos); }
		}
	// Dezimal-Trennzeichen
	string = stringParts[0] + decimal + stringParts[1];

	return string;
	}

