function toggleContactSelect(show){
	var wrapper = document.getElementById('contactSelectWrapper');
	if (show){
		wrapper.style.display = 'block';
	} else {
		wrapper.style.display = 'none';
	}
}



function triggerZIP(){
	var zip = document.getElementById('contactSelectZIPWrapper');
	var country = document.getElementById('contactSelectCountry');
	
	if (country.value == 'DE'){
		zip.style.display = 'block';
	} else {
		zip.style.display = 'none';
	}
}



function centerDropdowns(){
	var	topLevel = $('menu-hauptmenu');
	
	topLevel.getElements('li').each(function(el){
		var listRef = el.getElement('.sub-menu');
		
		//Only calculate new margin if link has a sub-menu
		if(listRef != null && listRef.getParent().getParent().get('class') != 'sub-menu'){
			//Remove top border from first sub-menu entry
			listRef.getElement('.menu-item').setStyle('background','none');

			//Center sub-menu on mouseover
			el.addEvent('mouseenter',function(){
				var linkRef = el.getElement('a');
				var linkWidth = linkRef.getStyle('width').replace('px','');
				var menuWidth = listRef.getStyle('width').replace('px','');
				
				//20px subtracted from width for link padding
				var width = parseInt((menuWidth - linkWidth)/2)-15;
				
				listRef.setStyle('marginLeft',-width+'px');
			});
			addUpArrow(listRef);
		}
	});
}



/*
 * Adds a small arrow to the top of the submenu which is provided
 * as an element. The submenu also receives a top margin to 
 * compensate for the required space of the arrow.
 *
 * @param subMenu expects a submenu of the the main menu as an
 * element
 */
function addUpArrow(subMenu){
	//Push all sub-menus 12px down to make room for arrow
	subMenu.setStyle('marginTop','10px');
	
	//Create arrow
	var arrow = document.createElement('span');
	arrow.setAttribute('class','navArrow');

	//Add arrow to sub menu
	subMenu.appendChild(arrow);
}



function submitenter(myfield,e){
	var keycode;
	if (window.event) 
		keycode = window.event.keyCode;
	else if (e) 
		keycode = e.which;
	else 
		return true;
	
	if (keycode == 13)
	   {
	   myfield.form.submit();
	   return false;
	   }
	else
	   return true;
}



// JavaScript Document
window.addEvent('domready',function(){
	centerDropdowns();
});
