/* ********************************************************************* */

// Clear field value
function clearField(fld) {
	if (fld.value && fld.value == fld.defaultValue)
		fld.value = "";
}


function showElement(elementId) {
	var elementStyle = document.getElementById(elementId);

	if(elementStyle.style.visibility == "hidden" || elementStyle.style == "")
		document.getElementById(elementId).style.visibility = 'visible';
	else
		document.getElementById(elementId).style.visibility = 'hidden';
}

function closeElement(elementLinkId, elementId) { }




// ***********************************************************************************************
//  Menue Script
// ***********************************************************************************************
var mouse_in=-1;
var showTimer=null;
var hideTimer=null;
//navigation navigation.style.visibility="visible";

//count all LI nodes in this Node-Array
function count_li(knoten){
	count=0;
	for(z=0;z<knoten.length;z++){
		if(knoten[z].nodeName == "LI"){
			count++;
		}
	}
	return count;
}
//----------------------------------------------------
//get all subnodes with tag name from second parameter
//i.e. x = get_subnodesByTagName(document.getElementById('mainmenuInner'),"UL");
//----------------------------------------------------
function get_subnodesByTagName(knoten,tag_name){
	var childs=new Array();
	var c_pos=0;

	for(n=0;n<knoten.childNodes.length;n++){
		if(knoten.childNodes[n].nodeName == tag_name){
			childs[c_pos] = knoten.childNodes[n];
			c_pos++;
		}
	}
	return childs;
}

function count_elements(x){
	var count=0;
	ul_list1= get_subnodesByTagName(document.getElementById('mainmenuInner'),"UL");
	if(ul_list1.length>0){
		li_list1= get_subnodesByTagName(ul_list1[0],"LI");

		if(li_list1.length>0){
			ul_list2= get_subnodesByTagName(li_list1[x],"UL");  //Akt

			if(ul_list2.length>0){
				li_list2= get_subnodesByTagName(ul_list2[0],"LI");

				for(n3=0;n3<li_list2.length;n3++){
					ul_list3= get_subnodesByTagName(li_list2[n3],"UL");

					if(ul_list3.length>0){

						x=count_li(ul_list3[0].childNodes)
						if(x>count){
							count=x;
						}
					}

				}
			}
		}
	}
	if(count==1){count++;}
	return count;
}

//onmousover:
function show_dropdown(x){
	this.mouse_in = x;
	s=x;
	if(hideTimer!=null){
		clearTimeout(hideTimer);
	}
	if(showTimer!=null){
		clearTimeout(showTimer);
	}

	showTimer = setTimeout('show_dropdown_x(s)',150);	// geändert von 600 auf 150ms 16.9.09 tk
}

function show_dropdown_x(x){
	//hide the current displayed dropdown before showing the next
	hide_dropdown_x()

	this.mouse_last = -1;
	el = count_elements(x);
	//dropdownheaders
	ul_list1= get_subnodesByTagName(document.getElementById('mainmenuInner'),"UL");
	if(ul_list1.length>0){
		li_list1= get_subnodesByTagName(ul_list1[0],"LI");
		if(li_list1.length>0){
			ul_list2= get_subnodesByTagName(li_list1[x],"UL");

			// Menupunkt hover ein
			a_list = get_subnodesByTagName(li_list1[x],"A");
			if(a_list.length>0){
				a_list[0].className="submenu trail_hover";
			}

			if(ul_list2.length>0){  //if level2 headers exists
				if(el==0){ //just level2 headers and no subitems
					el =1;
				}
				ul_list2[0].style.height= el*3 +1.5+ "em";
				ul_list2[0].style.visibility="visible";
				//document.getElementById('navigation').style.background = "url('_images/version2/navigation/background_rubric_1_hover.jpg') no-repeat center left";
				//document.getElementById('navigation').className = "navigation_dropdown_hover";
				document.getElementById('mainmenuInner').className = "navigation_dropdown_hover mod_navigation block";
				// alert(document.getElementById('navigation').style.background);
			}else{
				if(el==0){ //if no level2 headers exists
					//document.getElementById('navigation').style.background = "url('_images/version2/navigation/background_rubric_1.jpg') no-repeat center left";
					//document.getElementById('navigation').className = "navigation_dropdown";
					document.getElementById('mainmenuInner').className = "navigation_dropdown mod_navigation block";
				}
			}
		}
	}
}

//--------onmouseout:    -----------------------
function hide_dropdown(){
	this.mouse_in=-1;
	if(showTimer!=null){
		clearTimeout(showTimer);
	}
    if(hideTimer!=null){
		clearTimeout(hideTimer);
	}
	hideTimer = setTimeout('hide_dropdown_x()',200);
}

function hide_dropdown_x(){

	//dropdownheaders
	ul_list1= get_subnodesByTagName(document.getElementById('mainmenuInner'),"UL");
	if(ul_list1.length>0){
		li_list1= get_subnodesByTagName(ul_list1[0],"LI");
		for(m=0;m<li_list1.length;m++){
			ul_list2= get_subnodesByTagName(li_list1[m],"UL");

			// Menupunkt hover ein
			a_list = get_subnodesByTagName(li_list1[m],"A");
			if(a_list.length>0 ) {
				a_list[0].className="submenu";
			}
			if(ul_list2.length>0){
				if(m!=this.mouse_in){
					ul_list2[0].style.visibility="hidden";
				}
			}
		}
	}
	if(mouse_in==-1){
		// document.getElementById('navigation').style.background = "url('_images/version2/navigation/background_rubric_1.jpg') no-repeat center left";
		//document.getElementById('navigation').className = "";
		document.getElementById('mainmenuInner').className = "navigation_dropdown mod_navigation block";
	}
}



                /*     not testet child event protection
                onclick= x(event,this)
                x  function(e,self)
                var targ;
                if (!e) e = window.event;//IE
                if (e.target) targ = e.target;//firefox
	             else if (e.srcElement) targ = e.srcElement;//IE
	             if (targ.nodeType == 3) // defeat Safari bug
		          targ = targ.parentNode;
		          if (targ==self){
                  // show/hide
                }
                */
