var current_menu=null;
document.onclick=hide_menu;
//document.onkeydown=handle_keydown;


function textcounter(x) {
	if(!x.maxlimit){
		max = new getObj("max_" + x.id);
		if(max) x.maxlimit = 1*max.obj.innerHTML;
	}
	if(!x.count_obj) x.count_obj = new getObj("count_" + x.id);
	if(x.value.length >= x.maxlimit) alert ("You've reached the maximum text limit for this field.");
    if (x.value.length > x.maxlimit) {
      x.value = x.value.substring(0, x.maxlimit-1);
     }
    x.count_obj.obj.innerHTML = (x.maxlimit - x.value.length);
 }



function top_menu_setup(){
	var top_menu = new getObj('topbar');
	if(top_menu){
//		alert(top_menu.obj.innerHTML);
		var cells = top_menu.obj.getElementsByTagName('td');
		for(var x in cells){
			if(cells[x].id) top_menu_cell_setup(cells[x]);
		}
	}
}

function top_menu_cell_setup(x){
	var myid = x.id;
//	alert(x.id);
	var mydisp = new getObj(myid);
	x.display = mydisp;
	var mymenu = new getObj(myid + "-menu");
	if(mymenu){
//		alert(myid + "-menu");
		x.menu = mymenu;
		x.menu.style.display="none";
	}
	x.onmouseover = show_menu;
}

function set_pos(m,p){
	m.style.left = getPosX(p.obj) + "px";
	m.style.top = (getPosY(p.obj) + p.obj.offsetHeight) + "px";
}

function show_menu(e){
	set_pos(this.menu,this.display); 
	if(this.menu.style.display=='none'){
//		alert('showing menu '+ this.menu.style.display);
		hide_menu(e);
		this.menu.style.display='';
		current_menu=this;
	} 
	cancel_bubble(e);
}

function hide_menu(e){
	if(current_menu){
		current_menu.menu.style.display='none';
	}
	current_menu=false;
}