var mBoolIE = document.all
var mBoolNS6 = document.getElementById && !document.all
var mObjCurrentElement = null;
var mIntOffsetXPoint = -60; //Customize x offset of tooltip
var mIntOffsetYPoint = 20; //Customize y offset of tooltip
var mBoolToolTipVisible = false;
var mBoolMenuInitialised = false;
var mObjArrMenuHeight = new Array();
var mObjArrMenuToolTipShowed = new Array();

mObjArrMenuHeight[0] = "";
mObjArrMenuHeight[1] = "";
mObjArrMenuHeight[2] = "";
mObjArrMenuHeight[3] = "";
mObjArrMenuHeight[4] = "";
mObjArrMenuHeight[5] = "";
mObjArrMenuHeight[6] = "";
mObjArrMenuHeight[8] = "";
mObjArrMenuHeight[9] = "";
mObjArrMenuHeight[10] = "";

mObjArrMenuToolTipShowed[0] = true;
mObjArrMenuToolTipShowed[1] = true;
mObjArrMenuToolTipShowed[2] = true;
mObjArrMenuToolTipShowed[3] = true;
mObjArrMenuToolTipShowed[4] = true;
mObjArrMenuToolTipShowed[5] = true;
mObjArrMenuToolTipShowed[6] = true;
mObjArrMenuToolTipShowed[8] = true;
mObjArrMenuToolTipShowed[9] = true;
mObjArrMenuToolTipShowed[10] = true;


if (mBoolIE) {
	document.onmousedown = eventHandlerMouseDown;
} else {
	document.addEventListener("mousedown", eventHandlerMouseDown, true);
}

Array.prototype.clear = function() {
	if(this.length)
		return this.splice(0, this.length);
	return;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, "");
}

String.prototype.replaceAll = function(strSearch, strRepl) {
	var str = this;
	while (str.indexOf(strSearch) != -1)
		str = str.replace(strSearch, strRepl);
	return str;
}

String.prototype.isNumeric = function() {
	return /^\d+$/.test(this);
}

String.prototype.isNumber = function() {
	return /^[-]?\d+$/.test(this);
}

String.prototype.isNumericString = function() {
	return /^[0-9]+$/i.test(this);
}

String.prototype.isEmail = function() {
	return /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(this);
}

String.prototype.isTel = function() {
	return /^[+0-9\s?\(\)]+$/i.test(this);
}

String.prototype.isNoTel = function() {
	return /^(0\d{9})|(0\d[ \.-]\d{2}[ \.-]\d{2}[ \.-]\d{2}[ \.-]\d{2})$/.test(this);
}

String.prototype.isPassword = function() {
	return /^[a-zA-Z0-9]*[a-zA-Z0-9]$/.test(this);
}


String.prototype.isSpecialChar = function() {
	var arrStrSpecialChar = /\\|\~|\!|\#|\$|\%|\^|\&|\*|\.{2}|\{|\}|\[|\]|\?|\=|\`/i.exec(this);
	if(arrStrSpecialChar)
		return arrStrSpecialChar[0];
	else
		return '';
}

String.prototype.toDateTime = function() {//2004-06-08 13:31:34
	var str = this;
	var arrDateTime = str.split(' ');
	var arrDateParts = (arrDateTime[0]).split('-');
	var strTimePart = arrDateTime[1];
	return strTimePart+' '+arrDateParts[2]+'.'+arrDateParts[1]+'.'+arrDateParts[0];
}

String.prototype.parseDay = function() {
	var str = this;
	var arrDateTime = str.split(' ');
	var arrDateParts = (arrDateTime[0]).split('-');
	return arrDateParts[2];
}

String.prototype.parseMonth = function() {
	var str = this;
	var arrDateTime = str.split(' ');
	var arrDateParts = (arrDateTime[0]).split('-');
	return arrDateParts[1];
}

String.prototype.parseYear = function() {
	var str = this;
	var arrDateTime = str.split(' ');
	var arrDateParts = (arrDateTime[0]).split('-');
	return arrDateParts[0];
}

function isObj(name) {
	if (document.getElementById) 
		return ((document.getElementById(name) == null)?false:true);
	else if (document.all)
		return ((document.all[name] == null)?false:true);
	else if (document.layers)
		return ((document.layers[name] == null)?false:true);
	return false;
}

function getObj(name) {
  if (document.getElementById) {
  	this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
  } else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
  } else if (document.layers) {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

getObj.prototype.setAttr = function(strAttr, varValue) {
    this.obj.setAttribute(strAttr,varValue);
}

getObj.prototype.getAttr = function(strAttr) {
    return this.obj.attributes.getNamedItem(strAttr).value;
}

function removeObj(strObjId) {
	var objDiv = new getObj(strObjId);
	if(objDiv)
		if(objDiv.obj.currentStyle) 
			objDiv.obj.removeNode(true);
		else {
			var objParent = objDiv.obj.parentNode;
			objParent.removeChild(objDiv.obj);
		}
}

function getStyle(objElement, strStyleProperty) {
	var strStyle; 
	if (window.getComputedStyle)
		strStyle = window.getComputedStyle(objElement, null).getPropertyValue(strStyleProperty);
	else if (objElement.currentStyle)
		strStyle = eval('objElement.currentStyle.' + strStyleProperty);
	return strStyle;
}

function trim (zeichenkette) {
  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}

function validateRequiredValue(intRequired, strVal, strValidationRule) {
	if(intRequired == 1) {
		if(strVal == '')
			return false;
	}
	return true;
}

function validateText(intRequired, strValidationRule, strVal, displayNam) {
	var strSpecialChar = strVal.isSpecialChar();

	if(!validateRequiredValue(intRequired, strVal)) {
		alert("Eingabefeld: '"+displayNam+"' .\nDieses Feld darf nicht leer sein.\nBitte, geben sie einen Wert ein.");
		return false;	
	}
	
	if(strVal == '')
		return true;
	
	if(strValidationRule == 'text') {
		if(strSpecialChar != '') {
			alert("Eingabefeld: '"+displayNam+"' .\nDas eingegebene Wort ist keine gueltige Zeichenfolge.\nEs befindet sich das Steuerzeichen '"+strSpecialChar+"' in der Zeichenfolge.\nNicht zugelassene Zeichen: "+'\~!#$%^&*{}[]?=`..'+".\nBitte wiederholen Sie die Eingabe.");
			return false;
		}
	} else if(strValidationRule == 'mail') {
		if(!strVal.isEmail()) {
			alert("Eingabefeld: '"+displayNam+"' .\nDie eingegebene Mailadresse ist nicht in einem gueltigen Format.\nZugelassenes Format: "+'<name>@<domain>.<ext> z.B.: lotte@hotmail.com'+".\nBitte wiederholen Sie die Eingabe.");
			return false;
		}
	} else if(strValidationRule == 'telephone') {
		if(!strVal.isTel()) {
			alert("Eingabefeld: '"+displayNam+"' .\nDie eingegebene Telefonnummer ist nicht in einem gueltigen Format.\nNZugelassene Zeichen: "+'<[0-9][ ]>  z.B.: 0190 666 666'+".\nBitte wiederholen Sie die Eingabe.");
			return false;
		}		
	} else if(strValidationRule == 'numeric') {
		if(!strVal.isNumericString()) {
			alert("Eingabefeld: '"+displayNam+"' .\nDie eingegebene Zeichenfolge ist nicht in einem gueltigen Format.\nNicht zugelassene Zeichen: "+'<[0-9]> z.B.: 04711'+".\nBitte wiederholen Sie die Eingabe.");
			return false;
		}			
	} else if(strValidationRule == 'doc') {
		if(strVal == '') {
			alert("Eingabefeld: '"+displayNam+"' .\nSie m&uuml;ssen eine Datei ausw&auml;hlen.\nBitte stellen Sie sicher das die Datei dem Kontext entspricht.");
			return false;
		}			
	} else if(strValidationRule == 'pwd') {
		if(!strVal.isPassword()) {
			alert("Eingabefeld: '"+displayNam+"' .\nDie Eingabe ist kein gültiges Passwort.\nBitte stellen Sie sicher das Es aus dem Format '<[a-z 0-9]>' entspricht.");
			return false;
		}
    if(strVal.length <= 4 ) {
			alert("Eingabefeld: '"+displayNam+"' .\nDie Eingabe ist kein gültiges Passwort.\nBitte stellen Sie sicher das Es aus mindestenz 5 Zeichen besteht.");
			return false;
    }
	} else if(strValidationRule == 'combo') {
		if((strVal == '0') && (intRequired == 1)) {
			alert("Auswahlliste: '"+displayNam+"' .\nIn der Auswahlliste wurde kein Element ausgewählt.\nBitte wählen sie ein Element aus.");
			return false;
		}			
	}
	return true;
}

function validateFormElement(strName) {
	var objImp;
	var strVal;
	var strValidationRule;
	var intRequired;
	var strDisplayName;
	if(isObj(strName)) {
		objImp = new getObj(strName);
		strVal = objImp.obj.value;
		strValidationRule = objImp.getAttr('validate');
		intRequired = parseInt(objImp.getAttr('required'));
		displayName = objImp.getAttr('displayName');
		if(!validateText(intRequired, strValidationRule, strVal, displayName)) {
      objImp.obj.focus();
			return false;
    }
	}
	return true;	
}

function setFocus(strID) {
	var objInp = new getObj(strID);
	objInp.style.backgroundColor = "#FFFFE8";
}

function restoreFocus(strID) {
	var objInp = new getObj(strID);
	objInp.style.backgroundColor = "";	
}

function highlightTextBox(strID) {
  var objInp = new getObj(strID);
	objInp.style.borderLeft = '2px solid #FF0000';
	objInp.style.borderBottom = '2px solid #FF0000';
  objInp.style.borderTop = '2px solid #FF0000';
  objInp.style.borderRight = '2px solid #FF0000';
}
function restoreHighlightedTextBox(strID) {
  var objInp = new getObj(strID);
	objInp.style.borderLeft = '';
	objInp.style.borderBottom = '';
  objInp.style.borderTop = '';
  objInp.style.borderRight = '';
}

function eventHandlerMouseDown(event) {

  var objElement;
  
  if (mBoolIE) {
    objElement = window.event.srcElement;
  } else {
    objElement= (event.target.tagName ? event.target : event.target.parentNode);
	}
	
  if (objElement == mObjCurrentElement) {
    return;
	}
	
  if (objElement.className != "menuButton"  && objElement.className != "menuItem" &&
      objElement.className != "menuItemSep" && objElement.className != "menu") {
	    if (mObjCurrentElement) {
			  mObjCurrentElement.className = "menuButton";

			  if (mObjCurrentElement.menu) {
					mObjCurrentElement.menu.style.visibility = "hidden";
				}

			  mObjCurrentElement.isactive = false;
			  mObjCurrentElement = null;
			}
	}
}

function showMenuItems(event, strName) {

  var objElement;

  if (mBoolIE) {
    objElement = window.event.srcElement;
  } else {
    objElement = (event.target.tagName ? event.target : event.target.parentNode);
	}
	
  if (!objElement.menu && strName) {
    objElement.menu = document.getElementById(strName);
	}
	
  if (mObjCurrentElement && mObjCurrentElement != objElement) {
	  mObjCurrentElement.className = "menuButton";

	  if (mObjCurrentElement.menu) {
			mObjCurrentElement.menu.style.visibility = "hidden";
		}

	  mObjCurrentElement.isactive = false;
	  mObjCurrentElement = null;
	}
	
  if (!objElement.isactive) {
  	if (strName) {
		  objElement.className = "menuButtonActive";

		  if (mBoolIE && !objElement.menu.firstChild.style.width) {
		    objElement.menu.firstChild.style.width = objElement.menu.firstChild.offsetWidth + "px";
		  }

		  objElement.menu.style.left = (elementOffsetLeft(objElement)-1) + "px";
		  objElement.menu.style.top  = (elementOffsetTop(objElement) + objElement.offsetHeight + 1) + "px";
		  objElement.menu.style.visibility = "visible";

		  objElement.isactive = true;
		  mObjCurrentElement = objElement;
		}
	}
	
  return false;
}

function elementOffsetLeft(objElement) {
  return objElement.offsetLeft + (objElement.offsetParent ? elementOffsetLeft(objElement.offsetParent) : 0);
}

function elementOffsetTop(objElement) {
  return objElement.offsetTop + (objElement.offsetParent ? elementOffsetTop(objElement.offsetParent) : 0);
}

// Tooltip functions start here

function getBody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showToolTip(strText, strColor, strWidth) {
	if(mBoolToolTipVisible == false) {
		hideLightbox();
		var objToolTip = document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";

		if (mBoolNS6||mBoolIE) {
			if (typeof strWidth != "undefined") {
				objToolTip.style.width = strWidth + "px";
			}
			
			if (typeof strColor != "undefined" && strColor != "") {
				objToolTip.style.backgroundColor = strColor;
			}
			
			objToolTip.innerHTML = strText;
			mBoolToolTipVisible = true;
			return false;
		}
	} else if (mBoolNS6||mBoolIE) {
		return false;
	}
}

function toolTipEventHandler(e) {

	if (mBoolToolTipVisible) {
		var objToolTip = document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";
		var intX = (mBoolNS6) ? e.pageX : event.clientX + getBody().scrollLeft;
		var intY = (mBoolNS6) ? e.pageY : event.clientY + getBody().scrollTop;
		var intRightEdge = mBoolIE && !window.opera ? getBody().clientWidth - event.clientX - mIntOffsetXPoint : window.innerWidth - e.clientX - mIntOffsetXPoint - 20;
		var intBottomEdge = mBoolIE && !window.opera ? getBody().clientHeight - event.clientY - mIntOffsetYPoint : window.innerHeight - e.clientY - mIntOffsetYPoint - 20;
		var intLeftEdge = (mIntOffsetXPoint < 0) ? mIntOffsetXPoint * (-1) : -1000;

		if (intRightEdge < objToolTip.offsetWidth) {
			objToolTip.style.left = mBoolIE ? getBody().scrollLeft + event.clientX - objToolTip.offsetWidth + "px" : window.pageXOffset + e.clientX - objToolTip.offsetWidth + "px";
		} else if (intX < intLeftEdge) {
			objToolTip.style.left = "5px";
		} else {
			objToolTip.style.left = intX + mIntOffsetXPoint + "px";
		}

		if (intBottomEdge < objToolTip.offsetHeight) {
			objToolTip.style.top = mBoolIE? getBody().scrollTop + event.clientY - objToolTip.offsetHeight - mIntOffsetYPoint + "px" : window.pageYOffset + e.clientY - objToolTip.offsetHeight - mIntOffsetYPoint + "px";
		} else {
			objToolTip.style.top = intY + mIntOffsetYPoint + "px";
			objToolTip.style.visibility = "visible";
		}
	}
}

function hideToolTip() {
	if(mBoolToolTipVisible == true) {
		var objToolTip = document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";
		if (mBoolNS6 || mBoolIE) {
			mBoolToolTipVisible = false;
			objToolTip.style.visibility = "hidden";
			objToolTip.style.left = "-1000px";
			objToolTip.style.backgroundColor = '';
			objToolTip.style.width = '';
		}
	}
}

document.onmousemove = toolTipEventHandler;

function showTankPic(strValue) {
	showToolTip('<img height=\'75px\' alt=\'\' src=\'http://www.autogas-zentrum-koeln.de/layout/images/' + strValue + '.gif\' width=\'100px\' border=\'0px\'>','#696969', 100);
}

function showRefInfo(strValue) {
	var intLength = 200;
	if(strValue.length > 4) {
		intLength += (strValue.length*3);
	}
	showToolTip('<p style=\'color=#000000\'><font style=\'FONT-SIZE: 8pt\'>Hier klicken um <font style=\'color=#ff0000\'>' + strValue + '</font> Referenzfahrzeuge anzuzeigen!<font></p>','#ffffe1', intLength);
}

function showToolTipInfo(strValue) {
	showToolTip('<p style=\'color=#000000\'><font style=\'FONT-SIZE: 8pt\'>' + strValue + '</font></p>','#ffffe1', 170);
}

function shopTopItemHover(intID, boolHovering) {
	hideLightbox();
	var objMenu = new getObj('shopMenu' + intID);
	var objDropMenu = new getObj('dropMenu' + intID);
	var strClass = objMenu.obj.className;
	var strPicType = 'down';
  var strPicSuff = '';
	
  if( strClass == 'shopTopItemR')
    strPicSuff = '-r';
    
	if(objDropMenu.style.visibility == "visible") {
		strPicType = 'up';
	}
	
	if(boolHovering == true) {
		objMenu.style.background = 'url("http://www.autogas-zentrum-koeln.de/layout/images/arrow-' + strPicType + '-title-on' + strPicSuff + '.jpg") no-repeat 0 0;';
		objMenu.style.color = '#efefef';
		if((mObjArrMenuToolTipShowed[intID] == false) && (mBoolMenuInitialised == true)) {
			showToolTip('<p style=\'color=#000000\'><font style=\'FONT-SIZE: 8pt\'>zum öffnen und schließen des Menüs hier klicken!<font></p>','#ffffe1', 100);
			mObjArrMenuToolTipShowed[intID] = true;
		} else {
			hideToolTip();
		}
	} else {
		objMenu.style.background = 'url("http://www.autogas-zentrum-koeln.de/layout/images/arrow-' + strPicType + '-title' + strPicSuff + '.jpg") no-repeat 0 0;';
		objMenu.style.color = '#bbbbbb';
	}

}

function shopExpandMenu(intID) {
	
	var objDropMenu = new getObj('dropMenu' + intID);

	if(objDropMenu.style.visibility == "visible") {
		objDropMenu.style.visibility = 'hidden';
		objDropMenu.style.height = '0px';
    objDropMenu.style.display = 'none';
	} else {
    objDropMenu.style.display = 'block';
		objDropMenu.style.visibility = 'visible';
		objDropMenu.style.height = mObjArrMenuHeight[intID];
	}
	
	shopTopItemHover(intID, true);
}

function initShopMenu(boolArrMenuExpanded, strSelectedMenuID) {
	try {
		var intIndex = 1;
		var intCount = mObjArrMenuHeight.length;
		var boolExpanded = false;
		var objDropMenu;
		var objMenu;
		var strClass;
    
		for(intIndex = 1; intIndex < intCount; intIndex++) {
			try {
				objDropMenu = new getObj('dropMenu' + intIndex);
				boolExpanded = boolArrMenuExpanded[intIndex];
				mObjArrMenuHeight[intIndex] = objDropMenu.style.height;
				objDropMenu.style.visibility = boolExpanded ? 'visible' : 'hidden'; 
				if(boolExpanded == false) {
					objDropMenu.style.height = '0px';
           objDropMenu.style.display = 'none';
				} else {
					objMenu = new getObj('shopMenu' + intIndex);
          if(objMenu.obj.className == 'shopTopItemR') {
            objMenu.style.background = 'url("http://www.autogas-zentrum-koeln.de/layout/images/arrow-up-title-r.jpg") no-repeat 0 0;';
          } else {
            objMenu.style.background = 'url("http://www.autogas-zentrum-koeln.de/layout/images/arrow-up-title.jpg") no-repeat 0 0;';
          }
					objMenu.style.color = '#bbbbbb';
				}
			} catch(e1) {
				break;
			}
		}
		try {
      if(strSelectedMenuID != '') {
        objDropMenu = new getObj(strSelectedMenuID);
        objDropMenu.style.color = '#ff0000';
      }
    } catch(e2) {
    }
	} catch(e) {
	}
	mBoolMenuInitialised = true;
}

function setMenuState(strObjID, boolUseObj) {
	try {
    var intIndex = 1;
    var strMenuState = '0:0;';
    var objDropMenu;
    var strValue = '';
    
    for(intIndex = 1; intIndex <= 10; intIndex++) {
      strValue = '0';
      try {
        objDropMenu = new getObj('dropMenu' + intIndex);
        strValue = (objDropMenu.style.visibility == 'visible')?'1':'0'; 
      } catch(e) {
      }
      strMenuState = strMenuState + intIndex + ':' + strValue + ';';
    }
	} catch(e) {
	}
  
  strMenuState = strMenuState.substr(0,strMenuState.length - 1) + '&menuID=' + strObjID;
  //alert('1:'+strMenuState);
  if(boolUseObj) {
    objDropMenu = new getObj(strObjID);
    strHref = objDropMenu.obj.href;
    if(strHref.indexOf('.php') == (strHref.length-4)) {
    //alert('2:'+strHref + '?menuState=' + strMenuState);
      objDropMenu.obj.href = strHref + '?menuState=' + strMenuState;
    } else {
    //alert('3:'+strHref + '&menuState=' + strMenuState);
      objDropMenu.obj.href = strHref + '&menuState=' + strMenuState;
    }
  } else {
    objDropMenu = new getObj('menuState');
    objDropMenu.obj.value = strMenuState;
  	try {
      objDropMenu = new getObj('menuState2');
      objDropMenu.obj.value = strMenuState;
  	} catch(e) {
  	}
  }
  
  return true;
}
/*
	Lightbox JS: Fullsize Image Overlays 
	by Lokesh Dhakar - http://www.huddletogether.com

	For more information on this script, visit:
	http://huddletogether.com/projects/lightbox/

	Script featured on Dynamic Drive code library Jan 24th, 06':
	http://www.dynamicdrive.com

	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
	(basically, do anything you want, just leave my name and link)
	
	Table of Contents
	-----------------
	Configuration
	
	Functions
	- getPageScroll()
	- getPageSize()
	- pause()
	- getKey()
	- listenKey()
	- showLightbox()
	- hideLightbox()
	- initLightbox()
	- addLoadEvent()
	
	Function Calls
	- addLoadEvent(initLightbox)

*/



//
// Configuration
//

// If you would like to use a custom loading image or close button reference them in the next two lines.
var loadingImage = 'http://www.autogas-zentrum-koeln.de/layout/images/loading.gif';		
var closeButton = 'http://www.autogas-zentrum-koeln.de/layout/images/close.gif';		





//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//

function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){ hideLightbox(); }
}


//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }
	

//
// showLightbox()
// Preloads images. Pleaces new image in lightbox then centers and displays.
//
function showLightbox(objLink)
{
	// prep objects
	var objOverlay = document.getElementById('overlay');
	var objLightbox = document.getElementById('lightbox');
	var objCaption = document.getElementById('lightboxCaption');
	var objImage = document.getElementById('lightboxImage');
	var objLoadingImage = document.getElementById('loadingImage');
	var objLightboxDetails = document.getElementById('lightboxDetails');

	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// center loadingImage if it exists
	if (objLoadingImage) {
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px');
		objLoadingImage.style.display = 'block';
	}

	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';

	// preload image
	imgPreload = new Image();

	imgPreload.onload=function(){
		objImage.src = objLink.href;

		// center lightbox and make sure that the top and left values are not negative
		// and the image placed outside the viewport
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - imgPreload.height) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 20 - imgPreload.width) / 2);
		
		objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";


		objLightboxDetails.style.width = imgPreload.width + 'px';
		
		if(objLink.getAttribute('title')){
			objCaption.style.display = 'block';
			//objCaption.style.width = imgPreload.width + 'px';
			objCaption.innerHTML = objLink.getAttribute('title');
		} else {
			objCaption.style.display = 'none';
		}
		
		// A small pause between the image loading and displaying is required with IE,
		// this prevents the previous image displaying for a short burst causing flicker.
		if (navigator.appVersion.indexOf("MSIE")!=-1){
			pause(250);
		} 

		if (objLoadingImage) {	objLoadingImage.style.display = 'none'; }
		objLightbox.style.display = 'block';

		// After image is loaded, update the overlay height as the new image might have
		// increased the overall page height.
		arrayPageSize = getPageSize();
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		
		// Check for 'x' keypress
		listenKey();

		return false;
	}

	imgPreload.src = objLink.href;
	
}





//
// hideLightbox()
//
function hideLightbox()
{
	try {
		// get objects
		objOverlay = document.getElementById('overlay');
		objLightbox = document.getElementById('lightbox');

		// hide lightbox and overlay
		objOverlay.style.display = 'none';
		objLightbox.style.display = 'none';
		
		// disable keypress listener
		document.onkeypress = '';
	} catch(e) {
	}
}



function init() {
  try {
    var objBenzinPreis = document.all? document.all["BenzinPreis"] : document.getElementById? document.getElementById("BenzinPreis") : "";
    var objGasPreis = document.all? document.all["GasPreis"] : document.getElementById? document.getElementById("GasPreis") : "";
    var strBenzinPreis = trim(objBenzinPreis.innerHTML);
    var strGasPreis = trim(objGasPreis.innerHTML);
    document.getElementById('BenzinPreisEingabe').value = (parseFloat(strBenzinPreis.replace(',','.'))+0.01).toString().replace('.',',');
    document.getElementById('GasPreisEingabe').value = (parseFloat(strGasPreis.replace(',','.'))+0.01).toString().replace('.',',');
  } catch(e) {
  }
}
//
// initLightbox()
// Function runs on window load, going through link tags looking for rel="lightbox".
// These links receive onclick events that enable the lightbox display for their targets.
// The function also inserts html markup at the top of the page which will be used as a
// container for the overlay pattern and the inline image.
//
function initLightbox()
{
	init();
	
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");

	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "lightbox")){
			anchor.onclick = function () {showLightbox(this); return false;}
		}
	}

	// the rest of this code inserts html at the top of the page that looks like this:
	//
	// <div id="overlay">
	//		<a href="#" onclick="hideLightbox(); return false;"><img id="loadingImage" /></a>
	//	</div>
	// <div id="lightbox">
	//		<a href="#" onclick="hideLightbox(); return false;" title="Click anywhere to close image">
	//			<img id="closeButton" />		
	//			<img id="lightboxImage" />
	//		</a>
	//		<div id="lightboxDetails">
	//			<div id="lightboxCaption"></div>
	//			<div id="keyboardMsg"></div>
	//		</div>
	// </div>
	
	var objBody = document.getElementsByTagName("body").item(0);
	
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.onclick = function () {hideLightbox(); return false;}
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// preload and create loader image
	var imgPreloader = new Image();
	
	// if loader image found, create link to hide lightbox and create loadingimage
	imgPreloader.onload=function(){

		var objLoadingImageLink = document.createElement("a");
		objLoadingImageLink.setAttribute('href','#');
		objLoadingImageLink.onclick = function () {hideLightbox(); return false;}
		objOverlay.appendChild(objLoadingImageLink);
		
		var objLoadingImage = document.createElement("img");
		objLoadingImage.src = loadingImage;
		objLoadingImage.setAttribute('id','loadingImage');
		objLoadingImage.style.position = 'absolute';
		objLoadingImage.style.zIndex = '150';
		objLoadingImageLink.appendChild(objLoadingImage);

		imgPreloader.onload=function(){};	//	clear onLoad, as IE will flip out w/animated gifs

		return false;
	}

	imgPreloader.src = loadingImage;

	// create lightbox div, same note about styles as above
	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.style.position = 'absolute';
	objLightbox.style.zIndex = '100';	
	objBody.insertBefore(objLightbox, objOverlay.nextSibling);
	
	// create link
	var objLink = document.createElement("a");
	objLink.setAttribute('href','#');
	objLink.setAttribute('title','zum schließen klicken');
	objLink.onclick = function () {hideLightbox(); return false;}
	objLightbox.appendChild(objLink);

	// preload and create close button image
	var imgPreloadCloseButton = new Image();

	// if close button image found, 
	imgPreloadCloseButton.onload=function(){

		var objCloseButton = document.createElement("img");
		objCloseButton.src = closeButton;
		objCloseButton.setAttribute('id','closeButton');
		objCloseButton.style.position = 'absolute';
		objCloseButton.style.zIndex = '200';
		objLink.appendChild(objCloseButton);

		return false;
	}

	imgPreloadCloseButton.src = closeButton;

	// create image
	var objImage = document.createElement("img");
	objImage.setAttribute('id','lightboxImage');
	objLink.appendChild(objImage);
	
	// create details div, a container for the caption and keyboard message
	var objLightboxDetails = document.createElement("div");
	objLightboxDetails.setAttribute('id','lightboxDetails');
	objLightbox.appendChild(objLightboxDetails);

	// create caption
	var objCaption = document.createElement("div");
	objCaption.setAttribute('id','lightboxCaption');
	objCaption.style.display = 'none';
	objLightboxDetails.appendChild(objCaption);

	// create keyboard message
	var objKeyboardMsg = document.createElement("div");
	objKeyboardMsg.setAttribute('id','keyboardMsg');
	objKeyboardMsg.innerHTML = '<kbd>x</kbd> zum schließen';
	objLightboxDetails.appendChild(objKeyboardMsg);

}

function checkRadio(strID) {
  try {
    var objRadio = new getObj(strID);
    objRadio.obj.checked = true;
  } catch(e) {
  }
}

function updateProductCount(strID) {
  try {
    var objForm = new getObj(strID);
    var strProdCount = objForm.obj.value;
    var strProdID = strID.split('_')[1];
    var objForm = new getObj('prodid');
  	objForm.obj.value = strProdID;
    var objForm = new getObj('prodcount');
  	objForm.obj.value = strProdCount;
  	objForm = new getObj('updateOrderList');
  	objForm.obj.submit();		
  } catch(e) {
  }
}

function sendOrder() {
  try {
    var objForm = new getObj('ordered');
  	objForm.obj.value = '1';
  	objForm = new getObj('updateOrderList');
  	objForm.obj.submit();		
  } catch(e) {
  }
}

function setManufacturerFilter() {
  try {
    var objForm = new getObj('manufacturerSelection');
  	var strMan = objForm.obj.value;
  	objForm = new getObj('man');
    objForm.obj.value = strMan;
  	objForm = new getObj('refreshProductList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function setCategoryFilter() {
  try {
    var objForm = new getObj('categorySelection');
  	var strMan = objForm.obj.value;
  	objForm = new getObj('cat');
    objForm.obj.value = strMan;
  	objForm = new getObj('refreshProductList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function setSortFilter() {
  try {
    var objForm = new getObj('sortSelection');
  	var strMan = objForm.obj.value;
  	objForm = new getObj('order');
    objForm.obj.value = strMan;
  	objForm = new getObj('refreshProductList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function addNewProduct() {
  try {
    var objForm = new getObj('addnew');
    objForm.obj.value = '1';
  	objForm = new getObj('refreshProductList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function cancelEditNewProduct() {
  try {
    var objForm = new getObj('addnew');
    objForm.obj.value = '0';
  	objForm = new getObj('refreshProductList');
  	objForm.obj.submit();
  } catch(e) {
  }
}


function editNewProduct() {
  try {
    var objForm = new getObj('editnew');
    objForm.obj.value = '1';
  	objForm = new getObj('refreshProductList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function deleteProduct(strProdID) {
  try {
  	if(!confirm("Möchten Sie diesen Datensatz\nwirklich löschen?"))
  		return;
    var objForm = new getObj('delete');
    objForm.obj.value = '1';
    objForm = new getObj('prodid');
    objForm.obj.value = strProdID;
  	objForm = new getObj('refreshProductList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function updateProduct(strProdID) {
  try {
    var objForm = new getObj('update');
    objForm.obj.value = '1';
    objForm = new getObj('prodid');
    objForm.obj.value = strProdID;
  	objForm = new getObj('refreshProductList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function setFileName(strId, strPath) {
	var objInp;
	var arrParts = strPath.split('.');
	var strExtension = arrParts[arrParts.length-1];

	if((strExtension != 'jpg') && (strExtension != 'jpeg') && (strExtension != 'JPG') && (strExtension != 'JPEG')) {
		objInp = new getObj(strId);
		if(objInp.obj.value == '')
			return;		
		alert("Sie haben kein JPEG ausgewählt!\nBitte, versuchen sie Es erneut.");
		objInp = new getObj(strId);
		objInp.obj.value = '';
		objInp = new getObj('setpic');
		objInp.obj.value = '0';
		return;	
	}
	objInp = new getObj('setpic');
	objInp.obj.value = '1';
}

function setMultiFileName(strId, strPath, intFileId) {
	var objInp;
	var arrParts = strPath.split('.');
	var strExtension = arrParts[arrParts.length-1];
  
	if((strExtension != 'jpg') && (strExtension != 'jpeg') && (strExtension != 'JPG') && (strExtension != 'JPEG')) {
		objInp = new getObj(strId);
		if(objInp.obj.value == '') {
      objInp = new getObj('fldHRefPicsB'+intFileId);
      objInp.obj.href = '../layout/images/noPicb.gif';
      objInp = new getObj('fldHRefPicsS'+intFileId);
      objInp.obj.src = '../layout/images/noPic2.gif';
  		objInp = new getObj('setpic'+intFileId);
  		objInp.obj.value = '0';
			return;		
    }
		alert("Sie haben kein JPEG ausgewählt!\nBitte, versuchen sie Es erneut.");
    objInp = new getObj('fldHRefPicsB'+intFileId);
    objInp.obj.href = '../layout/images/noPicb.gif';
    objInp = new getObj('fldHRefPicsS'+intFileId);
    objInp.obj.src = '../layout/images/noPic2.gif';
		objInp = new getObj('setpic'+intFileId);
		objInp.obj.value = '0';
		return;	
	}  
	objInp = new getObj('setpic'+intFileId);
	objInp.obj.value = '1';
}

function removeCarPic(intFileId) {
  var objInp = new getObj('fldHRefPicsB'+intFileId);
  objInp.obj.href = '../layout/images/noPicb.gif';
  objInp = new getObj('fldHRefPicsS'+intFileId);
  objInp.obj.src = '../layout/images/noPic2.gif';
  objInp = new getObj('setpic'+intFileId);
  objInp.obj.value = '2';
}

function removeProductPic(intFileId) {
  var objInp = new getObj('imgb_'+intFileId);
  objInp.obj.href = '../layout/images/noPicb.gif';
  objInp = new getObj('imgs_'+intFileId);
  objInp.obj.src = '../layout/images/noPic2.gif';
  objInp = new getObj('setpic');
  objInp.obj.value = '2';
}

function setCarTypeFilter() {
  try {
    var objForm = new getObj('carTypeSelection');
  	var strType = objForm.obj.value;
  	objForm = new getObj('cartypeid');
    objForm.obj.value = strType;
  	objForm = new getObj('refreshRefList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function setCarFilter() {
  try {
    var objForm = new getObj('carSelection');
  	var strCar = objForm.obj.value;
  	objForm = new getObj('carid');
    objForm.obj.value = strCar;
  	objForm = new getObj('refreshRefList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function addNewCar() {
  try {
    var objForm = new getObj('addnew');
    objForm.obj.value = '1';
  	objForm = new getObj('refreshRefList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function cancelEditNewCar() {
  try {
    var objForm = new getObj('addnew');
    objForm.obj.value = '0';
  	objForm = new getObj('refreshRefList');
  	objForm.obj.submit();
  } catch(e) {
  }
}


function editNewCar() {
  try {
    var objForm = new getObj('editnew');
    objForm.obj.value = '1';
  	objForm = new getObj('refreshRefList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function deleteCar(strCarID) {
  try {
  	if(!confirm("Möchten Sie diesen Datensatz\nwirklich löschen?"))
  		return;
    var objForm = new getObj('delete');
    objForm.obj.value = '1';
    objForm = new getObj('carid');
    objForm.obj.value = strCarID;
  	objForm = new getObj('refreshRefList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function updateCar(strCarID) {
  try {
    var objForm = new getObj('update');
    objForm.obj.value = '1';
    objForm = new getObj('carid');
    objForm.obj.value = strCarID;
  	objForm = new getObj('refreshRefList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function updateFuelPrices() {
  try {
    var objForm = new getObj('update');
    objForm.obj.value = '1';
  	objForm = new getObj('fuelPriceList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function selectRefCarPic(intPicID) {
  try {
    var objForm = new getObj('fldHRefPics'+intPicID);
    objForm.obj.click();
  } catch(e) {
  }
}

function selectProductPic(intPicID) {
  try {
    var objForm = new getObj('prodpic_'+intPicID);
    objForm.obj.click();
  } catch(e) {
  }
}

function setTypeFilter() {
  try {
    var objForm = new getObj('typeSelection');
  	var strType = objForm.obj.value;
  	objForm = new getObj('custtype');
    objForm.obj.value = strType;
  	objForm = new getObj('custid');
    objForm.obj.value = '0';
  	objForm = new getObj('refreshCustomerList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function setCustomerFilter() {
  try {
    var objForm = new getObj('customerSelection');
  	var strType = objForm.obj.value;
  	objForm = new getObj('custid');
    objForm.obj.value = strType;
  	objForm = new getObj('refreshCustomerList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function editNewCustomer() {
  try {
    var objForm = new getObj('editnew');
    objForm.obj.value = '1';
  	objForm = new getObj('custid');
    objForm.obj.value = '0';    
  	objForm = new getObj('refreshCustomerList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function deleteCustomer(strCustID) {
  try {
  	if(!confirm("Möchten Sie diesen Datensatz\nwirklich löschen?"))
  		return;
    var objForm = new getObj('delete');
    objForm.obj.value = '1';
    objForm = new getObj('custid');
    objForm.obj.value = strCustID;
  	objForm = new getObj('refreshCustomerList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function updateCustomer(strCustID) {
  try {
    var objForm = new getObj('update');
    objForm.obj.value = '1';
    objForm = new getObj('custid');
    objForm.obj.value = strCustID;
  	objForm = new getObj('refreshCustomerList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function addNewCustomer() {
  try {
    var objForm = new getObj('addnew');
    objForm.obj.value = '1';
  	objForm = new getObj('refreshCustomerList');
  	objForm.obj.submit();
  } catch(e) {
  }
}

function cancelEditNewCustomer() {
  try {
    var objForm = new getObj('addnew');
    objForm.obj.value = '0';
    objForm = new getObj('custid');
    objForm.obj.value = '0';
  	objForm = new getObj('refreshCustomerList');
  	objForm.obj.submit();
  } catch(e) {
  }
}