cmnAdd_event( window, "load", AddListen );
cmnAdd_event( window, "load", PreloadImages );
cmnAdd_event( window, "load", ProcessPNG );
cmnAdd_event( window, "load", ShowCart );
searchstring = 'поиск по сайту';
var pass1, pass2;
var GalleryArray;
var KIT_timeout = new Array();//таймауты наездов на меню
function $(id)
	{
	return document.getElementById(id);
	}
function PreloadImages()
	{
	var image = new Array(
		'controls.png',
		's00.png',
		's01.png',
		's10.png',
		's11.png',
		'st.png',
		'sb.png',
		'sr.png',
		'sl.png'
		);
	var oImage = new Array();
	for(var i in image)
		{
		oImage[i] = new Image();
		oImage[i].src = '/images/'+image[i];
		}
	}

function AddListen()
	{
	//cmnAdd_event(window, 'scroll', OnScroll);

	GalleryArray = new Array();
	for (var i = 0; (oInput = document.getElementsByTagName('*')[i]); i++)
		{
		//kit
		if(cmnMatch_class(oInput, 'opensubs'))
			{
			cmnAdd_event(oInput, 'mousemove', ShowSubmenu);
			cmnAdd_event(oInput, 'mouseout', HideSubmenu);
			}
		/*if(cmnMatch_class(oInput, 'catalog_menu'))
			{
			cmnAdd_event(oInput, 'mousemove', HoverSubmenu);
			cmnAdd_event(oInput, 'mouseout', UnhoverSubmenu);
			}*/
		if(oInput.tagName == 'UL' && cmnMatch_class(oInput, 'submenu'))
			{
			if(cmnMatch_class(oInput, 'close'))
				oInput.style.display='none';
			else
				oInput.style.display='block';
			}
		//автоматическое раскрытие больших фоток
		if ( oInput.tagName == 'IMG' && ( cmnMatch_class(oInput, 'popup_image') || oInput.src.indexOf("popup_image")!=-1 ) )
			{
			cmnAdd_event(oInput, 'click', LoadImg);
			oInput.style.cursor = "pointer";
			im = new Image();
			im.src = getLargeImage(oInput.src);
			GalleryArray[GalleryArray.length] = im;
			}
		
		//скрыть попап, если кликнули вне его
		cmnAdd_event(oInput, 'click', TryToCloseEnlarged);
		
		//скрыть попап по клику на крест
		if(cmnMatch_class(oInput, 'div_close') || cmnMatch_class(oInput, 'div_close-hover'))
			{
			cmnAdd_event(oInput, 'click', CloseGallery);
			}
		
		//показать следующую картинку-попап
		if(cmnMatch_class(oInput, 'div_next') || cmnMatch_class(oInput, 'div_next-hover'))
			{
			cmnAdd_event(oInput, 'click', NextGallery);
			}
		
		//показать предыдущую картинку-попап
		if(cmnMatch_class(oInput, 'div_prev') || cmnMatch_class(oInput, 'div_prev-hover'))
			{
			cmnAdd_event(oInput, 'click', PrevGallery);
			}
		
		//автоматическая проверка заполненности формы
		if(cmnMatch_class(oInput, 'password_1'))
			{
			pass1 = oInput;
			cmnAdd_event(oInput, 'keyup', CheckStrict);
			cmnAdd_event(oInput, 'change', CheckStrict);
			}
		if(cmnMatch_class(oInput, 'password_2'))
			{
			pass2 = oInput;
			cmnAdd_event(oInput, 'keyup', CheckStrict);
			cmnAdd_event(oInput, 'change', CheckStrict);
			}
		if(oInput.tagName=='FORM' && cmnMatch_class(oInput, 'strictform'))
			{
			cmnAdd_event(oInput, 'submit', CheckStrictForm);
			}
		if (cmnMatch_class(oInput, 'strict'))
			{
			//check_(oInput);
			cmnAdd_event(oInput, 'keyup', CheckStrict);
			cmnAdd_event(oInput, 'change', CheckStrict);
			}
		
		//zo - форма подписки
		if(cmnMatch_class(oInput, 'subscribe'))
			{
			cmnAdd_event(oInput, 'keypress', ZO_ProcessSubscribe);
			}
		
		}
	
	//строка поиска - добавляем серым цветом "поиск по сайту", а когда Фокусируемся, убираем.
	if(oInput = document.getElementById('searchstring'))
		{
		if(!oInput.value || oInput.value == searchstring)
			{
			oInput.value = searchstring;
			oInput.style.color = 'gray';
			}
		cmnAdd_event(oInput, 'focus', SearchFocus);
		cmnAdd_event(oInput, 'blur', SearchBlur);
		}
	}
var hr = new Array();
function ProcessLink(event)
	{
	el = getElement(event);
	while( el.tagName != 'A' )
		{
		el = el.parentNode;
		}
	Prevent(event);
	hr = xajax_xLoadPage(el.href);
	pageScroll(0, document.getElementsByTagName('body')[0].scrollTop, 20);
	}
function FillPage()
	{
	ControlFlash('/images/vesta-flash2');
	document.getElementsByTagName('h1')[0].innerHTML = hr['h1_title'];
	$('div_content').innerHTML = hr['content'];
	if(hr['childmenu'])
		{
		$('div_childmenu').style.display='block';
		$('div_childmenu').innerHTML = hr['childmenu'];
		}
	else
		$('div_childmenu').style.display='none';
		
	$('div_mainmenu').innerHTML = hr['mainmenu'];
	document.title = hr['page_title'];
	
	divs = new Array('span_mainpage', 'div_logo');
	for(i=0;i<divs.length;i++)
		{
	linkmain = $(divs[i]);
	a = linkmain.getElementsByTagName('a')[0];
	if( a && (hr['action'] == 'index') )
		{
		linkmain.innerHTML = a.innerHTML;
		}
	else if( !a && (hr['action'] != 'index') )
		{
		linkmain.innerHTML = '<a href="/" class="ajax">'+linkmain.innerHTML+'</a>';
		}
		}
	AddListen();
	}

function CheckStrictForm(event)
	{
	oForm = getElement(event);
	Prevent(event);
	SubmitStrictForm(oForm);
	return false;
	}
function SubmitStrictForm(oForm)
	{
	for(var i=0; oElement = oForm.elements[i]; i++)
		{
		if( cmnMatch_class(oElement, 'strict') )
			{
			if( (state = check_(oElement)) !== true)
				{
				alert(state+' '+oElement.title);
				oElement.focus();
				return false;
				}
			}
		}
	if(pass1 && pass2)
		{
		if( (state = check_passwords()) !== true)
			{
			alert(state);
			pass1.focus();
			return false;
			}
		}
	oForm.submit();
	return false;
	}
function CheckStrict(event)
	{
	oInput = getElement(event);
	if(oInput == pass1 || oInput == pass2)
		{
		return check_passwords();
		}
	return check_(oInput);
	}
function check_passwords()
	{
		if(pass1.value==pass2.value)
			{
			pass1.style.background = '#F4FFF2';
			pass2.style.background = '#F4FFF2';
			return true;
			}
		else if(pass1.value && !pass2.value)
			{
			pass1.style.background = '#FFFBF2';
			pass2.style.background = '#FFF2F2';
			return "Введите новый пароль (повторно)";
			}
		else if(pass2.value && !pass1.value)
			{
			pass2.style.background = '#FFFBF2';
			pass1.style.background = '#FFF2F2';
			return "Введите новый пароль";
			}
		else if(pass2.value != pass1.value)
			{
			pass2.style.background = '#FFFBF2';
			pass1.style.background = '#FFFBF2';
			return "Введите совпадающие пароли";
			}
	}
function check_(oInput)
	{
	if( oInput.value=='' )
		{
		cmnSet_class(oInput, 'incorrect', 'partlyincorrect');
		cmnSet_class(oInput, 'incorrect', '');
		return "Введите";
		}
	else if( cmnMatch_class(oInput, 'email') && !CorrectEmailAddress(oInput.value) )
		{
		cmnSet_class(oInput, 'partlyincorrect', 'incorrect');
		cmnSet_class(oInput, 'partlyincorrect', '');
		return "Введите правильный";
		}
	else
		{
		cmnSet_class(oInput, '', 'incorrect');
		cmnSet_class(oInput, '', 'partlyincorrect');
		return true;
		}
	}
function SearchFocus(event)
	{
	el = getElement(event);
	if(el.value==searchstring)
		{
		el.value = '';
		el.style.color = 'black';
		}
	}
function SearchBlur(event)
	{
	el = getElement(event);
	if(!el.value)
		{
		el.value = searchstring;
		el.style.color = 'gray';
		}
	}
function ProcessPNG()//обработка картинок PNG 
	{
	
	for (var i = 0; (oImg = document.getElementsByTagName('img')[i]); i++)
		{
		if(oImg.src.substring(oImg.src.length-3, oImg.src.length) == 'png' && navigator.appName.indexOf('icrosoft') != -1)
			{
			w = oImg.scrollWidth;
			h = oImg.scrollHeight;
			oImg.style.height = h;
			oImg.style.width = w;
			oImg.runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+oImg.src+'", sizingMethod="scale")';
			oImg.src = "/images/spacer.gif";
			}
		}
	}

Img = new Image();
function getLargeImage(oUrl)
	{
	var what=oUrl.split("/");
	var wh="";
	for(i=0;i<what.length-1;i++)
		wh+=what[i]+'/';
	wh+='__large/'+what[i];
	return wh;
	}
function LoadImg(event)
	{
	el = getElement(event);
	
	oUrl=el.src;
	wh = getLargeImage(oUrl);
		
	if( !document.getElementById('div_shadow') )
		{
		extrahtml = xajax_xLoadShadow();
		document.body.innerHTML = document.body.innerHTML + extrahtml;
		AddListen();
		}
	for(i = 0; i < GalleryArray.length; i++ )
		{
		if(GalleryArray[i].src == wh)
			{
			Img = GalleryArray[i];
			setTimeout('_fill()',200);
			return;
			}
		}
	}
function _fill()
	{
		if(!isImageOk(Img))
			{
			setTimeout('_fill()',10);
			return;
			}
		shadow = document.getElementById('div_shadow');
		container = document.getElementById('div_enlarged');
		ofade = document.getElementById('fade');
		
		container.innerHTML = '';
		container.appendChild(Img);
		setTimeout('shadow.style.display = "block";'+
			'y = document.body.scrollTop + (document.body.clientHeight - Img.scrollHeight > 0 ? (document.body.clientHeight - Img.scrollHeight)/2 : 0);'+
			'x = document.body.scrollLeft + (document.body.clientWidth - Img.scrollWidth > 0 ? (document.body.clientWidth - Img.scrollWidth)/2 : 0);'+
			'shadow.style.top = y;'+
			'shadow.style.left = x;'+
			'shadow.style.visibility="visible";'+
			'ofade.style.width = document.body.scrollWidth;'+
			'ofade.style.height = document.body.scrollHeight;'+
			'ofade.style.display = "block";', 20);
	}
function OnScroll(event)
	{
	if(shadow = document.getElementById('div_shadow'))
		{
		y = document.body.scrollTop + (document.body.clientHeight - Img.scrollHeight > 0 ? (document.body.clientHeight - Img.scrollHeight)/2 : 0);
		shadow.style.top = y;
		}
	}
function isImageOk(img) {
    // During the onload event, IE correctly identifies any images
    // that weren't downloaded as not complete. Others should too.
    // Gecko-based browsers act like NS4 in that they report this
    // incorrectly: they always return true.
    if (!img.complete) {
        return false;
    }

    // However, they do have two very useful properties: naturalWidth
    // and naturalHeight. These give the true size of the image. If
    // it failed to load, either of these should be zero.
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }

    // No other way of checking: assume it's ok.
    return true;
}
function NextGallery(event)
	{
	Prevent(event);
	for(i = 0; i < GalleryArray.length; i++ )
		{
		if(GalleryArray[i] == Img)
			{
			if( i == GalleryArray.length - 1 )
				{
				i = -1;
				}
			Img = GalleryArray[i + 1];
			setTimeout('_fill()',10);
			return;
			}
		}
	}
function PrevGallery(event)
	{
	Prevent(event);
	for(i = 0; i < GalleryArray.length; i++ )
		{
		if(GalleryArray[i] == Img)
			{
			if( i == 0 )
				{
				i = GalleryArray.length;
				}
			Img = GalleryArray[i - 1];
			setTimeout('_fill()',10);
			return;
			}
		}
	}
function CloseGallery(event)
	{
	Prevent(event);
	if(shadow = document.getElementById('div_shadow'))
		{
		shadow.style.visibility = 'hidden';
		shadow.style.display = 'none';
		document.getElementById('fade').style.display = 'none';
		}
	}
function TryToCloseEnlarged(event)
	{
	if(shadow = document.getElementById('div_shadow'))
		{
		el = getElement(event);
		while(el = el.parentNode)
			{
			if( el.id == 'div_shadow' )
				return;
			}
		if(shadow.style.display != 'none')
			{
			shadow.style.visibility = 'hidden';
			shadow.style.display = 'none';
			document.getElementById('fade').style.display = 'none';
			if($('print_popup'))
				{
				$('print_popup').innerHTML = '';
				$('print_popup').style.display = 'none';
				}
			}
		}
	}
function run_movie(arg, w, h) 
	{ 
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="'+w+'" HEIGHT="'+h+'" id="'+arg+'" ALIGN=""><PARAM NAME=movie VALUE="'+arg+'.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=wmode VALUE=transparent> <EMBED src="'+arg+'.swf"  quality=high wmode=transparent  WIDTH="'+w+'" HEIGHT="'+h+'" NAME="'+arg+'" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>'); 
	}

function AddToCart( id )
	{
	el = document.getElementById('i_'+id);
	el.className = 'ordered';
	el.innerHTML = document.getElementById('t_ordered').innerHTML;
	setTimeout("xajax_xAddToCart( "+id+", 1 );ShowCart();", 10);
	setTimeout("el = document.getElementById('i_'+"+id+");el.className = '';el.innerHTML = document.getElementById('t_order').innerHTML;",500);
	}
function ShowCart()
	{
	if(typeof(xajax_xShowCart) == 'function')
		document.getElementById('div_show_cart').innerHTML = xajax_xShowCart();
	}
function validateKolvo(sQty)
	{
	var iQty = parseInt(sQty);
	return fnIsNaN(iQty) ? 0 : ( Math.max(0, iQty) );
	}
function fnIsNaN(iStr)
	{
	return (isNaN(iStr) || iStr == Number.NaN || iStr=='NaN');
	}
function RecountCart(event)
	{
	el = getElement(event);
	oForm = el.form;
	len = oForm.elements.length;
	var total = 0;
	var Cart = new Array();
	for(i = 0; i < len; i++)
		{
		oInput = oForm.elements[i];
		if(/*oInput.type=='text' && */cmnMatch_class(oInput, 'recount'))
			{
			kolvo = validateKolvo(oInput.value);
			//price = parseInt( document.getElementById( oInput.id.replace(/kolvo_/, 'price_') ).innerHTML );
			//total += kolvo * price;
			//document.getElementById( oInput.id.replace(/kolvo_/, 'cost_') ).innerHTML = kolvo * price;
			Cart[oInput.id.replace(/kolvo_/, '')] = kolvo;
			}
		}
	//document.getElementById( 'total_sum' ).innerHTML = total;
	xajax_xUpdateCart(Cart);
	//ShowCart();
	}
function CorrectEmailAddress(email)
	{
	if(email.length > 0 && ( email.indexOf("@",0) == -1 || email.indexOf(".",0) == -1 ) )
		return false;
	return true;
	}
function getElement(event)
	{
	// Internet Explorer
	if (event.srcElement)
		{
		el = event.srcElement;
		}
	// Netscape and Firefox
	else if (event.target)
		{
		el = event.target;
		}
	return el;
	}
function Prevent(event)
	{
	if (event.cancelable)
		{
		event.preventDefault();
		}
	else
		{
		event.returnValue=false;
		}
	}
function pageScroll(steps, distance, time)
	{
	if(steps < time)
		{
		v0 = 2*distance/time;
		a = v0/time;
		v = Math.ceil(v0-a*steps);
		window.scrollBy(0,-v);
		scrolldelay = setTimeout('pageScroll('+(steps*1 + 1)+', '+distance+', '+time+')',20);
		}
	else
		FillPage();
	}
function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName]
  }	else {
    return document[movieName]
  }
}
function ControlFlash(id)
	{
	mov = thisMovie(id);
	tfrms = mov.TGetProperty( "_level0/", 5);
	frm = (mov.TCurrentFrame("_level0/") + 1);
	frm = frm >= tfrms ? 1 : frm;
	mov.GotoFrame( frm );
	}
function CreateCalendar(element, trigger)
	{
	Zapatec.Calendar.setup({
	firstDay          : 1,
	weekNumbers       : false,
	showOthers        : true,
	electric          : false,
	inputField        : element,
	button            : trigger,
	ifFormat          : "%d.%m.%Y",
	daFormat          : "%Y/%m/%d"
	});
	}

function getBounds(element)
{
  var left = element.offsetLeft;
  var top = element.offsetTop;
  for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
  {
    left += parent.offsetLeft;
    top += parent.offsetTop;
  }
  return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
}

function ShowSubmenu(event)
	{
	el = getElement(event);
	do
		{
		if( cmnMatch_class(el, 'opensubs') )
			{
			break;
			}
		}
	while(el = el.parentNode);
	if(ul = $(el.id.replace(/li_/,'ul_')))
		{
		clearTimeout(KIT_timeout[ul.id]);
		ul.style.display = 'block';
		//cmnSet_class(el, ul.style.display == 'block' ? 'b-minus' : 'b-plus', ul.style.display == 'block' ? 'b-plus' : 'b-minus');
		}
	}
function HideSubmenu(event)
	{
	el = getElement(event);
	do
		{
		if( cmnMatch_class(el, 'opensubs') )
			{
			break;
			}
		}
	while(el = el.parentNode);
	if(ul = $(el.id.replace(/li_/,'ul_')))
		KIT_timeout[ul.id] = setTimeout("$('"+ul.id+"').style.display='none';", 40);
	}
/*
function HoverSubmenu(event)
	{
	el = getElement(event);
	do
		{
		if( cmnMatch_class(el, 'catalog_menu') )
			{
			break;
			}
		}
	while(el = el.parentNode);
	
	//el.style.display='block';
	clearTimeout(KIT_timeout[el.id]);
	}
function UnhoverSubmenu(event)
	{
	el = getElement(event);
	//alert(el.tagName);
	do
		{
		if( !cmnMatch_class(el, 'catalog_menu') )
			{
			return;
			}
		}
	while(el = el.parentNode);
	KIT_timeout[el.id] = setTimeout("$('"+el.id+"').style.display='none';", 500);
//	alert('!!!!!!');
	}*/