//----------------------------------------------------
	
	function openWindow(file, name, width, height, top, left, scroll, resizable)
	{			
		/*
		if(typeof thisPopUp == "object")
		{		
			thisPopUp.blur();
			thisPopUp.close();
		}
		*/
		// thisPopUp = window.open(file, name, "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",scrollbars=" + scroll + ",resizable=" + resizable);
		thisPopUp = window.open(file, name, "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",scrollbars=" + scroll + ",resizable=" + resizable + 'location=no,menubar=no,status=yes,toolbar=no');
		thisPopUp.focus();
		
		return false;
	}

//----------------------------------------------------

	function setFocus(formularName, formularField)
	{
		if(window.document.forms[formularName])
		{
			window.document.forms[formularName].elements[formularField].focus();
		}
	}

//----------------------------------------------------

	function checkSearchFields(formularName, caller)
	{
		var checkReturn = false;
		var form = window.document.forms[formularName];
		var searchWarning = "Sie haben in der Suche nichts ausgewählt!";
		
		var checkFields = "";
		
		if(caller == "submitMatchcode")
		{	
			checkFields += form.elements["searchMatchcode1"].value;
			checkFields += form.elements["searchVehicleGroup"].options[form.elements["searchVehicleGroup"].selectedIndex].text;
			checkFields += form.elements["searchCompany1"].options[form.elements["searchCompany1"].selectedIndex].text;
			checkFields += form.elements["searchProfile1"].options[form.elements["searchProfile1"].selectedIndex].text;
			checkFields += form.elements["searchEinsatz"].options[form.elements["searchEinsatz"].selectedIndex].text;		
		}
		else if(caller == "submitDimension")
		{
			checkFields += form.elements["searchWidth"].value;
			//checkFields += form.elements["searchDimension"].value;
			//checkFields += form.elements["searchSpeed"].value;
			checkFields += form.elements["searchRims"].options[form.elements["searchRims"].selectedIndex].text;
			checkFields += form.elements["searchDiameter"].value;
			checkFields += form.elements["searchCompany2"].options[form.elements["searchCompany2"].selectedIndex].text;
			checkFields += form.elements["searchProfile2"].options[form.elements["searchProfile2"].selectedIndex].text;
			checkFields += form.elements["searchEinsatz2"].options[form.elements["searchEinsatz2"].selectedIndex].text;
		}
		else if(caller == "submitArticle")
		{
			checkFields = checkFields + form.elements["searchPartNumber"].value;
		}
		else if(caller == "submitTubesMatchcode")
		{
			checkFields += form.elements["searchMatchcode2"].value;
		}
		else if(caller == "submitTubesArticle")
		{
			checkFields += form.elements["searchPartNumber2"].value;
		}
		else if(caller == "submitVehicles")
		{
			if(form.elements["searchCompany3"].options.length > 1)
			{
				checkFields = form.elements["searchCompany3"].options[form.elements["searchCompany3"].selectedIndex].text;
				searchWarning = "Bitte wählen Sie einen Fahrzeug-Hersteller aus!";
			}
			if(form.elements["searchVehicleModel"].options.length > 1)
			{
				checkFields = form.elements["searchVehicleModel"].options[form.elements["searchVehicleModel"].selectedIndex].text;
				searchWarning = "Bitte wählen Sie ein Fahrzeug-Modell aus!";
			}		
			if(form.elements["searchVehicleType"].options.length > 1)
			{
				checkFields = form.elements["searchVehicleType"].options[form.elements["searchVehicleType"].selectedIndex].text;
				searchWarning = "Bitte wählen Sie einen Fahrzeug-Typ aus!";
			}
		}
		
		//REPLACE Bitte wählen AND EMPTY SPACES: -> EMPTY OPTIONS
			checkFields = checkFields.replace(/Bitte wählen/gi, "");
			checkFields = checkFields.replace(/ /, "");
			
		if(checkFields != "") { checkReturn = true; }
		else { window.alert(searchWarning); }
		
		return checkReturn;
	}


//----------------------------------------------------

	function setBgColor(caller, menuePlace)
	{		
		var parentFrame;
		var navMenue = new Array();
		// navMenue[0] = new Array("produktsuche", "komplettsuche", "fahrzeugsuche", "reifensuche", "schlauchsuche", "downloads", "stammdaten", "startseite", "warenkorb", "kontakt", "impressum", "beenden", "login");	
		// navMenue[0] = new Array("aktuelles", "produktsuche", "downloads", "stammdaten", "startseite", "warenkorb", "kontakt", "impressum", "beenden", "login", "felgenberatung");	
		navMenue[0] = new Array("aktuelles", "produktsuche", "fahrzeugsuche", "reifensuche", "schlauchsuche", "downloads", "stammdaten", "startseite", "warenkorb", "kontakt", "impressum", "beenden", "login", "felgenberatung");	
		// navMenue[1] = new Array("startseite", "warenkorb", "kontakt", "impressum", "beenden", "login");
		
		if(menuePlace == "topFrame")
		{
			menueFrame = menuePlace;
			menuePlace = 0;
			parentFrame = "bottomFrame";		
		}
		else if(menuePlace == "bottomFrame")
		{
			menueFrame = menuePlace;
			menuePlace = 1;
			parentFrame = "topFrame";
		}
		
		if(window.document.getElementById(caller))
		{
			window.document.getElementById(caller).style.backgroundColor = "#000000";
			window.document.getElementById(caller).firstChild.style.color = "#F7E300";			
		}
		else if(parent.frames[menueFrame])
		{
			if(parent.frames[menueFrame].document.getElementById(caller))
			{		
				parent.frames[menueFrame].document.getElementById(caller).style.backgroundColor = "#000000";
				parent.frames[menueFrame].document.getElementById(caller).firstChild.style.color = "#F7E300";			
			}
		}
		
		//alert(navMenue.length);
		for(k = 0 ; k < navMenue.length ; k++)
		{		
			if(navMenue[k] == navMenue[menuePlace])
			{
				for(i = 0 ; i < navMenue[menuePlace].length ; i++)
				{
					if(navMenue[menuePlace][i])
					{
						if(navMenue[menuePlace][i] != caller)
						{
							if(window.document.getElementById(navMenue[menuePlace][i]))
							{	
								window.document.getElementById(navMenue[menuePlace][i]).style.backgroundColor = "";
								window.document.getElementById(navMenue[menuePlace][i]).firstChild.style.color = "";
							}
						}					
					}
				}
			}
			else
			{
				for(i = 0 ; i < navMenue[k].length ; i++)
				{
					if(parent.frames[parentFrame].document.getElementById(navMenue[k][i]))
					{
						parent.frames[parentFrame].document.getElementById(navMenue[k][i]).style.backgroundColor = "";
						parent.frames[parentFrame].document.getElementById(navMenue[k][i]).firstChild.style.color = "";
					}
				}
			}		
		}
	}

//----------------------------------------------------

	function setStyle(caller, menuePlace)
	{		
		var parentFrame;
		var navMenue = new Array();	
		navMenue[0] = new Array("reifensucheNav", "fahrzeugsucheNav", "schlauchsucheNav", "komplettsucheNav");	
		
		
		if(menuePlace == "topFrame")
		{
			menueFrame = menuePlace;
			menuePlace = 0;
			parentFrame = "bottomFrame";		
		}
		else if(menuePlace == "bottomFrame")
		{
			menueFrame = menuePlace;
			menuePlace = 1;
			parentFrame = "topFrame";
		}
		
		if(window.document.getElementById(caller))
		{
			window.document.getElementById(caller).style.fontWeight = "bold";			
		}
		else if(parent.frames[menueFrame].document.getElementById(caller))
		{		
			parent.frames[menueFrame].document.getElementById(caller).style.fontWeight = "bold";		
		}
		
		
		//alert(navMenue.length);
		for(k = 0 ; k < navMenue.length ; k++)
		{		
			if(navMenue[k] == navMenue[menuePlace])
			{
				for(i = 0 ; i < navMenue[menuePlace].length ; i++)
				{
					if(navMenue[menuePlace][i])
					{
						if(navMenue[menuePlace][i] != caller)
						{
							if(window.document.getElementById(navMenue[menuePlace][i]))
							{							
								window.document.getElementById(navMenue[menuePlace][i]).style.fontWeight = "";	
							}
						}					
					}
				}
			}
			else
			{
				for(i = 0 ; i < navMenue[k].length ; i++)
				{
					if(parent.frames[parentFrame].document.getElementById(navMenue[k][i]))
					{
						parent.frames[parentFrame].document.getElementById(navMenue[k][i]).style.fontWeight = "";	
					}
				}
			}		
		}
	}

//----------------------------------------------------

	function setLayerVisibility(layerName, visibility)
	{		
		// CHECK
			var checkWindowEvent;
			// checkWindowEvent = 1;
			if(window.event) { checkWindowEvent = 1; }
		
		//SET TIME FOR HIDING LAYER:
			if(layerName == "imageLayer") { hideAfterTime = 100000; }
			else if(layerName == "legendLayer" || layerName == "legendLayer2") { hideAfterTime = 10000; }
			else if(layerName == "displayVehicleTypes" ) { hideAfterTime = 0; }		 
			
		if(visibility == "visible")
		{
			//SET x-POSITION									
				if(checkWindowEvent)
				{	
					if(layerName == "imageLayer") { xKorr = -430; }
					else if(layerName == "legendLayer" || layerName == "legendLayer2") { xKorr = -240; }		
					else if(layerName == "displayVehicleTypes") { xKorr = 200; /* -700; */ }				
					
					if(layerName == "displayVehicleTypes")
					{
						window.document.getElementById(layerName).style.left = xKorr;
					}
					else
					{
						window.document.getElementById(layerName).style.left = window.event.x + xKorr;
					}	
					
				}			
				else
				{
					if(layerName == "imageLayer") { xKorr = 200; }
					else if(layerName == "legendLayer" || layerName == "legendLayer2") { xKorr = 660; }
					else if(layerName == "displayVehicleTypes") { xKorr = 200; }	
					window.document.getElementById(layerName).style.left = xKorr;				
				}
				
			//SET y-POSITION			
				if(layerName == "imageLayer") { yKorr = 0; }
				else if(layerName == "legendLayer" || layerName == "legendLayer2")
				{	
					if(checkWindowEvent)
					{
						yKorr = window.event.y;
					}
					else
					{
						yKorr = 60;
					}
				}	
				else if(layerName == "displayVehicleTypes") { yKorr = 0; }
				window.document.getElementById(layerName).style.top = document.body.scrollTop + yKorr;			
			
			//IF IMAGE LAYER WAS STARTED : HIDE LEGEND LAYER
				/*
				if(layerName == "imageLayer" || layerName == "legendLayer2")
				{				
					window.document.getElementById(layerName).style.visibility = "hidden";
				}
				*/
				
			//HIDE LAYER AFTER DEFINED TIME
				if(hideAfterTime > 0)
				{
					setTimeout("setLayerVisibility('" +  layerName + "' ,'hidden')",  hideAfterTime  );
				}
		}	
		
		window.document.getElementById(layerName).style.visibility = visibility;
	}

//----------------------------------------------------

	function setImageLayerContent(layerName, visibility, imageName, imageSource, imageHeader, imageText, imageWidth, imageHeight)
	{
		var imageFolder = "_products/";
		window.document.images[imageName].src = imageFolder + imageSource;	
		window.document.getElementById("imageLayerTitle").firstChild.nodeValue = imageHeader;
		
		imageText = imageText.replace(/###BR###/g, "<br>");	
		window.document.getElementById("imageLayerText").innerHTML = imageText;
		// window.document.all[layerName].style.width = (imageWidth + 200) + "px";
		// window.document.all[layerName].style.height = (imageHeight + 40)+ "px";
		
		setLayerVisibility(layerName, visibility);
	} 

//----------------------------------------------------

	function writeDisplayBasket(amountBasket)
	{
		if(parent.frames["bottomFrame"])
		{
			if(parent.frames["bottomFrame"].document.getElementById("displayBasket"))
			{
				parent.frames["bottomFrame"].document.getElementById("displayBasket").firstChild.nodeValue = amountBasket;
			}
		}
	}

//----------------------------------------------------

	function sortResult(page, formularName, caller)
	{
		form = window.document.forms[formularName];
		form.elements["sortField"].value = caller;
		form.action = page;	
		form.submit();
	}

//----------------------------------------------------

	function checkIfEnterWasPressed(formularName)
	{
		var key;
		
		if(window.event)
		{
			key = window.event.keyCode;
		}	
		if(key == "13")
		{
			window.document.forms[formularName].submit();
		}	
	}

//----------------------------------------------------

	function deleteEntries(formularName, targetFormularElement)
	{
		while (document.forms[formularName].elements[targetFormularElement].length > 0)
		{
			document.forms[formularName].elements[targetFormularElement].options[document.forms[formularName].elements[targetFormularElement].length - 1] = null;
		}
	}
	
	function setNewOptions(formularName, callingFormularElement, targetFormularElement)
	{
		optionArray = window.document.forms[formularName].elements[callingFormularElement].options[window.document.forms[formularName].elements[callingFormularElement].selectedIndex].text;
		
		//SELECT ARRAY CONCINATED IN search.php
			if(callingFormularElement == "searchCompany3")
			{
				arrOptionsLibrary = arrVehicleModels;
				deleteEntries(formularName, 'searchVehicleType');
			}
			else if(callingFormularElement == "searchVehicleModel")
			{
				selectedCompanyName = window.document.forms[formularName].elements["searchCompany3"].options[window.document.forms[formularName].elements["searchCompany3"].selectedIndex].text;
				arrOptionsLibrary = arrVehicleTypes[selectedCompanyName];
			}
			else if(callingFormularElement == "searchCompany1")
			{
				arrOptionsLibrary = arrCompanyProfiles;
				//deleteEntries(formularName, 'searchVehicleType');
			}
			else if(callingFormularElement == "searchCompany2")
			{
				arrOptionsLibrary = arrCompanyProfiles;
				//deleteEntries(formularName, 'searchVehicleType');
			}
		
		// delete all entries from select box
			deleteEntries(formularName, targetFormularElement);
		
		// add default value
			if(callingFormularElement != "searchVehicleModel")
			{	
				newOption = new Option('Bitte wählen', '', false, true);
				document.forms[formularName].elements[targetFormularElement].options[document.forms[formularName].elements[targetFormularElement].length] = newOption;
			}
		
		//ADD NEW OPTIONS	
			if(arrOptionsLibrary[optionArray])
			{
				for (i = 0; i < arrOptionsLibrary[optionArray].length; i++)
				{
					newValue = arrOptionsLibrary[optionArray][i];
					newText  = arrOptionsLibrary[optionArray][i];
					newOption = new Option(newText, newValue, false, true);
					document.forms[formularName].elements[targetFormularElement].options[document.forms[formularName].elements[targetFormularElement].length] = newOption;
				}
			}
		//SELECT DEFAULT OPTION
			if(document.forms[formularName].elements[targetFormularElement].options[0])
			{
				document.forms[formularName].elements[targetFormularElement].options[0].selected = true;
			}	
	}
  
//----------------------------------------------------

	function setOptionSelection(formularName, formularElement, selectedOptionText)
	{
		formElement = window.document.forms[formularName].elements[formularElement];
		optionsLength = formElement.options.length;
		for(i = 0 ; i < optionsLength ; i++)
		{
			if(formElement.options[i].text == selectedOptionText)
			{
				formElement.selectedIndex = i;
			}
		}
	}

//----------------------------------------------------

	function panicSwitch(stringURL)
	{		
		if(parent.frames["topFrame"] && parent.frames["mainFrame"])
		{
			// SET VISIBILTY OF TOPFRAME LOGO				
				// GET VISIBILTY
					
						var showEK = "";
						var switchType = parent.frames["topFrame"].document.getElementById("topLogo").style.visibility;
						if(switchType == "hidden") { switchType = "visible"; }
						else { switchType = "hidden"; }				
				// END GET VISIBILTY
				parent.frames["topFrame"].document.getElementById("topLogo").style.visibility = switchType;		
			// END SET VISIBILTY OF TOPFRAME LOGO
			
			// SET NEW CUSTOMERS DATAS AND RELOAD MAIN FRAME		
				
				// CHECK IF OTHER VARIABLES ARE ATTACHED IN URL
					var urlSeperator = "&";
					var checkUrlSeperator = stringURL.lastIndexOf("?");
					if(checkUrlSeperator < 0) { urlSeperator = "?"; }
					
				stringURL = stringURL + urlSeperator + "switchType=" + switchType;			
				parent.frames["mainFrame"].location = stringURL;
			// END SET NEW CUSTOMERS DATAS AND RELOAD MAIN FRAME	
		}	
	}

//----------------------------------------------------
	
	
	function checkLoginFields(formularName)
	{
		answer = true;
		form = window.document.forms[formularName];
		emptyFields = "";
		arrStoreIndex = new Array();
			
		if(formularName == "formCustomerLogin")
		{
			arrFormFields = new Array("sendCustomerLogin", "sendCustomerPassword");
			arrFieldNames = new Array("Debitorennummer", "Passwort");
		}
		
		if(formularName != "")
		{
			count = 0;
			for(i = 0 ; i < arrFormFields.length ; i++)
			{
				form.elements[arrFormFields[i]].style.backgroundColor = "";			
				if(form.elements[arrFormFields[i]].value == "")
				{
					answer = false;
					emptyFields += arrFieldNames[i] + ", ";
					arrStoreIndex[count] = i;
					count++;
				}			
			}
			if(arrStoreIndex.length > 0)
			{
				form.elements[arrFormFields[arrStoreIndex[0]]].focus();
				
				for( i = 0 ; i < arrStoreIndex.length ; i++ )
				{
					if(document.getElementById)
					{
						form.elements[arrFormFields[arrStoreIndex[i]]].style.backgroundColor = "#F7C9C9";
					}
				}
			}
		}
		
		if(answer == false)
		{
			emptyFields = emptyFields.substring(0, (emptyFields.length - 2));
			window.alert("Sie haben nicht alle nötigen Daten ausgefüllt:\n " + emptyFields + "!");
		}
		
		return answer;
	}

//----------------------------------------------------

	function submitThis(formName, caller, page)
	{
		var form = window.document.forms[formName];
		var sess = form.sess.value;	
		var mode = form.mode.value;
		
		var url = page + "?sess=" + sess;
		
		if(mode == "edit")
		{
			alert('Bitte speichern Sie erst oder klicken Sie "Abbrechen"!');
		}
		else 
		{					
			if(form.elements["editID"])
			{
				editID = form.elements["editID"].options[form.elements["editID"].selectedIndex].value;
				if(editID != "") { url = url + "&editID=" + editID; }
			}
			
			window.location.href = url;				
		}
		// alert(url);	
	}

//----------------------------------------------------

	function showSubMenue(elementId)
	{		
		var elementDiv = elementId + "Div";
		if(window.document.getElementById(elementDiv))
		{				
			var visibility = window.document.getElementById(elementDiv).style.visibility;
			
			if(visibility == "visible")
			{
				window.document.getElementById(elementDiv).style.visibility = "hidden";		
				window.document.getElementById(elementDiv).style.display = "none";	
			}
			else
			{
				window.document.getElementById(elementDiv).style.visibility = "visible";
				window.document.getElementById(elementDiv).style.display = "block";
			}			
		}
		if(elementId == "")
		{
				window.document.getElementById('produktsucheDiv').style.visibility = "hidden";		
				window.document.getElementById('produktsucheDiv').style.display = "none";	
		}
	}

//----------------------------------------------------

	function checkFrameset(page)
	{
		if(page == "") { page = "main.php"; }
		if(parent.frames.length == 0) {window.document.location.href="index.php?page="+page;}
	}

//----------------------------------------------------

	function getVehicleTypes(fileURL)
	{	
		fileURL = "getVehicleTypesNEW.php?tyresID="+fileURL;
		setLayerVisibility('displayVehicleTypes', 'visible');
			
		var http = null;
		if (window.XMLHttpRequest) {
		   http = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		   http = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (http != null) {
		   http.open("GET", fileURL, true);
		   http.onreadystatechange = ausgeben;
		   http.send(null);
		}
		
		function ausgeben() {
		   if (http.readyState == 4) {
		      document.getElementById("displayVehicleTypes").innerHTML =
		         http.responseText;
		   }
		}			
	}
	
//----------------------------------------------------
