//Pop-it menu- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use
var linkset=new Array();
var ie4=document.all;
var ns6=document.getElementById&&!document.all;
var ns4=document.layers;
var src_Popup = null;
function showmenu(src,e,which,style_menu){
	//style_menu = 0: horizontal menu, = 1: vertical menu
	if (!document.all&&!document.getElementById&&!document.layers)
		return;
	clearhidemenu();
	menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : "";
	menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj;
	//Dat lai do rong menu gia tri rong
	menuobj.thestyle.width = '';
	if (ie4||ns6)
		menuobj.innerHTML=which;
	else{
		menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=200 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+which+'</layer>');
		menuobj.document.close();
	}
	menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width;
	//Neu do rong qua nho thi dat la 140
	if(menuobj.contentwidth<140){
		menuobj.contentwidth = 140;
		menuobj.thestyle.width = 140;
	}
	//Chinh do rong cua cac menu item theo menu cha
	if(ie4){
		menuItems = menuobj.getElementsByTagName("div");
		for(i=0;i<menuItems.length;i++){
			menuItems[i].style.width = menuobj.contentwidth;//-1;
		}
	}
	menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height;
	eventX=ie4? event.clientX : ns6? e.clientX : e.x;
	eventY=ie4? event.clientY : ns6? e.clientY : e.y;
	
	aTag = src;
	toppos = 0;
	leftpos = 0;
	toppos += aTag.offsetTop;
	do{
		aTag = aTag.offsetParent;
		toppos += aTag.offsetTop;
		leftpos += aTag.offsetLeft;
	}while(aTag.tagName!="BODY");
	//Find out how close the mouse is to the corner of the window
	var bottomedge = ie4? document.body.clientHeight-eventY : window.innerHeight-eventY;
	var rightedge = ie4? document.body.clientWidth-leftpos - src.clientWidth: window.innerWidth-leftpos - src.clientWidth;
	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if(style_menu!=1){
		if (rightedge<menuobj.contentwidth){
			//move the horizontal position of the menu to the left by it's width
			menuobj.thestyle.left = leftpos - menuobj.contentwidth - 1;
			menuobj.className = "menuskin_right";
		}else{
			//position the horizontal position of the menu where the mouse was clicked
			menuobj.thestyle.left = leftpos + src.offsetLeft + src.clientWidth;
			menuobj.className = "menuskin_left";
		}	
		//same concept with the vertical position
		if (bottomedge<menuobj.contentheight){
			menuobj.thestyle.top = toppos-menuobj.contentheight+src.clientHeight;//+4;
		}else{
			menuobj.thestyle.top = toppos;// - 4;
		}
	}else{
		menuobj.className = "menuskin";
		if (rightedge<menuobj.contentwidth){
			//move the horizontal position of the menu to the left by it's width
			menuobj.thestyle.left = leftpos - menuobj.contentwidth + src.clientWidth;
		}else{
			//position the horizontal position of the menu where the mouse was clicked
			menuobj.thestyle.left = leftpos + src.offsetLeft;
		}	
		//same concept with the vertical position
		if (bottomedge<menuobj.contentheight){
			menuobj.thestyle.top = toppos-menuobj.contentheight-src.clientHeight-src.offsetHeight;
		}else{
			menuobj.thestyle.top = toppos + src.offsetHeight;
		}
	}
	src_Popup = src;
	menuobj.thestyle.visibility = "visible";
	Menu_hideElement('SELECT',menuobj);
	Menu_hideElement('APPLET',menuobj);
	return false;
}
function contains_ns6(a, b) {
//Determines if 1 element in contained in another
	while (b.parentNode)
		if ((b = b.parentNode) == a) return true;
	return false;
}
function hidemenu(){
	if (window.menuobj){
		menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide";
	}	
}
function dynamichide(e){
	if (ie4&&!menuobj.contains(e.toElement))
		hidemenu();
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		hidemenu();
}
function delayhidemenu(){
	if (ie4||ns6||ns4)
		delayhide=setTimeout("hidemenu()",200);
	Menu_showElement('SELECT');
	Menu_showElement('APPLET');	
	if(src_Popup!=null) {
		IB_Out(src_Popup);
	}		
}
function clearhidemenu(){
	if (window.delayhide)
		clearTimeout(delayhide);
}
function highlightmenu(e,state){
	if (document.all)
		source_el=event.srcElement;
	else if (document.getElementById)
		source_el=e.target;
	if(src_Popup!=null) {
		if(state!="off"){
			IB_Over(src_Popup);
		}else{
			IB_Out(src_Popup);
		}	
	}
	if (source_el.className=="menuitems"){
		source_el.id=(state=="on")? "menuitems_hover" : "";
	}else{
		while(source_el.id!="popmenu"){
			source_el=document.getElementById? source_el.parentNode : source_el.parentElement;
			if (source_el.className=="menuitems"){
				source_el.id=(state=="on")? "menuitems_hover" : "";
			}
		}
	}
}
if (ie4||ns6)
document.onclick=hidemenu;
////////////////////
function Menu_hideElement( elmID, overDiv ){
    if(ie4||ns6){
		for( i = 0; i < document.getElementsByTagName(elmID).length; i++ ){
			var obj = document.getElementsByTagName(elmID)[i];
			if( !obj || !obj.offsetParent ){
				continue;
			}      
			var objLeft   = obj.offsetLeft;
			var objTop    = obj.offsetTop;
			var objParent = obj.offsetParent;
			while( objParent.tagName.toUpperCase() != "BODY" ){
				objLeft  += objParent.offsetLeft;
				objTop   += objParent.offsetTop;
				objParent = objParent.offsetParent;
			}
			var objHeight = obj.offsetHeight;
			var objWidth = obj.offsetWidth;
	        
			if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
			else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
			else if( overDiv.offsetTop >= ( objTop + objHeight ));
			else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
			else{
				obj.style.visibility = "hidden";
			}
		}
    }
}   
function Menu_showElement(elmID){
    if(ie4||ns6){
		for( i = 0; i < document.getElementsByTagName(elmID).length; i++ ){
			var obj = document.getElementsByTagName(elmID)[i];
			if(!obj || !obj.offsetParent){
				continue;
			}
			obj.style.visibility = "";
		}
    }
}
function Add_sMenu(sVar,sTitle){
	return '<div class="menuitems" onclick="SubMenu_Click('+ sVar + ');">' + sTitle + '</div>';
}
function Add_Menu(sVar,sTitle){
	return '<div class="menuitems" onclick="IBEx_Click('+ sVar + ');">' + sTitle + '</div>';
}