function newWin(nameImg,width,height){
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
 	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	win=open("","",'height='+height+',width='+width+',top='+TopPosition+',left='+LeftPosition);
	win.document.write('<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0><table cellpadding=0 cellspacing=0 border=0><tr><td><img src="'+nameImg+'" style="cursor:hand;" onclick="window.close();" alt=""></td></tr></table></body></html>');
  	win.document.close();
}

function newWinHtml(urlHtml,width,height){
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
 	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	win=open(urlHtml,"",'height='+height+',width='+width+',top='+TopPosition+',left='+LeftPosition);
}

function open_window(link,w,h) {
 LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
 TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
 var win = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',menubar=no,location=no,scrollbars=yes,resizable=yes';
 newWin = window.open(link,'newWin'+w+h,win);
}

function procSubscribe(frm, proc, w, h) {
	ofrm = document.getElementById(frm);
	window.open('', frm, 'width='+w+',height='+h);
	eval("ofrm.subscribe_type.value="+proc);
	ofrm.submit();
}

function procFocus(ob, txt) {
	if (ob.value == txt) {
		ob.value = '';
	}	
}

function procBlur(ob, txt) {
	if (ob.value == '') {
		ob.value = txt;
	}	
}

document.onkeydown = register;

function register(e) {
	if (!e) e = window.event;
	var k = e.keyCode;
	if (e.ctrlKey) {
		var tagName = (e.target || e.srcElement).tagName;
		if (tagName != 'INPUT' && tagName != 'TEXTAREA') {
			var d;
			if (k == 37) {
				d = $('#previous_page');
			}
			if (k == 39) {
				d = $('#next_page');
			}
			if (d) location.href = d.attr('href');
		}
	}
}

/* xajax */	
	
	try { if (undefined == xajax.config) xajax.config = {}; } catch (e) { xajax = {}; xajax.config = {}; };
	xajax.config.requestURI = "/procajax.php";
	xajax.config.statusMessages = false;
	xajax.config.waitCursor = true;
	xajax.config.version = "xajax 0.5 rc1";
	xajax.config.legacy = false;
	xajax.config.defaultMode = "asynchronous";
	xajax.config.defaultMethod = "POST";
	
	xajax_vote = function() {
		return xajax.request( { xjxfun: 'vote' }, { parameters: arguments } );
	}

	xajax_voteResult = function() {
		return xajax.request( { xjxfun: 'voteResult' }, { parameters: arguments } );
	}
	
	xajax_showDot = function() {
		return xajax.request( { xjxfun: 'showDot' }, { parameters: arguments } );
	}
	
/* end xajax */

function checkForm(form) {
	// Заранее объявим необходимые переменные
	var el, // Сам элемент
	elName, // Имя элемента формы
	value, // Значение
	type; // Атрибут type для input-ов
	// Массив списка ошибок, по дефолту пустой
	var errorList = [];
	// Хэш с текстом ошибок (ключ - ID ошибки)
	var errorText = {
	1 : "Не заполнено поле 'Имя'",
	2 : "Не заполнено поле 'E-mail'",
	3 : "Не заполнено поле 'Телефон'",
	4 : "Неизвестная ошибка"
	}
	// Получаем семейство всех элементов формы
	// Проходимся по ним в цикле
	//form = document.getElementById(frm);
	for (var i = 0; i < form.elements.length; i++) {
	el = form.elements[i];
	elName = el.nodeName.toLowerCase();
	value = el.value;
	if (elName == "input") { // INPUT
	// Определяем тип input-а
	type = el.type.toLowerCase();
	// Разбираем все инпуты по типам и обрабатываем содержимое
	switch (type) {
	case "text" :
	if (el.title != "" && value == "") errorList.push("Не заполнено поле '"+el.title+"'");
	break;
	case "file" :
	//if (value == "") errorList.push(3);
	break;
	case "checkbox" :
	// Ничего не делаем, хотя можем
	break;
	case "radio" :
	// Ничего не делаем, хотя можем
	break;
	default :
	// Сюда попадают input-ы, которые не требуют обработки
	// type = hidden, submit, button, image
	break;
	}
	} else if (el.title != "" && elName == "textarea") { // TEXTAREA
	if (value == "") errorList.push("Не заполнено поле '"+el.title+"'");
	} else if (el.title != "" && elName == "select") { // SELECT
	if (value == 0) errorList.push("Не выбран элемент в поле '"+el.title+"'");
	} else {
	// Обнаружен неизвестный элемент ;)
	}
	}
	// Финальная стадия
	// Если массив ошибок пуст - возвращаем true
	if (!errorList.length) {
		return true;
	}
	// Если есть ошибки - формируем сообщение, выовдим alert
	// и возвращаем false
	var errorMsg = "При заполнении формы допущены следующие ошибки:\n\n";
	for (i = 0; i < errorList.length; i++) {
	errorMsg += errorList[i] + "\n";
	}
	alert(errorMsg);
	return false;
}

function setPosition(el) {
	if (self.innerHeight) {
		x = self.innerWidth;
		y = self.innerHeight;
		// IE 6 Strict Mode
	} else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
		// Остальные версии IE
	} else if (document.body) {
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	var top = document.body.scrollTop;
	var left = document.body.scrollLeft;

	var width = $("#"+el).width();
	var height = $("#"+el).height();
	

	var halfX = x /2;
	var halfWidth = width / 2;
	var leftPad = (left + halfX) - halfWidth;

	var halfY = y /2;
	var halfHeight = height / 2;
	var topPad = (top + halfY) - halfHeight;
	
	$("#"+el).css('top', topPad);
	$("#"+el).css('left', leftPad);
}

function popUp(x, y) {
	var height = $("#drope_info").height();
	var offx = 10;
	var offy = -10;
	var mappos = $('#big_map').offset();
	$("#drope_info").css('top', 330 + y - height + offy);
	$("#drope_info").css('left', mappos.left + x + offx);
	$('#drope_info').fadeIn('fast')
}

function popUp2() {
	setPosition('drope_info');
	$.dimScreen(500, 0.7, function() {$('#drope_info').fadeIn('fast')});
}

var closePopupTimer;
var mdelay = 2400;

function closePopUpTime() {
	closePopupTimer = setTimeout('closePopUp()', mdelay);
}

function closePopUp() {
	clearTimeout(closePopupTimer);
	$('#drope_info').css('display', 'none');
	if (document.getElementById('__dimScreen')) {
		$.dimScreenStop();
	}
	return false;
}

$(window).resize(function(){
	if (document.getElementById('__dimScreen')) {
		$('#__dimScreen').css({
            height: $(document).height() + 'px'
            ,width: $(document).width() + 'px'
    	});
		setPosition('drope_info');
	}
	//$('#scrollbox').css('width', $(document).width() - 300);
});


var delay = 1000;
var sup = 5;

$(document).ready(function(){
	$(".actions_block .items div").click(function(){
	$(this).removeClass("item");
	$(".actions_block .select").addClass("item");
	$(".actions_block .select").removeClass("select");
	$(this).addClass("select");

	$(".action_item").css("display", "none")
	var value = $(this).attr("rel");
	var fin = "#a_" + value;

	$(fin).css("display", "block")
	});
	
	// SCROLLBOX
	$("#scrollLeft").mouseover(function(e){
		//cWidth = $("#scrollbox").width() + 80;
        cWidth = $("#tscrollbox").width() + 80;
		cLeft = $("#scrollbox").scrollLeft();
		$("#scrollbox").animate({ scrollLeft: 0 }, (cLeft)*sup);
	});	
	$("#scrollLeft").mouseout(function(){
		$("#scrollbox").stop();
	});
	$("#scrollRight").mouseover(function(e){
		//cWidth = $("#scrollbox").width() + 80;
        cWidth = $("#tscrollbox").width() + 80;
		cLeft = $("#scrollbox").scrollLeft();
		$("#scrollbox").animate({ scrollLeft: cWidth }, (cWidth-cLeft)*sup);
	});	
	$("#scrollRight").mouseout(function(){
		$("#scrollbox").stop();
	});
	//$('#scrollbox').css('width', $(document).width() - 300);
});

var cur_dot = 0;

function showDot(id, type) {
	if(cur_dot) {
		$('#dlink'+cur_dot).toggleClass('active');	
		closePopUp();
	}
	if (cur_dot != id && id != 0) {
		$('#dlink'+id).toggleClass('active');
		cur_dot = id;
		xajax_showDot(id, type);
	} else {
		cur_dot = 0;
	}
	return false;
}


