
var comparePresent = new Array;
comparePresent = {};

function resize() {
	if (/iPad/.test(navigator.userAgent)) { return };
	if (/iPhone/.test(navigator.userAgent)) { return };

  var y = getClientHeight();
  var d1 = document.getElementById('div_list');
  var d2 = document.getElementById('div_info');
  var d3 = document.getElementById('div_message');
  var d4 = document.getElementById('div_task');
  var d5 = document.getElementById('div_tasklist');
  var d6 = document.getElementById('div_pane');
  //var d7 = document.getElementById('div_ex_pane');
  //var d8 = document.getElementById('div_exlist');
  var d9 = document.getElementById('div_msg');
  var otstup = 235;
  if (d4) { otstup = 165; }
  var a = y - otstup;
  if (a<200) { a = 200; }
  if (d1) { d1.style.height = a + 'px'; }
  if (d2) { d2.style.height = a + 'px'; }
  if (d3) { d3.style.height = a + 'px'; }
  if (d4) { d4.style.height = a + 'px'; }
  if (d5) { d5.style.height = a + 'px'; }
  if (d6) { d6.style.height = a + 'px'; }
  //if (d7) { d7.style.height = a-75 + 'px'; }
  //if (d8) { d8.style.height = a-75 + 'px'; }
  if (d9) { d9.style.height = a + 'px'; }
  
  //resize_width('catalog_id');
  
}

function getClientWidth(){return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;}
function getClientHeight(){return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;}
//Центрирование блока относительно экрана
function center_me(center_id){
  var d = document.getElementById(center_id);
  d.style.display = '';
  d.style.position = 'absolute';
  x = getClientWidth();
  x = x - d.offsetWidth;
  x = x/2;
  y = getClientHeight();
  y = y - d.offsetHeight;
  y = y/2 + document.documentElement.scrollTop + document.body.scrollTop;
  d.style.top = y + 'px';
  d.style.left = x + 'px';
}
function close_me(close_id){
  var d = document.getElementById(close_id);
  d.style.display = 'none';
}

function resize_width(element_id){
	var d = document.getElementById(element_id);
	screen_width = getClientWidth();
	p_width = 15;
	element_width = (p_width * screen_width)/100;
	d.style.width = element_width + 'px';
}

//Добавление товара в корзинку
function addToBasket(nom_id, qty) {
//	LoadHTML('addToBasket', document.getElementById('short_basket'), {'nom_id' : nom_id});
	var func = function(req, tag, env_par, dis, evl) {
		var s = req.responseJS[0];
		tag.innerHTML = s;
		var d = document.getElementById('bask_not');
		d.style.display = 'block';
		x = document.body.clientWidth - d.width;
		y = document.documentElement.clientHeight; //Функция getClientHeight() не работает в Opera
		if (document.documentElement.clientHeight == 0){
			y = getClientHeight();
		}
		y = y + document.documentElement.scrollTop + document.body.scrollTop - d.height; // Это одно и то же значение для разных браузеров. Нужно для фикса бага в хроме.
		d.style.display = 'none';
		
		jQuery("#bask_not").css({'top': y+jQuery('#bask_not').height()+'px', 'right': '0px'});
		jQuery('#bask_not').animate({ top: '-='+jQuery('#bask_not').height(), opacity: 'show' }, 1000)
		setTimeout(function(){jQuery('#bask_not').animate({ opacity: 'hide', top: '+='+jQuery('#bask_not').height()}, 1000)}, 3000);
	}
	if (!qty) { qty = 1; }
	Load('/cgi-bin/Runs/dyna_loader.pl', {par: 'addToBasket', nom_id: nom_id, qty: qty}, document.getElementById('short_basket'), func);
}

function add_compare(nom_id) {
	var func = function(req, tag, env_par, dis, evl) {
		var s = req.responseJS[0];
		tag.innerHTML = s;
		var d = document.getElementById('comp_not');
		d.style.display = 'block';
		x = d.width;
		y = document.documentElement.clientHeight;
		if (document.documentElement.clientHeight == 0){
		y = getClientHeight();
		}
		y = y + document.documentElement.scrollTop + document.body.scrollTop - d.height;
		d.style.display = 'none';
		
		d.style.top = y + 'px';
		d.style.left = '-'+x+'px';
		
		$("#comp_not").animate({ left: '+='+$("#comp_not").width(), opacity: 'show' }, 1000);
	    setTimeout(function(){$("#comp_not").animate({ left: '-='+$("#comp_not").width(), opacity: 'hide' }, 1000)}, 3000);
		
	}
	//LoadHTML('add_compare', document.getElementById('compare_div'), {nom_id: nom_id});
	Load('/cgi-bin/Runs/dyna_loader.pl', {par: 'add_compare', nom_id: nom_id}, document.getElementById('compare_div'), func);
}
function del_compare(nom_id) {
	LoadHTML('del_compare', document.getElementById('compare_div'), {nom_id: nom_id});
}

//Добавление товара к сравнению
function addCompareItem(itemInfo) { // старая версия, используется на сайтах
	if(comparePresent[itemInfo['nID']]) {
		alert('Товар уже добавлен к сравнению');
		return;
	}

	var compTbl = document.getElementById('compTbl');
	if(! compTbl) {
		return;
	}
	var rows = compTbl.rows;
	var present = 0;
	for(var i in comparePresent) {
		present = 1;
	}
	if(! present) {
		compTbl.deleteRow(0);
	}
		
	var row = compTbl.insertRow(rows.length);
	var id = Math.random();

	var cellChk = row.insertCell(0);
	var cellText = row.insertCell(1);
	
	cellChk.innerHTML = '<input type="checkbox" name="compare[]" value="' + itemInfo['nID'] + '" />';
	cellText.innerHTML = itemInfo['name'];
	
	//compDiv.innerHTML += '<br /><a href="' + itemInfo['href'] + '" title="Добавить к сравнению">' + itemInfo['name'] + '</a>';
	
	// добавление на сервере
	dynaExecute('addCompareItem', {'nID' : itemInfo['nID']});
	comparePresent[itemInfo['nID']] = itemInfo;
	
	alert('Товар добавлен в сравнительную таблицу');
	return false;
	
}

