
	var ie=(document.all)? true:false;
	var ns=(document.layers)? true:false;
	var ns6=navigator.appName.indexOf("Netscape")!=1&& parseInt(navigator.appVersion)>=5 ;

	hide = new Array ();
	/* nitLayers
		just give an array like onload="initLayers(new Array('vendor','category','article'))"
	*/
	function initLayers(pHide) {
		var i = 0;
		for (var foundMainEntry in pHide) {
			hide[pHide[i++]]="";
		}
		var dummy = "ads";
		dummy = "";
	}
	/* init layers as array with indexes as literals for each main layer
		all sublayers should be an array with names of sublayers or an empty entry if no more sublayers
		hide['text1'] = new Array('text1sub1','text1sub2');
		hide['text2'] = new Array('text2sub1','text2sub2','text2sub3');
		hide['text3'] = "";
	*/
	function initLayerWithSubLayers(pHide) {
		hide = pHide;
	}
	function doSwitch(pEbene) {
		if (isMainLayer(pEbene)) {
			switchMainLayers(pEbene);
		}
		else {
			switchSubLayers(pEbene);
		}
	}
	
	// helpers -------------------------
	function isMainLayer(pLayerName) {
		for (var foundMainEntry in hide) {
			if (pLayerName == foundMainEntry) {
				return true;
			}
		}
		return false;
	}
	
	function getSubLayersOfLayer(pLayerName) {
		var result = null;
		for (var foundMainEntry in hide) {
			if (foundMainEntry == pLayerName) {
				if (typeof hide[foundMainEntry] == "array" || typeof hide[foundMainEntry] == "object") {
					result = hide[foundMainEntry];
					break;
				}
			}
		}
		return result;		
	}
	function switchMainLayers(pLayerName) {
		for (var foundMainEntry in hide) {
			if (pLayerName == foundMainEntry) {
				turnLayerVisibility(foundMainEntry,true);
				switchMainSubLayers(foundMainEntry,true,"");
			}
			else {
				turnLayerVisibility(foundMainEntry,false);
				switchMainSubLayers(foundMainEntry,false,"");
			}
		}
	}

	function switchMainSubLayers(pLayerName,pVisibility,pSubLayerName) {
		for (var foundMainEntry in hide) {
			if (pLayerName == foundMainEntry) {
				subLayers = getSubLayersOfLayer(pLayerName);
				if (subLayers != null) {
					for (var i = 0; i < subLayers.length; i++) {					
						// is vis true set only the first layers visible as default
						curSublayerName = subLayers[i];
						turnOn = false;
						if (pVisibility == true) {
							if (pSubLayerName != null && pSubLayerName != "") {
								if (curSublayerName == pSubLayerName) {
									turnOn = true;
								}
							}
							else {
								if (i==0) {
									turnOn = true;
								}
							}
						}
						
						turnLayerVisibility(curSublayerName,turnOn);
					}
				}
			}
		}
	}
	
	function getMainlayerNameForSublayer(pLayerName) {
		result = null;
		for (var foundMainEntry in hide) {
			subLayers = getSubLayersOfLayer(foundMainEntry);
			if (subLayers != null) {
				for (var i = 0; i < subLayers.length; i++) {					
					if (subLayers[i] == pLayerName) {
						result = foundMainEntry;
						break;
					}
				}
			}
		}
		return result;
	}
	
	function switchSubLayers(pSubLayerName) {
		mainLayer = getMainlayerNameForSublayer(pSubLayerName);
		switchMainSubLayers(mainLayer,true,pSubLayerName);
	}

	function turnLayerVisibility(pLayerName,pVisibility) {
		if(ie) {
			if (pVisibility == true) {
	    		document.all[pLayerName].style.visibility="visible";
			}
			else {
	    		document.all[pLayerName].style.visibility="hidden";
	    	}
	   	}
		if(ns) {
			if (pVisibility == true) {
	    		document.layers[pLayerName].visibility="show";
			}
			else {
	    		document.layers[pLayerName].visibility="hide";
	    	}
	    }
		if(ns6) {
			if (pVisibility == true) {
	    		document.getElementById(pLayerName).style.visibility="visible";
			}
			else {
	    		document.getElementById(pLayerName).style.visibility="hidden";
    		}
	   	}			
	}
	
	function setLayerUrl(pLayerName,pIctUrl) {
		if(ie) {
    		document.all[pLayerName].style.backgroundImage='url('+pIctUrl+')';
	   	}
		if(ns) {
    		document.layers[pLayerName].backgroundImage='url('+pIctUrl+')';
	    }
		if(ns6) {
			document.getElementById(pLayerName).style.backgroundImage="url('"+pIctUrl+"')"; 
	   	}			
	}
	
	// end of layer stuff ------------------------------------------------
	
	
	function clearInput(pField) {
		pField.value="";
	}
	
	function validateCurrencyField(pField) {
		if (pField != "") {
			var value = pField.value;
			for (var i = 0; i < value.length; i++) {
				if ( !(value.charAt(i) >= 0 && value.charAt(i) <= 9) && value.charAt(i) != '.' && value.charAt(i) != ',') {
					alert("Bitte ein gültiges Preis Format benutzen, zB 999,99 oder 999");
					return false;
				}
			}
		}
		return true;
	}

	function validateCurrencyFieldByName(pFormName,pFieldName) {
		var aForm = document.forms[pFormName];
		var aElem = aForm.elements[pFieldName];
		var value = aElem.value;
			
		for (var i = 0; i < value.length; i++) {
			if ( !(value.charAt(i) >= 0 && value.charAt(i) <= 9) && value.charAt(i) != '.' && value.charAt(i) != ',') {
				alert("Bitte ein gültiges Preis Format benutzen, zB 999,99 oder 999");
				return false;
			}
		}
		return true;
	}
	
	function openImage(pPictPath,breite,hoehe) {
		if (pPictPath!="") {
			dokument="zwr_includes/common/zwrShowPict.php?pict="+pPictPath;
	     	posa=screen.width/2-248;
	     	posb=screen.height/2-200;
	     	bilfen=window.open(dokument,'bild','width='+breite+', height='+hoehe+', left='+posa+', top='+posb+', screenx='+posa+', screeny='+posb+', scrollbars=no');
		}
	}
	function basename(pString) {
		var result = "";
		String(pString);
		var index = pString.lastIndexOf("/");
		if (index > -1) {
			pString = pString.substring(index+1);
			index = pString.indexOf(".");
			if (index > -1) {
				pString = pString.substring(0,index);
			}
		}
		return pString;
	}
	function popupTall(pRelativeFilePath) {
		var winName = basename(pRelativeFilePath);
		height=screen.height-150;
		window.open(pRelativeFilePath,winName,'width=400, height='+height+', left=0, top=0, screenx=0, screeny=0, resizable=yes, scrollbars=yes');
	}
	function popupWide(pRelativeFilePath) {
		if (!ie) {
			var winName = basename(pRelativeFilePath);
		}
		else {
			var winName = "popup";
		}
		window.open(pRelativeFilePath,winName,'width=780, height=600, left=0, top=0, screenx=0, screeny=0, resizable=yes, scrollbars=yes');
	}
	function popup(datei,breite,hoehe,posa,posb){
		popfen=window.open(datei,'popup','width='+breite+', height='+hoehe+', left='+posa+', top='+posb+', screenx='+posa+', screeny='+posb+', resizable=yes, scrollbars=yes');
	}
	
	function zu(){
		window.close('popup')
	}
	function popupClose() {
		if (!ie) {
			var aName = self.name;
			window.close(aName);
		}
		else {
			window.close();
		}
	}
	function validateEmailFormFields(formName) {
	 	var form = document.forms[formName]; 
		var counter = 0;
	 	var errorFields = "";
	 	var errorFieldName = "";


		for(var i = 0; i < form.elements.length; i++) {
			if(form.elements[i].value == "") {
				errorFieldName="";
				inputFieldNameStrObj = new String(form.elements[i].name);
				if (-1 < inputFieldNameStrObj.indexOf('textfield_Name')) {
					errorFieldName = 'Name';
				}
				else if (-1 < inputFieldNameStrObj.indexOf('textfield_Email')) {
					errorFieldName = 'Email';
				}
				else if (-1 < inputFieldNameStrObj.indexOf('textfield_Subject')) {
					errorFieldName = 'Betreff';
				}
				else if (-1 < inputFieldNameStrObj.indexOf('textfield_Message')) {
					errorFieldName = 'Nachricht';
				}
				if (errorFieldName != "") {
					if (counter > 0) {
						errorFields = errorFields + ', ';
					}
					errorFields = errorFields + errorFieldName;
					counter++;
				}
			}
		} 
		if (counter > 0) {
			if (counter == 1) {
				errorTxt = 'Bitte das Feld ';
			}
			else {
				errorTxt = 'Bitte die Felder ';
			}
			errorTxt = errorTxt + errorFields + " verwenden";
			alert(errorTxt);
			return false;
		}
		return true; 
	}
	
	function zwrPrompt(pFormObj,pTitle) {
		var result = prompt(pTitle,"");
		if (result == null) {
			result = false;
		}
		else {
			pFormObj.response.value = result;
			result = true;
		}
		return result;
	}
	
	function setLayerHtml(pLayerName,pText) {
		if (ie) {
			document.all[pLayerName].innerHTML=pText;
		}
		if (ns) {
			document.layers[pLayerName].innerHTML=pText;
		}
		if (ns6) {
			document.getElementById(pLayerName).innerHTML=pText;
		}			
		
		
		/*
		else {
		document[pLayerName].document.open();
		document[pLayerName].document.write(pText);
		document[pLayerName].document.close();		
		}
		*/
	}
