﻿if ( typeof ( SIM ) == 'undefined' ) var SIM = {};

SIM.addEvent = function ( obj, type, fn )
{
	if (obj.addEventListener) obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj[type+fn] = function() { fn.apply ( obj, [ window.event ] ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

SIM.addEventOnce = function ( eventName, obj, type, fn )
{
	if ( typeof ( this.onetimeEvents ) == 'undefined' ) this.onetimeEvents = {};
	if ( typeof ( this.onetimeEvents[ eventName ] ) == 'undefined' )
	{
		SIM.addEvent ( obj, type, fn );
		this.onetimeEvents[ eventName ] = true;
	}
}

SIM.removeEvent = function ( obj, type, fn )
{
	if (obj.removeEventListener) obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
	}
}

SIM.inArray = function ( needle, array )
{
	for ( var i = 0; i < array.length; i ++ )
	{
		if ( array[ i ] == needle ) return true;
	}
	
	return false;
}

SIM.inArrayi = function ( needle, array )
{
	var regexp = new RegExp ( needle, 'i' )
	
	for ( var i = 0; i < array.length; i ++ )
	{
		if ( regexp.exec ( array[ i ] ) )
		{
			return true;
		}
	}
	return false;
}

SIM.isArray = function ( obj )
{
   return obj.constructor.toString ( ).indexOf ( 'Array' ) != -1;
}

SIM.loadXMLString = function ( str ) 
{
	try //Internet Explorer
	{
		xmlDoc = new ActiveXObject ( 'Microsoft.XMLDOM' );
		xmlDoc.async = 'false';
		xmlDoc.loadXML ( str );
		return xmlDoc; 
	}
	catch ( e )
	{
		try //Firefox, Mozilla, Opera, etc.
		{
			parser = new DOMParser ( );
			xmlDoc = parser.parseFromString ( str, 'text/xml' );
			return xmlDoc;
		}
		catch ( e ) { }
	}
	
	return null;
}
	
SIM.loadXMLDoc = function ( dname ) 
{
	try //Internet Explorer
	{
		xmlDoc = new ActiveXObject ( 'Microsoft.XMLDOM' );
	}
	catch(e)
	{
		try //Firefox, Mozilla, Opera, etc.
		{
			xmlDoc = document.implementation.createDocument ( '', '', null );
		}
		catch(e) { }
	}
	
	try 
	{
		xmlDoc.async = false;
		xmlDoc.load ( dname );
		return xmlDoc;
	}
	catch ( e ) { }
	
	return null;
}
	
SIM.performXSLTransformation = function ( XMLDoc, XSLPath )
{
	var result = null;
	  
	if ( window.ActiveXObject )
	{		
		var XSLDoc = new ActiveXObject ( 'MSXML2.FreeThreadedDOMDocument' );
			XSLDoc.async = false;
			XSLDoc.load ( XSLPath );

		var XSLTemplate = new ActiveXObject("MSXML2.XSLTemplate");
			XSLTemplate.stylesheet = XSLDoc;

		var XSLProcessor = XSLTemplate.createProcessor ( );
			XSLProcessor.input = XMLDoc; 
			XSLProcessor.transform ( );
		
		result = XSLProcessor.output;
	}
	else if ( window.XSLTProcessor )
	{
		var processor = new XSLTProcessor ( );
			processor.importStylesheet ( SIM.loadXMLDoc ( XSLPath ) );

		result = processor.transformToFragment ( XMLDoc, document );
	}
	
	return result;
}
	
SIM.MOSS_RSS = function ( text, modifiers )
{
	this.text = text;
	this.xml = null;

	this.getAsText = function ( ) { return this.text; }	
	this.getAsXML = function ( ) { return this.xml; }

	this.removeProcessingInstruction = function ( string ) { return string.replace ( /<\?.+?\?>/g, '' ); }
	this.removeComments              = function ( string ) { return string.replace ( /<!--.+?-->/g, '' ); }
	this.removeCDataTag              = function ( string ) { return string.replace ( /<!\[CDATA\[/g, '' ).replace ( /]]>/g, '' ); }	
	this.replaceEntities             = function ( string ) { return string.replace ( /&lt;/g, '<' ).replace ( /&gt;/g, '>' ).replace ( /&quot;/g, '"' ); }
	this.replaceRootTag              = function ( string ) { return string.replace ( /<rss version="2.0">/g, '<wcms3Contents>' ).replace ( /<\/rss>/g, '</wcms3Contents>' ); }
	this.replaceDivs                 = function ( string ) { return string.replace ( /<div><b>(.+):<\/b>\s*/g, '<mossvar name="$1">' ).replace ( /<\/div>/g, '</mossvar>' ); }	
	this.addXMLDeclaration           = function ( string ) { return '<?xml version="1.0" encoding="UTF-8"?>' + string; }
	
	this.remodelText = function ( )
	{
		this.text = this.replaceEntities ( this.text );
		this.text = this.removeProcessingInstruction ( this.text );
		this.text = this.removeComments ( this.text );
		this.text = this.removeCDataTag ( this.text );
		this.text = this.replaceRootTag ( this.text );
		this.text = this.replaceDivs ( this.text );
		this.text = this.addXMLDeclaration ( this.text );
	}
	
	this.makeXML = function ( )
	{
		this.xml = SIM.loadXMLString ( this.text );
	}
	
	this.applyModifiers = function ( )
	{
		for ( var i = 0; i < modifiers.length; i ++ ) modifiers[ i ]( this.xml );
	}
	
	this.remodelText ( );
	this.makeXML ( );
	this.applyModifiers ( );
}

SIM.getRequestObj = function ( )
{
	var result = null;
	
	if		( window.XMLHttpRequest )	result = new XMLHttpRequest ( );
	else if ( window.ActiveXObject )
	{
		try {							result = new ActiveXObject ( 'Msxml2.XMLHTTP' ); }
			catch ( ex ) { try { 		result = new ActiveXObject ( 'Microsoft.XMLHTTP' ); }
				catch ( ex ) { }
		}
	}
	
	return result;
}

/** 
 *
 */
SIM.trim = function ( string ) { return string.replace ( /^\s*/, '' ).replace ( /\s*$/, '' ); }
SIM.ltrim = function ( string ) { return string.replace ( /^\s*/, '' ); }
SIM.rtrim = function ( string ) { return string.replace ( /\s*$/, '' ); }

/**
 * Tab-Steuerung:
 */
	SIM.Tab = function ( element, contentElement, initState, tabs, selector )
	{
		var self = this;
		
		this.active = initState;
		
		this.isActive = function ( )
		{
			return this.active;
		}
		
		this.getFilter = function ( )
		{
			var result = '+' + SIM.trim ( element.innerHTML ).replace ( /&amp;/, '' ).replace ( /&/, '' ).replace ( /\s+/g, '_' );
		
			var divs = element.getElementsByTagName ( 'DIV' );
			for ( var i = 0; i < divs.length; i ++ )
			{
				if ( divs[ i ].className == 'filter' )
				{
					result = divs[ i ].innerHTML;
					break;
				}
			}
			
			return result;			
		}
		
		this.getLabel = function ( )
		{
			return SIM.trim ( element.firstChild.nodeValue );
		}
		
		element.Tab_activate = function ( )
		{
			self.active = true;
						
			for ( var i = 0; i < tabs.length; i ++ ) tabs[ i ].deactivate ( contentElement );
			
			element.className = 'active';
			if ( contentElement ) contentElement.style.display = 'block';
			
			if ( selector ) 
			{
				if ( selector.length )
				{
					for ( var i = 0; i < selector.length; i ++ )
					{
						selector[ i ].setFilter ( self.getFilter ( ) );
						selector[ i ].execute ( '' );
					}
				}
				else
				{
					selector.setFilter ( self.getFilter ( ) );
					selector.execute ( '' );
				}
			}
		}
		
		this.activate = element.Tab_activate;
		
		element.Tab_deactivate = function ( nextContentElement )
		{
			self.active = false;
			
			element.className = '';
			if ( contentElement && nextContentElement ) contentElement.style.display = 'none';
		}
		
		this.deactivate = element.Tab_deactivate;
		
		element.onmouseup = function ( )
		{
			this.Tab_activate ( );
		}
	}
		
	SIM.Tabs = function ( tabId, tabContentsId, init, selector, initialTabIndex )
	{
		this.tabs = [];
	
		this.getActiveFilter = function ( )
		{
			for ( var i = 0; i < this.tabs.length; i ++ )
			{
				if ( this.tabs[ i ].isActive ( ) ) return this.tabs[ i ].getFilter ( );
			}
			
			return '';
		}
	
		this.init = function ( )
		{
			var tabs = document.getElementById ( tabId );
			var tabContents = document.getElementById ( tabContentsId );

			if ( typeof initialTabIndex == 'undefined' ) initialTabIndex = 0;
			
			if ( typeof tabs != 'undefined' && typeof tabContents != 'undefined' && tabs.hasChildNodes ( ) && tabContents.hasChildNodes ( ) )
			{
				for ( var i = 0; i < tabs.childNodes.length; i ++ )
				{
					if ( tabs.childNodes[ i ].nodeName == 'DIV' )
					{
						var contentElement = typeof tabContents.childNodes[ i ] != 'undefined' ? tabContents.childNodes[ i ] : null;					
						this.tabs.push
						(
							new SIM.Tab
							(
								tabs.childNodes[ i ],
								contentElement,
								this.tabs.length == initialTabIndex,
								this.tabs,
								selector
							)
						);
					}
				}
			}
			
			if ( typeof this.tabs[ initialTabIndex ] != 'undefined' ) this.tabs[ initialTabIndex ].activate ( );
		}

		this.select = function ( label )
		{
			for ( var i = 0; i < this.tabs.length; i ++ )
			{
				if ( this.tabs[ i ].getLabel ( ) == label )
				{
					this.tabs[ i ].activate ( );
				}
			}
		}
	
		if ( init ) this.init ( ); else SIM.addEvent ( window, 'load', this.init );
	}
	
/**
 *
 */
 	SIM.SelectorController = function ( )
	{
		this.selectors = {};		
		this.addSelector = function ( name, selector ) { this.selectors[ name ] = selector; }
			
		this.execute = function ( str )
		{
			var chunks = str.split ( /&/ );
			for ( var i = 0; i < chunks.length; i ++ )
			{
				chunks[ i ] = chunks[ i ].replace ( /\*/, '&' );
				
				var selection = chunks[ i ].split ( /=/ );
				if ( selection.length == 2 && typeof this.selectors[ unescape ( selection[ 0 ] ) ] != 'undefined' )
				{
					this.selectors[ unescape ( selection[ 0 ] ) ].select ( unescape ( selection[ 1 ] ) );
				}
			}
		}
	}
	
/**
 * Gibt den Namen der Site (aus der URL) zurück.
 */
	SIM.getSiteName = function ( )
	{
		if ( window.location.pathname.match ( /([^\/]*)\/Pages\// ) )
		{
			return escape ( RegExp.$1 );
		}		
		
		return '';	
	}

/**
 * Gibt A-Tags zurück, der href-Attribute dem übergebenem regulärem Ausdruck entsprechen.
 */	
	SIM.getATagByHref = function ( href )
	{
		var result = [];
		var as = document.getElementsByTagName ( 'A' );
		for ( var i = 0; i < as.length; i ++ ) if ( typeof ( as[ i ].href ) != 'undefined' && as[ i ].href.match ( href ) ) result.push ( as[ i ] );
		return result;
	}
	
/**
 *
 */
 	SIM.getLanguage = function ( )
	{
		var pattern = new RegExp ( '/b2b/([^/]+)/', 'i' );
		var result = pattern.exec ( window.location.href );
		
		return result.length > 0 ? result[ 1 ] : null;
	}
	
/**
 *
 */
 	SIM.getPortal = function ( )
	{
		var pattern = new RegExp ( '/b2b/[^/]+/([^/]+?)/', 'i' );
		var result = pattern.exec ( window.location.href );
		
		return result.length > 0 ? result[ 1 ] : null;
	}
	
/**
 *
 */
	SIM.findLinks = function ( urls, callback )
	{
		var result = new Array ( );
		var links = document.getElementsByTagName ( 'A' );
		
		for ( i = 0; i < links.length; i ++ )
		{
			for ( ii = 0; ii < urls.length; ii ++ )
			{
				if ( new RegExp ( urls[ ii ], 'i' ).test ( links[ i ].href ) )
				{
					if ( callback ) callback ( links[ i ] );
					result.push ( links[ i ] );
				}
			}
		}
		
		return result;
	}

/**
 *
 */
	SIM.onReady = function ( func )
	{
		if ( document.addEventListener ) document.addEventListener ( 'DOMContentLoaded', func, false );
		else if ( document.attachEvent ) document.attachEvent ( 'onreadystatechange', function ( ) { if ( document.readyState === "complete" ) func ( ); } );
	}
	
/**
 *
 ******************************************/

/**
 * Sorgt für die Anzeige der Element
 */
	SIM.Selector = function ( id )
	{
		var elements = [];
		var events = [];
		
		this.pageIndex = 0;
		this.filter = '';
		this.globalFilter = '';
		
		/**
		 * Speichert einen event handler für den übergebenen event.
		 *
		 * @param eventName Name des Events
		 * @param handler Event-Handler
		 */
			this.addEventHandler = function ( eventName, handler )
			{
				if ( typeof events[ eventName ] == 'undefined' ) events[ eventName ] = [];
				events[ eventName ].push ( handler );
			}
		
		/**
		 * Löst einen Event aus. 
		 *
		 * @param eventName Name des Events
		 * @param context Objekt das den Event ausgelößt hat
		 * @param info Zusätzliche Daten (JSON)
		 */
			this.triggerEvent = function ( eventName, context, info )
			{
				if ( typeof events[ eventName ] != 'undefined' )
				{
					for ( var i = 0; i < events[ eventName ].length; i ++ )
					{
						events[ eventName ][ i ] ( eventName, context, info );
					}
				}
			}

		/**
		 * Gibt die sichtbaren Elemente zurück.
		 */
			this.getElements = function ( ) { return elements; }
		
		/**
		 * Setzt den aktiven PageIndex
		 */
			this.setActivePageIndex = function ( pageIndex )
			{
				this.pageIndex = pageIndex;
				this.triggerEvent ( 'onSetActivePageIndex', this );
			}
		
		/**
		 * Gibt den aktiven PageIndex zurück
		 */
			this.getActivePageIndex = function ( ) { return this.pageIndex; }
		
		/**
		 * Setzt Klassen-Namen die vorhanden sein müssen
		 *
		 * @param mustHaveClasses array of strings
		 */
		 	this.setFilter = function ( filter ) { this.filter = filter; }
		
		/**
		 * Gibt das zuletzt verwendete FilterObject zurück
		 */
		 	this.getFilterObject = function ( ) { return this.filterObject; }
		
		/**
		 * Setzt einen globalen Filter
		 *
		 * @param filter
		 */
		 	this.setGlobalFilter = function ( globalFilter ) { this.globalFilter = globalFilter; }
		
		/**
		 * Parst einen filter-string
		 *
		 * @param filter String
		 */
		 	this.parseFilter = function ( filter )
			{
				var result = { or : [], all : [], not : [] };
				
				var filterParts = filter.split ( /\s*,\s*/ );
				
				// for ( var i in filterParts )
				for ( i = 0; i < filterParts.length; i ++ )				
				{
					var filterPart = filterParts[ i ];
					
					if ( filterPart.match ( /^([+-]?)(.+)$/ ) )
					{
						switch ( RegExp.$1 )
						{
							case '+':
								result.all.push ( RegExp.$2 );
								break;
								
							case '-':
								result.not.push ( RegExp.$2 );
								break;
								
							default:
								result.or.push ( RegExp.$2 );
						}
					}
				}
				
				return result;
			}
		
		/**
		 * Überprüft ob ein Element angezeigt werden soll oder nicht
		 *
		 * @param filter String mit den Filter eigenschaften
		 * @param tagString String mit den vorhandenen Tags
		 */
		 	this.checkVisibility = function ( filterObject, tagString )
			{
				var tags = tagString.split ( /\s+/ );
				
				for ( var i = 0; i < filterObject.all.length; i ++ ) if ( ! SIM.inArray ( filterObject.all[ i ], tags ) ) return false;				
				for ( var i = 0; i < filterObject.not.length; i ++ ) if ( SIM.inArray ( filterObject.not[ i ], tags ) ) return false;				
				for ( var i = 0; i < filterObject.or.length; i ++ ) if ( SIM.inArray ( filterObject.or[ i ], tags ) ) return true;

				return filterObject.or.length <= 0;
			}
		
		/**
		 * Zeigt die Element von start bis start + offset an
		 *
		 * @param start Integer
		 * @param offset Integer				 
		 */
			this.makeVisible = function ( start, offset )
			{
				var end = start + offset;
				for ( var i = 0; i < elements.length; i ++ ) elements[ i ].style.display = i >= start && i < start + offset ? 'block' : 'none';						
				this.triggerEvent ( 'onMakeVisible', this );
			}
		
		/**
		 * Zeigt die DIV-Element unterhalb eines Elements an, sofern der Klassenname übereinstimmt.
		 * 
		 * @param id ID des Parent-Elements
		 * @param className CSS-Klasse die angezeigt werden soll
		 */
			this.execute = function ( filter )
			{
				var filterObject = this.parseFilter ( filter + ',' + this.filter + ',' + this.globalFilter );
				this.filterObject = filterObject;
				
				var parent = document.getElementById ( id );
				if ( parent )
				{
					elements = [];
					
					for ( var i = 0; i < parent.childNodes.length; i ++ )
					{
						if ( parent.childNodes[ i ].nodeType == 1 && parent.childNodes[ i ].nodeName == 'DIV' )
						{
							try
							{
								if ( this.checkVisibility ( filterObject, parent.childNodes[ i ].className ) )
								{
									parent.childNodes[ i ].style.display = 'block';
									elements.push ( parent.childNodes[ i ] );
								}
								else
								{
									parent.childNodes[ i ].style.display = 'none';
								}
							}
							catch ( e ) { }
						}
					}
					
					this.triggerEvent ( 'onExecute', this );
				}
			}
	}
	
/**
 * Sorgt für die Anzeige der Seiten
 */
	SIM.PageSelector = function ( id, selector, numElementsPerPage )
	{
		var self = this;
		
		var pageLinks = [];				
		if ( typeof numElementsPerPage == 'undefined' ) this.numElementsPerPage = 15;
		else this.numElementsPerPage = numElementsPerPage;
		
		this.STRINGS = {
			label : 'Page '
		}
		
		/**
		 * Setter für die Anzahl der Einträger pro Seite
		 *
		 * @param numElementsPerPage
		 */
			this.setNumElementsPerPage = function ( numElementsPerPage ) { this.numElementsPerPage = numElementsPerPage; }
		
		/**
		 * Getter für die Anzahl der Einträger pro Seite
		 */
			this.getNumElementsPerPage = function ( ) { return this.numElementsPerPage; }
		
		/**
		 * Erstellt die nötigen PageLinks
		 */
			this.createPageLinks = function ( eventName, selector, info )
			{
				if ( ! selector ) return false;

				var numPages = Math.ceil ( selector.getElements ( ).length / self.numElementsPerPage );
				var parent = document.getElementById ( id );
				
				if ( parent )
				{
					self.clearElement ( parent );
					
					if ( numPages > 0 )
					{					
						var label = document.createElement ( 'DIV' );
							label.className = 'label';
							label.appendChild ( document.createTextNode ( self.STRINGS.label ) );
							
						parent.appendChild ( label );
												
						for ( var i = 0; i < numPages; i ++ )
						{
							var pageLink = document.createElement ( 'DIV' );
								pageLink.className = 'pageLink';
								pageLink.innerHTML = i + 1;								
								pageLink.onclick = function ( ) { selector.setActivePageIndex ( parseInt ( this.innerHTML ) - 1 ); }
							
							parent.appendChild ( pageLink );
							pageLinks.push ( pageLink );							
						}
						
						selector.setActivePageIndex ( 0 );
					}
				}
			}
			
		/**
		 * "Befreit" das element von allen seinen Kindern ;)
		 *
		 * @param element
		 */
			this.clearElement = function ( element )
			{
				var toDelete = [];
				for ( var i = 0; i < element.childNodes.length; i ++ ) toDelete.push ( element.childNodes[ i ] );
				for ( var i = 0; i < toDelete.length; i ++ ) toDelete[ i ].parentNode.removeChild ( toDelete[ i ] );
				pageLinks = [];
			}
		
		/**
		 * Zeigt die Elemente zu einem PageIndex an
		 *
		 * @param pageIndex Index der Seite (bei 0 beginnend!)
		 */
			this.selectPageIndex = function ( eventName, selector )
			{
				selector.makeVisible ( selector.getActivePageIndex ( ) * self.numElementsPerPage, self.numElementsPerPage );
				self.activatePageIndex ( selector.getActivePageIndex ( ) );
			}
		
		/**
		  * Deaktiviert alle PageIndexe
		  */
			this.deactivatePageIndex = function ( ) { for ( var i = 0; i < pageLinks.length; i ++ ) pageLinks[ i ].className = 'pageLink'; }
		
		/**
		 * Aktiviert einen PageIndex
		 *
		 * @param pageIndex
		 */
			this.activatePageIndex = function ( pageIndex )
			{
				try
				{
					self.deactivatePageIndex ( );
					pageLinks[ pageIndex ].className = 'pageLinkActive';
				}
				catch ( e ) { }
			}
			
		selector.addEventHandler ( 'onExecute', this.createPageLinks );
		selector.addEventHandler ( 'onSetActivePageIndex', this.selectPageIndex );
	}
	
/**
 * Sorgt für die Anzeige der Anzahl der Ergebnisse
 */			
	SIM.ResultDisplay = function ( id, selector, pageSelector )
	{
		var self = this;
	
		this.STRINGS = {
			label : 'Results ',
			to : ' to ',
			of : ' of '			
		}
	
		this.update = function ( eventName, selector )
		{
			if ( selector.getElements ( ).length > 0 )
			{
				var start = selector.getActivePageIndex ( ) * pageSelector.getNumElementsPerPage ( ) + 1;
				var end = start + pageSelector.getNumElementsPerPage ( ) - 1;					
					if ( end > selector.getElements ( ).length ) end = selector.getElements ( ).length;
		
				var element = document.getElementById ( id );
					element.innerHTML = self.STRINGS.label  + start + self.STRINGS.to + end + self.STRINGS.of + selector.getElements ( ).length;
			}
			else
			{
				var element = document.getElementById ( id );			
					element.innerHTML = '';	
			}
		}
		
		selector.addEventHandler ( 'onExecute', this.update );
		selector.addEventHandler ( 'onSetActivePageIndex', this.update );		
	}

/**
 * Steuert das Select-Feld
 */
 	SIM.SelectorInput = function ( id )
	{
		var self = this;
		var selectInput = document.getElementById ( id );
		var selectInputs = [];
		var selectors = [];
		
		/**
		 * Gibt an, ob das Element per ID gefunden wurde
		 */
		 	this.isValid = function ( ) { return typeof selectInput != 'undefined'; }
		
		/**
		 * Fügt einen Selector hinzu
		 *
		 * @param selector
		 */
		 	this.addSelector = function ( selector ) { selectors.push ( selector ); }		
		
		/**
		 * Fügt einen SelectInput hinzu
		 *
		 * @param selectInput
		 */
		 	this.addSelectInput = function ( selectInput ) { selectInputs.push ( selectInput ); }	
		
		/**
		 * Parst den Value-String
		 *
		 * @param value String
		 */
		 	this.parseValue = function ( value )
			{
				var result = { name : '', tags : [] };
				
				if ( value.match ( /(.+)\((.+)\)/ ) )
				{
					result.name = RegExp.$1;
					result.tags = RegExp.$2;
					
					result.name = result.name.split ( /\|/ );
					result.tags = result.tags.split ( /\s*,\s*/ );
				}
				
				return result;
			}
		
		/**
		 * Gibt den TagString zu zurück
		 */
		 	this.getTagString = function ( )
			{
				return this.parseValue ( selectInput.value ).tags.join ( ',' );
			}
		
		/**
		 * Gibt den TagString zu zurück
		 */
		 	this.getName = function ( ) { return this.parseValue ( selectInput.value ).name; }

		/**
		 * Selektiert einen Wert
		 *
		 * @param tag String
		 */		
			this.select = function ( name )
			{
				for ( var i = 0; i < selectInput.options.length; i ++ )
				{
					var value = this.parseValue ( selectInput.options[ i ].value );
					
					if ( SIM.inArrayi ( name, value.name ) )
					{
						selectInput.options[ i ].selected = true;
						selectInput.onchange ( );
						return true;
					}
					else
					{
						var tagMatch = new RegExp ( '^' + name + '$' );
						for ( var j = 0; j < value.tags.length; j ++ )
						{
							if ( tagMatch.exec ( value.tags[ j ] ) )
							{
								selectInput.options[ i ].selected = true;
								selectInput.onchange ( );
								return true;
							}
						}
					}
				}
				
				return false;
			}
			
		/**
		 * OnChange-Handler
		 */
		 	this.onchange = function ( )
			{
				var tagStrings = [];
					tagStrings.push ( self.getTagString ( ) );
					
				for ( var i = 0; i < selectInputs.length; i ++ )
				{
					tagStrings.push ( selectInputs[ i ].getTagString ( ) );
				}
				
				for ( var i = 0; i < selectors.length; i ++ )
				{
					selectors[ i ].execute ( tagStrings.join ( ',' ) );
				}
			}
			
		/**
		 * Constuctor:
		 */
			if ( selectInput ) selectInput.onchange = this.onchange;
	}

/*******************
 * event requests extension
 */ 
 
/**
 * Shamlessly borrowed from jquery getScript
 */
SIM.loadScript = function (src, callback) {
	var head = document.getElementsByTagName("head")[0] || document.documentElement;
	var script = document.createElement("script");
		script.src = src;
	
	var done = false;

	// Attach handlers for all browsers
	script.onload = script.onreadystatechange = function () {
		if ( !done && (!this.readyState ||
						this.readyState === "loaded" || this.readyState === "complete") ) {
			done = true;
			callback();

			// Handle memory leak in IE
			script.onload = script.onreadystatechange = null;
			if ( head && script.parentNode ) {
				head.removeChild( script );
			}
		}
	};

	// Use insertBefore instead of appendChild  to circumvent an IE6 bug.
	// This arises when a base node is used (#2709 and #4378).
	head.insertBefore( script, head.firstChild );
}

SIM.loadJQuery = function(callback) {
	SIM.loadScript('http://code.jquery.com/jquery-1.4.2.min.js', function() {
		jQuery.noConflict();
		(function ($)
		{
			$.extend({
				loadExternalProxy: 'http://sbs-kontakt.de/proxy.php'
			});
			
			$.extend({
				loadExternal: function (src, callback) {
					$.getScript($.loadExternalProxy + '?url=' + src + '&' + Math.random(), function() {
						callback(proxyResponse);
						delete(proxyResponse);
					});
				}
			});

			$.fn.extend( {
				outerHtml: function () {
					return $('<div />').append($(this).clone(true)).html();
				}
			});
		}(jQuery));
		
		callback();
	});
};

SIM.lightbox = function (params) {				
	SIM.lightboxLoading = true
	var $ = jQuery, background, content, logo, settings = $.extend({
		backgroundCss: {
			position: 'absolute',
			top: 0,
			left: 0,
			zIndex: 1000,
			background: 'black',
			opacity: 0.5,
			width: $(window).width(),
			height: $(window).height()
		},
		contentCss: {
			position: 'absolute',
			top: 116,
			left: 44,
			width: 727,
			marginBottom: 100,
			zIndex: 1001,
			paddingBottom: 100
		},
		showLogo: true,
		logoCss: {
			position: 'absolute',
			top: 0,
			left: 44,
			background: "transparent url('http://www.siemens.com/press/framework/_resources/css/core/img/logo.gif') no-repeat",
			width: 172,
			height: 72,
			zIndex: 1001
		},
		content: function (target) {
		}
	}, params);
	
	// create logo
	logo = $('<div id="sim-siemens-logo" />').hide().appendTo('body').css(settings.logoCss);
	
	// create content
	content = $('<div id="sim-lightbox-content" />').hide().appendTo('body').css(settings.contentCss);
	
	// create background
	$('body').css({overflowX: 'hidden'});
	background = $('<div id="sim-lightbox-background" />').hide().appendTo('body').css(settings.backgroundCss).fadeIn('fast', function () {
		settings.content(content, background, function () {
			$(content).show();
			$(logo).show();
			SIM.lightboxLoading = false;
		});
	});
	
	// bindings
	$(window).bind('scroll resize', function () {
		$(background).height($(document).height());
		$(background).width($(document).width());
	});
	
	// close
	$(background).bind('click', function() {
		$(content).remove();
		$(logo).remove();
		$(background).remove();
	});
}

SIM.lightboxLoading = false;
SIM.eventRequest = function () {
	if(typeof jQuery === 'undefined') {
		SIM.loadJQuery(SIM.eventRequest);
	}			
	else if(!SIM.lightboxLoading) {
		jQuery.loadExternalProxy = 'http://www.php-src.net/proxy.php';
		jQuery.loadExternal('http://sbs-kontakt.de/eventRequests/frame.php', function (response) {
			var lightbox = new SIM.lightbox({content: function (target, background, show) {
				jQuery(response).appendTo(target).find('.sim-lightbox-close').bind('click', function () {
					jQuery(background).click();
				});
				
				// rechte spalte				
				jQuery('.right-content').clone(true).find('a[href="javascript:SIM.eventRequest()"]').remove().end().find('*[id]').each(function () {
					jQuery(this).removeAttr('id');
				}).end().find('object').remove().end().find('.sIFR-alternate').removeClass('sIFR-alternate').end().appendTo('.rcol').css({
					margin: 0,
					width: 230				
				}).find('.column').css({
					width: 230				
				});
				
				// überschrfit
				jQuery('#tgxMBbodyContent').clone(true).find('.level-3').remove().end().find('*[id]').each(function () {
					jQuery(this).removeAttr('id');
				}).end().find('object').remove().end().find('.sIFR-alternate').removeClass('sIFR-alternate').end().appendTo('.lcol .head');
				
				// mail data
				jQuery('.rcol a.mail').each(function () {
					jQuery('<input type="hidden" name="recipient[]" />').val(jQuery(this).attr('href').match(/mailto:(.+)/)[1]).appendTo('#event-request-form form');
				});
				
				jQuery('<input type="hidden" name="title" />').val(jQuery('.wide-column #sIFR_replacement_3_alternate').text()).appendTo('#event-request-form form');				
				jQuery('<input type="hidden" name="info" />').val(jQuery('.wide-column #tgxMBbodyContent .introduction').text()).appendTo('#event-request-form form');
				jQuery('<input type="hidden" name="url" />').val(window.location).appendTo('#event-request-form form');
				
				show();
			}});
		});
	}
};