

String.prototype.replaceAll = function(search, replace){
  return this.split(search).join(replace);
}
	
function editor_change(inst) {
	var text = inst.getBody().innerHTML
	var count = text.length; 
	var ids = inst.id+"_count";
	document.getElementById(ids).innerHTML  = 'Символов:' + count;
}


function editor_change_first(editor_id, body, doc) {
	var text = body.innerHTML
	var count = text.length; 
	var ids = editor_id+"_count";
	document.getElementById(ids).innerHTML  = 'Символов:' + count;
} 

function searchclr(elem) {
	elem.value='';	
}
	
function check_all(Element,Name){
	
if(document.getElementById) {
	ElementDiv=document.getElementById(Name);
	thisCheckBoxes = ElementDiv.getElementsByTagName('input');
	for (i = 1; i < thisCheckBoxes.length; i++){
		//if (thisCheckBoxes[i].name == Name){
			thisCheckBoxes[i].checked = Element.checked;
			//Colorize(document.getElementById(thisCheckBoxes[i].id.replace('cb','tr')), thisCheckBoxes[i]);
		//}
	}
	}
}

function Colorize(Element, CBElement){
if(document.getElementById) {
	if(Element && CBElement){
		Element.className = ( CBElement.checked ? 'selected' : 'default' );
	}
}
}

	
function _redirect(elem_id) {
		var mySelect=document.getElementById(elem_id);
			theIndx=mySelect.selectedIndex;
			{
			if (mySelect.options[theIndx].value != "none")
			(location = mySelect.options[theIndx].value)
			}

	}

function _ShowHideHenuItem(item_id) {
	if (document.getElementById('menu_item_'+item_id).style.display=='none') {
		document.getElementById('menu_item_'+item_id).style.display='inline'
		}
	else document.getElementById('menu_item_'+item_id).style.display='none';
	//alert(document.getElementById('menu_item_'+item_id).style.display);
}

function imposeMaxLength(Object, MaxLen) {
	return (Object.value.length <= MaxLen);
}

function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function _set_topw() {
	//var topw=window.innerWidth;
	var topw=getClientWidth();
	var topt1=document.getElementById('Table_top_menu');
	var topt2=document.getElementById('Table_04');
	topt1.style.width=topw+'px';
	topt2.style.width=topw+'px';

}
function urlconverter(url, node, on_save) {
	// Do some custom URL convertion
	
	var obj_re = new RegExp(/\/webroot\/(.+)$/);    
	var str_name = obj_re.exec(url);
	if(str_name!=null) url = '../../../../../'+str_name[1];
	
	// Return new URL
	return url;
}
