// ######################################################################
// ### Variabelndeklaration
var sNUMERIC			= "0123456789";
var sALPHABETIC		= "abcdefghijklmnopqrstuvwxyz´`-+";
var sALPHANUMERIC	= sNUMERIC + sALPHABETIC;

var sInValidChars	= "\"'";
var sError				= "";

var sLayerGlob		= "";
var loaded				= false;

var is						= new isObj();

// ######################################################################
// ### Browsertyp feststellen
function isObj() {
  var agt			= navigator.userAgent.toLowerCase();

  this.Major	= parseInt( navigator.appVersion );

  this.Nav		= agt.indexOf('mozilla') != -1 && 
								agt.indexOf('spoofer') == -1 && 
								agt.indexOf('compatible') == -1;
  this.Nav4		= this.Nav && this.Major == 4;
  this.Nav6		= this.Nav && this.Major >= 5;

  this.IE			= agt.indexOf('msie') != -1;
  this.IE4		= this.IE && this.Major <= 4;
  this.IE5		= this.IE && this.Major >= 5;
}


// ######################################################################
// ### function to check a string
function isValid(sData, sValidChars, iMinSize, iMaxSize)
{
	sError	= "";
	sData	= sData.toLowerCase();

	// Check size
	if( String(sData).length < iMinSize || String(sData).length > iMaxSize )
	{
		sError = "Please fill out all required fields correctly.";
		return false;
	}

	// Check sValidChars and sInValidChars
	for( iCounter = 0; iCounter < String(sData).length; iCounter++ )
	{
		// sValidChars
		if( String(sValidChars).length >= 1 &&
		    sValidChars.indexOf(sData.charAt(iCounter)) == -1 )
		{
			sError = "Please fill out all required fields correctly.";
			return false;
		}

		// sInValidChars
		if( String(sInValidChars).length >= 1 &&
		    sInValidChars.indexOf(sData.charAt(iCounter)) != -1 )
		{
			sError = "Please fill out all required fields correctly.";
			return false;
		}
	}

	// Value is ok
	return true;

} // isValid

// ######################################################################
// ### function to open the order window
function openOrder( sProductno, sQty, sPath ) {
 fenster = window.open( sPath + 'confirmproduct.jsp?productno=' + escape(sProductno).replace(/\+/g, "%2B") + '&qty=' + sQty + '&quarterly=0', 'order1', 'width=600,height=300,left=0,top=90' );
 fenster.focus();
} // openOrder

// ######################################################################
// ### function to open the order window
// ### quarterly only
function openOrderQuarterly( sProductno, sQty, sPath ) {
 fenster = window.open( sPath + 'confirmproduct.jsp?productno=' + escape(sProductno).replace(/\+/g, "%2B") + '&qty=' + sQty + '&quarterly=1', 'order1', 'width=600,height=300,left=0,top=90' );
 fenster.focus();
} // openOrder

// ######################################################################
// ### function to open the detail window
function openDetail( sProductno, sPage ) {
 var sLink = sPage + "?productno=" + escape(sProductno).replace(/\+/g, "%2B");
 fenster = window.open( sLink, "Fenster2", "scrollbars=yes,width=500,height=700,top=0,left=200" );
 fenster.focus();
} //openDetail

// ######################################################################
// ### function to open result.jsp or resultManufacturer.jsp from search.jsp
function openResult( sPath ) {
 var sLink;
 if( document.searchform.searchby[0].checked )
   sLink = sPath + 'searchResult.jsp?keyword=' + document.searchform.keyword.value;
 else
   sLink = sPath + 'searchResultManufacturer.jsp?keyword=' + document.searchform.keyword.value;

 window.location.href = sLink;
} //openEshop

// ######################################################################
// ### function to open the news window(s)
function openNews( sFilename ) {
 fenster = window.open( sFilename, 'news', 'scrollbars=yes,width=550,height=550,left=185,top=20' );
 fenster.focus();
} // openNews

// ######################################################################
// ### function to open the SATA window
function openSata( sPath ) {
 fenster = window.open( sPath + 'eshop_sata.jsp', 'SATA', 'width=400,height=250,left=90,top=90' );
 fenster.focus();
} // openSata

// ######################################################################
// ### function to open the BASF window
function openBasf( sPath ) {
 fenster = window.open( sPath + 'eshop_basf.jsp', 'BASF', 'width=650,height=650,left=90,top=20,scrollbars=yes' );
 fenster.focus();
} // openBasf

// ######################################################################
// ### function to open the Tec.Notes picture window
function openPicture( sFilename, sRootPath ) {
 fenster = window.open( sRootPath + 'service/tecpics/showPicture.jsp?filename=' + sFilename, 'DetailedPicture', 'width=600,height=600,left=90,top=90' );
 fenster.focus();
} // openPicture

// ######################################################################
// ### Werte von sold to nach ship to uebertragen
// ### For cartPersonal.jsp only
function transfer() {
	document.sold.sName2.value	= document.sold.sName.value;
	document.sold.sAttn2.value	= document.sold.sAttn.value;
	document.sold.sStreet2.value	= document.sold.sStreet.value;
	document.sold.sCity2.value	= document.sold.sCity.value;
	document.sold.sState2.value	= document.sold.sState.value;
	document.sold.sZip2.value	= document.sold.sZip.value;
	document.sold.sTel2.value	= document.sold.sTel.value;
	document.sold.sFax2.value	= document.sold.sFax.value;
	document.sold.sMail2.value	= document.sold.sMail.value;
} // transfer

// ######################################################################
// ### Werte vor dem Abschicken ueberpruefen
// ### For cartPersonal.jsp only
function checkSend() {
	var bContinue	= true;
	var sName	= "";
	var sValue	= "";

	// Alle Elemente ausser sMail und sMail2 des Formulars sold auf Inhalt pruefen
	for( i = 0; i < document.sold.elements.length && bContinue; i++ ) {
		sName	= document.sold.elements[i].name;
		sValue	= document.sold.elements[i].value;

		// Mailfelder auf Mailadressen ueberpruefen
		if( sName == "sMail" || sName == "sMail2" ) {
			if( !isValidEmail( sValue ) ) bContinue = false;
		} else if( sName == "sTel" || sName == "sTel2"
			|| sName == "sFax" || sName == "sFax2" ) {
			bContinue = isValidTel( sValue );
		} else if( sName == "copy" || sName == "sCode" || sName == "sContact" ) {
			// Da copy ein Button ist, passiert hier nichts
			// Dealership Felder werden ignoriert
		} else if( sName == "sZip" || sName == "sZip2" ) {
			if( !isValid( sValue, sNUMERIC, 4, 5 ) )
			bContinue = false;
		} else if( !isValid( sValue, sALPHANUMERIC + ".-/ ", 2, 20 ) )
			bContinue = false;
	} // for

	// Wenn alle Felder ausgefuellt sind, dann weiter, sonst erstes
	// fehlerhaftes Feld auswaehlen und Fehlermeldung ausgeben
	if( bContinue ) document.sold.submit();
	else {
		document.sold.elements[i-1].focus();
		alert( sError );
	} // else
} // checkSend

// ######################################################################
// ### function isValidEmail
function isValidEmail( sValue ) {
	// Emailfelder duerfen auch leer bleiben
	if( sValue.length == 0 ) return true; // Alles i.O.

	// Test auf Richtigkeit der Emailadresse, keine Sonderzeichen,
	// Leerzeichen, aber min. ein @ und ein .
	if(	isValid( sValue, sALPHANUMERIC + "@.-", 0, 50 ) &&
		sValue.indexOf( "@" ) != -1 &&
		sValue.indexOf( "." ) != -1 )
		return true; // Alles i.O.

	sError = "The e-mail address is invalid.";
	return false;
} // isValidEmail

// ######################################################################
// ### function isValidTel
function isValidTel( sValue ) {
	if( !isValid( sValue, sNUMERIC + "/- ", 4, 50 ) ) {
		sError = "The telephone or faxnumber is invalid.";
		return false;
	} // if
	return true;
} // isValidTel

// ######################################################################
// ### Funktionen fuer den OnMouseOver-Effekt in Contact-Bereich
// ######################################################################

// ######################################################################
// ### Diese Funktion blendet auf der aktuellen Seite den Layer mit
// ### uebergebenen layerID ein
function showLayer( varlayerID ) {
  if ( loaded ) {
    // Test, ob Netscape Navigator 4
    if( is.Nav4 )
      window.document.layers[varlayerID].visibility = 'show';
    else if( is.IE4 )
      document.all[varlayerID].style.visibility = 'visible';
    else
      document.getElementById(varlayerID).style.visibility = 'visible';
  } // Ende if loaded
} // showLayer


// ######################################################################
// ### Diese Funktion blendet auf der aktuellen Seite den Layer mit
// ### uebergebenen layerID aus
function hideLayer( varlayerID ) {
  if ( loaded ) {
    // Test, ob Netscape Navigator 4
    if( is.Nav4 )
      window.document.layers[varlayerID].visibility = 'hidden';
    else if( is.IE4 )
      document.all[varlayerID].style.visibility = 'hidden';
    else
      document.getElementById(varlayerID).style.visibility = 'hidden';
    //alert( varlayerID );
  } // Ende if loaded
} // hideLayer

// ######################################################################
// ### Event MouseMove abfangen
function capMouseMove() {
	if( is.IE ) document.onmousemove = MouseMove;
	else if( is.Nav4 ) document.captureEvents( Event.MOUSEMOVE );
	else document.addEventListener( "mousemove", MouseMove, true );
} // capMouseMove

// ######################################################################
// ### Funktion zum Verschieben eines Layers beim Bewegen der Maus
function MouseMove(e) {
	// Mausposition in x und y speichern
	var x = (is.Nav4||is.Nav6) ? e.pageX : event.x + document.body.scrollLeft;
	var y = (is.Nav4||is.Nav6) ? e.pageY : event.y + document.body.scrollTop;

	if( sLayerGlob != "" ) {
		if( is.Nav4 ) {
			window.document.layers[sLayerGlob].x = x + 15;
			window.document.layers[sLayerGlob].y = y + 15;
		} else if( is.IE4 ) {
			document.all[sLayerGlob].style.left = ( x + 15 ) + "px";
			document.all[sLayerGlob].style.top = ( y + 15 ) + "px";
		} else {
			document.getElementById(sLayerGlob).style.left = ( x + 15 ) + "px";
			document.getElementById(sLayerGlob).style.top = ( y + 15 ) + "px";
		} // if ... else
	} // if sLayerGlob

  return true;
} // mouseMove

// ######################################################################
// ### Funktion zum Schreiben in einen Layer
function writeTextToLayer( sText ) {
	if( is.Nav4 ) {
		document.layers[sLayerGlob].document.open();
		document.layers[sLayerGlob].document.write( sText );
		document.layers[sLayerGlob].document.close();
	} else {
		document.getElementById( sLayerGlob ).innerHTML = sText;
	} // if ... else
} // writeTextToLayer