function open_html(url, wwidth, wheight, resized, scrolls){
//	alert(wheight);
	if(resized) resizable_par=resized?',resizable=yes':',resizable=no'; else resizable_par=',resizable=no';
	if(scrolls) scroll_par=scrolls?',scrollbars=yes':',scrollbars=no'; else scroll_par=',scrollbars=no';
	pX = Math.round((screen.width - wwidth) / 2);
	pY = Math.round((screen.height - wheight) / 2);
	var rnd=Math.round(1000*Math.random());
	if(document.all){
		win_coords =',left='+pX+',top='+pY;
		new_window = window.open('', 'NewWindow'+rnd, 'width='+wwidth+',height='+wheight+',titlebar=no' + resizable_par + scroll_par + win_coords);
		new_window.location = url;
	}else{
		win_coords =',screenX='+pX+',screenY='+pY;
		new_window = window.open(url,'_blank', 'width='+wwidth+',height='+wheight+',titlebar=no,menubar=no,status=no,location=no,fullscreen=no,directories=no' + resizable_par + scroll_par + win_coords);
	}
}
function open_picture(url, wwidth, wheight){
	pX = Math.round((screen.width - wwidth) / 2);
	pY = Math.round((screen.height - wheight) / 2);
	if(document.all){
		win_coords =',left='+pX+',top='+pY;
		var w = window.open('', 'NewWindow', 'width='+wwidth+',height='+wheight+',titlebar=no,resizable=no,scrollbars=no'+win_coords);
		w.location = url;
	}else{
		win_coords =',screenX='+pX+',screenY='+pY;
		window.open(url,'_blank', 'width='+wwidth+',height='+wheight+',titlebar=no,menubar=no,status=no,location=no,fullscreen=no,directories=no,resizable=no,scrollbars=no'+win_coords);
	}
}

function switch_element(id){
	var status = document.getElementById(id).style.display;
	document.getElementById(id).style.display = (status=='none')?'block':'none';
}

function switch_checkboxes_old(form, group_name, status){
	var pat = new RegExp(group_name + "\[[0-9]+\]", "i")
	for (e in form.elements) {
		matched=e.match(pat);
		if(matched && form.elements[e].type=='checkbox'){
			form.elements[e].checked=status;
		}
	}
}

function switch_checkboxes(form, group_name, status){
	var pat = new RegExp(group_name + "\[[0-9]+\]", "i");
	var arr = form.elements;	var a;
	for (var i=0;i<arr.length;i++) {
		a = arr[i];
		matched=a.name.match(pat);
		if(matched && a.type=='checkbox'){
			a.checked=status;
		}
	}
}
function oldswitcher(form, f, s){
	for (i = 1; i < ids.length; i++) {
		c=eval('form[\"' + f + '[' + ids[i] + ']\"]');
		c.checked = s;
	}		
}

function TagInsert(form, field, Tag, Tag2){
	var obj = form[field];
	obj.focus();
	if(document.selection){
		var sel = document.selection.createRange();
		sel.text= Tag+sel.text+Tag2;
	} else {
		var start=obj.selectionStart;
		var end=obj.selectionEnd;
		var text=obj.value;
		var len=text.length;
		obj.value=text.substring(0, start) + Tag + 
			text.substring(start, end) + Tag2 +
			text.substring(end, len);
	}
}

function __________TagInsert(form, field, Tag, Tag2){
	form[field].focus();
	sel = document.selection.createRange();
	alert(sel.text);
	sel.text= Tag+sel.text+Tag2;
}



function big_photo(url){
	var screen_w = screen.width;
	var screen_h = screen.height;
	if(document.all){
		window.open(url,'','left=0,top=0,width=screen_w,height=screen_h,scrollbars=yes,fullscreen=yes');
	}else{
		window.open(url,'_blank', 'width='+screen_w+',height='+screen_h+',titlebar=no,menubar=no,status=no,location=no,fullscreen=yes,directories=no,resizable=no,screenX=0,screenY=0');
	}
}


function collect_IDs(obj, ID, direct) {
	var listvar = obj.value;
	switch(direct){
		case(true):{
			listvar = listvar+((listvar=='')?'':',')+ID;
			break;
		}
		case(false):{
			var listvar2 = ','+listvar+',';
			var pattern = ','+ID+',';
			eval('listvar = listvar2.replace(/'+pattern+'/g,",").replace(/^,/,"").replace(/,$/,"");');
			break;
		}
	}
	obj.value = listvar;
}

function autofit_and_center(){
	window.resizeBy(document.body.scrollWidth-document.body.offsetWidth, document.body.scrollHeight-document.body.offsetHeight+5);
	pX = Math.round((screen.width - document.body.offsetWidth) / 2);
	pY = Math.round((screen.height - document.body.offsetHeight) / 2);
	window.moveTo(pX,pY);
}

function CheckText(form, field){
	// функция частично слизана с hiero.ru. спасибо Давиду за идею
	var result = true; 
	var obj=document.forms[form][field];
	var original_text=obj.value;
	var text=original_text.replace(/([^\d])\1{2,}/g, "$1$1$1").replace(/^\s+|\s+$/g, '');
	obj.value=text;
//	return false;
	var lext=text.toLowerCase();
	var c=0;
	for(i=0; i<text.length; i++){
		if(text.charAt(i)!=lext.charAt(i)) c++;
	}
	cc=(c/text.length)*100;
	if(cc>20 && text.length>10){
		alert("Слишком много заглавных букв! \n" + cc + "%, а допускаетс\я не более 20% 8-)");
		result = false;
	}
	if(text.match(/нравитьс\я/i)) return confirm("Вы уверены, что слово \"нравитс\я\" здесь следует писать именно с мягким знаком?");
	if(text.match(/кажетьс\я/i)) { alert("Вот уж где-где, а в слове \"кажетс\я\" мягкого знака быть никак не может. Согласны?"); return false;}
	if(text.match(/смотритьс\я/i)) { alert("В слове \"смотритс\я\" мягкого знака быть не может. Да и вообще такого слова нет. 8-)"); return false;}
	if(text.match(/чавств/i)) return confirm("'учаВствовать' - это от слова 'чаВкать', не так ли?");
	if(text.match(/н[еиe]д[оаoa]ш[аa][рp]п/i)) { alert("Вы уж простите, но слова \"недошарп\" не существует в русском языке."); return false;}
	if(text.match(/^[0-9!]+[0-9!. ]*$/i)) { alert("Бессодержательный комментарий 8-("); return false;}

	return result;
}

/* Trim leading and trailing blanks from an input field */
function alltrim(obj){
   var trimmedstring="",startpos=0, endpos=obj.value.length - 1
   /* find start position of string */	
   while (startpos<=obj.value.length && obj.value.substring(startpos, startpos+1)==" ") {
 	   startpos++
   }
   /* null string */
   if (endpos == -1) {
     endpos=0
   }
   /* find end position of string */
   while (endpos >= 0 && obj.value.substring(endpos,endpos+1)==" ") {
	   endpos--
   }
   /* replace value with trimmed string */
   obj.value=obj.value.substring(startpos,endpos+1)
   return obj
}

function ajust_div_width(div_style, w){
	var size=document.body.offsetWidth;
	if(size<w){
		div_style.paddingRight=0;
	} else {
		div_style.paddingRight=size-w;
	}
}

function win_fit_and_center(){
	resizeX=document.body.scrollWidth-document.body.offsetWidth;
	resizeY=document.body.scrollHeight-document.body.offsetHeight;
	if(document.body.scrollHeight>screen.height){
		resizeY=screen.height-document.body.offsetHeight-100;
	}
//	alert(document.body.scrollHeight);
//	alert(document.body.offsetHeight);
//	alert(resizeY);

	window.resizeBy(resizeX, resizeY);
	new_width=document.body.scrollWidth;
	new_height=document.body.scrollHeight;
	pX = Math.round((screen.width - new_width) / 2);
	pY = Math.round((screen.height - new_height) / 2);
	if(pY<0) pY=0;
	window.moveTo(pX,pY);
}

function edit_tagselect(list){
    if (!list) return;
    var selected = new Array();  // tagnames, for display
    for ( $i = 0; $i < list.options.length; $i++ ) {
        if (list.options[$i].selected) {
            selected.push(list.options[$i].value);
        }
    }
	document.getElementById('tagfield').value = selected.join(", ");
}

function ajax_indicator_on(div){
	var indicator_pic='<img src=' + htmlrootpath + '/images/ajax/indicator.gif>';
	if (div){ document.getElementById(div).innerHTML=indicator_pic; }
}
function ajax_indicator_off(div){
	if (div){ document.getElementById(div).innerHTML=''; }
}
