/* Счетчики */
function best_stroy_counter() {
	id = 6964;
	type = 7;
	rnd = Math.random();
	c = '<a href="http://best-stroy.ru/" target=_blank>';
	c += '<img src="http://best-stroy.ru/counter.php?rnd=' + rnd + '&id=' + id + '&type=' + type + '"';
	c += ' width=88 height=31 border=0 alt="Строительство и ремонт - строительный портал БЕСТ-СТРОЙ.РУ"></a>';
	document.write(c);
}

function live_internet_counter() {
	var imgSrc = 'http://counter.yadro.ru/hit?t23.2;r'+escape(document.referrer);
	if (typeof(screen) != 'undefined')
		imgSrc += ';s' + screen.width + '*' + screen.height + '*' + (screen.colorDepth ? screen.colorDepth : screen.pixelDepth);
	imgSrc += ';u'+escape(document.URL)+';'+Math.random();
	document.write('<a href="http://www.liveinternet.ru/click" target="_blank"><img src="'+imgSrc+' alt="" title="LiveInternet: показано число посетителей за сегодня" width="88" height="15"/></a>');
}

/***********************
 *  Служебные функции
 */
function $(elementId) {
	return document.getElementById(elementId);
}


/**
 * Переход при выборе значения из селектов фильтра
 * selectorId - id select'а
 */
function goFilter(selectorId) {
	var link = selectorId == 'filter-collection' ? $(selectorId).value : '/coll/';

	var options = new Array();
	if ($('filter-state').value != '')
		options.push('state='+$('filter-state').value)
	var target = parseInt($('filter-target').value, 10);
	if (target > 0)
		options.push('target='+target);
	var country = parseInt($('filter-country').value, 10);
	if (country > 0)
		options.push('country='+country);
	var factory = parseInt($('filter-factory').value, 10);
	if (factory > 0)
		options.push('factory='+factory);

	if (options.length > 0)
		link += '?'+options.join('&');

	window.location = link;
}


/**
 * Изменяет иконку в соответствии с текущим интерьером
 * direction - направление: положительное - вперед, отрицательное - назад
 */
function change_interior_icon(direction) {
	if (typeof(window.collectionId) == 'undefined' || typeof(window.interiorsCount) == 'undefined')
		return false;

	if (typeof(window.currentInteriorNum) == 'undefined')
		window.currentInteriorNum = 1;

	if (direction > 0 && window.currentInteriorNum < window.interiorsCount)
		window.currentInteriorNum++;
	else if (direction < 0 && window.currentInteriorNum > 1)
		window.currentInteriorNum--;

	$('interior-next').style.visibility = (window.currentInteriorNum < window.interiorsCount) ? 'visible' : 'hidden';
	$('interior-prev').style.visibility = (window.currentInteriorNum > 1) ? 'visible' : 'hidden';

	var src = 'url("/img/int/'+Math.floor(window.collectionId/100)+'/'+window.collectionId+'_'+window.currentInteriorNum+'_ico.jpg")';
	$('interior-icon').style.backgroundImage = src;

	var link = '/coll/';
	if (window.collectionId > 99)
		link += window.collectionId;
	else if (window.collectionId > 9)
		link += '0'+window.collectionId;
	else
		link += '00'+window.collectionId;
	link += '/photos/';
	if (window.currentInteriorNum > 1)
		link += window.currentInteriorNum+'.html';
	if (window.filterParams != '')
		link += '?filter='+window.filterParams;
	$('interior-icon').setAttribute('href', link);

	return true;
}


/**
 * Показывает/скрывает поле адреса в форме оформления заказа
 */
function cart_toggle_address() {
	$('cart-address-block').style.display = $('cart-ship').checked ? 'block' : 'none';
}


/**
 * Изменение свойства display с none на block и обратно
 */
function toggle_display(id) {
	var el = $(id);
	if (!el)
		return;

	// IE не меняет свойство clientHeight после установки display из none в block
	// поэтому ориентироваться только на clientHeight не получится
	if (el.style.display == '')
		el.style.display = (el.clientHeight > 0) ? 'none': 'block';
	else
		el.style.display = (el.style.display == 'none') ? 'block' : 'none';
}