
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'; }
}

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;
  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 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.top = y + 'px';
		d.style.left = x + 'px';
		jQuery("#bask_not").show("drop", { direction: "down" }, 1000);
	    setTimeout('jQuery("#bask_not").hide("drop", { direction: "down" }, 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 = document.body.clientWidth - 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.top = y + 'px';
		d.style.left = 0;
		jQuery("#comp_not").show("drop", { direction: "left" }, 1000);
	    setTimeout('jQuery("#comp_not").hide("drop", { direction: "down" }, 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;
	
}

