womAdd('initPopMenu()');

function initPopMenu(){
	/* ensure that search elements are represented on page - if not then quit */
	if(document.getElementById("searchPopMenuLink")
	&& document.getElementById("searchMenu")){
	
	    a = document.getElementById("searchPopMenuLink");

		a.onclick = function(){
			show("searchMenu");
          
			try{
				document.getElementById("query").focus();
			}
			catch(e){
			/* focus failed */
			}

			return false;
		}
		
		a = document.getElementById("queryLink");
		
		a.onclick = function(){
            document.getElementById('searchForm').submit();
			return false;
		}		
	 }
}
    
function show(idx){

    borderHeight = 0;
	borderWidth = 0;

	if(idx=="searchMenu"){	    
		showhide(document.getElementById("searchMenu"));
		setmark(document.getElementById("searchContainer"));
	}
	    
	borderHeight = document.getElementById(idx).offsetHeight + 4;
	borderWidth = document.getElementById(idx).offsetWidth;
	
	document.getElementById("popBorder").style.width = borderWidth + "px";
	document.getElementById("popBorder").style.height = borderHeight + "px";
}

function calcPosition(idx){
    containerWidth = document.getElementById("popNavigation").offsetWidth;
    popPosition = document.getElementById(idx).offsetWidth;
    
    if(document.getElementsByTagName("body").item(0).className == "screen_hi") position = containerWidth - popPosition - 12;
    else position = containerWidth - popPosition - 4;
    
    return position + "px";
}

function showhide(idx){
	vista = (idx.className == 'show') ? 'hide' : 'show';
	idx.className = vista;
	
    if(document.getElementById("logonMenu")){
        /* override stylesheet if width is larger than default 160px */
	    ulWidth = idx.getElementsByTagName("ul").item(0).offsetWidth;
	    if(ulWidth>160) idx.style.width = ulWidth + "px";
	    
        popPosition = calcPosition(idx.id);
    }
    else{
        /* no logon dropdown - we need to adjust the search popup layer */
        popPosition = "-2px";
        document.getElementById("searchMenu").style.left = "-5px";
    }
	
	if(vista == "show") document.getElementById("popBorder").style.left = popPosition;
	else document.getElementById("popBorder").style.left = "-4000px";
}

function setmark(idx){
	mark = (idx.className == 'marked') ? '' : 'marked';
	idx.className = mark;
}
