// переход на страницу новостей по номеру
function goNewPage(page)
{
	var h = document.location.href, st = '';
	h = h.split('?');
	if(h.length > 1)
	{
		h = h[1];
		h = h.split('&');
		for(var i=0;i<h.length;i++)
		if(h[i].indexOf('newpageID') < 0)
			st += h[i]+'&';
	}
	document.location = 'index.php?'+st+'newpageID=' + page;
}

// открытие странички объекта в новом окне
function openObject(id, sa)
{
	var offset = (navigator.appName.indexOf('Explorer') != -1)?12:8;
	window.open('object.php?objectID='+id+'&sa='+sa,'','resizable=yes,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,top=0,left=0,height='+screen.height+',width='+(screen.width - offset));
	return false;
}
// открытие странички карты объекта в новом окне
function openMap(id)
{
	var offset = (navigator.appName.indexOf('Explorer') != -1)?12:8;
	window.open('map.php?objectID='+id,'','resizable=yes,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,top=0,left=0,height='+screen.height+',width='+(screen.width - offset));
	return false;
}

// открытие нового окна
function openWindow(url)
{
	var offset = (navigator.appName.indexOf('Explorer') != -1)?12:8;
	window.open(url,'','');
	return false;
}

// генерирует строку текста - сколько квартир выбрано
function gen_sel_str(x)
{
	var type = g_type;
	if(x == 0) return 'не сделан';
	var ok = '', main = (type == 'cottage')?'объект':'квартир';
	if(x > 9 && x < 21) ok = (type == 'cottage')?'ов':'';
	else
		if(x%10 == 1) ok = (type == 'cottage')?'':'а';
		if(x%10 > 1 && x%10 < 5) ok = (type == 'cottage')?'а':'ы';
	return x + ' ' + main + ok;
}

// установка куки
function setCookie(name, value)
{
	document.cookie = name + "=" + escape(value);
}

// нажали на чекбокс "выбрать"
function clickCheckBox(id,obj)
{
	if(obj == 'link')
	{
		obj = document.getElementById('check_'+id);
		// имитация нажатия на чекбокс
		obj.checked = (obj.checked)?0:1;
	}
	var i, f, sel = obj.checked;
	if(g_act == 'buy' || g_act == 'choice')
	{
		for(i=0,f=0;i<select_buy.length;i++)	if(select_buy[i] == id) { f = 1; break; }
		if(!sel && f) select_buy.splice(i, 1);
		if(sel && !f) select_buy[i] = id;
		if(g_act == 'buy')
		{
			document.getElementById('vibor1').innerHTML = gen_sel_str(select_buy.length);
			document.getElementById('vibor2').innerHTML = gen_sel_str(select_buy.length);
		}
	}
	else
	{
		for(i=0,f=0;i<select_rent.length;i++)	if(select_rent[i] == id) { f = 1; break; }
		if(!sel && f) select_rent.splice(i, 1);
		if(sel && !f) select_rent[i] = id;
		document.getElementById('vibor1').innerHTML = gen_sel_str(select_rent.length);
		document.getElementById('vibor2').innerHTML = gen_sel_str(select_rent.length);
	}
	// устанавливаем куки
	var st = '';
	st = '0';
	if(select_buy.length)
		{ st = ''; for(i=0;i<select_buy.length;i++)	st+= ((i)?'|':'')+select_buy[i]; }
	setCookie('select_buy',st);
	st = '0';
	if(select_rent.length)
		{ st = ''; for(i=0;i<select_rent.length;i++) st+= ((i)?'|':'')+select_rent[i]; }
	setCookie('select_rent',st);
	return false;
}

