//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
function findCSSRule(searchRule)
{
	var RegRule=new RegExp('^[\w\. ><:]*'+searchRule+'[\w\. ><:]*$','i');
	var resultRuleArray=new Array();
	for(var i=0;i<document.styleSheets.length;i++)
	{
		arrayRule=(document.styleSheets[i].cssRules)? document.styleSheets[i].cssRules:document.styleSheets[i].rules;
		for(var j=0;j<arrayRule.length;j++)
		{
			if(RegRule.test(arrayRule[j].selectorText))
			{
//				alert(arrayRule[j].selectorText);
				resultRuleArray[resultRuleArray.length]=arrayRule[j];
//				arrayRule[j].style['fontSize']='40px';
			}
		}
	}
	if(resultRuleArray.length)
		return resultRuleArray;
	else
		return false;
}
//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
function findOnceCSSRule(searchRule)
{
	var RegRule=new RegExp('^(\s)*'+searchRule+'(\s)*$','i');
	var resultRule;
	for(var i=0;i<document.styleSheets.length;i++)
	{
		arrayRule=(document.styleSheets[i].cssRules)? document.styleSheets[i].cssRules:document.styleSheets[i].rules;
		for(var j=0;j<arrayRule.length;j++)
		{
			if(RegRule.test(arrayRule[j].selectorText))
			{
				resultRule=arrayRule[j];
//				document.write(resultRule.selectorText);
			}
		}
	}
	if(resultRule)
		return resultRule;
	else
		return false;
}
//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
function changeCSSRule(searchRule,cssProperty,cssValue)
{
	if(typeof(cssProperty)!='object')
		cssProperty=new Array(cssProperty);

	if(typeof(cssValue)!='object')
		cssValue=new Array(cssValue);

	if(cssProperty.lenght!=cssValue.lenght)
		return false;

	var findRule=findOnceCSSRule(searchRule);

	if(findRule)
		for(var j=0;j<cssProperty.length;j++)
			findRule.style[cssProperty[j].trim()]=cssValue[j].trim();
}
//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
function correctSizeElForIE6()
{
	if(Prototype.Browser.IE6)
	{
		var arrayEl=getElByParamReg(document.body,'*','rel','needChangeSizeForIE6');
		for(var i=0;i<arrayEl.length;i++)
		{
			arrayEl[i]=$(arrayEl[i]);
			if(arrayEl[i].getHeight()%2!=0)
				arrayEl[i].style.height=(arrayEl[i].getHeight()+1)+'px';
			if(arrayEl[i].getWidth()%2!=0)
				arrayEl[i].style.width=(arrayEl[i].getWidth()+1)+'px';
		}

		var arrayEl=getElByParamReg(document.body,'*','rel','needChangeSizeForWidthIE6');
		for(var i=0;i<arrayEl.length;i++)
		{
			arrayEl[i]=$(arrayEl[i]);
			if(arrayEl[i].getWidth()%2!=0)
				arrayEl[i].style.width=(arrayEl[i].getWidth()+1)+'px';
		}
	}
}
//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
var rusChars = new Array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ч','Ц','Ш','Щ','Э','Ю','Я','Ы','Ъ','Ь','а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ч','ц','ш','щ','э','ю','я','ы','ъ','ь',' ', '\\', '/', '@', '%', '"', '\'','«','»');

var transChars = new Array('a','b','v','g','d','je','jo','zh','z','i','j','k','l','m','n','o','p','r','s','t','u','f','h','ch','c','sh','csh','e','ju','ja','y','\`','\'','a','b','v','g','d','je','jo','zh','z','i','j','k','l','m','n','o','p','r','s','t','u','f','h','ch','c','sh','csh','e','ju','ja','y','','','_','','', '', '', '', '','','');

function transconvert(text)
{
	return str_replace(rusChars,transChars,text);
}
//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
function replaceClassNameOnce(block,regSearchName,regReplaceHide)
{
	block=$(block);	if(!block)	{return false;}

	var regSearch = new RegExp(regSearchName);
	block.className=block.className.replace(regSearch,regReplaceHide);

	return true;
}

function show_block(block){return replaceClassNameOnce(block,'hideBlock','showBlock');}
function hide_block(block){return replaceClassNameOnce(block,'showBlock','hideBlock');}
//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
/**
 * Функция заменяет один класс на другой в элементе 'block', работает и в обратном направлении
 */
function replaceClassNameDouble(block,regShowName,regHideName)
{
	block=$(block);

	if(!block)
		return false;

	var regShow = new RegExp(regShowName);
	var regHide = new RegExp(regHideName);

	if (regShow.test(block.className))
		block.className=block.className.replace(regShow,regHideName);
	else
		block.className=block.className.replace(regHide,regShowName);

	return true;
}

function show_hide_block(block){return replaceClassNameDouble(block,'showBlock','hideBlock');}

function show_hide_inlineBlock(block){return replaceClassNameDouble(block,'showInlineBlock','hideBlock');}

function show_hide_inline(block){return replaceClassNameDouble(block,'showInline','hideBlock');}

function show_hide_vis(block){return replaceClassNameDouble(block,'showVis','hideVis');}

function show_hide_mainImg(block){return replaceClassNameDouble(block,'showMainImg','hideMainImg');}
//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
function getElByParam(idTagIn,tagName,nameParam,valueParam,iframeDoc)
{
	tagName=(tagName) ? tagName : "*";
	
	if(!iframeDoc)
		var tagParrent=$(idTagIn);
	else
		if(typeof(idTagIn)=='string')
			tagParrent=iframeDoc.getElementById(idTagIn);
		else
			tagParrent=idTagIn;

	
	var arrayChild=tagParrent.getElementsByTagName(tagName);
	var arrayResult=new Array();
	
	if(iframeDoc)
	{
		alert('tagParrent '+tagParrent.length);
		alert('arrayChild '+arrayChild.length);
	}

	for(var i=0;i<arrayChild.length;i++)		
		if(((nameParam!='className')&&(arrayChild[i].getAttribute(nameParam)==valueParam))||((nameParam=='className')&&(arrayChild[i].className==valueParam)))
			arrayResult[arrayResult.length]=arrayChild[i];

	if (arrayResult.length==0)
		return false;
	else
		return arrayResult;
}
//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
function setEventsOnInputGreyDescr(textColor,descrColor)
{
	textColor=(textColor.charAt(0)=='#')?textColor:'#'+textColor;
	descrColor=(descrColor.charAt(0)=='#')?descrColor:'#'+descrColor;

	$$('input[rel=greyDescr]').each(function(obj)
	{
		var defaultText=obj.getAttribute('defaultGreyText');

		if(!defaultText)
			defaultText=obj.defaultValue;

		if(!obj.value)
			obj.value=defaultText;

		if(obj.value==defaultText)
			obj.style.color=descrColor;

		obj.observe("focus", function(event)
		{
			var element = Event.element(event);
/*
			if(!defaultText)
				defaultText=element.defaultValue;
*/
			if(element.value==defaultText)
				{
					element.value='';
					element.style.color=textColor;
				}
		})

		obj.observe("blur", function(event)
		{
			var element = Event.element(event);
			if(!element.value)
				{
					element.value=defaultText;
					element.style.color=descrColor;
				}
		})
	});
}
//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
function getDocumentSize(doc) { // getting a real size document with scrolling etc.
  var r = { width: 0, height: 0 };

  var width1=0, width2=0, width3=0, width4=0, maxWidth=0;
  var height1=0, height2=0, height3=0, height4=0, maxHeight=0;

  if (doc.width) maxWidth = doc.width; 
  if (doc.body) {
	if (doc.body.scrollWidth) width1 = doc.body.scrollWidth;
	if (doc.body.offsetWidth) width2 = doc.body.offsetWidth;
  }
  if (doc.documentElement) {
	width3 = doc.documentElement.scrollWidth;
	width4 = doc.documentElement.clientWidth;
  }

  maxWidth = Math.max(Math.max(Math.max(width1, width2), Math.max(width3, width4)),maxWidth);

  if (doc.height) maxHeight = doc.height;
  if (doc.body) {
	if (doc.body.scrollHeight) height1 = doc.body.scrollHeight;
	if (doc.body.offsetHeight) height2 = doc.body.offsetHeight;
  }
  if (doc.documentElement) {
	height3 = doc.documentElement.scrollHeight;
	height4 = doc.documentElement.clientHeight;
  }
  maxHeight = Math.max(Math.max(Math.max(height1, height2), Math.max(height3, height4)),maxHeight);

  r.width = maxWidth;
  r.height = maxHeight;

  return r;
}
//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
function mousePageXY(e)
{
	var x = 0, y = 0;

	if (!e) e = window.event;

	if (e.pageX || e.pageY)
	{
		x = e.pageX;
		y = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
		y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	}

	return {"x":x, "y":y};
}
//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
/**
 * Функция получает следующий или предыдущий элемент "покругу". 
 * Тоесть если текущий элемент - это последний в списке, то функция возратит первый
 * 
 * @param object this_el текущий элемент
 * @param bool  is_prev=false если true то получить следующий элемент, иначе текущий.
 * @param string css
 * @return object|false
 */
function get_next_prev_el(this_el,is_prev,css)
{
	this_el=$(this_el);	if(!this_el)	{return false;}
	if(!is_prev)	{is_prev=false;}
	if(!css)	{css='';}

	var next_el=null;

	if(!is_prev)
	{
		next_el=this_el.next(css);
		if(!next_el)	{next_el=this_el.up().down(css);}
		if(!next_el) {return false;}
	}else{
		next_el=this_el.previous(css);
		if(!next_el)	
		{
			next_el=this_el.up().select(css);
			next_el=(next_el && next_el.length) ? next_el=next_el.last() : false;

			if(!next_el)	{return false;}
		}
	}
	return next_el;
}

function prev_global(caller,css,index)
{
	caller=$(caller);	if(!caller)	{return false;}
	if(!css)	{return false;}
	if(!index)	{index=0;}

	var list_el=$$(css);	if(!list_el || !list_el.length)	{return false;}
	var index_el=list_el.indexOf(caller);	if(!index_el)	{return false;}
	
	return list_el[index_el-1-index];
}

function next_global(caller,css,index)
{
	caller=$(caller);	if(!caller)	{return false;}
	if(!css)	{return false;}
	if(!index)	{index=0;}
	
	var list_el=$$(css);	if(!list_el || !list_el.length)	{return false;}
	var index_el=list_el.indexOf(caller);	if(index_el==-1)	{return false;}

	return list_el[index_el+1+index];
}

var metr_list_id_event=[];

function metrika_event_sent(id, txt)
{
	id=parseInt(id);
	
	if(metr_list_id_event[id])
		return false;
	
	metr_list_id_event[id]=true;
 
	yaCounter1615571.reachGoal(txt+id);
	return true;
}
