	
zscript.define('zAttachments', '/ztemplates/zscript/zAttachments.js');
zscript.define('zFirmeneintragFotoUploader', '/ztemplates/zscript/zFirmeneintragFotoUploader.js');
zscript.define('zLoginDialog', '/ztemplates/zscript/zLoginDialog.js');
zscript.define('zUser', '/ztemplates/zscript/zUser.js');
zscript.define('zStyle', '/ztemplates/zscript/zStyle.js');
zscript.define('jobsuchePanel', '/ztemplates/zscript/jobsuchePanel.js');
zscript.define('zajaxLoad', '/ztemplates/zscript/zajaxLoad.js');
zscript.define('zAjax', '/ztemplates/zscript/zAjax.js');
zscript.define('zForm', '/ztemplates/zscript/zForm.js');
zscript.define('zAutocomplete', '/ztemplates/zscript/zAutocomplete.js');
zscript.define('zMessages', '/ztemplates/zscript/zMessages.js');
zscript.define('zMap', '/ztemplates/zscript/zMap.js');
zscript.define('zOverlay', '/ztemplates/zscript/zOverlay.js');
zscript.define('zMenu', '/ztemplates/zscript/zMenu.js');

zscript.setLoaded('zAttachments');
zscript.setLoaded('zFirmeneintragFotoUploader');
zscript.setLoaded('zLoginDialog');
zscript.setLoaded('zUser');
zscript.setLoaded('zStyle');
zscript.setLoaded('jobsuchePanel');
zscript.setLoaded('zajaxLoad');
zscript.setLoaded('zAjax');
zscript.setLoaded('zForm');
zscript.setLoaded('zAutocomplete');
zscript.setLoaded('zMessages');
zscript.setLoaded('zMap');
zscript.setLoaded('zOverlay');
zscript.setLoaded('zMenu');



if(typeof zAttachments==='undefined') {
var zAttachments = function() {
    zscript.requiresInScript(['zUser', 'zMessages']);
    var onClose;
	
	function showLoginLayer(options, success) {
		zscript.log('checking logged in...');
	    onClose = success;		
	    
	    if(jQuery.isFunction(onClose)) {
			zscript.log('showLoginLayer: onClose callback provided: ' + onClose);
	    } else {
		    zscript.warn('showLoginLayer: no onClose callback provided!');
	    }

		if($('#loginDialog').size()==0) {
	      	zscript.log('creating login dialog div');
	      	$('body').append('<div class="loginDialog" id="loginDialog"><div id="loginDialogContent"></div></div>');
		}

		$.get(
		  'https://www.it-freiberufler.com/konto/login/dialog/anzeigen', 
		  options, 
		  function(data) {
		    $("#loginDialogContent").html(data);
			$('#loginDialog').dialog({
			    position: 'center',
				autoOpen: false,
				width: 500,
				//height: 150,
				modal: true,	
				resizable: false,
				title: 'Ihre Identität',	
				open: function(event, ui) {
					zscript.log('dialog opened');				
				},
				close: function(event, ui) {				
					zscript.log('dialog closed');	
					$("#loginDialogContent").html('dialog closed');			
				}
			});
			$('#loginDialog').dialog('open');			    
		});
	}//end showLoginLayer
	
	function showError(message) {
	   $("#loginDialogContent #dialogErrorMessage").html(message);
	   $("#loginDialogContent #dialogError").show();
	}

	
	function close() {
		$('#loginDialog').dialog('close');
		zUser.refreshUserData();
	   if(jQuery.isFunction(onClose)) {
	       zscript.log('calling ' + onClose);
	       onClose();
	   } else {
	       zscript.log('no callback on dialog close');
	   }
	}
	
	function showLoginPanel() {
		zMessages.hideMessages('#loginDialog');
		$('#loginPanel').show();
		$('#registrierenPanel').hide();
	}
	
	function showRegistrierenPanel() {
		zMessages.hideMessages('#loginDialog');
		$('#loginPanel').hide();
		$('#registrierenPanel').show();
	}
	

	
	function submitLoginForm(){
		zMessages.showGlobalMessage('#ajaxLoginForm', 'INFO', 'In Bearbeitung...');	
		
		jQuery.ajax({
			type: "GET",
			async: false,
			url: 'https://www.it-freiberufler.com/secure/konto/checklogin',
			dataType: 'html',
			success: function(data) {		
			    zscript.log('ajax userData returned: ' + data);
			}
		});
		var loginForm = $("#ajaxLoginForm");
		$.post(loginForm.attr('action'), loginForm.serialize(), function(data) {
		    var loginResponse = $(data);
		    if(loginResponse.find('#loginForm').size()==0) {
	       		zAttachments.close(true);
		    } else {
	   			zMessages.showGlobalMessage('#ajaxLoginForm', 'ERROR', 'Die Anmeldung ist fehlgeschlagen. Bitte geben Sie Ihre Anmeldedaten erneut ein.');	
		    }
		});	
	}
	
	return {
		showEditLayer: function(success, error) {
		   return showEditLayer(success, error);
		}
	};
}();
}




if(typeof zFirmeneintragFotoUploader==='undefined') {
var zFirmeneintragFotoUploader = function() {
	zscript.requires(['zForm', 'zMessages']);

	function createUploader(formSelector, inputId, uploadUrl, shadowClass) {
	    var triggerId = inputId + 'UploadTriggerId';
	    var previewId = inputId + 'PreviewId';
	    var messageId = inputId + 'UploadMessageId';
	    var shadowId = inputId + 'Shadow';
	    var deleteTriggerId = inputId + 'DeleteTriggerId';
	    
	    zForm.addSubmitListener(formSelector, function() {
			$('#' + messageId).hide();
		});
	    
	    
		var uploader = new AjaxUpload(triggerId, {
			action: uploadUrl,
			responseType: 'json',
			onChange: function(file, extension){
				$('#' + messageId).show();
				$('#' + messageId).text("Lade " + file + "...").removeClass("ui-state-error").addClass('ui-state-highlight');
			}, 
			onComplete: function(file, response) {
				zMessages.hideGlobalMessages(formSelector);
				if(response.msg) {
					$('#' + messageId).html('<div>' + response.msg + '</div><div>Sie müssen speichern um die Änderung zu übernehmen.</div>').removeClass("ui-state-error").addClass("ui-state-highlight");
				}
				else if(response.err) {
					$('#' + messageId).text(response.err).removeClass("ui-state-highlight").addClass("ui-state-error");
				} 
				else {
					$('#' + messageId).text("Fehler - Server liefert falsche Antwort.").removeClass("ui-state-highlight").addClass("ui-state-error");
				}
				if(response.imageUrl) {
					$('#' + inputId).val(response.imageName);
		            $('#' + previewId).attr("src", response.imageUrl);
		            if(typeof shadowClass!='undefined') {
		            	$('#' + shadowId).addClass(shadowClass);
		            }
				}
			}
		});	
		
		$('#' + deleteTriggerId).click(function(){
			if(confirm("Wirklich entfernen?")) {
				$('#' + inputId).val('');
				$('#' + previewId).attr('src', '');
	            if(typeof shadowClass!='undefined') {
	            	$('#' + shadowId).removeClass(shadowClass);
				} 
				$('#' + messageId).text('Sie müssen speichern um die Änderung zu übernehmen.').removeClass("ui-state-error").addClass("ui-state-highlight");
				zMessages.hideGlobalMessages(formSelector);
			}
			return false;
		});
		
			
	}	
	
	
	return {
		createUploader: function(formSelector, inputId, uploadUrl, shadowClass) {
		   return createUploader(formSelector, inputId, uploadUrl, shadowClass);
		}
	};
}();
}




if(typeof zLoginDialog==='undefined') {
var zLoginDialog = function() {
    zscript.requiresInScript(['zUser', 'zMessages']);
    var onClose;
	
	function showLoginLayer(options, success) {
		zscript.log('checking logged in...');
	    onClose = success;		
	    
	    if(jQuery.isFunction(onClose)) {
			zscript.log('showLoginLayer: onClose callback provided: ' + onClose);
	    } else {
		    zscript.warn('showLoginLayer: no onClose callback provided!');
	    }

		if($('#loginDialog').size()==0) {
	      	zscript.log('creating login dialog div');
	      	$('body').append('<div class="loginDialog" id="loginDialog"><div id="loginDialogContent"></div></div>');
		}

		$.get(
		  'https://www.it-freiberufler.com/konto/login/dialog/anzeigen', 
		  options, 
		  function(data) {
		    $("#loginDialogContent").html(data);
			$('#loginDialog').dialog({
			    position: 'center',
				autoOpen: false,
				width: 500,
				//height: 150,
				modal: true,	
				resizable: false,
				title: 'Ihre Identität',	
				open: function(event, ui) {
					zscript.log('dialog opened');				
				},
				close: function(event, ui) {				
					zscript.log('dialog closed');	
					$("#loginDialogContent").html('dialog closed');			
				}
			});
			$('#loginDialog').dialog('open');			    
		});
	}//end showLoginLayer
	
	function showError(message) {
	   $("#loginDialogContent #dialogErrorMessage").html(message);
	   $("#loginDialogContent #dialogError").show();
	}

	
	function close() {
		$('#loginDialog').dialog('close');
		zUser.refreshUserData();
	   if(jQuery.isFunction(onClose)) {
	       zscript.log('calling ' + onClose);
	       onClose();
	   } else {
	       zscript.log('no callback on dialog close');
	   }
	}
	
	function showLoginPanel() {
		zMessages.hideMessages('#loginDialog');
		$('#loginPanel').show();
		$('#registrierenPanel').hide();
	}
	
	function showRegistrierenPanel() {
		zMessages.hideMessages('#loginDialog');
		$('#loginPanel').hide();
		$('#registrierenPanel').show();
	}
	

	
	function submitLoginForm(){
		zMessages.showGlobalMessage('#ajaxLoginForm', 'INFO', 'In Bearbeitung...');	
		
		jQuery.ajax({
			type: "GET",
			async: false,
			url: 'https://www.it-freiberufler.com/secure/konto/checklogin',
			dataType: 'html',
			success: function(data) {		
			    zscript.log('ajax userData returned: ' + data);
			}
		});
		var loginForm = $("#ajaxLoginForm");
		$.post(loginForm.attr('action'), loginForm.serialize(), function(data) {
		    var loginResponse = $(data);
		    if(loginResponse.find('#loginForm').size()==0) {
	       		zLoginDialog.close(true);
		    } else {
	   			zMessages.showGlobalMessage('#ajaxLoginForm', 'ERROR', 'Die Anmeldung ist fehlgeschlagen. Bitte geben Sie Ihre Anmeldedaten erneut ein.');	
		    }
		});	
	}
	
	return {
		showLoginLayer: function(options, success) {
		   return showLoginLayer(options, success);
		},
		showError: function(message) {
		   showError(message);
		},
		showLoginPanel: function(){
			showLoginPanel();
		},
		showRegistrierenPanel: function(){
			showRegistrierenPanel();
		},
		submitLoginForm: function() {
			submitLoginForm();
		},
		close: function(success) {
		   close(success);
		}
	};
}();
}




if(typeof zUser==='undefined') {
var zUser = function() {
	var userData;

    zscript.requiresInScript('zLoginDialog');

	function initUserData(data){
	    userData=data;
	}

	function refreshUserData() {
		jQuery.ajax({
			type: "GET",
			async: false,
			url: 'http://www.it-freiberufler.com/konto/getUserData',
			dataType: 'json',
			success: function(data) {
				userData = data;
				fireUserDataListener(data);			
			    zscript.log('ajax userData returned: ' + userData);
			}
		});
	}

	function fireUserDataListener(data) {
		$(document).trigger('userDataChanged', data);
	}

	function addUserDataListener(callback) {
		$(document).bind('userDataChanged', callback);
	}

    function getUserData() {
	    if(typeof userData==='undefined') {
	    	refreshUserData();
		}
		return userData;
    }

	function isLoggedIn() {
	    zscript.log('logged in: ' + getUserData().loggedIn);
		return getUserData().kontoId;
	}
	
	function hasKontakt() {
	    getUserData();	    
		return userData.kontoId || userData.kontaktId;
	}
	
	
	function requireKontakt(options, success) {
		if(hasKontakt()) {
		    zscript.log('user has kontakt');
			success();
		} else {
		    zscript.log('user has no kontakt');
		    options.contact=true;
			zLoginDialog.showLoginLayer(options, success);
		}
	}
	
	function requireLogin(options, success, switchToHttps) {
		if(isLoggedIn()) {
		    zscript.log('user is logged in');
			success();
		} else {		    
		    zscript.log('user not logged in');
		    if(document.location.protocol.toLowerCase().indexOf('https')<0) {
		    	if(jQuery.isFunction(switchToHttps)){
		    		switchToHttps();
		    	} else {
		    		document.location.protocol='https';
		    	}
		    	return;
		    }
		    options.contact=false;		    
			zLoginDialog.showLoginLayer(options, success);
		}
	}

	function secure(selector) {
      	zscript.log('securing ' + selector);
	  	$(selector).find(".requireKontakt").click(function() {
      		 zscript.log('clicked ' + this);
      		 if(hasKontakt()) {
				return true;
 			 } else {       		 
	      		 var securedElement = this;
				 requireKontakt(function(){
				    zscript.log('login success ' + securedElement );				  	 
					$(securedElement).click(); 
				 });
				 return false;
			 }
		});
	}
	
	function login(user, password, success, error) {
		if(isLoggedIn()) {
			success();
		}
		jQuery.ajax({
			type: "GET",
			async: false,
			url: 'https://www.it-freiberufler.com/secure/konto/checklogin',
			dataType: 'html',
			success: function(data) {		
			    zscript.log('ajax userData returned: ' + data);
			}
		});		$.post('j_security_check', {j_username:user, j_password:password}, function(data) {
		    var loginResponse = $(data);
		    if(loginResponse.find('#loginForm').size()==0) {
		    	refreshUserData();
		    	if(jQuery.isFunction(success)) {
	   				success();	
	   			}
		    } else {
	   			if(jQuery.isFunction(error)) {
	   				error();
	   			}	
		    }
		});	
	}
	
	return {
	    initUserData: function(data){
	        initUserData(data);
	    },
		refreshUserData: function(){
			refreshUserData();
		},
		isLoggedIn: function () {
			return isLoggedIn();
		},
		hasKontakt: function () {
			return hasKontakt();
		},
		secure: function(selector) {
			return secure(selector);
		},
		requireKontakt: function (options, success) {
			return requireKontakt(options, success);
		},
		requireLogin: function (options, success, switchToHttps) {
			return requireLogin(options, success, switchToHttps);
		},
		addUserDataListener: function (callback) {
			addUserDataListener(callback);
		}, 
		login: function (user, password, success, error){
			login(user, password, success, error);
		}
	};
}();
}




if(typeof zStyle==='undefined') {
var zStyle = function() {
	function styleImpl(selector) {
		$(selector).find(".page-info:not(.plain)").addClass("ui-widget ui-widget-content ui-helper-clearfix form-spacer")
			.find(".page-info-title")
			.addClass("ui-widget-header");
		
		$(selector).find(".form-section").addClass("ui-widget ui-widget-content ui-helper-clearfix form-spacer span-12 last")
			.find(".form-subtitle")
				.addClass("span-12 last")
				.end()
			.find(".form-section-title")
			    .addClass('ui-widget-header')
				.wrap("<div class='span-12 last' style='margin-bottom:10px;'></div>")
				.end()
			.find(".form-row")
				.addClass("span-12 last")
				.find(".form-desc")
					.addClass("span-12 last")
					.end()
				.find(".form-label").each(function(){
					    var id = $(this).next(".form-input").find(":input").attr("id");
						$(this).wrapInner("<label for='" + id + "'></label>")
					})					
				.addClass("span-3")
					.end()
				.find(".form-input")
					.addClass("span-8")
					.end()
				.find(".form-info")
					.addClass("span-8 prepend-3 append-1 last")
					.end()
				.find(".form-info-button")
					.addClass("span-8 prepend-3 append-1 last")
					.end()
				.end()
			.find(".form-row-wide")
				.addClass("span-12 last")
				.find(".form-desc")
					.addClass("span-10 prepend-1 append-1 last")
					.end()
				.find(".form-label")
					.addClass("span-10 prepend-1 append-1 last")
					.end()
				.find(".form-input")
					.addClass("span-10 prepend-1")
					.end()
				.find(".form-info")
					.addClass("span-10 prepend-1 append-1 last")
					.end()
				.find(".form-row-info")
					.addClass("span-10 prepend-1 append-1 last")
					.end()
				.find(".form-info-button")
					.addClass("span-10 prepend-1 append-1 last")
					.end()
				.end();

		$(selector).find(".form-actions")
			.addClass("span-12 last form-spacer")
			.find(".form-submit")
				.addClass("span-4 prepend-3 last")
				.end()
			.find(".form-submit-error")
				.addClass("span-1 append-4 last")
				.end()
			.end();

		$(selector).find("input[type='submit'], .button").addClass("ui-state-default").hover( 
				function(){
		        	$(this).addClass("ui-state-hover");
			    },
			    function(){
		        	$(this).removeClass("ui-state-hover");
		    });
		
		$(selector).find(".section-title").addClass("ui-widget-header");

		$(selector).find("#PageView-error-text")
			.wrap("<div class='ui-state-error'></div>")
			.prepend("<span style='float: left; margin-right: 0.3em;' class='ui-icon ui-icon-alert'/>");

		$(selector).find("#dialogError")
			.css('clear', 'both').css('margin-bottom','0px').css('padding', '1px')
			.addClass("prepend-3 span-9 last")
			.find("#dialogErrorMessage")
			.wrap("<div class='ui-state-error' style='padding:2px;'></div>")
			.before("<span style='margin-right: 0.3em;' class='ui-icon ui-icon-alert'/>");

		$(selector).find("#PageView-message-text")
			.wrap("<div class='span-12 last ui-state-highlight'></div>")
			.prepend("<span style='float: left; margin-right: 0.3em;' class='ui-icon ui-icon-info'/>");

		$(selector).find(".link-button").addClass("ui-state-default").hover(
				function() { $(this).addClass('ui-state-hover'); }, 
				function() { $(this).removeClass('ui-state-hover'); }
			);

		$(selector).find("a[track]").live("click", function(){
			(new Image()).src=$(this).attr('track');
		});	
		
		$(selector).find(':input[required]').each(function() {
			var input = $(this);
			var label = $("label[for='" + input.attr("id") + "']");
			label.text(label.text() + " *");
	    });		
	    
        //jScale("img.logopreview", 60, 60);
        //jScale("img.logofull", 90, 90);
		//jScale(".profil img", 180, 180);	    
	}
	
	return {
		style: function (selector) {
			return styleImpl(selector);
		}
	};
}();
}




if(typeof jobsuchePanel==='undefined') {
var jobsuchePanel = function() {	
	return {
	};
}();
}




if(typeof zajaxLoad==='undefined') {
zscript.define('jquery.blockUI', '/ztemplates/zscript/ajaxload/blockui/jquery.blockUI.js');
var zajaxLoad = function() {	
    zscript.requires('jquery.blockUI');
    var defaultConfig = {
        containerId: undefined,
    	delay:0,
    	ajaxParams: {
			type: 'GET',
			async: true,
			url: undefined			
    	},
    	blockuiParams: { 
    			message: '<img src="/ztemplates/zscript/ajaxload/blockui/zajaxLoadLite.gif"/>', 
	    		css: { 
			        padding:        '3px', 
			        margin:         0, 
			        width:          '30%', 
			        top:            '40%', 
			        left:           '35%', 
			        textAlign:      'center', 
			        border:         'none', 
			        backgroundColor: 'transparent', 
			        opacity:         1
			     },
				overlayCSS:  { 
			        backgroundColor: '#eee', 
			        opacity:         0.5 
			    }				     
		},
    	htmlCallback: function(html) {
    	},
    	jsonCallback: function(json){
    	},
		block: function() {
			var toBlock = $('#' + this.containerId);
			this.position = toBlock.css("position");
			toBlock.block(this.blockuiParams);		
		},	
		unblock: function() {
			var toBlock = $('#' + this.containerId);
		    toBlock.css("position", this.position);
			toBlock.unblock(this.blockuiParams);		
		}
    };
    
	function load(config) {		
		config = jQuery.extend(true, {}, defaultConfig, config);
		config.block();
		if(config.delay > 0) {	
			setTimeout(doLoad(config), config.delay);
		} else {
			doLoad(config);
		}
		return config;
	}

    function doLoad(config) {
        var ajaxConfigSuccess = config.ajaxParams.success;    
        config.ajaxParams.success = function(val, textStatus, jqXHR) {
			config.unblock();
		    var contentType = jqXHR.getResponseHeader('Content-Type'); 
		    if(contentType.indexOf('text/html')>=0) {	
		    	var focusId = $('#' + config.containerId + ' *:focus').attr('id');
		    	if(config.replaceContainer){
					$('#' + config.containerId).replaceWith(val);
				} else {
					$('#' + config.containerId).empty().append(val);
				}
				if(typeof focusId!='undefined') {
					zscript.log('restoring focus on ' + focusId);
					$('#' + focusId).focus().select();
				}
				config.htmlCallback(val);	
		    } else if(contentType.indexOf('application/json')>=0) {
				config.jsonCallback( val);	
		    } else {
				zscript.error('zajaxLoad submit: unsupported Content-Type ' + contentType + ' in response formId=' + formId + ' triggerId=' + triggerId + ' ' + config.ajaxUrl);
		    }
			if(jQuery.isFunction(ajaxConfigSuccess)) {
				ajaxConfigSuccess(val, textStatus, jqXHR);
			}
		};
        var ajaxConfigError = config.ajaxParams.error;    
	    config.ajaxParams.error = function(xhttp, msg, exc){
			config.unblock();
			if(jQuery.isFunction(ajaxConfigError)) {
				ajaxConfigSuccess(xhttp, msg, exc);
			}
		}; 
		jQuery.ajax(config.ajaxParams);
    }
        
	return {
		getDefaultConfig: function() {
			return defaultConfig;
		},
		load: function(config) {
			return load(config);
		}				
	};
}();
}




if(typeof zAjax==='undefined') {
var zAjax = function() {	
	zscript.requires('zMessages');

	function getConfirm(url, messageSelector, confirmMessage, success, error) {
		if(!confirm(confirmMessage)) {
			zMessages.hideGlobalMessagesDiv($(messageSelector));
			return false;
		}
		get(url, messageSelector, success, error);
	}

	function get(url, messageSelector, success, error) {
		zMessages.showGlobalMessageDiv($(messageSelector), "INFO", 'In Bearbeitung...');
		$.ajax({
			type:'GET',
			url: url,
			dataType: 'json',
			success: function(json) {	 
			    zMessages.showGlobalMessagesDiv($(messageSelector), json.messages.globalMessages);

				if(json.state=='OK' || json.state=='WARN'){
					if(jQuery.isFunction(success)) {
						success(json);
					}				
				} else if(json.state=='ERROR'){
					if(jQuery.isFunction(error)) {
						error(json);
					}				
				} else {
					throw 'Unknown return status: ' + json.state;				
				}
			},
			error: function(xhttp, msg, exc){
				$(messageSelector).removeClass('ui-state-highlight').addClass('ui-state-error').text(msg + ' ' + xhttp.status  + ' ' + exc);
				if(jQuery.isFunction(error)) {
					error(xhttp, msg, exc);
				}
			}
		});
		
		return false;
	}
	
	return {
		get: function(url, messageSelector, success, error) {
			get(url, messageSelector, success, error);
		},
		getConfirm: function(url, messageSelector, confirmMessage, success, error) {
			getConfirm(url, messageSelector, confirmMessage, success, error);
		}
	};
}();
}




if(typeof zForm==='undefined') {
var zForm = function() {
    var submitSuccessListener = new Array();
    var submitErrorListener = new Array();
    
    zscript.requiresInScript(['zMessages']);

	function disable(selector) {
		$(selector).find(':input').attr('disabled', true);
		$(selector).find(':submit').hide();
	}
	
	function enable(selector) {
		$(selector).find(':input').attr('disabled', false);
		$(selector).find(':submit').show();
	}

	function addSubmitListener(selector, success, error) {
	 	if(typeof success!=='undefined') {
	 		if(typeof submitSuccessListener[selector]=='undefined') {
	 			submitSuccessListener[selector] = new Array();
	 		}
			submitSuccessListener[selector].push(success);
		}
	 	if(typeof success!=='undefined') {
	 		if(typeof submitErrorListener[selector]=='undefined') {
	 			submitErrorListener[selector] = new Array();
	 		}
			submitErrorListener.push(error);
		}
	}

	function submit(selector, shouldDisable, success, error) {
		var form = $(selector);
		zMessages.showGlobalMessage(form, 'INFO', 'In Bearbeitung...');
		
		$.ajax({
			type:'POST',
			url: form.attr('action'),
			data: form.serialize(),
			dataType: 'json',
			success: function(json) {	 
			    zMessages.hidePropertyMessages(form);
				if(shouldDisable && json.state=='OK'){
					disable(form);
				}
				zMessages.showMessages(form, json.messages);
				if(jQuery.isFunction(success)) {
					success(json);
				}
				if(typeof submitSuccessListener[selector] !='undefined') {
					for(var i=0;i < submitSuccessListener[selector].length;i++){
						submitSuccessListener[selector][i](json);
					}
				}
			},
			error: function(xhttp, msg, exc){
				zMessages.showGlobalMessage(form, 'ERROR', msg + ' ' + xhttp.status  + ' ' + exc);
				if(jQuery.isFunction(error)) {
					error(xhttp, msg, exc);
				}
				if(typeof submitErrorListener[selector] !='undefined') {
					for(var i=0;i < submitErrorListener[selector].length;i++){
						submitErrorListener[selector][i](json);
					}
				}
			}
		});
	}
	
	
	return {
		disable: function(selector) {
			disable(selector);
		}, 
		enable: function(selector) {
			enable(selector);
		}, 
		submit: function(selector, success, error) {
			submit(selector, false, success, error);
		},
		addSubmitListener: function(selector, success, error) {
			addSubmitListener(selector, success, error);
		},		
		submitAndDisable: function(selector, success, error) {
			submit(selector, true, success, error);
		}
	};
}();
}




if(typeof zAutocomplete==='undefined') {
var zAutocomplete = function() {
    	
    	function split( val ) {
			return val.split( /,\s*/ );
		}
		
		function extractLast( term ) {
			return split( term ).pop();
		}
		
		function autocomplete(selector, url) {
			$( selector )
				// don't navigate away from the field on tab when selecting an item
				.bind( "keydown", function( event ) {
					if ( event.keyCode === $.ui.keyCode.TAB &&
							$( this ).data( "autocomplete" ).menu.active ) {
						event.preventDefault();
					}
				})
				.autocomplete({
					source: function( request, response ) {
						$.getJSON( url, {
							term: extractLast( request.term )
						}, response );
					},
					search: function() {
						// custom minLength
						var term = extractLast( this.value );
						if ( term.length < 2 ) {
							return false;
						}
					},
					focus: function() {
						// prevent value inserted on focus
						return false;
					},
					select: function( event, ui ) {
						var terms = split( this.value );
						// remove the current input
						terms.pop();
						// add the selected item
						terms.push( ui.item.value );
						// add placeholder to get the comma-and-space at the end
						terms.push( "" );
						this.value = terms.join( ", " );
						return false;
					}
				});		
		}
    
	return {
	    autocomplete: function(selector, url) {
	    	return autocomplete(selector, url);
	    }	    
	};
}();
}




if(typeof zMessages==='undefined') {
var zMessages = function() {
	function showGlobalMessagesImpl(selector, globalMessagesJSON) {
		var globalMessagesDiv = $(selector).find('.globalMessages');
		showGlobalMessagesDiv(globalMessagesDiv, globalMessagesJSON);
	}	
		    
	function showGlobalMessagesDiv(globalMessagesDiv, globalMessagesJSON) {		    
		globalMessagesDiv.html('');
		for (var i = 0; i < globalMessagesJSON.length; i++) {
			var msg = globalMessagesJSON[i];			
			var style= "ERROR" == msg.type ? "ui-state-error" : "ui-state-highlight";
			globalMessagesDiv.append("<div class='" + style + "' style='padding:2px;'>" + msg.text + "</div>");
		}
		if(globalMessagesJSON.length>0){
			globalMessagesDiv.show();
		} else {
			globalMessagesDiv.hide();		
		}
	}	
	function showGlobalMessageImpl(selector, type, text) {
		var globalMessagesDiv = $(selector).find('.globalMessages');
		showGlobalMessageDiv(globalMessagesDiv, type, text);
	}
	function showGlobalMessageDiv(globalMessagesDiv, type, text) {
		globalMessagesDiv.html('');
		var style= "ERROR" == type ? "ui-state-error" : "ui-state-highlight";
		globalMessagesDiv.append("<div class='" + style + "' style='padding:2px;'>" + text + "</div>");
		globalMessagesDiv.show();
	}
	
	function showPropertyMessagesImpl(selector, propertyMessagesJSON) {		    
		var propertyMessagesDiv = $(selector).find('.propertyMessages');
		propertyMessagesDiv.html('');
		var showDiv = false;
	    $(selector).find(":input").each(function(index, elem) {
			var input = $(this);
			var propName = $(this).attr('name');
			var inputId = input.attr("id");
			var label = $("label[for='" + inputId + "']");
			var msgArr = propertyMessagesJSON[propName];
			if(msgArr!=null) {			
				var title = ""
				for (var i = 0; i < msgArr.length; i++) {
					title += msgArr[i].text + ' ';
				}	
				var origTitle = input.attr('origTitle');
				if(typeof origTitle=='undefined') {
				    var crtTitle = input.attr('title'); 
					if(typeof crtTitle!=='undefined') {    
						input.attr('origTitle', crtTitle);
					} else {
						input.attr('origTitle', 'origTitle');
					}
				}		
				input.attr('title', title);
				if($('a[name="' + propName + '"]').size()==0){				
					label.prepend("<a name='" + propName + "'/>");
				}				
				input.addClass('ui-state-error');
				
				showPropertyErrorMessage(inputId, title);
				showDiv = true;
			}
		});
		if(showDiv) {
			propertyMessagesDiv.show();
		} else {
			propertyMessagesDiv.hide();
		}
		 
	}
	
	function showPropertyErrorMessage(inputId, message) {
		var inputMessage = $('#' + inputId + 'Message');
		if(inputMessage.size()>0) {
			inputMessage.text(message).removeClass('ui-state-highlight').addClass('ui-state-error').addClass('form-input-propertyMessage').show();					
		} else {
			$('#'+inputId).after('<div id="' + inputId + 'Message" class="ui-state-error form-input-propertyMessage">' + message + '</div>');
		}
	}
	
	function showPropertyInfoMessage(inputId, message) {
		var inputMessage = $('#' + inputId + 'Message');
		if(inputMessage.size()>0) {
			inputMessage.text(message).removeClass('ui-state-error').addClass('ui-state-highlight').addClass('form-input-propertyMessage').show();					
		} else {
			$('#'+inputId).after('<div id="' + inputId + 'Message" class="ui-state-highlight form-input-propertyMessage">' + message + '</div>');
		}
	}
	
	
	
	function selectInputImpl(inputId) {
		$("#" + inputId).animate({
			backgroundColor: "#e99"
		}, 200, 
			function() {
				$(this).animate(
						{
							backgroundColor: "#ffffff"
						}, 5000).focus();
			});
		//$("#" + inputId).fadeOut('slow', function(){$(this).fadeIn('slow').focus()});	
	};
	
	function hidePropertyMessagesImpl(selector) {
		$(selector).find('.propertyMessages').each( function() {
			var propertyMessagesDiv = $(this);
			propertyMessagesDiv.html('');
			propertyMessagesDiv.hide();
		});
		$(selector).find(":input[.ui-state-error]").each(function(index, elem) {
			var input = $(this);
			var propName = $(this).attr('name');
			var label = $("label[for='" + input.attr("id") + "']");
			var origTitle = input.attr('origTitle');
			if(origTitle!=='origTitle') {
			    input.attr('title', origTitle); 
			} else {
			    input.attr('title', ''); 
			}		
			input.removeClass('ui-state-error');
			label.attr('title', '');
		});
		$(selector).find('.form-input-propertyMessage').hide();
	}
	
	function hideMessagesImpl(selector) {
		hideGlobalMessagesImpl(selector);
		hidePropertyMessagesImpl(selector);
	}

	function showMessagesImpl (selector, messagesJSON) {
		showGlobalMessagesImpl(selector, messagesJSON.globalMessages);
		showPropertyMessagesImpl(selector, messagesJSON.propertyMessages);
	}

	function hideGlobalMessagesImpl (selector) {
		hideGlobalMessagesDiv($(selector).find('.globalMessages'));
	}
	function hideGlobalMessagesDiv (elem) {
		elem.hide();
	}

	return {
		showGlobalMessagesDiv: function (elem, globalMessagesJSON) {
			showGlobalMessagesDiv(elem, globalMessagesJSON);
		},
		showGlobalMessages: function (selector, globalMessagesJSON) {
			showGlobalMessagesImpl(selector, globalMessagesJSON);
		},
		showGlobalMessage: function (selector, type, text) {
			showGlobalMessageImpl(selector, type, text);
		},
		showGlobalMessageDiv: function (elem, type, text) {
			showGlobalMessageDiv(elem, type, text);
		},
		hideGlobalMessages: function (selector) {
			hideGlobalMessagesImpl(selector);
		},
		hideGlobalMessagesDiv: function  (elem) {
			hideGlobalMessagesDiv (elem);
		},
		showPropertyMessages: function (selector, propertyMessagesJSON) {
			showPropertyMessagesImpl(selector, propertyMessagesJSON);
		},
		hidePropertyMessages: function (selector) {
			hidePropertyMessagesImpl(selector);
		},
		showMessages: function(selector, messagesJSON) {
			showMessagesImpl(selector, messagesJSON);
		},
		hideMessages: function(selector) {
			hideMessagesImpl(selector);
		},
		showPropertyErrorMessage: function(inputId, message){
			showPropertyErrorMessage(inputId, message);
		},
		showPropertyInfoMessage: function(inputId, message){
			showPropertyInfoMessage(inputId, message);
		},
		selectInput: function (inputId) {
		    selectInputImpl(inputId);
		}		
	};
}();
}




if(typeof zMap==='undefined') {
var zMap = function() {
    var maps = new Array();
    
    var disabled = typeof google ==='undefined';
    
    var geocoder;
    
    function getGeocoder() {
    	if(typeof geocoder==='undefined') {
    		geocoder = new google.maps.Geocoder();
    	}
    	return geocoder;
    }
    
    function getMap(mapId) {            
    	if(typeof maps[mapId]==='undefined') {
    	    var map = new Object();
			map.map = new google.maps.Map(document.getElementById(mapId), {
		      mapTypeId: google.maps.MapTypeId.ROADMAP
		    }); 	
		    map.markersArray = new Array();    
			maps[mapId] = map;
    	}
    	return maps[mapId];
    }    
    
    function createMap(mapId) {
    	maps[mapId]=undefined;
    	getMap(mapId);
	}
	    
	function setCenter(mapId, lat, lng, zoom) {
		var map = getMap(mapId).map; 
	    map.setCenter(new google.maps.LatLng(lat, lng));
	    if(zoom!=null) {
			map.setZoom(zoom);
		}
	}
	
	
	function removeMarkers(mapId) {
		var map = getMap(mapId); 
		for (i in map.markersArray) {
      		map.markersArray[i].setMap(null);
    	}
    	map.markersArray = new Array();	
	}
	
	function showMarker(mapId, lat, lng, zoom, icon, overlaySelector) {
 	  var map = getMap(mapId); 
	  setCenter(mapId, lat, lng, zoom);
	  var point = new google.maps.LatLng(lat, lng)
	  var options = {
		 position:point,
		 map: map.map
	  };
	  if(typeof icon!=='undefined') {
		options.icon = icon;
	  }
	  var marker = new google.maps.Marker(options);
	  map.markersArray.push(marker);
	  
	  if(typeof overlaySelector!='undefined' && overlaySelector!=null){
    	  google.maps.event.addListener(marker, 'click', function() {
    	   	  var infoWindow = new google.maps.InfoWindow();
			  infoWindow.setContent($(overlaySelector).html());
			  infoWindow.open(map.map, marker);
		  });    	  
	  }
	}    
    
	return {
	    createMap: function (mapId) {
		    if(disabled) {
		        $('#' + mapId).html('Der Kartenserver ist vorübergehend nicht erreichbar. Bitte haben Sie etwas Geduld, die Störung wird sofort behoben.');
		    	return;
		    }
	    	createMap(mapId);
	    },
	    setCenter: function (mapId, lat, lng, zoom) {
		    if(disabled) { return; }
	    	setCenter(mapId, lat, lng, zoom);
	    },
	    removeMarkers: function(mapId) {
		    if(disabled) { return; }
	    	removeMarkers(mapId);
	    },
	    showMarker: function (mapId, lat, lng, zoom, icon, overlayId) {
		    if(disabled) { return; }
	    	showMarker(mapId, lat, lng, zoom, icon, overlayId);
	    },
	    getGeocoder: function() {
		    if(disabled) { return; }
	    	return getGeocoder();
	    }	    
	};
}();
}




if(typeof zOverlay==='undefined') {
var zOverlay = function() {
	function showOverlay(triggerSelector) {
		if($('#zOverlayDiv').size()==0) {
	      	$('body').append('<div id="zOverlayDiv" class="apple_overlay"><div class="contentWrap"></div></div>');		
		}

		$(triggerSelector).attr('rel', '#zOverlayDiv').overlay({
			expose: '#ccc',
			effect: 'apple',
			onBeforeLoad: function() {
				var wrap = $('#zOverlayDiv .contentWrap');
				wrap.html('Daten werden geladen...');
				var href = this.getTrigger().attr('href');
				wrap.load(href);
			},
			fixed: false		
		});
	}	
	
	return {
		showOverlay: function(triggerSelector) {
		   return showOverlay(triggerSelector);
		}
	};
}();
}




if(typeof zMenu==='undefined') {
	var zMenu = function() {
	    zscript.requiresInScript('zUser', function(){
	    	zscript.log('--- addUserDataListener');
			zUser.addUserDataListener(function(){
				refresh();
			});
	    });
	    
	    function refresh() {
			$('#menu').load('http://www.it-freiberufler.com/ajax/menuDiv/loadMenuAction');
			zscript.log('+++ loaded menu');
	    }
		
		return {
			refresh: function() {
				refresh();
			}
		};
	}();
}



