function sendLiveSearch(inputId, project, subCatId){
	var inputId = inputId;
	var project = project;
	var subCatId = subCatId;
	
	this.doSearch = function(){
		$('#' + inputId).live('keyup', function(){
			if ($(this).val().length >= 3) {
				var searchValue = $(this).val();
				$.ajax({
					type: 'post',
					url: 'index.php?eID=leonhardt_dyn_content_check_scValue',
					data: 'project=' + project + '&subCatId=' + subCatId + '&searchValue=' + searchValue,
					beforeSend: function(){
						$('#' + inputId + '_selectionlist').html('<img src=\"/typo3conf/ext/leonhardt_dyn_content/img_shared/busy.gif\" width=\"16\" height=\"16\" />');
					},
					complete: function(){
					},
					success: function(html){
						$('#' + inputId + '_selectionlist').html('<div class=\"liveSearchResultWrap\">' + html + '</div>');
					}
				});
			}
		});
	};
	
	this.checkSelect = function(){
		$('#' + inputId).live('keyup', function(){
			if ($(this).val().length != 0) {
				$('select[name="subcategorievalue' + subCatId + '"]').attr("disabled", "disabled");
			} else {
				$('select[name="subcategorievalue' + subCatId + '"]').removeAttr("disabled");
			}
		});
	};
	$(document).ready(function() {
		$('.liveSearchValue').live('click', function() {
			$('#' + inputId).val($(this).html());
			$(this).remove();
		});
	});
}


function uploadImageFile(idUploadField, idUploadSpan, type, user, idDeleteLink){
	var idUploadField = idUploadField;
	var idUploadSpan = idUploadSpan;
	var type = type;
	var user = user;
	var idDeleteLink = idDeleteLink;
	
	
	var formatSize = function(bytes){
		var i = -1;                                    
        do {
            bytes = bytes / 1024;
            i++;  
        } while (bytes > 99);
        
        return Math.max(bytes, 0.1).toFixed(1) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i];
	};
	
	this.doUpload = function(){		
		url = 'index.php?eID=leonhardt_dyn_content_upload_image';
		new qq.FileUploader({
			// pass the dom node (ex. $(selector)[0] for jQuery users)
			element: document.getElementById(idUploadField),
			// path to server-side upload script
			action: url,
			multiple: false,
			// additional data to send, name-value pairs
			params: {
				type: type,
				user: user
			},

			// validation
			// ex. ['jpg', 'jpeg', 'png', 'gif'] or []
			allowedExtensions: [],
			// each file size limit in bytes
			// this option isn't supported in all browsers
			sizeLimit: 0, // max size
			minSizeLimit: 0, // min size

			// set to true to output server response to console
			debug: true,

			// events
			// you can return false to abort submit
			onSubmit: function(id, fileName){
				$('#' + idUploadSpan).text('Datei ' + fileName + ' wird versendet.');
			},
			onProgress: function(id, fileName, loaded, total){
				var html = '<img src="/typo3conf/ext/leonhardt_dyn_content/res/fileuploader/loading.gif" alt="" />'
					+ Math.round(loaded / total * 100)
					+ '% von ' 
					+ formatSize(total)
					+ ' übertragen.';
				$('#' + idUploadSpan).html(html);
			},
			onComplete: function(id, fileName, responseJSON){
				var response = JSON.stringify(responseJSON);
				response = JSON.parse(response);
				if(response['success']){
					$('#' + idUploadSpan).html(fileName + ' wurde hochgeladen.');
				}
				$('#imgOrgName_c_1').val(fileName);
				$('#imgSrc_c_1').val(response['filename']['detail']);
				$('#imgZoomSrc_c_1').val(response['filename']['zoom']);
				$('#teaserImg').val(response['filename']['teaser']);
				$('#teaserBigImg').val(response['filename']['bigteaser']);
			},
			onCancel: function(id, fileName){
				$('#' + idUploadSpan).text('Upload abgebrochen.');
			},

			messages: {
				// error messages, see qq.FileUploaderBasic for content
			},
			showMessage: function(message){ 
				//alert(message);
				$('#' + idUploadSpan).html(message);
			}
		});
		
		/*
		new AjaxUpload(idUploadField, {
			action: url,
			name: type,
			data: {
				type: type,
				user: user
			},
			autoSubmit: true,
			onSubmit: function(file, extension){
				if (/^(jpg|png|jpeg|gif)$/i.test(extension)) {
					this.setData({
						type: type,
						user: user
					});
					$('#' + idUploadSpan).busy({
						img: '/typo3conf/ext/leonhardt_dyn_content/img_shared/busy.gif',
						alt: 'Bitte warten.'
					});
				} else {
					$('#' + idUploadSpan).html('Bitte Bilddatei wählen.');
					return false;
				}
			},
			onComplete: function(file, response){
				responseArr = response.split(";");
				if (responseArr[0] == 'error') {
					text = responseArr[1];
					filename = '';
				} else {
					text = file+' wurde hochgeladen.';
					filenameArr = responseArr;
				}
				
				$('#' + idUploadSpan).html(text);
				$('#imgSrc_c_1').val(filenameArr[2]);
				$('#imgZoomSrc_c_1').val(filenameArr[3]);
				$('#teaserImg').val(filenameArr[0]);
				$('#teaserBigImg').val(filenameArr[1]);
				
				$('#' + idUploadSpan).busy("hide");
			}
		});*/
	};
	
	this.doDelete = function(){
		$('#' + idDeleteLink).live('click', function(){
			if ($('#imgSrc_c_1').val() == '') {
				return false;
			}
			var filesToDelete = $('#imgSrc_c_1').val() + ';' + $('#imgZoomSrc_c_1').val() + ';' + $('#teaserImg').val() + ';' + $('#teaserBigImg').val();
			$.ajax({
				type: 'post',
				url: 'index.php?eID=leonhardt_dyn_content_delete_file',
				data: 'mode=image&filesToDelete=' + filesToDelete,
				beforeSend: function(){
					$('#' + idUploadSpan).busy({
						img: '/typo3conf/ext/leonhardt_dyn_content/img_shared/busy.gif',
						alt: 'Bitte warten.',
						title: 'Bitte warten.'
					});
				},
				complete: function(){
				},
				success: function(html){
					$('#' + idUploadSpan).html(html);
					$('#imgOrgName_c_1').val('');
					$('#imgSrc_c_1').val('');
					$('#imgZoomSrc_c_1').val('');
					$('#teaserImg').val('');
					$('#teaserBigImg').val('');
					
					$('#' + idUploadSpan).busy("hide");
				}
			});
			
			return false;
		});
	};
}


function uploadAlternativeImageFile(idUploadField, idUploadSpan, type, user, idDeleteLink){
	var idUploadField = idUploadField;
	var idUploadSpan = idUploadSpan;
	var type = type;
	var user = user;
	var idDeleteLink = idDeleteLink;
	
	
	var formatSize = function(bytes){
		var i = -1;                                    
        do {
            bytes = bytes / 1024;
            i++;  
        } while (bytes > 99);
        
        return Math.max(bytes, 0.1).toFixed(1) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i];
	};
	
	this.doUpload = function(){
		url = 'index.php?eID=leonhardt_dyn_content_upload_alternative_image';
		new qq.FileUploader({
			// pass the dom node (ex. $(selector)[0] for jQuery users)
			element: document.getElementById(idUploadField),
			// path to server-side upload script
			action: url,
			multiple: false,
			// additional data to send, name-value pairs
			params: {
				type: type,
				user: user
			},

			// validation
			// ex. ['jpg', 'jpeg', 'png', 'gif'] or []
			allowedExtensions: [],
			// each file size limit in bytes
			// this option isn't supported in all browsers
			sizeLimit: 0, // max size
			minSizeLimit: 0, // min size

			// set to true to output server response to console
			debug: true,

			// events
			// you can return false to abort submit
			onSubmit: function(id, fileName){
				$('#' + idUploadSpan).text('Datei ' + fileName + ' wird versendet.');
			},
			onProgress: function(id, fileName, loaded, total){
				var html = '<img src="/typo3conf/ext/leonhardt_dyn_content/res/fileuploader/loading.gif" alt="" />'
					+ Math.round(loaded / total * 100)
					+ '% von ' 
					+ formatSize(total)
					+ ' übertragen.';
				$('#' + idUploadSpan).html(html);
			},
			onComplete: function(id, fileName, responseJSON){
				var response = JSON.stringify(responseJSON);
				response = JSON.parse(response);
				if(response['success']){
					$('#' + idUploadSpan).html(fileName + ' wurde hochgeladen.');
				}
				$('#imgAltOrgName_c_1').val(fileName);
				$('#imgAlternativeSrc_c_1').val(response['filename']['detail']);
				$('#imgAlternativeZoomSrc_c_1').val(response['filename']['zoom']);
			},
			onCancel: function(id, fileName){
				$('#' + idUploadSpan).text('Upload abgebrochen.');
			},

			messages: {
				// error messages, see qq.FileUploaderBasic for content
			},
			showMessage: function(message){ 
				$('#' + idUploadSpan).html(message);
			}
		});
		
		/*
		new AjaxUpload(idUploadField, {
			action: url,
			name: type,
			data: {
				type: type,
				user: user
			},
			autoSubmit: true,
			onSubmit: function(file, extension){
				if (/^(jpg|png|jpeg|gif)$/i.test(extension)) {
					this.setData({
						type: type,
						user: user
					});
					$('#' + idUploadSpan).busy({
						img: '/typo3conf/ext/leonhardt_dyn_content/img_shared/busy.gif',
						alt: 'Bitte warten.',
						title: 'Bitte warten.'
					});
				} else {
					$('#' + idUploadSpan).html('Bitte Bilddatei wählen.');
					return false;
				}
			},
			onComplete: function(file, response){
				responseArr = response.split(";");
				if (responseArr[0] == 'error') {
					text = responseArr[1];
					filename = '';
				} else {
					text = file+' wurde hochgeladen.';
					filenameArr = responseArr;
				}
				
				$('#' + idUploadSpan).html(text);
				$('#imgAlternativeSrc_c_1').val(filenameArr[0]);
				$('#imgAlternativeZoomSrc_c_1').val(filenameArr[1]);
				
				$('#' + idUploadSpan).busy("hide");
			}
		});*/
	};
	
	this.doDelete = function(){
		$('#' + idDeleteLink).live('click', function(){
			if ($('#imgAlternativeSrc_c_1').val() == '') {
				return false;
			}
			var filesToDelete = $('#imgAlternativeSrc_c_1').val() + ';' + $('#imgAlternativeZoomSrc_c_1').val();
			$.ajax({
				type: 'post',
				url: 'index.php?eID=leonhardt_dyn_content_delete_file',
				data: 'mode=image&filesToDelete=' + filesToDelete,
				beforeSend: function(){
					$('#' + idUploadSpan).busy({
						img: '/typo3conf/ext/leonhardt_dyn_content/img_shared/busy.gif',
						alt: 'Bitte warten.',
						title: 'Bitte warten.'
					});
				},
				complete: function(){
				},
				success: function(html){
					$('#' + idUploadSpan).html(html);
					$('#imgAltOrgName_c_1').val('');
					$('#imgAlternativeSrc_c_1').val('');
					$('#imgAlternativeZoomSrc_c_1').val('');
					
					$('#' + idUploadSpan).busy("hide");
				}
			});
			
			return false;
		});
	};
}


function uploadDownloadFile(idUploadField, idUploadSpan, dlId, idDeleteLink, errorMsg, idAddDeleteLink){
	var idUploadField = idUploadField;
	var idUploadSpan = idUploadSpan;
	var idDeleteLink = idDeleteLink;
	var idAddDeleteLink = idAddDeleteLink;
	var errorMsg = errorMsg;
	
	var formatSize = function(bytes){
		var i = -1;                                    
        do {
            bytes = bytes / 1024;
            i++;  
        } while (bytes > 99);
        
        return Math.max(bytes, 0.1).toFixed(1) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i];
	};
	
	this.doUpload = function(){
		url = 'index.php?eID=leonhardt_dyn_content_upload_download_file';
		new qq.FileUploader({
			// pass the dom node (ex. $(selector)[0] for jQuery users)
			element: document.getElementById(idUploadField),
			// path to server-side upload script
			action: url,
			multiple: false,
			// additional data to send, name-value pairs
			params: {
				type: 'download'
			},

			// validation
			// ex. ['jpg', 'jpeg', 'png', 'gif'] or []
			allowedExtensions: [],
			// each file size limit in bytes
			// this option isn't supported in all browsers
			sizeLimit: 0, // max size
			minSizeLimit: 0, // min size

			// set to true to output server response to console
			debug: true,

			// events
			// you can return false to abort submit
			onSubmit: function(id, fileName){
				$('.uploadedFile_' + dlId).text('Datei ' + fileName + ' wird versendet.');
			},
			onProgress: function(id, fileName, loaded, total){
				var html = '<img src="/typo3conf/ext/leonhardt_dyn_content/res/fileuploader/loading.gif" alt="" />'
					+ Math.round(loaded / total * 100)
					+ '% von ' 
					+ formatSize(total)
					+ ' übertragen.';
				$('.uploadedFile_' + dlId).html(html);
			},
			onComplete: function(id, fileName, responseJSON){
				var response = JSON.stringify(responseJSON);
				response = JSON.parse(response);
				if(response['success']){
					$('.uploadedFile_' + dlId).text(fileName + ' wurde hochgeladen.');
				}
				$('#inputOrgFilename_' + dlId).val(fileName);
				$('#inputFilename_' + dlId).val(response['filename']['download']);
			},
			onCancel: function(id, fileName){
				$('.uploadedFile_' + dlId).text('Upload abgebrochen.');
			},

			messages: {
				// error messages, see qq.FileUploaderBasic for content
			},
			showMessage: function(message){
				$('.uploadedFile_' + dlId).html(message);
			}
		});
		
		/*
		new AjaxUpload(idUploadField, {
			action: url,
			name: 'download',
			data: {
				type: 'download'
			},
			autoSubmit: true,
			onSubmit: function(file, extension){
				$('#' + idUploadSpan).busy({
					img: '/typo3conf/ext/leonhardt_dyn_content/img_shared/busy.gif',
					alt: 'Bitte warten.',
					title: 'Bitte warten.'
				});
			},
			onComplete: function(file, response){
				responseArr = response.split(";");
				if (responseArr[0] == 'error') {
					text = responseArr[1];
					filename = '';
				} else {
					text = file+' wurde hochgeladen.';
					filenameArr = responseArr;
				}
				
				$('.uploadedFile_' + dlId).text(text);
				$('#inputFilename_' + dlId).val(filenameArr[0]);
				
				$('#' + idUploadSpan).busy("hide");
			}
		});*/
		
		$(document).ready(function(){
			$('#label_' + dlId).rules('add', {
				required: function(value, element) {
					var reg = new RegExp('/s');
					//if (reg.test(value) || value == ''){
					if ($('#inputFilename_' + dlId).val() != '' && $('#inputFilename_' + dlId).val() != ' '){
						return true;
					}else{
						return false;
					}
					//return ($('#inputFilename_' + dlId).val() != '' || $('#inputFilename_' + dlId).val() != ' ');
				},
				messages: {
					required: errorMsg
				}
			});
		});
	};
	
	
	this.doDelete = function(){
		$('#' + idDeleteLink).live('click', function(){
			if ($('#inputFilename_' + dlId).val() == '') {
				return false;
			}
			var filesToDelete = $('#inputFilename_' + dlId).val();
			$.ajax({
				type: 'post',
				url: 'index.php?eID=leonhardt_dyn_content_delete_file',
				data: 'mode=download&filesToDelete=' + filesToDelete,
				beforeSend: function(){
					$('#' + idUploadSpan).busy({
						img: '/typo3conf/ext/leonhardt_dyn_content/img_shared/busy.gif',
						alt: 'Bitte warten.',
						title: 'Bitte warten.'
					});
				},
				complete: function(){
				},
				success: function(html){
					$('.uploadedFile_' + dlId).html(html);
					$('#inputOrgFilename_' + dlId).val('');
					$('#inputFilename_' + dlId).val('');
					
					$('#' + idUploadSpan).busy("hide");
				}				
			});
			
			$('#label_' + dlId).rules('remove');
			
			return false;
		});
	};
	
	this.doAddDelete = function(){
		$('#' + idAddDeleteLink).live('click', function(){
			if ($('#inputFilename_' + dlId).val() == '') {
				$('#addedDownload_' + dlId).empty();
				return false;
			}
			var filesToDelete = $('#inputFilename_' + dlId).val();
			$.ajax({
				type: 'post',
				url: 'index.php?eID=leonhardt_dyn_content_delete_file',
				data: 'mode=download&filesToDelete=' + filesToDelete,
				beforeSend: function(){
					$('#' + idUploadSpan).busy({
						img: '/typo3conf/ext/leonhardt_dyn_content/img_shared/busy.gif',
						alt: 'Bitte warten.',
						title: 'Bitte warten.'
					});
				},
				complete: function(){
				},
				success: function(html){
					$('.uploadedFile_' + dlId).html(html);
					$('#inputOrgFilename_' + dlId).val('');
					$('#inputFilename_' + dlId).val('');
					
					$('#addedDownload_' + dlId).empty();
					
					$('#' + idUploadSpan).busy("hide");
				}				
			});
			$('#label_' + dlId).rules('remove');
			
			return false;
		});
	};
}


function addDownload(addContainerId, addLinkId){
	var addContainerId = addContainerId;
	var addLinkId = addLinkId;
	
	this.add = function(){
		$(document).ready(function(){
			$('#' + addLinkId).live('click', function(){
				$.ajax({
					type: 'post',
					url: 'index.php?eID=leonhardt_dyn_content_add_download',
					data: 'addContainerId=' + addContainerId,
					beforeSend: function(){
					},
					complete: function(){
					},
					success: function(html){
						$('#' + addContainerId).append(html);
					}
				});
				return false;
			});
		});
	};
	
}


function dynamicFormValue(){

	this.showContactHTML = function(section){
		$('#dynamicBtnEnable.' + section).live('click', function(){
			$('#dynamicBtnEnable.' + section).toggle('slow');
			$('#dynamicBtnDisable.' + section).toggle('slow');
			//			$('#contactTextWrap').toggle('slow');
			$('#contactTextWrap').fadeIn('slow');
		});
		$('#dynamicBtnDisable.' + section).live('click', function(){
		
			$('#dynamicBtnEnable.' + section).toggle('slow');
			$('#dynamicBtnDisable.' + section).toggle('slow');
			//			$('#contactTextWrap').toggle('slow');
			$('#contactTextWrap').fadeOut('slow');
			
			tmpFilesToDelete = $('#inputFilename_l_1').val();
			doDelete(tmpFilesToDelete, 'download');
			
			$('#headline_m_1').val('');
			$('.cke_show_borders p').empty();
			
			
			$('.uploadedFile_l_1').html(' ');
			$('#addedDownloads_l_1').html(' ');
			$('#inputFilename_l_1').val('');
			$('#label_l_1').val('');
			CKEDITOR.instances.text_m_1.setData('');
			
			$('#url_l_2').val('mailto:');
			$('#label_l_2').val('E-Mail');
			$('#url_l_3').val('http://');
			$('#label_l_3').val('zur Stiftung');
			
		});
		$('#dynamicBtnDisable.' + section).confirm({
			msg: '<span class="cLabel">ACHTUNG! Alle Inhalte werden entfernt. Sind Sie sicher, dass Sie die Box schließen möchten?</span>',
			wrapper: '<div class="confirmationWrap"></div>',
			buttons: {
				ok: 'Ja',
				cancel: 'Nein',
				separator: '  '
			}
		});
	};
	
	this.showImageHTML = function(section){
		$('#dynamicBtnEnable.' + section).live('click', function(){
			$('#dynamicBtnEnable.' + section).toggle('slow');
			$('#dynamicBtnDisable.' + section).toggle('slow');
			//			$('#imageWrap').toggle('slow');
			$('#imageWrap').fadeIn('slow');
		});
		$('#dynamicBtnDisable.' + section).live('click', function(){
			$('#dynamicBtnEnable.' + section).toggle('slow');
			$('#dynamicBtnDisable.' + section).toggle('slow');
			
			
			tmpFilesToDelete = $('#imgSrc_c_1').val() + ';' + $('#imgZoomSrc_c_1').val() + ';' + $('#teaserImg').val() + ';' + $('#teaserBigImg').val() + ';' + $('#imgAlternativeSrc_c_1').val() + ';' + $('#imgAlternativeZoomSrc_c_1').val();
			doDelete(tmpFilesToDelete, 'image');
			
			$('#imgSrcFile_1').html(' ');
			$('#imgSrc_c_1').val('');
			$('#imgZoomSrc_c_1').val('');
			$('#teaserImg').val('');
			$('#teaserBigImg').val('');
			$('#imgAlternativeSrcFile_1').html(' ');
			$('#imgAlternativeSrc_c_1').val('');
			$('#imgAlternativeZoomSrc_c_1').val('');
			
			//			$('#imageWrap').toggle('slow');
			$('#imageWrap').fadeOut('slow');
		});
		$('#dynamicBtnDisable.' + section).confirm({
			msg: '<span class="cLabel">ACHTUNG! Alle Inhalte werden entfernt. Sind Sie sicher, dass Sie die Box schließen möchten?</span>',
			wrapper: '<div class="confirmationWrap"></div>',
			buttons: {
				ok: 'Ja',
				cancel: 'Nein',
				separator: '  '
			}
		});
	};
	
	
	
	var doDelete = function(filesToDelete, mode){
		var filesToDelete = filesToDelete;
		$.ajax({
			type: 'post',
			url: 'index.php?eID=leonhardt_dyn_content_delete_file',
			data: 'mode=' + mode + '&filesToDelete=' + filesToDelete,
			beforeSend: function(){
			},
			complete: function(){
			},
			success: function(html){
			}
		});
	};
}

function preview(formName, project, userId){
	var formName = formName;
	
	this.preview = function(){
		$('#previewTeaserText').live('click', function(){

			if(($("#teaserText").val() != "") && ($("#teaserHeadline").val() != "")){
				json = getJson();
				$.ajax({
					type: 'post',
					url: 'index.php?eID=leonhardt_dyn_content_preview',
					data: 'mode=previewTeaserText&project=' + project + '&userid=' + userId + '&json=' + json,
					beforeSend: function(){
						showSpinner('Kurztextvorschau wird erstellt.');
					},
					complete: function(){
					},
					success: function(html){
						showPreview(html);
					}
				});
			}else if(($("#teaserText").val() == "") && ($("#teaserHeadline").val() != "")){
				$('.error').html("<label for='teaserText' class='error'>Bitte geben Sie einen Teasertext ein.</label>");
			}else if(($("#teaserText").val() != "") && ($("#teaserHeadline").val() == "")){
				$('.error').html("<label for='teaserHeadline' class='error'>Bitte geben Sie eine Teaserüberschrift ein.</label>");
			}else{
				$('.error').html("<label for='teaserHeadline' class='error'>Bitte geben Sie einen Teaserüberschrift ein.</label>\n <label for='teaserText' class='error'>Bitte geben Sie einen Teasertext ein.</label>");
				$('.error').css("display", "block");
			}
			
			return false;
		});
		
		
		$('#previewMainText').live('click', function(){
			var editorContent = CKEDITOR.instances.text_c_1.getData();
			var editorContentArr = new Array();
			editorContentArr[0] = new Object();
			editorContentArr[0]['text_c_1'] = replaceForPreviewHTML(editorContent);
			var editorContentJson = getEditorContentJson(editorContentArr);
//			alert(editorContentJson);
			json = getJson();
			$.ajax({
				type: 'post',
				url: 'index.php?eID=leonhardt_dyn_content_preview',
				data: 'mode=previewMainText&project=' + project + '&userid=' + userId + '&json=' + json + '&editorContent=' + editorContentJson,
				beforeSend: function(){
					showSpinner('Haupttextvorschau wird erstellt.');
				},
				complete: function(){
				},
				success: function(html){
					$('.error').empty();
					showPreview(html);
				}
			});
			return false;
		});
		
		$('#previewDefaultContact').live('click', function(){
			
			if($('#showStandardContactBox').prop("checked") == true && $('#selectContact').val() != "noSelected"){
				json = getDefaultContactSelectionJson();
				$.ajax({
					type: 'post',
					url: 'index.php?eID=leonhardt_dyn_content_preview',
					data: 'mode=previewDefaultContact&project=' + project + '&userid=' + userId + '&json=' + json,
					beforeSend: function(){
						showSpinner('Infoboxvorschau wird erstellt.');
					},
					complete: function(){
					},
					success: function(html){
						$('#showContactError').empty();
						showPreview(html);
					}
				});
			}else if($('#showStandardContactBox').prop("checked") == true && $('#selectContact').val() == "noSelected"){
				$('#showContactError').html("Bitte wählen Sie einen Kontakt");
			}else{
				$('#showContactError').html("Die Standard-Kontaktbox ist nicht ausgewählt,<br /> die Preview steht nicht zur Verfügung.");
			}

			return false;
		});
		
		$('#previewImage').live('click', function(){
			var editorContent = CKEDITOR.instances.text_c_1.getData();
			var editorContentArr = new Array();
			editorContentArr[0] = new Object();
			editorContentArr[0]['text_c_1'] = replaceForPreviewHTML(editorContent);
			editorContent = CKEDITOR.instances.text_m_1.getData();
			editorContentArr[1] = new Object();
			editorContentArr[1]['text_m_1'] = replaceForPreviewHTML(editorContent);
			var editorContentJson = getEditorContentJson(editorContentArr);
			
			json = getJson();
			$.ajax({
				type: 'post',
				url: 'index.php?eID=leonhardt_dyn_content_preview',
				data: 'mode=previewImage&project=' + project + '&userid=' + userId + '&json=' + json + '&editorContent=' + editorContentJson,
				beforeSend: function(){
					showSpinner('Bildervorschau wird erstellt.');
				},
				complete: function(){
				},
				success: function(html){
					showPreview(html);
				}
			});
			return false;
		});
		
		$('#previewContact').live('click', function(){
			var editorContent = CKEDITOR.instances.text_m_1.getData();
			var editorContentArr = new Array();
			editorContentArr[0] = new Object();
			editorContentArr[0]['text_m_1'] = replaceForPreviewHTML(editorContent);
			var editorContentJson = getEditorContentJson(editorContentArr);
			
			json = getJson();
			$.ajax({
				type: 'post',
				url: 'index.php?eID=leonhardt_dyn_content_preview',
				data: 'mode=previewContact&project=' + project + '&userid=' + userId + '&json=' + json + '&editorContent=' + editorContentJson,
				beforeSend: function(){
					showSpinner('Infoboxvorschau wird erstellt.');
				},
				complete: function(){
				},
				success: function(html){
					showPreview(html);
				}
			});
			return false;
		});
		
		$('#previewComplete').live('click', function(){
			var editorContent = CKEDITOR.instances.text_c_1.getData();
			var editorContentArr = new Array();
			editorContentArr[0] = new Object();
			editorContentArr[0]['text_c_1'] = replaceForPreviewHTML(editorContent);
			editorContent = CKEDITOR.instances.text_m_1.getData();
			editorContentArr[1] = new Object();
			editorContentArr[1]['text_m_1'] = replaceForPreviewHTML(editorContent);
			var editorContentJson = getEditorContentJson(editorContentArr);
			
			json = getJson();
			$.ajax({
				type: 'post',
				url: 'index.php?eID=leonhardt_dyn_content_preview',
				data: 'mode=previewComplete&project=' + project + '&userid=' + userId + '&json=' + json + '&editorContent=' + editorContentJson,
				beforeSend: function(){
					showSpinner('Vorschau wird erstellt.');
				},
				complete: function(){
				},
				success: function(html){
					showPreview(html);
				}
			});
			return false;
		});
	};
	
	var replaceForPreviewText = function(str){
		var replace = new Array(/&nbsp;/g, /&iexcl;/g, /&cent;/g, /&pound;/g, /&curren;/g, /&yen;/g, /&brvbar;/g, /&sect;/g, /&uml;/g, /&copy;/g, /&ordf;/g, /&laquo;/g, /&not;/g, /&shy;/g, /&reg;/g, /&macr;/g, /&deg;/g, /&plusmn;/g, /&sup2;/g, /&sup3;/g, /&acute;/g, /&micro;/g, /&para;/g, /&middot;/g, /&cedil;/g, /&sup1;/g, /&ordm;/g, /&raquo;/g, /&frac14;/g, /&frac12;/g, /&frac34;/g, /&iquest;/g, /&Agrave;/g, /&Aacute;/g, /&Acirc;/g, /&Atilde;/g, /&Auml;/g, /&Aring;/g, /&AElig;/g, /&Ccedil;/g, /&Egrave;/g, /&Eacute;/g, /&Ecirc;/g, /&Euml;/g, /&Igrave;/g, /&Iacute;/g, /&Icirc;/g, /&Iuml;/g, /&ETH;/g, /&Ntilde;/g, /&Ograve;/g, /&Oacute;/g, /&Ocirc;/g, /&Otilde;/g, /&Ouml;/g, /&times;/g, /&Oslash;/g, /&Ugrave;/g, /&Uacute;/g, /&Ucirc;/g, /&Uuml;/g, /&Yacute;/g, /&THORN;/g, /&szlig;/g, /&agrave;/g, /&aacute;/g, /&acirc;/g, /&atilde;/g, /&auml;/g, /&aring;/g, /&aelig;/g, /&ccedil;/g, /&egrave;/g, /&eacute;/g, /&ecirc;/g, /&euml;/g, /&igrave;/g, /&iacute;/g, /&icirc;/g, /&iuml;/g, /&eth;/g, /&ntilde;/g, /&ograve;/g, /&oacute;/g, /&ocirc;/g, /&otilde;/g, /&ouml;/g, /&divide;/g, /&oslash;/g, /&ugrave;/g, /&uacute;/g, /&ucirc;/g, /&uuml;/g, /&yacute;/g, /&thorn;/g, /&yuml;/g, /&fnof;/g, /&Alpha;/g, /&Beta;/g, /&Gamma;/g, /&Delta;/g, /&Epsilon;/g, /&Zeta;/g, /&Eta;/g, /&Theta;/g, /&Iota;/g, /&Kappa;/g, /&Lambda;/g, /&Mu;/g, /&Nu;/g, /&Xi;/g, /&Omicron;/g, /&Pi;/g, /&Rho;/g, /&Sigma;/g, /&Tau;/g, /&Upsilon;/g, /&Phi;/g, /&Chi;/g, /&Psi;/g, /&Omega;/g, /&alpha;/g, /&beta;/g, /&gamma;/g, /&delta;/g, /&epsilon;/g, /&zeta;/g, /&eta;/g, /&theta;/g, /&iota;/g, /&kappa;/g, /&lambda;/g, /&mu;/g, /&nu;/g, /&xi;/g, /&omicron;/g, /&pi;/g, /&rho;/g, /&sigmaf;/g, /&sigma;/g, /&tau;/g, /&upsilon;/g, /&phi;/g, /&chi;/g, /&psi;/g, /&omega;/g, /&thetasym;/g, /&upsih;/g, /&piv;/g, /&bull;/g, /&hellip;/g, /&prime;/g, /&Prime;/g, /&oline;/g, /&frasl;/g, /&weierpv/g, /&image;/g, /&real;/g, /&trade;/g, /&alefsym;/g, /&larr;/g, /&uarr;/g, /&rarr;/g, /&darr;/g, /&harr;/g, /&crarr;/g, /&lArr;/g, /&uArr;/g, /&rArr;/g, /&dArr;/g, /&hArr;/g, /&forall;/g, /&part;/g, /&exist;/g, /&empty;/g, /&nabla;/g, /&isin;/g, /&notin;/g, /&ni;/g, /&prod;/g, /&sum;/g, /&minus;/g, /&lowast;/g, /&radic;/g, /&prop;/g, /&infin;/g, /&ang;/g, /&and;/g, /&or;/g, /&cap;/g, /&cup;/g, /&int;/g, /&there4;/g, /&sim;/g, /&cong;/g, /&asymp;;/g, /&ne;/g, /&equiv;/g, /&le;/g, /&ge;/g, /&sub;/g, /&sup;/g, /&nsub;/g, /&sube;/g, /&supe;/g, /&oplus;/g, /&otimes;/g, /&perp;/g, /&sdot;/g, /&amp;/g, /&lt;/g, /&gt;/g, /&OElig;/g, /&oelig;/g, /&Scaron;/g, /&scaron;/g, /&Yuml;/g, /&circ;/g, /&tilde;/g, /&ensp;/g, /&emsp;/g, /&thinsp;/g, /&zwnj;/g, /&zwj;/g, /&lrm;/g, /&rlm;/g, /&ndash;/g, /&mdash;/g, /&lsquo;/g, /&rsquo;/g, /&sbquo;/g, /&ldquo;/g, /&rdquo;/g, /&bdquo;/g, /&dagger;/g, /&Dagger;/g, /&permil;/g, /&lsaquo;/g, /&rsaquo;/g, /&euro;/g, /&/g);
		var by = new Array(" ", "¡", "¢", "£", "¤", "¥", "¦", "§", "¨", "©", "ª", "«", "¬", "­", "®", "¯", "°", "±", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "ƒ", "Α", "Β", "Γ", "Δ", "Ε", "Ζ", "Η", "Θ", "Ι", "Κ", "Λ", "Μ", "Ν", "Ξ", "Ο", "Π", "Ρ", "Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω", "α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", "λ", "μ", "ν", "ξ", "ο", "π", "ρ", "ς", "σ", "τ", "υ", "φ", "χ", "ψ", "ω", "ϑ", "ϒ", "ϖ", "•", "…", "′", "″", "‾", "⁄", "℘", "ℑ", "ℜ", "™", "ℵ", "←", "↑", "→", "↓", "↔", "↵", "⇐", "⇑", "⇒", "⇓", "⇔", "∀", "∂", "∃", "∅", "∇", "∈", "∉", "∋", "∏", "∑", "−", "∗", "√", "∝", "∞", "∠", "∧", "∨", "∩", "∪", "∫", "∴", "∼", "≅", "≈", "≠", "≡", "≤", "≥", "⊂", "⊃", "⊄", "⊆", "⊇", "⊕", "⊗", "⊥", "⋅", "&", "<", ">", "Œ", "œ", "Š", "š", "Ÿ", "ˆ", "˜", '" "', '" "', '" "', '"‌"', '"‍"', "‎", "‏", "–", "—", "‘", "’", "‚", "“", "”", "„", "†", "‡", "‰", "‹", "›", "€", "~und~");
		
		for (var i = 0; i < replace.length; i++) {
			str = str.replace(replace[i], by[i]);
		}
		
		return str;
	};
	
	var replaceForPreviewHTML = function(str){
		var replace = new Array(/&quot;/g, /&#39;/g, /&nbsp;/g, /&iexcl;/g, /&cent;/g, /&pound;/g, /&curren;/g, /&yen;/g, /&brvbar;/g, /&sect;/g, /&uml;/g, /&copy;/g, /&ordf;/g, /&laquo;/g, /&not;/g, /&shy;/g, /&reg;/g, /&macr;/g, /&deg;/g, /&plusmn;/g, /&sup2;/g, /&sup3;/g, /&acute;/g, /&micro;/g, /&para;/g, /&middot;/g, /&cedil;/g, /&sup1;/g, /&ordm;/g, /&raquo;/g, /&frac14;/g, /&frac12;/g, /&frac34;/g, /&iquest;/g, /&Agrave;/g, /&Aacute;/g, /&Acirc;/g, /&Atilde;/g, /&Auml;/g, /&Aring;/g, /&AElig;/g, /&Ccedil;/g, /&Egrave;/g, /&Eacute;/g, /&Ecirc;/g, /&Euml;/g, /&Igrave;/g, /&Iacute;/g, /&Icirc;/g, /&Iuml;/g, /&ETH;/g, /&Ntilde;/g, /&Ograve;/g, /&Oacute;/g, /&Ocirc;/g, /&Otilde;/g, /&Ouml;/g, /&times;/g, /&Oslash;/g, /&Ugrave;/g, /&Uacute;/g, /&Ucirc;/g, /&Uuml;/g, /&Yacute;/g, /&THORN;/g, /&szlig;/g, /&agrave;/g, /&aacute;/g, /&acirc;/g, /&atilde;/g, /&auml;/g, /&aring;/g, /&aelig;/g, /&ccedil;/g, /&egrave;/g, /&eacute;/g, /&ecirc;/g, /&euml;/g, /&igrave;/g, /&iacute;/g, /&icirc;/g, /&iuml;/g, /&eth;/g, /&ntilde;/g, /&ograve;/g, /&oacute;/g, /&ocirc;/g, /&otilde;/g, /&ouml;/g, /&divide;/g, /&oslash;/g, /&ugrave;/g, /&uacute;/g, /&ucirc;/g, /&uuml;/g, /&yacute;/g, /&thorn;/g, /&yuml;/g, /&fnof;/g, /&Alpha;/g, /&Beta;/g, /&Gamma;/g, /&Delta;/g, /&Epsilon;/g, /&Zeta;/g, /&Eta;/g, /&Theta;/g, /&Iota;/g, /&Kappa;/g, /&Lambda;/g, /&Mu;/g, /&Nu;/g, /&Xi;/g, /&Omicron;/g, /&Pi;/g, /&Rho;/g, /&Sigma;/g, /&Tau;/g, /&Upsilon;/g, /&Phi;/g, /&Chi;/g, /&Psi;/g, /&Omega;/g, /&alpha;/g, /&beta;/g, /&gamma;/g, /&delta;/g, /&epsilon;/g, /&zeta;/g, /&eta;/g, /&theta;/g, /&iota;/g, /&kappa;/g, /&lambda;/g, /&mu;/g, /&nu;/g, /&xi;/g, /&omicron;/g, /&pi;/g, /&rho;/g, /&sigmaf;/g, /&sigma;/g, /&tau;/g, /&upsilon;/g, /&phi;/g, /&chi;/g, /&psi;/g, /&omega;/g, /&thetasym;/g, /&upsih;/g, /&piv;/g, /&bull;/g, /&hellip;/g, /&prime;/g, /&Prime;/g, /&oline;/g, /&frasl;/g, /&weierpv/g, /&image;/g, /&real;/g, /&trade;/g, /&alefsym;/g, /&larr;/g, /&uarr;/g, /&rarr;/g, /&darr;/g, /&harr;/g, /&crarr;/g, /&lArr;/g, /&uArr;/g, /&rArr;/g, /&dArr;/g, /&hArr;/g, /&forall;/g, /&part;/g, /&exist;/g, /&empty;/g, /&nabla;/g, /&isin;/g, /&notin;/g, /&ni;/g, /&prod;/g, /&sum;/g, /&minus;/g, /&lowast;/g, /&radic;/g, /&prop;/g, /&infin;/g, /&ang;/g, /&and;/g, /&or;/g, /&cap;/g, /&cup;/g, /&int;/g, /&there4;/g, /&sim;/g, /&cong;/g, /&asymp;;/g, /&ne;/g, /&equiv;/g, /&le;/g, /&ge;/g, /&sub;/g, /&sup;/g, /&nsub;/g, /&sube;/g, /&supe;/g, /&oplus;/g, /&otimes;/g, /&perp;/g, /&sdot;/g, /&amp;/g, /&lt;/g, /&gt;/g, /&OElig;/g, /&oelig;/g, /&Scaron;/g, /&scaron;/g, /&Yuml;/g, /&circ;/g, /&tilde;/g, /&ensp;/g, /&emsp;/g, /&thinsp;/g, /&zwnj;/g, /&zwj;/g, /&lrm;/g, /&rlm;/g, /&ndash;/g, /&mdash;/g, /&lsquo;/g, /&rsquo;/g, /&sbquo;/g, /&ldquo;/g, /&rdquo;/g, /&bdquo;/g, /&dagger;/g, /&Dagger;/g, /&permil;/g, /&lsaquo;/g, /&rsaquo;/g, /&euro;/g, /&/g);
		var by = new Array("\"", "\'", " ", "¡", "¢", "£", "¤", "¥", "¦", "§", "¨", "©", "ª", "«", "¬", "­", "®", "¯", "°", "±", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "ƒ", "Α", "Β", "Γ", "Δ", "Ε", "Ζ", "Η", "Θ", "Ι", "Κ", "Λ", "Μ", "Ν", "Ξ", "Ο", "Π", "Ρ", "Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω", "α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", "λ", "μ", "ν", "ξ", "ο", "π", "ρ", "ς", "σ", "τ", "υ", "φ", "χ", "ψ", "ω", "ϑ", "ϒ", "ϖ", "•", "…", "′", "″", "‾", "⁄", "℘", "ℑ", "ℜ", "™", "ℵ", "←", "↑", "→", "↓", "↔", "↵", "⇐", "⇑", "⇒", "⇓", "⇔", "∀", "∂", "∃", "∅", "∇", "∈", "∉", "∋", "∏", "∑", "−", "∗", "√", "∝", "∞", "∠", "∧", "∨", "∩", "∪", "∫", "∴", "∼", "≅", "≈", "≠", "≡", "≤", "≥", "⊂", "⊃", "⊄", "⊆", "⊇", "⊕", "⊗", "⊥", "⋅", "&", "<", ">", "Œ", "œ", "Š", "š", "Ÿ", "ˆ", "˜", '" "', '" "', '" "', '"‌"', '"‍"', "‎", "‏", "–", "—", "‘", "’", "‚", "“", "”", "„", "†", "‡", "‰", "‹", "›", "€", "~und~");
		
		for (var i = 0; i < replace.length; i++) {
			str = str.replace(replace[i], by[i]);
		}
		styleRepl = /style="(.*?)"/g;
		str = str.replace(styleRepl, '');
		return str;
	};
	
	var getJson = function(){
		var s = $('#' + formName).serializeArray();
		var t = {};
		
		jQuery.each(s, function(){
			t[this.name] = replaceForPreviewText(this.value);
		});
		
		$('#selectContact :selected').each(function(i, option){
			t['setDefaultContactBySlectionList' + i] = option.value;
		});
		t[$('#disableDefaultContact').val()] = $('#disableDefaultContact').is(':checked');
		
		
		json = JSON.stringify(t);

		return json;
	};
	
	var getDefaultContactSelectionJson = function(){
		var selectBoxEntry = new Array();
		var t = {};
		$('#selectContact :selected').each(function(i, option){
			t['setDefaultContactBySlectionList' + i] = option.value;
		});
		t[$('#disableDefaultContact').val()] = $('#disableDefaultContact').is(':checked');
		
		json = JSON.stringify(t);

		return json;
	};
	
	var getEditorContentJson = function(arr){
		
		json = JSON.stringify(arr);
		return json;
	};
	
	var foreach = function(callback){
		for (var k = 0; k < this.length; k++) {
			callback(k, this[k]);
		}
	};
	
	var showPreview_old = function(html){
		$('#previewDialog > .jqmWindow').jqm({
			onShow: function(h){
				var previewHeight;
				if (typeof(window.innerWidth) == 'number') {
					previewHeight = window.innerHeight;
				} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
					previewHeight = document.documentElement.clientHeight;
				} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
					previewHeight = document.body.clientHeight;
				}
				previewHeight = previewHeight - 100;
				$('#previewDialog > .jqmWindow').html('<div class="jqmWrap"><div class="jqmHeader"><div class="jqmClose"><!--close--></div></div><div class="jqmContent"><div class="jqmInnerWrap" style="height:' + previewHeight + 'px;">' + html + '</div></div></div>');
				h.w.fadeIn(888);
				h.w.show();
			},
			onHide: function(h) { 
		      h.o.remove(); // remove overlay
		      h.w.fadeOut(888); // hide window
		    }
		});
		$('#previewDialog .jqmWindow').jqmShow();
	};
	
	var showPreview = function(html){
		//$('#previewDialog > .jqmWindow .jqmInnerWrap').hide().html(html).fadeIn('slow');
		$('#previewDialog .jqmWindow .jqmInnerWrap').fadeOut('slow', function(){
			$(this).empty();
			$(this).html(html).fadeIn('slow');
		});
	};
	
	var showSpinner = function(msg){
		var html = '<div class="spinnerWrap">'
			+ '	<img src="/typo3conf/ext/leonhardt_dyn_content/img_shared/ajax-loader.gif" alt="Bitte warten" />'
			+ '	<span class="spinnerText">'
			+ 		msg
			+ '		<br /> Bitte warten ...'
			+ '	</span>'
			+ '</div>';
		$('#previewDialog .jqmWindow').empty();
		$('#previewDialog .jqmWindow').jqm({
			onShow: function(h){
				//h.o.remove();
				var previewHeight;
				if (typeof(window.innerWidth) == 'number') {
					previewHeight = window.innerHeight;
				} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
					previewHeight = document.documentElement.clientHeight;
				} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
					previewHeight = document.body.clientHeight;
				}
				previewHeight = previewHeight - 100;
				$('#previewDialog > .jqmWindow').html('<div class="jqmWrap"><div class="jqmHeader"><div class="jqmClose"><!--close--></div></div><div class="jqmContent"><div class="jqmInnerWrap" style="height:' + previewHeight + 'px;">' + html + '</div></div></div>');
				h.w.fadeIn(888);
				h.w.show();
			},
			onHide: function(h) { 
		      h.w.fadeOut(888); // hide window
		      //h.o.remove(); // remove overlay
		      h.o.fadeOut(888); // remove overlay
		      //h.o.remove(); // remove overlay
		    }
		});
		$('#previewDialog .jqmWindow').jqmShow();
	};
}

function previewOverview(){
	this.preview = function(){
		$('.previewOverview').live('click', function(){
			var id = $(this).attr('rel');
			$.ajax({
				type: 'post',
				url: 'index.php?eID=leonhardt_dyn_content_preview_overview',
				data: 'mode=previewOverview&articleId=' + id,
				beforeSend: function(){
					showSpinner('Vorschau wird erstellt.');
				},
				complete: function(){
				},
				success: function(html){
					showPreview(html);
				}
			});
			return false;
		});
	};
	
	var showPreview_old = function(html){
		$('#previewDialog > .jqmWindow').jqm({
			onShow: function(h){
				var previewHeight;
				if (typeof(window.innerWidth) == 'number') {
					previewHeight = window.innerHeight;
				} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
					previewHeight = document.documentElement.clientHeight;
				} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
					previewHeight = document.body.clientHeight;
				}
				previewHeight = previewHeight - 100;
//				$('#previewDialog > .jqmWindow').html('<div class="jqmWrap"><div class="jqmHeader"><div class="jqmClose"><!--close--></div></div><div style="clear:both"><!-- clearer --></div><div class="jqmContent"><div class="jqmInnerWrap" style="height:' + previewHeight + 'px;">' + html + '</div></div><div style="clear:both"><!-- clearer --></div></div>');
				$('#previewDialog > .jqmWindow').html('<div class="jqmWrap"><div class="jqmHeader"><div class="jqmClose"><!--close--></div></div><div class="jqmContent"><div class="jqmInnerWrap" style="height:' + previewHeight + 'px;">' + html + '</div></div></div>');
				h.w.show();
			}
		});
		$('#previewDialog .jqmWindow').jqmShow();
	};
	
	var showPreview = function(html){
		//$('#previewDialog > .jqmWindow .jqmInnerWrap').hide().html(html).fadeIn('slow');
		$('#previewDialog > .jqmWindow .jqmInnerWrap').fadeOut('fast', function(){
			$(this).empty();
			$(this).html(html).fadeIn('slow');
		});
	};
	
	var showSpinner = function(msg){
		var html = '<div class="spinnerWrap">'
			+ '	<img src="/typo3conf/ext/leonhardt_dyn_content/img_shared/ajax-loader.gif" alt="Bitte warten" />'
			+ '	<span class="spinnerText">'
			+ 		msg
			+ '		<br /> Bitte warten ...'
			+ '	</span>'
			+ '</div>';
		$('#previewDialog > .jqmWindow').empty();
		$('#previewDialog > .jqmWindow').jqm({
			onShow: function(h){
				var previewHeight;
				if (typeof(window.innerWidth) == 'number') {
					previewHeight = window.innerHeight;
				} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
					previewHeight = document.documentElement.clientHeight;
				} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
					previewHeight = document.body.clientHeight;
				}
				previewHeight = previewHeight - 100;
				$('#previewDialog > .jqmWindow').html('<div class="jqmWrap"><div class="jqmHeader"><div class="jqmClose"><!--close--></div></div><div class="jqmContent"><div class="jqmInnerWrap" style="height:' + previewHeight + 'px;">' + html + '</div></div></div>');
				h.w.fadeIn(888);
				h.w.show();
			},
			onHide: function(h) { 
		      h.w.fadeOut(888); // hide window
		      //h.o.remove(); // remove overlay
		      h.o.fadeOut(888); // remove overlay
		    }
		});
		$('#previewDialog > .jqmWindow').jqmShow();
	};
}


function deleteArticle(){

	this.deleteContent = function(id){
		$('.del_' + id).live('click', function(){
			doDelete(id);
		});
		$('.del_' + id).confirm({
			msg: '<span class="cLabel">ACHTUNG! Sind Sie sicher, dass Sie diesen Beitrag löschen möchten?</span>',
			wrapper: '<div class="confirmationWrap"></div>',
			buttons: {
				ok: 'Ja',
				cancel: 'Nein',
				separator: '  '
			}
		});
	};
	
	var doDelete = function(id){
		$.ajax({
			type: 'post',
			url: 'index.php?eID=leonhardt_dyn_content_delete_article',
			data: 'mode=deleteArticle&articleId=' + id,
			beforeSend: function(){
				$('#' + id + ' .linkWrap').busy({
					img: '/typo3conf/ext/leonhardt_dyn_content/img_shared/busy.gif',
					alt: 'Bitte warten.',
					title: 'Bitte warten.'
				});
			},
			complete: function(){
			},
			success: function(html){
				//location.reload();
				$('#' + id).fadeOut('slow');
				$('#' + id + ' .linkWrap').busy("hide");
			}
		});
	};
}

function tabMenu(){
	this.renderTabMenu = function(id){
		$("#tabMenu" + id).show();
		$("#tabBox" + id + " .tabBoxItem").hide();
		menu = "<ul>";
		$("#tabBox" + id + " .tabBoxItem .tbiHeadline").each(function(index){
			linkid = $(this).parent(".tabBoxItem").attr("id");
			onClickFunction = 'tabmenu_' + id + '.showTab(\'' + id + '\', \'' + linkid + '\');return false;';
			menu += "<li><a href=\"\" onclick=\"" + onClickFunction + "\" id=\"link" + linkid + "\">" + $(this).text() + "</a></li>";
		});
		menu += "</ul><div class=\"clearer\"><!-- clearer --></div>";
		first = $("#tabBox" + id + " .tabBoxItem .tbiHeadline").parent(".tabBoxItem").attr("id");
		$("#tabMenu" + id).html(menu);
		
		showTab(id, first);
		
	};
	
	this.showTab = function(menuId, id){
		$("#tabMenu" + menuId + " a").attr("class", "");
		$("#link" + id).attr("class", "active");
		$("#tabBox" + menuId + " .tabBoxItem").hide();
		$("#" + id).show();
	};
}

function imageWidthHeight(image){
	var imgWH = new Array();
	var img = new Image();
	img.onload = function(){
		imgWH[0] = this.width;
		imgWH[1] = this.height;
		return imgWH[0];
	};
	img.src = image;
}


function additionalCategorie(){
	this.activateDate = function(catNr){
		$('#additionalCategorie' + catNr).live('click', function(){
			var isAutomaticDate = $('#teaserDate').attr('type');
			if(isAutomaticDate == 'hidden'){
				var teaserDate = $('#teaserDate').val();
				var teaserDateHtml = '<div class="clear"><!--clear--></div>'
					+ '<label for="teaserDate">Datum*</label>'
					+ '<input type="text" name="teaserDate" id="teaserDate" size="20" value="' + teaserDate + '" class="date-pick" />'
					+ '<div class="clear"><!--clear--></div>';
				
				$('.startDate').eq(0).html(teaserDateHtml);
				$('#teaserDate').datePicker();
			}
						
			var isAutomaticEndDate = $('#teaserEndDate').attr('type');
			if(isAutomaticEndDate == 'hidden'){
				var teaserEndDate = $('#teaserEndDate').val();
				var teaserEndDateHtml = '<label for="teaserEndDate">End-Datum*</label>'
					+ '<input type="text" name="teaserEndDate" id="teaserEndDate" size="20" value="' + teaserEndDate + '" class="date-pick" />'
					+ '<input type="hidden" name="teaserEndDateSelected" id="teaserEndDateSelected" value="none" />';
				
				$('.endDate').eq(0).html(teaserEndDateHtml);
				$('#teaserEndDate').datePicker();
			}
		});		
	}
}


function calendarSwitch(){
	this.change = function(id, displayId, cat, project, additionalLinkParts){
		$('#calendar_' + id + ' .cal').wrap('<div class="dynWrap"></div>');
		
		var mainCssObj = {
			'overflow': 'hidden',
			'height': ($('#calendar_' + id + ' .dynWrap').height()) + 'px',
			'position': 'relative'
		}
		
		$('#calendar_' + id + ' .dynWrap').css(mainCssObj);
		$('#calendar_' + id + ' .calPrev').live('click', function(){
			var newDate = $(this).attr('rel');
			ajaxRequest(newDate, 'left', id, displayId, cat, project, additionalLinkParts);
			
			return false;
		});
		
		$('#calendar_' + id + ' .calNext').live('click', function(){
			var newDate = $(this).attr('rel');
			ajaxRequest(newDate, 'right', id, displayId, cat, project, additionalLinkParts);
			
			return false;
		});
		
		$('#calendar_' + id).next('.selectFilterWrap').each(function(){
			var calSelect = $(this);
			calSelect.find('#year').live('change', function(){
				var newDate = '1-' + calSelect.find('#month').val() + '-' + $(this).val();
				var position = ($('#calendar_' + id + ' .calNext').attr('rel').split('-')[2] < $(this).val()) ? 'right' : 'left';

				ajaxRequest(newDate, position, id, displayId, cat, project, additionalLinkParts);
			});
			
			calSelect.find('#month').live('change', function(){
				var newDate = '1-' + $(this).val() + '-' + calSelect.find('#year').val();
				var nextRel = parseInt($('#calendar_' + id + ' .calNext').attr('rel').split('-')[1]);
				var curSelection = parseInt($(this).val());
				var position = (nextRel == '1') ? 'left' : (curSelection > nextRel) ? 'right' : (curSelection == nextRel) ? 'right' : (curSelection < nextRel) ? 'left' : 'right';
				
				ajaxRequest(newDate, position, id, displayId, cat, project, additionalLinkParts);
			});
		});
	}
	
	var ajaxRequest = function(newDate, position, id, displayId, cat, project, additionalLinkParts){
		additionalLinkParts = additionalLinkParts.split('&');
		$.ajax({
			type: 'post',
			url: 'index.php?eID=leonhardt_dyn_content_calendar',
			data: 'mode=&displayID=' + displayId + '&newDate=' + newDate + '&cat=' + cat + '&project=' + project + '&additinalLinkParts=' + additionalLinkParts,
			beforeSend: function(){
				$('#calendar_' + id + ' .switchSpinner').css({
					'display' : 'block',
					'width' : $('#calendar_' + id + ' .dynWrap').width() + 'px',
					'height' : $('#calendar_' + id + ' .dynWrap .cal').eq(0).height() + 'px'
				});
				$('#calendar_' + id + ' .switchSpinner img').css({
					'left' : (($('#calendar_' + id + ' .dynWrap').width()/2) - 16) + 'px',
					'top' : (($('#calendar_' + id + ' .dynWrap .cal').eq(0).height()/2) - 16) + 'px'
				});
			},
			complete: function(){
			},
			success: function(html){				
				$.ajax({
					type: 'post',
					url: 'index.php?eID=leonhardt_dyn_content_change_calendar_all_link',
					data: 'mode=changeAllLink&displayID=' + displayId + '&newDate=' + newDate + '&cat=' + cat + '&project=' + project + '&additinalLinkParts=' + additionalLinkParts,
					beforeSend: function(){},
					complete: function(){},
					success: function(linkHtml){
						$('#calendar_' + id).next().next().find('.links ul li').html(linkHtml);
					}
				});
				
				$('#calendar_' + id + ' .dynWrap').append(html);
				var appendCssObj = {
					'position': 'absolute',
					'top': '0',
					'left': ((position == 'left') ? '-' : '') + $('#calendar_' + id + ' .dynWrap').width() + 'px',
					'width': $('#calendar_' + id + ' .dynWrap .cal').eq(1).width() + 'px',
					'height': ($('#calendar_' + id + ' .dynWrap .cal').eq(1).height()) + 'px'
				}
				$('#calendar_' + id + ' .dynWrap .cal').eq(1).css(appendCssObj);
				
				$('#calendar_' + id + ' .dynWrap .cal').eq(1).animate({
					"left" : "0"
				}, { duration: 500, queue: false, complete: function(){
					$('#calendar_' + id + ' .switchSpinner').fadeOut('fast');
				} });		
				$('#calendar_' + id + ' .dynWrap').animate({
					"height" : ($('#calendar_' + id + ' .dynWrap .cal').eq(1).height())
				}, { duration: 500, queue: false });					
				$('#calendar_' + id + ' .dynWrap .cal').eq(1).prev().animate({
					"opacity" : '0'
				}, { duration: 1000, queue: false, complete: function(){
					$(this).remove();
				}});
				if($('#calendar_' + id).next().attr('class') == 'selectFilterWrap'){
					//1-9-2011
					var splitDate = newDate.split('-');
					$('#calendar_' + id).next().find('#month').val(splitDate[1]);
					$('#calendar_' + id).next().find('#year').val(splitDate[2]);
				}
			}
		});
	}
	
}


$().ready(function(){
	//overlayImgZoom close
	
	$('#zoomImage .jqmPreviewClose').live('click', function(){
		$('#zoomImage > .jqmWindow').jqmHide();
	});
	
	$('#zoomImage .jqmClose').live('click', function(){
		$('#zoomImage > .jqmWindow').jqmHide();
	});
	
	$('#previewDialog .jqmClose').live('click', function(){
		$('#previewDialog .jqmWindow').jqmHide();
	});
	
	$('#teaserText').keyup(function(){
		var maxtxt = 250;
		var len = $('#teaserText').val().length;
		if ((maxtxt - len) < 0) {
			$('#counterDisplay').css('color', 'red');
			$('#teaserText').css('color', 'red');
		}
		else {
			$('#counterDisplay').css('color', 'green');
			$('#teaserText').css('color', 'black');
		}
		$('#counterDisplay').html(len);
	});
	
	$('#selectContact').live('change', function(){
		if($('#selectContact').val() != "noSelected"){
			$('#showStandardContactBox').attr("checked","checked");
		}else{
			$('#showStandardContactBox').attr("checked","");
		}
	});
	
	$('#previewDialog .imgZoom').live('click',function(){
		var imgSrc = $(this).attr('href');
		var iw = parseInt( $(this).attr('rel'));
		$('#zoomImage > .jqmWindow').jqm({
			onShow: function(h){
				var img = '<img src="' + imgSrc + '" alt="" width="' + iw + '" />';				
				var previewHeight;
				if (typeof(window.innerWidth) == 'number') {
					previewHeight = window.innerHeight;
				} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
					previewHeight = document.documentElement.clientHeight;
				} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
					previewHeight = document.body.clientHeight;
				}
				previewHeight = previewHeight - 100;
				$('#zoomImage > .jqmWindow').html('<div class="jqmWrap" style="width:' + (iw + 20) + 'px;"><div class="jqmHeader"><div class="jqmPreviewClose"><!--close--></div></div><div class="jqmContent"><div class="jqmInnerWrap" style="max-height:' + previewHeight + 'px;width:' + iw + 'px;">' + img + '</div></div></div>');
				h.w.fadeIn(888);
				h.w.show();
			},
			onHide: function(h) { 
		      h.w.fadeOut(888); // hide window
		      //h.o.remove(); // remove overlay
		      h.o.fadeOut(888); // remove overlay
		    }
		});
		$('#zoomImage .jqmWindow').jqmShow();
		return false;
	});
	
	$('.imgZoom').live('click',function(){
		var imgSrc = $(this).attr('href');
		var iw = parseInt( $(this).attr('rel'));
		$('#zoomImage > .jqmWindow').jqm({
			onShow: function(h){
				var img = '<img src="' + imgSrc + '" alt="" width="' + iw + '" />';				
				var previewHeight;
				if (typeof(window.innerWidth) == 'number') {
					previewHeight = window.innerHeight;
				} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
					previewHeight = document.documentElement.clientHeight;
				} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
					previewHeight = document.body.clientHeight;
				}
				previewHeight = previewHeight - 100;
				$('#zoomImage > .jqmWindow').html('<div class="jqmWrap" style="width:' + (iw + 20) + 'px;"><div class="jqmHeader"><div class="jqmClose"><!--close--></div></div><div class="jqmContent"><div class="jqmInnerWrap" style="max-height:' + previewHeight + 'px;width:' + iw + 'px;">' + img + '</div></div></div>');
				h.w.fadeIn(888);
				h.w.show();
			},
			onHide: function(h) { 
		      h.w.fadeOut(888); // hide window
		      //h.o.remove(); // remove overlay
		      h.o.fadeOut(888); // remove overlay
		    }
		});
		$('#zoomImage .jqmWindow').jqmShow();
		return false;
	});

	
});
