var sPreloadingArea = 'v3_sub';lazyModules['cForm'].loaded = true;lazyModules['cTemplate'].loaded = true;

/* ---------- /var/www/africanworld.de/htdocs/totoya/cache/core/clib/lib/jquery/jquery.cform.js ---------- */

/**
  * Easy to use ajax forms
 * @author haustein
 * @package core
 * @subpackage ajax
 */


(function( $ ) {
	/**
	 * Creates a cform form and handles the events
	 * based upon jquery
	 *
	 * @param string sAction
	 * @param object oParam
	 * @param function fCallback
	 */
	var oSelectedInput;
	$.fn.cForm = function(sAction, oParam, fCallback) {
		// store local context
		var oSelf 			= this;
		// some basic checks

		if(sAction != "init" &&  sAction != "setup" ) {
			if(!$(oSelf).data(	'sFormName')) {
				log("ERROR: form loading has not started yet.");
				return oSelf;
			}
			if(!$(oSelf).data(	'bDataLoaded')) {
				log("ERROR: form loading has not finished yet.");
				return oSelf;
			}
			var oFuncParam = oParam;
			oParam = {};
		}

		// declare things local and load from data store
		oParam				= $.extend($(oSelf).data('oParam'), oParam);
		var iDatasetId		= $(oSelf).data('iDatasetId');
		var sLanguage		= $(oSelf).data('sLanguage');
		var sFormName		= $(oSelf).data('sFormName');
		var sFormId			= $(oSelf).data('sFormId');
		var oFields			= $(oSelf).data('oFields');
		var oFieldsSorted	= $(oSelf).data('oFieldsSorted');
		var oOptions		= $(oSelf).data('oOptions');
		var oDatasetIds		= $(oSelf).data('oDatasetIds');
		var oTemplates		= $(oSelf).data('oTemplates');
		var oMessages		= $(oSelf).data('oMessages');
		var oServerSiteClass= $(oSelf).data('oServerSiteClass');
		// internal functions


		// setup form
		function initForm(oParam) {
			// use different serverside class if set
			var sClass = (
					typeof oParam.oServerSiteClass == 'string'
						&& oParam.oServerSiteClass != null
						&& oParam.oServerSiteClass.length > 0 ?
					oParam.oServerSiteClass :'cForm'
				);
			var sUrl = '';
			
			switch(oSystem.sName) {
				case 'typo3':
					sUrl = '/?eID=json&action=totoyaRequest&sClass=' + sClass + '&sFunction=ajaxGetForm'
				break;
				case 'wordpress':
					sUrl = '/wp-content/plugins/chio-newsletter/totoya/totoya-ajax.php?action=totoyaRequest&sClass=' + sClass + '&sFunction=ajaxGetForm';
				break;
				case 'totoya':
				default:
					sUrl = '/ajax/'+sClass+'/ajaxGetForm'
				break;
			}
			$.post(sUrl, {"sName": sFormName,"iDatasetId":iDatasetId,"sLanguage":(typeof sLanguage == 'undefined' ? '' : sLanguage)}, function(oData){
				var oFormDefinition	= oData.mData;
				// initialize the "global" parameters
				sFormId				= 'form_' + $.getUniqueDomId(oSelf);
				oFields				= {};
				oFieldsSorted		= [];
				if(oFormDefinition.aOptions) {
					oOptions			= oFormDefinition.aOptions.options;
				}
				oDatasetIds			= {};
				oTemplates			= oParam.oTemplates;
				oMessages			= oFormDefinition.oMessages;
				// do some corrections
				if(typeof oOptions != 'object' || oOptions == null) {
					oOptions = {};
				}

				// my container has to have an id for easy selection
				if($(oSelf).attr('id')=='') {
					$(oSelf).attr('id', 'form_container_'+$.getUniqueDomId(oSelf));
				}

				// QUICK AND DIRTY:
				oMessages = {
					"E_REQUIRED":	"Dies ist ein Pflichtfeld. Bitte füllen Sie es aus!"
					,"E_EMAIL":		"Bitte geben Sie hier eine E-Mail-Adresse ein!"
					,"E_ZIP":		"Dies ist keine gültige Postleitzahl!"
					,"E_PASSWORD":	"Die eingegebenen Passwörter sind nicht identisch!"
				};
				// END QUICK AND DIRTY
				// store these in an accessible context
				$(oSelf).data(		'iDatasetId',		iDatasetId);
				$(oSelf).data(		'onBeforeSubmit',	oParam.onBeforeSubmit);
				$(oSelf).data(		'onAfterSubmit',	oParam.onAfterSubmit);
				$(oSelf).data(		'bNoSubmitField',	oParam.bNoSubmitField);
				$(oSelf).data(		'sFormName',		sFormName);
				$(oSelf).data(		'sFormId',			sFormId);
				//$(oSelf).data(		'oFormManager',	oFormManager);
				$(oSelf).data(		'oFields',			oFields);
				$(oSelf).data(		'oFieldsSorted',	oFieldsSorted);
				$(oSelf).data(		'oMessages',		oMessages);
				$(oSelf).data(		'oOptions',			oOptions);
				$(oSelf).data(		'oDatasetIds',		oDatasetIds);
				$(oSelf).data(		'oTemplates',		oTemplates);
				$(oSelf).data(		'oServerSiteClass', oParam.oServerSiteClass);
				$(oSelf).data(		'bIsSubform', 		oParam.bIsSubform);
				$(oSelf).data(		'sLanguage', 		oParam.sLanguage);
				if(!oParam.bIsSubform) {
					// initialize dom:
					$(oSelf).html('<form method="POST" action="" id="'+sFormId+'" enctype="multipart/form-data" autocomplete="off"></form>');
					// catch submit-request
					$('#'+sFormId).bind("submit", saveData);
				}
				else {
					$(oSelf).html('<div id="'+sFormId+'"></div>');
				}
				// populate form by calling each field-handler
				// step through every row (dataset may have more than one!)
				var sFormHTML = '';
				for(var iRow in oFormDefinition.aRows) {
					oDatasetIds[iRow] = oFormDefinition.aRows[iRow].iDatasetId;
					for(var i in oFormDefinition.aRows[iRow].aFields) {
						var oField = 			oFormDefinition.aRows[iRow].aFields[i];
						var iId = 				iRow*10000+parseInt(oField.iId);
						oFieldsSorted.push(iId);
						var iInternalId =		oField.iId;
						var sName =				'field_'+$.getUniqueDomId(oSelf)+'_'+iRow+'_'+iId;
						var sType =				oField.sType;
						var sHandler =			'totoyaFormField'+sType;
						if(oField.sJsHandlerName) {
							sHandler =			oField.sJsHandlerName;
						}
						if (typeof oField.oClientParameter != 'undefined' && $.trim(oField.oClientParameter).length > 0) {
							var sFirstLetter = $.trim(oField.oClientParameter).substr(0, 1);
							if (sFirstLetter == '{' || sFirstLetter == '[') {
								eval('var oClientParameter = '+	oField.oClientParameter);
							} else {
								var oClientParameter = oField.oClientParameter;
							}
						} else {
							var oClientParameter = null;
						}
						// change - to _
						sHandler = sHandler.replace("-", "_");
						sType = sType.replace("-", "_");

						var aDependencies = 	oField.aDependencies;
						var sTargetDomId =		oField.sTargetDomId;
						var aShowConditional =	oField.aShowConditional;
						var sLabel = 			oField.sLabel;
						var sHelp = 			oField.sHelp;
						var sTemplate =			oField.sTemplate;
						if(!sTemplate && typeof oTemplates == "object") {
							sTemplate =			oTemplates[sType.toLowerCase()];
						}
						var sData = 			oField.sData;
						var mParam =			oField.mParam;
						var aSort =				oField.aSort;
						var bRequired =			oField.bRequired;
						var sErrorMessage = 	oField.sErrorMessage;
						// store things in internal structure
						oFields[iId] = {
							sName: 				sName
							,iId: 				iInternalId
							,iRow:				iRow
							,sType:				sType
							,sHandler: 			sHandler
							,oClientParameter:	oClientParameter
							,aDependencies: 	aDependencies
							,sTargetDomId:		sTargetDomId
							,aShowConditional:	aShowConditional
							,sLabel:			sLabel
							,sHelp:				sHelp
							,sTemplate:			sTemplate
							,sData:	 			sData
							,mParam:			mParam
							,aSort:				aSort
							,bDirty:			false
							,bRequired:			bRequired
							,sErrorMessage:		sErrorMessage
							,fValidator:		null
							,sSelfId:			$(oSelf).attr('id')
						};
						
						// create field handler
						if(typeof window[sHandler] != 'function') {
							alert('unsupported field type' + sHandler);
							//do this when ync-loding is supported by lazyLoad:
							//$.lazyLoad([sHandler], function() {
							//	oFields[iId].fHandler = eval("new "+sHandler+"(oFields[iId])");
							//});
						}
						else {
							oFields[iId].fHandler = eval("new "+sHandler+"(oFields[iId])");
						}
					}
				}

				// append submit field
				if($(oSelf).data('bNoSubmitField') != true && !oParam.bIsSubform) {
					var iId = 9996999;
					var sTemplate =			'';
					if(typeof oTemplates == "object") {
						sTemplate =			oTemplates['submit'];
					}
					oFieldsSorted.push(iId);
					oFields[iId] = {
							sName: 			'field_'+$.getUniqueDomId(oSelf)+'_'+iRow+'_'+iId
							,iId: 			iId
							,aDependencies:	[]
							,iRow:			iRow
							,sType:			'submit'
							,sHandler: 		'totoyaFormFieldSubmit'
							,aDependencies: []
							,sLabel:		'Absenden'
							,sHelp:			''
							,sTemplate:		sTemplate
							,sData:	 		null
							,mParam:		null
							,aSort:			null
							,bDirty:		false
							,bRequired:		false
							,fValidator:	null
							,sSelfId:		$(oSelf).attr('id')
					};

					// create field handler
					if(typeof window['totoyaFormFieldSubmit'] != 'function') {
						alert('totoyaFormFieldSubmit'); // 
						$.lazyLoad(['totoyaFormFieldSubmit'], function() {
							oFields[iId].fHandler = eval("new "+'totoyaFormFieldSubmit'+"(oFields[iId])");
						});
					}
					else {
						oFields[iId].fHandler = eval("new "+'totoyaFormFieldSubmit'+"(oFields[iId])");
					}
				}
				// send "init"-request to field handlers
				if($(oSelf).data(	'bAutorender') == true) {
					renderForm(oParam);
				}
				// set data loaded flag
				$(oSelf).data(	'bDataLoaded', true);

				// execute callback
				var tmpCallBack;
				tmpCallBack = {
					callback: fCallback
				};
				fCallback = null;
				executeCallback(tmpCallBack.callback);
				// end of init load request
			}, "json");
		}




		/**
		 * renders the form HTML into the DOM
		 *
		 * @param object oParam		unused!
		 */

		function renderForm(oParam) {
			var aFormHTML		= {};
			var oFields			= $(oSelf).data('oFields');
			var oFieldsSorted	= $(oSelf).data('oFieldsSorted');
			var oOptions		= $(oSelf).data('oOptions');
			var sTargetId		= "";
			for(var i in oFieldsSorted) {
				sTargetId					= oFields[oFieldsSorted[i]]['sTargetDomId'];
				if(!sTargetId || sTargetId == '' || sTargetId == undefined || sTargetId == null) {
					sTargetId = '_default';
				}
				if(typeof aFormHTML[sTargetId] != 'string') {
					aFormHTML[sTargetId]	= '';
				}

				if(oParam.bRenderReadonly && typeof oFields[oFieldsSorted[i]].fHandler.createReadonly == "function") {
					var sFieldHtml			= oFields[oFieldsSorted[i]].fHandler.createReadonly();
				}
				else {
					var sFieldHtml			= oFields[oFieldsSorted[i]].fHandler.create();
				}
				
				if(-1 == sFieldHtml.indexOf(oFields[oFieldsSorted[i]].sName + '_container')) {
					sFieldHtml = '<div id="' + oFields[oFieldsSorted[i]].sName + '_container">' + sFieldHtml + '</div>';
				}
				
				aFormHTML[sTargetId]		+= sFieldHtml;
				if(oOptions && oOptions.sepperator == 'on') {
					// insert element sepperator
					aFormHTML[sTargetId]	+= '<div class="formFieldSepperator"></div>';
				}
			}


			// put html-code into targets
			// empty target
			$('#'+$(oSelf).data('sFormId')).html('');
			// add missing target divs and fill "foreign" targets
			for(sTargetId in aFormHTML) {
				// skip target "default"
				if(sTargetId == '_default') {
					continue;
				}
				// add div, if target div id does not exists (what should be the default to render the div into the form-tag!)
				if($('#'+sTargetId).length == 0) {
					$('#'+$(oSelf).data('sFormId')).append('<div id="' + sTargetId + '"></div>');
				}
				// add the html-code
				$('#'+sTargetId).html(aFormHTML[sTargetId]);
			}
			// append "default"-target
			$('#'+$(oSelf).data('sFormId')).append(aFormHTML['_default']);


			// init fields
			if(!oParam.bRenderReadonly) {
				for(var i in oFields) {
					if(typeof oFields[i].fHandler.init == 'function') {
						oFields[i].fHandler.init();
					}
				}
			}
			
			// check Conditional fields
			checkConditionalFields(true);
			
			// remember the focus for the conditional checking
			$('input, textarea, select, button')
				.focus(function() {
					oSelectedInput = this;
				})
				.blur(function(){
					if(oSelectedInput == this) {
						oSelectedInput = null;
					}
				});
			
			// make control+s save the form:
			function saveOnControlS(event) {
			    if (!(event.which == 115 && event.ctrlKey)) return true;
			    saveData();
			    event.preventDefault();
			    return false;
			};
			$(oSelf).keypress(saveOnControlS);
			// find "iframes" which are part of complex editors
			window.setTimeout(
				function(){
					$(oSelf).find('iframe').each(
						function() {
							if (this.contentWindow.addEventListener) {
								this.contentWindow.addEventListener('keypress', saveOnControlS, true);
							} else if (this.contentWindow.attachEvent) {
								this.contentWindow.attachEvent('onkeypress', saveOnControlS);
							}

							// find frame-in-frame at fck-editor
							var oEditFrame = (
								this.contentDocument
								? this.contentDocument
								: this.contentWindow.document
							).getElementById('xEditingArea');
							if (oEditFrame) {
								if (oEditFrame.firstChild.contentWindow.addEventListener) {
									oEditFrame.firstChild.contentWindow.addEventListener('keypress', saveOnControlS, true);
								} else if (oEditFrame.firstChild.contentWindow.attachEvent) {
									oEditFrame.firstChild.contentWindow.attachEvent('onkeypress', saveOnControlS);
								}
							}
						}
					);
				}
				,2000
			);

		}





		/**
		 * checks wether the fields are to be displayed in case of conditions
		 * 
		 * @param bool bSkipAnimations	if true, the default animations will be skipped
		 */
		function checkConditionalFields(bSkipAnimations) {
			var oFields			= $(oSelf).data('oFields');
			var oFieldsSorted	= $(oSelf).data('oFieldsSorted');
			var bChanged		= false;

			// walk throug the fields
			for(var i in oFieldsSorted) {
				var oField		= oFields[oFieldsSorted[i]];
				var bResult		= null;
				if(typeof oField.aShowConditional == 'object' && oField.aShowConditional != null) {
					// walk through the conditions of the field
					for(var i in oField.aShowConditional) {
						/* structure is:
						  {
							sMode:		'AND'
							,iFieldId:	123
							,aValues:	[10,20,30]
							,bIsSet:	true/false/null
						} */
						// summorize data
						var sMode			= oField.aShowConditional[i].sMode;
 						var sForeignValue	= oFields[oField.aShowConditional[i].iFieldId].sData;
						var bIsSet			= oField.aShowConditional[i].bIsSet;
						var aPossibleValues	= oField.aShowConditional[i].aValues;

						// handle AND/OR concatenations of conditions
						if(sMode == 'AND' && bResult === false) {
							// false AND anything will be false, so we set false and continue with next condition (maybe OR-concatenated)
							continue;
						}
						if(sMode == 'OR' && bResult === true) {
							// true OR anything will allways stay true, furthermore AND has more priority than or,
							// so any part, that is true on one side of an or statement will return true in result
							break;
						}
						// Any other case will change the result to the result of the next condition
						// so we are going to check our new condition:

						// check the bIsSet condition
						if(bIsSet === true || bIsSet === false) {
							if(sForeignValue) {
								bResult = bIsSet;
							}
							else {
								bResult = !bIsSet;
							}
							// if isSet condition is used, any other condition will be skipped
							continue;
						}
						
						// check the value-matching-condition
						if($.inArray(sForeignValue, aPossibleValues) !== -1) {
							bResult = true;
						}
						else {
							bResult = false;
						}
					} // end of condition-checking
					// execute condition result
					if(bResult == false) {
						if($('#'+oField.sName + '_container').css('display') != 'none') {
							bChanged = true;
							if(bSkipAnimations) {
								$('#'+oField.sName + '_container').hide();
							}
							else {
								$('#'+oField.sName + '_container').slideUp(300);
							}
						}
						oField.sData = '';
					}
					else{
						if($('#'+oField.sName + '_container').css('display') == 'none') {
							bChanged = true;
							if(bSkipAnimations) {
								$('#'+oField.sName + '_container').show();
							}
							else {
								$('#'+oField.sName + '_container').slideDown(300, function(){
									$(this).slideDown(100,function(){
										$(this).hide().show();
									});
								});
							}
						}
					}
					// tell field handler to init changed field data
					if(typeof oField.fHandler.init == 'function') {
						oField.fHandler.init();
					}
				}
			}
			if(bChanged) {
				var oFocus = oSelectedInput;
				window.setTimeout(function() {
						// 1) tab pressed AND
						// 2) focus on null OR focus on field _1 step below_ a "new" field
						// OR
						// 1) shift+tab pressed AND
						// 2) focus null OR focus _1 step above_ a "new" field
						
						var bFound = false;
						$("input, textarea, select, button").each(function(){
							if(bFound) {
								bFound=false;
								$(this).focus();
								return false;
							}
							if($(this).attr('id') == $(oFocus).attr('id')) {
								bFound = true;
								
							}
							return true;
						});

						//$(oFocus).trigger({ type : 'keypress', which : 9 });
					} ,50);
			}
		}
		



		/**
		 * validates one field
		 * 
		 * @param object oField		field to change
		 * @param string sNewValue	new Value to put into field
		 */

		function validateData(oField, sNewValue) {
			var oResult = {
					bError: 	false
					,aMessages:	[]
			};
			// check mandatory
			if(oField.bRequired && (sNewValue == '' || sNewValue == null)) {
				oResult.bError = true;
				oResult.aMessages.push("E_REQUIRED");
			}
			// call validator of the field
			if(typeof oField.fHandler.validate == "function") {
				oField.fHandler.validate(sNewValue, oResult);
			}
			// render messages for display:
			var aMessages = [];
			if(typeof oField.fHandler.renderMessages == "function") {
				if(typeof oField.fHandler.sErrorMessage == "string" && oResult.bError){
					aMessages.push(oField.fHandler.sErrorMessage);
				}
				else {
					// get messages from global array
					for(i in oResult.aMessages) {
						if(oMessages[oResult.aMessages[i]] != null) {
							aMessages.push(oMessages[oResult.aMessages[i]]);
						}
						else {
							aMessages.push(oResult.aMessages[i]);	
						}
					}
				}
				oField.fHandler.renderMessages(aMessages);
			}
			// return false if an error accured
			if(oResult.bError == true) {
				return false;
			}
			// TODO: system validator je nach Konfiguration in der XML
			return true;
		}

		// on change of all fields
		function changeData(oParam) {
			validateData(oParam.element, oParam.value);
			
			// store data in internal array
			var oFields = $(oSelf).data('oFields');
			oFields[oParam.element.iId].sData = oParam.value;
			oFields[oParam.element.iId].bDirty = true;
			$(oSelf).data('oFields', oFields);
			
			// search for dependencies
			for(i in oFields) {
				if(typeof oFields[i].aDependencies == "object") {
					if(-1 != $.inArray(oParam.element.iId, oFields[i].aDependencies)) {
						if(typeof oFields[i].fHandler.update == "function") {
							log('update caused by dependenciy: ' + oFields[i].sLabel + ':' + oFields[i].iId);
							oFields[i].fHandler.update();
						}
						else if(typeof oFields[i].fHandler.init == "function") {
							log('UPDATE FAILED USING INIT-FUNCTION-CALL caused by dependenciy: ' + oFields[i].sLabel + ':' + oFields[i].iId);
							oFields[i].fHandler.init();
						}
						else alert('Dependencie cannot be resolved!');
					}
				}
				
				// check if conditions of fields enable to display them:
				checkConditionalFields(false);
			}
			return false;
		}

		function validateAllFields() {
			var oFields = $(oSelf).data('oFields');
			var bFieldsOk = true;
			var iFirstErrorField = null;
			for(var i in oFields) {
				var bOldValue = bFieldsOk;
				bFieldsOk &= validateData(oFields[i], oFields[i].sData);
				if(bFieldsOk == false && bOldValue == true) {
					iFirstErrorField=i;
				}
			}
			return {
				"iFirstErrorField"	: iFirstErrorField
				,"bFieldsOk"		: bFieldsOk
			};
		}




		/**
		 * sends the changed form fields to server via ajax
		 *
		 * - first executes validation
		 * - does not send if validation fails
		 * - does execute the "onBeforeSubmit" before submit and interrupts if it returns false
		 *
		 * @param object oParam		usually the event object, in case of custom calls an object with optional configuration data
		 */

		function saveData(oFuncParam) {
			if(typeof oFuncParam == 'object' && oFuncParam != null && typeof oFuncParam.preventDefault == 'function') {
				oFuncParam.preventDefault();
			}
			var oFields = $(oSelf).data('oFields');
			var bFieldsOk = true;
			if(typeof oFuncParam == 'object' && !oFuncParam.dontValidate) {
				oValidateResult = validateAllFields();
				var bFieldsOk			= oValidateResult.bFieldsOk;
				var iFirstErrorField	= oValidateResult.iFirstErrorField;
				if(!bFieldsOk) {
					log("error in fields, dont save");
					//alert("Bitte füllen Sie alle Pflichtfelder aus, bevor Sie erneut speichern.");
					var oOffset = $('#message_'+oFields[iFirstErrorField].sName).offset();
					oOffset = (oOffset == null ? $(oFields[iFirstErrorField].sName).offset() : oOffset);
					if (oOffset != null) {
						iTop = $('#message_'+oFields[iFirstErrorField].sName).offset()['top'];
						$('#'+oFields[iFirstErrorField].sSelfId).scrollTop(
							($('#'+oFields[iFirstErrorField].sSelfId).scrollTop()) + iTop - ($('#'+oFields[iFirstErrorField].sSelfId).offset()['top'])
						);
					}
					$('#'+oFields[iFirstErrorField].sName).focus();
					return false;
				}
			}
			log('save');
//--
			// copy dirty fields to seperate object structure
			var oSend = {
				sLanguage:	$(oSelf).data('sLanguage'),
				sName: 		$(oSelf).data('sFormName'),
				aRows:		{}
			};
			// call update function on all fieldHandlers which need that like RTE-fields
			for(var i in oFields){
				if(oFields[i].fHandler.update && typeof(oFields[i].fHandler.update) == "function"){
					oFields[i].fHandler.update(oFields[i].fHandler);
				}
			}
			var bFormDirty = false;
			if($(oSelf).data('iDatasetId') == -1) {
				// new forms are allways "dirty"
				bFormDirty = true;
			}
			var oDatasetIds = $(oSelf).data('oDatasetIds');
			for(var i in oFields) {
				var iDatasetId = parseInt(oDatasetIds[oFields[i].iRow]);
				if(iDatasetId < 1 || isNaN(iDatasetId) ) {
					iDatasetId = -1;
					oDatasetIds[oFields[i].iRow] = -1;
				}
				if(oFields[i].bDirty) {
					if(typeof oSend.aRows[iDatasetId] != 'object') {
						oSend.aRows[iDatasetId] = {
							iDatasetId: iDatasetId,
							aFields: {}
						};
					}
					oSend.aRows[iDatasetId].aFields[oFields[i].iId] = oFields[i].sData;
					bFormDirty = true;
				}
			}
			var onBeforeSubmit = $(oSelf).data('onBeforeSubmit');

			// convert onBeforeSubmit to an totoya-callback object
			if(typeof onBeforeSubmit == "function") {
				onBeforeSubmit = { fFunction: onBeforeSubmit };
			}
			if (typeof onBeforeSubmit == "object" && onBeforeSubmit != null) {
				onBeforeSubmit.oScope = oSelf;
				onBeforeSubmit.mParam = oSend;
			}
			// just fires if realy data will be submitted
			if(
				(typeof onBeforeSubmit == "object" && typeof onBeforeSubmit.fFunction == "function" && onBeforeSubmit != null)
			) {
				var beforeSubmitResult = executeCallback(onBeforeSubmit);
				if (typeof beforeSubmitResult == 'boolean' && !beforeSubmitResult) {
					return false;
				}
			}

			if(!bFormDirty) {
				sendSuccess(false);
				return false;
			}

			var sClass = (
				typeof $(oSelf).data('oServerSiteClass') == 'string'
					&& $(oSelf).data('oServerSiteClass') != null
					&& $(oSelf).data('oServerSiteClass').length > 0 ?
				$(oSelf).data('oServerSiteClass') :
				'cForm'
			);
			// do not save subforms async:
			if(typeof oFuncParam == 'object' && oFuncParam != null && oFuncParam.bSubformSave) {
				var sUrl = ''
				switch(oSystem.sName) {
					case 'typo3':
						sUrl = '/?eID=json&action=totoyaRequest&sClass=' + sClass + '&sFunction=ajaxSaveForm'
					break;
					case 'wordpress':
						sUrl = '/wp-content/plugins/chio-newsletter/totoya/totoya-ajax.php?action=totoyaRequest&sClass=' + sClass + '&sFunction=ajaxSaveForm';
					break;
					case 'totoya':
					default:
						sUrl = '/ajax/'+sClass+'/ajaxSaveForm'
					break;
				}
				$.ajax({
						url:		sUrl
						,data:		convert2PostData(oSend)
						,success:	sendSuccess
						,dataType:	'json'
						,async:		false
						});
			}
			else {
				var bFileUpload = false;
				for(var i in oFields) {
					if( oFields[i].sType == "ImageUpload" && oFields[i].bDirty) {
						bFileUpload = true;
						break;
					}
				}

				
				var sUrl = ''
				switch(oSystem.sName) {
					case 'typo3':
						sUrl = '/?eID=json&action=totoyaRequest&sClass=' + sClass + '&sFunction=ajaxSaveForm'
					break;
					case 'wordpress':
						sUrl = '/wp-content/plugins/chio-newsletter/totoya/totoya-ajax.php?action=totoyaRequest&sClass=' + sClass + '&sFunction=ajaxSaveForm';
					break;
					case 'totoya':
					default:
						sUrl = '/ajax/'+sClass+'/ajaxSaveForm'
					break;
				}				

				if(bFileUpload) {
					// for sending via form we create a hiden extra form
					// and an iframe, that will be the target of the submit

					$('body').prepend(
						$(
							'<div id="submitHelper" style="position:absolute; top:-2000px; height:300px; width: 300px; overflow:hidden;">'
							+ '<form style="border: 2px solid red;" id="submitForm" target="submitIframe" action="' + sUrl + '" method="post" enctype="multipart/form-data" />'
							+ '<iframe id="submitIframe" name="submitIframe" width="100" height="100" border="10" frameborder="0"></iframe>'
							+ '</div>'
						)
					);
					
					// now we convert the post-data into input fields that we put into the hidden form
					oSend.sCallBack = "top.$('#"+oSelf.attr('id')+"').cForm('sendSuccess', {{DATA}})";
					convert2inputFields($('#submitForm'), oSend);
					
					// and move all file-upload-fields into that form
					for(var i in oFields) {
						var iDatasetId = parseInt(oDatasetIds[oFields[i].iRow]);
						if(iDatasetId < 1 || isNaN(iDatasetId) ) {
							iDatasetId = -1;
						}
						if( oFields[i].sType == "ImageUpload" && oFields[i].bDirty) {
							// TODO: Wenn mehrere Felder, dann alle hin und Her hängen!
							for(j=0; j<oFields[i].fHandler.iRowNum; j++) {
								$('#' + oFields[i].sName + '_' + j).before('<div class ="file_placeholder" id="' + oFields[i].sName + '_' + j + '_placeholder" />');
								$('#submitForm').append(
									$('#' + oFields[i].sName + '_' + j)	
								);
								$('#' + oFields[i].sName + '_' + j).attr('name', 'aRows[' + iDatasetId + '][aFields][' + oFields[i].iId + '][]');
							}
						}
					}
					
					// now we submit the form and wait for the callback
					$(oSelf).data('fCallback', fCallback);
					$('#submitForm').submit();

				}
				else {
					$.post(sUrl, convert2PostData(oSend), sendSuccess, 'json');
					
				}
			}
			// true indicates, that there were no problems, which is important for subforms
			return true; 
		}




		/**
		 * called by saveData ajax request on success
		 *
		 * -fetches id from server return and stores it as new datasetid
		 * -calls all "after send" handlers of the subfields
		 * -starts the callbackFunction "onAfterSubmit"
		 *
		 * @param object o	ajax response object
		 */

		function sendSuccess(oFuncParam) {
			log('sendSuccess');
			// only load fCallback if iframe-submit was used:
			if($('.file_placeholder').length>0) {
				fCallback = $(oSelf).data('fCallback');
			}
			// move file inputs back
			$('.file_placeholder').each(function(){
				var me = $(this);
				var sFieldName = me.attr('id').slice(0,-12);
				me.after($('#'+sFieldName));
				me.remove();
			});
			//set idDataset according to serverside answer
			var iNewDatasetId = parseInt(oFuncParam.mData);
			var oDatasetIds = $(oSelf).data('oDatasetIds');
			var oFields = $(oSelf).data('oFields');

			if(iNewDatasetId > 0) {
				$(oSelf).data('iDatasetId', iNewDatasetId);
				for(i in oDatasetIds) {
					oDatasetIds[i]	= iNewDatasetId;
					break;
				}
			}
			
			
			// NICE: Hier muss eigentlich folgendes getan werden, was ich aus Zeitgründen nicht ausprogrammiere:
			// für alle after-submits muss ein callback übergeben werden, der dann wie bei lazy-load hochzählt,
			// bis alle callbacks ausgeführt wurden und erst dann dürfen die unten stehenden Aktionenn "CMS-Saved"
			// und der Form-Callback "After Submit" durchgeführt werden.

			// call afterSubmit function on all fieldHandlers which need that like subform-fields
			var bSuccess = true;
			var iFirstElementId = false;
			for(var i in oFields){
				if(iFirstElementId === false) {
					iFirstElementId = i;
				}
				if(oFields[i].fHandler.afterSubmit && typeof(oFields[i].fHandler.afterSubmit) == "function"){
					bSuccess &= oFields[i].fHandler.afterSubmit(oFields[i].fHandler);
				}
			}

			// interrupt if subforms did not succeed!
			if(!bSuccess) {
				log('subforms have errors, recall will not be executed!');
				return true;
			}

			// fire onAfterSubmit of the form
			// will only be fired, if the subforms where saved too!
			if(typeof $(oSelf).data('onAfterSubmit') == "function" && $(oSelf).data('onAfterSubmit') != null) {
				var callbackObject = {
					fFunction:	$(oSelf).data('onAfterSubmit')
					,oScope:	this
					,mParam:	{
									"sServerResponse"	:oFuncParam.mData
									,"sFlag"			:oFuncParam.sFlag
									,"iDatasetId"		:(iNewDatasetId>0)?iNewDatasetId:oDatasetIds[oFields[iFirstElementId].iRow]
									,"oFields"			:oFields
								}
				};
				var afterSubmitResult = executeCallback(callbackObject);
				if (typeof afterSubmitResult == 'boolean' && !afterSubmitResult) {
					return false;
				}
			}


			log('form sucessfully saved!');

			// set fields undirty
			for (var i in oFields) {
				if (oFields[i].bDirty) {
					oFields[i].bDirty = false;
				}
				if(parseInt(oDatasetIds[oFields[i].iRow]) == -1 && !isNaN(iNewDatasetId)) {
					oDatasetIds[oFields[i].iRow] = iNewDatasetId;
					log("changed to:"+iNewDatasetId);
				}
			}


			if(typeof cmsShowSaved == 'function') {
				cmsShowSaved();
			}

			// execute callback
			var tmpCallBack;
			tmpCallBack = {
				callback: fCallback
			};
			fCallback = null;
			executeCallback({
				fFunction: tmpCallBack.callback
				,oScope:	this
				,mParam:	{
									"sServerResponse"	:oFuncParam.mData
									,"sFlag"			:oFuncParam.sFlag
									,"iDatasetId"		:(iNewDatasetId>0)?iNewDatasetId:oDatasetIds[oFields[iFirstElementId].iRow]
									,"oFields"			:oFields
							}
				});
			
			// remove submit helper after callback (for "top" being avaliable)
			$('#submitHelper').remove();

			return true;
		}


//--

		// global operation
		var mRet = null;
		switch(sAction){
			case 'setup':
			case 'init':
				iDatasetId		= oParam.iDatasetId;
				sFormName		= oParam.sFormName;
				sLanguage		= oParam.sLanguage;
				if(sAction == 'setup') {
					$(oSelf).data(	'bAutorender',	true);
				}
				initForm(oParam);
				// here: register render-action for callback!
				break;
			case 'render':
				mRet = renderForm(oParam);
				break;
			case 'change':
				mRet = changeData(oFuncParam);
				break;
			case 'quickSave':
				oParam.dontValidate = true;
			case 'save':
				mRet = saveData(oFuncParam);
				break;
			case 'validate':
				mRet = validateAllFields();
				break;
			case 'sendSuccess':
				mRet = null;
				sendSuccess(oFuncParam);
				break;
		}
		$(oSelf).data('oParam', oParam);
		return mRet;
	};

})(jQuery);











/* ---------- /var/www/africanworld.de/htdocs/totoya/cache/core/clib/lib/jquery/cform/fields.js ---------- */



//--------------------
//	definition of default behavior
//--------------------


function createDefaultField(oSelf, oElement) {

	oSelf.oElement = oElement;

	oSelf.sTemplate =
		'<div class="formFieldLabel">{{sLabel}}{{bRequired:}} <span class="formFieldRequired">*</span>{{:bRequired}}</div>'
		+'<div class="formFieldData">'
			+'<input class="formFieldText" name="{{sName}}" id="{{sName}}" type="text" /> {{sHelp}}'
			+'<div class="formFieldMessage" id="message_{{sName}}" style="display:none">'
				+'<div class="formFieldMessageText" id="message_text_{{sName}}"></div>'
			+'</div>'
		+'</div>';
	oSelf.sTemplateReadonly =
		'<div class="formFieldLabel"><span>{{sLabel}}</span></div>'
		+'<div class="formFieldData"><span>{{sRenderValue}}</span></div>'
		+'<div class="floatEnd"></div>';
	
	oSelf.createReadonly = function(oParent) {
		// creating HTML elements
		this.oElement.sRenderValue = this.oElement.sData;
		if(typeof this.beforeCreateReadonly == 'function') {
			var sRet = this.beforeCreateReadonly();
			if(typeof sRet == 'string') {
				this.oElement.sRenderValue = sRet;
			}
		}
		if(this.oElement.sTemplateReadonly) {
			return cTemplate.parse(this.oElement.sTemplateReadonly, this.oElement);
		}
		else {
			return cTemplate.parse(this.sTemplateReadonly, this.oElement);
		}

	};
	oSelf.create = function(oParent) {
		// creating HTML elements
		if(typeof this.beforeCreate == 'function') {
			this.beforeCreate();
		}
		if(this.oElement.sTemplate && this.oElement.sTemplate.length > 0) {
			return cTemplate.parse(this.oElement.sTemplate, this.oElement);
		}
		else {
			return cTemplate.parse(this.sTemplate, this.oElement);
		}
	};

	oSelf.init = function() {
		if(typeof this.beforeInit == 'function') {
			this.beforeInit();
		}
		$('#'+this.oElement.sName)
			.val(	this.oElement.sData)
			.unbind().bind(	'change',	{'oSelf':this},	this.change);
		if(typeof this.afterInit == 'function') {
			this.afterInit();
		}
	};

	oSelf.change = function(o) {
		var oSelf		= o.data.oSelf;
		var oElement 	= oSelf.oElement;
		if(typeof oSelf.beforeChange == 'function') {
			oSelf.beforeChange(o);
		}
		var oParam =  {
				"element":	oElement,
				"value":	$(this).val()
		};
		if(typeof oSelf.afterChange == 'function') {
			oSelf.afterChange(o, oParam);
		}
		$('#'+oElement.sSelfId).cForm('change', oParam);
	};
	
	oSelf.validate = function(sValue, oResult){
		// no validation by default
	};
	
	oSelf.renderMessages = function(aMessages) {
		var sMessage = "";
		for(var i in aMessages) {
			sMessage += aMessages[i] + "<br />";
		}
		if(sMessage != ''){
			$('#message_text_'+this.oElement.sName).html(sMessage);
			$('#message_'+this.oElement.sName).show('fast');
		}
		else {
			$('#message_'+this.oElement.sName).hide('fast');
		}
	};
}

//--------------------
//helper functions for select elements
//--------------------

function createDropdown(aItems, iActiveItemValue) {
	var oSelect = document.createElement('select');
	addDropdownItems(oSelect, aItems, iActiveItemValue);
	return oSelect;
}
function addDropdownItems(oDomNode, aItems, iActiveItemValue, bMultiple, aSort) {
	if (typeof aSort != 'object' || typeof aSort == null) {
		aSort = [];
		for (var i in aItems) {
			aSort.push(i);
		}
	}
	$(oDomNode).empty();
	for(var i in aSort) {
		var k = aSort[i];
		var oOption = document.createElement('option');
		oOption.setAttribute('value', k);
		oOption.innerHTML = aItems[k];
		if(!bMultiple && k == iActiveItemValue) {
			oOption.setAttribute('selected', 'selected');
		}
		else if(bMultiple) {
			for(var j in iActiveItemValue) {
				if(k == iActiveItemValue[j]) {
					oOption.setAttribute('selected', 'selected');
				}
			}
		}
		oDomNode.appendChild(oOption);
	}
	return;
}


//--------------------
//class for text inputs
//--------------------


function totoyaFormFieldText(oElement) {
	createDefaultField(this, oElement);
}

//--------------------
//class for text inputs with counter
//--------------------

function totoyaFormFieldText_counter(oElement) {

	createDefaultField(this, oElement);

	this.init = function() {
		this.oElement.mParam = parseInt(this.oElement.mParam);
		// if mParam is greater than 0, initialise the countervalue and call this.counter on changes, instead of directly this.change
		if(this.oElement.mParam > 0){
			$('#'+this.oElement.sName)
				.unbind()
				.bind('change',	{'oSelf':this},	this.counter)
				.bind('keyup',	{'oSelf':this},	this.counter);
			$('#'+this.oElement.sName+"_counterdiv").css("display", "block");
			$('#'+this.oElement.sName+"_counter").val(this.oElement.mParam - this.oElement.sData.length);
		}else{
			$('#'+this.oElement.sName).unbind().bind('change', {'oSelf':this}, this.change);
		}
		$('#'+this.oElement.sName).val(this.oElement.sData);
	};

	this.counter = function(o) {
		var sCurrentLength = _(this.oElement.sName).value.length;

		// if the current length is greater than it should be cut the last chars off
		if(sCurrentLength > this.oElement.mParam){
			_(this.oElement.sName).value = _(this.oElement.sName).value.substring(0, this.oElement.mParam);
			sCurrentLength = this.oElement.mParam;
		}

		// display the charsleftcounter in the counterfield
		if(_(this.oElement.sName+"_counter")){
			_(this.oElement.sName+"_counter").value = this.oElement.mParam - sCurrentLength;
		}

		// call the changefunction after all counterspecific things are done
		o.data.oSelf.change(o);
	};
}


//--------------------
//class for email inputs
//--------------------


function totoyaFormFieldEmail(oElement) {
	createDefaultField(this, oElement);

	this.validate = function(sNewValue, oResult) {
		var oRegExpMailcheck = new RegExp('^([a-zA-Z0-9\-\.\_]+)(\@)([a-zA-Z0-9\-\.]+)(\.)([a-zA-Z]{2,4})$');
		log(!oRegExpMailcheck.test(sNewValue));
		if(!oRegExpMailcheck.test(sNewValue)){
			oResult.bError = true;
			oResult.aMessages.push("E_PASSWORD");
		}
		return oResult;
	};
}

//--------------------
//class for Number inputs
//--------------------

function totoyaFormFieldInt(oElement) {

	createDefaultField(this, oElement);

	this.beforeChange = function(o) {
		$('#'+o.data.oSelf.oElement.sName).val(parseInt($('#'+o.data.oSelf.oElement.sName).val()));
	};
}

function totoyaFormFieldFloat(oElement) {

	createDefaultField(this, oElement);

	this.change = function(o) {
		var oSelf		= o.data.oSelf;
		var oElement 	= oSelf.oElement;
		var oParam =  {
				"element":	oElement,
				"value":	parseFloat($(this).val().toString().replace(',','.'))
		};
		$('#'+o.data.oSelf.oElement.sName).val(oParam.value.toString().replace('.',','));
		$('#'+oElement.sSelfId).cForm('change', oParam);
	};
	this.beforeChange = function(o) {

	};
}


//--------------------
//class for password inputs
//--------------------

function totoyaFormFieldPassword(oElement) {
	var oSelf = this;
	createDefaultField(this, oElement);
	this.sTemplate = '<div class="formFieldLabel">{{sLabel}} {{bRequired:}}<span class="formFieldRequired">*</span>{{:bRequired}}</div><span class="formFieldData"><input class="formFieldPassword" name="{{sName}}_1" id="{{sName}}_1" type="password" /> {{sHelp}}<br />{{sLabel}} wiederholen *<br /><input class="formFieldPassword" name="{{sName}}_2" id="{{sName}}_2" type="password" /></span>';

	this.init = function() {
		$('#'+this.oElement.sName+'_1').unbind().bind(	'change',	this.change);
		$('#'+this.oElement.sName+'_2').unbind().bind(	'change',	this.change);
	};

	this.change = function(o) {
		var oParam =  {
				"element":	oSelf.oElement,
				"value":	$(this).val()
		};
		$('#'+oSelf.oElement.sSelfId).cForm('change', oParam);
	};

	this.validate = function(sNewValue, oResult) {
		if (
				$('#'+oSelf.oElement.sName+'_1').val() != $('#'+oSelf.oElement.sName+'_2').val() 
				|| 
				($('#'+oSelf.oElement.sName+'_1').val().length < 5 && $('#'+oSelf.oElement.sName+'_1').val().length > 0)
			) {
			oResult.bError = true;
			oResult.aMessages.push("E_PASSWORD");
		}		
		else if($('#'+oSelf.oElement.sName+'_1').val().length == 0) {
			oSelf.oElement.bDirty = false;
		}

		return oResult;
	};
}


//--------------------
//class for simple password inputs
//--------------------

function totoyaFormFieldSimplepassword(oElement) {
	var oSelf = this;
	createDefaultField(this, oElement);
	this.sTemplate = '<div class="formFieldLabel">{{sLabel}} {{bRequired:}}<span class="formFieldRequired">*</span>{{:bRequired}}</div><span class="formFieldData"><input class="formFieldPassword" name="{{sName}}" id="{{sName}}" type="password" /> {{sHelp}}</span>';
}

//--------------------
//class for checkbox
//--------------------

function totoyaFormFieldCheckbox(oElement) {

	createDefaultField(this, oElement);

	this.sTemplate = '<div class="formFieldLabel">{{sLabel}}{{bRequired:}}<span class="formFieldRequired">*</span>{{:bRequired}}</div>'
			+'<div class="formFieldData">'
				+'<input class="formFieldCheckbox" name="{{sName}}" id="{{sName}}" type="checkbox" value="1"> {{sHelp}}'
				+'<div class="formFieldMessage" id="message_{{sName}}" style="display:none"></div>'
			+'</div>';

	this.beforeCreateReadonly = function() {
		return (oElement.sData)?'ja':'nein';
	};

	this.beforeInit = function() {
		this.oElement.sData = (this.oElement.sData == '' ? 0 : parseInt(this.oElement.sData));
		$('#'+oElement.sName).attr('checked', this.oElement.sData > 0 ? 'checked':'');
	};

	this.change = function(o) {
		var oSelf		= o.data.oSelf;
		var oElement 	= oSelf.oElement;
		if(typeof oSelf.beforeChange == 'function') {
			oSelf.beforeChange(o);
		}
		var oParam =  {
				"element":	oElement,
				"value":	($(this).attr("checked") ? 1 : 0)
		};
		if(typeof oSelf.afterChange == 'function') {
			oSelf.afterChange(o, oParam);
		}
		$('#'+oElement.sSelfId).cForm('change', oParam);
	};
}




//--------------------
//class for textareas
//--------------------

function totoyaFormFieldTextarea(oElement) {
	var oSelf = this;
	createDefaultField(this, oElement);

	this.sTemplate = '<div class="formFieldLabel">{{sLabel}}</div><span class="formFieldData"><textarea class="formFieldTextarea" name="{{sName}}" id="{{sName}}"></textarea> {{sHelp}}</span>';

	this.afterInit = function() {
		this.oElement.mParam = parseInt(this.oElement.mParam);
		// if mParam is greater than 0, initialise the countervalue and call this.counter on changes, instead of directly this.change
		if(this.oElement.mParam > 0){
			$('#'+this.oElement.sName).unbind().bind('change', oSelf.counter);
			$('#'+this.oElement.sName).unbind().bind('keyup', oSelf.counter);
			$('#'+this.oElement.sName+"_counterdiv").css("display","block");
			$('#'+this.oElement.sName+"_counter").val(oSelf.oElement.mParam - oSelf.oElement.sData.length);
		}
	};

	this.counter = function(o) {
		var iCurrentLength = $('#'+oSelf.oElement.sName).val().length;

		// if the current length is greater than it should be cut the last chars off
		if(iCurrentLength > oSelf.oElement.mParam){
			$('#'+oSelf.oElement.sName).val(
					$('#'+oSelf.oElement.sName).val().substring(0, oSelf.oElement.mParam)
			);
			iCurrentLength = oSelf.oElement.mParam;
		}

		// display the charsleftcounter in the counterfield
		$('#'+oSelf.oElement.sName+"_counter").val(oSelf.oElement.mParam - iCurrentLength);

		// call the changefunction after all counterspecific things are done
	};

}

//FOR BIG TEXTAREAS ONLY THE TEMPLATE HAS TO BE CHANGED
// if that does not work: replace the code by the code bove and only replace the template
function totoyaFormFieldBigtextarea(oElement) {
	var oTextField = new totoyaFormFieldTextarea(oElement);
	$.extend(this, oTextField);
	this.sTemplate = '<div class="formFieldLabel">{{sLabel}}</div><span class="formFieldData"><textarea class="formFieldBigTextarea" name="{{sName}}" id="{{sName}}"></textarea> {{sHelp}}</span>';
}


//--------------------
//class for submit buttons
//--------------------

function totoyaFormFieldSubmit(oElement) {

	this.oElement=oElement;

	this.sTemplate = '<div class="formFieldLabel"></div><span class="formFieldData"><input class="formFieldSubmit" name="{{sName}}" id="{{sName}}" type="submit" value="{{sLabel}}"></span>';
	this.create = function(oParent) {
		// creating HTML elements
		if(this.oElement.sTemplate) {
			return cTemplate.parse(this.oElement.sTemplate, this.oElement);
		}
		else {
			return cTemplate.parse(this.sTemplate, this.oElement);
		}
	};

	this.init = function(){
	};

}

//--------------------
//class for readonly texts
//--------------------

function totoyaFormFieldReadonly(oElement) {

	this.oElement=oElement;

	this.sTemplate = '<div class="formFieldLabel">{{sLabel}}</div><span class="formFieldData">{{sData}}</span>';
	this.create = function(oParent) {
		// creating HTML elements
		if(this.oElement.sTemplate) {
			return cTemplate.parse(this.oElement.sTemplate, this.oElement);
		}
		else {
			return cTemplate.parse(this.sTemplate, this.oElement);
		}
		// return the most outer element
		return null;
	};
	this.init = function() {
	};
	this.change = function(o) {
	};
}

//--------------------
//class for select fields
//--------------------

function totoyaFormFieldSelect(oElement) {
	createDefaultField(this, oElement);

	this.sTemplate = '<div class="formFieldLabel">{{sLabel}} {{bRequired:}}<span class="formFieldRequired">*</span>{{:bRequired}}</div><span class="formFieldData"><select class="formFieldSelect" name="{{sName}}" id="{{sName}}"></select> {{sHelp}}</span>';
	this.beforeCreateReadonly = function() {
		return oElement.mParam[oElement.sData];
	};
	this.init = function() {
		addDropdownItems(_(oElement.sName), oElement.mParam, oElement.sData, false, oElement.aSort);
		$('#'+this.oElement.sName).unbind().bind('change', {'oSelf':this}, this.change);
	};
}

//--------------------
//class for multiselect fields
//--------------------

function totoyaFormFieldMultiselect(oElement) {
	createDefaultField(this, oElement);

	this.sTemplate = '<div class="formFieldLabel">{{sLabel}}</div><span class="formFieldData"><select class="formFieldSelect" multiple="multiple" size="10" name="{{sName}}" id="{{sName}}"></select> {{sHelp}}</span>';
	this.init = function() {
		addDropdownItems(_(oElement.sName), oElement.mParam, oElement.sData, bMultiple=true);
		$('#'+this.oElement.sName).unbind().bind('change', {'oSelf':this}, this.change);
	};
}

//--------------------
//class for radio fields
//--------------------

function totoyaFormFieldRadio(oElement) {
	createDefaultField(this, oElement);

	this.sTemplate = '<div class="formFieldLabel">{{sLabel}} {{bRequired:}}<span class="formFieldRequired">*</span>{{:bRequired}}</div><span class="formFieldData"><div class="formFieldRadio" name="{{sName}}" id="{{sName}}"></div> {{sHelp}}</span>';
	this.beforeCreateReadonly = function() {
		return oElement.mParam[oElement.sData];
	};
	this.init = function() {
		if (oElement.sData == '0') {
			oElement.sData = '';
		}
		for(var sValue in oElement.mParam) {
			var sHtml = '<div class="formFieldRadio">'
				+'<input type="radio" name="'+oElement.sName+'_input" id="'+oElement.sName+'_'+sValue+'" value="'+sValue+'" />'
				+oElement.mParam[sValue]
				+'</div>';
			$('#'+oElement.sName).append(sHtml);
			if(sValue == oElement.sData) {
				$('#'+oElement.sName+'_'+sValue).attr('checked', 'checked');
			}
			$('#'+oElement.sName+'_'+sValue).unbind().bind('change', {'oSelf':this}, this.change);
		}
		
	};
}


//--------------------
//class for sub forms
//--------------------
function totoyaFormFieldForeign_forms(oElement) {
	createDefaultField(this, oElement);
	this.sTemplate			= '<div class="formSubformLabel">{{sLabel}}{{bRequired:}} <span class="formFieldRequired">*</span>{{:bRequired}}</div>'
								+'<div id="{{sName}}">'
									+'<div id="{{sName}}_subforms"></div>'
									+'<center><button id="{{sName}}_add_btn"><img src="/totoya/cache/core/clib/lib/jquery/cform/add.png" border="0" alt="" align="absmiddle" /> hinzufügen</button></center>'
								+'</div>';
	this.sSubformTemplate	= '<div id="subform_{{sName}}_{{iNum}}_container" class="subform_container">'
								+'<div id="subform_{{sName}}_{{iNum}}"></div>'
								+'<center><button id="subform_{{sName}}_{{iNum}}_del_btn"><img src="/totoya/cache/core/clib/lib/jquery/cform/remove.png" border="0" alt="" align="absmiddle" />  entfernen</button></center>'
							+'</div>';
	this.init = function() {
		$('#'+oElement.sName+'_add_btn').unbind().bind('click',function(e){
			oElement.fHandler.addForm(-1);
			e.preventDefault();
			return false;
		});

		oElement.iNum = 0;
		oElement.aForms = [];
		var oForm = $('#'+oElement.sSelfId);
		var sClass = (
				typeof $(oForm).data('oServerSiteClass') == 'string'
					&& $(oForm).data('oServerSiteClass') != null
					&& $(oForm).data('oServerSiteClass').length > 0 ?
				$(oForm).data('oServerSiteClass') :
				'cForm'
			);

		// init form
		if(typeof oElement.oClientParameter == 'string') {
			eval("oElement.oClientParameter = "+ oElement.oClientParameter);
		}

		// only look for foreign entrys if already a dataset id exists
		if ($('#'+oElement.sSelfId).data('oDatasetIds')[oElement.iRow] != null) {
			$.post('/ajax/'+sClass+'/ajaxGetIdsByForeignId'
				,{
					"iDatasetId"	: $('#'+oElement.sSelfId).data('oDatasetIds')[oElement.iRow]
					,"sName"		: oElement.oClientParameter.sFormName
					,"sForeignCol"	: oElement.oClientParameter.sForeignCol
					,"sOrderCol"	: oElement.oClientParameter.sOrderCol
					,"sOrderDir"	: oElement.oClientParameter.sOrderDir
				}
				,this.addFormsProxi
				,'json');
		}
	};

	// change cannot happen here, or can it?
	this.change = function(o) {
		return false;
	};


	this.validate = function(sValue, oResult){
		// has to call the validate function of subforms and return a or combined sum
		// validate subforms before parent form
		var bReturn = true;
		for(i in oElement.aForms) {
			bReturn = bReturn && $('#subform_'+oElement.sName+'_'+oElement.aForms[i])
				.cForm('validate', {});
		}
		return bReturn;
	};


	// save subforms after parent form to have the id for sure
	this.afterSubmit = function(){

		log("Saving subform with foreign ID:"+$('#'+oElement.sSelfId).data('iDatasetId'));
		var bResult = true;
		for(i in oElement.aForms) {
			bResult &= $('#subform_'+oElement.sName+'_'+oElement.aForms[i])
				.cForm(
					'save'
					,{
						'bSubformSave':true,
						'iForeignId':$('#'+oElement.sSelfId).data('iDatasetId')
					}
				);
		}
		return bResult;
	};

	this.addFormsProxi = function(o){
		// if not, the server returned not valid totoya-json :-/
		if (typeof o.mData == 'object') {
			for(var i in o.mData) {
				oElement.fHandler.addForm(o.mData[i].id);
			}
		}
		else {
			throw('Serverside return value was not well formed (totoya-json expected):'+o.mData);
		}
	};

	this.addForm = function(iForeignDatasetId) {

		// create htmlcode for new subform
		var sNewForm;
		if(oElement.sSubformTemplate) {
			sNewForm = cTemplate.parse(oElement.sSubformTemplate, oElement);
		}
		else {
			sNewForm = cTemplate.parse(oElement.fHandler.sSubformTemplate, oElement);
		}
		//append html into parent element
		$('#'+oElement.sName+'_subforms').append(sNewForm);

		// define callback in subform to set the foreign key col
		function onBeforeSubformSubmit(oPostData) {
			var iMasterFormId = $('#'+oElement.sSelfId).data('iDatasetId');
			for(var i in oPostData.aRows) {
				oPostData.aRows[i].sForeignKeyCol		= oElement.oClientParameter.sForeignCol;
				oPostData.aRows[i].iForeignKeyColData	= iMasterFormId;
			}
		}

		$('#subform_'+oElement.sName+'_'+oElement.iNum)
			.cForm('setup', $.extend({
				'bIsSubform'		: true
				,'iDatasetId'		: iForeignDatasetId
				,'onBeforeSubmit'	: onBeforeSubformSubmit
				}, oElement.oClientParameter)
			);

		// add del btn
		$('#subform_'+oElement.sName+'_'+oElement.iNum+'_del_btn')
			.unbind().bind('click', {"sName":oElement.sName,"iNum":oElement.iNum}, function(e){
				e.preventDefault();
				if(confirm("Wirklich entfernen?")) {
					oElement.fHandler.removeForm(e.data.iNum, e.data.sName);
				}
				return false;
			});

		oElement.aForms.push(oElement.iNum);
		oElement.iNum ++;
	};

	this.removeForm = function(iNum, sName) {
		// remove from forms array
		var iFormIndex = oElement.aForms.indexOf(iNum);
		oElement.aForms.slice(iFormIndex,1);
		// delete from database if it was saved before
		// get id
		var oForm	= $('#subform_'+sName+'_'+iNum);
		var iId		= $('#subform_'+sName+'_'+iNum).data('oDatasetIds')[0];
		iId			= parseInt(iId);
		if(!isNaN(iId) && iId > 0) {
			var sClass = (
					typeof $(oForm).data('oServerSiteClass') == 'string'
						&& $(oForm).data('oServerSiteClass') != null
						&& $(oForm).data('oServerSiteClass').length > 0 ?
					$(oForm).data('oServerSiteClass') :
					'cForm'
				);
			// ajax request
			$.post(
					'/ajax/'+sClass+'/ajaxdeleteitem'
					,convert2PostData({
						"sName": 		oElement.oClientParameter.sFormName
						,'iDatasetId':	iId
					})
				);
		}
		$('#subform_'+sName+'_'+iNum+'_container').remove();
	};
}





//--------------------
//class for HTMLInputs
//--------------------
function totoyaFormFieldHtml(oElement) {

	this.oElement=oElement;

	this.sTemplate = '<div class="fieldHTML" style="width:100%">{{sLabel}}{{bRequired:}} <span class="formFieldRequired">*</span>{{:bRequired}}<br />&nbsp;<br /><textarea name="{{sName}}" id="{{sName}}"></textarea></div>';
	this.create = function(oParent) {
		// creating HTML elements
		if(this.oElement.sTemplate) {
			return cTemplate.parse(this.oElement.sTemplate, this.oElement);
		}
		else {
			return cTemplate.parse(this.sTemplate, this.oElement);
		}
	};
	this.oEditor = null;
	this.init = function() {
		//@NICE: make fck an lazy load element (and better update to ck-edit)
		_(this.oElement.sName).value = this.oElement.sData;
		this.oEditor = new FCKeditor(this.getEditorInstanceName());
		this.oEditor.BasePath = "/totoya/cache/core/clib/lib/fckeditor/";
		this.oEditor.Height = "100%";
		this.oEditor.ReplaceTextarea();
		FCKeditorDoOnComplete[FCKeditorDoOnComplete.length] = {
				oScope: this,
				fnFunction: this.initEditor
		};


	};

	this.initEditor = function(){
		this.oEditor = FCKeditorAPI.GetInstance(this.getEditorInstanceName());

	};
	this.getEditorInstanceName = function(){
		return this.oElement.sName;
	};
	this.getEditorContent = function(o){
		return this.oEditor.GetHTML();
	};

	this.update = function(o){
		if(this.oElement.sData == this.getEditorContent()){
			this.oElement.bDirty = false;
		}else{
			this.oElement.sData = this.getEditorContent();
			this.oElement.bDirty = true;
			_(this.getEditorInstanceName()).value = this.oElement.sData;
			//this.change();
		}
	};

	//this.change = function(o) {
	//	this.oElement.oFormManager.fieldChange(this.oElement, _(this.oElement.sName).value);
	//};

}


//--------------------
//class for Images
//--------------------

//uses picture chooser
//=> must load it with lazy load
//=> drag n drop with media libary has to be made new!
function imageCallbackHelper(oParam) {
	$('#' + oParam.sName + '_image').html('<img src="/image/' + oParam.framework.iId + '/0/300/boundingbox/center/jpg" title="" alt="" />');
	$('#' + oParam.sName).val(oParam.framework.iId);
}	
function totoyaFormFieldImage(oElement) {
	var oSelf = this;
	createDefaultField(this, oElement);
	oSelf.oElement.iDatasetId	= $('#' + oElement.sSelfId).data('iDatasetId');
	oSelf.oElement.iOrderKey	= oElement.mParam.iOrderKey;
	oSelf.oElement.sTable		= oElement.mParam.sTable;
	this.sTemplate =
		'<div class="formFieldLabel">{{sLabel}}{{bRequired:}} <span class="formFieldRequired">*</span>{{:bRequired}}</div>'
		+'<div class="formFieldData">'
			+'<div style="width:100%; overflow:hidden; border:1px solid black; height:300px;" id="{{sName}}_image"></div>'
			+'<input type="hidden" value="{{sData}}" id="{{sName}}" /> {{sHelp}}'
			+'<button type="button" onclick="top.fnPictureChooser({{iDatasetId}}, \'{{sTable}}\', {{iOrderKey}}, null, { fFunction: imageCallbackHelper, mParam: {sName:\'{{sName}}\'} });">Bild wechseln</button>'
			+'<div class="formFieldMessage" id="message_{{sName}}" style="display:none">'
				+'<div class="formFieldMessageText" id="message_text_{{sName}}"></div>'
			+'</div>'
		+'</div>';
		
		
	this.create = function(oParent) {
		// creating HTML elements
		if(this.oElement.sTemplate) {
			return cTemplate.parse(this.oElement.sTemplate, this.oElement);
		}
		else {
			return cTemplate.parse(this.sTemplate, this.oElement);
		}
	};

	this.init = function() {
		// set current data
		$(oSelf.oElement.sName).value = oSelf.oElement.sData;

		// show image
		if(oSelf.oElement.sData > 0) {
			$('#' + oSelf.oElement.sName + '_image').html('<img src="/image/' + oSelf.oElement.sData + '/0/300/boundingbox/center/jpg" title="" alt="" />');
		}
	};
}


//--------------------
//class for Image Upload
//--------------------

function totoyaFormFieldImageUpload(oElement) {
	var oSelf = this;
	createDefaultField(this, oElement);
	oSelf.oElement.iDatasetId	= $('#' + oElement.sSelfId).data('iDatasetId');
	oSelf.oElement.iOrderKey	= oElement.mParam.iOrderKey;
	oSelf.oElement.sTable		= oElement.mParam.sTable;
	oSelf.bMultiple				= false;
	oSelf.iMaxUploads			= 9999;
	oSelf.iRowNum				= 1;
	this.sRow =
		'<div id="{{sName}}_row_AAA">'
			+'<div class="image_upload_preview" id="{{sName}}_AAA_image_preview"></div>'
			+'<div class="image_upload_button_container">'
				+'<div class="image_upload_button_inner_container">'
						+'<input type="file" value="{{sData}}" id="{{sName}}_AAA" class="image_upload_button_button" />'
				+'</div>'
			+'</div>'
		+'</div>';
	this.sTemplate =
		'<div class="formFieldLabel">{{sLabel}}{{bRequired:}} <span class="formFieldRequired">*</span>{{:bRequired}}</div>'
		+'<div class="formFieldData" id="{{sName}}_rows">'
			+ this.sRow.replace(/AAA/g, '0')
			+'<span id="{{sName}}_remove_all">Bild löschen</span>'
			+'{{sHelp}}'
		+'</div>';
	
	this.sTemplateReadonly = ''
		+'<div style="width:100px; overflow:hidden; border:1px solid black; height:120px;" id="{{sName}}_0_image_preview">'
			+'<img src="/image/i{{sRenderValue}}/100/120/centerbox/center/jpg" title="" alt="" />'
		+'</div>';
	
	
	
	/**
	 * cFormField renderer fpr read only
	 * 
	 * @param oParent
	 * @returns string HTML of field
	 */
	oSelf.createReadonly = function(oParent) {
		// creating HTML elements
		if(parseInt(oSelf.oElement.sData) > 0) {
			oSelf.oElement.sRenderValue = oSelf.oElement.sData;
			if(typeof oSelf.beforeCreateReadonly == 'function') {
				var sRet = oSelf.beforeCreateReadonly();
				if(typeof sRet == 'string') {
					oSelf.oElement.sRenderValue = sRet;
				}
			}
			if(oSelf.oElement.sTemplateReadonly) {
				return cTemplate.parse(oSelf.oElement.sTemplateReadonly, oSelf.oElement);
			}
			else {
				return cTemplate.parse(oSelf.sTemplateReadonly, oSelf.oElement);
			}
		}
		else {
			return '';
		}
	};

	
	
	
	/**
	 * cFormField init function
	 * sets events and co
	 * 
	 * @returns void
	 */
	this.init = function() {
		// show image
		if(oSelf.oElement.sData > 0) {
			$('#' + oSelf.oElement.sName + '_0_image_preview').html('<img src="/image/i' + oSelf.oElement.sData + '/100/120/centerbox/center/jpg" title="" alt="" />');
		}
		// define change handler
		$('#' + oSelf.oElement.sName+'_0').change(oSelf.change);
		
		// define handling of multiple file uploads:
		// checking definition of parameter
		if(parseInt(oElement.mParam) > 0) {
			oSelf.bMultiple = true;
			oSelf.iMaxUploads = parseInt(oElement.mParam);
			$('#' + oSelf.oElement.sName+'_remove_all').remove();
		}
		else if(oElement.mParam == 'multiple' || oElement.mParam == 'true') {
			oSelf.bMultiple = true;
			$('#' + oSelf.oElement.sName+'_remove_all').remove();
		}
		else {
			$('#' + oSelf.oElement.sName+'_remove_all')
				.css('cursor','pointer')
				.click(oSelf.removeAll);
		}	
			
		// check whether the browser supports html5 like uploads
		var oInput = document.getElementById(oSelf.oElement.sName + '_0');
		if(oSelf.bMultiple && typeof oInput.files == 'object' && oInput.files != null) {
			// if true then init :-)
			$(oInput).attr('multiple', 'multiple');
		}
	};
	
	
	
	
	
	/**
	 * cFormField validator
	 * 
	 * @param string sValue
	 * @param object oResult
	 */
	this.validate = function(sValue, oResult){
		return oSelf.oElement.bDirty;
	};

	
	
	
	this.removeAll = function() {
		if(confirm('Wollen Sie das Bild wirklich löschen?')) {
			oSelf.oElement.sData = 'remove';
			oSelf.oElement.bDirty = true;
			$('.image_upload_preview_pfotto img').remove();
			$('#'+oSelf.oElement.sSelfId).cForm('save');
		}
	};
	
	
	
	
	/**
	 * cFormField change handler
	 */
	this.change = function(e) {
		oSelf.oElement.sData = '1';
		oSelf.oElement.bDirty = true;
		var oInput = e.currentTarget;
		if(typeof oInput.files == 'object' && oInput.files != null) {
			var sUrl = oInput.files.item(0).getAsDataURL();
		}
		else {
			var sUrl = $('#' + oSelf.oElement.sName).val();
		}
		$('#' + $(oInput).attr('id') + '_image_preview').html('<img src="' + sUrl + '" aligntitle="" alt="" width="100" align="absmiddle" />');
		function resizeMargins() {
			var iHeight = $('#' + oSelf.oElement.sName + '_image_preview img').height();
			var iMarginTop = parseInt((120-iHeight)/2 ).toString();
			log(iMarginTop);
			$('#' + oSelf.oElement.sName + '_image_preview img').css('margin-top', iMarginTop + 'px');
		}
		resizeMargins();
		window.setTimeout(resizeMargins, 500);
		iMyNum = parseInt($(oInput).attr('id').substr($(oInput).attr('id').lastIndexOf('_')+1));
		if(oSelf.bMultiple && iMyNum == oSelf.iRowNum-1) {
			$('#'+oSelf.oElement.sName + '_rows')
				.append(
					cTemplate.parse(oSelf.sRow.replace(/AAA/g, oSelf.iRowNum), oSelf.oElement)
				);
			oNewInput = document.getElementById(oSelf.oElement.sName + '_'+oSelf.iRowNum);
			$(oNewInput).change(oSelf.change);
			if(typeof oNewInput.files == 'object' && oNewInput.files != null) {
				// if true then init :-)
				$(oNewInput).attr('multiple', 'multiple');
			}
			oSelf.iRowNum++;
		}
		var oParam =  {
				"element":	oElement,
				"value":	oSelf.iRowNum
		};
		$('#'+oElement.sSelfId).cForm('change', oParam);
	};
}


//--------------------
// class for Hidden
//--------------------


function totoyaFormFieldHidden(oElement) {

	var bChangedValue = (
		typeof oElement.oClientParameter != 'undefined'
		&& oElement.oClientParameter !== null
	);
	
	if (bChangedValue) {
		oElement.sData = oElement.oClientParameter;
	}

	createDefaultField(this, oElement);

	this.sTemplate = '<input type="hidden" name="{{sName}}" id="{{sName}}" value="{{oClientParameter}}" />';

	this.update = function(o) {
		if (bChangedValue) {
			oElement.bDirty = true;
		}
	};
}





//--------------------
//class for date fields
//--------------------

function totoyaFormFieldDate(oElement) {
	var oSelf = this;

	createDefaultField(this, oElement);

	this.sTemplate = '<div class="formFieldLabel">{{sLabel}}</div>'
			+'<div class="formFieldData">'
				+'<input class="formFieldDate" name="{{sName}}" id="{{sName}}" type="text"> {{sHelp}}'
			+'</div>';

	this.init = function() {
		$.lazyLoad(['jqueryDatePicker'], function() {
			$.dpText = {
				TEXT_PREV_YEAR		:	'Vorheriges Jahr',
				TEXT_PREV_MONTH		:	'Vorheriger Monat',
				TEXT_NEXT_YEAR		:	'N&auml;chstes Jahr',
				TEXT_NEXT_MONTH		:	'N&auml;chster Monat',
				TEXT_CLOSE			:	'Schlie&szlig;en',
				TEXT_CHOOSE_DATE	:	'Kalender',
				HTML_CHOOSE_DATE	:	'<img src="/totoya/cache/core/clib/lib/jquery/datepicker/btn_calendar.png" alt="Kalender" />'
			};
			$('#'+oElement.sName).val(english2GermanDate(oElement.sData));
			setGermanDate();
			oSelf.checkDate(oElement.sName);
			var options = $.extend(
				{
					beforeRenderCallback:	oSelf.checkDate
					, startDate:			'01/01/1900'
				}
				, oElement.oClientParameter
			);
	
	
			$('#'+oElement.sName)
				.datePicker(options)
				.bind('dateSelected', oSelf.changeDate)
				.bind('change', oSelf.changeDate);
		});
	};

	this.checkDate = function(sId) {
		var sDate = $('#'+sId).val();
		var aDate = sDate.split('.');
		var iDay = parseInt(aDate[0], 10);
		var iMonth = parseInt(aDate[1], 10);
		var iYear = parseInt(aDate[2], 10);
		if (
			aDate.length != 3
			|| isNaN(iDay)
			|| iDay < 1
			|| isNaN(iMonth)
			|| iMonth < 1
			|| isNaN(iYear)
			|| iYear < 1
		) {
			$('#'+sId).val('');
			oElement.sData = '';
		} else {
			var sDay = iDay.toString();
			while (sDay.length < 2) {
				sDay = '0' + sDay;
			}
			var sMonth = iMonth.toString();
			while (sMonth.length < 2) {
				sMonth = '0' + sMonth;
			}
			var sYear = iYear.toString();
			sYear = (sYear.length == 1) ? sYear = '0' + sYear : sYear;
			while (sYear.length == 2) {
				sYear = (iYear < 30 ? '20' : '19') + sYear;
			}
			$('#'+sId).val(sDay + '.' + sMonth + '.' + sYear);
			oElement.sData = sDay + '.' + sMonth + '.' + sYear;
		}
	};
	
	this.validate = function(sDate, oResult){
		if(
			typeof oElement.oClientParameter != 'undefined' 
			&& oElement.oClientParameter !== null
			&& typeof oElement.oClientParameter.minAge == 'number' 
			&& oElement.oClientParameter.minAge > 0
		) {
			var oMaxDate = new Date();
			oMaxDate.setFullYear(oMaxDate.getFullYear()-oElement.oClientParameter.minAge);
			var aDate = sDate.split('-');
			var iDay = parseInt(aDate[2], 10);
			var iMonth = parseInt(aDate[1], 10);
			var iYear = parseInt(aDate[0], 10);
			oGivenDate = new Date(iYear, iMonth-1, iDay);
			if(oGivenDate>oMaxDate) {
				oResult.bError = true;
				oResult.aMessages.push("Das Mindestalter beträgt " + oElement.oClientParameter.minAge + " Jahre");
			}
		};
		return oResult;
	};

	this.changeDate = function() {
		if(typeof oSelf.beforeChange == 'function') {
			oSelf.beforeCreate(o);
		}
		oSelf.checkDate(oElement.sName);
		var oParam =  {
			"element":	oElement,
			"value":	german2EnglishDate($(this).val())
		};
		if(typeof oSelf.afterChange == 'function') {
			oSelf.afterChange(o, oParam);
		}
		$('#'+oElement.sSelfId).cForm('change', oParam);
	};
}

function english2GermanDate(sDate) {
	var aDate = sDate.split('-');
	if (aDate.length == 3) {
		sDate = aDate[2]+'.'+aDate[1]+'.'+aDate[0];
	}
	return sDate;
}

function german2EnglishDate(sDate) {
	var aDate = sDate.split('.');
	if (aDate.length == 3) {
		sDate = aDate[2]+'-'+aDate[1]+'-'+aDate[0];
	}
	return sDate;
}




//--------------------
//class for learning fields
//--------------------

function totoyaFormFieldLearning(oElement) {

	this.oElement=oElement;
	this.sTemplate = '<div class="formFieldLabel">{{sLabel}}</div><div class="formFieldLearningOuterDiv"><input class="formFieldLearningInput" name="{{sName}}" id="{{sName}}" type="text"><div id="{{sName}}_autocomplete" className="formFiledLearningSuggestion"></div></div>{{sHelp}}';
	this.oDataSource = 		new YAHOO.widget.DS_JSArray(this.oElement.mParam);

	this.create = function(oParent) {
		// creating HTML elements
		var oDiv = 		document.createElement('div');
		if(this.oElement.sTemplate) {
			oDiv.innerHTML = cTemplate.parse(this.oElement.sTemplate, this.oElement);
		}
		else {
			oDiv.innerHTML = cTemplate.parse(this.sTemplate, this.oElement);
		}

		oParent.appendChild(oDiv);

		_(this.oElement.sName).value = this.oElement.sData;

		this.oAutoComplete = new YAHOO.widget.AutoComplete(this.oElement.sName, this.oElement.sName+'_autocomplete', this.oDataSource);
	    this.oAutoComplete.prehighlightClassName = "yui-ac-prehighlight";
	    this.oAutoComplete.typeAhead = false;
	    this.oAutoComplete.useShadow = true;
	    this.oAutoComplete.minQueryLength = 0;
	    this.oAutoComplete.textboxFocusEvent.subscribe(function(oSelf){
	        var sInputValue = YAHOO.util.Dom.get(oSelf.oElement.sName).value;
	        if(sInputValue.length === 0) {
	            window.setTimeout(function(oSelf2){oSelf2.sendQuery(sInputValue);},0, oSelf);
	        }
	    });
		this.oAutoComplete.itemSelectEvent.subscribe(this.change, this, true);

		Event.addListener(this.oElement.sName, 'change', this.change, this, true);

		// return the most outer element
		return;
	};

	this.change = function(o) {
		this.oElement.oFormManager.fieldChange(this.oElement, _(this.oElement.sName).value);
	};
}





/* ---------- /var/www/africanworld.de/htdocs/totoya/cache/core/clib/admin/framework/skin/default/js/ctemplate.js ---------- */

var cTemplate = {

	parse: function(sTemplate, oData) {
		for(var i in oData) {
			if(typeof oData[i] == "array" || typeof oData[i] == "object") {
				// explode template in three parts (before block, block and after block)
				var sBlock = this.getBlock(sTemplate, i);
				if(sBlock == null) continue;
				// recurse with only parsing the block for each item in array or object
				var sReplace = "";
				for(var j in oData[i]) {
					sReplace += this.parse(sBlock, oData[i][j]);
				}
				// replace block by generated content
				sTemplate = this.replaceBlock(sTemplate, i, sReplace);
			}
			else if(typeof oData[i] == "boolean") {
				var sBlock = this.getBlock(sTemplate, i);
				if(sBlock == null) continue;
				// recurse with only parsing the block for each item in array or object
				if(!oData[i]) {
					sBlock = "";
				}
				// replace block by generated content
				sTemplate = this.replaceBlock(sTemplate, i, sBlock);
			}
			else {
				sTemplate = this.replaceItem(sTemplate, i, oData[i]);
			}
		}
		return sTemplate;
	}

	,getBlock:	function(sTemplate, sBlockName) {
		var sRegExp = '{{'+sBlockName+':}}([\\s\\S]*){{:'+sBlockName+'}}';
		var oRegExp = new RegExp(sRegExp, "g");
		var aMatches = oRegExp.exec(sTemplate);
		if(aMatches == null) {
			return null;
		}
		return aMatches[1];
	}

	,replaceBlock:	function(sTemplate, sBlockName, sReplace) {
		var sRegExp = '{{'+sBlockName+':}}([\\s\\S]*){{:'+sBlockName+'}}';
		if (typeof sReplace != 'string' && typeof sReplace != 'number') {
			sReplace = '';
		}
		var sNewTemplate = sTemplate.replace(new RegExp(sRegExp, "g"), sReplace);
		return sNewTemplate;
	}

	,replaceItem:	function(sTemplate, sItemName, sReplace) {
		var sRegExp = '{{'+sItemName+'}}';
		if (typeof sReplace != 'string' && typeof sReplace != 'number') {
			sReplace = '';
		}
		var sNewTemplate = sTemplate.replace(new RegExp(sRegExp, "g"), sReplace);
		return sNewTemplate;
	}

};

/* ---------- template-global_v3-animation2 ---------- */

/*
 *	jQuery carouFredSel 1.1.2
 *	www.frebsite.nl
 *	Copyright (c) 2009 Fred Heusschen
 *	Licensed under the MIT license.
 *	http://www.opensource.org/licenses/mit-license.php
 */


(function($) {
	$.fn.carouFredSel = function(options) {
		return this.each(function() {
			var opts 			= $.extend({}, $.fn.carouFredSel.defaults, options),
				$ul 			= $(this),
				$items 			= $("li", $ul),
				totalItems		= $items.length,
				lastItem		= opts.visibleItems,
				firstItem		= totalItems-1,
				itemWidth		= $items.outerWidth(),
				itemHeight		= $items.outerHeight(),
				autoInterval	= null,
				direction		= (opts.direction == "up" || opts.direction == "right") ? "next" : "prev";


			if (opts.direction == "right" ||
				opts.direction == "left"
			) {
				var css = {
					width	: itemWidth * opts.visibleItems,
					height	: $ul.outerHeight() || itemHeight
				}
			} else {
				var css = {
					height	: itemHeight * opts.visibleItems,
					width	: $ul.outerWidth() || itemWidth
				}
			}

			$ul.wrap('<div class="caroufredsel_wrapper" />').css({
				position	: "absolute"
			}).parent().css(css).css({
				position	: "relative",
				overflow	: "hidden"
			});

			if (opts.scrollItems 		== 0)	opts.scrollItems		= opts.visibleItems;
			if (opts.scrollItemsButtons == 0)	opts.scrollItemsButtons = opts.scrollItems;

			if (opts.visibleItems >= totalItems) return false;

			$items.filter(":gt("+(opts.visibleItems-1)+")").remove();
			$ul
				.bind("pause", function() {
					if (autoInterval != null) {
						clearTimeout(autoInterval);
					}
				})
				.bind("play", function(e, d) {
					if (opts.pauseDuration > 0) {
						if (d == null	||
							d == '' 	||
							typeof(d)	|| 'undefined'
						) {
							d = direction;
						}

						autoInterval = setTimeout(function() {
							$ul.trigger(d);
						}, opts.pauseDuration);
					}
				})
				.bind("next", function(e, b) {
					if ($ul.is(":animated")) return false;

					var numItems = (b) ? opts.scrollItemsButtons : opts.scrollItems;

					for (var a = 0; a < numItems; a++) {
						$ul.append($($items[lastItem]).clone());
						if (++lastItem  >= totalItems) lastItem  = 0;
						if (++firstItem >= totalItems) firstItem = 0;
					}
					if (opts.direction == "right" ||
						opts.direction == "left"
					) {
						var pos = 'left',
							mea = 'width',
							siz = itemWidth;
					} else {
						var pos = 'top',
							mea = 'height',
							siz = itemHeight;
					}
					var css = {},
						ani = {},
						cal = {};

					css[mea] = (siz * 0.1) + (siz * $("li", $ul).length);
					ani[pos] = -(siz * numItems);
					cal[pos] = 0;

					$ul.css(css)
						.animate(ani, {
							duration: opts.scrollSpeed,
							easing	: opts.scrollEffect,
							complete: function() {
								$ul.css(cal).find("li:lt("+numItems+")").remove();
							}
						}
					);

					//	auto-play
					$ul.trigger("pause").trigger("play", "next");
				})
				.bind("prev", function(e, b) {
					if ($ul.is(":animated")) return false;

					var numItems = (b) ? opts.scrollItemsButtons : opts.scrollItems;

					for (var a = 0; a < numItems; a++) {
						$ul.prepend($($items[firstItem]).clone());
						if (--firstItem < 0) firstItem = totalItems-1;
						if (--lastItem  < 0) lastItem  = totalItems-1;
					}
					if (opts.direction == "right" ||
						opts.direction == "left"
					) {
						var pos = 'left',
							mea = 'width',
							siz = itemWidth;
					} else {
						var pos = 'top',
							mea = 'height',
							siz = itemHeight;
					}

					var css = {},
						ani = {};

					css[pos] = -(siz * numItems);
					css[mea] = (siz * 0.1) + (siz * $("li", $ul).length);
					ani[pos] = 0;

					$ul.css(css)
						.animate(ani, {
							duration: opts.scrollSpeed,
							easing	: opts.scrollEffect,
							complete: function() {
								$ul.find("li:gt("+(opts.visibleItems-1)+")").remove();
							}
						}
					);

					//	auto-play
					$ul.trigger("pause").trigger("play", "prev");
				});

			if (opts.pauseOnHover) {
				$ul.hover(
					function() { $ul.trigger("pause"); },
					function() { $ul.trigger("play", direction); }
				);
			}

			//	via prev- en/of next-buttons
			if (opts.next != null || opts.prev != null) {
				if (opts.next != null) {
					opts.next.click(function() {
						$ul.trigger("next", true);
						return false;
					});
				}
				if (opts.prev != null) {
					opts.prev.click(function() {
						$ul.trigger("prev", true);
						return false;
					});
				}

			//	alleen via auto-play
			} else {
				if (opts.pauseDuration == 0) opts.pauseDuration = 2500;
			}

			//	via auto-play
			$ul.trigger("play", direction);
		});
	}
	$.fn.carouFredSel.defaults = {
		visibleItems		: 4,
		scrollItems			: 0,
		scrollItemsButtons	: 0,
		scrollEffect		: 'swing',
		scrollSpeed			: 500,
		next				: null,
		prev				: null,
		direction			: "right",
		pauseDuration		: 0,
		pauseOnHover		: false
	}
})(jQuery);






/***********************************************************************
 *
 * fixed header
 *
 **********************************************************************/

var bFixed = false;
var bThirdFixed = false;
function createFixedHeader () {
	var iThirdHeight = $('#third_menu').height();
	$(window).scroll(function() {

		if ($(window).scrollTop() >= 120) {
			if(!bFixed) {
				$('#header').addClass('header_fixed');
				$('#sub_menue').addClass('header_fixed');
				//$('#third_menu').addClass('header_fixed');
				bFixed = true;
			}
		}
		else{
			if(bFixed) {
				$('#header').removeClass('header_fixed');
				$('#sub_menue').removeClass('header_fixed');
				//$('#third_menu').removeClass('header_fixed');
				bFixed = false;
			}
		}

		if(bFixed && $(window).scrollTop() >= iThirdHeight - window.innerHeight) {
			console.log($(window).height(), window.innerHeight, iThirdHeight);
			$('#third_menu').css({
				'top' :		(Math.min(60, -(iThirdHeight - window.innerHeight - 260))) + 'px'
				,'position' :	'fixed'
			});
			bThirdFixed = true;
		}
		else {
			if(bThirdFixed) {
				$('#third_menu').css({
					'top' :		''
					,'position' :	''
				});
				bThirdFixed = false;
			}
		}
		
	})
	.trigger('scroll');
}










/***********************************************************************
 *
 * MAW-Menü
 *
 **********************************************************************/
var aMainMenu		= [];
var iActiveItem		= -1;
var iLastActiveItem	= -1;
var iMouseOutCnt	= 0;
var iMouseX = 0;
var iMouseY = 0;
var bSubOpen = false;
function getMainMenuStructure() {
	var iMenuId = 0;
	var bAnyActiveItem = false;
	$('li.main-menu').each(function() {
		var me 		= $(this);
		var myAnker = me.find('a');
		var myPic	= me.find('img');
		// store date in array
		aMainMenu[iMenuId] = {
			sName:		myPic.attr('alt')
			,sUrl:		myAnker.attr('href')
			,bActive:	me.hasClass('active')
			,oElement:	me
			,oPic:		myPic
		};

		// determine if there is any active item
		bAnyActiveItem |= aMainMenu[iMenuId].bActive;
		if(aMainMenu[iMenuId].bActive) {
			iActiveItem = iMenuId;
		}
		// setup events
		me.bind('mouseover',	{iId:iMenuId}, handleMainOver)
			.bind('click',		{iId:iMenuId}, handleMainClick);
		iMenuId++;
	});

	// if none is active, it should be home!
	if(!bAnyActiveItem) {
		aMainMenu[0].bActive = true;
		aMainMenu[0].oElement.trigger('mouseover');
		iActiveItem = 0;
	}
	getSubmenuStructure();
}




function getSubmenuStructure() {
	var iMenuId = 0;
	$('ul.submenu').each(function() {
		var me 		= $(this);
		// store date in array
		aMainMenu[iMenuId].oSubMenu = me;
		aMainMenu[iMenuId].iSubItems = me.find('li').length;
		iMenuId++;
		me.css('display','none');
	});
}




function createMawMenu() {
	getMainMenuStructure();

	// do some inits
	$(document).mousemove( function(e) {
	   iMouseX = e.pageX;
	   iMouseY = e.pageY;
	 });
	window.setInterval(handleMousePosition,500);
	window.setTimeout(function(){
		var aOffset	= aMainMenu[iActiveItem].oElement.offset();
		var iWidth	= aMainMenu[iActiveItem].oElement.width();
		var iDestX	= aOffset.left + iWidth / 2 - 19;
		$('#sun').css('left', iDestX+'px').fadeIn('slow');
	} ,500);
	$('#sub_menue').css('opacity', 0.85);
	$(window).resize(function(){
		moveSun(iLastActiveItem);
	});
}


function handleMainOver(o) {
	iMouseOutCnt = 0;
	var iId = o.data.iId;

	// supress double hover's
	if(iId == iLastActiveItem && bSubOpen) {
		return;
	}
	iLastActiveItem = iId;


	for(var i in aMainMenu) {
		aMainMenu[i].oPic.attr('src','/media/template/global_v2/header/' + (i==iId?'':'in') +'active/' + aMainMenu[i].sName.toLowerCase() + '.png');
	}
	moveSun(iId);



	// create submenu


	// make empty menus show fast:
	if(aMainMenu[iId].iSubItems==1) {
		$('#sub_menue').clearQueue().stop().animate({height: 1}, 400, 'swing');
		$('#submenu_items').clearQueue().stop().fadeOut(200);
	}

	// change content animated
	else {
		$('#submenu_items').clearQueue().stop().fadeOut(200,function(){
			for(var i in aMainMenu) {
				aMainMenu[i].oSubMenu.css('display',(i==iId?'block':'none'));
			}
			var h = $(this).height();
			$('#sub_menue').clearQueue().stop().animate({height: h+30}, 400, 'swing');
			$(this).fadeIn(300, function(){
				$(this).css('opacity',1);
			})
		});
	}

	// show submenue
	fadeinSubmenu();
}

function handleMainClick(o) {
	var iId = o.data.iId;
	if(aMainMenu[iId].sUrl) {
		document.location.href = aMainMenu[iId].sUrl;
	}
}

function resetMenu() {
	for(var i in aMainMenu) {
		aMainMenu[i].oPic.attr('src','/media/template/global_v2/header/' + (aMainMenu[i].bActive?'':'in') +'active/' + aMainMenu[i].sName.toLowerCase() + '.png');
	}
	moveSun(iActiveItem);
	fadeoutSubmenu();
}

function handleMousePosition(o) {

	// consider fixed menu
	var iMyMouseY = iMouseY;
	if(bFixed) {
		iMyMouseY = iMouseY - $(window).scrollTop() + 115;
	}

	// consider actual menu height
	var iMenuHeight = $('#sub_menue').height();

	// if mouse out of menu than count time
	if(iMyMouseY > (175 + iMenuHeight) || iMyMouseY < 100) {
		iMouseOutCnt += 500;
	}

	// if mouse over menu than reset time
	if(iMyMouseY < (140 + iMenuHeight) && iMyMouseY > 125) {
		iMouseOutCnt = 0;
	}

	// if time counter over 1 sec than reset menu
	if(iMouseOutCnt >= 1000 || iMyMouseY > (200 + iMenuHeight)) {
		resetMenu();
		iMouseOutCnt = 0;
	}
}

function moveSun(iPos) {
	if(typeof aMainMenu[iPos] != 'object') {
		return;
	}
	var aOffset	= aMainMenu[iPos].oPic.offset();
	var iWidth	= aMainMenu[iPos].oPic.width();
	var iDestX	= aOffset.left + iWidth / 2 - 19;
	$('#sun').css('opacity','1').clearQueue().stop().animate({left:	iDestX}, 900, 'swing');
}

function fadeoutSubmenu() {
	iLastActiveItem	= iActiveItem;
	$('#sub_menue').animate({height:0}, 600, 'swing');
	$('#submenu_items').fadeOut(400);
	bSubOpen = false;
}

function fadeinSubmenu() {
	bSubOpen = true;
}





/***********************************************************************
 *
 * third level menu
 *
 **********************************************************************/

function m3MenuSetup() {
	var oActiveItem = $('#m3-active');
	if(oActiveItem.length == 1) {
		oActiveItem.css('top',parseInt($('#m3-active').parent().position()['top'])+4+'px');
		oActiveItem.css('height',parseInt($('#m3-active').parent().height())+10+'px');
	}
	// rotate specials
	var oSpecials = $('#specials li');
	oSpecials.css('display','none');
	var iActiveSpecial = -1;
	function rotateSubmenuSpecials() {
		if(iActiveSpecial > -1) {
			$(oSpecials[iActiveSpecial]).fadeOut(300, function(){
				iActiveSpecial ++;
				if(iActiveSpecial >= oSpecials.length) {
					iActiveSpecial = 0;
				}
				$(oSpecials[iActiveSpecial]).fadeIn(300, function(){

				});
				$('#specials').animate({'height': $(oSpecials[iActiveSpecial]).height()+'px'}, 300);
			});
		}
		else {
			iActiveSpecial = Math.floor(Math.random() * (oSpecials.length));
			$(oSpecials[iActiveSpecial]).fadeIn(300, function(){
				$('#specials').animate({'height': $(oSpecials[iActiveSpecial]).height()+'px'}, 300);
			});
		}
	}
	window.setInterval(rotateSubmenuSpecials, 5000);
	rotateSubmenuSpecials();
}



/***********************************************************************
 *
 * MAW-Flights
 *
 **********************************************************************/

function setupFlightRotation() {

	// define routation
	$('#flights').carouFredSel({
		visibleItems		: 5,
		scrollItems			: 1,
		scrollItemsButtons	: 5,
		scrollEffect		: 'swing',
		scrollSpeed			: 500,
		direction			: 'right',
		next				: $('#flightbox_right'),
		prev				: $('#flightbox_left'),
		pauseDuration		: 2500,
		pauseOnHover		: true
	});

	// define click action
	$('#flights li').live('click', function(){
		document.location.href= '/german/angebote/flugangebote.html';
	});
}




/***********************************************************************
 *
 * IBE-Box
 *
 **********************************************************************/

var iIbeboxMouseOutside	= 0;
var iIbeboxActiveTab	= 0;

function setupIbebox() {
	for(var iCnt = 1; iCnt < 5; iCnt ++) {
		$('#ibebox_reiter_'+iCnt).bind('click', {iId:iCnt}, function(o){
			iIbeboxActiveTab = o.data.iId;
			for(var i = 1; i < 5; i ++)
			{
				if(o.data.iId == i) {
					$('#ibebox_reiter_'+i).addClass('ibr_active');
					$('#ibebox_content_'+i).addClass('ibc_active');
				}
				else {
					$('#ibebox_reiter_'+i).removeClass('ibr_active');
					$('#ibebox_content_'+i).removeClass('ibc_active');
				}
			}
		});
	}
	$('#ibebox_reiter_1').trigger('click');

}

/***********************************************************************
 *
 * standard js
 *
 **********************************************************************/

/* ------------------------
   common known variables
   (like constants)
   ------------------------ */

var sAjaxLoaderSrc = '/totoya/cache/core/clib/admin/framework/skin/default/media/ajaxloader.gif';
var sAjaxLoaderImg = '<img src="'+sAjaxLoaderSrc+'">';

/* ------------------------
    standard functions lib
   ------------------------ */

function log(o) {
	if(typeof console == "object"){
		if(typeof console.log == "function") {
			top.console.log(o);
		}
	}
}


// AJAX HANDLING
function convert2PostData(obj, aOuterElements) {
	var ret="";
	var seperator="";
	for(var i in obj) {
		if(typeof obj[i] == "function") {
			continue;
		}
		if(typeof obj[i] == "object" || typeof obj[i] == "array" ) {
			if(typeof aOuterElements != "array" && typeof aOuterElements != "object") {
				aOuterElements = new Array();
			}
			aOuterElements.push(i);
			ret += convert2PostData(obj[i], aOuterElements);
			aOuterElements.pop();
		} else {
			if(typeof aOuterElements == "array" || typeof aOuterElements == "object") {
				seperator="&";
				ret += seperator;
				for(var k in aOuterElements) {
					 if(k==0) {
						ret += aOuterElements[0];
					 }
					 else {
					 	ret += "["+aOuterElements[k]+"]";
					 }
				}
				ret += "["+i+"]";
			}
			else {
				ret += seperator;
				ret += i;
			}
			ret += '=' + encodeURIComponent(obj[i]);
			seperator="&";
		}
	}
	delete aOuterElements;
	return ret;
}



// CALLBACK HANDLING
function executeCallback(oCallbackObject, mAdditionalParam) {
	var ret;
	// no callback -> nothing to do!
	if(oCallbackObject == null) {
		return false;
	}

	// initialize CB Temp Store
	if(typeof oCallbackObject == "object") {
		var oTempStore = {
			"fFunction"	: oCallbackObject.fFunction,
			"oScope"	: oCallbackObject.oScope,
			"mParam"	: oCallbackObject.mParam
		};
		delete oCallbackObject;
		oCallbackObject = null;
	}
	else {
		var oTempStore = {
			"fFunction"	: oCallbackObject,
			"oScope"	: null,
			"mParam"	: {}
		};

	}

	// add additional param
	if(mAdditionalParam != null) {
		$.extend(oTempStore.mParam, mAdditionalParam);
	}

	// if there is a valid function -> execute callback!
	if(typeof oTempStore.fFunction == "function") {
		if(oTempStore.oScope) {
			ret = oTempStore.fFunction.apply(oTempStore.oScope, [oTempStore.mParam]);
		}
		else {
			ret = oTempStore.fFunction(oTempStore.mParam);
		}
	}
	return ret;
}


function cloneObject(oObj) {
	Object.prototype.clone = function() {
		var tmp = this.constructor();
		for(var i in this)  {
			if(typeof this[i] == "object" && this[i] != null) {
				tmp[i] = this[i].clone();
			}
			else {
		 		tmp[i] = this[i];
		 	}
		}
		return tmp;
	};
	var tmp = oObj.clone();
	delete Object.prototype.clone;
	return tmp;
}



/***********************************************************************
 * ENDE standard.js
 **********************************************************************/


/***********************************************************************
 *
 * IBE-Site
 *
 **********************************************************************/

// click
var oIbeItems = [];
function ibeSiteSetup() {
	function fIbeItemClick(e) {
		log(e.data);
		document.location.href = e.data.sUrl;
	}
	$('.ibe_result_item').each(
		function() {
			var oItem = {};
			me = $(this);
			oItem.sUrl = me.find('.data-link:first').attr('href');
			me.unbind().bind(
				'click'
				,oItem
				,fIbeItemClick
			);
			oIbeItems.push(oItem);
		}
	);
}

// sort
function doSort() {
	$.getScript('/media/template/global_v3/jquery.quicksand.min.js');
    var regions = $('#ibe_search_result ul:first ul');
    window.setTimeout(function(){
        regions.each(function(){
            var aReplace = $(this).find('li');
            var oTemp = aReplace[2];
            aReplace[2] = aReplace[0];
            aReplace[0] = oTemp;
            aReplace.splice(4,2);
            $(this).quicksand(
                 aReplace
                ,{
                    adjustHeight:    'auto'
                    ,duration:        3000
                    ,easing:        'swing'
                    ,attribute:
                        function(v) {
                            return $(v).find('.ibe_result_bold').text();
                        }

                }
            );
        });
    },2500);
}


// format prices
function getInEuros(fPrice) {
	var aPrice = fPrice.toString(10).split('.');
	//var sCents = parseInt(parseFloat('0.'+aPrice[1])*100).toString();
	var sEuros = '';
	var iLen = 0;
	for(i=aPrice[0].length-1; i>=0 ; i--) {
		if(iLen%3==0 && iLen>0) {
			sEuros = '.' + sEuros;
		}
		sEuros = aPrice[0].substr([i],1) + sEuros;
		iLen++;
	}
	return sEuros; //+ ',' + (sCents.length==1?'0':'') + sCents;
}


/***********************************************************************
 *
 * Website init
 *
 **********************************************************************/

function setupPage(){
	$('#servicetelefon').click(function(){
		document.location.href= '/german/kontakt.html';
	});
}


/***********************************************************************
 *
 * Website tooltips
 *
 **********************************************************************/

function tooltips(){
	$('.toolt-icon').live('mouseover', function(oEvent) {
		var sHtml = '<div class="toolt-text">'
				+ $(this).parent().find('.toolt-data').html()
			+ '</div>';
		$('body').append(sHtml);
		$('.toolt-text').offset({
			top: oEvent.pageY + 10
			, left: oEvent.pageX + 10
		});
	});

	$('.toolt-icon').live('mousemove', function(oEvent) {
		$('.toolt-text').offset({
			top: oEvent.pageY + 10
			, left: oEvent.pageX + 10
		});
	});

	$('.toolt-icon').live('mouseout', function() {
		$('.toolt-text').remove();
	});
}



/***********************************************************************
 *
 * Website init
 *
 **********************************************************************/

$(document).ready(function() {
	createFixedHeader();
	if ($('#main_menue').length > 0) {
		createMawMenu();
	}
	setupFlightRotation();
	setupIbebox();
	ibeSiteSetup();
	//cBadjieHotelsearch.init();
	//cSpecialsTeaser.init();
	//setupCatalogbox();
	//setupInfobox();
	//setupPage();
	m3MenuSetup();
	tooltips();
});

