// dwds dwds.js v0.1, 27.08.2008
// Copyright (c) 2008-2010 Alexander Siebert (http://www.dwds.de)
// 
// needed script.aculo.us and prototype -> protoculous (lightweighted version)
//
function l(m){try{console.log(m);}catch(e){}}
var dwds = 
{
	db_id_from_element_id: function(element)
	{
		return element.id.substring(element.id.search(/_[0-9]+/)+1);
	},
	db_id_from_event: function(evt)
	{
		return dwds.db_id_from_element_id(evt.element());
	},
	
	track_piwik: function(url, title)
	{
		try 
		{
			title = 'AJAX: ' + title;
			piwikTracker.setCustomUrl(url);
			piwikTracker.setDocumentTitle(title);
			piwikTracker.trackPageView();
			piwikTracker.enableLinkTracking();
		} 
		catch (err) 
		{
			l('Piwik Tracker (' + url + ' - ' + title + ')');
			l(err);
		}
	}
}


	// ##################################################################################
	function deleteAccount() {
		location.href = '/user/deleteAccount/';
	}

	// ##################################################################################
	function use_actual_view_for_my_own() {
		new Ajax.Updater("body_content", '/view/storeactualview2user/', {asynchronous:true, evalScripts:true,method:'post',
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}	
		});
	}

	// ##################################################################################
	function loadWPDDC_sub(panel_id,tablename, id, page) {
		var url = '/search/wortprofil/ddc/'+panel_id+'/'+tablename+'/'+id+'/'+page+'/';
	    new Ajax.Updater('wp_ddc_'+panel_id+'_'+page, url, {asynchronous:true,
		    evalScripts:true,
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
		dwds.track_piwik(url, 'WPDDC_sub');
	    //$('wp_ddc_'+panel_id).show();
	}
	// ##################################################################################
	function loadWPDDC09_sub(panel_id,tablename, id, page) {
		var url = '/search/wortprofil09/ddc/'+panel_id+'/'+tablename+'/'+id+'/'+page+'/';
	    new Ajax.Updater('wp_ddc_'+panel_id+'_'+page, url, {asynchronous:true,
		    evalScripts:true,
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
		dwds.track_piwik(url, 'WPDDC09_sub');
	    //$('wp_ddc_'+panel_id).show();
	}

	// ##################################################################################
	function loadWPDDC(panel_id,tablename, id, page) {
		var url = '/search/wortprofil/ddc/'+panel_id+'/'+tablename+'/'+id+'/'+page+'/';
    	    new Ajax.Updater('wp_ddc_'+panel_id, url, {asynchronous:true,
    		    evalScripts:true,
    		    onComplete: function() 
                {
                    $('dwds_search_wait').update('');
                },
    		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
    		    });
    		dwds.track_piwik(url, 'WPDDC');
    	    $('wp_ddc_'+panel_id).show();
    	}
    	// ##################################################################################
    function loadWPDDC09(panel_id,tablename, id, page, cloudstyle, count) {
        var el = null;
        if(cloudstyle == 1)
            el = $('wp_ddc_'+panel_id);
        else
            el = $('wp_ddc_'+id);
		var url = '/search/wortprofil09/ddc/' + panel_id + '/' + tablename + '/' + id + '/' + page + '/';
        var scrollpos = $('wp_ddc_' + panel_id).getHeight();
		if(scrollpos && count != undefined)
		    scrollpos -= 50;
		else if(scrollpos && count == undefined)
		    scrollpos = 0
        new Ajax.Updater(el, url, 
        {
			parameters:
			{
				count: count || 20
			},
            asynchronous: true,
            evalScripts: true,
            onComplete: function()
            {
                $('dwds_search_wait').update('');
				var container = $('content_panel_r_' + panel_id).select('#wp_panel_table').first();
                if (container == undefined) 
				{
					container = $('content_panel_r_' + panel_id).select('.cloud_body').first();
					if ($('content_panel_r_' + panel_id).clientHeight < $('content_panel_r_' + panel_id).scrollHeight) 
					{
						$('content_panel_r_' + panel_id).scrollTop = container.getHeight() + scrollpos;
					}
					else 
					{
						$('wp_ddc_' + panel_id).scrollTo();
					}
				}
				else
				{
	                var offset = $('wp_ddc_' + id).offsetTop;
	                $('content_panel_r_' + panel_id).scrollTop = offset - 20;
				}
            },
            onCreate: function()
            {
                $('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');
            }
        });
        el.show();
		dwds.track_piwik(url, 'Wortprofil');
	}
	
	// ##################################################################################	
	// clears filter options from corpus panel
	function clear_filter(panel_id) {
		new Ajax.Updater('ddc_panel_'+panel_id, '/search/filter/clear/'+panel_id+'/', {asynchronous:true,
		    evalScripts:true,
		    onComplete: function()
			{
				new Ajax.Updater('footer_'+panel_id,'/search/filter/footer/0/'+panel_id+'/',{asynchronous:true});
				$('dwds_search_wait').update('');
			},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
		 
		//	
	}
	
//    function show_wortprofil_rel_filter(panel_id, wp_id, show_tag, pos_id, cloud_style)
//    {
//        var filter = $('wortprofil_rel_filter').value;
//        if(cloud_style == 1)
//        {
//            show_wortprofil(panel_id, wp_id, show_tag, pos_id);
//        }
//        else
//        {
//            show_wortprofilTable(panel_id, wp_id, pos_id);
//        }
//    }
	// ##################################################################################	
    function show_wortprofilTable(panel_id,id, pos_id, rel_filter, sort) {
        var url = '/search/wortprofil/show/table/'+panel_id+'/'+id+'/'
        if(pos_id != undefined)
            url += pos_id + '/';
//        if(sort != undefined)
//            if(sort.length > 0)
//                url += sort + '/';
//        if(rel_filter != undefined)
//            if(rel_filter.length > 0)
//                url += rel_filter + '/';
        new Ajax.Updater('ddc_panel_'+panel_id, url, {asynchronous:true,
            evalScripts:true,
            parameters:
            {
                "rel_filter": rel_filter,
                "sort": sort
            },
            onComplete: function() 
            {$
                var url = '/search/wortprofil/footer/' + panel_id + '/' + id + '/0/1/';
                if(pos_id != undefined)
                    url += pos_id + '/';
                new Ajax.Updater('footer_' + panel_id, url, 
                {
                    asynchronous: true,
                    onComplete: function()
                    {
                        $('indicator1').hide();
                    }
                });
            },
            onCreate: function() 
            {
                $('indicator1').show();
            }
        });
		 dwds.track_piwik(url, 'Wortprofil-Tabelle');
	}
    
    function toggle_tagshow(ev)
    {
		var btn = $(ev.currentTarget);
		var p = btn.up('.cl');
        var el = p.select('.subpos');
        if(el.length == 0) return;
        el.invoke('toggle');
        if(el[0].visible())
            btn.update('Tags aus');
        else
            btn.update('Zeige Tags');
    }
	
	function show_wortprofil(panel_id,id, showtag, pos_id, rel_filter) {
        var url = '/search/wortprofil/show/'+panel_id+'/'+id+'/'+showtag+'/';
        if(pos_id != undefined)
            url += pos_id + '/';
        new Ajax.Updater('ddc_panel_'+panel_id, url, {asynchronous:true,
            evalScripts:true,
            parameters:
            {
                "rel_filter": rel_filter
            },
            onComplete: function() 
            {
                var url = '/search/wortprofil/footer/' + panel_id + '/' + id + '/' + showtag + '/0/';
                if(pos_id != undefined)
                    url += pos_id + '/';
                new Ajax.Updater('footer_' + panel_id, url, 
                {
                    asynchronous: true,
                    onComplete: function()
                    {
                        $('indicator1').hide();
						$$('.toggle_tags').invoke('observe', 'click', toggle_tagshow);
                    }
                });
                
            },
		    onCreate: function() 
            {
                $('indicator1').show();
            }
		});
		dwds.track_piwik(url, 'Wortprofil-Wolke');
	}
    
    function toggle_rel_filter(panel_id)
    {
        $('display_rel_filter_' + panel_id).toggle();
    }

	function go() {
	
		var serializedForm = Form.serialize('mainsearch');
		//alert(serializedForm);
		
		location.href = '?'+serializedForm ;
	}
	
	function change_view2() {
		var url = '/view/change/'+$('viewswitcher2').value+'/';
		new Ajax.Updater("body_content", url, {asynchronous:true, evalScripts:true,method:'post',
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}	
		});
		dwds.track_piwik(url, 'Sicht laden');
	}

	function create_new_view() {
	    
	    v = $('view_name').value;
		var url = '/view/create/'+v+'/';
	    new Ajax.Updater("body_content", '/view/create/'+v+'/', {asynchronous:true, evalScripts:true,method:'post',
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}	
		});
	    myLightWindow.deactivate();
		dwds.track_piwik(url, 'Sicht laden');	
	}

	function change_view_per_nb(id) {
		myLightWindow.deactivate();
		var url = '/view/change/'+id+'/';
		new Ajax.Updater("body_content", url, {asynchronous:true, evalScripts:true,method:'post',
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}	
		});
		dwds.track_piwik(url, 'Sicht ändern');
	} 

	function change_view() {
		var url = '/view/change/'+$('viewswitcher').value+'/';
		new Ajax.Updater("body_content", url, {asynchronous:true, evalScripts:true,method:'post',
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}	
		});
		dwds.track_piwik(url, 'Sicht ändern');
	}

	function panelstat_info(o,id) {
		var url = '/view/panel/statinfo/'+id+'/';
		new Ajax.Updater("pp_desc"+o, url, {asynchronous:true, evalScripts:true,method:'post',
		    onCreate: function() {$('pp_desc'+o).update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}	
		});
		dwds.track_piwik(url, 'Statinfo');
	}
	

	function panelcorpus_info(o,corpus_id) {
		$('pp_desc'+o).update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');
		var url = '/view/panel/corpusinfo/'+corpus_id+'/';
		new Ajax.Updater("pp_desc"+o, url, {asynchronous:true, evalScripts:true,method:'post'
			
		});
		dwds.track_piwik(url, 'Korpusinfo');
	}

	function panel_add2view(type, content_id) {
//        panel_loader.add_panel(type, content_id);
//        return;
//        
		myLightWindow.deactivate();
		var url = '/view/panel/add2view/'+type+'/'+content_id+'/';
		new Ajax.Updater("body_content", url, {asynchronous:true, evalScripts:true,method:'post',
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}	
		});
	   dwds.track_piwik(url, 'Panel hinzufügen');
	}

	function panel_close(panel_id) {

		new Ajax.Updater("body_content", '/view/panel/delete/'+panel_id+'/', {asynchronous:true, evalScripts:true,method:'post',
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}	
		});
	
	}


	function basket_beleg_change_metadaten(beleg_id) {

	    if (document.getElementById('result_'+beleg_id).style.display == "none") {
			var url = '/basket/change_metadaten/'+beleg_id+'/';
			new Ajax.Updater('result_'+beleg_id,url,{
				    method:'post',
				    evalScripts:true,
				    asynchronous:true});
		
			$('result_'+beleg_id).show();
			dwds.track_piwik(url, 'Beleg anzeigen');
	//	new Effect.BlindDown('result_'+beleg_id,{asynchronous:true,duration: 0.2});
		}
		else {
	//		new Effect.BlindUp('result_'+beleg_id,{asynchronous:true,duration: 0.2});
		$('result_'+beleg_id).hide();
		
		}
	}

	function basket_delete(beleg_id) {

		new Ajax.Updater('body_content','/basket/delete/'+beleg_id+'/',{
			    method:'post',
			    evalScripts:true,
			    asynchronous:true});
	
	
	}
	
	function basket_delete_beleg_question(type,beleg_id) {
		
		new Ajax.Updater('del_beleg_'+beleg_id,'/basket/delete_question/'+type+'/'+beleg_id+'/',{
			    method:'post',
			    evalScripts:true,
			    asynchronous:true});
	}

	function cancelSaveBeleg(pos, panel_id) {
		
		$('basket_saved_'+panel_id+'_'+pos).hide();

	}
	
	function insert2input(form_field, value) {
		
		$(form_field).value = value;
	}

	function basket_save_changed_metadaten(beleg_id) {
	
		var serializedForm = Form.serialize('basket_form_'+beleg_id);
        var url = '/basket/change/'+beleg_id+'/'+serializedForm+'/';
		new Ajax.Updater('result_'+beleg_id,url,{
		    method:'post',
		    evalScripts:true,
		    asynchronous:true,
		    onComplete: function() { 
		    
		    	new Effect.Highlight('result_'+beleg_id,{asynchronous:true,duration: 3  }); }  ,

		    onCreate: function() {$('result_'+beleg_id).update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });	
		    
		
		new Ajax.Updater('body_content','/basket/show/',{
			    method:'post',
			    evalScripts:true,
			    asynchronous:true});		    
		dwds.track_piwik(url, 'Mein Korpus ändern');
	}
	
	function saveBelegwithComment(pos, panel_id) {
	   var url = '/basket/add_with_comment/'+panel_id+'/'+pos+'/';
		new Ajax.Updater('basket_saved_'+panel_id+'_'+pos,url,{
		    method:'post',
		    evalScripts:true,
		    asynchronous:true})
	    dwds.track_piwik(url, 'Mein Korpus Beleg speichern');
	}

	function saveBeleg(pos, panel_id) {
		
		var serializedForm = Form.serialize('basket_form_'+panel_id+'_'+pos);
        var url = '/basket/add/'+panel_id+'/'+pos+'/'+serializedForm+'/';
		new Ajax.Updater('basket_saved_'+panel_id+'_'+pos,url,{
		    method:'post',
		    evalScripts:true,
		    asynchronous:true,
		    onComplete: function() { 
		    
		    	new Effect.Highlight('basket_saved_'+panel_id+'_'+pos,{asynchronous:true,duration: 3  }); }  ,

		    onCreate: function() {$('basket_saved_'+panel_id+'_'+pos).update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });	
		new Effect.Fade('basket_saved_'+panel_id+'_'+pos,{asynchronous:false,duration: 4});
		dwds.track_piwik(url, 'Mein Korpus Beleg speichern');
	}


function load_wdg_referenz_list(prefix) {
	if ( prefix.length > 1) {
		var serializedForm = Form.serialize('searchfield');
		var url = '/wdg/references/'+prefix+'/'+serializedForm+'/';
		new Ajax.Updater('wdg_referenz_list', url, {
			method: 'post',
			evalScripts: true,
			asynchronous: true,
			onCreate: function() {
				$('wdg_referenz_list').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');
			}
		} );	
		dwds.track_piwik(url, 'WDG-Referenz');
	}
}


	function load_kerncorpus_list(prefix) {
		if ( prefix.length > 3) {
			var serializedForm = Form.serialize('searchfield');
            var url = '/resource/kerncorpus/liste/'+prefix+'/'+serializedForm+'/';
			new Ajax.Updater('kerncorpus_list',url,{
			
			    method:'post',
			    evalScripts:true,
			    asynchronous:true,
			    onCreate: function() {$('kerncorpus_list').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
			    });
			dwds.track_piwik(url, 'Kernkorpus Liste');	
		}		
		//wdg_key_list_indicator
		
	}

	function load_wdg_key_list(prefix) {
		
		if ( prefix.length > 1) {
			var url = '/wdg/headwords/'+prefix+'/';
			new Ajax.Updater('wdg_key_list',url,{
			    method:'post',
			    evalScripts:true,
			    asynchronous:true,
			    onCreate: function() {$('wdg_key_list').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
			    });
			dwds.track_piwik(url, 'WDG Key List');	
		}		
		//wdg_key_list_indicator
		
	}


function load_wortwarte_def_list(prefix) {
	if ( prefix.length > 1) {
		var url = '/wortwarte/def/'+prefix+'/';
		new Ajax.Updater('wortwarte_key_list',url, {
			method:'post',
			evalScripts:true,
			asynchronous:true,
			onCreate: function() {
				$('wortwarte_key_list').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');
			}
	    	} );
		dwds.track_piwik(url, 'Wortwarte Def.-Liste');	
	} else {
		$('wortwarte_key_list').update('')
	}
}
	

	//dropdown on" id="search_drop" onclick="dropdown_menue('search_drop');	
	function dropdown_menue(name) {
	    //alert(name);
	    //$(name).toggle();
	    //$(name).setStyle({'display':'inline-block'});
	    
	    $(name).removeClassName("off");
	    $(name).addClassName("on");
	    
	}

	// ##################################################################################
	function gui_panel_show_form(nb) {

	    if (nb != '1' && $('gui_panel_add_form_1').style.display != "none") 
		$('gui_panel_add_form_1').hide();
	    if (nb != '2' &&$('gui_panel_add_form_2').style.display != "none") 
		$('gui_panel_add_form_2').hide();
	    if (nb != '3' && $('gui_panel_add_form_3').style.display != "none") 
		$('gui_panel_add_form_3').hide();


	    a = $('gui_content_desc').getElementsByClassName('gui_panel_add_form');

            for (var i = 0; i < a.length; ++i) {
		
                if ($(a[i]).style.display == "none")
		    $(a[i]).hide();
            }
	    
	    if (document.getElementById('gui_panel_add_form_'+nb).style.display == "none") {
		new Ajax.Updater('gui_panel_add_form_'+nb,'/panel/show/form/'+nb+'/',{asynchronous:true,onComplete: function() {new Effect.BlindDown('gui_panel_add_form_'+nb,{asynchronous:true,duration: 0.2}); } })
	    }
	    if (document.getElementById('gui_panel_add_form_'+nb).style.display != "none") {
		new Effect.BlindUp('gui_panel_add_form_'+nb,{asynchronous:true,duration: 0.2});
	    }
	}

	// ##################################################################################
	function showGuiInfo(nb) {
	    if (document.getElementById('gui_help').style.display == "none") {
			new Ajax.Updater('gui_help','/help/'+nb+'/',{asynchronous:true,onComplete: function() {new Effect.BlindDown('gui_help',{asynchronous:true,duration: 0.5}); } })
			$('gui_help_link').update("Schließen");
                }
                else {
                        new Effect.BlindUp('gui_help',{asynchronous:true,duration: 0.5});
			$('gui_help_link').update("Mehr Informationen ...");
              }
	}

	// ##################################################################################
	function create_new_panel() {
	
	    
	}

	// ##################################################################################
	function dwds_searchEnter() {
	    //alert( $F('mainsearch'));
    //location.href = 'http://beta.dwds.de/?qu=' + $F('mainsearch');
//	   console.log('dwds_searchEnter');
//        location.href = '/?qu=' + $F('mainsearch');
//		return true;
	    /*
		var serializedForm = Form.serialize('dwds_main_search');
		//alert(serializedForm);
		new Ajax.Updater('body_content','/search/send/'+serializedForm+'/',{
		    method:'post',
		    evalScripts:true,
		    asynchronous:true,
		    onComplete: function() {$('dwds_search_wait').update('Suche');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });	
	    return false;*/
	}

	// ##################################################################################
	function dwds_search_my_corpus() {
		var serializedForm = Form.serialize('dwds_main_search');
		location.href = '/my/corpus/search/' + serializedForm + '/' ;
		//location.href = 'http://beta.dwds.de/my/corpus/search/' + serializedForm + '/' ;
	}

	// ##################################################################################
	function dwds_search() {
	    
	    //var serializedForm = Form.serialize('dwds_main_search');
	    //$F('mainsearch'));
	    //alert($F('mainsearch'));
	    location.href = '/?qu=' + $F('mainsearch');
	    /*new Ajax.Updater('body_content','/search/send/'+serializedForm+'/',{
		    method:'post',
		    evalScripts:true,
		    asynchronous:true,
		    onComplete: function() {$('dwds_search_wait').update('Suche');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });*/
	}


	// ##################################################################################
	function sendDemoComments() {
	    var serializedForm = Form.serialize('democomment');
	    
	    //new Ajax.Request('/demo/comments/send/'+serializedForm+'/',{asynchronous:false, method:'post'});
	    new Ajax.Updater('demo_comment','/demo/comments/send/'+serializedForm+'/',{asynchronous:true})
	}

	// ##################################################################################
	function showDemoComments() { 
	    //new Ajax.Updater('demo_comment','/demo/comments/',{asynchronous:true,onComplete: function() {new Effect.BlindDown('demo_comment',{asynchronous:true,duration: 0.3}); } })
	    new Ajax.Updater('demo_comment','/demo/comments/',{asynchronous:true})
	}

        
	
	// ##################################################################################
	function saveDisplayOptions(panel_id) {
		var serializedForm = Form.serialize('displayoptions_'+panel_id);
		//alert(serializedForm);
		new Ajax.Updater('ddc_panel_'+panel_id, '/search/displayoptions/save/'+panel_id+'/'+serializedForm+'/', {asynchronous:true,
		    evalScripts:true,
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
		 
		new Ajax.Updater('footer_'+panel_id,'/search/displayoptions/footer/0/'+panel_id+'/',{asynchronous:true})
	    
	}
	
	// ##################################################################################
	function saveFilter(panel_id) {
		var serializedForm = Form.serialize('filter_'+panel_id);
		
		new Ajax.Updater('ddc_panel_'+panel_id, '/search/filter/save/'+panel_id+'/'+serializedForm+'/', {asynchronous:true,
		    evalScripts:true,
		    onComplete: function()
			{
				new Ajax.Updater('footer_'+panel_id,'/search/filter/footer/0/'+panel_id+'/',{asynchronous:true})
				$('dwds_search_wait').update('');
			},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
	    
	}
	
	// ##################################################################################

	function showDDCQuery(panel_id,type) {		
		new Ajax.Updater('ddc_panel_'+panel_id, '/search/debug/ddcquery/'+panel_id+'/'+type+'/', {asynchronous:true,
		    evalScripts:true,
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
		 
		new Ajax.Updater('footer_'+panel_id,'/search/debug/ddcquery/footer/'+type+'/'+panel_id+'/',{asynchronous:true})
	}


	// ##################################################################################
	function showExamples(panel_id) {
		
		var url = '/dwdswb/view/examples/'+panel_id+'/';
		new Ajax.Updater('ddc_panel_'+panel_id, url, {asynchronous:true,
		    evalScripts:true,
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
		 
		new Ajax.Updater('footer_'+panel_id,'/dwdswb/footer/'+panel_id+'/',{asynchronous:true})
		dwds.track_piwik(url, 'DWDSWB Examples');
	}

// ###########################################################################
function showEintrag(panel_id) {
	var url = '/dwdswb/view/entry/'+panel_id+'/';
	new Ajax.Updater('r_'+panel_id, url, {
		asynchronous:true, evalScripts:true,
		onComplete: function() { $('dwds_search_wait').update(''); },
		onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">'); }
	});
	dwds.track_piwik(url, 'DWDSWB Eintrag');
}
	
	// ##################################################################################	
	function showDivCompsInPlace(panel_id) {
		var url = '/dwdswb/view/comps/'+panel_id+'/';
		new Ajax.Updater('ddc_panel_'+panel_id+'_bottom', url, {asynchronous:true,
		    evalScripts:true,
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
		$('ddc_panel_'+panel_id+'_bottom').show(); 
		dwds.track_piwik(url, 'DWDSWB DivCompsInPlace');
	}
	
	// ##################################################################################
	function showDivComps(panel_id) {
		var url = '/dwdswb/view/comps/'+panel_id+'/';
		new Ajax.Updater('ddc_panel_'+panel_id, url, {asynchronous:true,
		    evalScripts:true,
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
		 
		new Ajax.Updater('footer_'+panel_id,'/dwdswb/footer/'+panel_id+'/',{asynchronous:true})
		dwds.track_piwik(url, 'DWDSWB DivComps');
	}

	// ##################################################################################
	function showZitate(panel_id) {
		var url = '/dwdswb/view/citations/'+panel_id+'/';
		new Ajax.Updater('ddc_panel_'+panel_id, url, {asynchronous:true,
		    evalScripts:true,
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
		 
		new Ajax.Updater('footer_'+panel_id,'/dwdswb/footer/'+panel_id+'/',{asynchronous:true});
		dwds.track_piwik(url, 'DWDSWB Zitate');
	}
	
	
 
	// ##################################################################################
	function showFilter(panel_id) {
		new Ajax.Updater('ddc_panel_'+panel_id, '/search/filter/'+panel_id+'/', {asynchronous:true,
		    evalScripts:true,
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
		 
		new Ajax.Updater('footer_'+panel_id,'/search/filter/footer/1/'+panel_id+'/',{asynchronous:true});
	}
	
	// ##################################################################################
	function showDisplayOptions(panel_id) {
		new Ajax.Updater('ddc_panel_'+panel_id, '/search/displayoptions/'+panel_id+'/', {asynchronous:true,
		    evalScripts:true,
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
		 
		new Ajax.Updater('footer_'+panel_id,'/search/displayoptions/footer/1/'+panel_id+'/',{asynchronous:true})
        return false;
	}
	
	// ##################################################################################
	function saveViewEdit(view_id) {
	    var serializedForm = $F('view_name');
	    
	    new Ajax.Updater('editView','/search/editview/save/'+view_id+'/'+serializedForm+'/',{evalScripts:true,asynchronous:true})
	    
	    new Effect.Highlight('editView',{asynchronous:true,duration: 1});
	}
	
	// ##################################################################################
	function deleteView(view_id) {
	
	    new Ajax.Request("/view/delete/"+view_id+"/", {method: 'post'});
	    location.href = '/';
	}
	
	// ##################################################################################}
	
	// ##################################################################################
	function showViewEditExpand(option,value) {
	
		new Ajax.Updater('editView','/search/editview/'+option+'/'+value+'/',{evalScripts:true,asynchronous:true})
		new Effect.Highlight('editView',{asynchronous:true,duration: 1});
	}
	
	// ##################################################################################
	function showSearchExpand(value) {
	    if (value==0) {
		new Effect.Appear('extendedDWDSSearch',{asynchronous:true,duration: 0.1});
		$('fspr').update('<img src="/media/img/beige/arrow-up.gif" /> <a href="#" onclick="showSearchExpand(1);">Hilfe ausblenden</a>');	
	    }
	    else {
		new Effect.BlindUp('extendedDWDSSearch',{asynchronous:true,duration: 0.1});
		$('fspr').update('<a href="/search/my/" class="lbOn" onclick="showSearchHelp();" style="padding-right:10px;">Suchhistorie</a>   <img src="/media/img/beige/question-mark.gif" /> <a href="#" onclick="showSearchExpand(0);">Hilfe anzeigen</a>');	
	    }

	}
	
	// ##################################################################################	
	function clearForm(field) {
	//alert(Form.Element.getValue('id_query'));
	//Form.Element.clear('id_query');
	    $(field).update("");
	}
	
	// ##################################################################################
	function update_div(a) {
	    new Ajax.Updater('my_div', '/update/'+a+'/', {asynchronous:true})
        }

        // ##################################################################################
	function send_query_request() {
	    new Ajax.Updater('ddc_panel', '/requestddc/', {asynchronous:true})
        }

	// ##################################################################################
        function ddc_change_beleg_size(size,panel_id) {
	    
		var url = '/search/ddc_panel_update/1/'+panel_id+'/'+size+'/';
          new Ajax.Updater('ddc_panel_'+panel_id, url, {asynchronous:true,
		    evalScripts:true,
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
            dwds.track_piwik(url, 'Korpus Beleganzahl');
          //new Ajax.Updater('tt', '/ajaxtt/', {asynchronous:true})
        }
        
        // ##################################################################################
        function mycorpus_change_beleg_size(belegsize) {
			var url = '/my/corpus/belegsize/'+belegsize+'/';
		new Ajax.Updater('basket', url, {asynchronous:true,
		    evalScripts:true,
		    //onComplete: function() {$('av_pages').update('Suche');},
		    onCreate: function() {$('av_pages').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });	        
			dwds.track_piwik(url, 'Mein Korpus Beleggrösse');
        }
	
	// ##################################################################################
	function mycorpus_page_load(page) {
        var url ='/my/corpus/page/'+page+'/';
		new Ajax.Updater('basket', url, {asynchronous:true,
		    evalScripts:true,
		    //onComplete: function() {$('av_pages').update('Suche');},
		    onCreate: function() {$('av_pages').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });	
	    dwds.track_piwik(url, 'Mein Korpus Seite laden');
	}
	
	// ##################################################################################
        function ddc_page_load(a,panel_id) {
	    var url = '/search/ddc_panel_update/'+a+'/'+panel_id+'/';
          new Ajax.Updater('ddc_panel_'+panel_id, url, {asynchronous:true,
		    evalScripts:true,
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
		    });
			dwds.track_piwik(url, 'Korpus Seite laden');
//lightwindowInit();
          //new Ajax.Updater('tt', '/ajaxtt/', {asynchronous:true})
        }

        // ##################################################################################
	function expandSearch(value) {
		var url = '/ajaxddc2/Expand/'+value+'/';
          new Ajax.Updater('ddc_panel', url, {asynchronous:true})
          /*new Ajax.Updater('panel_right', '/ajaxddc2/ExpandSwitcher/'+value+'/', {asynchronous:true})  */
		 dwds.track_piwik(url, 'Suche erweitern');
        }

        // ##################################################################################
	function adjustToGrid() {
            a = $('tr').getElementsByClassName('cl');
            for (var i = 0; i < a.length; ++i)
                $(a[i]).setStyle({'width':'420px'});
	    
	    new Ajax.Request("/view/AdjustToGrid/", {method: 'get'});
	   
        }

        // ##################################################################################
	function adjustHorizontal() {
            a = $('tr').getElementsByClassName('cl');
            for (var i = 0; i < a.length; ++i)
                $(a[i]).setStyle({'width':'882px'});
	   
	    new Ajax.Request("/view/AdjustToHorizontal/", {method: 'get'});
	}
/*      function myCallBackOnFinish(obj) {
                new Effect.Highlight(obj.element.id,{asynchronous:true, delay:0.1});
        }*/

	// ##################################################################################    
	function myCallBackOnFinish(){
          alert("the Element's id the effect was applied to is :");
        }
	
	function killWDGButtons(sense_id,panel_id) {
	    if (document.getElementById('buttons_'+sense_id+'_'+panel_id).style.display != "none") {
		new Effect.toggle('buttons_'+sense_id+'_'+panel_id,'blind',{delay:2});	
	    }


	}

// #########################################################################
function updateSense(sense_id, panel_id) {
	var url = '/dwdswb/update/sense/'+sense_id+'/'+panel_id+'/';
	new Ajax.Updater('result_'+sense_id+'_'+panel_id, url, { asynchronous: true, onComplete: function() { new Effect.Highlight('result_'+sense_id+'_'+panel_id, { asynchronous: true, duration: 0.05} ); } } )
	dwds.track_piwik(url, 'DWDSWB Update Sense');	
}


// ########################################################################
function showDetails(all, panel_id) {
	$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');
	for (var i =0; i<all.length; ++i) {
		if (all[i]!=-1) {
			var url = '/dwdswb/unfold/sense/'+all[i]+'/'+panel_id+'/';
			new Ajax.Updater('result_'+all[i]+'_'+panel_id,url, {asynchronous:true});
			$('result_'+all[i]+'_'+panel_id).show();
			dwds.track_piwik(url, 'DWDSWB Details');
		}
	}
	$('dwds_search_wait').update('');
}
    

// ########################################################################
function expandSense(sense_id,panel_id) {
	if (document.getElementById('result_'+sense_id+'_'+panel_id).style.display == "none") {
		var url = '/dwdswb/unfold/sense/'+sense_id+'/'+panel_id+'/';
		new Ajax.Updater('result_'+sense_id+'_'+panel_id,url,{asynchronous:true,onComplete: function() {new Effect.BlindDown('result_'+sense_id+'_'+panel_id,{asynchronous:true,duration: 0.05}); } } )
		dwds.track_piwik(url, 'DWDSWB Details');
	} else {
		new Effect.BlindUp('result_'+sense_id+'_'+panel_id,{asynchronous:true,duration: 0.05});
	}
}


// #########################################################################
function expandLine(value_id,content_id) {
	if (document.getElementById('result_'+value_id+'_'+content_id).style.display == "none") {
		var url = '/view/ExpandLine/'+value_id+'/'+content_id+'/';
		new Ajax.Updater('result_'+value_id+'_'+content_id,url,{asynchronous:true});
		$('result_'+value_id+'_'+content_id).show()
		dwds.track_piwik(url, 'KWIC-Zeile laden');
	} else {
		$('result_'+value_id+'_'+content_id).hide()                
	}
}


// #########################################################################
        function maximize(value) {
	    
            a = $('tr').getElementsByClassName('cl');

            for (var i = 0; i < a.length; ++i) {
                if (a[i] != value)
                   $(a[i]).hide();
            }
	    
	    $(value).setStyle({'width':'932px','height':'auto'});
            a = $(value).getElementsByClassName('content_panel');
	   
	   
        var url = '/view/max/'+value+'/';
	    new Ajax.Updater("view", url, {asynchronous:true, evalScripts:true,
		    onComplete: function() {
		    $(value).setStyle({'width':'932px','height':'auto'});
		    $('dwds_search_wait').update('');
},

		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
	    });
		dwds.track_piwik(url, 'Ansich maximieren');

        }

        // ##################################################################################
	function minimize(value) {
		var url = '/view/min/'+value+'/';
	    new Ajax.Updater("body_content", url, {asynchronous:true, evalScripts:true,
		    onComplete: function() {$('dwds_search_wait').update('');},
		    onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
	    })
        dwds.track_piwik(url, 'Ansich minimieren');

        }
// 
//Drop Down Tabs Menu- Author: Dynamic Drive (http://www.dynamicdrive.com)
// free usage
//Created: May 16th, 07'

var tabdropdown={
	disappeardelay: 200, //set delay in miliseconds before menu disappears onmouseout
	disablemenuclick: false, //when user clicks on a menu item with a drop down menu, disable menu item's link?
	enableiframeshim: 1, //1 or 0, for true or false

	//No need to edit beyond here////////////////////////
	dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, previousmenuitem:null,
	currentpageurl: window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, ""), //get current page url (minus hostname, ie: http://www.dynamicdrive.com/)

	getposOffset:function(what, offsettype){
		var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
		var parentEl=what.offsetParent;
			while (parentEl!=null){
				totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
				parentEl=parentEl.offsetParent;
			}
		return totaloffset;
	},

	showhide:function(obj, e, obj2){ //obj refers to drop down menu, obj2 refers to tab menu item mouse is currently over
		if (this.ie || this.firefox)
			this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
		if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
			if (obj2.parentNode.className.indexOf("default")==-1) //if tab isn't a default selected one
				obj2.parentNode.className="selected"
			obj.visibility="visible"
			}
		else if (e.type=="click")
			obj.visibility="hidden"
	},

	iecompattest:function(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	},

	clearbrowseredge:function(obj, whichedge){
		var edgeoffset=0
		if (whichedge=="rightedge"){
			var windowedge=this.ie && !window.opera? this.standardbody.scrollLeft+this.standardbody.clientWidth-15 : window.pageXOffset+window.innerWidth-15
			this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth
		if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)  //move menu to the left?
			edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth
		}
		else{
			var topedge=this.ie && !window.opera? this.standardbody.scrollTop : window.pageYOffset
			var windowedge=this.ie && !window.opera? this.standardbody.scrollTop+this.standardbody.clientHeight-15 : window.pageYOffset+window.innerHeight-18
			this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight
			if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){ //move up?
				edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight
				if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) //up no good either?
					edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
			}
			this.dropmenuobj.firstlink.style.borderTopWidth=(edgeoffset==0)? 0 : "1px" //Add 1px top border to menu if dropping up
		}
		return edgeoffset
	},

	dropit:function(obj, e, dropmenuID){
		if (this.dropmenuobj!=null){ //hide previous menu
			this.dropmenuobj.style.visibility="hidden" //hide menu
			if (this.previousmenuitem!=null && this.previousmenuitem!=obj){
				if (this.previousmenuitem.parentNode.className.indexOf("default")==-1) //If the tab isn't a default selected one
					this.previousmenuitem.parentNode.className=""
			}
		}
		this.clearhidemenu()
		if (this.ie||this.firefox){
			obj.onmouseout=function(){tabdropdown.delayhidemenu(obj)}
			obj.onclick=function(){return !tabdropdown.disablemenuclick} //disable main menu item link onclick?
			this.dropmenuobj=document.getElementById(dropmenuID)
			this.dropmenuobj.onmouseover=function(){tabdropdown.clearhidemenu()}
			this.dropmenuobj.onmouseout=function(e){tabdropdown.dynamichide(e, obj)}
			this.dropmenuobj.onclick=function(){tabdropdown.delayhidemenu(obj)}
			this.showhide(this.dropmenuobj.style, e, obj)
			this.dropmenuobj.x=this.getposOffset(obj, "left")
			this.dropmenuobj.y=this.getposOffset(obj, "top")
			this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"
			this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+1+"px"
			this.previousmenuitem=obj //remember main menu item mouse moved out from (and into current menu item)
			this.positionshim() //call iframe shim function
		}
	},

	contains_firefox:function(a, b) {
		while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
		return false;
	},

	dynamichide:function(e, obj2){ //obj2 refers to tab menu item mouse is currently over
		var evtobj=window.event? window.event : e
		if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
			this.delayhidemenu(obj2)
		else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
			this.delayhidemenu(obj2)
	},

	delayhidemenu:function(obj2){
		this.delayhide=setTimeout(function(){tabdropdown.dropmenuobj.style.visibility='hidden'; if (obj2.parentNode.className.indexOf('default')==-1) obj2.parentNode.className=''},this.disappeardelay) //hide menu
	},

	clearhidemenu:function(){
		if (this.delayhide!="undefined")
			clearTimeout(this.delayhide)
	},

	positionshim:function(){ //display iframe shim function
		if (this.enableiframeshim && typeof this.shimobject!="undefined"){
			if (this.dropmenuobj.style.visibility=="visible"){
				this.shimobject.style.width=this.dropmenuobj.offsetWidth+"px"
				this.shimobject.style.height=this.dropmenuobj.offsetHeight+"px"
				this.shimobject.style.left=this.dropmenuobj.style.left
				this.shimobject.style.top=this.dropmenuobj.style.top
			}
		this.shimobject.style.display=(this.dropmenuobj.style.visibility=="visible")? "block" : "none"
		}
	},

	hideshim:function(){
		if (this.enableiframeshim && typeof this.shimobject!="undefined")
			this.shimobject.style.display='none'
	},

isSelected:function(menuurl){
	var menuurl=menuurl.replace("http://"+menuurl.hostname, "").replace(/^\//, "")
	return (tabdropdown.currentpageurl==menuurl)
},

	init:function(menuid, dselected){
		this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
		var menuitems=document.getElementsByTagName("a")
		for (var i=0; i<menuitems.length; i++){
			if (menuitems[i].getAttribute("rel")){
				var relvalue=menuitems[i].getAttribute("rel")
				document.getElementById(relvalue).firstlink=document.getElementById(relvalue).getElementsByTagName("a")[0]
				menuitems[i].onmouseover=function(e){
					var event=typeof e!="undefined"? e : window.event
					tabdropdown.dropit(this, event, this.getAttribute("rel"))
				}
			}
			if (dselected=="auto" && typeof setalready=="undefined" && this.isSelected(menuitems[i].href)){
				menuitems[i].parentNode.className+=" selected default"
				var setalready=true
			}
			else if (parseInt(dselected)==i)
				menuitems[i].parentNode.className+=" selected default"
		}
	}

}

tabdropdown.init("bluemenu", 0);

//JST dazu:
function autocomplete_selector(a)
{
	l(a);
}

//var DWDS_Autocomplete = Class.create(Ajax.Autocompleter, {
//  updateChoices: function(choices) {
//    if(!this.changed && this.hasFocus) 
//	{
//      this.update.innerHTML = choices;
//      Element.cleanWhitespace(this.update);
//      Element.cleanWhitespace(this.update.down());
//
//      if(this.update.firstChild && this.update.down().childNodes) {
//        this.entryCount = 
//          this.update.down().childNodes.length;
//        for (var i = 0; i < this.entryCount; i++) {
//          var entry = this.getEntry(i);
//          entry.autocompleteIndex = i;
//          this.addObservers(entry);
//        }
//      } else { 
//        this.entryCount = 0;
//      }
//
//      this.stopIndicator();
//      this.index = 0;
//      
//      if(this.entryCount==1 && this.options.autoSelect) {
//        this.selectEntry();
//        this.hide();
//      } else {
//        this.render();
//      }
//	  l(this.update.visible());
//	  if(this.update.visible())
//	    $('autocomplete_info').show();
//	  else
//	    $('autocomplete_info').hide();
//    }
//  }
//});
//var DWDS_Autocomplete = Class.create();
//DWDS_Autocomplete.prototype = Object.extend(new Ajax.Autocompleter())

function autocomplete_init()
{
	return;
    if ($("qu")) 
    {
        new Ajax.Autocompleter("qu", "autocomplete_query", "/search/qu/", 
        {
            'qu': $F('qu'),
            minChars: 1,
			frequency: 0,
            onShow: autocomplete_show,
            onHide: autocomplete_hide,
			updateElement: autcomplete_start_search
        });
    }
    else 
        if ($("mainsearch")) 
        {
            new Ajax.Autocompleter("mainsearch", "autocomplete_query", "/search/qu/", 
            {
                'qu': $F('mainsearch'),
                minChars: 1,
				frequency: 0,
	            onShow: autocomplete_show_result_page,
	            onHide: autocomplete_hide,
				updateElement: autcomplete_start_search,
				onSuccess: function(a)
				{
					// hack => sollte besser nach 
					// DWDS_Autocomplete updateChoices (s.o.)
					$('autocomplete_query').insert(a.responseText);
					try 
					{
						var ul = $('autocomplete_query').select('ul')[1];
						var n = ul.childElements().length;
						var h = n*20;
						if (h > 132) 
						{
							h = 165;
						}
						else 
						{
							h += 35;
						}
						$('autocomplete_info').setStyle({top: h + 'px'})
					}catch(e){l(e);}
				}
            });
        }
}

function autocomplete_show(e, f)
{
	$(f).show();
	$('autocomplete_info').show();
}

function autocomplete_show_result_page(e, f)
{
    var h = $(f).getHeight();
	if(h < 130)
	{
		h += 35;
		l(h);
	    $('autocomplete_info').setStyle({top: h + 'px'})
	} 
    $(f).show();
    $('autocomplete_info').show();
}

function autocomplete_hide(e, f)
{
	$(f).hide();
	$('autocomplete_info').hide();
}

function autcomplete_start_search(el)
{
	var txt = $(el).id;
    if ($("qu")) 
	{
		var p = '/?qu=' + txt + '&view=' + $F('viewswitcher');
		$("qu").value = txt;
	}
	else 
	{
		var p = '/?qu=' + txt;
		$("mainsearch").value = txt;
	}
	location.href = p;
}

document.observe("dom:loaded", function()
{
	$$('.wikinames_toggle').invoke('observe', 'click', wikinames_panel_expand_names);
    if($$('.toggle_tags'))
        $$('.toggle_tags').invoke('observe', 'click', toggle_tagshow);
	if($$('.neologismen_feedback'))
	   $$('.neologismen_feedback').invoke('observe', 'click', neologismen_feedback);
    if($$('.neologismen_share'))
       $$('.neologismen_share').invoke('observe', 'click', neologismen_share);
    autocomplete_init();
});

/**
 * ajax fuer wikinames tabelle
 * @param {String} names_type "newcomer", "toplist", "changes"
 * @param {Int} panel_id
 */
function load_wikinames(names_type, panel_id, pagenum)
{
	$("wikinames_loader").show();
	if (names_type == "toplist" ) { pagenum = 1; }
	new Ajax.Updater("ddc_panel_" + panel_id, "/wikinames/" + names_type + "/" + panel_id + "/" + pagenum + "/", 
	{
		onComplete: function(r)
		{
			$("wikinames_button_container").select(".active").invoke("removeClassName", "active");
			$("wikinames_" + names_type).addClassName("active");
			$("wikinames_loader").hide();
			$$('.wikinames_toggle').invoke('observe', 'click', wikinames_panel_expand_names);
		}
	});
}

function wikinames_panel_expand_names(e)
{
	var el_id = $(e.target).id
	var id = el_id.substring(el_id.search(/_[0-9]+/)+1);
	var el = $('wikinames_names_container_' + id);
//	$$('.wikinames_container').invoke('setStyle', '{"height":"20px"}');
	if (el.getHeight() == 20) 
	{
		$('wikinames_toggle_' + id).src = "http://media.dwds.de/dwds/media/img/beige/arrow-up.gif"
		el.setStyle(
		{
			"height": "auto"
		});
	}
	else 
	{
		$('wikinames_toggle_' + id).src = "http://media.dwds.de/dwds/media/img/beige/arrow-down.gif"
		el.setStyle(
		{
			"height": "20px"
		});
	}
} 
// JST ende

var panel_loader = 
{
    set_loading: function(id)
    {
        var img = new Element('img', {'src': context.MEDIAHOST + "http://media.dwds.de/dwds/media/img/spinner_moz.gif", "class": "panelLoaderCentered"});
        $(id).update(img);
    },
    add_panel: function(type, content_id)
    {
        var panels = $$('.cl');
        var id = 1;
        if(panels)
        {
            id = panels.length + 1;
        }
        id = 'r_' + id;
        
        var el = new Element('div', {'id': id, 'class': 'cl'});
        $('tr').appendChild(el);
        myLightWindow.deactivate();
        new Ajax.Updater(id, '/view/panel/addsingle2view/'+type+'/'+content_id+'/', 
        {
            asynchronous:true, 
            evalScripts:true,
            method:'post',
            onCreate: function() {panel_loader.set_loading(id);}
        });
    }
}

function wp_beleg_close(e)
{
	//!TODD: DO sth.
}

function neologismen_toggle()
{
	$('neologismen_desc').toggle();
	if($('neologismen_desc').visible())
	   $('neologismen_toggler').update('[weniger]');
	else
	   $('neologismen_toggler').update('[mehr]');
}

function neologismen_feedback(e)
{
	var id = $(e.currentTarget).getAttribute('data-id');
	var url = '/neologismen/feedback/' + id + '/';
	myLightWindow.activateWindow({href: url,title:'Kommentar',width:350,height:370,loading_animation:false});
}

function neologismen_share(e)
{
    var id = $(e.currentTarget).getAttribute('data-id');
    var url = '/neologismen/share/' + id + '/';
    myLightWindow.activateWindow({href: url,title:'Teilen',width:350,height:370,loading_animation:false});
}

function show_wortprofilFilter(panel_id)
{
	var url = '/search/wortprofil/filter/'+panel_id+'/'; 
    new Ajax.Updater('ddc_panel_'+panel_id, url, {
		method: 'GET',
		asynchronous:true,
        evalScripts:true,
        onComplete: function()
		{
			new Ajax.Updater('footer_'+panel_id,'/search/wortprofil/filter/footer/'+panel_id+'/',{asynchronous:true});
			$('dwds_search_wait').update('');
		},
        onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
        });
}

function save_wortprofilFilter(panel_id)
{
    var url = '/search/wortprofil/filter/'+panel_id+'/';
	var filter = $('wp_filter_form_'+panel_id).serialize(true);
    new Ajax.Updater('ddc_panel_'+panel_id, url, {
		method: 'POST',
		parameters: $('wp_filter_form_'+panel_id).serialize(true),
		asynchronous:true,
        evalScripts:true,
        onComplete: function()
		{
			new Ajax.Updater('footer_' + panel_id, '/search/wortprofil/footer/' + panel_id + '/', 
			{
				asynchronous: true,
			    onComplete: function()
                {
                    $('indicator1').hide();
                    $$('.toggle_tags').invoke('observe', 'click', toggle_tagshow);
                }
			});
			$('dwds_search_wait').update('');
			$('reset_wp_filter').show();
		},
        onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
        });
    dwds.track_piwik(url, 'Wortprofil filtern');
}

function clear_wp_filter(panel_id)
{
    var url = '/search/wortprofil/filter/'+panel_id+'/';
    new Ajax.Updater('ddc_panel_'+panel_id, url, {
        method: 'POST',
		parameters: {},
        asynchronous:true,
        evalScripts:true,
        onComplete: function()
        {
            $('dwds_search_wait').update('');
        },
        onCreate: function() {$('dwds_search_wait').update('<img src="http://media.dwds.de/dwds/media/img/spinner_moz.gif">');}
        });
    dwds.track_piwik(url, 'Wortprofil Filter zurücksetzen');
}

