// ---------------------------------------------------------------------------------------------
// Funktionen fuer "Schubladen" in Promospalte

function openDrawer(drawerDivId, effectDuration) {
	if (!effectDuration) effectDuration = 0.3 ;

	new Effect.BlindDown(drawerDivId, {duration: effectDuration, queue: {position: 'end', scope: 'drawerscope', limit: 2}}) ;
}



function closeDrawer(drawerDivId, effectDuration) {
	if (!effectDuration) effectDuration = 0.3 ;

	new Effect.BlindUp(drawerDivId, {duration: effectDuration, queue: {position: 'end', scope: 'drawerscope', limit: 2}}) ;
}



function toggleDrawer(drawerDivId, effectDuration) {
	if ($(drawerDivId).getStyle('display') == "none") {
		openDrawer(drawerDivId, effectDuration) ;
	}
	else {
		closeDrawer(drawerDivId, effectDuration) ;
	}
}



function toggleDrawerWithButton(drawerDivId, openDrawerBtImg, closeDrawerBtImg, effectDuration) {
	if (!openDrawerBtImg) openDrawerBtImg = "/shared/images/buttons/plus.gif" ;
	if (!closeDrawerBtImg) closeDrawerBtImg = "/shared/images/buttons/minus.gif" ;

	if ($(drawerDivId).getStyle('display') == "none") {
		openDrawer(drawerDivId, effectDuration) ;
		document.getElementById("bt" + drawerDivId).src = closeDrawerBtImg ;
	}
	else {
		closeDrawer(drawerDivId, effectDuration) ;
		document.getElementById("bt" + drawerDivId).src = openDrawerBtImg ;
	}
}


// ---------------------------------------------------------------------------------------------
// verschiedene Anzeige-Funktionen

var BubblePopup = Class.create({
	initialize: function(elementId, linkId, options) {
		this.options = Object.extend(Object.extend({ }, this.DefaultOptions), options || { }) ;

		this.element = $(this.setup(elementId)) ;
		this.link = $(linkId) ;
		this.fadeOutTimer = "" ;
		this.scope = "" ;

		var position = this.element.cumulativeOffset() ;
		var dimensions = this.element.getDimensions() ;
		var linkPosition = this.link.cumulativeOffset() ;
		var linkDimensions = this.link.getDimensions() ;

		var leftPos = linkPosition.left + linkDimensions.width / 2 - dimensions.width / 2 < 8 ? 8 : parseInt(linkPosition.left + linkDimensions.width / 2 - dimensions.width / 2) ;
		var topPos = (this.options.orientation == 1 ? linkPosition.top - dimensions.height + 6 : linkPosition.top + linkDimensions.height - 8) < 8 ? 8 : (this.options.orientation == 1 ? linkPosition.top - dimensions.height + 6 : linkPosition.top + linkDimensions.height - 8) ;

		this.element.setStyle({	
			display: 'none',
			left: leftPos + 'px', 
			position: 'absolute', 
			top: topPos + 'px',
			visibility: 'visible'
		}) ;

		if (this.options.openOnMouseover) {
			this.link.observe('mouseover', this.show.bindAsEventListener(this)) ;
		}
		else {
			this.link.href = "javascript:void(0);" ;
			this.link.target = "_top" ;
			this.link.observe('click', this.show.bindAsEventListener(this)) ;
		}

		if (this.options.closeButton != "" && this.options.closeButton != true) {
			this.options.closeDelay = 0 ;
			$(this.options.closeButton).href = "javascript:void(0);" ;
			$(this.options.closeButton).observe('click', this.fadeOut.bindAsEventListener(this)) ;
		}
		else {
			this.link.observe('mouseout', this.fadeOut.bindAsEventListener(this)) ;
			this.element.observe('mouseover', this.show.bindAsEventListener(this)) ;
			this.element.observe('mouseout', this.fadeOut.bindAsEventListener(this)) ;
			
		}

	},

	setup: function(elementId) {
		var setupElement = $(elementId) ;

		var newElementId ;
		var closeButtonId ;
		var insertAtElement ;

		var newElement ;
		var bubbleWidth ;
		
		if (this.options.setupBubble) {
			// create unique ids for bubble elements
			do {
				newElementId = elementId + new Date().getTime() ;
				closeButtonId = newElementId + "cbt" ;
			} while (document.getElementById(newElementId) || document.getElementById(closeButtonId)) ;
	
			// get position for and insert bubble dom elements, if possible
			// do no setup at all if no insert position can be found

			insertAtElement = setupElement.previous() ;
			if (!insertAtElement) insertAtElement = setupElement.up().firstDescendant() ;

			if (insertAtElement) {
				setupElement.remove() ;

				bubbleWidth = setupElement.length > 1500 ? 600 : (setupElement.length > 1000 ? 500 : 400) ;

				newElement = 
					Builder.node('table', {id: newElementId, className: 'bubblepopup', style: 'visibility: hidden, width: ' + bubbleWidth + 'px', cellpadding: '0', cellspacing: '0'}, [
						Builder.node('tbody', [
							Builder.node('tr', [Builder.node('td', {className: 'bubbletopleftcorner'}), Builder.node('td', {className: 'bubble' + this.options.orientation + 'top'}), Builder.node('td', {className: 'bubbletoprightcorner'}, [(this.options.closeButton == true ? Builder.node('img', {src: '/shared/images/interface/closebubble.png', id: closeButtonId, alt: 'Schlie&szlig;en', style: 'cursor: pointer; left: -6px; position: relative; top: 7px'}) : "")])]),
							Builder.node('tr', [Builder.node('td', {className: 'bubbleleft'}), Builder.node('td', {className: 'bubblecenter'}, [setupElement.show()]), Builder.node('td', {className: 'bubbleright'})]),
							Builder.node('tr', [Builder.node('td', {className: 'bubblebottomleftcorner'}), Builder.node('td', {className: 'bubble' + this.options.orientation + 'bottom'}), Builder.node('td', {className: 'bubblebottomrightcorner'})])])
						]) ;

				insertAtElement.insert({after: newElement}) ;

				if (this.options.closeButton == true) this.options.closeButton = closeButtonId ;			// now return the new button object id to the options object

			}

		}
		else {
			newElementId = elementId ;
		}

		if (Prototype.Browser.IE) $$('body')[0].appendChild($(newElementId).remove()) ; // resolves overlapping problems due to IE 6/7 z-index bug

		return newElementId ;			// return the new bubble object id

	},

	show: function() {
		if (this.fadeOutTimer != "") {
			clearTimeout(this.fadeOutTimer) ;
			this.fadeOutTimer = "" ;
		}
		
		if (this.element.getStyle('display') == "none") {
			new Effect.Parallel([ 
	 			new Effect.Appear(this.element, {from: 0.0, to: 1.0}) ,
				new Effect.Move(this.element, {y: (this.options.orientation == 1 ? -6 : 6)})
			], {duration: this.options.showDuration, queue: {position: 'end', scope: this.scope, limit: 1}}) ;
		}

	},

	fadeOut: function() {
		if (this.fadeOutTimer == "") this.fadeOutTimer = this.doFadeOut.delay(this.options.closeDelay, this) ;
		
	},

	doFadeOut: function(elementId) {
		new Effect.Fade(elementId.element, {
			from: 1.0, 
			to: 0.0, 
			duration: elementId.options.fadeDuration, 
			queue: {position: 'end', scope: elementId.scope, limit: 1}, 
			afterFinish: function(effect) {effect.element.setStyle({top: (parseInt(effect.element.getStyle('top')) - (elementId.options.orientation == 1 ? -6 : 6)) + "px"}) ;}
		}) ;

		elementId.fadeOutTimer = "" ;
	},

	DefaultOptions: {
		setupBubble:		false,	// true = object inserts bubble style html/css into element, false = element style is not touched
		orientation:		2,		// 1 = bubble above, <> 1 = bubble below
		showDuration:		0.4,	// seconds
		openOnMouseover:	false,	// true = bubble opens on mouseover, false = bubble opens only on click
		openDelay:			0.3,	// not yet implemented
		fadeDuration:		0.4,	// seconds
		closeButton:		'',		// true = insert closeButton while setup (setupBubble = true), otherwise object id of existing button, automatic closing if empty
		closeDelay:			1		// seconds, only when no closeButtons is defined (auto closing)
	}

}) ;


var ExwButton = Class.create({
	initialize: function(elementId, labelElementId, options) {
		this.element = $(elementId);
		if (typeof labelElementId == "undefined" || labelElementId == "") {
			this.hasLabel = false;
		}
		else {
			this.labelElement = $(labelElementId);
			this.hasLabel = true;
		}

		this.hasMouse = false;
		this.effect = 0;
		this.hideTimer = "" ;
		
		this.options = Object.extend(Object.extend({ }, this.DefaultOptions), options || { }) ;

		this.addButton(this.element);	

		if (this.options.hasOverState || this.options.hasClickState) {
			this.imageUrl = this.element.src ;
			if (this.options.hasOverState) this.options.overImageUrl == "" ? this.overImageUrl = this.element.src.replace(/(\.jpg|\.gif|\.png)/, "_over$1") : this.overImageUrl = this.options.overImageUrl;
			if (this.options.hasClickState) { 
				this.options.clickImageUrl == "" ? this.clickImageUrl = this.element.src.replace(/(\.jpg|\.gif|\.png)/, "_click$1") : this.clickImageUrl = this.options.clickImageUrl;
				this.element.observe('mousedown', this.click.bindAsEventListener(this));
			}
		}

		if (this.hasLabel) {
			this.addButton(this.labelElement);
			this.labelElement.style.display = "none" ;
		}

	},

	addButton: function(buttonId) {
		$(buttonId).observe('mouseover', this.show.bindAsEventListener(this));
		$(buttonId).observe('mouseout', this.fadeOut.bindAsEventListener(this));

	},
	
	show: function() {
		this.hasMouse = true;

		if (this.options.hasOverState) this.element.src = this.overImageUrl;

		if (this.hasLabel) {
			if (this.hideTimer != "") {
				window.clearTimeout(this.hideTimer) ;
				this.hideTimer = "" ;
			}

			if (isNaN(this.effect)) {
				if (this.effect.state != "finished") this.effect.cancel() ;
			}
		}		

		if (this.hasMouse && this.options.beforeShow) this.options.beforeShow(this);
		if (this.hasMouse && this.hasLabel) {
			this.opacity = this.labelElement.getStyle('display') == "none" ? 0 : this.labelElement.getStyle('opacity') ;
			this.effect = new Effect.Appear(this.labelElement, { duration: this.options.showDuration, from: this.opacity, 
				afterFinish: function(effect) { 
					effect.element.show(); 
				} 
			}) ;
		}
		if (this.hasMouse && this.options.afterShow) this.options.afterShow.delay(this.options.fadeDuration, this);

	},

	fadeOut: function() {
		this.hasMouse = false;

		if (this.options.hasOverState) this.element.src = this.imageUrl;

		if (this.hideTimer == "") {
			this.hideTimer = this.doFadeOut.delay(this.options.fadeDelay, this) ;
		}

	},

	doFadeOut: function(elementId) {
		elementId.hideTimer = "" ;

		if (elementId.hasLabel) {
			if (isNaN(elementId.effect)) {
				if (elementId.effect.state != "finished") elementId.effect.cancel() ;

			}
		}

		if (!this.hasMouse && elementId.options.beforeHide) elementId.options.beforeHide(elementId);
		if (!this.hasMouse && elementId.hasLabel) {
			elementId.effect = new Effect.Fade(elementId.labelElement, { duration: elementId.options.fadeDuration, from: elementId.labelElement.getStyle('opacity'), 
				afterFinish: function(effect) { 
					effect.element.hide(); 
				} 
			}) ;
		}
		if (!this.hasMouse && elementId.options.afterHide) elementId.options.afterHide.delay(elementId.options.fadeDelay+elementId.options.fadeDuration, elementId);

	},

	click: function() {
		this.element.src = this.clickImageUrl;
	},

	DefaultOptions: {
		hasOverState:	false,	// button has image for over event, if true
		overImageUrl:	'',		// image to be used on over event (if empty, default name is 'xxx_over.yyy')
		hasClickState:	false,	// button has image for mousedown event, if true
		clickImageUrl:	'',		// image  to be used on mousedown event (if empty, default name is 'xxx_click.yyy')
		showDuration:	0.2,	// seconds
		fadeDuration:	0.5,	//
		fadeDelay:		0.2,	//
		beforeShow:		null,
		afterShow:		null,
		beforeHide:		null,
		afterHide:		null
	}

}) ;


var Drawer = Class.create({
	initialize: function(elementId, handleId, options) {
		this.options = Object.extend(Object.extend({ }, this.DefaultOptions), options || { }) ;
		this.element = $(elementId) ;
		this.addHandle(handleId) ;
	},

	addHandle: function(handleId) {
		$(handleId).observe('click', this.toggle.bindAsEventListener(this));
	},

	toggle: function() {
		if (this.element.getStyle('display') == "none") {
			this.open() ;
		}
		else {
			this.close() ;
		}
	},

	open: function() {
		new Effect.BlindDown(this.element, {duration: this.options.effectDuration, queue: 'end'}) ;
	},

	close: function() {
		new Effect.BlindUp(this.element, {duration: this.options.effectDuration, queue: 'end'}) ;
	},

	DefaultOptions: {
		effectDuration:		0.2,									// seconds
		animateHandle:		false,									//
		openImgFile:		'/shared/images/buttons/plus.gif',		//
		closeImgFile:		'/shared/images/buttons/minus.gif'		//
	}

}) ;


var FanMenu = Class.create({
	initialize: function(elementId, fanItemOpenedWidth, options) {
		this.options = Object.extend(Object.extend({ }, this.DefaultOptions), options || { }) ;

		this.element = $(elementId);
  		this.fanMenuItems = [];
  		this.resetTimer = "";

   		this.fanItemOpenedWidth = fanItemOpenedWidth ;
		if (fanItemOpenedWidth == 0) this.options.breadCrumbMode = true ;

		this.ulElement = $(this.element.firstDescendant()) ;
		if (this.ulElement.tagName.toLowerCase() != "ul") return null;

		this.fanWidth = this.element.getWidth() ;
		this.fanTotalWidth = 0 ;
		this.liElements = $(this.ulElement.childElements()) ;
		this.fanMenuSize = this.liElements.size() ;
		this.semiCollapseFactor = 1 ;
		this.collapseFactor = 1 ; 
		this.startWith = 1 ;
		this.endWith = 0 ;

		var newItem = null ;
		var totalWidth = 0 ;
		var lockedWidth = 0 ;
		var semiCollapsibleWidth = 0 ;
		var collapsibleWidth = 0 ;


		for (i = 0; i < this.fanMenuSize; i++) {
			newItem = new FanMenuItem(this.liElements[i], this, i) ;
			this.fanMenuItems.push(newItem) ;
			if (this.options.breadCrumbMode && this.fanMenuSize > 1) {
				totalWidth += newItem.width ;
				if (i == 0 || i == this.fanMenuSize - 1) {
					lockedWidth += newItem.width ;
				}
				else if (this.fanMenuSize > 4 && (i == 1 || i == this.fanMenuSize - 2)) {
					semiCollapsibleWidth += newItem.width ;
				}
				else {
					collapsibleWidth += newItem.width ;
				}
			}
		};
		if (this.options.breadCrumbMode) {
			if (totalWidth <= this.fanWidth || lockedWidth > this.fanWidth || this.fanMenuSize < 3) return this.release() ;
			semiCollapseFactor = collapseFactor = (this.fanWidth - lockedWidth - semiCollapsibleWidth) / collapsibleWidth;

			if (collapseFactor > 0.45) {
				this.startWith = 2 ;
				this.endWith = this.fanMenuSize - 3;
			}
			else {
				// TO DO: semiCollapseFactor has still to be calculated and used!
				collapseFactor = ((this.fanWidth - lockedWidth) / (semiCollapsibleWidth + collapsibleWidth));
				this.startWith = 1;
				this.endWith = this.fanMenuSize - 2;

                if ((this.fanMenuItems[this.startWith].width * collapseFactor) <= 30) return this.release();
			}

			this.fanMenuItems.each(function(item, index) {
				if (index >= this.startWith && index <= this.endWith) {
				    item.setCollapsedWidth(Math.round(item.width * collapseFactor));
				}
			}.bind(this)); 
		}
		else {
			this.fanItemStandardWidth = Math.round(this.fanWidth / this.liElements.size()) ;
			this.fanItemMiniWidth = (this.fanWidth - this.fanItemOpenedWidth) / (this.liElements.size() - 1) ;
			this.startWith = 0 ;
			this.endWith = this.fanMenuSize - 2 ;
		}

		this.element.observe('mouseout', this.reset.bindAsEventListener(this)) ;

		this.reset() ;

	},

	reset: function() {
		if (this.resetTimer == "") {
			this.resetTimer = this._doReset.delay(this.options.resetDelay, this) ;
		}
	},

	_doReset: function(elementId) {
		elementId.resetTimer = "" ;
		elementId.fanItemSelected = -1 ;
		elementId.fanMenuItems.invoke("reset") ;
	},

	release: function() {
		this.fanMenuItems.invoke("release") ;
		this.element.stopObserving() ;

		return (this.element = null);
	},

	DefaultOptions: {
		breadCrumbMode:				false,
		animationDuration:			0.2,	// seconds
		resetDelay:					0.3,	//
		resetAnimationDuration:		0.4		//
	}

}) ;


var FanMenuItem = Class.create({
	initialize: function(elementId, parentId, itemNo) {
		this.element = $(elementId) ;
		this.parent = parentId ;
		this.itemNo = itemNo ;

		this.label = this.element.firstDescendant().innerHTML;
		this.collapsedLabel = "";
		this.width = this.element.getWidth() ;
		this.actualWidth = 0 ;

		this.animation = 0 ;

		this.element.observe('mouseover', this.open.bindAsEventListener(this));

		//return this.element ;

	},

	setCollapsedWidth: function(width) {
		this.collapsedWidth = width ;
	},

	open: function() {
		this.parent.fanItemSelected = this.itemNo ;
		if (this.parent.resetTimer != "") {
			window.clearTimeout(this.parent.resetTimer) ;
			this.parent.resetTimer = "" ;
		}

		this.animate((this.parent.options.breadCrumbMode ? this.width + 1 : this.parent.fanItemOpenedWidth), this.parent.options.animationDuration) ;
			this.parent.fanMenuItems.each( function(elementId) {
				if (elementId.itemNo != elementId.parent.fanItemSelected) elementId.minimize();

			});
	},

	minimize: function() {
		this.animate((this.parent.options.breadCrumbMode ? this.collapsedWidth : this.parent.fanItemMiniWidth), this.parent.options.animationDuration) ;
	},

	reset: function() {
		this.animate((this.parent.options.breadCrumbMode ? this.collapsedWidth : this.parent.fanItemStandardWidth), this.parent.options.resetAnimationDuration) ;
	},
	
	animate: function(toWidth, animationDuration) {
		if (this.itemNo < this.parent.startWith || this.itemNo > this.parent.endWith) return;

		if (isNaN(this.animation)) if (this.animation.state != "finished") {
			this.animation.cancel() ;
			this._redrawLabel();
		}

		this.actualWidth = this.element.getWidth() ;
		if (this.actualWidth > (toWidth + 1) || this.actualWidth < (toWidth - 1)) {
			var fromToWidth = toWidth * 100 / this.actualWidth ;

			if (this.parent.options.breadCrumbMode) {
				this.animation = new Effect.Scale(this.element, Math.round(fromToWidth*10)/10, { duration: animationDuration, scaleY: false, scaleContent: false, scaleMode: { originalWidth: Math.round(this.actualWidth) }, afterFinish: this._redrawLabel.bind(this) } ) ;
			}
			else {
				this.animation = new Effect.Scale(this.element, Math.round(fromToWidth*10)/10, { duration: animationDuration, scaleY: false, scaleContent: false, scaleMode: { originalWidth: Math.round(this.actualWidth) } } ) ;
			}
		}
	},

	_redrawLabel: function() {
		if (!this.parent.options.breadCrumbMode) return; 

		var curWidth = this.element.getWidth();

		if (curWidth >= this.width - 1) {
			this.element.firstDescendant().innerHTML = this.label ;
		}
		else {
			if (this.collapsedLabel == "") {
				var tempLi = new Element('li', { style: 'display: none'});
				var tempText = "";
				var tempText2 = "";
	
				this.element.up().insert({ bottom: tempLi });
				if (this.element.className != "") tempLi.className = this.element.className;
				tempLi.insert({ top: this.element.innerHTML });
	
				tempText2 = tempLi.firstDescendant().innerHTML ;
				var i = 0;
	
				while (tempLi.getWidth() > curWidth && i < 40) {
					i++;
					tempText = tempText2;
					tempText2 = tempText.substring(0, Math.floor(tempText.length/2)) + tempText.substring(Math.round(tempText.length/2), tempText.length);
					if (tempText2 == tempText) tempText2 = tempText.substring(0, Math.floor(tempText.length/2)) + tempText.substring(Math.round(tempText.length/2+1), tempText.length);
	
					tempLi.firstDescendant().update(tempText2+"...");
				}
				this.collapsedLabel = tempText.substring(0, Math.floor(tempText.length/2)) + "..." + tempText.substring(Math.round(tempText.length/2+1), tempText.length);
				tempLi.remove();
			}
	
			this.element.firstDescendant().innerHTML = this.collapsedLabel ;
		}
	},

	release: function() {
		this.element.stopObserving() ;
		return (this.element = null);
	}

}) ;


var ShowCase = Class.create({
	initialize: function(elementId, options) {
		this.element = $(elementId) ;
		this.options = Object.extend(Object.extend({ }, this.DefaultOptions), options || { }) ;
		this.liElement = this.element.select('li') ;
		this.liCount = this.liElement.size() ;
		this.activeElement = 0 ;
		this.lastElement = 0 ;

		this.executer = new PeriodicalExecuter(this.play.bind(this), this.options.showDuration) ;

		return this.element ;
	},

	play: function() {
		this.lastElement = this.activeElement ;
		
		if (this.options.randomMode) {
			do { this.activeElement = Math.floor(Math.random() * this.liCount) ; } while (this.lastElement == this.activeElement) ;
		}
		else {
			this.activeElement += 1 ;
			if (this.activeElement > this.liCount - 1) this.activeElement = 0 ;
		}

		if (this.activeElement < this.lastElement) {
			if (this.lastElement != 0)
			new Effect.Fade(this.liElement[this.lastElement].select('img')[0], { duration: this.options.effectDuration,
				beforeStart: function(effect) {
					if (this.lastElement != 0) this.liElement[this.activeElement].select('img')[0].show() ;
					}.bind(this)
			}) ;
		}
		else {
			new Effect.Appear(this.liElement[this.activeElement].select('img')[0], { duration: this.options.effectDuration, 
				afterFinish: function(effect) {
					if (this.lastElement != 0) this.liElement[this.lastElement].select('img')[0].hide() ;
					}.bind(this)
			}) ;
		}
	},

	stop: function() {
		this.executer.stop();

	},

	release: function() {
		this.stop() ;
		return (this.element = null) ;
	},

	DefaultOptions: {
		showDuration:	9,		// seconds
		effectDuration:	1.2,
		randomMode:		false	//
	}

}) ;


var PageOverlay = Class.create({
	initialize: function(options) {
		this.options = Object.extend(Object.extend({ }, this.DefaultOptions), options || { }) ;

		// create page overlay element
		do {
			newElementId = "pageOverlay_" + new Date().getTime() ;
		} while (document.getElementById(newElementId)) ;
	
		$$('body')[0].appendChild( Builder.node('div', {id: newElementId, style: 'background-color: ' + this.options.color + '; display: none; height: 500px; left: 0; position: absolute; top: 0; width: 100%; z-index: ' + this.options.zIndex }) );
		this.element = $(newElementId) ;

		this.clickObserver = this.element.observe('click', this.click.bindAsEventListener(this))

		return this.element;
	},

	show: function() {
	   	this.element.setStyle({ width: document.viewport.getWidth() + 'px', height: document.viewport.getHeight() + 'px' }) ; 	// update overlay to current viewport dimensions
		new Effect.Appear(this.element, { duration: this.options.effectDuration, from: 0.0, to: this.options.opacity, queue: 'end' });
	},

	click: function(event) {
		event.stop();

		this.element.stopObserving('click', this.clickObserver);
		this.hide();

		if (this.options['onClick']) this.options['onClick'](this);		// call custom defined function
	},

	hide: function() {
		new Effect.Fade(this.element, { duration: this.options.effectDuration, queue: 'end' });

	},

	DefaultOptions: {
		color:			'#000000',
		zIndex:			900,
		effectDuration:	0.2,
		opacity:		0.4,
		onClick:		null
	}

}) ;


// ---------------------------------------------------------------------------------------------
// div. alte Funktionen

function changeImgSrc(imgName, newImg) {
	document.getElementsByName(imgName)[0].src = newImg;

}


function mysubmit(i)
{
  document.forms[i].submit();
  return true;
}


function popup(){
	var vr="";
	vr = vr + "width=" + arguments[1];
	vr = vr + ",height=" + arguments[2];
	vr = vr + ",scrollbars=" + arguments[3];
	vr = vr + ",resizable=" + arguments[4];
	vr = vr + ",menubar=no,toolbar=no,directories=no,location=no,status=no";
	window.open(arguments[0],"",vr);
}


function showGenehmigungen() {
	window.open('/seite/pg_genehmigungen','','width=600,height=400,scrollbars=yes,resizable=no');
}


// ---------------------------------------------------------------------------------------------
// Funktionen fuer die Suche

var currentTimeouts = new Array(); 

function simpleQuickSearch(livesearchValue, target) { 
	
	if( currentTimeouts[target] ) { 
		clearTimeout( currentTimeouts[target] );
		$('livesearchwait').src='/huebershop/img/bug.gif';
	} 
	
	// Suche ab mind. 3 Zeichen abschicken
	if (livesearchValue.length > 2) { 
		currentTimeouts[target] = setTimeout(function() { doSimpleQuickSearch(); } , 100 );
	} else {
		// DIV ausblenden
    	$('searchoutput').style.visibility = 'hidden';
	}
} 

/* Schnellsuche */
function doSimpleQuickSearch() { 
    	
    	$('livesearchwait').src='/huebershop/img/allgemein/livesearchwait.gif';
    	
        saveForm('/huebershop/schnellsuche.html', 'livesearchForm', 'searchoutput', true);
		
		if ($('zgheaderzgauswahl')!=null) {
			$('zgheaderzgauswahl').style.visibility = 'hidden';
		}
		
        $('searchoutput').style.visibility = 'visible'; 
}

/* Formular abschicken und Ausgabe in Ziel-DIV */ 
function saveForm(url, formName, placeholder, js) { 

    if (!js) { 
        js = false; 
    } 
    var pars = Form.serialize(formName); 
    
    // alert("pars: " + pars); 
    var myAjax = new Ajax.Updater( placeholder, url, { method: 'get', parameters: pars, evalScripts: js }); 
}

function redirectSearchResult(category, view) {
	
	newUrl = '/huebershop/gesamtsuche.html?livesearchKeywords=' + $('livesearchKeywords').value;
	
	/* Feld mit UTF-8 Wert zusaetzlich uebergeben, um korrekte Codierung zu erzwingen */
	newUrl += '&d=' + $('d').value;
	
	if(category!='')
		newUrl += '&category=' + category;
		
	if(view!='')
		newUrl += '&view=' + view;
		
	window.location.href =  encodeURI(newUrl);
	
}

function initLivesearchOverlay() {
	
	var livesearchContent = $('searchoutput').remove() ;
	$("footerblock").insert({after: livesearchContent});

	var positionLeft = $('livesearchKeywords').cumulativeOffset().left - 2;
	var positionTop = $('livesearchKeywords').cumulativeOffset().top - $('searchoutput').cumulativeOffset().top + 20;

	$('searchoutput').setStyle({ left: positionLeft+'px', position: 'relative', top: positionTop+'px' }) ;
}


// ---------------------------------------------------------------------------------------------
// Funktionen zur LWS-Navigation

var loaded;
var interx;
var intervalTimer = 250;

function displaySubNavi(id){
	window.clearInterval(interx);
	if(loaded != id){
		if(id)
			intervalTimer = 250;
		else
			intervalTimer = 1500;
		
		interx = window.setTimeout("checkDisplay("+id+");",intervalTimer);
	}
}

function hideSubNavi(id){
	displaySubNavi();
}

function checkDisplay(id){
	if($('subn_'+loaded)){
		closeDrawer('subn_'+loaded);
	}
	loaded = 0;
	if(id){
		/*
		var mover = document.createAttribute("onmouseover");
		var mout = document.createAttribute("onmouseout");
			mover.nodeValue = "displaySubNavi('"+id+"');";
			mout.nodeValue = "hideSubNavi();";
		$('subn_'+id).setAttributeNode(mover);	
		$('subn_'+id).setAttributeNode(mout);	

		$('subn_'+id).setAttribute('onmouseover',"displaySubNavi('"+id+"');");	
		$('subn_'+id).setAttribute('onmouseout',"hideSubNavi();");	
		*/
		openDrawer('subn_'+id);
		loaded = id;
	}
}


// ---------------------------------------------------------------------------------------------
// Funktionen zum Online-Woerterbuch

function sendFormHWB()
{
    window.open('about:blank', 'PopWnd', 'width=900,height=600,scrollbars=yes');
    window.setTimeout('window.document.forms[\'myform\'].submit();', 1);
}
