////////////////////////////////////////////////////
// Copyright by Vitaliy Ostrovsky(vitos@ukr.net)
////////////////////////////////////////////////////
vm_menu=new Array()
function vMenu(objName,expandDir,redirect,target) {	
	this.objName=objName
	//window.alert(redirect_) 
	this.redirect=redirect
	this.target=target
	vm_menu[vm_menu.length]=objName
	this.show=vm_show
	this.addItem=vm_addItem
	this.showChilds=vm_showChilds
	this.hide=vm_hide
	this.delayHide=vm_delayHide
	this.clearHide=vm_clearHide
	this.left=100
	this.top=0
	this.height=15
	this.width=160
	this.offsetLeft=213
	this.offsetTop=-22
	this.overBgColor='#FFFFFF';
	this.outBgColor='#FFFFFF';
	this.divId='parent_div'+objName
	this.delay=200
	this.delayObj=0
	this.parent=0
	this.childs=new Array()
	if (expandDir)
		this.expandDir=expandDir
	else
		this.expandDir='right'
	var st_str=""
	if (this.width)
		st_str+="width:"+vm_parseInt(this.width)+"px;"
	if (this.heigth)
		st_str+="height:"+vm_parseInt(this.height)+"px;"
	document.write('<div id="'+this.divId+'" name="'+this.divId+'" class="vmenu_div" style="'+st_str+'"></div>')
}
function vm_addItem(item) {
	this.childs[this.childs.length]=item
	item.parent=this
	if (item.childObj) {
		item.childObj.parent=this
		item.childObj.expandDir=this.expandDir
	}
}
function vm_show(obj) {
	vm_hideAll();
	var divobj=document.getElementById?document.getElementById(this.divId):document.all?document.all[this.divId]:eval(this.divId)
	this.clearHide()
	var tmpStr='<table id="vmenu_main_'+divobj.name+'" border=0 cellpadding=0 cellspacing=0   width="100%">'
	if (this.childs)
		for(i=0;i<this.childs.length;i++) {
			tmpStr+='<tr><td colspan=2 height=10 id="table_'+this.childs[i].objName+'" background="/main/img/bg_thin_02.gif"></td></tr>'
			tmpStr+='<tr>'
			if (this.childs[i].childObj) {
				tmpStr+='<td width="10" background="/main/img/buttons_29.gif"></td><td  class="vmenu_link" background="/main/img/buttons_29.gif" onmouseover="'+this.childs[i].childObj.objName+'.showChilds(\''+i+'\')" onmouseout="'+this.childs[i].childObj.objName+'.delayHide()"><a href="'+this.childs[i].link+'" class="vmenu_link" target="'+this.childs[i].target+'">'+this.childs[i].name+'</a></td>'
			} else {
				tmpStr+='<td width="10" id="table2_'+this.childs[i].objName+'" background="/main/img/buttons_29.gif"></td><td  id="table3_'+this.childs[i].objName+'" class="vmenu_link" background="/main/img/buttons_29.gif" onmouseover="_showHideSelect(\''+this.divId+'\');ddd = document.getElementById(\'table_'+this.childs[i].objName+'\'); ddd.style.background=\'url(/main/img/bg_thin_02_a.gif)\';ddd = document.getElementById(\'table2_'+this.childs[i].objName+'\'); ddd.style.background=\'url(/main/img/buttons_29_a.gif)\';ddd = document.getElementById(\'vmenu_main_'+divobj.name+'\'); ddd.style.backgroundColor=\'#FBFBFB\';ddd = document.getElementById(\'table3_'+this.childs[i].objName+'\'); ddd.style.background=\'url(/main/img/buttons_29_a.gif)\'" onmouseout="ddd = document.getElementById(\'table_'+this.childs[i].objName+'\'); ddd.style.background=\'url(/main/img/bg_thin_02.gif)\';ddd = document.getElementById(\'table2_'+this.childs[i].objName+'\'); ddd.style.background=\'url(/main/img/buttons_29.gif)\';ddd = document.getElementById(\'vmenu_main_'+divobj.name+'\'); ddd.style.backgroundColor=\'#8AB3D6\';ddd = document.getElementById(\'table3_'+this.childs[i].objName+'\'); ddd.style.background=\'url(/main/img/buttons_29.gif)\'"><a href="'+this.childs[i].link+'" class="vmenu_link" target="'+this.childs[i].target+'">'+this.childs[i].name+'</a></td>'
			}
			tmpStr+='</tr>'
//			tmpStr+='<tr><td colspan=2><img src="/main/img/spacer.gif"  height="1"></td></tr>'
			tmpStr+='<tr><td bgcolor="#DBE6F0" colspan=2><img src="/main/img/spacer.gif"  height="2"></td></tr>'
//			tmpStr+='<tr>'
//              tmpStr+='<td width="10"><img src="/i/1.gif" width=1 height=1 border=0 vspace=0></td><td  background="/main/img/div_n_35.gif"><img src="/main/img/div_n_35.gif" width="3" height="1"></td>';
//            tmpStr+='</tr>'
		}
	tmpStr+='</table>'
//	window.alert(tmpStr)
	divobj.innerHTML=tmpStr
	if (this.expandDir=='right') {
		this.left=vm_getOffset(obj.offsetParent,'left')+vm_parseInt(obj.offsetLeft)+vm_parseInt(this.offsetLeft)
		this.top=vm_getOffset(obj.offsetParent,'top')+vm_parseInt(obj.offsetTop)+vm_parseInt(this.offsetTop)
	} else if (this.expandDir=='left') {
		this.left=vm_getOffset(obj.offsetParent,'left')+vm_parseInt(obj.offsetLeft)-vm_parseInt(this.offsetLeft)-vm_parseInt(this.width)+vm_parseInt(obj.offsetWidth)
		this.top=vm_getOffset(obj.offsetParent,'top')+vm_parseInt(obj.offsetTop)+vm_parseInt(this.offsetTop)
	}
	divobj.style.left=vm_parseInt(this.left)+"px"
	divobj.style.top=vm_parseInt(this.top)+"px"
	var ouover,ouout,oclick;
	onover=eval("new Function('e','vm_clearHide(e,\""+this.objName+"\")')");
	onout=eval("new Function('e','vm_delayHide(e,\""+this.objName+"\")')");
	oclick=eval("new Function('e','vm_delayHide(e,\""+this.objName+"\")')");
	if (divobj.attachEvent) {
		divobj.attachEvent("onmouseover",onover)
		divobj.attachEvent("onmouseout",onout)
		divobj.attachEvent("onclick",oclick)
	} else if (divobj.addEventListener) {
		divobj.addEventListener("mouseover",onover,false)
		divobj.addEventListener("mouseout",onout,false)
		divobj.addEventListener("click",oclick,false)
	}
	
	divobj.style.visibility="visible";
	
	Vmenu_showHideSelect(divobj);

}
function vm_showChilds(pos) {
	var divobj=document.getElementById?document.getElementById(this.divId):document.all?document.all[this.divId]:eval(this.divId)
	_showHideSelect(this.divId); 
	this.offsetTop = pos*(this.parent.height-2);

	this.parent.clearHide()
	this.clearHide()
	var tmpStr='<table   border=0 cellpadding=0 cellspacing=0 width=100% class="vmenu_table">'
	if (this.childs)
		for(i=0;i<this.childs.length;i++) {
			tmpStr+='<tr><td colspan=2 height=11  background="/main/img/bg_thin_02.gif"></td></tr>'
			tmpStr+='<tr>'
			if (this.childs[i].childObj) {
				tmpStr+='<td  background="/main/img/buttons_29.gif" width=10><img src="/i/bullet_03.gif" border=0 hspace=5 vspace=4></td><td background="/main/img/buttons_29.gif" onmouseover="'+this.childs[i].childObj.objName+'.showChilds(\''+i+'\')" onmouseout="'+this.childs[i].childObj.objName+'.delayHide()"><a href="'+this.childs[i].link+'" class="vmenu_link"  target="'+this.childs[i].target+'">'+this.childs[i].name+'</a></td>'
			} else {
				tmpStr+='<td   background="/main/img/buttons_29.gif" width=10></td><td background="/main/img/buttons_29.gif" onmouseover="_showHideSelect(\''+this.divId+'\')" ><a href="'+this.childs[i].link+'" class="vmenu_link" target="'+this.childs[i].target+'">'+this.childs[i].name+'</a></td>'
			}
			tmpStr+='</tr>'
			tmpStr+='<tr><td colspan=2><img src="/main/img/spacer.gif"  height="2"></td></tr>'
			tmpStr+='<tr><td bgcolor="#DBE6F0" colspan=2><img src="/main/img/spacer.gif"  height="2"></td></tr>'
			
		}
	tmpStr+='</table>'
	divobj.innerHTML=tmpStr 
	
	margin_left = vm_parseInt(this.parent.left)+2*vm_parseInt(this.parent.width)+vm_parseInt(this.offsetLeft)
	if ( (document.body.clientWidth < margin_left)|| (this.parent.expandDir=='left')) this.expandDir='left';
	
	margin_right = vm_parseInt(this.parent.left)-vm_parseInt(this.parent.width)-vm_parseInt(this.offsetLeft)
	if ( (0 > margin_right)&& (this.expandDir=='left')) this.expandDir='right';
	
	//alert('margin_left='+margin_left+' '+document.body.clientWidth);
	if (this.expandDir=='right') {
		this.left=vm_parseInt(this.parent.left)+vm_parseInt(this.parent.width)+vm_parseInt(this.offsetLeft)
		//this.top=vm_parseInt(this.parent.top)+vm_parseInt(this.offsetTop)
		
	} else if (this.expandDir=='left') {
		this.left=vm_parseInt(this.parent.left)-vm_parseInt(this.parent.width)-vm_parseInt(this.offsetLeft)
		//this.top=vm_parseInt(this.parent.top)+vm_parseInt(this.offsetTop)
		
	}
	
	this.top = document.body.scrollTop+event.clientY-20;
	overBottom = document.body.clientHeight-(this.top+this.childs.length*this.parent.height);
	if (overBottom < 0) this.top=this.top+overBottom;

	divobj.style.left=vm_parseInt(this.left)+"px"
	divobj.style.top=vm_parseInt(this.top)+"px"
	var ouover,ouout,oclick;
	onover=eval("new Function('e','vm_clearHide(e,\""+this.objName+"\")')");
	onout=eval("new Function('e','vm_delayHide(e,\""+this.objName+"\")')");
	oclick=eval("new Function('e','vm_delayHide(e,\""+this.objName+"\")')");
	if (divobj.attachEvent) {
		divobj.attachEvent("onmouseover",onover)
		divobj.attachEvent("onmouseout",onout)
		divobj.attachEvent("onclick",oclick)
	} else if (divobj.addEventListener) {
		divobj.addEventListener("mouseover",onover,false)
		divobj.addEventListener("mouseout",onout,false)
		divobj.addEventListener("click",oclick,false)
	}
	divobj.style.visibility="visible";
	Vmenu_showHideSelect(divobj);
	
}
function vm_hide() {
	var divobj=document.getElementById?document.getElementById(this.divId):document.all?document.all[this.divId]:eval(this.divId)
	var divobjp=document.getElementById?document.getElementById(this.parent.divId):document.all?document.all[this.parent.divId]:eval(this.parent.divId)
	
	divobj.style.visibility="hidden"
	Vmenu_showHideSelect(divobj, 'hide');

	if (divobjp) Vmenu_showHideSelect(divobjp);

}
function vm_delayHide(e,objName) {
	var obj;
	if (typeof(objName)!="undefined")
		obj=eval(objName)
	else
		obj=this
	_showHideSelect(obj.divId); 

	
	if (obj.parent)
		obj.parent.delayHide()
	if (!obj.delayObj)
		obj.delayObj=setTimeout(obj.objName+".hide()",obj.delay)
	else {
		clearTimeout(obj.delayObj)
		obj.delayObj=setTimeout(obj.objName+".hide()",obj.delay)
	}
	if(e&&(typeof(e)!="undefined")&&e.stopPropagation)
		e.stopPropagation()
}
function vm_clearHide(e,objName) {
	var obj;
	if (typeof(objName)!="undefined")
		obj=eval(objName)
	else
		obj=this
	if (obj.delayObj) {
		clearTimeout(obj.delayObj)
		obj.delayObj=0
	}
	if (obj.parent) {
		obj.parent.clearHide()
	}
	if(e&&(typeof(e)!="undefined")&&e.stopPropagation)
		e.stopPropagation()
}
function vSubMenu(objName) {
	this.objName=objName
	vm_menu[vm_menu.length]=objName
	this.addItem=vm_addItem
	this.showChilds=vm_showChilds
	this.hide=vm_hide
	this.delayHide=vm_delayHide
	this.clearHide=vm_clearHide
	this.left=0
	this.top=0
	this.height=15
	this.width=160
	this.offsetLeft=0
	this.offsetTop=1000
	this.overBgColor2='#ffffff';
	this.outBgColor2='#ffffff';
	this.divId='childs_div'+objName
	this.delay=200
	this.delayObj=0
	this.childs=new Array()
	this.parent=0
	this.expandDir='right'
	eval(objName+"=this;")
	var st_str=""
	if (this.width)
		st_str+="width:"+vm_parseInt(this.width)+"px;"
	if (this.heigth)
		st_str+="height:"+vm_parseInt(this.height)+"px;"
	document.write('<div id="'+this.divId+'" name="'+this.divId+'" class="vmenu_div" style="'+st_str+'"></div>')
}

function vMenuItem(objName,name,link,hasChilds,redirect,target) {
	this.name=name
	this.link=link
	this.redirect=redirect
	this.target=target
	this.objName=objName
	this.childObj=0
	this.parent=0
	this.childs=0
	if (hasChilds) {
		this.childObj=new vSubMenu(objName)
	}
}
function vm_parseInt(num) {
	var t=parseInt(num);
	if (t&&!isNaN(t)) {
		return t;
	}
	return 0;
}
function vm_hideAll() {
	for(i=0;i<vm_menu.length;i++) {
		var tmp=eval(vm_menu[i])
		tmp.hide();
	}
}
function vm_getOffset(parent,which) {
	var ret_val=0;
	while(parent) {
		ret_val+=(which=='left'?vm_parseInt(parent.offsetLeft):vm_parseInt(parent.offsetTop));
		parent=parent.offsetParent
	}
	return ret_val;
}



function _showHideSelect(divId) {
 var divobj=document.getElementById?document.getElementById(divId):document.all?document.all[divId]:eval(divId)
 Vmenu_showHideSelect(divobj)	

}
function Vmenu_showHideSelect(element, action) {

		function getStyleProp(obj, style){
			var value = obj.style[style];
			if (!value) {
				if (document.defaultView && typeof (document.defaultView.getComputedStyle) == "function") { // Gecko, W3C
					value = document.defaultView.
						getComputedStyle(obj, "").getPropertyValue(style);
				} else if (obj.currentStyle) { // IE
					value = obj.currentStyle[style];
				} else {
					value = obj.style[style];
				}
			}
			return value;
		};

		var tags = new Array("applet", "select");
		var el = element;
	
		var p = vmenu_getAbsolutePos(el);
		var EX1 = p.x;
		var EX2 = el.offsetWidth + EX1;
		var EY1 = p.y;
		var EY2 = el.offsetHeight + EY1;
		
		for (var k = tags.length; k > 0; ) {
			var ar = document.getElementsByTagName(tags[--k]);
			var cc = null;
	
			for (var i = ar.length; i > 0;) {
				cc = ar[--i];
				if (cc.name == 'months' || cc.name == 'years') continue;
				
				p = vmenu_getAbsolutePos(cc);
				var CX1 = p.x;
				var CX2 = cc.offsetWidth + CX1;
				var CY1 = p.y;
				var CY2 = cc.offsetHeight + CY1;
				//alert(CX1+'>'+EX2+' '+CX2+'<'+EX1+' '+CY1+'>'+EY2+' '+CY2+'<'+EY1);
	      
				if (action == 'hide' || (CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) {
					
					if (!cc.__msh_save_visibility) {
						cc.__msh_save_visibility = getStyleProp(cc, "visibility");
					}
					cc.style.visibility = cc.__msh_save_visibility;
					//alert(cc.style.visibility);
				} else {

					if (!cc.__msh_save_visibility) {
						cc.__msh_save_visibility = getStyleProp(cc, "visibility");
					}
					cc.style.visibility = "hidden";
				}
			}
		}

	}
	
	function vmenu_getAbsolutePos(el) {
		var r = { x: el.offsetLeft, y: el.offsetTop };
		if (el.offsetParent) {
			var tmp = vmenu_getAbsolutePos(el.offsetParent);
			r.x += tmp.x;
			r.y += tmp.y;
		}
		return r;
	}