/************************* Basket *************************/
// получить значение cookie
function getCookie(name) {
  var prefix = name + "="
  var StartIndex = document.cookie.indexOf(prefix)
  if (StartIndex == -1) {return null;}
  var EndIndex = document.cookie.indexOf(";", StartIndex + prefix.length)
  if (EndIndex == -1) {EndIndex = document.cookie.length;}
  return unescape(document.cookie.substring(StartIndex + prefix.length, EndIndex))
}
// сколько товаров в cookie
function getBasketCount(){
   var bc = getCookie('basketcount');
   if ((document.cookie)&&(bc != null)&&bc>0) {return bc;}
   else {return 0;}
}
// на сколько денег rur
function getTotalPriceRur(){
   var bc = getCookie('basketpricerur');
   if ((document.cookie)&&(bc != null)&&bc>0) {return bc;}
   else {return 0;}
}
// ничего нет
function writeEmptyBasket(){
  document.getElementById('BasketMayBeEmpty').innerHTML='<h3>Ваша корзина пуста</h3>';
  document.getElementById('BasketItemsCount').innerHTML='Товаров:&nbsp;<b>0</b>';
  document.getElementById('BasketMoneyTxt').innerHTML='Добавьте товар в корзину';
  document.getElementById('ProcessOrder').innerHTML='<img src="/i/d/button-makeorder-disabled.gif" width="113" height="18" border="0" alt="" class="toBasket" />';
}
// что-то есть
function writeFullBasket(itemCount, priceRur){
  document.getElementById('BasketMayBeEmpty').innerHTML='<h3>Ваша корзина</h3>';
  document.getElementById('BasketItemsCount').innerHTML='Товаров:&nbsp;<b class="red strong">'+itemCount+'</b>';
  document.getElementById('BasketMoneyTxt').innerHTML='Сумма заказа:<br /><b class="red strong">'+priceRur+'&nbsp;руб.</b><br /><b>Все налоги учтены!</b>';
  document.getElementById('ProcessOrder').innerHTML='<a href="/shop/order.jsp?ID=index"><img src="/i/d/button-makeorder.gif" width="113" height="18" border="0" alt="Оформить заказ" title="Оформить заказ" class="toBasket" /></a>';
}
// отрендерить блок с корзинкой
function processBasketFillValues(){
  var itemCount = getBasketCount();
  var priceRur = getTotalPriceRur();
  // itemCount ++;
  if ((itemCount>0) && (priceRur>0)) {writeFullBasket(itemCount, priceRur);}
  else {writeEmptyBasket()};
}

/************************** Menu **************************/
function show(list) {list.style.left = 'auto'; list.style.visibility = 'visible';}
function hide(list) {list.style.left = '-999em'; list.style.visibility = 'hidden';}

// Banners
function apic() {
	var apicCounterPlace;
	if (apicCounterPlace = document.getElementById('apicCounterPlace')) {
		apicCounterPlace.innerHTML =
			'<a href="http://top.apic.ru/index.cgi?Template=description&Id=50">'+
			'<img src="http://top.apic.ru/cgi-bin/request?CLSID=CC45GSD73&Id=50&Action=Count&NoCache='+ (Math.ceil(Math.random(1000)*10000000)) +'" width="88" height="31" border="0" hspace="2" alt="" />'+
			'</a>';
	}
}
function hotlog() {
	var hotlogCounterPlace;
	if (hotlogCounterPlace = document.getElementById('hotlogCounterPlace')) {
		var hotlog_r = ""+ Math.random() +"&s=1001727&r="+ escape(document.referrer) +"&pg="+ escape(window.location.href);
		document.cookie = "hotlog=1; path=/"; hotlog_r += "&c="+ (document.cookie ? "Y" : "N");
		hotlog_r += "&j="+ (navigator.javaEnabled() ? "Y" : "N");
		hotlog_r += "&wh="+ screen.width +'x'+ screen.height +"&px="+ (((navigator.appName.substring(0,3) == "Mic")) ? screen.colorDepth : screen.pixelDepth);
		hotlogCounterPlace.innerHTML =
			'<img src="http://hit7.hotlog.ru/cgi-bin/hotlog/count?'+ hotlog_r +'&js=1.3&" width="1" height="1" border="0" alt="" />';
	}
}
function rambler() {
	var ramblerCounterPlace;
	if (ramblerCounterPlace = document.getElementById('ramblerCounterPlace')) {
		ramblerCounterPlace.innerHTML =
			'<img src="http://counter.rambler.ru/top100.cnt?415152" width="1" height="1" border="0" alt="" />'+
			'<a href="http://top100.rambler.ru/top100/">'+
			'<img src="/i/b/banner-rambler.gif" width="88" height="31" border="0" hspace="2" alt="" />'+
			'</a>';
	}
}

// Menu
function loadMenu() {
	// not NN4
	if (!document.layers) {
		// IE cell height fix
		if (document.getElementById('centercont') && document.getElementById('menu')) {
			document.getElementById('menu').style.height = document.getElementById('centercont').offsetHeight + 'px';
		}
		
		var item = document.getElementById("topmenu").getElementsByTagName("td");

		// about
		item[1].getElementsByTagName("div")[0].onclick = function() {window.location = "/about/"}
		item[1].innerHTML +=
		'<ul class="pulldown">'+
		'<li><a href="/about/vacancy/">Вакансии</a></li>'+
		'<li><a href="/about/press-center/">Пресс-центр</a></li>'+
		'<li><a href="/about/portfolio/">Наши клиенты</a></li>'+
		'<li><a href="/contact/">Контакты</a></li>'+
		'</ul>';

		// service
		item[2].getElementsByTagName("div")[0].onclick = function() {window.location = "/service/"}
		item[2].innerHTML +=
		'<ul class="pulldown">'+
		'<li><a href="/service/corporate/">Корпоративным клиентам</a></li>'+
		'<li><a href="/service/person/">Частным клиентам</a></li>'+
		'<li><a href="https://www.rusklimat.ru/dealer/" target="_blank">Дилерам</a></li>'+
		'<li><a href="/service/warranty/">Сервисное&nbsp;и гарантийное<br>обслуживание</a></li>'+
		'</ul>';

		// goods
		item[3].getElementsByTagName("div")[0].onclick = function() {window.location = "/goods/"}
		item[3].innerHTML +=
		'<ul class="pulldown">'+
		'<li><a href="/catalog/" class="nowrp">Каталог оборудования</a></li>'+
//		'<li><a href="/price/">Прайс лист</a></li>'+
		'<li><a href="/partners/">Торговые марки</a></li>'+
		'<li><a href="/goods/pr/">Специальные акции</a></li>'+
		'</ul>';

		// info
		item[4].getElementsByTagName("div")[0].onclick = function() {window.location = "/info/";}
		item[4].innerHTML +=
		'<ul class="pulldown">'+
		'<li><a href="/news/">Новости</a></li>'+
		'<li><a href="/info/corner/">Уголок покупателя</a></li>'+
		'<li><a href="http://www.russian-climat.ru/">Газета &laquo;Русский&nbsp;климат&raquo;</a></li>'+
		'<li><a href="/info/publications/">Публикации в&nbsp;прессе</a></li>'+
		'<li><a href="/info/exhibition/">Отчеты о выставках</a></li>'+
		'<li><a href="/info/manual/">Инструкции пользователя</a></li>'+
		'</ul>';

		// where2buy
		item[5].getElementsByTagName("div")[0].onclick = function() {window.location = "/where2buy/";}
		item[5].innerHTML +=
		'<ul class="pulldown">'+
		'<li><a href="/where2buy/moscow/">Москва</a></li>'+
		'<li><a href="/where2buy/spb/" class="nowrp">Санкт-Петербург</a></li>'+
		'<li><a href="/where2buy/">Регионы России</a></li>'+
		'<li><a href="/shop/" class="nowrp">Интернет магазин</a></li>'+
		'</ul>';

		for (var i = 0; item[i]; i++) {
			if (item[i].getElementsByTagName("ul")[0]) {
				if (item[i].style.cursor) item[i].style.cursor = 'pointer';
				item[i].onmouseover = function() {show(this.getElementsByTagName("ul")[0])}
				item[i].onmouseout = function() {hide(this.getElementsByTagName("ul")[0])}
			}
		}

		// FOR Opera 7+ and not 9
		if (window.opera && document.getElementById && document.readyState && parseInt(navigator.appVersion) != 9) {
			list = document.getElementById("topmenufirst").getElementsByTagName("ul");
			for (var i = 0; i < item.length; i++) {
				if (list[i]) list[i].style.width = '89%';
			}
		}
	}
}

window.onload = function() {
	rambler();
//	hotlog();
//	apic();
}

/************************** Zoom **************************/
// Mozilla = (navigator.userAgent.indexOf('Gecko') != -1) && (document.getElementById?true:false);
var Mozilla = (document.getElementById?true:false);
function zoom(img) {return zoomf('/images/docs/' + img, '');}
function zoomf(img, title) {
  if (!title) title = '';
  winID = Math.random() + ""; winID = winID.substr(2, 10); // random ID for IE 6-
  win = window.open("","win"+winID,"top=50,left=200,width=" + 300 + ",height=" + 300 + ",toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes");
  win.document.write(
    '<html>'+
		'<head><title>' + title + '</title></head>'+
    '<body style="margin: 0; padding: 0">'+
    '<a href="#" onclick="window.close()">'+
		'<img src="'+ img +'" border="0" id="myimg" onload="if (' + Mozilla + ') {window.resizeTo(this.width + 30, this.height + 30); window.resizeTo(this.width + 8, this.height + 53)} else {window.resizeTo(this.width, this.height)}" />'+
		'</a>'+
    '</body>'+
		'</html>'
  );
  win.document.close();
}

function redirectURL(redir) {
  var first = true
  for (var i = 0; i < document.forms['addmore'].elements.length; i++) {
    var item = document.forms['addmore'].elements[i]
    if (item.checked) {redir += (first ? '' : '-') + item.name; first = false}
  }
  this.location = redir + '.jsp'
  return false;
}
