// Gibt den Browser zurueck
function GetBrowser()
{
	Browser = '';

	if ( navigator.userAgent.indexOf( 'konqueror' ) > 0 )
	{
		Browser = 'KON';
	}
	else if ( document.all )
	{
		Browser = 'IE';
	}
	else if ( document.layers )
	{
		Browser = 'NS';
	}

	return Browser;
}

// Gibt die Version des Browsers zurueck
function GetBrowserVersion()
{
	Version = '';

	if ( GetBrowser() == 'NS' )
	{
		if ( document.layers )
		{
			Version = '4';
		}
	}
	else if ( GetBrowser() == 'IE' )
	{
		if ( document.all && navigator.userAgent.indexOf( 'MSIE 5' ) > 0 )
		{
			Version = '5';
		}
		else if ( document.all && navigator.userAgent.indexOf( 'MSIE 6' ) > 0 )
		{
			Version = '6';
		}
		else
		{
			Version = '4';
		}
	}
	else
	{
		Version = '0';
	}

	return Version;
}

// erstellt einen Link, fuegt hinten den Wert einen Feldes (HTML-Elementes) an und schickt diesen ab.
function LinkWithField( LinkZiel, FeldName )
{
	element=document.getElementsByName( FeldName )[0];
	document.location.href=LinkZiel+element.value;
}

// Prueft das Feld auf eine Ganzahl in einem Bereich (DeH)
function CheckFieldInteger( FormName, TextFeldName, BereichVon, BereichBis, AlertText )
{
	Value = parseInt( document.forms[ FormName ].elements[ TextFeldName ].value );

	if ( isNaN( Value ) == true )
	{
		alert( AlertText );
		return false;
	}

	if ( Value < BereichVon || Value > BereichBis )
	{
		alert( AlertText );
		return false;
	}

	return true;
}

// setzt alle checkboxen deren Namen mit 'Name' beginnen auf Wert (True/False)
function SetCheckBoxes( FormName, chkBoxName, Wert )
{
	if ( document.forms[ FormName ] )
	{
		for ( i = 0; i < document.forms[ FormName ].elements.length; i++ )
		{
			if ( document.forms[ FormName ].elements[ i ].name.indexOf( chkBoxName ) != -1 )
			{
				document.forms[ FormName ].elements[ i ].checked = Wert ;
			}
		}
	}
}

// prueft das uebergebene Feld auf Mindestlaenge. (DeH)
function chkInputLength( InputField, MinLength, AlertText, isNullLengthAllowed )
{
	if ( InputField.value.length < MinLength && ( InputField.value.length != 0 || ! isNullLengthAllowed ) )
	{
		alert( AlertText ) ;
		InputField.focus() ;
		return false ;
	}
}

//fuegt einem Formular ein verstecktes eingabefeld mit Namen und Wert hinzu, um Werte als Parameter an ein Serverscript zu uebergeben (rat)
function AddParameter( Form, Name, Wert )
{
	if ( document.forms[Form] )
	{
		InputHidden = document.createElement('input');
		InputHidden.type = 'hidden';
		InputHidden.name = Name;
		InputHidden.value = Wert;
		document.getElementById(Form).appendChild(InputHidden);
	}
}

//fuegt einem Hyperlink einen Parameter (Namen und Wert) hinzu (rat)
function AddLinkParameter( LinkID, Name, Wert )
{
	if ( document.getElementById(LinkID) )
	{
		href = document.getElementById(LinkID).href;

		if ( href != "" && href.search( /^javascript\:/ ) == -1  )
		{
			href = document.getElementById(LinkID).href;
			zeichen = "?";
			if ( href.search(/\?/) != -1 )
			{
				zeichen = "&";
			}
			document.getElementById(LinkID).href += zeichen+Name+'='+Wert;
		}
	}
}


function KategorieWaehlenOpenWindow( )
{
	var url = "kategorie_waehlen.php";
	var win = window.open(url, "Waehlen", "width=700,height=120,scrollbar, resizable=yes");

	if ( ! win.opener ) win.opener = self;
	if ( win.focus != null ) win.focus();
}

function KategorieWaehlenKlick( KID )
{
	window.opener.document.Edit.KategorieID.value=KID;
	self.close();
}


// Muenchen Standard

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	winName = winName.replace( / /, '_' );
	var NewWindow = window.open(theURL,winName,features);
	NewWindow.focus();
}

function MM_openBrWindowAndReturn(theURL,winName,features) { //v2.0
	winName = winName.replace( / /, '_' );
	return window.open(theURL,winName,features);
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

// Anpassung der Fenstergroesse(olaf)
function Resize( Width )
{
	window.resizeTo( Width, 600 ) ;


	if ( document.body.offsetHeight + 20 > 600 )
	{
		window.innerHeight = 600 ;
	}
	else
	{
		window.innerHeight = document.body.offsetHeight + 20 ;
	}
}

//Automatische Anpassung der Fenstergroesse(olaf)
function AutoResize( TransBild )
{
	//wenn sich das Fenster in einem Frame oder Iframe befindet, dann nichts machen
	if ( ! self.opener )
	{
		return true;
	}

	// Standard Zusaetze
	ScrollBar = 15; // Breite
	FensterKopf = 70; // Hoehe
	Taskleiste = 150; // Hoehe der Taskleiste

	window.resizeTo( 800, 600 ) ; // erstmal auf Minimal Groesse setzen, damit sich der Body darstellt

	// Bild an den Body anfuegen
	Bild = document.createElement("img");
	Bild.src = TransBild;
	Bild.align = "right";
	Bild.width = 1;
	Bild.height = 1;
	Bild.hspace = 0;
	Bild.vspace = 0;
	Bild.border = 0;
	document.getElementsByTagName("body")[0].appendChild(Bild);

	// Hoehe ausrechnen
	myTarget = Bild;
	totop = 0;
	toleft = 0;

	while ( myTarget != document.body )
	{
		totop += myTarget.offsetTop;
		toleft += myTarget.offsetLeft;
		myTarget = myTarget.offsetParent;
	}

	if ( totop + FensterKopf > screen.height - Taskleiste )
	{
		totop = (screen.height - Taskleiste);
	}

	window.moveTo( 10, 10 );
	window.resizeTo( document.getElementsByTagName("body")[0].offsetWidth + ScrollBar , totop + FensterKopf ) ;
}


// berechnet den Rabattpreis anhand des Grundpreises (fuer Artikelpreise Admin)
function CalcRabattpreis(Grundpreis, GrundpreisFeldname, GrundpreisNummer, AnzahlRabatte)
{
	zahl = Grundpreis;
	grundpreisvalue = document.SaveAll.elements[GrundpreisFeldname].value;

 	for ( i = 1; i <= AnzahlRabatte; i++ )
 	{

		faktorvalue = document.SaveAll.elements[ "Prices[" + GrundpreisNummer + "][Discounts][" + i + "][DiscountFactor]" ].value;

		if (zahl.search(/,/) != -1 )
		{
			zahl = zahl.replace(/,/, ".");
			document.SaveAll.elements[GrundpreisFeldname].value = zahl;
		}

		if ( ! isNaN(zahl) )
		{
			value = Math.round( ( grundpreisvalue - grundpreisvalue * faktorvalue / 100 ) * 100 ) / 100;
			value +="";

			reg = /\.\d$/;
			if ( reg.test( value ) )
			{
				value += "0";
			}

			reg = /\.0$/;
			if ( reg.test( value ) )
			{
				value += "0";
			}

			document.SaveAll.elements[ "Prices[" + GrundpreisNummer + "][Discounts][" + i + "][DiscountPrice]" ].value = value;
		}
		else
		{
			document.SaveAll.elements[ "Prices[" + GrundpreisNummer + "][Discounts][" + i + "][DiscountPrice]" ].value = "0.0";
		}

	}
}

// berechnet den Rabattpreis anhand des Rabattfaktors sowie des Grundpreises (fuer Artikelpreisrabatte Admin)
function CalcRabattpreisByRabattfaktor(Rabattfaktor, Grundpreis)
{
	zahl = Rabattfaktor;
	grundpreisvalue = Grundpreis

	if (zahl.search(/,/) != -1 )
	{
		zahl = zahl.replace(/,/, ".");
		document.SaveDiscountData.DiscountFactor.value = zahl;
	}

	if ( ! isNaN(zahl) )
	{
		if ( zahl < 0 || zahl > 100 )
		{
			document.SaveDiscountData.DiscountPrice.value = grundpreisvalue;
		}
		else
		{
			document.SaveDiscountData.DiscountPrice.value = Math.round( ( grundpreisvalue - grundpreisvalue * zahl / 100) *100 ) / 100;
		}
	}
	else
	{
		document.SaveDiscountData.DiscountPrice.value = grundpreisvalue;
	}

	reg1 = /^.*\.\d$/;
	reg2 = /^\d*$/;
	if ( reg1.test( document.SaveDiscountData.DiscountPrice.value ) )
	{
		document.SaveDiscountData.DiscountPrice.value += "0";
	}
	else if ( reg2.test( document.SaveDiscountData.DiscountPrice.value ) )
	{
		document.SaveDiscountData.DiscountPrice.value += ".00";
	}
}

// berechnet den Rabattfaktor anhand des Rabattpreises und des Grundpreises (fuer Artikelpreisrabatte Admin)
function CalcRabattfaktor(Rabattpreis, Grundpreis)
{
	zahl = Rabattpreis;
	grundpreisvalue = Grundpreis
	rabattpreisvalue = document.SaveDiscountData.DiscountPrice.value

	if (zahl.search(/,/) != -1 )
	{
		zahl = zahl.replace(/,/, ".");
		document.SaveDiscountData.DiscountPrice.value = zahl;
	}

	if ( ! isNaN(zahl) && ! isNaN( grundpreisvalue ) && ! grundpreisvalue == "" && ! isNaN( rabattpreisvalue ) )
	{
		document.SaveDiscountData.DiscountFactor.value = Math.round( ( (1 - rabattpreisvalue / grundpreisvalue) *100) * 1000 ) / 1000;
	}
	else
	{
		document.SaveDiscountData.DiscountFactor.value = "0.00";
	}

}

// fuegt einer Auswahlliste ein neues Element hinzu (fuer Artikel Admin)
function HerstellerHinzufuegen(Nummer)
{
	SelectedHersteller = eval("document.ArtikelEigenschaften.HerstellerNeuAuswahl"+Nummer+".options[document.ArtikelEigenschaften.HerstellerNeuAuswahl"+Nummer+".selectedIndex].value");

	NeuerEintrag = new Option(SelectedHersteller, SelectedHersteller, false, true);

	if ( SelectedHersteller && ! isEntry( SelectedHersteller, Nummer ) )
	{
		eval("document.ArtikelEigenschaften.HerstellerListeAuswahl"+Nummer+".options[document.ArtikelEigenschaften.HerstellerListeAuswahl"+Nummer+".length] = NeuerEintrag");
	}
}

// loescht selektierte Eintraege aus der Auswahlliste
function HerstellerLoeschen(Nummer)
{

	Element = hasSelectedElements(Nummer);

	while( Element != -1 )
	{
		eval("document.ArtikelEigenschaften.HerstellerListeAuswahl"+Nummer+".options[ Element ] = null");
		Element = hasSelectedElements(Nummer);
	}

}

//prueft, ob ein Eintrag in der Liste bereits vorhanden ist
function isEntry( Entry, Nummer )
{
	Anzahl = eval("document.ArtikelEigenschaften.HerstellerListeAuswahl"+Nummer+".length");

	for ( i = 0; i < Anzahl; i++ )
	{
		if ( eval("document.ArtikelEigenschaften.HerstellerListeAuswahl"+Nummer+".options[i].value.toUpperCase()") == Entry.toUpperCase( ) )
 		{
 			return true;
 		}
	}

	return false;
}

//prueft, ob sich noch selektierte Elemente in einer mehrzeileigen Auswahliste befinden
function hasSelectedElements(Nummer)
{
	Anzahl = eval("document.ArtikelEigenschaften.HerstellerListeAuswahl"+Nummer+".length");

	for ( i = 0; i < Anzahl; i++ )
	{
		if ( eval("document.ArtikelEigenschaften.HerstellerListeAuswahl"+Nummer+".options[ i ].selected") == true )
		{
			return i;
		}

	}

	return -1;
}

// sendet alle Eingabefelder sowie alle (auch nicht selektierte) Eintraege einer mehrzeilige Auswahlliste fuer Artikeleigenschaften an den Server
function SubmitArtikelEigenschaften(Nummern, opener_reload)
{
	for ( i = 0; i < Nummern.length; i++ )
	{
		if ( eval("document.ArtikelEigenschaften.HerstellerListeAuswahl"+Nummern[i]) )
		{
			Anzahl = eval("document.ArtikelEigenschaften.HerstellerListeAuswahl"+Nummern[i]+".length");

			for ( j = 0; j < Anzahl; j++ )
			{
				eval("document.ArtikelEigenschaften.HerstellerListeAuswahl"+Nummern[i]+".options[j].selected = true");
			}

//			document.forms["ArtikelEigenschaften"].elements["HerstellerListeAuswahl"+Nummern[i]].name = document.forms["ArtikelEigenschaften"].elements["HerstellerListeAuswahl"+Nummern[i]].name+"[ ]";
		}
	}

	document.ArtikelEigenschaften.submit();

	if ( opener_reload )
	{
		window.opener.location.reload();
	}
}

//prueft, ob es innerhalb der angegebenen Form Textfelder bzw. Textareas mit leerem Inhalt gibt
function CheckInputEmptyInForm( FormName )
{
	isLeer = false;

	for ( i=0; i< document.forms[FormName].elements.length; i++ )
	{
		if ( document.forms[FormName].elements[i].type == "text" || document.forms[FormName].elements[i].type == "textarea" )
		{
			Value = document.forms[FormName].elements[i].value;

			//Leerzeichen links und rechts abschneiden
			Value = Value.replace(/\s+$/gi, "");
			Value = Value.replace(/^\s*/gi, "");

			if ( Value == "" )
			{
				isLeer = true;
				break;
			}
		}
	}

	return isLeer;
}

//prueft, ob der aktuellen Wert einer Textbox dem angegebenen Format entspricht
function CheckInputTextFormat( InputTextID, Format )
{
	Value = document.getElementById(InputTextID).value;

	switch( Format )
	{
		case "numeric":
			ValueMatch = Value.match(/^\d*$/);
		break;

		case "float":
			ValueMatch = Value.match(/^\d*(\.|,)?\d*$/);
		break;
	}

	if ( ! ValueMatch )
	{
		return false;
	}

	return true;
}

//Funktion fuer das Anzeigen bzw. verstecken von Seitenelementen
function ShowHide( DivID, ImageName, ImagePathOpen, ImagePathClose, Host )
{
	if ( document.getElementById(DivID) )
	{
		if ( document.getElementById(DivID).style.visibility == 'hidden' )
		{
			document.getElementById(DivID).style.visibility='visible';
			if (document.all ) document.getElementById(DivID).style.width=10; //wird gebraucht, damit der Explorer bei relativer Positionierung die Ebene ueberhaupt darstellt
			document.getElementById(DivID).style.position='relative';

			if ( document.images[ImageName] )
			{
				document.images[ImageName].src=ImagePathClose;
			}

			//Session umsetzen
			document.images['SessionScriptImage'].src=Host+'session_set_layer_visibility.php?visible=1&LayerID='+DivID+'&'+(new Date()).getTime();
		}
		else
		{
			document.getElementById(DivID).style.position='absolute';
			document.getElementById(DivID).style.visibility='hidden';

			if ( document.images[ImageName] )
			{
				document.images[ImageName].src=ImagePathOpen;
			}

			//Session umsetzen
			document.images['SessionScriptImage'].src=Host+'session_set_layer_visibility.php?visible=0&LayerID='+DivID+'&'+(new Date()).getTime();
		}
	}
}

//spezielle Funktion fuer die Suche des Sprachenadmins. setzt 'hidden'-felder auf sichbar bzw. verborgen, je nach Status der Ebene
function SprachenSucheSetHidden( DivID )
{
	if ( document.getElementById(DivID) )
	{
		if ( document.getElementById(DivID).style.visibility == 'hidden' )
		{
			document.Suche.SearchMode.value='0';

			if ( document.Uebersetzungen )
			{
				document.Uebersetzungen.SearchMode.value='0';
			}

			if ( document.BlaetternVon )
			{
				document.BlaetternVon.SearchMode.value='0';
			}

			document.SprachWechsel.SearchMode.value='0';
		}
		else
		{
			document.Suche.SearchMode.value='1';

			if ( document.Uebersetzungen )
			{
				document.Uebersetzungen.SearchMode.value='1';
			}

			if ( document.BlaetternVon )
			{
				document.BlaetternVon.SearchMode.value='1';
			}

			document.SprachWechsel.SearchMode.value='1';
		}
	}
}

/*
* Gibt den markierten Wert einer Radioliste zurueck. Wenn keiner ausgewaehlt ist, wird ein Leerstring zurueck gegeben.
*/
function GetCheckedValueFromRadio( RadioObject )
{
	var Value = "";

	if ( RadioObject )
	{
		if ( RadioObject.length )
		{
			for( i = 0; i < RadioObject.length; i++ )
			{
				if( RadioObject[i].checked )
				{
					Value = RadioObject[i].value;
					break;
				}
			}
		}
		else
		{
			if ( RadioObject.checked )
			{
				Value = RadioObject.value;
			}
		}
	}

	return Value;
}

/* Hebt eine Datenzeile hervor, indem die Hintergrundfarbe geaendert wird */
function HighlightDataRow( RowID, Color )
{
	Names = document.getElementById( RowID ).childNodes;

	for(i = 0; i < Names.length; i++ )
	{
		if ( Names[i].nodeName == 'TD' && Names[i].style )
		{
			Names[i].style.backgroundColor = Color;
		}
	}
}

// **************************************** InfoBox ********************************************
var InfoBoxID;
function tip( Name )
{
	InfoBoxID = Name;
	// Mausposition
	x = 0;
	y = 0;

	if ( document.getElementById( InfoBoxID ) )
	{
		document.onmousemove = mousemove; // Mausevent abfangen

		Div = document.getElementById( InfoBoxID ).parentNode.removeChild( document.getElementById( InfoBoxID ) );
		document.body.insertBefore( Div, document.body.firstChild );
		// IFrame = document.getElementById( InfoBoxID+"IFrame" ).parentNode.removeChild( document.getElementById( InfoBoxID+"IFrame" ) );
		// document.body.insertBefore( IFrame, document.body.firstChild );

		Div.style.position = 'absolute';

		WindowWith = ( window.innerWidth ) ? window.innerWidth + window.pageXOffset - 16 : document.body.offsetWidth - 20;
		WindowHeight = ( window.innerHeight ) ? window.innerHeight + window.pageYOffset : document.body.offsetHeight;

		if ( x <= 0 || y <= 0 ) // konqueror can't get mouse position
		{
			// middle of window
			x = ( WindowWith - 250 ) / 2 + ( window.pageXOffset ? window.pageXOffset : 0 );
			y = ( WindowHeight - 50 ) / 2 + ( window.pageYOffset ? window.pageYOffset : 0 );
		}

		if ( GetBrowser() == 'IE' && event.clientX )
		{
			x = event.clientX + document.body.scrollLeft;
			y = event.clientY + document.body.scrollTop;
		}

		// Goesse der Box an Inhalt anpassen
		DivWidth = Div.offsetWidth;
		DivHeight = Div.offsetHeight;

		if ( DivHeight > 40 )
		{
			Verhaeltnis = Math.sqrt( ( DivWidth * DivHeight ) / ( 16 * 9 ) ); // Verhaeltnis: 16 * 9
			Div.style.width = 16 * Verhaeltnis;
			Div.style.height = 1; // die Hoehe regelt der Browser selber
		}

		showtip( x, y );

		if ( GetBrowser() == 'IE' && DivHeight == 0 ) showtip( x, y ); // beim ersten Durchlauf kennt der IE die Hoehe noch nicht
	}
}

function showtip( x, y )
{
	Div = document.getElementById( InfoBoxID );
	IFrame = document.getElementById( InfoBoxID+"IFrame" );

	WindowWith = ( window.innerWidth ) ? window.innerWidth + window.pageXOffset - 16 : document.body.offsetWidth - 20;
	WindowHeight = ( window.innerHeight ) ? window.innerHeight + window.pageYOffset : document.body.offsetHeight;

	// Div Groesse
	DivWidth = Div.offsetWidth;
	DivHeight = Div.offsetHeight;

	// Groesse des Mauszeigers
	x = x + 12;
	y = y + 12;

	// Wenn der Div ausserhalb des Fensters laege
	if ( GetBrowser() == 'IE' )
	{
		x = ( ( ( x + DivWidth ) < WindowWith ) ? x : x - DivWidth - 20 );
		y = ( ( ( y + DivHeight ) < WindowHeight ) ? y : y - DivHeight );
	}
	else
	{
		x = ( ( ( x + DivWidth ) < WindowWith ) ? x : x - DivWidth );
		y = ( ( ( y + DivHeight ) < WindowHeight ) ? y : y - DivHeight );
	}

	Div.style.left = x;
	Div.style.top = y;
	Div.style.position = 'absolute';
	Div.style.display = 'block';

	if ( GetBrowser() == 'NS' )
	{
		Div.style.visibility = 'show';
	}
	else
	{
		Div.style.visibility = 'visible';
	}

	if ( GetBrowser() == 'IE' &&  IFrame)
	{
		IFrame.style.width = Div.offsetWidth;
	    IFrame.style.height = Div.offsetHeight;
	    IFrame.style.top = Div.style.top;
	    IFrame.style.left = Div.style.left;
//	    IFrame.style.display = 'block';
	}
}

function mousemove( e )
{
	if ( document.getElementById( InfoBoxID ) )
	{
		Div = document.getElementById( InfoBoxID );

		if ( Div.style.visibility == 'visible' || Div.style.visibility == 'show' )
		{
			if ( e )
			{
				x = e.pageX ? e.pageX : e.clientX ? e.clientX : 0;
				y = e.pageY ? e.pageY : e.clientY ? e.clientY : 0;
			}
			else if ( event )
			{
				x = event.clientX;
				y = event.clientY;
			}
			else
			{
				x = 0;
				y = 0;
			}

			if ( GetBrowser() == 'IE' ) // Workaround for scroll offset of IE
			{
				x += document.body.scrollLeft;
				y += document.body.scrollTop;
			}

			showtip( x, y );
		}
	}
}

function untip( Name )
{
	if ( document.getElementById( InfoBoxID ) )
	{
		if ( GetBrowser() == 'NS' )
		{
			Div.style.visibility = 'hide';
		}
		else
		{
			Div.style.visibility = 'hidden';
		}

		if ( GetBrowser() == 'IE' )
		{
			IFrame = document.getElementById( InfoBoxID+"IFrame" );
			if (IFrame) IFrame.style.display = 'none';
		}
	}
}


/*
var IWIDTH=250  // Tip box width
var ns4         // Are we using Netscape4?
var ie4         // Are we using Internet Explorer Version 4?
var ie5         // Are we using Internet Explorer Version 5 and up?
var kon         // Are we using KDE Konqueror?
var x,y,winW,winH  // Current help position and main window size
var idiv=null   // Pointer to infodiv container
var px="px"     // position suffix with "px" in some cases

function nsfix(){setTimeout("window.onresize = rebrowse", 2000);}

function rebrowse(){window.location.reload();}

function infoinit(){
	ns4=(document.layers)?true:false, ie4=(document.all)?true:false;
	ie5=((ie4)&&((navigator.userAgent.indexOf('MSIE 5')>0)||(navigator.userAgent.indexOf('MSIE 6')>0)))?true:false;
	kon=(navigator.userAgent.indexOf('konqueror')>0)?true:false;
	x=0;y=0;winW=800;winH=600;
	idiv=null;
	document.onmousemove = mousemove;
	if(ns4&&document.captureEvents) document.captureEvents(Event.MOUSEMOVE);
	// Workaround for just another netscape bug: Fix browser confusion on resize
	// obviously conqueror has a similar problem :-(
	if(ns4||kon){ nsfdenix() }
	if(ns4) { px=""; }
}

function untip(){
	if(idiv) idiv.visibility=ns4?"hide":"hidden";
	idiv=null;
}

function gettip(name)
{
	if ( document.layers && document.layers[name] ) // NS
	{
		return document.layers[name];
	}
	else if (document.all&&document.all[name]&&document.all[name].style) // IE
	{
		Div = document.getElementById( name ).parentNode.removeChild( document.getElementById( name ) );
		document.body.insertBefore( Div, document.body.firstChild );
		IFrame = document.getElementById( name+"IFrame" ).parentNode.removeChild( document.getElementById( name+"IFrame" ) );
		document.body.insertBefore( IFrame, document.body.firstChild );
		return document.all[name].style;
	}
	else if ( document[name] )
	{
		return document[name];
	}
	else if ( document.getElementById(name) )
	{
		return document.getElementById(name).style;
	}
	else
	{
		return 0;
	}
}

function tip(name)
{
	if(idiv) untip();

	idiv = gettip( name );

	if( idiv )
	{
		winW = ( window.innerWidth ) ? window.innerWidth + window.pageXOffset - 16 : document.body.offsetWidth - 20;
		winH = ( window.innerHeight ) ? window.innerHeight + window.pageYOffset : document.body.offsetHeight;

		if ( x <= 0 || y <= 0 ) // konqueror can't get mouse position
		{
			// middle of window
			x=(winW-IWIDTH)/2+(window.pageXOffset?window.pageXOffset:0);
			y=(winH-50)/2+(window.pageYOffset?window.pageYOffset:0);
		}

		showtip(name);
	}
}

function showtip( Name )
{
	// ToDo Div Groesse
	idiv.left = ( ( ( x + 260 ) < winW ) ? x + 12 : x - 255 ) + px ;
	idiv.top = ( ( ( y + 90 ) < winH ) ? y + 12 : y - 90 ) + px;
	idiv.visibility = ns4 ? "show" : "visible";

	if ( document.all ) // IE
	{
		Div = document.getElementById( Name );
		IFrame = document.getElementById( Name+"IFrame" );
		IFrame.style.width = Div.offsetWidth;
	    IFrame.style.height = Div.offsetHeight;
	    IFrame.style.top = Div.style.top;
	    IFrame.style.left = Div.style.left;
	    IFrame.style.display = 'block';
	}
}

function mousemove(e){
	if(e)
	{
		x=e.pageX?e.pageX:e.clientX?e.clientX:0; y=e.pageY?e.pageY:e.clientY?e.clientY:0;
	}
	else if(event)
	{
		x=event.clientX; y=event.clientY;
	}
	else
	{
		x=0; y=0;
	}

	if((ie4||ie5) && document.documentElement) // Workaround for scroll offset of IE
	{
		x+=document.documentElement.scrollLeft;
		y+=document.documentElement.scrollTop;
	}

	if(idiv) showtip('');
}
// Initialize after loading the page
window.onload=infoinit;*/
// **************************************** InfoBox ********************************************


// **************************************** MsgBox *********************************************
var MessageBoxActiveInterval;
function MsgboxShow( Name )
{
	if ( document.getElementById )
	{
		Div = document.getElementById( Name ).parentNode.removeChild( document.getElementById( Name ) );
		EmptyDiv = document.getElementById( Name+"EmptyLayer" ).parentNode.removeChild( document.getElementById( Name+"EmptyLayer" ) );
		document.body.insertBefore( Div, document.body.firstChild );
		document.body.insertBefore( EmptyDiv, document.body.firstChild );

		if ( document.all ) // IE
		{
			Width = ( document.body.offsetWidth / 2 ) - 150;
			Height = ( document.body.offsetHeight / 2 ) - 100;
			Div.style.position = 'absolute';
			EmptyDiv.style.position = 'absolute';
			MessageBoxActiveInterval = window.setInterval( "MsgboxMove('"+Name+"')", 100 );
		}
		else // NS | Mozilla
		{
			Width = ( window.innerWidth / 2 ) - 150;
			Height = ( window.innerHeight / 2 ) - 100;
			Div.style.position = 'fixed';
			EmptyDiv.style.position = 'fixed';
		}

		Div.style.left = Width;
		Div.style.top = Height;
		Div.style.width = 300; // wird gebraucht, damit der Explorer bei relativer Positionierung die Ebene ueberhaupt darstellt
		Div.style.visibility = 'visible';
		Div.style.display = 'block';
		Div.style.zIndex = 99;

		EmptyDiv.style.left = "1px";
		EmptyDiv.style.top = "1px";
		EmptyDiv.style.visibility = 'visible';
		EmptyDiv.style.display = 'block';
		EmptyDiv.style.zIndex = 98;

		if ( document.all ) // IE
		{
			IFrame = document.getElementById( Name+"IFrame" );
			
			if (IFrame)
			{
				IFrame = IFrame.parentNode.removeChild( IFrame );
				IFrame.style.width = Div.offsetWidth;
		    	IFrame.style.height = Div.offsetHeight;
		    	IFrame.style.top = Div.style.top;
		    	IFrame.style.left = Div.style.left;
				IFrame.style.visibility = 'visible';
		    	IFrame.style.display = 'block';
		    	IFrame.style.zIndex = 97;
				document.body.insertBefore( IFrame, document.body.firstChild );
			}
		}
	}
}

function MsgboxHide( Name )
{
	if ( document.getElementById )
	{
		Div = document.getElementById( Name );
		EmptyDiv = document.getElementById( Name+"EmptyLayer" )
		IFrame = document.getElementById( Name+"IFrame" );

		Div.style.position = 'absolute';
		Div.style.visibility = 'hidden';
		Div.style.display = 'none';

		if (IFrame)
		{
			IFrame.style.position = 'absolute';
			IFrame.style.visibility = 'hidden';
			IFrame.style.display = 'none';
		}

		EmptyDiv.style.position = 'absolute';
		EmptyDiv.style.visibility = 'hidden';
		EmptyDiv.style.display = 'none';

		window.clearInterval( MessageBoxActiveInterval );
	}
}

function MsgboxMove( Name )
{
	if ( document.all ) // IE
	{
		Div = document.getElementById( Name );
		IFrame = document.getElementById( Name+"IFrame" );

		PL = document.body.scrollLeft + document.body.offsetWidth / 2 - Div.offsetWidth / 2;
		PT = document.body.scrollTop + document.body.offsetHeight / 2 - Div.offsetHeight / 2;

		Div.style.pixelLeft = PL;
		Div.style.pixelTop = PT;

		if (IFrame)
		{
	    	IFrame.style.pixelTop = PT;
	    	IFrame.style.pixelLeft = PL;
	    }
	}
}
// **************************************** MsgBox *********************************************


//###################### CountDown-Beginn ####################################################
var cmin,csec, fkt ;
function Down( time , name , funktion )	// time =muss in Format "mm:ss" uebergeben werden
{									   // name = Name des Span oder Objektes
	cmin = 1 * Minutes( time ) ;	  // fkt = Funktion die nach Ablauf ausgefuehrt werden soll(js)
	csec = 0 + Seconds( time ) ;
	fkt = funktion ;
DownRepeat( name ) ;
}
function Minutes( data )
{
	for(var i = 0 ; i < data.length; i++ ) if( data.substring( i , i + 1 ) == ":" ) break ;
		return( data.substring( 0 , i ) ) ;
}
function Seconds( data )
{
	for( var i = 0 ; i < data.length ; i++ ) if( data.substring( i , i + 1 ) == ":" ) break ;
		return( data.substring( i + 1 , data.length ) ) ;
}
function DownRepeat( name )
{
	csec-- ;
	if( csec== -1 )
	{
		csec=59 ; cmin-- ;
	}
		document.getElementById( name ).firstChild.nodeValue=Display( cmin , csec ) ;

	if( ( cmin == 0 ) && ( csec == 0 ) ) eval( fkt ) ;
	else down=setTimeout( "DownRepeat('"+ name +"')", 1000 ) ;
}
function Display( min , sec )
{
	var disp;
	if( min <= 9 ) disp= " 0" ;
	else disp = " " ;
	disp += min + ":" ;

	if( sec <= 9 ) disp += "0" + sec ;
	else disp += sec ;

	return( disp ) ;
}
//###################### CountDown-Ende ####################################################

// Vergroessert ein Element auf die Hoehe des Eltern Elements.
function resizeToParentHeight( ElementId )
{
	if ( !document.getElementById( ElementId ) ) return;

	var Element = document.getElementById( ElementId );
	var Parent = Element.parentNode;

	if ( Parent.tagName.toLowerCase() == "tr" ) // bei Tabellen die Hoehe der Tabelle
	{
		Parent = Parent.parentNode;
	}

	Element.style.height = Parent.offsetHeight;
	Element.style.visibility = "visible";
}

// Verbreitert ein Element auf die Breite des Eltern Elements.
function resizeToParentWidth( ElementId )
{
	if ( !document.getElementById( ElementId ) ) return;

	var Element = document.getElementById( ElementId );
	var Parent = Element.parentNode;
	Element.style.width = Parent.offsetWidth;
	Element.style.visibility = "visible";
}

//resize des Artikel-tree-Layers
function resizelayer( TreeTD_ID, TreeDIV_ID, MinHeight )
{
	//articletreetd
	//articletreediv

	if ( document.getElementById(TreeTD_ID) )
	{
		y = document.getElementById(TreeTD_ID).offsetHeight;

		if ( y < MinHeight )
		{
			document.getElementById(TreeDIV_ID).style.height = MinHeight;
		}
		else
		{
			document.getElementById(TreeDIV_ID).style.height = y;
		}

		document.getElementById(TreeDIV_ID).style.width = document.getElementById(TreeTD_ID).offsetWidth;
		document.getElementById(TreeDIV_ID).style.visibility = "visible";
	}
}
//resize des Zeichnungslayers
function resizepiclayer()
{
	x = document.getElementById('bildtd').offsetHeight;

	if ( x < 365 )
	{
		document.getElementById('bilddiv').style.height = 365 ;
	}
	else
	{
		document.getElementById('bilddiv').style.height = x ;
	}
	document.getElementById('bilddiv').style.width = document.getElementById('bildtd').offsetWidth;
}

/*################## Editierleiste fuer Textarea ######################*/
function TextAreaInsert( FormName, TextAreaName, aTag, eTag)
{
  var input = document.forms[ FormName ].elements[ TextAreaName ];
  input.focus();

  /* fuer Internet Explorer */
  if( typeof document.selection != 'undefined' )
  {
    /* Einfuegen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;

    /* Anpassen der Cursorposition */
    range = document.selection.createRange();

    if (insText.length == 0)
    {
      range.move('character', -eTag.length);
    } else
    {
      range.moveStart('character', aTag.length + insText.length + eTag.length);
    }

    range.select();
  }
  /* fuer neuere auf Gecko basierende Browser */
  else if( typeof input.selectionStart != 'undefined' )
  {
    /* Einfuegen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);

    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0)
    {
      pos = start + aTag.length;
    } else
    {
      pos = start + aTag.length + insText.length + eTag.length;
    }

    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
}

/**
* @desc Setzt den aktuellen Stand des Fortschrittsbalken.
* @since 27.09.2005
* @author Detlef Habenicht
* @param Percent integer Fortschritt in Prozent.
* @param Text string Text zum Fortschritt.
* @see ProgressBar::SetCurrentProgress(), class/progress/progressbar.inc.php
*/
function UpdateProgressBar( Percent, Text )
{
	document.getElementById( 'ProgressBar_Bar' ).style.width = Percent * 2;
	document.getElementById( 'ProgressBar_Percent' ).firstChild.nodeValue = Percent+'%';
	if ( Text.length > 0 ) document.getElementById( 'ProgressBar_Text' ).firstChild.nodeValue = Text;
}

/**
* @desc Zeigt den Fortschrittsbalken an.
* @since 27.09.2005
* @author Detlef Habenicht
* @see ProgressBar::GetIframeShow(), class/progress/progressbar.inc.php
*/
function ShowProgressBar()
{
	Box = document.getElementById( 'ProgressBar_Frame' ).parentNode.removeChild( document.getElementById( 'ProgressBar_Frame' ) );
	document.body.insertBefore( Box, document.body.firstChild );
	document.body.style.overflow='hidden'; // kein Scrollen

	if ( document.all ) // IE
	{
		Width = ( document.body.offsetWidth / 2 ) - 150;
		Height = ( document.body.offsetHeight / 2 ) - 100;
		Box.style.position = 'absolute';
	}
	else // NS | Mozilla
	{
		Width = ( window.innerWidth / 2 ) - 150;
		Height = ( window.innerHeight / 2 ) - 100;
		Box.style.position = 'fixed';
	}

	Box.style.left = Width;
	Box.style.top = Height;
	Box.style.width = 400; // wird gebraucht, damit der Explorer bei relativer Positionierung die Ebene ueberhaupt darstellt
	Box.style.display = 'block';
}

/**
* @desc Blendet den Fortschrittsbalken wieder aus.
* @since 24.10.2005
* @author Detlef Habenicht
* @see ProgressBar::GetIframeShow(), class/progress/progressbar.inc.php
*/
function HideProgressBar()
{
	if ( document.getElementById( 'ProgressBar_Frame' ) )
	{
		AktDocument = document;
	}
	else
	{
		AktDocument = parent.document;
	}

	AktDocument.body.style.overflow='auto'; // Scrollen wieder erlauben
	AktDocument.getElementById( 'ProgressBar_Frame' ).style.display = 'none';
}

/**
* @desc Blendet ein beliebiges Element aus oder ein.
* @since 14.02.2006
* @author Detlef Habenicht
* @param ElementId string ID des Elements.
* @param Show string Soll das Element eine oder ausgeblendet werden? ('true', 'false', 'auto') (auto heisst das Gegenteil von seinem jetzigen Zustand)
*/
function ShowElement( ElementId, Show, DefaultDisplayType )
{
	if ( DefaultDisplayType != 'inline' ) DefaultDisplayType = 'block';

	if ( document.getElementById( ElementId ) )
	{
		Element = document.getElementById( ElementId );

		if ( Show == 'true' ) Element.style.display=DefaultDisplayType;
		else if ( Show == 'false' ) Element.style.display='none';
		else if ( Element.style.display == 'none' ) Element.style.display=DefaultDisplayType; // auto
		else Element.style.display='none'; // auto
	}
}

/**
* @desc Laesst 'blink'-Tags auch im IE blinken.
* @since 04.07.2006
* @author Detlef Habenicht
* @param Speed float Interval des Blinkens.
*/
blink( 0.7 ); // Initialisierender Aufruf
function blink( Speed )
{
	if ( document.all ) // IE
	{
		if ( Speed ) // Initialisierung
		{
			setInterval( "blink()", Speed * 1000 );
		}
		else // das Blinken
		{
			var blink = document.all.tags( "BLINK" );

			for ( var i = 0; i < blink.length; i++ )
			{
				blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "";
			}
		}
	}
}

/**
* @desc Markiert in Shop-Artikelansichten den richtigen Preis.
* @since 22.09.2006
* @author Detlef Habenicht
* @param ElementIdPrefix string Prefix zur Erkennung der Elemente.
* @param FontWeight string Schriftstil: entwder 'normal' oder 'bold'.
*/
function markPriceTabRow( ElementIdPrefix, FontWeight )
{
	for ( var i = 1; i <= 3; i++ )
	{
		if ( document.getElementById( ElementIdPrefix + '_' + i ) )
			document.getElementById( ElementIdPrefix + '_' + i ).style.fontWeight = FontWeight;
		if ( document.getElementById( ElementIdPrefix + '_VE' + i ) )
			document.getElementById( ElementIdPrefix + '_VE' + i ).style.fontWeight = FontWeight;
	}
}

/**
* @desc Resizet einen Bereich mit der Id 'OverflowArea' mit der im Dukument frei zur Verfügung stehenden Höhe. Das Tag mit der ID 'OverflowArea' sollte dann 'overflow:auto' haben.
* @since 17.11.2006
* @author Detlef Habenicht
*/
function resizeOverflowArea()
{
	var WindowHeight = ( window.innerHeight ) ? (window.innerHeight + window.pageYOffset) : document.getElementsByTagName('BODY')[0].offsetHeight;
	var OverflowArea = document.getElementById('OverflowArea');
	var ParentElem = OverflowArea;
	var OtherHeight = ParentElem.offsetTop;

	while ( ParentElem.offsetParent && !isNaN( ParentElem.offsetParent.offsetTop ) ) {
		ParentElem = ParentElem.offsetParent;
		OtherHeight += ParentElem.offsetTop;
	}

	OverflowArea.style.height = WindowHeight - OtherHeight;
	window.clearInterval( OverflowAreaInterval );
}

/**
* @desc Setzt den Inhalt des Elements mit der angegebenen Id neu. 
* @since 06.02.2009 16:41
* @author Raik Träger
* @param id string Id des Elements
* @param content string neuer Inhalt
*/
function setElementContent(id, content)
{
	$("#"+id).html(content+'');
}

/*------------ Funktionen fuer allg. Selectboxen ---------------------*/

/**
* @desc Liest die Werte aus den angegebenen Select-Elementen und erzeugt daraus ein UTC-Timestamp. 
* @since 29.08.2008 09:25
* @author Raik Träger
* @param selectYear string ID-des Select-Elementes für das Jahr
* @param selectMonth string ID-des Select-Elementes für den Monat
* @param selectDay string ID-des Select-Elementes für den Tag
* @param selectHour string ID-des Select-Elementes für die Stunde
* @param selectMinute string ID-des Select-Elementes für die Minute
* @param selectSecond string ID-des Select-Elementes für die Sekunde
*/
function getUTCTimeFromDateTimeSelects(selectYear, selectMonth, selectDay, selectHour, selectMinute, selectSecond)
{
	date = new Date();
	
	//default-Werte
	year = date.getFullYear();
	month = date.getMonth();
	day = date.getDate();
	hour = date.getHours();
	minute = date.getMinutes();
	second = date.getSeconds();
	
	//Jahr
	id = document.getElementById(selectYear);
	type = id ? new String(id.type) : new String();
	if (type.indexOf('select') == 0)
	{
		year = id.options[id.selectedIndex].value;
	}

	//Monat
	id = document.getElementById(selectMonth);
	type = id ? new String(id.type) : new String();
	if (type.indexOf('select') == 0)
	{
		month = id.options[id.selectedIndex].value;
		month -= 1;
	}
	
	//Tag
	id = document.getElementById(selectDay);
	type = id ? new String(id.type) : new String();
	if (type.indexOf('select') == 0)
	{
		day = id.options[id.selectedIndex].value;
	}
	
	//Stunde
	id = document.getElementById(selectHour);
	type = id ? new String(id.type) : new String();
	if (type.indexOf('select') == 0)
	{
		hour = id.options[id.selectedIndex].value;
	}
	
	//Minute
	id = document.getElementById(selectMinute);
	type = id ? new String(id.type) : new String();
	if (type.indexOf('select') == 0)
	{
		minute = id.options[id.selectedIndex].value;
	}

	//Sekunde
	id = document.getElementById(selectSecond);
	type = id ? new String(id.type) : new String();
	if (type.indexOf('select') == 0)
	{
		second = id.options[id.selectedIndex].value;
	}
	
	return Date.UTC(year, month, day, hour, minute, second) / 1000;
}

/**
* @desc Aktion zum verschieben von Werten zwischen 2 Selectboxen 
* @since 05.02.2009 15:45
* @author Raik Träger
* @param fromId string Id der Quellselectbox
* @param rightId string Id der Zielselectbox
*/
function selectbox_movevalues(fromId, toId)
{
	var select_from = document.getElementById(fromId);
	var select_to = document.getElementById(toId);
	
	from_length = select_from.length;
	delvalues = new Array();
	for (var i = 0; i < from_length; i++)
	{
		if (select_from[i].selected)
		{
			ind = select_to.length;
			if (!_hasValue(toId, select_from[i].value))
			{
				select_to.options[ind] = new Option(select_from[i].text, select_from[i].value, false, false);
				delvalues.push(select_from[i].value);
			}
		}
    }
	
	while (select_from.selectedIndex != -1)
	{
		select_from[select_from.selectedIndex] = null;
	}
}

function _hasValue(id, value)
{
	elem = document.getElementById(id);
	count = elem.length;
	
	for (var i = 0; i < count; i++ )
	{
		if (elem[i].value == value) return true;
	}
	
	return false;
}

/**
* @desc Wählt alle Einträge einer Mehrfachselectbox aus.
* @since 06.02.2009 15:45
* @author Raik Träger
* @param id string Id der Selectbox
*/
function selectAllEntries(id)
{
	elem = document.getElementById(id);
	len = elem.length;
	
	for (var i = 0; i < len; i++)
	{
		elem[i].selected = true;
    }
}

/**
* @desc Gibt die gesamtanzahl enthaltener Elemente fuer die angegebene Selectbox zurueck.
* @since 06.02.2009 12:54
* @author Raik Träger
* @param id string Id der Selectbox
*/
function getCountEntries(id)
{
	elem = document.getElementById(id);
	return elem.length;
}

/**
* @desc Fenster, fuer beliegigen Inhalt. Benötigt JQuery.
* @since 16.02.2009 11:53
* @author Raik Träger
* @param width integer Breite des Fensters
* @param height integer Hoehe des Fensters
* @param title string Titeltext des Fensters
* @param content string Inhalt welcher in dem Fenster angezeigt werden soll.
* @param refElement string Id des Elementes, welcher der Positionsbestimmung des Fensters dient,
* d.h. das Fenster richtet sich in der Darstellung nach diesem Element aus.
*/
function uiWindow(titletext, content, refElementId)
{
	jQuery('#uiContainerContent').html(content);

	var cumulativeOffset = function(element) {
       	var valueT = 0, valueL = 0;

       	do
        {
			valueT += element.offsetTop  || 0;
            valueL += element.offsetLeft || 0;
            element = element.offsetParent;
        } while (element);

        return [valueL, valueT];
	}

    var pos = cumulativeOffset( document.getElementById(refElementId) );
	var left = pos[0]-300 + 'px';
	var top= pos[1]-330 + 'px';
	
	jQuery('.containerPlus').css('left', left);
	jQuery('.containerPlus').css('top', top);
	jQuery('.containerPlus .n').text(titletext);

	jQuery('.containerPlus').css('display', 'block');
}

