unsupported_text="(Ihr Internet-Browser konnte nicht identifiziert werden - der Bedienungskomfort ist leicht eingeschraenkt)";

menus_desired_state_array = new Array();
menus_is_state_array = new Array();
dropdown_width_fixed = new Array();
ActiveMenuID='';
if (debugtext_static==null) debugtext_static='';
debugtext='';

/***************** browser detection ******************/

// IE browser? IE version?
Browser_is_unsupported=false;
Browser_is_IE_6_or_lower=false;
Browser_is_FF=Browser_is_Opera=Browser_is_Safari=Browser_is_Seamonkey=false;
Browser_is_FF_old=false;
Browser_Version=0;

var js_UserAgent = navigator.userAgent.toLowerCase();
Browser_Nom_Version = parseFloat(navigator.appVersion); 

if (Browser_Nom_Version < 4) Browser_is_unsupported=true;

while(true) {
    if (Browser_is_unsupported)
        break;
    Browser_is_IE = ( (js_UserAgent.indexOf('msie') != -1) && (js_UserAgent.indexOf('opera') == -1) && (js_UserAgent.indexOf('webtv') == -1) ); 
    if (Browser_is_IE) {
        Browser_Version = parseFloat( js_UserAgent.substring( js_UserAgent.indexOf('msie ') + 5 ) );
        Browser_is_IE_6_or_lower=(Browser_is_IE && Browser_Version<7.0);
        if (Browser_Version<6) Browser_is_unsupported=true;
        break;
    }
    Browser_is_FF = (js_UserAgent.indexOf('firefox/')!=-1);
    if (Browser_is_FF) {
        Browser_Version = parseFloat( js_UserAgent.substring(js_UserAgent.indexOf('firefox/')+8));
        Browser_is_FF_old=(Browser_Version<3.0);
        if (Browser_Version<1.5) Browser_is_unsupported=true;
        break;
    }
    Browser_is_Opera=(js_UserAgent.indexOf('opera/') != -1);
    Browser_is_Safari=(js_UserAgent.indexOf('safari') != -1);
    Browser_is_Seamonkey=(js_UserAgent.indexOf('seamonkey') != -1);
    break;
}


/***************** dropdown menu  ******************/

//debugtext=js_UserAgent + ' ' + Browser_is_IE + ' ' + Browser_Version + ' nv ' + Browser_Nom_Version;

function show_dropdown_menu_real(menuid,info){
    //<% if Client_is_Developer %> debugtext+='opening '+menuid+'<br>'; <% end_if %>
    var add_left=-10;
	menu_button_span=document.getElementById('menu_button_span_'+menuid);
	menu_button=document.getElementById('menu_button_'+menuid);
	submenu=document.getElementById('menubox'+menuid);
	new_left=menu_button_span.offsetLeft+add_left;
	if (new_left<0) new_left=0;
	submenu.style.left=new_left+"px";
	submenu.style.top=(menu_button_span.offsetTop+menu_button.offsetHeight-3)+"px";
	
	// fix dropdown box width for IE6 (no min-width available), can be disabled for other browsers
    //debugtext=submenu.offsetWidth;
    if (dropdown_width_fixed[menuid]!=true) {
        newwidth=submenu.offsetWidth+15;
        if (newwidth<220) newwidth=220;
        submenu.style.width=newwidth+'px';
        dropdown_width_fixed[menuid]=true;
    }
    active_dropdown_entry_width=submenu.offsetWidth-12;
	
	// make dropdown menu visible
	submenu.style.visibility = "visible";
	
	// for active menu / drop-down: set menu button background to "active" (like onmouseover)
	menu_button.style.background="url("+js_ThemeImageDir+"menu-button-hover.png) repeat-x";
}

function hide_dropdown_menu_real(menuid){
    //<% if Client_is_Developer %> debugtext+='closing '+menuid+'<br>'; <% end_if %>
	menu_button=document.getElementById('menu_button_'+menuid);
	submenu=document.getElementById('menubox'+menuid);
	// for active menu / drop-down: set menu button background back to "inactive" (like onmouseout)
	if (menu_button!=null) {
        if (menuid==ActiveMenuID)
			menu_button.style.background="url("+js_ThemeImageDir+"menu-button-active.png) repeat-x";
	    else
			menu_button.style.background="url("+js_ThemeImageDir+"menu-button.png) repeat-x";
    }
	if (submenu!=null) submenu.style.visibility = "hidden";		
}

function updatemenus(){
    for(var i in menus_desired_state_array) {
        if (menus_desired_state_array[i] != menus_is_state_array[i]) {
            if (menus_desired_state_array[i]=='open')
                show_dropdown_menu_real(i);
            else
                hide_dropdown_menu_real(i);
            menus_is_state_array[i]=menus_desired_state_array[i];
        }
    }
}

function show_dropdown_menu(menuid,info){
    if (Browser_is_unsupported) return;
    menus_desired_state_array[menuid]='open';
    setTimeout('updatemenus()', 5);
    //debugtext+='show-'+info+'-'+menuid+'<br>';
}
function hide_dropdown_menu(menuid,info){
    if (Browser_is_unsupported) return;
    menus_desired_state_array[menuid]='close';
    setTimeout('updatemenus()', 5);
    //debugtext+='hide-'+info+'-'+menuid+'<br>';
}
function click_dropdown_menubutton(menuid,info){ hide_dropdown_menu(menuid,info); }
function click_dropdown_entry(menuid,info) {
    if (Browser_is_unsupported) return;
    hide_dropdown_menu(menuid,info);
    //document.getElementById('loading_message').innerHTML='LADEN '+menuid;
}
// + fix dropdown entry width for IE6, can be disabled for other browsers
function mouseover_dropdown_entry(entryid) {
    if (Browser_is_unsupported) return;
    entry=document.getElementById('dropdown_entry_'+entryid);
    entry.style.width=active_dropdown_entry_width+'px';
}

function debugdisplay() {
    if (!js_Client_is_Developer) return;
    dtxt=debugtext_static;
    if (dtxt!='') dtxt+='<br>';
    dtxt+=debugtext;
    if (dtxt=='') return;
    testdiv=document.getElementById("test")
    while(testdiv.firstChild) testdiv.removeChild(testdiv.firstChild);
    testdiv.appendChild(document.createTextNode(dtxt));
}

function w_onload_debug() {
    if (js_Client_is_Developer)
        setInterval ("debugdisplay()", 200 );
}

function w_onload_browser_supported() {
    if (Browser_is_unsupported) {
	    Amenu_sub_container=document.getElementById('menu_sub_container_id');
	    if (Amenu_sub_container!=null) Amenu_sub_container.style.visibility = "visible";

	    div_preview=document.getElementById("browser_unsupported");
	    div_preview.innerHTML=unsupported_text;
        return false;
    }
    return true;
}

function w_onload_fix_minheight_bug() {
    // fix FF 1.5/2.0 / Safari Bug (set background div height large enough so thjat background-image gets shown by buggy browsers)
    maindiv=document.getElementById("main_container");
    contentdiv=document.getElementById("main_content_sidebar_container");
    maindiv.style.height=contentdiv.offsetTop+contentdiv.offsetHeight+'px';
}

function w_onload_handle_menu() {
    // set x-pos of submenu
    if (ActiveMenuID == '') return;

	Amain_menu_container=document.getElementById("main_menu_container");
	active_main_button_span=document.getElementById('menu_button_span_'+ActiveMenuID);
	active_main_button=document.getElementById('menu_button_'+ActiveMenuID);
	
	Amenu_sub_container=document.getElementById('menu_sub_container_id');
	if (Amenu_sub_container==null) return;

    center_it=(active_main_button_span.offsetWidth-Amenu_sub_container.offsetWidth)/2; /* center to parent button */
    if (center_it>0) center_it=0; /* but align to parent button left if parent button is larger */
    newx=active_main_button_span.offsetLeft;

    maxnewx=1000-Amenu_sub_container.offsetWidth;
    minnewx=0;
    if (newx>maxnewx) newx=maxnewx;
    if (newx<minnewx) newx=minnewx;

    Amenu_sub_container.style.left=newx+"px";
	Amenu_sub_container.style.visibility = "visible";

    if (!Browser_is_FF_old && !Browser_is_Opera) {
	    menubutton_below=document.getElementById('menu_mainbutton_active_below');
	    menubutton_below.innerHTML=" ";
	    menubutton_below.style.width=active_main_button.offsetWidth-0+"px";
	    //alert(menubutton_below.offsetWidth);
	}
}

function w_onload_handle_logo() {
    // set logo image (gif for IE 6 / png for others)
    logoimg=document.getElementById("main_logo_image");
    if (logoimg==null) return;
    if (Browser_is_IE_6_or_lower)  logoimg.src=js_ThemeImageDir+"logo-fraktal-cyan.gif";
    else               logoimg.src=js_ThemeImageDir+"logo-fraktal-cyan.png";
}

function w_onload_silver() {
    w_onload_debug();
    if (!w_onload_browser_supported()) return;
    w_onload_fix_minheight_bug();
    w_onload_handle_logo();
    w_onload_handle_menu();
    
    commentarea=document.getElementById("PageCommentInterface_Form_PostCommentForm_Comment");
    if (commentarea!=null) {
        commentarea.cols=80; commentarea.rows=5;
    }
}

function w_onload_menuonly() {
    w_onload_debug();
    if (!w_onload_browser_supported()) return;
    w_onload_handle_logo();
    w_onload_handle_menu();
}


function form_custom_filter_keys(e) {
     var key;
     if(window.event) key = window.event.keyCode;     //IE
     else key = e.which;     //firefox
     if(key == 13) return false;
     else return true;
}


