var panelSelect;
var nameModulFlag;
var titleStatus;

/*Подсказки*/
function titleCookie()
{
	var titleOn = document.getElementById('titleOn');
	var titleOff = document.getElementById('titleOff');
	var date = new Date(2200, 01, 01);
	if(getCookie('title_status')){
		titleStatus = getCookie('title_status');
		if(titleStatus == 0){
			titleOn.className = 'color4 cursor';
			titleOff.className = '';
		}
	}else{
		setCookie('title_status', '1', date, '/');
		titleStatus = 1;
		titleOn.className = '';
		titleOff.className = 'color4 cursor';
	}
}
function titleOnOff(on) //on off 
{
	var titleOn = document.getElementById('titleOn');
	var titleOff = document.getElementById('titleOff');
	var date = new Date(2200, 01, 01);
	if(titleStatus == 1 && on == 0){
		setCookie('title_status', '0', date, '/');
		titleStatus = 0;
		titleOn.className = 'color4 cursor';
		titleOff.className = '';
	}else if(titleStatus == 0 && on == 1){
		setCookie('title_status', '1', date, '/');
		titleStatus = 1;
		titleOn.className = '';
		titleOff.className = 'color4 cursor';
	}
}

function titleShow(ev,obj,text)
{
	if(titleStatus == 0) return;
	var t = document.getElementById('titleBlock');
	var tText = document.getElementById('titleBlockText');
	var offsetX = 10;
	var offsetY = 10;
	var x = window.event ? window.event.x : ev.clientX;
    var y = window.event ? window.event.y : ev.clientY;
	
	if(panelSelect) return;
	
	t.style.display = 'block';
	t.style.position = 'absolute';
  if((x + offsetX + t.clientWidth) < document.body.clientWidth){
  	t.style.left=x + offsetX + 'px';
	t.style.top=y + offsetY + document.body.scrollTop + 'px';
  }else{
  	t.style.left=(x - 200) + 'px';
	t.style.top=y + offsetY + document.body.scrollTop + 'px';
  }

	tText.innerHTML = text;
	
	obj.onmouseout = function(){
		if(t.style.display == 'block'){
			t.style.display = 'none';
		}
	}
}
/*function titleHidden()
{
	if(titleStatus == 0) return;
	var t = document.getElementById('titleBlock');
	//var tText = document.getElementById('titleBlockText');
	t.style.display = 'none';
}*/

/*Подсветка разделов*/
function highlights(item, type)
{
	if(type == 'true'){
 		item.className = 'selected_row';	
 	}else{
 		item.className = '';	
	}
}

/*Подсветка разделов и иконок*/
function higlightYes(id,name,nameModul,type)
{
	if(panelSelect) return;

	nameModulFlag = nameModul;

	var item = document.getElementById('item' + id);
	var addImg1 = document.getElementById('addImg' + id + '_1');
	var addImg2 = document.getElementById('addImg' + id + '_2');
	var modulImg1 = document.getElementById(nameModul + id + '_1');
	var modulImg2 = document.getElementById(nameModul + id + '_2');

	item.className = 'selected_row';
	addImg1.style.display = 'none';
	addImg2.style.display = '';
	if(nameModul != ''){
		modulImg1.style.display = 'none';
		modulImg2.style.display = '';
	}
}
function higlightNo(id,name,nameModul,type)
{
	if(panelSelect) return;

	nameModulFlag = nameModul;

	var item = document.getElementById('item' + id);
	var addImg1 = document.getElementById('addImg' + id + '_1');
	var addImg2 = document.getElementById('addImg' + id + '_2');
	var modulImg1 = document.getElementById(nameModul + id + '_1');
	var modulImg2 = document.getElementById(nameModul + id + '_2');

	item.className = '';
	addImg1.style.display = '';
	addImg2.style.display = 'none';
	if(nameModul != ''){
		modulImg1.style.display = '';
		modulImg2.style.display = 'none';
	}
}

/*Открытие блока для добавления разделов*/
function showAddBlock(id,page_id,page_name)
{
	if(panelSelect) return;
	panelSelect = page_id;
	
	var agt = navigator.userAgent.toLowerCase();
	var centerTd = document.getElementById('center');
	var structureTab = document.getElementById('structure');
	var plusTd = document.getElementById('plus' + page_id);
	var addForm = document.getElementById('addBlock');
	var addSection = document.getElementById('addSection');
	var winBody = document.body;
	var pX = 0;
	var pY = 0;
	var bUgl = 0;
	var curleft = 0;
	var curtop = 0;

	var fildHidden = document.getElementById('page_id');
	fildHidden.value = page_id;

	if(agt.indexOf('msie') != -1){pX = 15; pY = 10;}
	else if(agt.indexOf('gecko') != -1){pX = 22; pY = 10;}
	else{pX = 22; pY = 10;}

	if(id == 1){
		addForm.style.display = 'block';

		if(plusTd){
			while(plusTd.offsetParent){
				curleft += plusTd.offsetLeft;
				curtop += plusTd.offsetTop;
				plusTd = plusTd.offsetParent;
			}
		}
		bUgl = (curtop + 165);
		addForm.style.left = (curleft + pX);
		if(bUgl < (winBody.clientHeight + document.body.scrollTop)){addForm.style.top = (curtop + pY);}
		else{addForm.style.top = (curtop - 165);}
	}else if(id == 2){
		if(addSection){
			while(addSection.offsetParent){
				curleft += addSection.offsetLeft;
				curtop += addSection.offsetTop;
				addSection = addSection.offsetParent;
			}
		}
		addForm.style.display = 'block';
		addForm.style.left = (curleft + pX);
		addForm.style.top = (curtop + pY);
	}
}

/*Уничтожение блока для добавления разделов*/
function closeAddBlock(){
	var addForm = document.getElementById('addBlock');
	addForm.style.display = 'none';
	var item = document.getElementById('item' + panelSelect);
	var addImg1 = document.getElementById('addImg' + panelSelect + '_1');
	var addImg2 = document.getElementById('addImg' + panelSelect + '_2');
	var modulImg1 = document.getElementById(nameModulFlag + panelSelect + '_1');
	var modulImg2 = document.getElementById(nameModulFlag + panelSelect + '_2');

	if(item){
		item.className = '';
		addImg1.style.display = '';
		addImg2.style.display = 'none';
		if(nameModulFlag != ''){
			modulImg1.style.display = '';
			modulImg2.style.display = 'none';
		}
	}
	panelSelect = false;
}

var oldonload = window.onload;
if (typeof window.onload != 'function') {
	window.onload = function(){
		scanerSel();
	}
}
else {
	window.onload = function() {
		oldonload();
		scanerSel();
	}
}

function scanerSel(){
	var sel = document.getElementsByTagName('select');
	for(i = 0; i <= sel.length-1; i++){
		sel[i].defaultValue = sel[i].selectedIndex;
	}
}

function optionModule(name,tag,link){
	
	var modType = document.getElementById(tag);
	var formSel = document.forms[0];
	
	selIndex = formSel.elements[name].selectedIndex;
	selIndex2 = formSel.elements[name].defaultValue;
	if(selIndex != selIndex2){
		modType.innerHTML = '<span class="color2" title="Сохраните изменения">изменён</span>';
	}else{
		if(link != ''){
			modType.innerHTML = '<a href="' + link + '">настроить</a>';
		}else{
			modType.innerHTML = '<span id="' + tag + '"></span>';
		}
	}
}

