function hideBigImg() {
	var the_div = document.getElementById('bigimgs');
	if (the_div) the_div.style.display = 'none';
	//
	return false;
}

var preBigImages = new Array();
function preLoadBigImg(sImgSrc) {
	if (typeof(preBigImages[sImgSrc]) === 'undefined') {
		preBigImages[sImgSrc] = new Image();
		preBigImages[sImgSrc].src = sImgSrc;
	}
}

function prepBigImg(sImgSrc) {
	hideBigImg();
	//
	var the_img = document.getElementById('bigimg');
	if (the_img) the_img.src = sImgSrc;
	return false;
}

function showBigImg(theImg) {
	var the_div = document.getElementById('bigimgs');
	if (the_div) {
		if (theImg) {
			var the_divs = the_div.getElementsByTagName('div');
			if (the_divs.length) {
				var the_div_2 = the_divs.item(0);
				if (the_div_2) {
					var arr_childs = the_div_2.childNodes;
					var i=0;
					for (i=(arr_childs.length-1); i>=0; i--) {
						var the_child = arr_childs.item(i);
						if (the_child && the_child.tagName) {
							the_child.style.display = 'none';
						}
					}
					the_div_2.appendChild(theImg);
					theImg.style.display = '';
				}
			}
		}
		//
		the_div.style.visibility = "hidden";
		the_div.style.left = '0px';
		the_div.style.top = '0px';
		the_div.style.display = 'block';
		//
		var iW = the_div.offsetWidth;
		var iH = the_div.offsetHeight;
		//
		var i_win_width = document.documentElement.clientWidth;
		if (!i_win_width) i_win_width = document.body.offsetWidth;
		if (!i_win_width) i_win_width = window.innerWidth;
		if (!i_win_width) i_win_width = 0;
		//
		var i_left = parseInt((i_win_width - iW)/2);
		if (i_left < 0) i_left = 0;
		//
		the_div.style.left = i_left + 'px';
		the_div.style.top = (20 + document.documentElement.scrollTop) + 'px';
		the_div.style.visibility = "visible";
	}
	//
	return false;
}

function highLightMenu(s_stem_path, s_self_path) {
	//alert(s_stem_path + "\r\n" + s_self_path);
	var the_menu1 = document.getElementById('menu1');
	if (the_menu1) {
		var arr_menu1 = the_menu1.childNodes;
		var s = null;
		for (s in arr_menu1) {
			var theLi = arr_menu1[s];
			if (theLi.tagName && theLi.tagName.toUpperCase() === 'LI') {
				var a = theLi.firstChild;
				if (a.href) {
					if (a.href === ('http://www.soldolina.ru' + s_stem_path) || a.href === ('http://www.soldolina.ru' + s_stem_path + '/')) {
						if (theLi.className && theLi.className.length) {
							theLi.className = theLi.className + ' selected';
						} else {
							theLi.className = 'selected';
						}
						break;
					}
				}
			}
		}
	}
	var the_menu2 = document.getElementById('menu2');
	if (the_menu2) {
		var arr_menu2 = the_menu2.childNodes;
		var s = null;
		for (s in arr_menu2) {
			var theLi = arr_menu2[s];
			if (theLi.tagName && theLi.tagName.toUpperCase() === 'LI') {
				var a = theLi.firstChild;
				if (a.href) {
					if (a.href === ('http://www.soldolina.ru' + s_self_path) || a.href === ('http://www.soldolina.ru' + s_self_path + '/')) {
						if (theLi.className && theLi.className.length) {
							theLi.className = theLi.className + ' selected';
						} else {
							theLi.className = 'selected';
						}
						break;
					}
				}
			}
		}
	}
}


function clickSitemap(e) {
	if (!e) var e = event;
	//
	if (e) {
		var theEl = e.target;
		if (!theEl) theEl = e.srcElement;
		if (theEl) {
			var sEl = theEl.tagName.toUpperCase();
			if (sEl === 'A') {
				document.location.href = theEl.href;
			} else if (sEl === 'LI') {
				theUl = theEl.firstChild;
				while (!(theUl.tagName && theUl.tagName.toUpperCase() === 'UL') && theUl.nextSibling) {
					theUl = theUl.nextSibling;
				}
				if (theUl && theUl.tagName && theUl.tagName.toUpperCase() === 'UL') {
					var sState = 'expanded';
					if (theUl.className === 'sitemap-group-expanded') sState = 'collapsed';
					theUl.className = 'sitemap-group-' + sState;
					theEl.className = 'sitemap-item-' + sState;
				}
			}
		}
		if (e.stopPropagation) e.stopPropagation();
		e.cancelBubble = true; // deprecated
	}
	//
	return false;
}


function checkWebForm(obj) {
	var element, pattern;
	for (var i = 0; i < obj.elements.length; i++) {
		element = obj.elements[i];
		if (!element.getAttribute("required")) continue;
		if (pattern = element.getAttribute("check_pattern")) {
			pattern = new RegExp(pattern, "g");
			if (!pattern.test(element.value)) {
				var v_req = element.getAttribute("required");
				if (typeof(v_req) !== 'string' || v_req === "required") v_req = "Необходимо заполнить все обязательные поля";
				alert(v_req);
				element.focus();
				return false;
			} 
		} else if (/^\s*$/.test(element.value)) {
			var v_req = element.getAttribute("required");
			if (typeof(v_req) !== 'string' || v_req === "required") v_req = "Необходимо заполнить все обязательные поля";
			alert(v_req);
			element.focus(); 
			return false; 
		}
	}
	//
	return true; 
}
/* ========================================================================== */

var oMainSwf = null;
var oLargeApart = null;
var oLargeInfo = null;
function hideLargeApart() {
	if (oLargeApart) oLargeApart.style.display='none';
	if (oLargeInfo) oLargeInfo.style.display='none';
	if (oMainSwf) oMainSwf.style.visibility='visible';
	return false
}
var viewApartment = function (sTowerName, iFloor, sApartName, s_appart_title) {

	oLargeApart = $('zoom_apart');
	oMainSwf = $('choose-apps');
	oLargeInfo = $('zoom_info');
	oLargeApart.innerHTML = '';

	new Ajax.Request('/modeldata/apartments/'+sApartName, {
		method: 'get',
		onSuccess: function(transport) {
			var oRes = transport.responseXML;
			if (typeof(oRes.firstChild)) {
				var oRoot = oRes.firstChild;
				var sTitle = s_appart_title;//oRoot.getAttribute('title');
				var sSrc = oRoot.getAttribute('image');

				var sText = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tbody>'
						+ '<tr><td id="zoom_apart_td1"><div class="relater"><table width="100%" border="0"><tbody><tr>'
							+ '<td><h4>' + sTitle + ', ' + iFloor + ' этаж</h4></td>'
							+ '<td><a href="#" title="вернуться" onclick="return hideLargeApart();"><h4>назад</h4></a></td>'
						+ '</tr></tbody></table></div></td></tr>'
						+ '<tr><td id="zoom_apart_td2"><div class="relater">'
							+ '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="bigapart" align="middle" width="504" height="587">'
								+ '<param name="allowScriptAccess" value="sameDomain" />'
								+ '<param name="movie" value="' + sSrc + '" />'
								+ '<param name="quality" value="high" />'
								+ '<param name="bgcolor" value="#FFFFFF" />'
								+ '<param name="wmode" value="transparent" />'
								+ '<embed src="' + sSrc + '" quality="high" bgcolor="#ffffff" width="504" height="587" name="bigapart" align="middle" allowScriptAccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
							+ '</object>'
						+ '</div></td></tr>'
					+ '</tbody></table>';

				if (oLargeApart) {
					if (oMainSwf) oMainSwf.style.visibility = 'hidden';
					oLargeApart.innerHTML = sText;
					oLargeApart.style.display = 'block';
				}
				//
				var s_info = "<table><thead><tr><th>Поз.</th><th>Помещение</th><th>Площадь (м.кв)</th></tr></thead><tbody>";
				var s_text = "";
				var s_general_sq = oRoot.getAttribute('square');
				var arr_nodes = oRoot.childNodes;
				var i_node = 0;
				for (i_node = 0; i_node < arr_nodes.length; i_node++) {
					var the_node = arr_nodes.item(i_node);
					if (the_node.nodeType && the_node.nodeType == 1) {
						if (the_node.nodeName == 'obj') {
							s_info += "<tr><td>" + (the_node.getAttribute('name')) + "</td><td>" + (elementHTML(the_node)) + "</td><td>" + (the_node.getAttribute('square')) + "</td></tr>";
						} else if (the_node.nodeName == 'text') {
							s_text = (elementHTML(the_node));
						}
					}
				}
				s_info += "</tbody><tfoot><tr><th colspan=\"3\">Общая площадь: " + s_general_sq + " кв. м</th></tr></tfoot></table>";
				if (oLargeInfo) {
					if (oMainSwf) oMainSwf.style.visibility = 'hidden';
					oLargeInfo.innerHTML = s_info + "<br/><br/>" + s_text;
					oLargeInfo.style.display = 'block';
				}
				//
				if (window.scrollTo) {
					window.scrollTo(0, 80);
				} else if (window.scroll) {
					window.scroll(0, 80);
				}
			}
		}
	});

}

var apartmentDemand = function(sTowerName, iFloor, sApartName, s_appart_title) {

	var theForm = document.createElement('form');
	theForm.action="/mailer.php";
	theForm.method = "post";
	//theForm.onsubmit="return checkWebForm(this);";

	theForm.style.position = "relative";
	theForm.style.padding = "0px";
	theForm.style.paddingTop = "97px";
	theForm.style.marginBottom = "16px";
	theForm.style.marginLeft = "20px";
	theForm.style.marginRight = "20px";

	var theHidden = document.createElement('input');
	theHidden.type = "hidden";
	theHidden.name = "fb[appartment]";
	theHidden.value = s_appart_title;
	theForm.appendChild(theHidden);

	var theHidden = document.createElement('input');
	theHidden.type = "hidden";
	theHidden.name = "service[onsuccess]";
	theHidden.value = '/services/messagesendok';
	theForm.appendChild(theHidden);

	var theHidden = document.createElement('input');
	theHidden.type = "hidden";
	theHidden.name = "service[onerror]";
	theHidden.value = '/services/messagesenderr';
	theForm.appendChild(theHidden);

	var theHidden = document.createElement('input');
	theHidden.type = "hidden";
	theHidden.name = "service[oncaptcha]";
	theHidden.value = '/services/messagesendcaptcha';
	theForm.appendChild(theHidden);

	var theHidden = document.createElement('input');
	theHidden.type = "hidden";
	theHidden.name = "service[recipients]";
	theHidden.value = 'fb_mails';
	theForm.appendChild(theHidden);

	//theForm.style.borderStyle = "solid";
	//theForm.style.borderWidth = "1px";
	//theForm.style.borderColor = "#936f4c";

	theForm.style.width = "580px";
	theForm.style.height = "330px";

	var theTable = document.createElement('table');
	theTable.width = "100%";
	theTable.cellPadding = "0";
	theTable.cellSpacing = "0";

	var theTBody = document.createElement('tbody');

	var arr_inputs = new Array();
	arr_inputs[0] = new Array("string", "fb[name]", "Ф.И.О.", "Укажите, пожалуйста, ваше имя");
	arr_inputs[1] = new Array("string", "fb[mail]", "E-mail", "Укажите, пожалуйста, ваш e-mail для связи");
	arr_inputs[2] = new Array("string", "fb[phone]", "Телефон", "");
	arr_inputs[3] = new Array("string", "fb[country]", "Страна", "");
	arr_inputs[4] = new Array("string", "fb[city]", "Город", "");
	arr_inputs[5] = new Array("text", "fb[message]", "Текст", "Введите, пожалуйста, текст сообщения");

	// ====
	var f = 0;
	for (f=0; f<arr_inputs.length; f++) {
		arr_input = arr_inputs[f];
		if (arr_input[0] === "string") {
			var theTr = document.createElement('tr');
			theTr.style.height = "28px";

			var theTd1 = document.createElement('td');
			theTd1.style.width = "150px";
			theTd1.style.color = "#FFEEC3";
			theTd1.style.fontWeight = "bold";

			theTd1.innerHTML = arr_input[2];

			var theTd2 = document.createElement('td');
			theTd2.style.width = "450px";
			theTd2.style.whiteSpace = "nowrap";

			var theInput = document.createElement('input');
			theInput.name = arr_input[1];
			theInput.type = "text";
			theInput.style.width = "440px";
			theInput.style.height = "20px";
			theInput.style.borderTop = "1px solid #9d8362";
			theInput.style.borderLeft = "1px solid #9d8362";
			theInput.style.borderBottom = "none";
			theInput.style.borderRight = "none";
			theInput.style.color = "#76451c";
			theInput.style.fontWeight = "bold";

			var theSup = document.createElement('sup');

			if (arr_input[3]) {
				theSup.innerHTML = "*";
				theSup.style.marginLeft = "5px";
				theSup.style.color = "#FFEEC3";
			}

			theTd2.appendChild(theInput);
			theTd2.appendChild(theSup);

			theTr.appendChild(theTd1);
			theTr.appendChild(theTd2);

			theTBody.appendChild(theTr);
		} else if (arr_input[0] === "text") {
			var theTr = document.createElement('tr');
			theTr.style.height = "138px";

			var theTd1 = document.createElement('td');
			theTd1.style.width = "150px";
			theTd1.style.color = "#FFEEC3";
			theTd1.style.fontWeight = "bold";

			theTd1.innerHTML = arr_input[2];

			var theTd2 = document.createElement('td');
			theTd2.style.width = "450px";
			theTd2.style.whiteSpace = "nowrap";

			var theInput = document.createElement('textarea');
			theInput.name = arr_input[1];
			theInput.style.width = "440px";
			theInput.style.height = "130px";
			theInput.style.overflow = "auto";
			theInput.style.borderTop = "1px solid #9d8362";
			theInput.style.borderLeft = "1px solid #9d8362";
			theInput.style.borderBottom = "none";
			theInput.style.borderRight = "none";
			theInput.style.color = "#76451c";
			theInput.style.fontWeight = "bold";

			var theSup = document.createElement('sup');

			if (arr_input[3]) {
				theSup.innerHTML = "*";
				theSup.style.marginLeft = "5px";
				theSup.style.color = "#FFEEC3";
			}

			theTd2.appendChild(theInput);
			theTd2.appendChild(theSup);

			theTr.appendChild(theTd1);
			theTr.appendChild(theTd2);

			theTBody.appendChild(theTr);
		}
	}
	// ====
	var theTr = document.createElement('tr');
	theTr.style.height = "28px";

	var theTd1 = document.createElement('td');
	theTd1.style.width = "150px";
	theTd1.style.color = "#FFEEC3";
	theTd1.style.fontWeight = "bold";

	theTd1.innerHTML = "Введите символы";

	var theTd2 = document.createElement('td');
	theTd2.style.width = "360px";
	theTd2.style.whiteSpace = "nowrap";
	theTd2.style.paddingLeft = "92px";
	theTd2.style.background = "url(/captcha.php) 0px 1px no-repeat";

	var theInput = document.createElement('input');
	theInput.name = "captcha";
	theInput.type = "text";
	theInput.style.width = "348px";
	theInput.style.height = "20px";
	theInput.style.borderTop = "1px solid #9d8362";
	theInput.style.borderLeft = "1px solid #9d8362";
	theInput.style.borderBottom = "none";
	theInput.style.borderRight = "none";
	theInput.style.color = "#76451c";
	theInput.style.fontWeight = "bold";

	var theSup = document.createElement('sup');
	theSup.innerHTML = "*";
	theSup.style.marginLeft = "5px";
	theSup.style.color = "#FFEEC3";

	theTd2.appendChild(theInput);
	theTd2.appendChild(theSup);

	theTr.appendChild(theTd1);
	theTr.appendChild(theTd2);

	theTBody.appendChild(theTr);
	// ====

	var theTr = document.createElement('tr');
	theTr.style.height = "28px";
	var theTd1 = document.createElement('td');
	var theTd2 = document.createElement('td');
	var theSubmit = document.createElement('input');
	theSubmit.type = "submit";
	theSubmit.value = "";

	theSubmit.style.width = "108px";
	theSubmit.style.height = "29px";
	theSubmit.style.border = "1px solid #9d8362";
	theSubmit.style.background = "#76451c url(/images/sbtn.jpg) 0 0 no-repeat";

	theTd2.appendChild(theSubmit);
	theTr.appendChild(theTd1);
	theTr.appendChild(theTd2);
	theTBody.appendChild(theTr);
	// ====

	theTable.appendChild(theTBody);
	theForm.appendChild(theTable);
	//
	showBigImg(theForm);
}

var elementHTML = function(o_element) {
	if (false && o_element.text) {
		return o_element.text;
	} else {
		var o_div = document.createElement('DIV');

		var arr_nodes = o_element.childNodes;
		var i_node = 0;
		for (i_node = 0; i_node < arr_nodes.length; i_node++) {
			var the_node = arr_nodes.item(i_node);
			if (the_node.nodeType == 1) {
				o_div.innerHTML = o_div.innerHTML + "<" + the_node.nodeName + ">" + elementHTML(the_node) + "<" + the_node.nodeName + "/>";
			} else if (the_node.nodeType == 3 || the_node.nodeType == 4) {
				o_div.innerHTML = o_div.innerHTML + the_node.nodeValue;
			}
		}

		return o_div.innerHTML;
	}
}
