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_vote_result = function() {
		return xajax.request( { xjxfun: 'vote_result' }, { parameters: arguments } );
	}
	
	xajax_openStuffDescr = function() {
		return xajax.request( { xjxfun: 'openStuffDescr' }, { parameters: arguments } );
	}
	
	xajax_addCart = function() {
		return xajax.request( { xjxfun: 'addCart' }, { parameters: arguments } );
	}
	
	addCart = function(id, v_id) {
		if (v_id){
			amount = $('#vamount'+v_id).attr('value');
		} else {
			amount = $('#amount'+id).attr('value');
		}
		xajax_addCart(id, v_id, amount);
		return false;
	}
	
/* 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 checkForm2(frm) {
	// Заранее объявим необходимые переменные
	var el, // Сам элемент
	elName, // Имя элемента формы
	value, // Значение
	type; // Атрибут type для input-ов
	// Массив списка ошибок, по дефолту пустой
	var errorList = [];
	// Хэш с текстом ошибок (ключ - ID ошибки)
	var errorText = {
	1 : "Не заполнено поле 'Имя'",
	2 : "Не заполнено поле 'E-mail'",
	3 : "Не заполнено поле 'Телефон'",
	4 : "Неизвестная ошибка"
	}
	form = document.getElementById(frm);
	// Получаем семейство всех элементов формы
	// Проходимся по ним в цикле
	//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 switc(obj){
	if(document.getElementById){
 		var el = document.getElementById(obj);
		if(el.style.display != "block"){
			el.style.display = "block";
  		} else {
	    	el.style.display = "none";
  		}
 	}
}

function changeCount(el, num) {
	var cvalue = $('#'+el).attr('value');
	if (cvalue > 1 || num > 0) {
		$('#'+el).attr('value', parseInt(cvalue)+num);	
	}
}

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;
	//alert(width+'_'+height);
	$("#"+el).css('top', topPad);
	$("#"+el).css('left', leftPad);	
}

function popUp() {
	setPosition('pop_up');
	//$("div.main").fadeTo("slow", 0.33);
	//$("#pop_up").fadeIn('slow');
	$.dimScreen(500, 0.7, function() {$('#pop_up').fadeIn('fast')});
}

var closePopupTimer;
var mdelay = 3000;

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

function closePopUp() {
	clearTimeout(closePopupTimer);
	//$("div.main").fadeTo("normal", 1);
	$('#pop_up').css('display', 'none');
	//$('#pop_up').Puff(500);
    //$('#pop_up').remove();
	$.dimScreenStop();
	return false;
}

function onDimResize() {
	setPosition('pop_up');
	jQuery('#__dimScreen').css({
            height: $(document).height() + 'px' //$(document).height()
            ,width: $(document).width() + 'px' //$(document).width()
    });
}

var cur_img = 0;

function changeImg(path, src, el) {
	if (cur_img) {
		$('#gal'+cur_img).attr('src', '/img/0.gif');
	}
	$('#gal'+el).attr('src', '/img/kat_bord.gif');
	$('#'+path).attr('src', src);
	cur_img = el;
}

function confirmOrder() {
	if (checkForm2('frmOrder')) {
		document.frmOrder.submit();
	}	
	return false;
}

var cur_b = 0;
var cur_n = 1;

function changeAdv(src, id, n, el, link, el2) {
	if (id != cur_b) {
		$('#'+el).attr("src", src);
		$('#'+el2).attr("href", link);
		//alert($('#'+el2).attr("href"));
		if (cur_b) {
			$('#blink'+cur_b).attr("src", "/img/ban_ic"+cur_n+"_off.png");
		}	
		$('#blink'+id).attr("src", "/img/ban_ic"+n+"_on.png");
		cur_b = id;
		cur_n = n;
	}
	return false;
}

function changeAdv2(src, id, n, el) {
	if (id != cur_b) {
		$('#'+el).css("background", "url('"+src+"')");
		alert($('#'+el).css("background"));
		if (cur_b) {
			$('#blink'+cur_b).css("background", "url('/img/ban_ic"+cur_n+"_off.png')");
		}	
		$('#blink'+id).css("background", "url('/img/ban_ic"+n+"_on.png')");
		alert($('#blink'+id).css("background"));
		cur_b = id;
		cur_n = n;
	}
	return false;
}

function openCatMenu() {
	var agt=navigator.userAgent.toLowerCase();
	var disp = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)) ? 'block' : 'table';
	$('#catmenu').css('display', disp);
}