jQuery(function($){
         
			$.editableText.defaults.newlinesEnabled = false;

			$('.editableText').editableText();
			
			$('.editableText').change(function(){
				
                    var newValue = $(this).html();
                

				$.post("saveData.php",{key:$(this).attr("id"),val:$(this).html()},function(e){ 
					if( e != "OK" ){
						alert( e );
				}} );
			});


			$('input[type="text"]').focus(function() {
       			$(this).removeClass("idleField").addClass("focusField");
       			$("#for"+$(this).attr("id")).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('input[type="text"]').blur(function() {
    			$("#for"+$(this).attr("id")).removeClass("focusField").addClass("idleField");
    			$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});

    		$('select').focus(function() {
       			$(this).removeClass("idleField").addClass("focusField");
       			$("#for"+$(this).attr("id")).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
    		});
    		$('select').blur(function() {
    			$("#for"+$(this).attr("id")).removeClass("focusField").addClass("idleField");
    			$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});

    		$('input[type="password"]').focus(function() {
       			$(this).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('input[type="password"]').blur(function() {
    			$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});    		
			
    		
    		$("a[rel]").overlay({

				expose: '#ebebeb',
				effect: 'apple',

				onBeforeLoad: function() {

					// grab wrapper element inside content
					var wrap = this.getContent().find(".contentWrap");

					// load the page specified in the trigger
					wrap.load(this.getTrigger().attr("href"));
					
					$("embed").hide();
				},
				
				onLoad: function(){
					$("#sortable").sortable();
					$("#sortable").disableSelection();

				},
				onClose: function(){
					$("embed").show();
				}

			});

        });
        var abschnitt = 1000;
        function addWorkAbschnitt( x ){
        	$.get("neuer_abschnitt.php",{id:abschnitt++},function(e){
        		$( "#sortable" ).append( e );
        	});
        }
        
        function removeAbschnitt( x ){
        	if ( confirm("Wollen Sie diesen Abschnitt wirklich entfernen?") ){
        		$("#abschnitt_"+ x ).fadeOut(1000, function () {
        			$("#abschnitt_"+ x ).text("Abschnitt wird entfernt!");
        			$("#abschnitt_"+ x ).remove();
      			});
        	}
        }

        function checkMail( x ){
            if( validate( $(x).val() )){
			$.get("checkMail.php",{mail:$(x).val()}, function( e ){
				if( e != 0 ){
					alert("Achtung! Diese E-Mail Adresse ist bereits in unserem System registriert!");
					$(x).val("");
					$(x).focus();
				}else{
					$(x).css("background-color","#66FF66");
				}
			});
            }else{
					alert("Die E-Mail Adresse scheint nicht korrekt zu sein!");
					$(x).val("");
					$(x).focus();
            }
        }

        function validate(email) {
        	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        	   if(reg.test(email) == false) {
        	      return false;
        	   }else{
            	   return true;
        	   }
        }
        
        function verifyAnmeldung(){
        	if( $("#email").val() == "" ){
        		$("#email").expose({api:true, lazy:true, color: 'darkred'}).load();
        		return false;
        	}
        	
        	if( $("#geschlecht").val() == 0 ){
        		$("#geschlecht").expose({api:true, lazy:true, color: 'darkred'}).load();
        		return false;
        	}
        	        	
        	if( $("#vorname").val() == "" ){
        		$("#vorname").expose({api:true, lazy:true, color: 'darkred'}).load();
        		return false;
        	}
        	
        	if( $("#name").val() == "" ){
        		$("#name").expose({api:true, lazy:true, color: 'darkred'}).load();
        		return false;
        	}
        	
        	if( $("#telefon").val() == "" ){
        		$("#telefon").expose({api:true, lazy:true, color: 'darkred'}).load();
        		return false;
        	}
        	
        	if( !$("#agb:checked").attr("checked") ){
        		$("#agb").expose({api:true, lazy:true, color: 'darkred'}).load();
        		return false;
        	}
        	  	
        	
        	return true;
        }
        
        function none(){}
