
	/********* ALF ***055********/
	
	var json_url = '_json/';
	var co_url = json_url + 'action/co_operate/';
	
		//////////// ToolTip
		
		function tooltip_open( info ) {
			$('tooltip').style.left = ( mouseX + 10 ) + 'px';
			$('tooltip').style.top = ( mouseY + 10 ) + 'px';
			$('tooltip').innerHTML = info;
			$('tooltip').style.display = '';
		}
		
		function tooltip_close( ) {
			$('tooltip').style.display = 'none';
		}
	
		/////////////
		
		function check_and_submit( form_name, co_name ) {
			
			co_operate( co_name, 'check_entry', $( form_name ).serialize( true ), null, function(json) {
					$( form_name ).submit();
				});
			
		}
	
		///////////// CO OPERATE
		
	  function co_operate( _co, action, data, button, onSuccess, onFail ) {
		  
		  if( typeof( data ) != 'object' ) {
			  data = $( data ).serialize( true );
		  }
		  post_data = { action: action, data: data, co: _co };
		  post_data = Object.toJSON( post_data );
		  
		  alf_json( co_url, { json: post_data }, null, onSuccess, onFail );
		  
	  }
	
		///////////// json UPDATE
	
		function alf_update( dbal, data, button, onSuccess ) {
		
			alf_json( json_url + 'action/alf_update/dbal/' + dbal, data, button, onSuccess );
				
		}
		
		/////////// json check_entry
			
		function alf_check_entry( button, dbal ) {
		
			alf_json_form( json_url + 'check_entry/', dbal + '_form', button.id, function( json ) {
					$( dbal + '_form' ).submit();
				} );
		
		}
	
		///////////// json FORM
	
		function alf_json_form( url, form, button, onSuccess, onFail ) {
		
			alf_json( url, $( form ).serialize( true ), button, onSuccess, onFail );
				
		}
		
		///////////// Clear json
		
		function alf_json( url, parameters, button, onSuccess, onFail ) {
		
			var trans = '';
			
			if( button != null )  {
				button.disabled = true;
				parameters[ 'button' ] = button.id;
			}
				
			new Ajax.Request( url, {
					method: 'post',
					parameters: parameters,
					requestHeaders: { Accept: 'application/json' },
					onComplete: function( transport ) {
						
						if( transport.status != 200 ) {
							if( onFail != null ) {
								onFail( 'Adresse nicht erreichbar' );	
							}
						}
						
						if( button != null && button != undefined ) 
							button.disabled = false;
							
					},
					onSuccess: function( transport ) {
						
						try {
							
							////// JSON interpretieren
							var json = transport.responseText.evalJSON( true );
							
						} catch( error ) {
							
							//////// DEBUG MASTER
							if( window.debug_add ) {
								debug_add( transport.responseText );
							
								//////// Fehlerbehandlung wenn nicht valider JSON Code kam
								if( onFail != null ) {
									onFail( 'Syntax Error' );	
								} else {
									//alf_msg( 'Syntax Error' );
								}
							
							}
							
							/////// Abbruch
							return false;
							
						}
						
						if( json[ 'signal' ] == 'ERROR' ) {
							
							if( onFail != null ) {
								onFail( json[ 'msg' ] );	
							} else {
								if( json[ 'link' ] && $( json[ 'link' ] ) ) {
									//$( json[ 'link' ] ).style.color = '#CC0000';
									new Effect.Highlight( $(json[ 'link' ]), { startcolor: '#CC0000', endcolor: '#ffffff' });
									//window.scrollTo( 0, $( json[ 'link' ] ).offsetTop + 150 );
									
								} else {
								
									alf_msg( json[ 'msg' ] );
								
								}
							}
							
						} else if( json[ 'signal' ] == 'OK' ) {
							
							if( onSuccess != null ) {
								onSuccess( json );	
							}
								
						} else if( json[ 'signal' ] == 'LOGIN FAIL' ) {
						
							alf_msg( 'Bitte loggen Sie sich neu ein. Die SESSION ist abgelaufen.' );
							if( login_url != undefined ) {
								window.location = login_url;
							}
						
						} else {
							
							if( onFail != null ) {
								onFail( 'Interner Fehler: JSON liefert keine verwertbare Antwort' );	
							} else {
								alf_msg( 'Interner Fehler: JSON liefert keine verwertbare Antwort' );
							}
							
						}
								
					}
				} );
				
		}
		
		//////// Roundabout
		
		Object.extend(Object, { 
			 isObject: function (object){ 
				  return object && object.constructor === Object; 
			 }, 
			 merge: function(dest, source){ 
				  for(var x in source){ 
						if(Object.isObject(source[x])){ 
							 if(!dest[x]){ dest[x] = {}; } 
							 Object.merge(dest[x],source[x]); 
						}else{ 
							 dest[x] = source[x]; 
						} 
				  } 
				  return dest; 
			 } 
		}); 
		
		function padding(laenge) {
			result = '';
			for (i = 0; i < laenge; i++)
			result = result + '___';
			return result;
		}
		
		function print_r(das_array, ebene) {
			var result = '';
			for (var wert in das_array)
			if (typeof das_array[wert] == "object")
			result = result + ' ' + padding(ebene) + wert + "\n" + print_r(das_array[wert], ebene + 1);
			else
			result = result + ' ' + padding(ebene) + wert + ' = ' + das_array[wert] + "\n";
			
			return result;
		}
		
		/////// MSG BOX
		
		function alf_msg( msg ) {
			/*$( 'alf_msg' ).innerHTML = msg;
			$( 'alf_blackbox' ).style.display = '';
			$( 'alf_msg_box' ).style.display = '';*/
			alert(msg);
		}
		
		function alf_msg_hide() {
			$( 'alf_blackbox' ).style.display = 'none';
			$( 'alf_msg_box' ).style.display = 'none';
		}
		
		//////////////////////////
		
		function selectOption( obj_option, obj_value ) {
		
			for( i=0; i<obj_option.options.length; i++ ) {
				if( obj_option.options[ i ].value == obj_value )	{
					obj_option.options[ i ].selected = true;
					return true;
				}
			}
			
			return false;
		
		}
		
		
		/**

		**/
		function alf_mailto( email, text ) {
			
			plain_email = alf_decode_email( email );
			plain_text = alf_decode_email( text );
			
			document.write( '<a href="mailto:' + plain_email + '">' + plain_text + '</a>' );
			
		}
		
		function alf_email( email ) {
			
			plain_email = alf_decode_email( email );
			
			document.write( plain_email );
			
		}

 		function alf_decode_email( email ) {
			
			email = email.replace( /\§\%\§/g, '@' );
			email = email.replace( /\%\§\%/g, '.' );
			
			return email;
			
		}
		
		
		/*
		other
		*/
		
		function nl2br(str) {
			
			if(typeof(str)=="string") {
				return str.replace(/(\r\n)|(\n\r)|\r|\n/g,"<br />");
		   	} else return str;
		
		   	return str;
		}
		
		function submit_on_enter( form_id ) { 
			if ( window.event.keyCode == 13 ) { 
				$( form_id ).submit(); 
			} 
		} 
	
		function function_on_enter( own_function ) { 
			if ( window.event.keyCode == 13 ) { 
				own_function();
			} 
		}
