	

	function AjaxTransport()
	{
		this.getXMLHTTP = function( url, singleContainerId )
		{
			var xmlHttp = false;
			// Internet Explorer
			try
			{
				xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				try
				{
					xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e)
				{
					xmlHttp  = false;
				}
			}          
			// Mozilla, Opera und Safari
			if ( !xmlHttp && typeof XMLHttpRequest != 'undefined' )
			{
				xmlHttp = new XMLHttpRequest();
			}
			if ( xmlHttp )
			{
				xmlHttp.open( 'POST', url, true );
				xmlHttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded;charset=utf-8' );
				xmlHttp.onreadystatechange = function ()
				{
					if ( xmlHttp.readyState == 4 && xmlHttp.status == 200) //Complete
					{
						var body = document.getElementsByTagName( "body" )[0];
						var oldAjaxContainers = document.getElementsByTagName( "div" );
						var responseText = xmlHttp.responseText;										
						{
							var ajaxMethod = "ajaxRefreshAllContainers";
							var ajaxMethodPoint = responseText.indexOf( ajaxMethod );
							if( ajaxMethodPoint != -1 )
							{
								//reload full page
								var ajaxMethodParamStart = responseText.indexOf( "{", ajaxMethodPoint );
								var ajaxMethodParamEnd = responseText.indexOf( "}", ajaxMethodPoint );
								responseText = responseText.substring( 0, ajaxMethodPoint ) + 
									responseText.substring( ajaxMethodParamEnd + 1, responseText.length );
								singleContainerId = null;								
							}
						}
						
						var responseXML = document.createElement( "div" );
						responseXML.innerHTML = responseText;
						//alert( xmlHttp.getAllResponseHeaders() );
						//alert( responseText );

						var isAnyNewCorrespondingContainerFound = false;
						var newAjaxContainers = responseXML.getElementsByTagName( "div" );
						
						/* Check for Browser used by User because of problems in Opera
						 * Opera is cycling the following for-loop two times
						 * First loop cycle is ok.
						 * In the second cycle the newContainer contains no elements, therefore
						 * the page elements are deleted during swapping new -> old.
						 * 
						 */
						var isOpera = navigator.appName.toLowerCase() == "opera";
						var isGecko = navigator.userAgent.toLowerCase().indexOf("gecko") != -1;
						
						var appName = navigator.appName.toLowerCase();
						
						for( var index in oldAjaxContainers )
						{	
							var oldContainer = oldAjaxContainers[index];
							if( oldContainer
									&& ( ( oldContainer.className != null
											&& oldContainer.className.toLowerCase().indexOf( "ajaxcontainer" ) != -1 )
										|| ( oldContainer.id != null
													&& oldContainer.id.toLowerCase().indexOf( "ajaxcontainer" ) != -1 )
										)
									&& ( singleContainerId == null 
											|| oldContainer.id == singleContainerId 
											|| oldContainer.id == (singleContainerId + "_tlc") )	//Top level elements hotfix										
								)
							{		
								
								for( var index2 in newAjaxContainers )
								{
									var newContainer = newAjaxContainers[index2];
									if( newContainer != null
											&& ( oldContainer.id == newContainer.id 
													|| oldContainer.id == (newContainer.id + "_tlc") ) //Top level elements hotfix
										)
									{
										isAnyNewCorrespondingContainerFound = true;
										
										//evaluate server callbacks
										var newContainerText = newContainer.innerHTML;
										{
											var ajaxMethod = "ajaxForceFullReload";
											var ajaxMethodPoint = newContainerText.indexOf( ajaxMethod );
											if( ajaxMethodPoint != -1 )
											{
												//reload full page
												var ajaxMethodParamStart = newContainerText.indexOf( "{", ajaxMethodPoint );
												var ajaxMethodParamEnd = newContainerText.indexOf( "}", ajaxMethodPoint );
												var url = newContainerText.substring( ajaxMethodParamStart + 1, ajaxMethodParamEnd )
												//alert( "reload: " + url );
												window.location.href = url; 
												return;
											}
										}										
										{
											var ajaxMethod = "ajaxHideContainer";
											var ajaxMethodPoint = newContainerText.indexOf( ajaxMethod );
											if( ajaxMethodPoint != -1 )
											{
												//reload full page
												var ajaxMethodParamStart = newContainerText.indexOf( "{", ajaxMethodPoint );
												var ajaxMethodParamEnd = newContainerText.indexOf( "}", ajaxMethodPoint );
												var newHTML = 
													newContainerText.substring( 0, ajaxMethodPoint ) + 
													newContainerText.substring( ajaxMethodParamEnd + 1, newContainerText.length );
												
												newContainer.innerHTML = newHTML;
												oldContainer.style.display = "none";
											}
										}										
										{
											var ajaxMethod = "ajaxJavascript";
											var ajaxMethodPoint = newContainerText.indexOf( ajaxMethod );
											while ( ajaxMethodPoint != -1 )
											{
																						
												//reload full page
												var ajaxMethodParamStart = newContainerText.indexOf( "{", ajaxMethodPoint );
												var ajaxMethodParamEnd = newContainerText.indexOf( "}", ajaxMethodPoint );
												var param = newContainerText.substring( ajaxMethodParamStart + 1, ajaxMethodParamEnd )
										
												var newHTML = 
													newContainerText.substring( 0, ajaxMethodPoint ) + 
													newContainerText.substring( ajaxMethodParamEnd + 1, newContainerText.length );
												
												newContainer.innerHTML = newHTML;
												window.setTimeout( param, 10 );
												
												ajaxMethodPoint = newContainerText.indexOf( ajaxMethod, ajaxMethodPoint + 1 );
											}
										}
									
										//exchange containers
										//alert(navigator.appName.toLowerCase() + " " + navigator.userAgent.toLowerCase());
										
										//The "null" checks fail in Firefox, therefore using a browser check
										if (
											isGecko
											|| !isOpera 
											|| (newContainer != null && newContainer.children != null && newContainer.children.length > 0)
										) {
											_ajaxUpdateContent( oldContainer, newContainer );
										}
									}
								}
							}
						}
						
						//useless ajax response (different page?) -> sync lost, reload page
						if( !isAnyNewCorrespondingContainerFound )
						{
//							alert( "Lost ajax synchronisation, webpage will be refreshed!" );
//							window.location.reload( true );
							
							//reload complete body content from response text 
							var lowerResponseText = responseText.toLowerCase();
							var bodyIndex = lowerResponseText.indexOf( "<body" );
							var bodyContentStartIndex = responseText.indexOf( ">", bodyIndex ) + 1;
							var bodyCloseIndex = lowerResponseText.indexOf( "</body", bodyContentStartIndex );						
							var responseBodyText = responseText.substring( bodyContentStartIndex, bodyCloseIndex );
							body.innerHTML = responseBodyText;
						}
						
						//setting default cursor						
						body.style.cursor = "default";						
					}
				};
				
				//setting wait cursor (clock)
				var body = document.getElementsByTagName( "body" )[0];
				if( body != null )
				{
					body.style.cursor = "wait";
				}
				return xmlHttp;
			}
			else
			{
				alert("Your browser does not support XmlHttpRequest. Please use either Firefox 1.5, Internet Explorer 6.0, or Opera 9.0 or better.");
				return null;
			}
		}
		
		this.send = function( postURL, postValue, singleContainerId )
		{
			//postURL = "http://localhost:9001/manuell.htm";// + postURL;
			//alert(postURL);
			//alert( "submit: " + postURL + " ? " + postValue + " ? " + singleContainerId);
			var xmlHTTP = this.getXMLHTTP( postURL, singleContainerId );
			//alert(xmlHTTP);
			xmlHTTP.send( postValue );
			//alert(xmlHTTP.responseText);
		}

	}
	
	function _ajaxUpdateContent( oldContainer, newContainer )
	{
			//exchange containers
			var firstChild;
			//clear old container
			while( (firstChild = oldContainer.firstChild ) != null )
			{
				oldContainer.removeChild( firstChild );
			}										
			//add new children to old container 
			while( (firstChild = newContainer.firstChild ) != null )
			{
				//alert(firstChild);
				newContainer.removeChild( firstChild );
				oldContainer.appendChild( firstChild );
			}
	}
	
	/**
	 * submit a form with ajax
	 * @form id of the form to submit
	 * @singleContainerId may be null or not provided at all, if provided, only the specified AjaxContainer will be exchanged
	 */
	function ajaxSubmit( formId, singleContainerId  )
	{
		var form = document.getElementById( formId );
		if( form == null
				|| form.id != formId ) //ie hack
		{
			var forms = document.getElementsByTagName( "form" );
			
			for( var index in forms )
			{	
				if( forms[ index ].id == formId )
				{					
					form = forms[ index ];
				}
			}
		}
		if( form != null )
		{
			ajaxSubmitForm( form, singleContainerId );
		}
		else
		{
			alert( "form does not exist: " + formId );
		}
	}
	
	/**
	 * submit a form with ajax
	 * @form form object
	 * @singleContainerId may be null or not provided at all, if provided, only the specified AjaxContainer will be exchanged
	 */
	function ajaxSubmitForm( form, singleContainerId  )
	{
		if( form != null )
		{
			if ( typeof encodeURIComponent == "function" )
			{
				var postURL = form.action;
				var postValue = "isAjaxCall=1";
				for ( var i = 0; i < form.elements.length; i++ )
				{
					if ( form.elements[i].type == 'checkbox' )
					{
						if ( form.elements[i].checked )
						{
							if( postValue != "" ) postValue += '&';
							postValue += encodeURIComponent( form.elements[i].name );
							postValue += '=';
							postValue += encodeURIComponent( form.elements[i].value );
						}
					}
					else if ( form.elements[i].type == 'radio' )
					{
						if ( form.elements[i].checked )
						{
							if( postValue != "" ) postValue += '&';
							postValue += encodeURIComponent( form.elements[i].name );
							postValue += '=';
							postValue += encodeURIComponent( form.elements[i].value );
						}
					}
					else if ( form.elements[i].type != 'submit'
								|| form.elements[i].type != 'text' )
					{
						if( postValue != "" ) postValue += '&';
						postValue += encodeURIComponent( form.elements[i].name );
						postValue += '=';
						postValue += encodeURIComponent( form.elements[i].value );
					}
				}
				if ( new AjaxTransport().send( postURL, postValue, singleContainerId  ) == false )
				{	
					form.submit();
				}
			}
			else
			{
				form.submit();
			}
		}
		else
		{
			alert( "form is null!" );
		}
	}

	/** 
	 * extension of ajaxSubmit() with additional form fields
	 * TODO: maybe, to realize all the calls via this code being more flexible
	*/
	function ajaxSubmitPlus( param ) // params: formId, singleContainerId {, fieldname, fieldValue }0..n
	{
		var args = ajaxSubmitPlus.arguments;
		var form = document.getElementById(args[0]);
		var singleContainerId = args[1];
		if(form != null)
		{
			for ( var i = 0; i < (args.length-2)/2; i++ )
			{
//				var input = getField(form, args[i*2+2]);
//				if (input == null)
//				{
					input = document.createElement("input");
					input.name = args[i*2+2];
//				}
				input.value = args[i*2+3];
				input.type = "hidden";
				form.appendChild(input);
			}
			ajaxSubmitForm(form, singleContainerId);
		}
		else
		{
			alert( "form does not exist: " + formId );
		}
	}
	
//	function getField(form, fieldName)
//	{
//		var elements = form.elements;
//		for (i = 0; i < elements.length; i++)
//		{
//			if (elements[i].name == fieldName) 
//			{
//				return elements[i];
//			}
//		}
//		return null;
//	}
	
	/**
	 * to call from an anchor / link
	 * @url request url
	 * @singleContainerId may be null or not provided at all, if provided, only the specified AjaxContainer will be exchanged
	 * 
	 */
	function ajaxCall( url, singleContainerId )
	{	
		if ( typeof encodeURIComponent == "function" )
		{	 
			var postValue = "";
			if ( new AjaxTransport().send( url, postValue, singleContainerId  ) == false)
			{
				document.location.href = url;
			}
		}
		else
		{
			document.location.href = url;
		}
	}

