// JavaScript Document

metro = new Array();
mimg = new Array();
metro_sel = new Array();

var timeout	= 500;
var closetimer	= 0;
var ddmenuitem = "";

// Search Buttons background state
var sb_bgpos = "0px 0px";

// Notepad Cookie name
var notecookie = 'object_ids';




$(document).ready(function() {
						
	if (!document.getElementById("selSearchType")) return;
	
	// Select apartment
	document.getElementById("selSearchType").selectedIndex = 0;
	$("#LocationList").val("");
	
	// Object Listing Stripes Zebra
	if (document.getElementById("listing")) { $("#listing tr.child:even").addClass("brown"); }
	
	// Set Rent or sale hidden field to default @RENT@
	document.getElementById("RentOrSellText").value = "rent";
	document.getElementById("Decoration").style.display = "none";
});


  
function ShowRequestDarkBox()
{
	showBlackSquare();
	

	var canvas = document.createElement("div");
	canvas.setAttribute("id", "canvas");
	
	var paddingDiv = document.createElement("div");
	paddingDiv.setAttribute("class", "requestFormPad");
	paddingDiv.className = "requestFormPad";
	paddingDiv.innerHTML = 
		"<h1>Заявка</h1>" +
		"<form name='request' action='/serverside/request.php' method='post'>" +
		"	<input type='hidden' name='return_href' value='' id='ReturnHrefText' />" +
		"   <input type='hidden' name='idnum' value='' id='ObjectID' />" +
		"	<table>" +
		"   <tr>" +
		"		<td width='150'><label>Вы хотите</label></td>" +
		"		<td><select name='order_type'>" +
		"			<option>Снять</option>" +
		"			<option>Сдать</option>" +
		"			<option>Купить</option>" +
		"			<option>Продать</option>" +
		"			</select></td>" +
		"	</tr>" +
		"	<tr>" +
		"		<td width='150'><label>Тип недвижимости</label></td>" +
		"		<td><select name='estate_type'>" +
		"			<option>Квартира</option>" +
		"			<option>Коттедж</option>" +
		"			<option>Коммерческая недвижимость</option>" +
		"			</select></td>" +
		"	</tr>" +
		"	<tr>" +
		"		<td width='150'><label>Имя <span class='required'>*</span></label></td>" +
		"		<td><input type='text' size='37' value='' name='name' /></td>" +
		"	</tr>" +
		"	<tr>" +
		"		<td width='150'><label>E-mail</label></td>" +
		"		<td><input type='text' size='37' value='' name='email' /></td>" +
		"	</tr>" +
		"	<tr>" +
		"		<td width='150'><label>Телефон <span class='required'>*</span></label></td>" +
		"		<td><input type='text' size='37' value='' name='phone' /></td>" +
		"	</tr>" +
		"	<tr>" +
		"		<td width='150'><label>Сообщение <span class='required'>*</span></label></td>" +
		"		<td><textarea rows='8' wrap='hard' value='' name='memo'></textarea></td>" +
		"	</tr>" +
		"	<tr>" +
		"		<td> </td>" +
		"		<td><input type='submit' value='Отправить' />&nbsp;&nbsp;<input type='button' onclick='CloseRequestDarkBox();' value='Закрыть' /></td>" +
		"	</tr>" +
		"   <tr>" +
		"   	<td colspan=2 class='zvezda'>Поля, помеченные символом *, обязательны для заполения" +
		"	</td></tr>" +
		"	</table>" +
		"</form>";
		
	document.getElementById("invisibleLogo").style.display = "block";
	
	document.getElementById("w1").appendChild(canvas);
	document.getElementById("canvas").appendChild(paddingDiv);
	

	document.getElementById("ReturnHrefText").value = location.href;
	
	if (location.href.indexOf('id=') != -1) {
		var begin = location.href.indexOf('id=');
		var objectnum = location.href.slice(begin, location.href.length);
		document.getElementById("ObjectID").value = objectnum;
	}

}

function CloseRequestDarkBox()
{
	document.getElementById("w1").removeChild(document.getElementById('canvas'));
	document.getElementById("invisibleLogo").style.display = "none";
	
	hideBlackSquare();
}

//Metro darkbox
function ShowMetroDarkBox()
{
	showBlackSquare();
	

	var canvas = document.createElement("div");
	canvas.setAttribute("id", "canvasMetro");
	
	var paddingDiv = document.createElement("div");
	paddingDiv.setAttribute("id", "MetroFormPad");
	paddingDiv.innerHTML = 
		"<div id='MetroMapPicture'></div>" +
		"<div id='MetroX' onclick='MetroCancel();'></div>" +
		"<div id='Metro1Button' onclick='SelectRing(1);'></div>" +
		"<div id='Metro2Button' onclick='SelectRing(2);'></div>" +
		"<div id='MetroClsButton' onclick='Cls();'></div>" +
		"<div id='MetroAcceptButton' onclick='AcceptMetro();'></div>";
		
	document.getElementById("invisibleLogo").style.display = "block";
	
	document.getElementById("w1").appendChild(canvas);
	document.getElementById("canvasMetro").appendChild(paddingDiv);
	
	CreateMetroList();
}

function MetroCancel()
{
	for (idx = 0; idx < 300; idx++)
	{
		if (metro_sel[idx]) {
			metro_sel[idx] = false;
			document.getElementById("station" + idx).style.background = "none";
		}
	}
	
	CloseMetroDarkBox();
}

function CloseMetroDarkBox()
{
	document.getElementById("w1").removeChild(document.getElementById('canvasMetro'));
	document.getElementById("invisibleLogo").style.display = "none";
	
	hideBlackSquare();
}


function ChangeSaleRentOption(what)
{
	if (what == "sell") {
		sb_bgpos = "0 -34px";
		document.getElementById("SearchTabs").style.backgroundPosition = sb_bgpos;
		document.getElementById("RentOrSellText").value = "sale";
		
		// Если выбрана квартира, то надо показать ТИП РЕМОНТА
		var selidx = document.getElementById("selSearchType").options[document.getElementById("selSearchType").selectedIndex].value;
		var selid = parseInt(selidx);
		if (selid == 1) {
			if ($.browser.msie) {
				$("#Decoration").css('display', 'block');
			} else {
				$("#Decoration").css('display', 'table-row');
			}
		}
	}
	
	if (what == "rent") {
		sb_bgpos = "0px 0px";
		document.getElementById("SearchTabs").style.backgroundPosition = sb_bgpos;
		document.getElementById("RentOrSellText").value = "rent";
		
		// Скрываем поля ТИП РЕМОНТА, так как они должны присутствовать только в продаже
		document.getElementById("Decoration").style.display = "none";
	}
}

function HoverSearchButtons(what)
{
	state = document.getElementById("SearchTabs").style.backgroundPosition;
	
	if (what == "rent") {
		if (document.getElementById("RentOrSellText").value == "rent") {
			return;	
		} else {
			sb_bgpos = state;
			document.getElementById("SearchTabs").style.backgroundPosition = "0 -68px";
		}
	} else if (what == "sale") {
		if (document.getElementById("RentOrSellText").value == "rent") {
			sb_bgpos = state;
			document.getElementById("SearchTabs").style.backgroundPosition = "0 -102px";
		} else {
			return;
		}	
	}
}

function RestoreSearchButtons()
{
	document.getElementById("SearchTabs").style.backgroundPosition = sb_bgpos;		
}

//       
function AddSubHighway(fulllist, selllist)
{	
	//   
	var curidx = document.getElementById(fulllist).selectedIndex;
	
	if ($('#' + fulllist + ' :selected').val() == null) return;

	if (document.getElementById(selllist).options[0].value == "0") 
		$('#' + selllist).children().remove();
	
	$('#' + selllist).append($('#' + fulllist + ' :selected'));
	$('#' + fulllist + ' :selected').remove();
	//     
	document.getElementById(fulllist).selectedIndex = curidx - 1;
	
 	/*$('#' + fulllist + ' :selected').each(function(i, selected) {
		
		$(selected).remove();
		$('#' + selllist).append($(selected));
	});*/
	
	//         , 
	//    
	var location = document.getElementById("LocationList");
	var opts = document.getElementById(selllist);
	
	location.value = "";
	
	for (var idx = 0; idx <= opts.options.length - 1; idx++)
	{
		location.value += ' ' + opts.options[idx].value;
	}
	
	// Delete problems from IE 7 o_0
	document.getElementById(selllist).style.backgroundColor = "#eee";
	document.getElementById(selllist).style.backgroundColor = "#fff";
}

function RemoveSubHighway(fulllist, selllist)
{  
	if ( document.getElementById(selllist).options[0].text == " " ) return;
	
	document.getElementById("LocationList").value = "";
	$('#' + fulllist).append($('#' + selllist + ' :selected'));
	$('#' + selllist + ' :selected').remove();

	if ( document.getElementById(selllist).options.length == 0 ) 
	{
		var sh = document.getElementById(selllist);
		sh.options[sh.options.length] = new Option('Не важно', '0');
		return;
	}
	
	document.getElementById(selllist).selectedIndex = document.getElementById(selllist).options.length - 1;
	
	
	var location = document.getElementById("LocationList");
	var opts = document.getElementById(selllist);
	//if (opts.options.length = 1 && opts.options[0].value == "0") location.value = ""; return;
	
	location.value = "";
	for (var idx = 0; idx <= opts.options.length - 1; idx++)
	{
		location.value += ' ' + opts.options[idx].value;
	}
}

function ChangeSearchBlock() {
	var selidx = document.getElementById("selSearchType").options[document.getElementById("selSearchType").selectedIndex].value;

	selid = parseInt(selidx);
	
	switch(selid) {
		case 1: 
			if ($.browser.msie) {
				$("#Subway").css('display', 'block');
				$("#RoomsAmount").css('display', 'block');
				$("#SquareArea").css('display', 'block');
				
				if (document.getElementById("RentOrSellText").value == "sale") {
					$("#Decoration").css('display', 'block');
				}
			} else {
				$("#Subway").css('display', 'table-row');
				$("#RoomsAmount").css('display', 'table-row');
				$("#SquareArea").css('display', 'table-row');
				if (document.getElementById("RentOrSellText").value == "sale") {
					$("#Decoration").css('display', 'table-row');
				}
			}
			
			//hide
			$("#Highway").css('display', 'none');
			$("#FloorsAmount").css('display', 'none');
			
			$("#TransportZone").val("subway");
			break;
		case 2:
			$("#Subway").css('display', 'none');
			$("#RoomsAmount").css('display', 'none');
			$("#SquareArea").css('display', 'none');
			$("#Decoration").css('display', 'none');
			
			if ($.browser.msie) {
				$("#Highway").css('display', 'block');
				$("#FloorsAmount").css('display', 'block');
			} else {
				$("#Highway").css('display', 'table-row');
				$("#FloorsAmount").css('display', 'table-row');
			}
			
			$("#TransportZone").val("highway");
			break;
		default: 
			if ($.browser.msie) {
				$("#Subway").css('display', 'block');
				$("#RoomsAmount").css('display', 'block');
				$("#SquareArea").css('display', 'block');
			} else {
				$("#Subway").css('display', 'table-row');
				$("#RoomsAmount").css('display', 'table-row');
				$("#SquareArea").css('display', 'table-row');
			}
			
			//hide
			$("#Decoration").css('display', 'none');
			$("#Highway").css('display', 'none');
			$("#FloorsAmount").css('display', 'none');
			
			$("#TransportZone").val("subway");
	}
}

// Used from second search form. Search By ID
function FindID()
{
	var loc = document.getElementById("txtSearchById").value;
	
	if (parseInt(loc)) 
	{
		location.href = "http://g-realty.ru/serverside/linkvision.php?id=" + loc;	
	}
}

function CreateMetroList()
{
	metro[082] = new Array("Авиамоторная", 509, 309);
	metro[216] = new Array("Автозаводская", 390, 491);
	metro[101] = new Array("Академическая", 191, 585);
	metro[214] = new Array("Александровский сад", 223, 409);
	metro[091] = new Array("Алексеевская",390,110);
	metro[129] = new Array("Алтуфьево",316,60);
	metro[163] = new Array("Аннино",290,665);
	metro[215] = new Array("Арбатская",207,393);
	metro[212] = new Array("Аэропорт",191,100);
	metro[087] = new Array("Бабушкинская",390,70);
	metro[211] = new Array("Багратионовская",52,297);
	metro[210] = new Array("Баррикадная",179,260);
	metro[209] = new Array("Бауманская",509,229);
	metro[122] = new Array("Беговая",176,199);
	metro[208] = new Array("Белорусская",225,239);
	metro[105] = new Array("Беляево",191,625);
	metro[130] = new Array("Бибирево",316,70);
	metro[213] = new Array("Библиотека Ленина",235,409);
	metro[109] = new Array("Новоясеневская",191,667);
	metro[140] = new Array("Боровицкая",241,419);
	metro[089] = new Array("Ботанический сад",390,90);
	metro[158] = new Array("Братиславская",407,625);
	metro[255] = new Array("Бунинская аллея",290,755);
	metro[090] = new Array("ВДНХ",390,100);
	metro[207] = new Array("Варшавская",365,537);
	metro[254] = new Array("Вернадского проспект",87,645);
	metro[132] = new Array("Владыкино",316,90);
	metro[206] = new Array("Водный стадион",191,70);
	metro[039] = new Array("Войковская",191,80);
	metro[114] = new Array("Волгоградск. пр-т.",490,625);
	metro[156] = new Array("Волжская",407,605);
	metro[205] = new Array("Воробьевы горы",87,625);
	metro[110] = new Array("Выхино",490,665);
	metro[253] = new Array("Выставочная",128,348);
	metro[204] = new Array("Динамо",191,110);
	metro[135] = new Array("Дмитровская",265,179);
	metro[203] = new Array("Добрынинская",290,487);
	metro[202] = new Array("Домодедовская",390,655);
	metro[164] = new Array("Донского Дмитрия бульвар",290,697);
	metro[161] = new Array("Дубровка",407,575);
	metro[201] = new Array("Измайловская",509,189);
	metro[104] = new Array("Калужская",191,615);
	metro[200] = new Array("Кантемировская",390,625);
	metro[199] = new Array("Каховская",302,594);
	metro[198] = new Array("Каширская",390,513);
	metro[197] = new Array("Киевская",158,377);
	metro[096] = new Array("Китай-город",354,349);
	metro[154] = new Array("Кожуховская",407,584);
	metro[218] = new Array("Коломенская",390,501);
	metro[196] = new Array("Комсомольская",386,259);
	metro[106] = new Array("Коньково",191,635);
	metro[195] = new Array("Красногвардейская",390,671);
	metro[078] = new Array("Краснопресненская",187,268);
	metro[005] = new Array("Красносельская",490,100);
	metro[007] = new Array("Красные ворота",372,273);
	metro[153] = new Array("Крестьянская застава",456,439);
	metro[194] = new Array("Кропоткинская",209,436);
	metro[193] = new Array("Крылатское",17,228);
	metro[118] = new Array("Кузнецкий мост",317,312);
	metro[112] = new Array("Кузьминки",490,645);
	metro[192] = new Array("Кунцевская",17,262);
	metro[191] = new Array("Курская",421,317);
	metro[059] = new Array("Кутузовская",72,317);
	metro[100] = new Array("Ленинский проспект",191,575);
	metro[009] = new Array("Лубянка",325,320);
	metro[157] = new Array("Люблино",407,614);
	metro[084] = new Array("Марксистская",418,397);
	metro[159] = new Array("Марьино",407,635);
	metro[190] = new Array("Маяковская",229,265);
	metro[086] = new Array("Медведково",390,60);
	metro[252] = new Array("Международная",128,338);
	metro[137] = new Array("Менделеевская",265,212);
	metro[189] = new Array("Молодежная",17,237);
	metro[144] = new Array("Нагатинская",290,558);
	metro[145] = new Array("Нагорная",290,568);
	metro[146] = new Array("Нахимовский пр-т",290,578);
	metro[079] = new Array("Новогиреево",509,279);
	metro[188] = new Array("Новокузнецкая",333,399);
	metro[068] = new Array("Новослободская",265,224);
	metro[103] = new Array("Новые черемушки",191,605);
	metro[098] = new Array("Октябрьская",241,479);
	metro[124] = new Array("Октябрьск поле",176,179);
	metro[187] = new Array("Орехово",390,645);
	metro[131] = new Array("Отрадное",316,80);
	metro[186] = new Array("Охотный Ряд",289,356);
	metro[73] = new Array("Павелецкая",384,451);
	metro[76] = new Array("Парк Культуры",196,449);
	metro[165] = new Array("Парк Победы",105,376);
	metro[251] = new Array("Партизанская",509,199);
	metro[52] = new Array("Первомайская",509,179);
	metro[080] = new Array("Перово",509,289);
	metro[133] = new Array("Петровско-Разум.",290,130);
	metro[155] = new Array("Печатники",407,595);
	metro[250] = new Array("Пионерская",32,277);
	metro[128] = new Array("Планерная",176,139);
	metro[083] = new Array("Площадь Ильича",456,362);
	metro[185] = new Array("Площадь революции",307,374);
	metro[123] = new Array("Полежаевская",176,189);
	metro[141] = new Array("Полянка",290,469);
	metro[150] = new Array("Пражская",290,645);
	metro[003] = new Array("Преображенская площадь",490,80);
	metro[115] = new Array("Пролетарская",456,451);
	metro[093] = new Array("Проспект Мира",353,234);
	metro[102] = new Array("Профсоюзная",191,595);
	metro[119] = new Array("Пушкинская",223,303);
	metro[41] = new Array("Речной вокзал",191,60);
	metro[092] = new Array("Рижская",390,121);
	metro[152] = new Array("Римская",456,374);
	metro[111] = new Array("Рязанский п-т",490,655);
	metro[136] = new Array("Савеловская",265,189);
	metro[088] = new Array("Свиблово",390,80);
	metro[147] = new Array("Севастопольская",290,594);
	metro[049] = new Array("Семеновская",509,209);
	metro[142] = new Array("Серпуховская",290,499);
	metro[223] = new Array("Скобелевская улица",290,725);
	metro[222] = new Array("Славянский бульвар",63,333);
	metro[184] = new Array("Смоленская",192,378);
	metro[038] = new Array("Сокол",191,90);
	metro[004] = new Array("Сокольники",490,90);
	metro[183] = new Array("Спортивная",87,615);
	metro[221] = new Array("Старокачаловская улица",290,709);
	metro[166] = new Array("Строгино",17,218);
	metro[058] = new Array("Студенческая",82,327);
	metro[094] = new Array("Сухаревская",353,265);
	metro[127] = new Array("Сходненская",176,149);
	metro[116] = new Array("Таганская",414,409);
	metro[33] = new Array("Тверская",229,293);
	metro[32] = new Array("Театральная",298,365);
	metro[113] = new Array("Текстильщики",490,635);
	metro[107] = new Array("Теплый стан",191,645);
	metro[134] = new Array("Тимирязевская",265,169);
	metro[097] = new Array("Третьяковская",322,399);
	metro[167] = new Array("Трубная",297,243);
	metro[143] = new Array("Тульская",290,548);
	metro[095] = new Array("Тургеневская",353,303);
	metro[126] = new Array("Тушинская",176,159);
	metro[121] = new Array("Улица 1905 года",176,209);
	metro[220] = new Array("Улица Горчакова",290,745);
	metro[001] = new Array("Ул. Подбельского",490,60);
	metro[17] = new Array("Университет",87,635);
	metro[219] = new Array("Ушакова адмирала бульвар",290,735);
	metro[62] = new Array("Филевский парк",42,287);
	metro[60] = new Array("Фили",62,307);
	metro[14] = new Array("Фрунзенская",87,605);
	metro[217] = new Array("Царицыно",390,635);
	metro[138] = new Array("Цветной бульвар",285,243);
	metro[002] = new Array("Черкизовская",490,70);
	metro[148] = new Array("Чертановская",290,625);
	metro[139] = new Array("Чеховская",235,303);
	metro[008] = new Array("Чистые пруды",353,291);
	metro[151] = new Array("Чкаловская",423,329);
	metro[099] = new Array("Шаболовская",191,565);
	metro[081] = new Array("Шоссе энтузиастов",509,299);
	metro[53] = new Array("Щелковская",509,169);
	metro[125] = new Array("Щукинская",176,169);
	metro[048] = new Array("Электрозаводская",509,219);
	metro[019] = new Array("Юго-Западная",87,659);
	metro[149] = new Array("Южная",290,635);
	metro[162] = new Array("Янгеля Академика",290,655);
	metro[108] = new Array("Ясенево",191,655);
	
	// Арбатско-Покровская линия
	metro[256] = new Array("Мякинино",17,207);
	metro[257] = new Array("Волоколамская",17,197);
	metro[258] = new Array("Митино",17,187);
	
	// Люблинская линия
	metro[259] = new Array("Достоевская",316,211);
	metro[260] = new Array("Марьина роща",316,189);
	
	for (var i = 0; i < 300; i++)
	{
		if (metro[i])
		{
			var stationid = "station" + i;

			mimg[i] = document.createElement("SPAN");
			mimg[i].style.position = "absolute";
			mimg[i].style.top = metro[i][2] + 'px';
			mimg[i].style.left = metro[i][1] + 'px';
			mimg[i].style.width = "9px";
			mimg[i].style.height = "9px";
			mimg[i].style.overflow = "hidden";
			mimg[i].style.cursor = "hand";
			mimg[i].style.cursor = "pointer";
			//mimg[i].style.background = "url(i/pp.gif) center center no-repeat";
			mimg[i].setAttribute("id", stationid);
			mimg[i].onclick = new Function("AddStation("+i+")");
			
			document.getElementById("MetroFormPad").appendChild(mimg[i]);
		}
	}
	
	// If this is not first load.
	for (idx = 0; idx < 300; idx++)
	{
		if (metro_sel[idx])
		{
			var stid = "station" + idx;
			document.getElementById(stid).style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		}
	}

}

function AddStation(idx)
{
	var s_id = "station" + idx;
	
	//document.getElementById("station28").style.background = "green";
	//document.getElementById("station27").style.background = "red";
	
	//alert(s_id);
	var obj = document.getElementById(s_id);
	
	if (obj.style.backgroundImage == "url(http://g-realty.ru/i/pp.gif)") 
	{
		obj.style.background = "none";
		metro_sel[idx] = false;
	} else {
		obj.style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[idx] = true;
	}
}

function Cls()
{
	var idn;
	
	for (idx = 0; idx <= 300; idx++)
	{
		if (metro_sel[idx]) {
			metro_sel[idx] = false;	
			idn = "station" + idx;
			document.getElementById(idn).style.background = "";
		}
	}
}

function SelectRing(opt)
{
	if (opt==1) // На кольцевой
	{
		metro_sel[197] = true;
		document.getElementById("station197").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[78] = true;
		document.getElementById("station78").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[208] = true;
		document.getElementById("station208").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[68] = true;
		document.getElementById("station68").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[93] = true;
		document.getElementById("station93").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[196] = true;
		document.getElementById("station196").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[191] = true;
		document.getElementById("station191").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[151] = true;
		document.getElementById("station151").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[84] = true;
		document.getElementById("station84").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[116] = true;
		document.getElementById("station116").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[73] = true;
		document.getElementById("station73").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[203] = true;
		document.getElementById("station203").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[98] = true;
		document.getElementById("station98").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[76] = true;
		document.getElementById("station76").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
	} else if (opt==2) // Внутри кольцевой
	{
		metro_sel[194] = true;
		document.getElementById("station194").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[140] = true;
		document.getElementById("station140").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[213] = true;
		document.getElementById("station213").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[214] = true;
		document.getElementById("station214").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[215] = true;
		document.getElementById("station215").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[184] = true;
		document.getElementById("station184").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[141] = true;
		document.getElementById("station141").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[97] = true;
		document.getElementById("station97").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[188] = true;
		document.getElementById("station188").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[185] = true;
		document.getElementById("station185").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[32] = true;
		document.getElementById("station32").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[186] = true;
		document.getElementById("station186").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[118] = true;
		document.getElementById("station118").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[139] = true;
		document.getElementById("station139").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[119] = true;
		document.getElementById("station119").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[33] = true;
		document.getElementById("station33").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[190] = true;
		document.getElementById("station190").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[138] = true;
		document.getElementById("station138").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[167] = true;
		document.getElementById("station167").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[8] = true;
		document.getElementById("station8").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[94] = true;
		document.getElementById("station94").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[95] = true;
		document.getElementById("station95").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[7] = true;
		document.getElementById("station7").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
		metro_sel[96] = true;
		document.getElementById("station96").style.background = "url(http://g-realty.ru/i/pp.gif) center center no-repeat";
	}
}

function AcceptMetro()
{
	document.getElementById("selSubway").options.length = 0;
	for (idx = 0; idx < 300; idx++)
	{
		if (metro_sel[idx]) {
			addOption("selSubway", metro[idx][0], ConvertMetroIndexes(idx));
		}
	}
	
	var location = document.getElementById("LocationList");
	var opts = document.getElementById("selSubway");
	
	location.value = "";
	
	for (var idx = 0; idx <= opts.options.length - 1; idx++)
	{
		location.value += ' ' + opts.options[idx].value;
	}
	
	CloseMetroDarkBox();
}

function addOption (oListbox, text, value, isDefaultSelected, isSelected)
{
	var oOption = document.createElement("option");
	oOption.appendChild(document.createTextNode(text));
	oOption.setAttribute("value", value);
	
	if (isDefaultSelected) oOption.defaultSelected = true;
	else if (isSelected) oOption.selected = true;
	
	document.getElementById(oListbox).appendChild(oOption);
}

function ConvertMetroIndexes(index)
{
	switch(index) {
		case 218: return 28; break;
		case 217: return 23; break;
		case 216: return 29; break;
		case 215: return 44; break;
		case 214: return 54; break;
		case 213: return 11; break;
		case 212: return 37; break;
		case 211: return 61; break;
		case 210: return 120; break;
		case 209: return 47; break;
		case 208: return 35; break;
		case 207: return 27; break;
		case 206: return 40; break;
		case 205: return 16; break;
		case 203: return 74; break;
		case 202: return 21; break;
		case 201: return 50; break;
		case 200: return 24; break;
		case 199: return 26; break;
		case 198: return 25; break;
		case 197: return 42; break;
		case 196: return 70; break;
		case 195: return 20; break;
		case 194: return 12; break;
		case 193: return 66; break;
		case 192: return 64; break;
		case 191: return 71; break;
		case 190: return 34; break;
		case 189: return 65; break;
		case 188: return 31; break;
		case 187: return 22; break;
		case 186: return 10; break;
		case 185: return 45; break;
		case 184: return 43; break;
		case 183: return 15; break;
		default: return index;
	}
}

function mshow(obj, num)
{
	var idd = "flyout" + num;
	
	if (num == 1) {
		document.getElementById("flyout2").style.display = "none";	
	} else {
		document.getElementById("flyout1").style.display = "none";
	}


	// cancel close timer
	mcancelclosetime(obj);

	ddmenuitem = $("#" + idd);
	
	//document.getElementById(obj).style.height = "200px";

	$("#" + idd).slideDown("fast");
}

function FlyoutHide(num)
{
	var idd = "flyout" + num;
	$('#' + idd).hide();
}

function mclose()
{
	if (ddmenuitem) $(ddmenuitem).hide();	
}

function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);	
}

function mcancelclosetime(obj)
{
	document.getElementById(obj).style.height = "auto";
	
	if (closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function AddObjectToNotepad(id,obj)
{
	var allids = getCookie(notecookie);
	
	// Если надо удалить объект из кукисов
	if (obj.className == "removefromnotepad") {
		if (allids != null && allids != "") {
			allids = allids.replace("," + id, "");
			allids = allids.replace(id + ",", "");
			allids = allids.replace(id, "");
			
			obj.className = "addtonotepad";
			obj.innerHTML = "Добавить в блокнот";
			setCookie(notecookie, allids, 365);
			
			// Подправить блок с общей суммой объектов недвижимости
			var curnum = parseInt(document.getElementById("NotepadObjectsAmountText").innerHTML);
			if (curnum == 0 || curnum == NaN || curnum == 1) {
				document.getElementById("NotepadObjectsAmountText").innerHTML = 0;
				$(".notepadWidget").css("display", "none");
			} else {
				document.getElementById("NotepadObjectsAmountText").innerHTML = curnum - 1;
			}
			
			return;
		} else {
			return;
		}
	}
	
	if (allids != null && allids != "") {
		if (allids.indexOf(id) != -1) {
			return;
		} else {
			allids += "," + id;
			setCookie(notecookie, allids, 365);
		}
		
		obj.className = 'removefromnotepad';
		obj.innerHTML = 'Удалить из блокнота';
	} else {
		setCookie(notecookie, id, 365);
		obj.className = 'removefromnotepad';
		obj.innerHTML = 'Удалить из блокнота';
	}
	
	// Подправить блок с общей суммой объектов недвижимости
	var curnum = parseInt(document.getElementById("NotepadObjectsAmountText").innerHTML);
	
	if (curnum == 0 || curnum == NaN) {
		document.getElementById("NotepadObjectsAmountText").innerHTML = 1;
		$(".notepadWidget").css("display", "block");
	} else {
		document.getElementById("NotepadObjectsAmountText").innerHTML = curnum + 1;
	}
}

function ClearNotebook() 
{
	Delete_Cookie(notecookie, '/', '.g-realty.ru');
	
	document.getElementById("NotepadObjectsAmountText").innerHTML = 0;
	$(".notepadWidget").css("display", "none");
	location.href="http://g-realty.ru";
}

function getCookie(c_name)
 {
 var i,x,y,ARRcookies=document.cookie.split(";");
 for (i=0;i<ARRcookies.length;i++)
 {
   x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
   y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
   x=x.replace(/^\s+|\s+$/g,"");
   if (x==c_name)
     {
     return unescape(y);
     }
   }
 }

 function setCookie(c_name,value,exdays)
 {
	 var exdate=new Date();
	 exdate.setDate(exdate.getDate() + exdays);
	 var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()) + "; path=/; domain=.g-realty.ru";
	 document.cookie=c_name + "=" + c_value;
 }
 
 function Delete_Cookie( name, path, domain ) {
document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
















