// ---------------------------------------------------------------
// Class Popup
// (C) Copyright by Publicform GmbH (www.publicform.de)
//
// Version: 2.0
// Date: 2006-02-02
// Author: Andreas Doelling (doelling@publicform.de)
//
// Pops up a browser window, if it gets a click or keypress event
// on an HTML node with the CSS class "popup [type]".
// ---------------------------------------------------------------

function Popup() {
	this.currentType 	= '';
	this.currentHref 	= 'about:blank';
	this.types			= 	{
							video: 		{ windowName: 'video', windowSettings: 'width=808,height=530,left=0,top=0,resizable=yes,scrollbars=yes' }, 
							audio: 		{ windowName: 'audio', windowSettings: 'width=810,height=575,left=0,top=0,resizable=no,scrollbars=yes' }, 
							job: 		{ windowName: 'job', windowSettings: 'width=666,height=700,left=50,top=50,resizable=yes,scrollbars=yes' },
							history: 	{ windowName: 'history', windowSettings: 'width=560,height=800,left=0,top=0,resizable=yes,scrollbars=yes' }, 
							ecard: 		{ windowName: 'ecard', windowSettings: 'width=875,height=670,left=0,top=0,resizable=yes,scrollbars=yes' }, 
							toc: 		{ windowName: 'toc', windowSettings: 'width=640,height=590,left=0,top=0,resizable=no,scrollbars=yes' }, 
							discover: 	{ windowName: 'discover', windowSettings: 'scrollbars=no,width=787,height=550' }, 
							standard: 	{ windowName: 'popup', windowSettings: 'width=800,height=600' }
							}
	
	
	// -----------------------------------------------------
	// Method addType
	// Defines a new popup type.
	// -----------------------------------------------------
	this.addType = function(identifier, windowName, windowSettings) {
		if(typeof this.types[identifier] == 'object') {
			alert('Der Popup-Typ '+identifier+' ist bereits definiert!');
		} else {
			this.types[identifier] = { windowName: windowName, windowSettings: windowSettings };
		}
	}
	
	
	// -----------------------------------------------------
	// Method click
	// Handles click events propagated by a Controller object.
	// -----------------------------------------------------
	this.click = function(evt) {
		if(this != arguments.callee.scope){
	      if(typeof arguments.callee.apply == "function") {
			  	return arguments.callee.apply(arguments.callee.scope, arguments);
			} else {
		  		return  arguments.callee.scope.click(evt);
			}
	    }
		var srcElement = (evt.srcElement)? evt.srcElement : evt.target;
		if(this.isResponsible(srcElement)) {
			this.popup();
			return false;
		} else {
			return true;
		}
		return false;
	}
	this.click.scope = this;
	
	
	// -----------------------------------------------------
	// Method keypress
	// Handles keypress events propagated by a Controller object.
	// -----------------------------------------------------
	this.keypress = this.click;
	this.keypress.scope = this;
	
	
	// -----------------------------------------------------
	// Method isResponsible
	// Checks if the current Popup instance is responsible for
	// handling the propagated event, i.e. if the source elements
	// CSS class name is "popup_"+[type].
	// -----------------------------------------------------
	this.isResponsible = function(srcElement) {
		var classRegExp;
		// Check if the click came from an anchor node or from a node within an anchor:
		while(srcElement.tagName != "BODY" && srcElement.tagName != "A") {
			srcElement = srcElement.parentNode;
		}
		if(srcElement.tagName != "A") { 
			return false;
		}
		for(type in this.types) {
			classRegExp = new RegExp("popup\\s+" + type);
			if(srcElement.className.match(classRegExp)) {
				this.currentType = type;
				this.currentHref = srcElement.getAttribute("href");
				srcElement.blur();
				return true;
			}
		}
		return false;
	}
	
	
	// -----------------------------------------------------
	// Method popup
	// Opens a popup window.
	// -----------------------------------------------------
	this.popup = function() {
		window.open(this.currentHref, this.types[this.currentType]["windowName"], this.types[this.currentType]["windowSettings"]);
		return false;
	}
}

// C. Koch

function newPopup(obj)
	{
	var w = 808;
	var h = 530;
	var pop = null;
	//var url = (obj.getAttribute) ? obj.getAttribute('href') : obj.href;
	//if (!url) return true;
	w = (w) ? w += 20 : 150;
	h = (h) ? h += 25 : 150;
	var args = 'width='+w+',height='+h+',resizable,scrollbars=yes';
	pop = window.open('http://www.thomson-webcast.net/de/dispatching/?event_id=e9cb8861875d6bef51f28fd149c152d2&portal_id=a8a73e422f0a3887b5ac94a4eddfa32d','',args);
	//pop = window.open('http://www.google.de','',args);
	//return (pop) ? false : true;
	}






