function ticketConfirm(toid, showid, srcEl, showDate) {
	var vnr = toid.substr(4, 3);
	
	/*	anderer Popup-text für Aufführungen ab einer bestimmten Spielzeit anhand der Stück-IDs
		
	
	if ((vnr > 399 && vnr < 600) || vnr > 800) {		
		var content = ''+
		'<div class="ticketPopup">'+
		'Der Vorverkauf für die gesamte Spielzeit 2008/2009 beginnt am 25. August 2008.<br>'+
		'Karten können aber ab sofort online oder schriftlich reserviert werden.<br>Die Reservierungen werden in der Reihenfolge des Eingangs bearbeitet und schriftlich Ende August 2008 beantwortet. Platzwünsche werden, soweit möglich, berücksichtigt. Bei Abonnement-Vorstellungen steht jedoch nur ein beschränktes Kartenkontingent zum Verkauf zur Verfügung.'+
		'<div class="button" style="width:200px;"><a style="color:#ffffff; text-decoration:none;" href="kartenbestellung?Open&amp;showId='+showid+'">Reservierung über die Theaterkasse</a></div>'+
		'<br>&nbsp;</div>';
	} else {*/
	
	
	
	var content = ''+
	'<div class="ticketPopup">'+
	'Ihre Online-Ticketbestellung wird über den externen Anbieter "Ticket online GmbH" abgewickelt. Dieses Unternehmen agiert unabhängig vom Stadttheater Fürth. Es gelten dessen Allgemeine Geschäftsbedingungen und Bestellmodalitäten. Es wird eine Vorverkaufs- und Versandgebühr erhoben. Dieser Bestellvorgang ermöglicht Ihnen freie Platzwahl über die Saalplanfunktion und stellt einen verbindlichen Kaufvorgang dar.';
	/* remove next line n 24.August 2009 */
	var time = new Date();
	if(time.getTime() < Date.parse('24 Aug 2009 00:00:00')) {
		content = content +'<br><br>Karten für die Spielzeit 2009/2010 können Sie erst zu Beginn des Vorverkaufs ab dem 24. August 2009 über Ticket online bestellen.';
	}
	content = content + '<div class="button" style="width:200px; margin-top:5px;"><a style="color:#ffffff; text-decoration:none;" target="_blank" href="http://www.ticketonline.de/trans/prlist?LI=TO358&LG=DE&MENU=NO&VK=8500&IDX='+toid+'" onclick="return ticketOnline('+toid+')">Kartenbestellung über Ticket online</a></div>'+
	'<br><br><br>'+
	'Wenn Sie dies nicht wünschen, können Sie Ihre Tickets natürlich auch über die Theaterkasse bestellen. Bitte beachten Sie, dass diese Bestellungen nur während der Kassenöffnungszeiten bearbeitet werden können und kein Anspruch auf die bestellten Karten besteht. Unser Kassenteam wird sich schnellstmöglich mit Ihnen in Verbindung setzen.'+
	'<div class="button" style="width:200px;"><a style="color:#ffffff; text-decoration:none;" href="kartenbestellung?Open&amp;showId='+showid+'">Kartenbestellung über die Theaterkasse</a></div>'+
	'<br>&nbsp;</div>';
	
	if (showDate) {
		showDate = showDate.replace(/([^\.]*)\.([^\.]*)\.([^\.]*)/, "$3-$2-$1");
		if (showDate >= '2010-09-06') {
			content = ''+
			'<div class="ticketPopup">'+
			'Der Vorverkauf für die gesamte Spielzeit 2010/2011 beginnt am 6. September 2010. ' + 
			'<br>' +
			'Zu diesem Zeitpunkt ist auch der Direktverkauf über Ticket Online möglich.' +
			//'Telefonische Kartenreservierungen nehmen wir zu unseren Kassenöffnungszeiten entgegen.' +
			'<br><br>'+
			'Karten können ab sofort online reserviert werden. ' +
			'Bestellungen werden in der Reihenfolge des Eingangs bearbeitet und schriftlich Anfang September 2010 beantwortet. ' +
			'Platzwünsche werden, soweit möglich, berücksichtigt.' +
			'<br><br>'+
			'<div class="button" style="width:200px;"><a style="color:#ffffff; text-decoration:none;" href="kartenbestellung?Open&amp;showId='+showid+'">Kartenbestellung über die Theaterkasse</a></div>'+				
			'<br>&nbsp;</div>';		
		}
	}
	
	
	popContent(content, 'Kartenbestellung', srcEl)
	return false;
}

function ticketOnline(id) { 
	if(self.popInfo) self.popInfo.remove();
	popWin('http://www.ticketonline.de/trans/prlist?LI=TO358&LG=DE&MENU=NO&VK=8500&IDX='+id,'Ticket Online Kartenbestellung');
	return false;
}

function popWin(url, wintitle, height) {
	if(!height) height = 800;
	if(!wintitle) wintitle='';
	//document-Referenz, DOM-Id, css-ClassName, Instanz-Name, Window-Title, buttons, parentRef
	popInfo = new DragWin(self.document, 'dialogShow', 'dragWin', 'popInfo', wintitle, 'close');
	popInfo.create();
	iframeHeight = height;
	//maxHeight = document.documentElement.clientHeight - 110;
	maxHeight = document.documentElement.clientHeight - 80;
	if(iframeHeight > maxHeight) iframeHeight = maxHeight;
	popInfo.setPosTop(document.documentElement.scrollTop + 20 + 'px');
	popInfo.setContent('<iframe width="100%" height="'+iframeHeight+'" marginwidth="0" marginheight="0" frameborder="0" src="'+url+'"></iframe>');
}

function popContent(content, wintitle, srcEl) {
	if(!wintitle) wintitle='';
	//document-Referenz, DOM-Id, css-ClassName, Instanz-Name, Window-Title, buttons, parentRef
	popInfo = new DragWin(self.document, 'contentPop', 'dragWin popContent', 'popInfo', wintitle, 'close');
	popInfo.create();
	maxTop = document.documentElement.scrollTop + 20;
	thisTop = getPos(srcEl,'y') - 200;
	popInfo.setPosTop((maxTop>thisTop ? maxTop : thisTop) + 'px');
	popInfo.setContent(content);
}



//
// 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;
}

function getPos(obj, direction) {  //abs. Position ermitteln; Element-ID, 'left'|'top'
	var xpos = 0;
	var ypos = 0;
	myElement = obj;
	do {
		xpos += myElement.offsetLeft;
		ypos += myElement.offsetTop;
		myElement = myElement.offsetParent;
	}
	while(myElement.tagName != 'BODY' && myElement.tagName != 'HTML');
	if(direction == 'x') return xpos;
	if(direction == 'y') return ypos;
}

function popImg(imgUrl) {
	//document-Referenz, DOM-Id, css-ClassName, Instanz-Name, Window-Title, buttons, parentRef
	popInfo = new DragWin(self.document, 'dialogShow', 'dragWin', 'popInfo', '', 'close');
	popInfo.create();
	runner = 0;
	popInfo.setPosTop(document.documentElement.scrollTop + 20 + 'px');
	popInfo.setContent('<img src="'+imgUrl+'" alt="">');
	checkImgPopWidth();
}

function popGallery() {
	//document-Referenz, DOM-Id, css-ClassName, Instanz-Name, Window-Title, buttons, parentRef
	popInfo = new DragWin(self.document, 'contentPop', 'dragWin galleryWin', 'popInfo', '', 'close');
	popInfo.create();
	popInfo.setPosTop(document.documentElement.scrollTop + 20 + 'px');
	popInfo.setContent('<div id="gallery"></div>');
	popInfo.show();
}


function checkImgPopWidth() {
	if(self.cipwTO) clearTimeout(cipwTO);
	if(popInfo.getContentImgWidth() < 40) {
		cipwTO=setTimeout("checkImgPopWidth()", 200);
	}
	popInfo.setContentWidth(popInfo.getContentImgWidth()+1);
	popInfo.centerH();
	setTimeout("popInfo.show()",200);
}

//
// 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;
	}
}

function getElementsByClassName(node, classname) {
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
		if(re.test(els[i].className)) a.push(els[i]);
	return a;
}

function getElementsByAttributeValue(node, attrib, value) {
	var elements = new Array();
	if(node) {
		if(node.tagName && node.getAttribute(attrib) && node.getAttribute(attrib).indexOf(value) != -1)
			elements[elements.length] = node;
	}
	if(node.hasChildNodes) {
		for(var x=0; x<node.childNodes.length; x++) {
			var childElements = getElementsByAttributeValue(node.childNodes[x], attrib, value);
			for(var i=0; i<childElements.length; i++)
				elements[elements.length] = childElements[i];
		}
	}
	return elements;
}

function addEvent(obj, evt, fn) {
	if(obj.addEventListener) {
		obj.addEventListener(evt, fn, false);
	} else {
		obj.attachEvent('on'+evt, fn);
	}
}

function removeEvent(obj, evt, fn) {
	if(obj.removeEventListener) {
		obj.removeEventListener(evt, fn, false);
	} else {
		obj.detachEvent('on'+evt, fn);
	}
}

function loading(action) {
	if(action == 'show') {
		toggleSelects(0);
		disp = 'block';
	}
	else disp = 'none';
	if(document && document.getElementById('loading')) document.getElementById('loading').style.display = disp;
}


// ------------------------- Popup ---------------------------

var movingElement = false;
var scrollX = 0;
var scrollY = 0;
  
function DragWin(documentRef, elId, elClass, elInst, title, buttons, parentRef) {
	this.ovEl = false;
	this.documentRef = documentRef;
	if(!parentRef) this.parentRef = documentRef.body;
	else this.parentRef = parentRef;
	this.dEl = false;
	this.dElTitle = false;
	this.dElContent = false;
	this.elId = elId;
	this.elClass = elClass;
	this.offsetX = 0;
	this.offsetY = 0;
	this.content = '';
	this.buttons = buttons;
	this.title = title;
	this.elInst = elInst;
	this.startMove = function(e) {
		if(e && e.target) {
			var mouseX = e.pageX;
			var mouseY = e.pageY;
		}
		else {
			var mouseX = event.clientX;
			var mouseY = event.clientY;
		}
		this.offsetX = mouseX - this.dEl.offsetLeft;
		this.offsetY = mouseY - this.dEl.offsetTop;
		movingElement = this;
	}
	this.stopMove = function() {
		movingElement = false;
	}
	this.create = function() {
		setOverlay(1);
		// dragWin
		dEl = this.documentRef.createElement('table');
		dEl.id = this.elId;
		dEl.onmousemove = move;
		dEl.className = this.elClass;
		// border top
		dElBorderTop = dEl.insertRow(-1);
		borderTopLeft = this.documentRef.createElement('td');
		borderTopLeft.className = 'wBorderTopLeft';
		dElBorderTop.appendChild(borderTopLeft);
		borderTopCenter = this.documentRef.createElement('td');
		borderTopCenter.className = 'wBorderTopCenter';
		dElBorderTop.appendChild(borderTopCenter);
		borderTopRight = this.documentRef.createElement('td');
		borderTopRight.className = 'wBorderTopRight';
		dElBorderTop.onmousedown = function () {return false;}
		dElBorderTop.onselectstart = function () {return false;}
		dElBorderTop.ondragstart = function () {return false;}
		dElBorderTop.appendChild(borderTopRight);
		// title
		dElTitle = dEl.insertRow(-1);
		titleLeft = this.documentRef.createElement('td');
		titleLeft.className = 'wTitleLeft';
		dElTitle.appendChild(titleLeft);
		titleCenter = this.documentRef.createElement('td');
		titleCenter.className = 'wTitleCenter';
			titleContainer =  this.documentRef.createElement('div');
			titleContainer.style.width = '100%';
			titleContainer.style.height = '100%';
			titleContainer.style.position = 'relative';
			titleCenter.appendChild(titleContainer);
				titleContent = this.documentRef.createElement('div');
				titleContent.className = 'wTitle';
				titleContent.innerHTML = this.title;
				titleContainer.appendChild(titleContent);
		dElTitle.appendChild(titleCenter);
		titleRight = this.documentRef.createElement('td');
		titleRight.className = 'wTitleRight';
		//dElTitle.onmousedown = wrap(this, this.startMove);
		//dElTitle.onmouseup = wrap(this, this.stopMove);
		dElTitle.ondragstart = function () {return false;}
		dElTitle.appendChild(titleRight);
		// content
		dElContent = dEl.insertRow(-1);
		contentLeft = this.documentRef.createElement('td');
		contentLeft.className = 'wContentLeft';
		dElContent.appendChild(contentLeft);
		contentCenter = this.documentRef.createElement('td');
		contentCenter.className = 'wContentCenter';
		dElContent.appendChild(contentCenter);
		contentRight = this.documentRef.createElement('td');
		contentRight.className = 'wContentRight';
		dElContent.onmousedown = function () {return false;}
		dElContent.onselectstart = function () {return false;}
		dElContent.appendChild(contentRight);
		// border bottom
		dElBorderBottom = dEl.insertRow(-1);
		borderBottomLeft = this.documentRef.createElement('td');
		borderBottomLeft.className = 'wBorderBottomLeft';
		dElBorderBottom.appendChild(borderBottomLeft);
		borderBottomCenter = this.documentRef.createElement('td');
		borderBottomCenter.className = 'wBorderBottomCenter';
		//borderBottomCenter.innerHTML = '<span id="toStatustext">Ihre Online-Ticketbestellung wird über einen externen Anbieter &quot;Ticket online GmbH&quot; abgewickelt. Dieses Unternehmen agiert<br>unabhängig vom Stadttheater Fürth. Es gelten dessen Allgemeine Geschäftsbedingungen und Bestellmodalitäten.<br>Wenn Sie dies nicht wünschen, senden Sie einfach eine E-Mail mit dem Kartenwunsch an die Theaterkasse (<a style="color:#ffffff;" href="mailto:theaterkasse@fuerth.de">theaterkasse@fuerth.de</a>)</span>';
		dElBorderBottom.appendChild(borderBottomCenter);
		borderBottomRight = this.documentRef.createElement('td');
		borderBottomRight.className = 'wBorderBottomRight';
		dElBorderBottom.onmousedown = function () {return false;}
		dElBorderBottom.onselectstart = function () {return false;}
		dElBorderBottom.appendChild(borderBottomRight);
		
		addEvent(this.documentRef, 'mousedown', selectionDisable);
		addEvent(this.documentRef, 'selectstart', selectionDisable);	
		toggleSelects(0);
		this.parentRef.appendChild(dEl);
		this.dEl = dEl;
		this.dElTitle = titleContent;
		this.dElContent = contentCenter;
		this.setHandleButtons();
	}
	this.setContent = function(contentHTML) {
		this.dElContent.innerHTML = contentHTML;
	}
	this.setContentWidth = function(width) {
		this.dEl.style.width = width + contentLeft.offsetWidth + contentRight.offsetWidth + 'px';
	}
	this.setContentHeight = function(height) {
		this.dEl.style.height = height + dElTitle.offsetHeight + dElBorderBottom.offsetHeight + 'px';
	}
	this.setHandle = function(contentHTML) {
		this.dElTitle.innerHTML += contentHTML;
	}
	this.remove = function() {
		removeEvent(this.documentRef, 'mousedown', selectionDisable);
		removeEvent(this.documentRef, 'selectstart', selectionDisable);	
		toggleSelects(1);
		setOverlay(0);
		this.parentRef.removeChild(this.dEl);
		//this.documentRef.body.style.overflow = 'auto';
		this.dEl = false;
		this.dElDraghandle = false;
		this.dElContent = false;
	}
	this.setHandleButtons = function() {
		if(this.buttons.indexOf('close')!=-1) this.setHandle('<a href="javascript:'+this.elInst+'.remove()" class="wButtonClose"></a>');
	}
	this.setPosLeft = function(lPos) {
		this.dEl.style.left = lPos;
	}
	this.setPosTop = function(tPos) {
		this.dEl.style.top = tPos;
	}
	this.show = function() {
		this.dEl.style.visibility = 'visible';
	}
	this.centerH = function() {
		this.dEl.style.marginLeft = -Math.floor(this.dEl.offsetWidth/2) + 'px';
	}
	this.getWidth = function() {
		return this.dEl.offsetWidth;
	}
	this.getContentWidth = function() {
		return this.dElContent.offsetWidth;
	}
	this.getContent = function() {
		return this.dElContent.innerHTML;
	}
	this.getContentImgWidth = function() {
		if(this.dElContent.childNodes[0].tagName == 'IMG') {
			return this.dElContent.childNodes[0].offsetWidth;
		}
	}
}

function selectionDisable() {
	return false;
}

function toggleSelects(flag) {
	ua = navigator.userAgent.toLowerCase();
	if(ua.indexOf('msie')!=-1 && ua.indexOf('opera')==-1) {
		flag ? disp = 'visible' : disp = 'hidden';
		selects = document.getElementsByTagName('select');
		for(var i=0; i<selects.length; i++) {
			selects[i].style.visibility = disp;
		}
	}
}

function wrap(obj, method) {
	return function(e) {return method.call(obj, e, this)}
}

function move(e) {
	if(movingElement) {
		if(e && e.target) {
			var mouseX = e.pageX;
			var mouseY = e.pageY;
		}
		else {
			var mouseX = event.clientX;
			var mouseY = event.clientY;
		}
		xPos = mouseX - movingElement.offsetX;
		yPos = mouseY - movingElement.offsetY;
		
		if(xPos < document.body.scrollLeft) // ganz links
			movingElement.dEl.style.left = document.body.scrollLeft + 'px';
		else if(xPos + 2 + movingElement.dEl.offsetWidth > document.body.offsetWidth + document.body.scrollLeft)  // ganz rechts
			movingElement.dEl.style.left = document.body.offsetWidth + document.body.scrollLeft - movingElement.dEl.offsetWidth - 2 + 'px';
		else // ok 
			movingElement.dEl.style.left = xPos + 'px';
		
		if(yPos < document.body.scrollTop) // ganz oben
			movingElement.dEl.style.top = document.body.scrollTop + 'px';
		else if(yPos + movingElement.dEl.offsetHeight > document.body.offsetHeight + document.body.scrollTop)  // ganz rechts
			movingElement.dEl.style.top = document.body.offsetHeight + document.body.scrollTop - movingElement.dEl.offsetHeight + 'px';
		else // ok 
			movingElement.dEl.style.top = yPos + 'px';
	}
}


function setOverlay(on) {
	if(on) {
		if(!document.getElementById('overlay')) {
			objBody = document.getElementsByTagName("body").item(0);
			ov = document.createElement('div');
			ov.setAttribute('id','overlay');
			ov.style.position = 'absolute';
			ov.style.top = '0';
			ov.style.left = '0';
			ov.style.zIndex = '1000';
			objBody.appendChild(ov);
			addEvent(self, 'resize', checkOverlay);
		}
		ovEl = document.getElementById('overlay');
		winDim = getPageSize();
		ovEl.style.width = winDim[0] + 'px';
		ovEl.style.height = winDim[1] + 'px';
		ovEl.style.display = 'block';
	}
	else {
		if(document.getElementById('overlay')) document.getElementById('overlay').style.display = 'none';
	}
}

function checkOverlay() {
	if(document.getElementById('overlay') && document.getElementById('overlay').style.display == 'block') {
		ovEl = document.getElementById('overlay');
		winDim = getPageSize();
		ovEl.style.width = winDim[0] + 'px';
		ovEl.style.height = winDim[1] + 'px';
	}
}


