

// ---------------------------------------------------------------
//
// Prueft, ob eine Variante gewewchselt wurde
//
// ---------------------------------------------------------------
function checkProductVariant(ProdForm,sessName,sessID)
{
	option_data_id	=	ProdForm.value;
	if(option_data_id.indexOf(":") != -1 )
	{
		var option_value = option_data_id.split (':');
		var productID	=	option_value[1];
		location.href='/product_info.php?products_id='+productID+'&'+sessName+'='+sessID;
	}
}


// ---------------------------------------------------------------
//
// Newsletterregistrierung
//
// ---------------------------------------------------------------
function checkNewsletterRegForm(oForm,fName,fEmail,oErrName,oErremail)
{
/*
	alert(oForm.emailname.value);
	alert(oForm.email.value);
	alert(oForm.action.value);
*/
	if(oForm.action.value == "subscribe")
	{
		// Pruefen, ob Name angegeben
		if( trim(oForm.emailname.value) == "" || oForm.emailname.value == fName)
		{
			alert(oErrName);
			oForm.emailname.focus();
			return false;
		}
		// Pruefen, ob E-Mail korrekt
		if( trim(oForm.email.value) == "" || oForm.email.value == fEmail || !DoCheckemailConform(trim(oForm.email.value)))
		{
			alert(oErremail);
			oForm.email.focus();
			return false;
		}
	}
	if(oForm.action.value == "delete")
	{
		// Pruefen, ob E-Mail korrekt
		if( trim(oForm.email.value) == "" || oForm.email.value == fEmail || !DoCheckemailConform(trim(oForm.email.value)))
		{
			alert(oErremail);
			oForm.email.focus();
			return false;
		}
	}
	return true;
}

// ---------------------------------------------------------------
//
//	DoCheckemail
//	@Die Funktion DoCheckemail prueft einen String auf eine 
//	gueltige Email Adresse   
//
// ---------------------------------------------------------------

function DoCheckemailConform( str )
{
	// Feld darf nicht leer sein
	if( trim(str) == '' )
	{
		return(false);
	}
	// Auf Zeichen @
	if( str.indexOf("@") == -1 )
	{
		return(false);
	}
	// Auf Zeichen -.-
	if( str.indexOf(".") == -1 )
	{
		return(false);
	}
	return(true);
}

// ---------------------------------------------------------------
//
// Zum Seitenanfang
//
// ---------------------------------------------------------------
function goPageTop()
{
	pUrl	=	location.pathname + location.search + '#Top';
	location.href=pUrl;
}


// ---------------------------------------------------------------
//
// Öffnet ein Fenster
//
// ---------------------------------------------------------------
	function oNewPopupWin()
	{

		winPara = new Array(6);
		winPara[0]	=	'';		//	URL
		winPara[1]	=	'myPopup';		//	Fenstername
		winPara[2]	=	'500';	//	Breite
		winPara[3]	=	'500';	//	Höhe
		winPara[4]	=	'no';	//	Scrollbars
		winPara[5]	=	'no';	//	Toolbars
		winPara[6]	=	'yes';	//	resizable
		for (var i=0; i<oNewPopupWin.arguments.length; i++)
		{
			winPara[i]	=	oNewPopupWin.arguments[i];
		}
		if(winPara[0] != '')
		{
			WindowName	= 	window.open('/cms/upload/popup/' + winPara[0],winPara[1],'width='+winPara[2]+',height='+winPara[3]+',dependent=yes,scrollbars='+winPara[4]+',toolbar='+winPara[5]+',resizable='+winPara[6]);
			WindowName.focus();
		}
	}

// ---------------------------------------------------------------
//
// Führt einen exec Befehl aus
//
// ---------------------------------------------------------------
function doExecCommand(c)
{
	document.execCommand(c);
}

// ---------------------------------------------------------------
//
// Druckvorschau
//
// ---------------------------------------------------------------

/*
	des isch net so eifach ...
*/


// ---------------------------------------------------------------
//
// Funktion zum zeilenweise Umschalten von Tabellenhintergründen, 
// wenn die Maus über eine Tabellenzeile fährt. Jede Tabellenzeile 
// benötigt zum korrekten Funktionieren eine eindeutige ID.
//
// ---------------------------------------------------------------

function rowRollover(myId,BackgroundColorStandard,BackgroundColorMouseOver,isInRow) {
  // myId is our own integer id, not the DOM id
  // isInRow is 1 for onmouseover, 0 for onmouseout
  var row = document.getElementById(myId);
  rowWithMouse = (isInRow) ? row : null;
  row.style.backgroundColor = (row == rowWithMouse) ? BackgroundColorMouseOver : BackgroundColorStandard;
}



// ---------------------------------------------------------------
//
// Zahl runden
//
// ---------------------------------------------------------------
	function runde(x, n)
	{
		if (n < 1 || n > 14) return false;
		var e = Math.pow(10, n);
		var k = (Math.round(x * e) / e).toString();
		if (k.indexOf('.') == -1) k += '.';
		k += e.toString().substring(1);
		return k.substring(0, k.indexOf('.') + n+1);
	}


// ---------------------------------------------------------------
//
// Filter auf numerische Werte.
//
// ---------------------------------------------------------------
function cashFilter(nCash)
{
	nCash=runde(nCash,2);
	nCash	= 	''+nCash;
	nCash 	=	nCash.replace('.',',');
	fCash	= 	'';
	// Filter anwenden
	numPos		=	-1;
	setPoint	=	0;
	for( i = (nCash.length-1); i >= 0; i -- )
	{
		if( nCash.charAt( i ) == ",")
		{
			setPoint = 1;
		}
		if(numPos==3)
		{
			// Punkt einfuegen
			fCash='.' + fCash;
			numPos=0;
		}
		if(setPoint == 1)
		{
			numPos++;
		}
		fCash=nCash.charAt( i ) + fCash;
	}
	// wenn setPoint immer noch == 0, dann gibt es keine Nachkommastellen
	numPos		=	0;
	if(setPoint==0)
	{
		// Wert initialisieren
		fCash='';
		for( i = (nCash.length-1); i >= 0; i-- )
		{
			if(numPos==3)
			{
				// Punkt einfuegen
				fCash='.' + fCash;
				numPos=0;
			}
			numPos++;
			fCash=nCash.charAt( i ) + fCash;
		}
	}
	return fCash;

}

// ---------------------------------------------------------------
//
// Numerische Eingabe (,) korrigieren.
//
// ---------------------------------------------------------------
function toDBNumber(valField)
{
	sValue	=	valField;
	if(trim(sValue) == '')
	{
		return 0;
	}
	
	sTmpValue=sValue;
	for( i = 0; i < sTmpValue.length; i ++ )
	{
		if( sTmpValue.charAt( i ) == ".")
		{
			sValue	=	sValue.replace('.','');
		}
	}
	nValue	=	sValue.replace(',','.');
	// Jeden Char prüfen
	for( var i = 0; i < nValue.length; i++ )
	{
		// Char aus dem String holen
		FieldChar = nValue.charAt(i);
		// Optionales Vorzeichen handeln
		if( (i==0) && (FieldChar == "+") && (FieldChar == "-") )
		{ continue;	}
		// testen, ob der Char im gueltigen Bereich liegt
		if( (FieldChar != "." ) && ((FieldChar < "0") || (FieldChar > "9")) )
		{
			return 0;
		}
	}
	return parseFloat(nValue);
}


/*
function click(e){if (document.all) if (event.button == 2) return false;if
(document.layers) if (e.which == 3) return false;}
function click2(){event.returnValue=false;return false;}if (document.layers)
document.captureEvents(Event.MOUSEDOWN);document.onmousedown=click;document.oncontextmenu=click2;
*/


nn4 = (document.layers)? true:false
ie4 = (document.all)? true:false
function CheckEnterPressed(Ereignis) {
 if (nn4) var taste=Ereignis.which
 if (ie4) var taste=event.keyCode
 if (taste==13) {return true;}
 return false;
}

	function checkEnterForSearch(e)
	{
		var characterCode;

		if(e && e.which)
		{
			e = e;
			characterCode = e.which
		}
		else
		{
			e = event;
			characterCode = e.keyCode;
		}

		if(characterCode == 13)
		{
			search();
		}
	}

	function submitt(aktion,toAnchor)
	{
		if(toAnchor)
		{
			document.form1.action = document.form1.action + '#' + toAnchor;
		}
				
		document.form1.aktion.value=aktion;
		document.form1.submit();
	}



	function openAdminWin()
	{
		var adminWin;
		adminWin = window.open('/intranet/admin/user/user.php','adminWin','width=700,height=275,dependent=yes,scrollbars=no,statusbar=no,toolbar=no,resizable=no');
		adminWin.focus();
	}


	function StartOpenNewWindow(paurl,pawidth,paheight,pascrollbars,patoolbar,WindowName)
	{
		WindowName	= 	window.open( paurl,WindowName,'width='+pawidth+',height='+paheight+',dependent=yes,scrollbars='+pascrollbars+',toolbar='+patoolbar+',resizable=yes');
		WindowName.focus();
	}


// ---------------------------------------------------------------
//
//	trim
//	@Die Funktion trim uebernimmt einen String entfernt
//	 ggf. vorausstehende sowie anhaengende Blanks und 
//	 gibt den (modifizierten) String wieder zurueck.   
//
// ---------------------------------------------------------------

function trim( str )
{
	var n;
	var i;

	// initialisieren der Blanks vor dem String i entspricht dem ersten Index		 
	for( i = 0; i < str.length; i ++ )
	{
		if( str.charAt( i ) != " ") { break; }
	}
	
	// initialisieren der Blanks nach dem String n entspricht dem zweiten Index	
	for( n = str.length-1; n >= i; n -- )
	{
		if( str.charAt( n ) != " " ) { break; }
	}

	// Ausschneiden des Stringabschnittes	
	str=str.substring( i, n+1 );

	// Rueckgabe des modifizierten Strings   
	return(str);
	
} // trim


// ---------------------------------------------------------------
//
//	stringToTime
//	@Uhrzeiteingabe im Format <HH:mm>
//  @<datum>: zu wandelnder String
//
// ---------------------------------------------------------------

function stringToTime( patime ,errorMsg_a,errorMsg_b,errorMsg_c)
{
	var i, j, str, ch;
	var anzPunkte = 0;

	// ---
	// Konsitenzpuefungen
	// ---
	if( patime.length != 5 )
	{
		errorMsg_a	=	errorMsg_a.replace('%a',patime);
		alert( errorMsg_a );
		return( null );
	}
	for( i = 0; i < patime.length; i ++ )
	{
		ch = patime.charAt( i );
		if( ch == ':' )
		{ 
			anzPunkte ++;
		}
		else
		{
			if( ch < '0' || ch > '9' )
			{
				errorMsg_b	=	errorMsg_b.replace('%a',patime);
				errorMsg_b	=	errorMsg_b.replace('%b',ch);
				alert( errorMsg_b );
				return( null );
			}
		}
	}
	if( anzPunkte != 1 )
	{
		errorMsg_c	=	errorMsg_c.replace('%a',patime);
		alert( errorMsg_c );
		return( null );
	}

	// Alles OK
	return(true);
	
} // stringToTime

