//для меню раскрывающегося

menu = {	"id1": '',
	"id2": ''}

mnTime = 1000;
hTimer1 = null;
hTimer2 = null;

mnsel = Array(7);
mnsel[0] = Array(4);
mnsel[1] = Array(1);
mnsel[2] = Array(3);
mnsel[3] = Array(3);
mnsel[4] = Array(3);
mnsel[5] = Array(3);
mnsel[6] = Array(4);
for(var i=0; i<mnsel.length; i++)
	for(var j=0; j<mnsel[i].length; j++){ mnsel[i][j] = 1; }
colorShow = "#aaaaaa";
colorHide = "#dddddd";

//----------- обработки для скрыть/показать пункты меню ----------
function mnOnTime1(){	if(menu.id1 != ''){		document.getElementById(menu.id1).style.display = 'none';
		menu.id1 = '';
	}}
function mnOnTime2(){	if(menu.id2 != ''){		document.getElementById(menu.id2).style.display = 'none';
		menu.id2 = '';
	}
}

function mnHideAll(){	mnOver2();
	mnOnTime1();
	mnOnTime2();
}

function mnShow1(idv){
	mnOver1();
	if(menu.id1 != '') document.getElementById(menu.id1).style.display = 'none';
	if(menu.id2 != ''){	document.getElementById(menu.id2).style.display = 'none'; menu.id2 = ''; }
	menu.id1 = idv;
	document.getElementById(idv).style.display = 'block';
}
function mnShow2(idv){	if(menu.id1 != ''){
		mnOver2();
		if(menu.id2 != '') document.getElementById(menu.id2).style.display = 'none';
		menu.id2 = idv;
		document.getElementById(idv).style.display = 'block';
	}
}
function mnStart1(){
	hTimer1 = setTimeout(mnOnTime1, mnTime);
}
function mnStart2(){
	hTimer1 = setTimeout(mnOnTime1, mnTime);
	hTimer2 = setTimeout(mnOnTime2, mnTime);
}

function mnOver1(){
	if(hTimer1>0){ clearTimeout(hTimer1); hTimer1 = 0; }
}
function mnOver2(){
	if(hTimer1>0){ clearTimeout(hTimer1); hTimer1 = 0; }
	if(hTimer2>0){ clearTimeout(hTimer2); hTimer2 = 0; }
}

//--------------- действия по пунктам меню ----------
function changed(key1, key2){
	var i=0; var j=0; var el; var el_all;
  	for(i=0; i<mnsel.length; i++){
  		for(j=0; j<mnsel[i].length; j++){
			el = document.getElementById('id'+ i +'_'+ j);
			if( i==key1 && ( j==key2 || key2=='all') ){				if(mnsel[i][j] <= 0){
					mnsel[i][j] = 1;
					a.show(i, j);
					if(el) el.style.background = colorShow;
				}
			}else{				if(mnsel[i][j] > 0){					mnsel[i][j] = 0;
					a.hide(i, j);
					if(el) el.style.background = colorHide;
				}
			}//if
		}// for j
		el_all = document.getElementById('id'+ i +'_all');
		if(el_all) if(i==key1) el_all.style.background = colorShow; else el_all.style.background = colorHide;
	}// for i
	if( key1>0 && key1<6 ) document.getElementById('all_shops').style.background = colorShow;
	else document.getElementById('all_shops').style.background = colorHide;
	document.getElementById('id_all_all').style.background = colorHide;
}

function changed_allshops(){	var i=0; var j=0; var el; var el_all;
  	for(i=0; i<mnsel.length; i++){
  		for(j=0; j<mnsel[i].length; j++){
			el = document.getElementById('id'+ i +'_'+ j);
			if( i>0 && i<6 ){
				if(mnsel[i][j] <= 0){
					mnsel[i][j] = 1;
					a.show(i, j);
					if(el) el.style.background = colorShow;
				}
			}else{
				if(mnsel[i][j] > 0){
					mnsel[i][j] = 0;
					a.hide(i, j);
					if(el) el.style.background = colorHide;
				}
			}//if
		}// for j
		el_all = document.getElementById('id'+ i +'_all');
		if(el_all) if( i>0 && i<6 ) el_all.style.background = colorShow; else el_all.style.background = colorHide;
	}// for i
	document.getElementById('all_shops').style.background = colorShow;
	document.getElementById('id_all_all').style.background = colorHide;
}

function change_all(){
	var i=0; var j=0; var el; var el_all;
  	for(i=0; i<mnsel.length; i++){
  		for(j=0; j<mnsel[i].length; j++){
			if(mnsel[i][j] <= 0){
				mnsel[i][j] = 1;
				a.show(i, j);
				el = document.getElementById('id'+ i +'_'+ j);
				if(el) el.style.background = colorShow;
			}
		}// for j
		el_all = document.getElementById('id'+ i +'_all');
		if(el_all) el_all.style.background = colorShow;
	}// for i
	document.getElementById('all_shops').style.background = colorShow;
	document.getElementById('id_all_all').style.background = colorShow;
}

//---------- интерфейс админки -------------

fl_sel_my = true;
function mySelClick(){
	if(fl_sel_my){
		document.getElementById('new_my').style.display = 'none';
		document.getElementById('adm_users').style.display = 'block';
		fl_sel_my = false;
		document.getElementById('but_sel_my').value = 'Показать добавление';
	}else{
		document.getElementById('adm_users').style.display = 'none';
		document.getElementById('new_my').style.display = 'block';
		fl_sel_my = true;
		document.getElementById('but_sel_my').value = 'Показать существующих';
	}
}

fl_sel_shops = true;
function shopsSelClick(){
	if(fl_sel_shops){
		document.getElementById('new_shop').style.display = 'none';
		document.getElementById('my_shops').style.display = 'block';
		fl_sel_shops = false;
		document.getElementById('but_sel_shops').value = 'Добавить новый';
	}else{
		document.getElementById('my_shops').style.display = 'none';
		document.getElementById('new_shop').style.display = 'block';
		fl_sel_shops = true;
		document.getElementById('but_sel_shops').value = 'Показать существующие';
	}
}

fl_sel_roads = true;
function roadsSelClick(){
	if(fl_sel_roads){
		document.getElementById('new_road').style.display = 'none';
		document.getElementById('my_roads').style.display = 'block';
		fl_sel_roads = false;
		document.getElementById('but_sel_roads').value = 'Добавить новую';
	}else{
		document.getElementById('my_roads').style.display = 'none';
		document.getElementById('new_road').style.display = 'block';
		fl_sel_roads = true;
		document.getElementById('but_sel_roads').value = 'Показать существующие';
	}
}
