// Показать/скрыть объекты древовидного меню
function sw(id){
var img=document.getElementById("menu_img_"+id);
var div=document.getElementById("menu_div_"+id);
	if(img && div){
		if(div.style.display=="none"){
		div.style.display="block"
		img.src="http://www.mnepu.ru/m.gif"
		}else{
		div.style.display="none";
		img.src="http://www.mnepu.ru/p.gif"
		}
	}
return false
}

// Поиск координат объекта
function findPosY(obj){
var curtop=0;
	if(obj.offsetParent){
		while(1){
		curtop+=obj.offsetTop;
			if(!obj.offsetParent){
			break;
			}
		obj=obj.offsetParent;
		}
	}else if (obj.y){
	curtop+=obj.y;
	}
return curtop;
}

// Скрыть - промо страничку
function promoViewDown(){
document.getElementById("layoutText").style.display="block"
promoCycleViewDown()
}

function promoCycleViewDown(){
var h=document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
h=h+document.getElementById("layout").scrollTop-50
var e=document.getElementById("promoDiv")
	if(e){
	var i=findPosY(e)
		if(i<h){
		var step=(h-i)/10
			if(step<10)step=10
		i+=step
			if(i>h)i=h
		e.style.top=i+"px"
			if(i<h){
			setTimeout("promoViewDown()",3)
			return true
			}
		}
	e.style.display="none"
	document.getElementById("fixed").style.display="block"
	}
}

// Показать - промо страничку
function promoViewTop(){
var h=document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
e=document.getElementById("promoDiv")
e.style.top=(h-50+document.getElementById("layout").scrollTop)+"px"
e.style.display="block"
e.style.height=(h+document.getElementById("layout").scrollTop-17)+"px"
document.getElementById("fixed").style.display="none"
promoCycleViewTop()
}

function promoCycleViewTop(){
var e=document.getElementById("promoDiv");
var top=document.getElementById("layout").scrollTop
	if(e){
	var i=findPosY(e)
		if(i>top){
		var step=(i-top)/10
			if(step<10)step=10
			i-=step
			if(i<=top)i=top
		e.style.top=i+"px"
			if(i>top){
			setTimeout("promoCycleViewTop()",3)
			return true
			}
		}
	document.getElementById("layoutText").style.display="none"
	}
}

var mark_x=0
var mark_move=0
var mark_position="left"
	function moveMark(c){
		if(mark_move==0){
			if(c==1 && mark_position=="left"){
			mark_x=-229
			mark_move=1
			}
			if(c==-1 && mark_position=="right"){
			mark_x=0
			mark_move=-1
			}
		}
		if(mark_move!=0){
		var m=document.getElementById("mark")
			if(m){
			mark_x+=(mark_move*20)
				if((mark_position=="left" && mark_x<0) || (mark_position=="right" && mark_x>-229)){
				setTimeout("moveMark(0)",20)
				}else{
				document.getElementById("mark_name").src="http://www.mnepu.ru/img/design/mark_"+mark_position+".gif"
					if(mark_position=="left"){
					mark_x=0
					mark_position="right"
					}else{
					mark_x=-229
					mark_position="left"
					}
				mark_move=0
				}
			m.style.left=mark_x+"px"
			}
		}
	}
	
var keyhandler=function(e){ 
	if(!e){
	var e=event;
	}
	if((e.ctrlKey) && ((e.keyCode == 0xA)||(e.keyCode == 0xD))){
	var sts=""
		if (document.getSelection){
		sts=document.getSelection()
		}
		else {
			if (document.selection.createRange()){
			var range = document.selection.createRange()
			sts = range.text;
			}
		}
	document.getElementById("report_error_text").value=sts
	document.getElementById("report_error_url").value=location.href
	document.getElementById("report_error_code").value=500+(location.href+sts).length
	e=document.getElementById("div_form_error")
		if(e){
		e.style.display="block"
		e.style.top=(100+document.body.scrollTop)+"px"
		e.style.left=(100+document.body.scrollLeft)+"px"
		}
	}
}

if (document.addEventListener){
document.addEventListener('keypress', keyhandler, false);
} else if (document.attachEvent){
document.attachEvent('onkeypress', keyhandler);
} else {
document.onkeypress = keyhandler;
}

