
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
    return this.replace(/\s+$/,"");
}
//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
function str_replace (search, replace, subject, count) 
{
	var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
		f = [].concat(search),
		r = [].concat(replace),
		s = subject,
		ra = r instanceof Array, sa = s instanceof Array;
	s = [].concat(s);
	if (count) {
		this.window[count] = 0;
	}

	for (i=0, sl=s.length; i < sl; i++)
	{
		if (s[i] === '') 
		{
			continue;
		}
		for (j=0, fl=f.length; j < fl; j++) 
		{
			temp = s[i]+'';
			repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
			s[i] = (temp).split(f[j]).join(repl);
			if (count && s[i] !== temp) {
				this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
	return sa ? s : s[0];
}
//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');}

function show_vis(block){return replaceClassNameOnce(block,'hideVis','showVis');}
function hide_vis(block){return replaceClassNameOnce(block,'showVis','hideVis');}
//ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
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
