function ChangeLang(url, value)
{
	if (url == "/admin.php")
		location.href=url+"?newlang="+value+"";
	else location.href=url+"&newlang="+value+"";
}

function SubListOff(parent, count)
{
	var i;
	for (i=1; i<=count; i++)
	{
		var div=document.getElementById("div"+parent+"_"+i);
		var hidden = document.getElementById("hidden"+parent+"_"+i);
		var hidden_count = document.getElementById("hidden"+parent+"_"+i+"_count");
		div.style.display = "none";
		if (hidden_count.value > 0)
			SubListff(hidden.value, hidden_count.value);
	}
}

function SubListOn(parent, count)
{
	var i;
	for (i=1; i<=count; i++)
	{
		var div=document.getElementById("div"+parent+"_"+i);
		var hidden = document.getElementById("hidden"+parent+"_"+i);
		var hidden_count = document.getElementById("hidden"+parent+"_"+i+"_count");
		div.style.display = "";
		var img=document.getElementById("img"+hidden.value);
		var buf = img.src.substring(img.src.length-7, img.src.length);
		if (buf != "off.gif")
			SubListOn(hidden.value, hidden_count.value);
	}
}

function SubList(parent, count)
{
	var img=document.getElementById("img"+parent);	
	var buf = img.src.substring(img.src.length-7, img.src.length);

	if (buf == "off.gif")
	{
		img.src = "aimages/blueon.gif";
		img.alt = "Скрыть";
		var i;
		for (i=1; i<=count; i++)
		{
			var div=document.getElementById("div"+parent+"_"+i);
			div.style.display = "";
			var hidden = document.getElementById("hidden"+parent+"_"+i);
			var hidden_count = document.getElementById("hidden"+parent+"_"+i+"_count");
			var img=document.getElementById("img"+hidden.value);
			var buf = img.src.substring(img.src.length-7, img.src.length);
			if (buf != "off.gif")
				SubListOn(hidden.value, hidden_count.value);
		}
	}
	else 
	{
		img.src = "aimages/blueoff.gif";
		img.alt = "Раскрыть";
		var i;
		for (i=1; i<=count; i++)
		{
			var div=document.getElementById("div"+parent+"_"+i);
			var hidden = document.getElementById("hidden"+parent+"_"+i);
			var hidden_count = document.getElementById("hidden"+parent+"_"+i+"_count");
			div.style.display = "none";
			if (hidden_count.value > 0)
				SubListOff(hidden.value, hidden_count.value);
		}
	}
}

function MyCheck(url) { 
var res = confirm( 'Вы уверены, что хотите удалить эту страницу?' ); 
if (res)
	MakeOn(url);
}

function MakeOn(url)
{
	var expand = document.getElementById('expand');
	url = url+"&expand="+expand.value;
	window.location.href=url;
}

function DopImg()
{
        targetId="dopimg";
        targetElement = document.getElementById(targetId);
	if (targetElement.style.visibility == "hidden")
	        targetElement.style.visibility= "";
	else targetElement.style.visibility= "hidden";
	location.href = "#dopimg";
}

var curid;
function ContextMenu(event, id){
	if (event.button == 3) return false;

	if (curid)
	{
	        var o = document.getElementById(curid);
	       	o.style.visibility ='';
	}
	curid = id;
        var o = document.getElementById(id);
		o.style.left = event.clientX+document.body.scrollLeft;
        o.style.top = event.clientY+document.body.scrollTop;
        o.style.visibility ='visible';
		preventBubble(event);
}
function ContextMenuHide(){
	if (curid)
	{
	        var o = document.getElementById(curid);
        	o.style.visibility ='';
	}
}

var u=navigator.userAgent;
var isIE=(u.indexOf("MSIE")>0);
var isMoz=(u.indexOf("Gecko")>0);
var isOp=(u.indexOf("Opera")>0);
if(isOp) isIE=false;

function highlightie5(event, id){
var buf = document.getElementById(id);
buf.style.backgroundColor="highlight"
buf.style.color="white"
}

function lowlightie5(event, id){
var buf = document.getElementById(id);
buf.style.backgroundColor=""
buf.style.color="black"
}

function jumptoie5(event){
if (isIE){
if (event.srcElement.className=="menuitems"){
if (event.srcElement.getAttribute("target")!=null)
window.open(event.srcElement.url,event.srcElement.getAttribute("target"))
else
window.location=event.srcElement.getAttribute("url")
}
}
}

function showImage(src){document.getElementById("bigimage").src=src;}

function preventBubble(E){
	if(isIE){
		event.cancelBubble=true;
		event.returnValue=false
	}
	else if(isOp){
		if(DocumentEvent.stopPropagation)DocumentEvent.stopPropagation();
		 else DocumentEvent.preventBubble()
	}
	else {
		if(E.stopPropagation)E.stopPropagation();
		 else E.preventBubble(event)
	}
}

function popup_image(url, w, h, s, mnf_id, mnf_name) {

	wWidth = w + 50;
	wHeight = h + 60;
	if (wWidth > screen.width) wWidth = screen.width - 100;
	if (wHeight > screen.height) wHeight = screen.height - 200;

	wnd=window.open("", "imgWin", 'width=' + wWidth + ',height=' + wHeight + ',resizable=1,scrollbars=1,toolbar=no,menubar=no');
	wnd.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /><title>Просмотр оригинального изображения</title><link rel="stylesheet" href="/images/style.css" type="text/css" /></script></head><body oncontextmenu="return false;">');
	wnd.document.write('<div align="center"><br />');
	wnd.document.write('<img id="orImage" src="' + url + '" width="' + w + '" height="' + h + '" border="0" alt="" /><br />');
	//if ( heading ) wnd.document.write('<h1>'+heading+'</h1>');
	if ( s ) wnd.document.write('<p style="margin:0px 20px;">'+s+'</p>');
	if ( mnf_id ) {
		var txt = 'Производитель';
		if ( mnf_name )
			txt += ' :: '+mnf_name;
		wnd.document.write('<p><a href="#" onclick="opener.location.href=\'/manufacturers/manufacturers.php?id='+mnf_id+'\'; window.close(); return false;">'+txt+'</a></p>');
	}
	wnd.document.write('<p><a href="javascript:window.close();"><div class="textPhotoTitle">Закрыть окно</div></a></p>');
	wnd.document.write('</div>');
	wnd.document.write('</body></html>');
	wnd.document.close();
	wnd.focus();

}
