//----------------------------------------------------------windows-1251----
//	Title				Base site scripts
//  Date 				13 August 2008
//  Copyright	 		Ulter West, http://uw.ru
//  Version				1.0
//--------------------------------------------------------------------------
//	Desription
//--------------------------------------------------------------------------
//	Файл объединяет скрипты (JavaScript) для стандартного сайта. 
//--------------------------------------------------------------------------
//	Contents
//--------------------------------------------------------------------------
//	Даный файл содержит содержимое следующих файлов
//	использовавшихся для разработки ранее:
//
//	cookie.js			работа с куками;
//	ValidForm.js		валидация форм;
//	ShowImage.js		показывает увеличенную версию картинки в новом окне;
//	searchtips.js		показывает реферер поисковых систем, со ссылками на карту сайта и т.п.;
//	PrintMode.js		переключение на версию для печати (добавляет к URI параметр printmode);
//	addmessage.js		добавление сообщений на доску объявлений и в форум;
//
//	Файл разделён на секции соответствующие ранее существовавшим файлам,
//	
//--------------------------------------------------------------------------

//Подключает валидацию поиска и вывод пояснени в поле запроса
//к форме с id="search"
//Временно не используется
/*(function(){
		var oldonload = window.onload;
		window.onload=function(){
		if (typeof oldonload == 'function' && !!oldonload) oldonload();

			var _lang = UWCONST['language'];
			var _phrase = UWCONST['search']['phrase'][_lang];
			var _err_msg = UWCONST['search']['error'][_lang];
			
			var trim = /(^\s+)|(\s+$)/g;
			
			if (!document.forms["search"])return; 
			with (document.forms["search"]){
				q.onfocus = function(){	if (q.value.replace(trim,'')==_phrase) q.value='';};
				q.onblur = function(){if (q.value.replace(trim,'')=='') q.value=_phrase;};

				onsubmit = function(){
					var t = q.value.replace(trim, ''); 
					if (t == '' || t == _phrase)
					{
						alert(_err_msg);
						q.focus();
						return false;
					}
				};
			}
		}
	})();


// Реализует CSS своиство min-width в ie6 для BODY
(function(){
	var _width = UWCONST['minWidthIE6'];
	if (_width == 0 || navigator.appVersion.search('MSIE 6') == -1) return;
	
	var handler = function(){
		if (document.documentElement.clientWidth <= 1000)
			document.body.style.width=_width + 'px';
		else if(document.body.style.width == "1000px")
			document.body.style.width = "100%"; 
	};
	var oldonload = window.onload;
	window.onload = function(){
		oldonload();
		handler();
	};

	var oldonresize = window.onresize;
	window.onresize = function(){
		if (typeof oldonresize == 'function' && !!oldonresize) oldonresize();
		handler();
	};
})();*/


//--------------------------------------------------windows-1251----
//	Title				BlockGallery (Script)
//  Date 				2008 October 28
//  Author	 			Alexey Generalov [webradical]
//  Copyright	 		Ulter West
//  Version				1.3
//	Last edit			20081106
//------------------------------------------------------------------
	function BlockGallery()
	{
	
		var div = document.body.getElementsByTagName("div");
		var n = div.length;
		
		var gallery = [];
		
		for (var i = 0; i < n; i++)
			if (div[i].className == "BlockGallery") gallery.push(div[i]);

		if (gallery.length == 0)
			return;
		
		var that = this;
		
		var n = gallery.length;
		for (var i = 0; i < n; i++)
			createGallery(gallery[i]);

		function createGallery(gallery)
		{
			if (!gallery) return;
			
			var wrapper = document.createElement("div");
			wrapper.className = "wrapper";
			
			
			var source_data = gallery.firstChild;
			
			var source = gallery.getElementsByTagName("img");
			var source_captions = gallery.getElementsByTagName("span");
	
			var captions = [];		
			var caption = document.createElement("p");
			caption.appendChild(document.createTextNode(""));
			caption.className = "BlockGalleryCaption";
			
			if (that.CAPTION)
			{
				for (var i = 0; i < source_captions.length; i++)
					captions.push(source_captions[i].firstChild.nodeValue);
					
			}

			var gallery_width = that.GALLERY_WIDTH;
			var gallery_height = that.GALLERY_HEIGHT;

			
			if (that.AUTO_SIZE_MODE)
			{
				var max_width = 0;
				var max_height = 0;
				var n =  source.length;
				
				for (var i = 0; i < n; i++)
				{
					max_width = (max_width < source[i].width) ? source[i].width : max_width;
					max_height = (max_height < source[i].height) ? source[i].height : max_height;
				}
				
				gallery_width = max_width;
				gallery_height = max_height;
				
			}
			
			gallery.style.width = gallery_width + "px";
			wrapper.style.height = gallery_height + "px";
			
			var first = source[0].cloneNode(false);
			var last = source[source.length - 1].cloneNode(false);
			
			first.width = source[0].width;
			first.height = source[0].height;
			last.width = source[source.length-1].width;
			last.height = source[source.length-1].height;
		
			var images = [last];
			for (var i = 0; i < source.length; i++)
				images.push(source[i]);
			images.push(first);
	
			var index = 1;
			var positions = [];
			var sumwidth = 0;
			var block = false;
		
			for (var i = 0; i < images.length; i ++)
			{
				positions.push(sumwidth);
				
				if (that.ONE_IMAGE_PER_FRAME_MODE)
				{
					var deltaWidth = images[i].width - gallery_width;
					var deltaHeight = images[i].height - gallery_height;
					
					if (deltaWidth < 0)
					{
						var margins = parseInt(Math.abs(deltaWidth)/2);
						var xoffset = Math.abs(deltaWidth) % 2;
						images[i].style.marginLeft = margins + "px";
						images[i].style.marginRight = margins + xoffset + "px";
					}

					if (deltaHeight < 0)
					{
						var margins = parseInt(Math.abs(deltaHeight)/2);
						images[i].style.marginTop = margins + "px";
					}
					
				}

	
				if (that.ONE_IMAGE_PER_FRAME_MODE)
					sumwidth += gallery_width;
				else
					sumwidth += images[i].width;
				
				images[i].style.position = "static";
				images[i].style.cssFloat = "left";
				images[i].style.width=images[i].width + "px";
				
				if (that.ORIGINAL_VIEW_MODE)
				{
					var isSmall = /(_\d*x\d*)\.\w{3}$/g
					var parts = /(.+)(_\d*x\d*)(\.\w{3})$/g
			
					images[i].src.match(parts);
					
					if (RegExp.$2)
					{
						var original = RegExp.$1 + RegExp.$3;

						var a = document.createElement("a");
						a.setAttribute("href", original);
						
						function cl(p){
							return function(){photoGallery.addImage(p); return false;};
						}
						
						a.onclick = cl(a);
						
						a.appendChild(images[i]);
						wrapper.appendChild(a);
					}else{
						wrapper.appendChild(images[i]);
					}
				}
				else
				{
					wrapper.appendChild(images[i]);
				}

			}
			
			wrapper.style.width = sumwidth + "px";
			
			
			wrapper.style.overflow = "hidden";

			wrapper.style.position= "relative";
			wrapper.style.left= "-" + positions[1] + "px";
		
			gallery.style.position = "relative";
			gallery.style.overflow = "hidden";
			
			if (that.CAPTION && that.CAPTION_SIDE == "TOP")
				gallery.appendChild(caption);
			gallery.appendChild(wrapper);
			if (that.CAPTION && that.CAPTION_SIDE == "BOTTOM")
				gallery.appendChild(caption);
		
			/* Navigation */
			var navBar = document.createElement("ul");
			var backButton = document.createElement("li");
			var nextButton = document.createElement("li");
			var firstButton = document.createElement("li");
			var lastButton = document.createElement("li");
			var leftDotsButton = document.createElement("li");
			var rightDotsButton = document.createElement("li");
			
			backButton.appendChild(document.createTextNode("<"));
			nextButton.appendChild(document.createTextNode(">"));
			
			firstButton.appendChild(document.createTextNode("<<"));
			lastButton.appendChild(document.createTextNode(">>"));
			
			leftDotsButton.appendChild(document.createTextNode("..."));
			rightDotsButton.appendChild(document.createTextNode("..."));
					
			backButton.style.cursor = "pointer";
			nextButton.style.cursor = "pointer";
			firstButton.style.cursor = "pointer";
			lastButton.style.cursor = "pointer";
			leftDotsButton.style.cursor = "pointer";
			rightDotsButton.style.cursor = "pointer";
			
			navBar.appendChild(firstButton);
			navBar.appendChild(backButton);
			navBar.appendChild(leftDotsButton);
	
			for (var i = 1, item, node; i < images.length -1; i ++)
			{
				item = document.createElement("li");
				node = document.createTextNode(i);
				item.appendChild(node);
				item.onclick = goToPosition;
				item.style.cursor = "pointer";
				navBar.appendChild(item);
			}
		
			navBar.appendChild(rightDotsButton);
			navBar.appendChild(nextButton);
			navBar.appendChild(lastButton);
			
					
			navBar.className = "BlockGalleryPager";


			var scrollStep = 150;
			var interval = 100;
			var clear = null;

			nextButton.onclick = next;
			rightDotsButton.onclick = next;
			backButton.onclick = back;
			leftDotsButton.onclick = back;
			lastButton.onclick = toLast;
			firstButton.onclick = toFirst;
			
			gallery.appendChild(navBar);
		
			update();
			
			gallery.removeChild(source_data);
			
		
			function abstractNext(pos)
			{
				var k = Math.abs(pos - index);
			
				var left = wrapper.style.left;
				left = parseInt(left.match(/\d+/));
						
				if (Math.abs(positions[pos] - left) > k*scrollStep)
				{
					left = (pos-index > 0) ? left + k*scrollStep : left - k*scrollStep;			
					wrapper.style.left = "-" + left + "px";
					return false;				
				}
			
			
				if (pos == images.length-1)
				{
					index = 1;
				}else if (pos==0)
				{
					index = images.length-2;
				}else{
					index = pos;
				}
	
				wrapper.style.left = "-" + positions[index] + "px";
				window.clearInterval(clear);
				update();
				block=false;
			}

			function goToPosition()
			{
				this.className = "selected";
			
				if (block==false) 
					block=true;
				else
					return;
				
				var pos = parseInt(this.childNodes[0].nodeValue);
				clear = window.setInterval(function(){abstractNext(pos);}, interval);
			}
		
			function next()
			{
				if (block==false) 
					block=true;
				else
					return;
			
				clear = window.setInterval(function(){abstractNext(index + 1);}, interval);
			}
		
			function back()
			{

				if (block==false) 
					block=true;
				else
					return;
					
				clear = window.setInterval(function(){abstractNext(index - 1);}, interval);
			}
			
			function toFirst()
			{
				if (index==1)  return;
				
				if (block==false) 
					block=true;
				else 
					return;

				clear = window.setInterval(function(){abstractNext(1);}, interval);
			}
			
			function toLast()
			{
				if (index==images.length - 2)  return;
	
				if (block==false) 
					block=true;
				else 
					return;

				clear = window.setInterval(function(){abstractNext(images.length - 2);}, interval);
			}
			
		
			function update()
			{
				if (that.CAPTION) caption.firstChild.nodeValue = captions[index - 1];
				
				var delta = images.length - 2 - that.PAGER_SIZE;
				var k = index - that.PAGER_SIZE; 
				
				var nodes = navBar.getElementsByTagName("li");
				var n = nodes.length;
				
				var offset = 3;
				
				for (var i = 0; i < n; i++)
				{
					nodes[i].className = (i == index + 2) ? "selected" : "";
					nodes[i].style.display = "block";
					if ((i >= offset && i < n-offset) && (i < k + offset || (i > that.PAGER_SIZE + k + (offset - 1) && k > 0) || (i > that.PAGER_SIZE + (offset - 1) && k <= 0))) nodes[i].style.display = "none";
				}
				if (k <= 0) nodes[offset - 1].style.display = "none";
				if (k == that.PAGER_SIZE) nodes[nodes.length - offset].style.display = "none";
			
			}
		

		}		
	}


	//Определяем размеры для галереи в [px]
	BlockGallery.prototype.GALLERY_WIDTH = 500;
	BlockGallery.prototype.GALLERY_HEIGHT = 500;
	
	BlockGallery.prototype.ONE_IMAGE_PER_FRAME_MODE = true;
	BlockGallery.prototype.AUTO_SIZE_MODE = false;
	BlockGallery.prototype.ORIGINAL_VIEW_MODE = true;
	BlockGallery.prototype.CAPTION = true;
	BlockGallery.prototype.CAPTION_SIDE = "TOP";
	BlockGallery.prototype.PAGER_SIZE = 5;

//--------------------------------------------------windows-1251----
//	Title				Photo Gallery (Script)
//  Date 				20 October 2008
//  Author	 			Alexey Generalov [webradical]
//  Copyright	 		Ulter West
//  Version				1.1
//	Last Edit			20081021
//------------------------------------------------------------------
// 	Скрипт позволяет организовать на сайт фотогаллерею,
//  с возможностью открывать, перетаскивать и закрывать 
//	полноразмерные изображения.
//
//	Пример подключения:
//	<div class="photo">
//	<a href="/images/upload/71/ru/land2_big.jpg" onclick="photoGallery.addImage(this); return false;">
//	<img alt="ОБъект 2_big" title="ОБъект 2_big" align="" width="150" height="112" src="/images/upload/71/ru/land2.jpg" class=""/>
//	</a>
//	</div>
//------------------------------------------------------------------
	
	function PhotoGallery()
	{
		var photos = [];
		
		this.push = function(obj){photos.push(obj);}
		
		this.remove = function(obj){
			for (var i = 0; i < photos.length; i++) 
			{
				if (photos[i] == obj)
					photos.splice(i, 1);
			}
			this.update();
		}
		
		this.getIndex = function(obj)
		{
			for (var i = 0; i < photos.length; i ++)
			{
				if (obj == photos[i]) return i;
			}
			throw Error("Неизвестный объект");
		}
		
		this.getSize = function(){return photos.length;}
		
		this.bubble = function(obj){
			for (var i = 0; i < photos.length; i ++)
				if (obj == photos[i]) break;
				
			photos.splice(i, 1);
			photos.push(obj);
			this.update();
		}
		
		this.update = function()
		{
			for (var i = 0; i < photos.length; i ++)
				photos[i].style.zIndex = i + 1;
		}
		
		this.inGallery = function(src)
		{
			for (var i = 0; i < photos.length; i++)
			{
				if (photos[i].getElementsByTagName("img")[0].src == src)
					return true;
			}
			return false;
		}
	}
	
	PhotoGallery.prototype.MAX_WIDTH = 800;
	PhotoGallery.prototype.MAX_HEIGHT = 800;
	
	PhotoGallery.prototype.addImage = function(anchor)
	{
		if (!anchor) throw Error("Функция вызвана с недопустимым количеством аргументов");
		if (!anchor.href) throw Error("Не указан URL изображения");
		
		var that = this;
		var origImage = new Image();
		
		if (this.inGallery(anchor.href)) return;
		
		var wrapper = document.createElement("div");
		wrapper.className = "original-photo";
		wrapper.appendChild(origImage);
		
		this.push(wrapper);
		
		if (document.addEventListener)
			origImage.addEventListener("load", originalConstruction, false);
		else if (document.attachEvent)
			origImage.attachEvent("onload", originalConstruction);
	
		origImage.src = anchor.href;
		origImage.style.cursor = "pointer";

		function originalConstruction()
		{
			if (origImage.width > that.MAX_WIDTH || origImage.height > that.MAX_HEIGHT)
			{ 
				window.open(origImage.src,"");
				return;
			}

			var icon = anchor.getElementsByTagName('img')[0];
			
			var c = {
				"x" : parseInt(getLeft(icon) + icon.width/2),
				"y" : parseInt(getTop(icon) + icon.height/2)
			};
		
			wrapper.style.position = "absolute";
			wrapper.style.zIndex = that.getIndex(wrapper) + 1;
			
			var pos = {
				"x" : parseInt(c.x - origImage.width/2),
				"y" : parseInt(c.y - origImage.height/2)
			};
			
						
			wrapper.style.left = pos.x + "px";
			wrapper.style.top = pos.y + "px";
		
			document.body.appendChild(wrapper);
			
			wrapper.onmousedown = function(e){
					drag(e, wrapper);
			}
			
			
			function getLeft(obj)
			{
					var r = 0;
					r = obj.offsetLeft
					obj = obj.offsetParent;
					
					if (obj.tagName != 'BODY' && obj.tagName != 'HTML')
						r += getLeft(obj);
					else
						r += obj.offsetLeft;
					return r;					
			}
			function getTop(obj)
			{
					var r = 0;
					r = obj.offsetTop;
					obj = obj.offsetParent;
					
					if (obj.tagName != 'BODY' && obj.tagName != 'HTML')
						r += getTop(obj);
					else
						r += obj.offsetTop;
					return r;					
			}				
		}

		function drag(event, element)
		{
			
			var event = event || window.event;
			var startPos = {x : element.offsetLeft, y : element.offsetTop};
		
			var dX = event.clientX - element.offsetLeft;
			var dY = event.clientY - element.offsetTop;
	
			if (document.addEventListener)
			{
				document.addEventListener("mousemove", moveHandler, true);
				document.addEventListener("mouseup", upHandler, true);
			}
			else if(document.attachEvent)
			{
				element.setCapture();
				element.attachEvent("onmousemove", moveHandler);
				element.attachEvent("onmouseup", upHandler);
				element.attachEvent("onlosecapture", upHandler);
			}
		
			if (event.stopPropagation) event.stopPropagation();
			else event.cancelBubble = true;
		
			if (event.preventDefault) event.preventDefault();
			else returnValue = false;
		
			element.style.cursor = "move";
		
			function moveHandler(e)
			{	
				var e = e || window.event;
		
				element.style.left = e.clientX - dX + "px";
				element.style.top = e.clientY - dY + "px";
			
				if (e.stopPropagation) e.stopPropagation();
				else e.cancelBubble = true;
			}
			
			function upHandler(e)
			{
				var e = e || window.event;
			
				if (document.removeEventListener)
				{
					document.removeEventListener("mouseup", upHandler, true);
					document.removeEventListener("mousemove", moveHandler, true);
				}
				else if (element.detachEvent)
				{
					element.detachEvent("onlosecapture", upHandler);
					element.detachEvent("onmouseup", upHandler);
					element.detachEvent("onmousemove", moveHandler);
					element.releaseCapture();
				}
			
				if (e.stopPropagation) e.stopPropagation();
				else e.cancelBubble = true;
			
				if (element.offsetLeft == startPos.x && element.offsetTop == startPos.y)
				{
					var zindex = parseInt(element.style.zIndex);
					if (zindex < that.getSize())
					{
						that.bubble(element);
					}else{
						that.remove(element);
						element.parentNode.removeChild(element);						
					}
				}
				element.style.cursor = "pointer";
			}
		}

	}
	
	var photoGallery = new PhotoGallery();
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------

		//Вставляет на страницу текстовое поле с текстом ссылки на текущую страницу
		//чтобы её мог скопировать оттуда пользователь и вставить на свой сайт или блог
		//
		//пример ссылки:
		//<a href="#" onclick="pageLink(this); return false;">Получить ссылку на эту страницу</a>  
		function pageLink(obj)
		{
			if (obj.nextSibling.tagName == "TEXTAREA")
			{
				obj.parentNode.removeChild(obj.nextSibling);
				return;
			}
			
			var text = '<a href="' + location + '">' + document.title  + '</a>';
			var node = document.createElement('textarea');
			node.className = "pageLink";
			node.appendChild(document.createTextNode(text));
			obj.parentNode.insertBefore(node, obj.nextSibling);
		}
//--------------------------------------------------------------------------		
		// Защита E-mail от спам роботов
		// Ссылка на адрес vasya@mail.ru будет выглядеть так
		// <a href="javascript:void pismo('vasya','mail.ru')">Написать письмо (здесь так же может быть картинка с адресом)</a> 
		function pismo()
		{
			if (!arguments[0] || !arguments[1]) alert('Неправильно указан адрес почты');
			location = 'mailto:' + arguments[0] + '@' + arguments[1];
			return false;
		}
//--------------------------------------------------------------------------		
		// Добавляет текущую страницу в избранное (IE, FF, Opera)
		// в качестве названия по умолчанию используется title страницы.
		// Для остальных браузеров (Safari) выводится сообщение что данная функция для них недоступна
		// 
		// Пример:
		// <a href="/" onclick="return addBookmark(this)">Добавить в избранное</a>
		//
		// если href=="/" то добавляется текущая страница, если href != "/" 
		// то добавляется страница с адресом который указан в href.
		// Если у ссылки прописан аттрибут title то он используется в качестве названия закладки,
		// если его нет то в качестве имени закладки используется заголовок документа.
		
 		function addBookmark(a){
 			if (!a) return false;
 			var title = a.getAttribute('title')  || document.title;
 			var href = (a.getAttribute('href') && a.getAttribute('href')!='/') || location.href;
 			 
			try{
 				window.external.AddFavorite(href, title);
 			}catch(e){
 				try{
 					window.sidebar.addPanel(title, href,"");
 				}catch(e){
 					if (window.opera && a){
 						if (!a.getAttribute('rel')) a.setAttribute('rel', 'sidebar');
 						a.setAttribute('href', location.href);
 						a.setAttribute('title', title);
 						return true;
 					}else{
 						alert("Ваш браузер не поддерживает эту функцию.\nНажмите, пожалуйста, <Ctrl> + <D>\nчтобы добавить сайт в избранное.");
 						return false;
 					}
 					
 				}
 			}
 			return false;
 		}
 		
//-------------------------------------------------------------------------- 		
//	ValidForm(.js)
//	Автоматическая проверка полей формы
// 	Последнее редактирование - 31.01.2007
//--------------------------------------------------------------------------
//	INSTRUCTION
//--------------------------------------------------------------------------
/*
	Использование скрипта автоматической проверки полей формы:
	1. Во всех <input> элементах формы, требующих проверки на правильность заполнения необходимо прописать атрибут
			title: текстовое название поля (будет использоваться при выводе сообщения об ошибке).
            Если проверяемая форма состоит из единственного поля (input), атрибут title не требуется.			
	2. Для каждого элемента формы необходимо создать метку вида:
		<label id="код_шаблона" for="id_элемента"></label>
	 Где:
		id_элемента: id элемента, для которого должно применяться правило проверки
		код_шаблона: шаблон, по которому будет осуществляться проверка

	Доступные коды шаблонов:
		text:  поле проверяется только на наличие содержимого, без анализа самого содержимого
		int:   поле проверяется на соответствие типу int (целочисленная величина)
		float: поле проверяется на соответствие типу float (дробная числовая величина)
		email: поле проверяется на соответствие корректному адресу email
		phone: поле проверяется на соответствие корректному номеру телефона
		вида +7(495)234-3472 или 151-68-55 или 8 (495) 7376047 ну и т.п.
		alph:  поле проверяется на отсутствие символов русского алфавита и спецсимволов (допускаются цифры, латинские буквы большие и малые, а также точка (.) и дефис (-))
		select: выпадающее меню проверяется на выбранность ненулевого элемента списка (option value != "")
		checkbox: флажок проверяется на помеченность
		radio: переключатель проверяется на помеченность
		file: поле для загрузки файла проверяется на заполненность

		Внимание: префикс "?" или "!" является обязательным в коде шаблона!

		Префикс "?" обозначает необязательность заполнения поля.
		Префикс "!" перед кодом обозначает обязательность заполнения поля.
		Например "!phone" - обязательное поле типа "телефонный номер".
		Постфикс ":xx:yy" позволяет указать минимальную и максимальную длину значения.
		Например "!int:10" - обязательное числовое поле длиной не менее 10 символов (ИНН).
         	"!text:10:300" - обязательное числовое поле длиной не менее 10 и не более 300 символов (сообщение).
		Префикс "=" перед кодом обозначает, что поле должно иметь значение, равное указанному полю после знака "=".
		Например "!=pwd2" - обязательное поле, которое должно иметь такое же значение, как и поле pwd2.
		Если префикс отсутствует и указан только код шаблона,
		то поле проверяется на соответствие формату только если оно не пустое.

		3.Вызов валидатора подключается на кнопку отправки формы (<input type="submit" />) :

		<input type="submit" value="Отправить" onclick="return validateForm(this.form, 'Проверьте правильность заполнения следующих полей:');" />

		или к форме (для формы, использующей метод get, в том числе, поиска):

		<form id="search" method="get" action="/search/" onsubmit="return validateForm(this.form, 'Введите поисковый запрос');">

		4.Для подключения скрипта к странице в <head> следует добавить строку:

		<script type="text/javascript" src="/js/ValidForm.js"></script>

		5.Предупреждающий текст может быть задан как переменная в строке подключения к форме или в <head> страницы:

		<script type="text/javascript">default_err_msg = 'Проверьте правильность заполнения следующих полей:';</script>

		--------------------------------------------
		По всем вопросам работы этого скрипта
		можно обращаться в компанию ООО Алтер-Вест
		тел: +7 495 234-3472
		admin(dog)uw.ru
		http://www.uw.ru
		Пользуйтесь на здоровье!
		--------------------------------------------
*/
//--------------------------------------------------------------------------
	var err_msg = "";
	var err_obj = null;

	String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

	//Убирает выделение ошибки перед повторной проверкой
	function clearClass(obj) 
	{
		var cn = obj.className;
		if (cn != '')
		{
			if (cn != 'error')
			{
				var tail = cn.search(' error');
				if (tail != -1)
				{
					obj.className = cn.slice(0, tail);
		  		}
	  		}
	  		else
	  		{
	 	  		obj.className = '';
	  		}
  		}
	}
	
	function setClass(obj) 
	{
		if (obj.className != '')
		{
			obj.className = obj.className + ' error';
  		}
  		else 
  		{
			obj.className = 'error';
  		}
	}
	
	function commitError(obj, msg)
	{
		err_obj = err_obj == null ? obj : err_obj;
		err_msg += '\n  '+msg;
	}

	function validateForm(f, err_text) 
	{
		// initialization
		err_msg=err_text;
		if (err_msg==null) err_msg = default_err_msg;
		err_obj = null;
		// actually validating
		var label = f.getElementsByTagName('label');
		for (var i=0; i<label.length; i++) 
		{
		
			if (!label[i].htmlFor) continue;
			// parsing rule
			var obj = f.elements[label[i].htmlFor];
			if (!obj) continue;
			var rule = label[i].id;
			var required = false;
			var prefix = rule.substr(0, 1);
			if (prefix == '!') required = true
			else if (prefix != '?') continue;
			rule = rule.substr(1, rule.length-1);
			var p = rule.split(':');
			rule = p[0];
			var minlength = (isNaN(parseInt(p[1]))) ? 0 : parseInt(p[1]);
			var maxlength = (isNaN(parseInt(p[2]))) ? 0 : parseInt(p[2]);

			// checking rule
			if (rule.substr(0, 1) == '=') 
			{
				clearClass(obj);
				var other_hand = rule = rule.substr(1, rule.length-1);
				if (required || (obj.value != '')) 
				{
					var obj2 = f.elements[other_hand];
					if (required && (obj.value == '')) 
					{
						commitError(obj, obj.title);
						setClass(obj);
					}
					else if ((obj2) && (obj.value != obj2.value))
					{
						commitError(obj2, obj2.title);
						setClass(obj2);
					}
				}
			}
			else
				switch (rule) {
					case 'text':
						clearClass(obj);
						var value = obj.value.trim();
						if (obj.value == '') {
							setClass(obj)
						};
					case 'select':
						var value = obj.value.trim();
						if (!required && (obj.value == '')) break;
						if ((value == '') || (value.length < minlength) || ((value.length > maxlength)&(maxlength != ''))) commitError(obj, obj.title);
						break;
					case 'checkbox':
						var item_ok = 0;
						for (var j=0; j<obj.length; j++) {
							if (obj[j].checked) item_ok++;
						}
						if (required && ((item_ok < minlength) || (item_ok == 0))) commitError(obj[0], obj[0].title);
						break;
					case 'radio':
						var selected_item = -1;
						for (var j=0; j<obj.length; j++) {
							if (obj[j].checked) selected_item = j;
						}
						if (required && (selected_item == -1)) commitError(obj[0], obj[0].title);
						break;
					case 'int':
						clearClass(obj);
						var value = parseInt(obj.value);
						if (!required && (obj.value == '')) break;
						if (isNaN(value) || (value != obj.value.trim()) || ((value == 0) && required) || (obj.value.trim().length < minlength)) {
							commitError(obj, obj.title);
							setClass(obj);
						}
						break;
					case 'float':
						clearClass(obj);
						var value = parseFloat(obj.value);
						if (!required && (obj.value == '')) break;
						if (isNaN(value) || (value != obj.value.trim()) || ((value == 0) && required)) {
							commitError(obj, obj.title);
							setClass(obj);
						}
						break;
					case 'email':
						clearClass(obj);
						var value = obj.value.trim();
						if (!required && (obj.value == '')) break;
						if (!/^([a-zA-Z0-9_.+-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,6})+$/.test(value)) {
							commitError(obj, obj.title);
							setClass(obj);
						}
						break;
					case 'phone':
						clearClass(obj);
						var value = obj.value.trim();
						if (!required && (obj.value == '')) break;
						if (!/^(\+?\d{1,3}?)?(\s)*(\(?\d{3}\)?)?(\s)*(\d{3}-?\d{2}-?\d{2})$/.test(value)) {
							commitError(obj, obj.title);
							setClass(obj);
						}
						break;
					case 'alph':
						clearClass(obj);
						var value = obj.value.trim();
						if (!required && (obj.value == '')) break;
						if (!/^([a-zA-Z0-9.-])+$/.test(value)) {
							commitError(obj, obj.title);
							setClass(obj);
						}
						break;
					case 'file':
						clearClass(obj);
						var value = obj.value.trim();
						if (obj.value == '') {
							setClass(obj)
						};
				}
		}

		// checking the results
		if (err_obj != null) {
			alert(err_msg);
			err_obj.focus();
			return false;
		}	else {
			return true;
		}
	}

	function processForm(f) {
		if (validateForm(f)) f.submit();
	}


//--------------------------------------------------------------------------
//	COOKIE(.js)
//--------------------------------------------------------------------------
//	INSTRUCTION
//--------------------------------------------------------------------------
	// Функция установки значения cookie
	// name - имя cookie
	// value - значение cookie
	// liveDay - срок жизни cookie в днях
	// [expires] - дата окончания действия cookie (по умолчанию - до конца сессии)
	// [path] - путь, для которого cookie действительно (по умолчанию - документ, в котором значение было установлено)
	// [domain] - домен, для которого cookie действительно (по умолчанию - домен, в котором значение было установлено)
	// [secure] - логическое значение, показывающее требуется ли защищенная передача значения cookie

	function setCookie(name, value, liveDay, path, domain, secure) {
		var today=new Date();
		var expires=new Date(new Date(today.getTime()+liveDay*24*60*60*1000));
        var curCookie = name + "=" + escape(value) +
                ((expires) ? "; expires=" + expires.toGMTString() : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "")
                document.cookie = curCookie;
	}



	// Функция чтения значения cookie
	// Возвращает установленное значение или пустую строку, если cookie не существует.
	// name - имя считываемого cookie

	function getCookie(name) {
        var prefix = name + "="
        var cookieStartIndex = document.cookie.indexOf(prefix)
        if (cookieStartIndex == -1)
                return null
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length
		return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
	}



	// Функция удаления значения cookie
	// name - имя cookie
	// [path] - путь, для которого cookie действительно
	// [domain] - домен, для которого cookie действительно
	function deleteCookie(name, path, domain) {
        if (getCookie(name)) {
                document.cookie = name + "=" + 
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 10-Feb-82 00:00:01 GMT"
        }
	}

//--------------------------------------------------------------------------
//	ShowImage(.js)
//--------------------------------------------------------------------------
//	INSTRUCTION
//--------------------------------------------------------------------------

	function showImage(img_path, img_alt, img_w, img_h, resizable){
		if(!(resizable)){
			var resizable = 'yes, menubar=yes';
			var img_w = 600;
			var img_h = 600;
		}
		var winn = window.open('', '', 'resizable=' + resizable + ', width=' + img_w + ', height=' + img_h + ', left=50, top=50');

		winn.document.open();
		winn.document.writeln('<html>');
		winn.document.writeln('<head>');
		winn.document.writeln('<title>'+img_alt+'</title>');
		winn.document.writeln('</head>');
		winn.document.writeln('<body style="margin:0; padding:0;">');
		winn.document.writeln('<img src='+ img_path + ' alt="'+img_alt+'" style="cursor: pointer;" onclick="window.close();" />');
		winn.document.writeln('</body>');
		winn.document.writeln('</html>');		
		winn.document.close();
	}

//----------------------------------------------------------windows-1251----
//	Title				Searh Tips
//  Date 				29 July 2008
//  Author	 			Alexey Generalov [webr@dical]
//  Copyright	 		Ulter West
//  Version				0.2
//--------------------------------------------------------------------------
//	INSTRUCTION
//--------------------------------------------------------------------------
//	1. 	Add to HTML:
//		into head section:					
//		<script type="text/javascritp" src="/path/to/searchtips.js" ></script>
//
//		into body section:
//		<div id="search_tips">&nbsp;</div>
//
//	2. 	Edit the "mainText" variable 
//		The script supported several keywords/expressions into `tips` variable:
//		{:query}			- Query from referrer page;
//		{:br}				- Create <br> tag;
//		{param1:param2}		- Create <a> tag with text `param1` and href attribute `param2`;
//		
//		var search_tips = "Вы искали на нашем сайте \"{:query}\"?{:br}Если на этой странице ничего подходящего нет, то можно {поискать:/search/} по сайту, посмотреть на {карте:/sitemap/} или {спросить:/mailsample/} администратора.";
//--------------------------------------------------------------------------
	function getRusChars(num)
	{
		if (num > 0x1F && num < 0x80) return String.fromCharCode(num);
		num = parseInt(num); 

		if (num == 168) return 'Ё';
		if (num == 184) return 'ё';
		if (num == 185) return '№';
		if (num < 192 || num > 256) return;
		
		var cp = new Array(
			'А', 'Б', 'В', 'Г',	'Д', 'Е', 
			'Ж', 'З', 'И', 'Й',	'К', 'Л', 'М',
			'Н', 'О', 'П', 'Р', 'С', 'Т', 'У',
			'Ф', 'Х', 'Ц', 'Ч',	'Ш', 'Щ', 'Ъ',
			'Ы', 'Ь', 'Э', 'Ю',	'Я',
			'а', 'б', 'в', 'г',	'д', 'е', 
			'ж', 'з', 'и', 'й',	'к', 'л', 'м',
			'н', 'о', 'п', 'р', 'с', 'т', 'у',
			'ф', 'х', 'ц', 'ч',	'ш', 'щ', 'ъ',
			'ы', 'ь', 'э', 'ю',	'я'
		);
		return cp[num-192];
	}
	
	function decodeURI(str)
	{
		var char_rxp = /%[A-F0-9][A-F0-9]/i
		var charCodeHex;
		var char;
		while (str.search(char_rxp) != -1)
		{
			charCodeHex = '0x' + String(str.match(char_rxp)).slice(1);
			char = getRusChars(charCodeHex);
			if (char == undefined) throw {source : 'function decodeURI()', message : 'Unsupported encoding', code: 0};
			str = str.replace(char_rxp, getRusChars(charCodeHex));
		}

		str = str.replace(/\+/g, ' ');
		return str;		
	}


	function getSearchQuery(uri)
	{
		var str = (uri == undefined) ? document.referrer : uri;

		var google = /(?:&|\?)q=([a-zA-Z%+~\-*_\.0-9]*)/g
		var yandex = /(?:&|\?)text=([a-zA-Z%+~\-*_\.0-9]*)/g
		var rambler = /(?:&|\?)words=([a-zA-Z%~+\-*_\.0-9]*)/g
		var mailru = /(?:&|\?)q=([a-zA-Z%+~\-*_\.0-9]*)/g
		var searchlive = /(?:&|\?)q=([a-zA-Z%+~\-*_\.0-9]*)/g

		if(str.indexOf("google.")!= -1)
		{
				str.match(google);
				str = RegExp.$1;
		}
		else if (str.indexOf("yandex.")!= -1)
		{
				str.match(yandex);
				str = RegExp.$1;
		}
		else if (str.indexOf("rambler.")!= -1)
		{
				str.match(rambler);
				str = RegExp.$1;
		}
		else if (str.indexOf("go.mail.ru")!= -1)
		{
				str.match(mailru);
				str = RegExp.$1;
		}
		else if (str.indexOf("search.live.com")!= -1)
		{
				str.match(searchlive);
				str = RegExp.$1;
		}
		
		else throw {source : 'function getSearchQuery()', message : 'Unsupported search engine'};
		
		try
		{
			str = decodeURI(str);
		}
		catch(e)
		{
			//alert("Error in " + e.source + " because " + e.message);
		}
		finally
		{
			try
			{
				str = decodeURIComponent(str);
			}
			catch(e)
			{
				//alert(e);
				throw {source : 'function getSearchQuery()', message : 'Unsupported encoding', code: 0};
			}
		}
		
		str = str.replace(/\+/g, ' ');
		
		return str;
	}
	
	function A(text, link)
	{
		var a = document.createElement('a');
		var node = document.createTextNode(text);
		a.appendChild(node);
		a.setAttribute('href', link);
		return a;
	}
	
	function searchTips()
	{
		var o = document.getElementById('search_tips');
		if (!o) return;
		
		var searchQuery;
		try
		{
			searchQuery = getSearchQuery();
		}
		catch(e)
		{
			//alert('Выходим из программы, ничего не выводим');
			return false;
		}
		
		var p = document.createElement('p');
		var sentence = /\{[^:]*:[^\}]*}/
		var preceding = /[^\{]*/;
	
		var text = search_tips;
		do
		{
			var preceding_text =  '' + text.match(preceding);
			var node = document.createTextNode(preceding_text);
			p.appendChild(node);
			text = text.replace(preceding, '');
			
			var next_sentence = '' + text.match(sentence);
			text = text.replace(sentence, '');

			next_sentence.match(/([^:{]*)(?::)([^:}]*)/);
						
			if (RegExp.$2 == 'query')
			{
				var  subnode = document.createTextNode(searchQuery);
				node = document.createElement('strong');
				node.appendChild(subnode); 
			}
			else if (RegExp.$2 == 'br')
			{
				var node = document.createElement("br");			
			}
			else 
			{
				node = A(RegExp.$1, RegExp.$2);
			}
			p.appendChild(node);
		}
		while(!!String(text.match(sentence) || text.match(preceding)));
		o.replaceChild(p, o.firstChild);
	}

//--------------------------------------------------------------------------
//	PrintMode(.js)
//	Переключение на версию для печати
//--------------------------------------------------------------------------
//	INSTRUCTION
//--------------------------------------------------------------------------
// PrintModeCheck добавляет '&printmode' или '?printmode' в конец адреса страницы
// переводя сайт в режим для печати
// используется в start.tpl и index.tpl следующим образом
//<a onclick="PrintModeCheck(document.location.href);" onmouseover="this.style.cursor='hand'">printmode</a>
//
	function PrintModeCheck(url){
		var page = url.split('#')[0];
  		if(url.indexOf('?',0) > 0){
    		document.location.href=page+'&printmode';
  		}else{
    		document.location.href=page+'?printmode';
  		}
	}

// PrintModeBack отсекает 10 символов в конце адреса страницы '?printmode' или '&printmode'
// возвращая из режима печати в режим сайта 
// используется в print.tpl следующим образом
//<a onClick="PrintModeBack(document.location.href);" onmouseover="this.style.cursor='hand'">sitemode</a>

	function PrintModeBack(url){
		if(url.indexOf('printmode',0) > 0){
    		document.location.href=url.substring(0, url.length - 10);
  		}else{
    		document.location.href=url;
  		}
	}

	
//--------------------------------------------------------------------------
//	addmesage(.js)
//	добавление сообщений на доску объявлений и в форум
//--------------------------------------------------------------------------
//	INSTRUCTION
//--------------------------------------------------------------------------
	var message;
	var forummessage;

	function addBoardMessage(sectionID){
	    message=window.open('/utf8/addboardmessage?sectionID='+sectionID,'message','resizable=yes,scrollbars=no,width=570,height=350');
   	 message.focus();
	}

	function addForumMessage(sectionID,parentID,lang){
    	forummessage=window.open('/utf8/addforummessage?sectionID='+sectionID+'&parentID='+parentID+'&parentLang='+lang,'forummessage','resizable=yes,scrollbars=no,width=570,height=360');
    	forummessage.focus();
	}

	function addForumMessage(sectionID,parentID){
	    forummessage=window.open('/utf8/addforummessage?sectionID='+sectionID+'&parentID='+parentID+'&parentLang=ru','forummessage','resizable=yes,scrollbars=no,width=570,height=360');
   		forummessage.focus();
	}

	function closeWindow(){
    	opener.message.close();
	}

//--------------------------------------------------------------------------
//	Загрузчик скриптов
//--------------------------------------------------------------------------

	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		}else{
			window.onload = function() {
				if (oldonload){
				oldonload();
				}
      			func();
    		}
  		}
	}

	addLoadEvent(function() {
		searchTips();
		var gallery = new BlockGallery();
	});
		
