//================================================
//
//  Slavon.net menu v0,7b "write" lib
//
//   menu_x - x of "place_menu"
//   menu_y - y of "place_menu"
//   temp_menu - menu array by id (ex: menu[i].pid = 2)
//   index_menu - indexes between menu[] and temp_menu
//   menu_gen - menu (ID) already generated
//
//////////////////////////////////////////////////
//
//   TO DO:
//   1. menu[id].ori have 0,2 ; need 1,3
//   2. menu[id].type - horizontal, vertical
//   3. cellpadding - ok; cellspacing - need check
//   4. Optimization :)
//
//
//================================================

function is_child(id) {
	var i;
	for(i=1; i<menu.length; i++)
		if (menu[i].pid==id)
			return true;

	return false;
}

function write_menu_l1(ox, oy){
	if (!isDOM) return true;
	menu_x = ox;
	menu_y = oy;
	write_menu_custom(0);
}
function write_menu_other(){
	if (!isDOM) return true;
}
function write_menu_custom(id){
	if (!isDOM) return true;
	var temp_menu = new Array();
	var index_menu = new Array();
	var str = '';


	for(i=0; i<menu_gen.length; i++)
	if (menu_gen[i] == id)
	return true;

	for(i=1; i<menu.length; i++)
	if (menu[i].pid == id){
		temp_menu[(temp_menu.length?temp_menu.length:0)] = menu[i];
		index_menu[(index_menu.length?index_menu.length:0)] = i;
	}
	if (temp_menu.length){
		if (menu_gen.length && menu[id].ori== 2){
			xx = menu[id].x + menu[id].w;
			yy = menu[id].y;
			//            alert(yy);
		}else{
			xx = menu_gen.length?menu[id].x:'';
			yy = menu_gen.length?(menu[id].y + menu[id].h):'';
		}

		if (!menu_gen.length){
			str = '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
			for(i=0; i<temp_menu.length; i++){
				if (temp_menu[i].div_style){

					str += '<tr>';
					str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" class="table-lmenu2-s">';
					str += '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr>';
					str += '<TD width="100%" height="19"><A href="'+ temp_menu[i].url + '">' + temp_menu[i].text +'</A></TD>';
					str += '</tr></table>';
					str += '</td>';
					str += '</tr>';

					//   str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '"><a href="'+ temp_menu[i].url + '">' + temp_menu[i].text +'</a></td>';
				}else{
					str += '<tr>';
					str += '<td onclick="document.location=\'' + temp_menu[i].url + '\';" id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');this.className = \'table-lmenu-s\';" onmouseout="td_menu_out();this.className = \'table-lmenu\';"' + ' class="table-lmenu">';
					str += '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr>';
					str += '<td width="100%" height="19"><a href="'+ temp_menu[i].url + '">' + temp_menu[i].text +'</a></td>';
					str += '</tr></table>';
					str += '</td>';
					str += '</tr>';

				}
					if ((temp_menu.length-1) != i ){
						str += '<tr>';
						str += '<TD class="r"><DIV style="width: 0px; height: 1px;"><SPACER type="block" height="1"></SPACER></DIV></TD>';
						str += '</tr>';
					}
				
				if (menu[index_menu[i]].div_style && is_child(index_menu[i]))
				for(k=1; k<menu.length; k++){
					if (k==1){
						str += '<TR>';
						str += '<TD width="100%" style="height: 100%">';
						str += '<TABLE border="0" cellspacing="0" cellpadding="0" style="height: 100%">';
						str += '<TR style="height: 100%"><TD height="100%" style="height: 100%">';
						str += '<TABLE border="0" cellspacing="0" cellpadding="0" style="height: 100%">';
						str += '<TR><TD><DIV style="width: 0px; height: 10px;"><SPACER type="block" height="10"></SPACER></DIV></TD></TR>';
						str += '<TR style="height: 100%"><TD><DIV style="width: 21px;"><SPACER type="block" width="21"></SPACER></DIV></TD>';
						str += '<TD background="/common/img/pol_2.gif" height="100%"><DIV style="width: 15px;"><SPACER% type="block" width="15"></SPACER></DIV></TD>';
						str += '</TR><TR><TD><DIV style="width: 0px; height: 10px;"><SPACER type="block" height="10"></SPACER></DIV></TD></TR>';
						str += '</TABLE></TD><TD width="100%">';
						str += '<TABLE border="0" cellspacing="0" cellpadding="0" width="100%">';
						str += '<TR><TD valign="top"><TABLE border="0" cellspacing="0" cellpadding="0" width="100%">';
					}

					if (menu[k].pid == index_menu[i]){

						if (menu[k].div_style){

							str += '<tr><td class="lmenu2-s">';
							str += '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr>';
							str += '<td width="100%" height="19"><a href="'+menu[k].url+'"><b>'  + menu[k].text + '</b></a></td>';
							str += '</tr></table>';
							str += '</td>';
							str += '</tr>';

							if (menu[k].div_style && is_child(k))
							for(kk=1; kk<menu.length; kk++){
								if (kk==1){
									str += '<TR>';
									str += '<TD width="100%" style="height: 100%">';
									str += '<TABLE border="0" cellspacing="0" cellpadding="0" style="height: 100%">';
									str += '<TR style="height: 100%"><TD height="100%" style="height: 100%">';
									str += '<TABLE border="0" cellspacing="0" cellpadding="0" style="height: 100%">';
									str += '<TR><TD><DIV style="width: 0px; height: 10px;"><SPACER type="block" height="10"></SPACER></DIV></TD></TR>';
									str += '<TR style="height: 100%"><TD><DIV style="width: 0px;"><SPACER type="block" width="0"></SPACER></DIV></TD>';
									str += '<TD background="/common/img/pol_2.gif" height="100%"><DIV style="width: 15px;"><SPACER% type="block" width="15"></SPACER></DIV></TD>';
									str += '</TR><TR><TD><DIV style="width: 0px; height: 10px;"><SPACER type="block" height="10"></SPACER></DIV></TD></TR>';
									str += '</TABLE></TD><TD width="100%">';
									str += '<TABLE border="0" cellspacing="0" cellpadding="0" width="100%">';
									str += '<TR><TD valign="top"><TABLE border="0" cellspacing="0" cellpadding="0" width="100%">';
								}
								if (menu[kk].pid == k){
									if (menu[kk].div_style){

										str += '<tr><td class="lmenu2-s">';
										str += '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr>';
										str += '<td width="100%" height="19"><a href="'+menu[kk].url+'"><b>'  + menu[kk].text + '</b></a></td>';
										str += '</tr></table>';
										str += '</td>';
										str += '</tr>';
									}else{
										str += '<tr><td onmouseover="this.className = \'lmenu2-s\';" onmouseout="this.className = \'lmenu2\';" class="lmenu2">';
										str += '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr>';
										str += '<TD width="100%" height="19"><A href="'+menu[kk].url+'">'  + menu[kk].text + '</A></td>';
										str += '</tr></table>';
										str += '</td>';
										str += '</tr>';
									}
								}

								if ((menu.length-1) == kk ){
									str += '</TABLE>';
									str += '</TD></TR></TABLE>';
									str += '</TD></TR></TABLE>';
									str += '</TD></TR>';
								}
							}



						}else{
							str += '<tr><td onmouseover="this.className = \'lmenu2-s\';" onmouseout="this.className = \'lmenu2\';" class="lmenu2">';
							str += '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr>';
							str += '<TD width="100%" height="19"><A href="'+menu[k].url+'">'  + menu[k].text + '</A></td>';
							str += '</tr></table>';
							str += '</td>';
							str += '</tr>';
						}
					}
					if ((menu.length-1) == k ){
						str += '</TABLE>';
						str += '</TD></TR></TABLE>';
						str += '</TD></TR></TABLE>';
						str += '</TD></TR>';
						str += '<tr>';
						str += '<TD class="r"><DIV style="width: 0px; height: 1px;"><SPACER type="block" height="1"></SPACER></DIV></TD>';
						str += '</tr>';
					}
				}
			}
			str += '</table>';
		}else{
			str = "<div id='a" + id + "' name='a" + id + "' style='width: 166px; position: absolute; left: " + xx + "px; top: " + yy + "px; visibility: visible; z-index: 999999;'>";
			str += '<table border="0" cellspacing="0" cellpadding="0" width="166">';
			str += '<tr valign="top">';
			str += '<td background="/common/img/d_m_u_bg.gif"><img src="/common/img/d_m_u_1.gif" width="5" height="13" border="0" alt=""></td>';
			str += '<td width="157">';
			str += '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
			str += '<tr><td bgcolor="#b4b4b4"><div style="height: 1px; width: 0px;"><spacer type="block" height="1"></spacer></div></td></tr>';
			str += '</table>';
			str += '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
			for(i=0; i<temp_menu.length; i++){
				str += '<tr>';
				str += '<td onclick="document.location=\'' + temp_menu[i].url + '\';" id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');this.className = \'table-umenu-s\';" onmouseout="td_menu_out();this.className = \'table-umenu\';" class="table-umenu"><table border="0" cellspacing="0" cellpadding="2" width="100%">';
				str += '<tr>';
				str += '<td><a href="' + temp_menu[i].url + '">' + temp_menu[i].text + '</a></td>';
				str += '</tr>';
				str += '</table></td>';
				str += '</tr>';


				if ((temp_menu.length-1) != i ){
					str += '<tr>';
					str += '<td><table border="0" cellspacing="0" cellpadding="0" width="100%">';
					str += '<tr><td bgcolor="#d5d5d5"><div style="height: 1px; width: 0px;"><spacer type="block" height="1"></spacer></div></td></tr>';
					str += '</table></td>';
					str += '</tr>';
				}
			}

			str += '</table>';
			str += '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
			str += '<tr><td bgcolor="#b4b4b4"><div style="height: 1px; width: 0px;"><spacer type="block" height="1"></spacer></div></td></tr>';
			str += '<tr><td bgcolor="#ffffff"><div style="height: 1px; width: 0px;"><spacer type="block" height="1"></spacer></div></td></tr>';
			str += '<tr><td bgcolor="#b4b4b4"><div style="height: 1px; width: 0px;"><spacer type="block" height="1"></spacer></div></td></tr>';
			str += '</table>';
			str += '</td>';
			str += '<td bgcolor="#244f7f"><div style="height: 0px; width: 4px"><spacer type="block" width="4"></spacer></div></td>';
			str += '</tr>';
			str += '</table>';
			str += "</div>";
		}
		if(menu_gen.length){
			getRef('place_menu2').innerHTML += str;
		}else{
			getRef('place_menu').innerHTML = str;
		}
		for(i=0; i<temp_menu.length; i++){
			if (menu_gen.length){
				menu[index_menu[i]].x = getRef("a" + id).offsetLeft + getRef("td_" + index_menu[i]).offsetLeft;
				menu[index_menu[i]].y = getRef("a" + id).offsetTop + getRef("td_" + index_menu[i]).offsetTop;
			}else{
				menu[index_menu[i]].x = menu_x + getRef("place_menu").offsetLeft + getRef("td_" + index_menu[i]).offsetLeft + 0;
				menu[index_menu[i]].y = menu_y + getRef("place_menu").offsetTop + getRef("td_" + index_menu[i]).offsetTop + 0;
			}
			menu[index_menu[i]].h = getRef("td_" + index_menu[i]).offsetHeight;
			menu[index_menu[i]].w = getRef("td_" + index_menu[i]).offsetWidth;
		}
		menu_gen[(menu_gen.length?menu_gen.length:0)] = id;
	}
}

function clear_all(){
	if (!isDOM) return true;
	menu_show = new Array();
	menu_gen = new Array();
	menu_id = "";
	menu_status = 0;
	getRef('place_menu2').innerHTML = "";
	getRef('place_menu').innerHTML = "";
	write_menu_l1(menu_x, menu_y);
}
