function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
 
function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}


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');
		}
	}
}


function popUp() {
	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 = $("#pop_up").width();
	var height = $("#pop_up").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;

	$("#pop_up").css('top', topPad);
	$("#pop_up").css('left', leftPad);

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

var closePopupTimer;
var mdelay = 3000;

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

function closePopUp() {
	clearTimeout(closePopupTimer);
	$('#pop_up').css('display', 'none');
	$.dimScreenStop();
	return false;
}

/* 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_addCart = function() {
		return xajax.request( { xjxfun: 'addCart' }, { parameters: arguments } );
	}
    
/* end xajax */

var lastBanId = 1;

var banTimer;
var bandelay = 7000;

function timedShowBan() {
	banTimer = setTimeout('autoShowBan()', bandelay);
}

$(document).ready(function(){
	timedShowBan();
});

function autoShowBan() {
	var num = lastBanId == 3 ? 1 : lastBanId+1;
	showBan(num);
	timedShowBan();
}

function onOverBan() {
	clearTimeout(banTimer);
}

function onOutBan() {
	timedShowBan();
}

function showBan(num) {
    if (lastBanId && lastBanId != num) {
        if (lastBanId) {
            $('#dban'+lastBanId).toggleClass('special_number_off');
            $('#dban'+lastBanId).toggleClass('special_number_on');
            $('#aban'+lastBanId).toggleClass('special_ss_on');
            $('#aban'+lastBanId).toggleClass('special_ss_off');
            //$('#bban'+lastBanId).css('display', 'none');
        }
        $('#dban'+num).toggleClass('special_number_off');
        $('#dban'+num).toggleClass('special_number_on');
        $('#aban'+num).toggleClass('special_ss_on');
        $('#aban'+num).toggleClass('special_ss_off');
        //$('#bban'+it).css('display', 'block');
		stepcarousel.stepTo('mygallery', num)
        lastBanId = num;
    }
	return false;
}

function checkForm(frmId) {
	// Заранее объявим необходимые переменные
	var el, // Сам элемент
	elName, // Имя элемента формы
	value, // Значение
	type; // Атрибут type для input-ов
	// Массив списка ошибок, по дефолту пустой
	var errorList = [];
	
	// Получаем семейство всех элементов формы
	// Проходимся по ним в цикле
	//form = document.getElementById(frm);
	form = document.getElementById(frmId);
	//alert(form.elements.length);
	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) {
		form.submit();
		return false;
	}
	// Если есть ошибки - формируем сообщение, выовдим alert
	// и возвращаем false
	var errorMsg = "При заполнении формы допущены следующие ошибки:\n\n";
	for (i = 0; i < errorList.length; i++) {
	errorMsg += errorList[i] + "\n";
	}
	alert(errorMsg);
	return false;
}
