function ChangeLang()
{
	document.changeLang.submit();
}

function focusSub(id)
{	
	if (previds != 0)
	{
		var bprevid = "mdiv"+previds;
		var buf = document.getElementById(bprevid);
		buf.style.display = "none";
		var bprevid = "mimg"+previds;
		var buf = document.getElementById(bprevid);
		buf.style.display = "none";
		var targetId = "mtd"+previds;
		var buf = document.getElementById(targetId);	
		buf.style.background = "";		
	}
	previds = id;
	var mdiv = "mdiv"+id;
	var buf = document.getElementById(mdiv);
	buf.style.display = "";
	var mdiv = "mimg"+id;
	var buf = document.getElementById(mdiv);
	buf.style.display = "";
	var targetId = "mtd"+id;
	var buf = document.getElementById(targetId);	
	buf.style.background = "url(/images/circ2.gif) repeat-x";		
}

function focusCategory(id, key, count)
{
	for (i=0; i<count; i++)
	{
		var targetId = "td"+i;
		var buf = document.getElementById(targetId);	
		buf.style.borderLeft = "#8d8e8e 1px solid";	
	}
	var targetId = "bot8";
	var buf = document.getElementById(targetId);				
	buf.style.display = "";
	
	var targetId = "bot1";
	var buf = document.getElementById(targetId);
	buf.style.display = "";
	var targetId = "bot2";
	var buf = document.getElementById(targetId);
	buf.style.borderBottom = "#8d8e8e 1px solid";
	var targetId = "bot3";
	var buf = document.getElementById(targetId);
	buf.style.display = "";
	var targetId = "bot4";
	var buf = document.getElementById(targetId);
	buf.style.borderTop = "#8d8e8e 1px solid";
	var targetId = "bot5";
	var buf = document.getElementById(targetId);
	buf.style.background = "url(/images/mrbg.gif) repeat-y right";
	var targetId = "bot6";
	var buf = document.getElementById(targetId);
	buf.style.display = "";


	var targetId = "subtop";
	var buf = document.getElementById(targetId);
	buf.innerHTML = "<center>Loading...</center>";

	JsHttpRequest.query('/include/core/topmenu.php',{ id: id, lang: lang}, 
	function(result, errors) {topMenu(result)}, true);

	if (prevId)
	{
		var targetId = "img"+prevId;
		var buf = document.getElementById(targetId);	
		buf.style.display = "none";	
		var targetId = "tdd"+prevId;
		var buf = document.getElementById(targetId);	
		buf.style.background = "none";	
	}
	
	var targetId = "td"+key;
	var buf = document.getElementById(targetId);	
	buf.style.borderLeft = "none";
	var targetId = "img"+key;
	var buf = document.getElementById(targetId);	
	buf.style.display = "";	
	var targetId = "tdd"+key;
	var buf = document.getElementById(targetId);	
	buf.style.background = "url(/images/circ2.gif) repeat-x";	
	
	prevId = key;
}

function topMenu(result)
{
	if(!result) return;
	var str = "";
	if (result['top']['img'])
		str = '<img src="/upload/catalog/'+lang+'/'+result['top']['img']+'" id="subimg"><br>';
	else str = '<img src="/images/spacer.gif" id="subimg"><br>';
	str = str+'<div class="parent" align="left"><div id="targetId_1">';
	if (result['top']['sub'].length>0)
	{
		for (i=0; i<result['top']['sub'].length; i++)
		{
			str = str+'<a href="/'+lang+'/tovar/';
			if (result['top']['sub'][i]['text_value'])
				str = str + result['top']['sub'][i]['text_value'];
			else str = str + result['top']['sub'][i]['id'];
			str = str + '.htm" class="topmenu" onMouseOver="focusSubCategory(\''+result['top']['sub'][i]['id']+'\')">'+result['top']['sub'][i]['text_name']+'</a><br>';
		}
	}	
	str = str+'</div></div><table width="11" cellpadding="0" cellspacing="0" border="0" height="67" align="right"><tr><td valign="top"><img src="/images/scroll_up.gif" width="11" height="6" style="cursor: pointer;" onMouseOver="marginMove(\'down\', \'targetId_1\');" onMouseOut="marginMoveStop();"></td></tr><tr><td valign="bottom"><img src="/images/scroll_down.gif" width="11" height="6" style="cursor: pointer;" onMouseOver="marginMove(\'up\', \'targetId_1\');" onMouseOut="marginMoveStop();"></td></tr></table>';
	var targetId = "subtop";
	var buf = document.getElementById(targetId);
	buf.innerHTML = str;
}

function focusSubCategory(id)
{
	JsHttpRequest.query('/include/core/subcategory.php',{ id: id, lang: lang}, 
	function(result, errors) {viewfocusSubCategory(result)}, true);
}

function viewfocusSubCategory(result)
{	
	var targetId = "subimg";
	var buf = document.getElementById(targetId);
	if (result['img'])
		buf.src = '/upload/catalog/'+lang+'/'+result['img'];
	else buf.src = '/images/spacer.gif';
}

function showLogin(module)
{
	if (module != "login")
	{
		var buf = document.getElementById('login');
		if (buf.style.display == "none")
			buf.style.display = "";
		else buf.style.display = "none";
	}
}

function changeMonth(pr, lang, arc)
{
	if (pr == "next")
		bmonth++;
	else if (pr == "prev")
		bmonth--;	
	if (bmonth == 13)
		bmonth=1;
	if (bmonth == 0)
		bmonth = 12;
	var month_ru = new Array("январь", "февраль", "март", "апрель", "май", "июнь", "июль", "август", "сентябрь", "октябрь", "ноябрь", "декабрь");
	var month_ua = new Array("січень", "лютий", "березень", "квітень", "травень", "червень", "липень", "серпень", "вересень", "жовтень", "листопад", "грудень");
	var month_en = new Array("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december");	
	document.getElementById('newbmonth').value=bmonth;
	if (arc == '1')
		document.getElementById('smonth').value=bmonth;
	var buf = document.getElementById('bmonth');	
	if (lang == "ru")
		buf.innerHTML = month_ru[bmonth-1];
	else if (lang == "ua")
		buf.innerHTML = month_ua[bmonth-1];
	else if (lang == "en")
		buf.innerHTML = month_en[bmonth-1];
}

function changeList(pr)
{
	if ((pr == "next") && ((cbegin+3)<cbirth))
	{
		cbegin = cbegin+3;
	}
	if ((pr == "prev") && ((cbegin-3)>=0))
	{
		cbegin = cbegin-3;
	}
	var cend = cbegin+3;
	if (cend > cbirth)
		cend = cbirth;
	ihtml = "";
	for(i=cbegin+1; i<=cend; i++)
	{
		k=i-1;
		ihtml = ihtml + '<a href="#" style="color: #8d8d8d; text-decoration: none;" onClick="changeBirth(\''+k+'\'); return false;" id="ai'+k+'">'+i+'</a>';
		if (i<cend)
			ihtml = ihtml+" | ";		
	}	
	document.getElementById('ilist').innerHTML = ihtml;
	previd="-1";
}

function changeBirth(i)
{
	document.getElementById('iname').innerHTML = i_names[i];
	document.getElementById('idate').innerHTML = i_datebirth[i];
	if (i_depart[i] != "")
		document.getElementById('idepart').innerHTML = prefdep+" "+i_depart[i];
	else document.getElementById('idepart').innerHTML = '';	
	if (i_links[i] != "")
		document.getElementById('ilink').innerHTML = '<a href="mailto:'+i_links[i]+'" class="gray">'+preflink+'</a>';
	else document.getElementById('ilink').innerHTML = '';
	if (i_img[i] != "")
		document.getElementById('iimg').src = '/upload/partners/ru/tn_'+i_img[i];
	else document.getElementById('iimg').src = '/images/spacer.gif';
	if (previd != "-1")
		document.getElementById('ai'+previd).style.color = "#898989";
	document.getElementById('ai'+i).style.color = "#e5040c";
	previd = i;
}

function changeYear(pr)
{
	if (pr == "next")
		byear++;
	else if (pr == "prev")
		byear--;
	if (byear>nyear)
		byear = fyear;
	if (byear<fyear)
		byear = nyear;
	document.getElementById('newbyear').value=byear;
	document.getElementById('syear').value=byear;
	var buf = document.getElementById('byear');	
	buf.innerHTML = byear;
		
}

function marginMoveStop()
{
	begin = 0;
}

var begin = 0;

function marginMove(order, id) {	
	begin=1;
	marginMoveNext(order, id)
}

	function marginMoveNext(order, id) {	
		if (begin == 0)
			return;
		// Опеределим шаг прокрутки в пикселях
		var step = 10;
		// Получим доступ к ДИВу
		var movedDiv;
		if (!(movedDiv = document.getElementById(id))) return;
		// Опеределим существующие значения marginTop & marginLeft
		var top = movedDiv.style.marginTop ? parseInt(movedDiv.style.marginTop) : 0;
		var left = movedDiv.style.marginLeft ? parseInt(movedDiv.style.marginLeft) : 0;
		// Установим новые значения margin, в зависимости от направления прокрутки		
		if ((order == "down") && ((movedDiv.style.marginTop == "0px") || (movedDiv.style.marginTop == "")))
			return;
		var buf = movedDiv.offsetHeight-60;
		if ((buf<0) && (order == "up"))
			return;
		buf = "-"+buf;
		var cur = top - step;
		if ((order == "up") && (cur<buf))
			return;
		switch (order) {
			case "up" :
				movedDiv.style.marginTop = (top - step) + "px";
			break;
			case "down" :
				movedDiv.style.marginTop = (top + step) + "px";
			break;
			default :
				// Nothing
			break;
		}
		setTimeout('marginMoveNext(\''+order+'\', \''+id+'\')', 100);			
	}
