var lPrev='';

var lParent='';

var lTimeout=false;


function menuOver(pEv) {

	if(pEv.srcElement) lEl=pEv.srcElement;

	else lEl=pEv.target;

	if(lTimeout) window.clearTimeout(lTimeout);

	lTimeout=setTimeout("menu(lEl)", 500);

}


function menu(pEl) {

	if(lEl=getEl(pEl, "menu_")) {

		var lBr=new Array();

		var lIndex=lEl.id.substr(5);

		if (lIndex.indexOf('_')==-1)

			lParent=document.getElementById('submenu_');

		else {

			lParent=document.getElementById('submenu_'+lIndex.substr(0, lIndex.lastIndexOf('_'))).rows[0].cells[0]; 

			if(lParent.childNodes[0].tagName=='TABLE')

				lParent=lParent.childNodes[0];

			else lParent=lParent.childNodes[1];

		}

		

		if (document.getElementById('submenu_'+lIndex) && document.getElementById('submenu_'+lIndex).style.display=='block')

			closeNode(lIndex, -1);

		openParentNode('_'+lIndex);

		

		if(lIndex.indexOf('_')==-1 && lIndex!=lPrev && document.getElementById('submenu_'+lIndex))

			lPrev=lIndex;

		

		if (lIndex.indexOf('_')==-1) { //Исключение для меню, начнающегося со второго уровня

			var menuCnt=document.getElementById('submenu_counter').value - 1;

			for (var jj=1; jj<=menuCnt; jj++)

				if(document.getElementById('submenu_'+jj) && document.getElementById('submenu_'+jj).style.display=='block' && jj!=lIndex)

					closeNode(jj, 1);

		}

		else {

			lCh=lParent.rows;

			for (var i=0;i<lCh.length;i++) {

				lC=lCh[i].cells;

				for (var j=0;j<lC.length;j++)

					if (lC[j].id.substr(0, 5)=='menu_' && lC[j].id!=lEl.id)

						lBr[lBr.length]=lC[j].id.substr(5);

			}

			for(var z=0;z<lBr.length;z++)

				if(document.getElementById('submenu_'+lBr[z]) && document.getElementById('submenu_'+lBr[z]).style.display=='block')

					closeNode(lBr[z], 1);

		}


	}

	else if (lPrev!='') {

		closeNode(lPrev, 1);

		lPrev='';

	}

}


function closeNode(pIndex, pF) {

	if (pF==1) {

		document.getElementById('submenu_'+pIndex).style.display='none';

		document.getElementById('submenu_'+pIndex).style.visibility='hidden';	

	}

	for (var i=1; document.getElementById('menu_'+pIndex+'_'+i);i++)

		if(document.getElementById('submenu_'+pIndex+'_'+i) && document.getElementById('submenu_'+pIndex+'_'+i).style.display=='block')

			closeNode(pIndex+'_'+i, 1);

}


function openParentNode(pIndex){

	while(pIndex.indexOf('_')!=-1){

		if(e=document.getElementById('submenu'+pIndex)) {

			e.style.display='block';

			e.style.visibility='visible';

		}

		pIndex=pIndex.substr(0, pIndex.lastIndexOf('_'));

	}

}


function getEl(el, pId) {

	if(el && el.tagName) {

		while (el.tagName.toLowerCase() != "body") {

			if (el.id.substr(0, pId.length) == pId)	return el;

			if (el.id.substr(0, 8) == "submenu_" && el.id.length>8)

				el=document.getElementById(pId+el.id.substr(8));

			else	el = el.parentNode;

		}

	} return false;

}







function checkDate(){

	var dateDayObj = document.getElementById('querydataday').options[document.getElementById('querydataday').selectedIndex];

	var dateMonthObj = document.getElementById('querydatamonth').options[document.getElementById('querydatamonth').selectedIndex];

	var formObj = document.getElementById('queryform');


	var monthCompare = new Array();


	monthCompare['Январь'] = 31;

	monthCompare['Февраль'] = 29;

	monthCompare['Март'] = 31;

	monthCompare['Апрель'] = 30;

	monthCompare['Май'] = 31;

	monthCompare['Июнь'] = 30;

	monthCompare['Июль'] = 31;

	monthCompare['Август'] = 31;

	monthCompare['Сентябрь'] = 30;

	monthCompare['Октябрь'] = 31;

	monthCompare['Ноябрь'] = 30;

	monthCompare['Декабрь'] = 31;


	if (dateDayObj.text == '' || dateMonthObj.text == '' || dateDayObj.text > monthCompare[dateMonthObj.text]) {

		alert('Ошибка!!! Не корректо заполнена дата!');

	}

	else {

		formObj.submit();

	}

}
