document.onmousemove = function(e){var mCur = mousePageXY(e); $('#x_cursor').val(mCur.x); $('#y_cursor').val(mCur.y);};

function add_title(text) {
	window.document.title = window.document.title + ' - ' + text;
}

function gvbid(id) {
	return document.getElementById(id).value;
}

function ajaxaction(action,arg1,arg2) {
	$.post('/ajax/'+action+'/?root=clear', {'arg1':arg1,'arg2':arg2}, function(data){
		document.location = document.location;
	});
}

function ajx(url,refresh) {
	$.get(url, function(data){
		if (refresh) document.location = document.location;
	});
}

function srt(k) {
	lct = document.URL;
	lct = lct.replace('srt=1','srt='+k);
	lct = lct.replace('srt=2','srt='+k);
	lct = lct.replace('srt=3','srt='+k);
	if (document.URL != lct) {
		document.location = lct;
	} else {
		if (lct.replace('?','') != lct) {
			document.location = lct+'&srt='+k;
		} else {
			document.location = lct+'?srt='+k;
		}
	}
}

function sh(blockid,id) {
	if (document.getElementById(blockid+"_new_element_"+id).style.display=='none') { 
		$("[name='"+blockid+"_new_element']").hide();
		$("#"+blockid+"_new_element_"+id).fadeIn('side');
	} else {
		$("[name='"+blockid+"_new_element']").hide();
	}
}

function slideT(id) {
	$("#"+id).slideToggle('side');
}

function fadeI(id) {
	if (document.getElementById(id).style.display=='none') {
		$("#"+id).fadeIn('side');
	} else {
		$("#"+id).fadeOut('side');
	}
}

function edit_mode(blockid,status) {
	if (status==1) {
		if (document.getElementById('edit_mode_1_'+blockid)) document.getElementById('edit_mode_1_'+blockid).style.display='';
		if (document.getElementById('edit_mode_0_'+blockid)) document.getElementById('edit_mode_0_'+blockid).style.display='none';
	} else {
		if (document.getElementById('edit_mode_0_'+blockid)) document.getElementById('edit_mode_0_'+blockid).style.display='';
		if (document.getElementById('edit_mode_1_'+blockid)) document.getElementById('edit_mode_1_'+blockid).style.display='none';
	}
	if (status==1) {
		$("[name='editable_"+blockid+"']").fadeIn(1000);
	} else {
		$("[name='editable_"+blockid+"']").fadeOut('side');
	}
}

function new_block(parent_id,typeblock,prefix){
	name = document.getElementById(prefix+'_name').value;
	if(name!='') {
		$.post('/block/add/'+parent_id+'?root=clear', {"group": typeblock, "Block[Позиция]": '', "Block[text]": name}, function(data){
			a = $('#'+prefix);
			iclass = a.attr('class');
			if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
				for (i=0;i<50;i++) {
					b = a.parent();
					a = b;
					iclass = b.attr('class');
					if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
						break;
					}
				}
			}
			eval(a.attr('id')+'("load");');
			});
	}
}

function new_block2(parent_id,typeblock,prefix){
	name = document.getElementById(prefix+'_name').value;
	if(name!='') {
		$.post('/block/add/'+parent_id+'?root=clear', {"group": typeblock, "Block[Позиция]": '', "Block[text]": name}, function(data){
			document.location = document.location;
		});
	}
}

function save_subgroup(id,group){
	$.post("/block/add?root=clear", {"text": $("#"+id).val(), "parent": group}, function(data) { 
		a = $('#'+id).parent();
		iclass = a.attr('class');
		if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
			for (i=0;i<50;i++) {
				b = a.parent();
				a = b;
				iclass = b.attr('class');
				if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
					break;
				}
			}
		}
		eval(a.attr('id')+'("loadedit");');
	});
}

function save_group(id,blockid){
	$.post("/block/add/"+blockid+"?root=clear", {"text": $("#"+id).val(), "type":'group'}, function(data) {
		a = $('#'+id).parent();
		iclass = a.attr('class');
		if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
			for (i=0;i<50;i++) {
				b = a.parent();
				a = b;
				iclass = b.attr('class');
				if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
					break;
				}
			}
		}
		eval(a.attr('id')+'("loadedit");');
	});
}

function save_mitem(id,blockid,svid,asvid){
	edit_mode(blockid,0);
	$.post("/block/add/"+blockid+"?root=clear", {"text": $("#"+id).val(), "type":'mitem'}, function(data) {
		$.post("/find/all_menu_only/"+blockid+"?root=clear", function(data2) {
			$('#menuitems').html(data2);
		});
	});
}

function comm_autors(autors, id, tag_id, block_id) {
	
	xcur = $('#x_cursor').val();
	ycur = $('#y_cursor').val();
	
	a = document.getElementById('win_'+id);
	if (a) {
		a.parentNode.removeChild(a);
	} else {
		//Создать меню
		all = document.getElementsByName('wina');
		for(i=0;i<all.length;i++) {
			all[i].parentNode.removeChild(all[i]);
		}
		//par = $("#"+id).parent();
		//par.html('<div name="wina" style="display:none;z-index:1;" id="win_'+id+'" class="main"></div>'+par.html());
		$("body").append('<div name="wina" style="display:none;z-index:1;" id="win_'+id+'" class="main"></div>');
		a = document.getElementById('win_'+id);
		//tmp = document.getElementById(id);
		//p_webpos = WebForm_GetElementPosition(tmp);
		a.style.top = parseInt(ycur);//p_webpos.height);//+parseInt(p_webpos.y);
		a.style.left = parseInt(xcur);//p_webpos.x);
		$.post("/block/commautors/?root=clear", {ky: 'win_'+id, users: autors, tagid: tag_id, blockid: block_id}, function(data) {
			if (document.getElementById('win_'+id)) {
				$(a).fadeIn('side');
				$(a).html(data);
			}
		});
	}
}

function descr_autors(autors, id) {
	
	xcur = $('#x_cursor').val();
	ycur = $('#y_cursor').val();
	
	a = document.getElementById('win_'+id);
	if (a) {
		a.parentNode.removeChild(a);
	} else {
		//Создать меню
		all = document.getElementsByName('wina');
		for(i=0;i<all.length;i++) {
			all[i].parentNode.removeChild(all[i]);
		}
		//par = $("#"+id).parent();
		//par.html('<div name="wina" style="display:none;z-index:1;" id="win_'+id+'" class="main"></div>'+par.html());
		$("body").append('<div name="wina" style="display:none;z-index:1;" id="win_'+id+'" class="main"></div>');
		a = document.getElementById('win_'+id);
		//tmp = document.getElementById(id);
		//p_webpos = WebForm_GetElementPosition(tmp);
		a.style.top = parseInt(ycur);//p_webpos.height);//+parseInt(p_webpos.y);
		a.style.left = parseInt(xcur);//p_webpos.x);
		$.post("/block/descrautors/?root=clear", {ky: 'win_'+id, users: autors}, function(data) {
			if (document.getElementById('win_'+id)) {
				$(a).fadeIn('side');
				$(a).html(data);
			}
		});
	}
}

function idtoclick(id) {
	xcur = $('#x_cursor').val();
	ycur = $('#y_cursor').val();
	
	a = document.getElementById(id);
	
	a.style.top = parseInt(ycur);
	a.style.left = parseInt(xcur);
	
}

function comm_autors_close(id) {
	a = document.getElementById(id);
	if (a) {
		a.parentNode.removeChild(a);
	}
}

function save_comment(id,text,parentid){
	$.post("/block/addcomment/?blockid="+id+"&root=clear", {"text": text}, function(data) {
		a = $('#comment_'+id).parent();
		iclass = a.attr('class');
		if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
			for (i=0;i<50;i++) {
				b = a.parent();
				a = b;
				iclass = b.attr('class');
				if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
					break;
				}
			}
		}
		if(parentid>0) {
			eval('ccomm_'+parentid+'();');
		} else {
			eval(a.attr('id')+'("load");');
		}
	});
}
function save_comment1(id,text,parentid){
	$.post("/block/addcomment/?blockid="+id+"&root=clear", {"text": text}, function(data) {
		a = $('#comment1_'+id).parent();
		iclass = a.attr('class');
		if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
			for (i=0;i<50;i++) {
				b = a.parent();
				a = b;
				iclass = b.attr('class');
				if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
					break;
				}
			}
		}
		if(parentid>0) {
			eval('ccomm1_'+parentid+'();');
		} else {
			eval(a.attr('id')+'("load");');
		}
	});
}

function delfromblock(id,iddom){
	$.get("/block/del/?id="+id+"&root=clear", function(data) {
		a = $('#'+iddom).parent();
		iclass = a.attr('class');
		if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
			for (i=0;i<50;i++) {
				b = a.parent();
				a = b;
				iclass = b.attr('class');
				if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
					break;
				}
			}
		}
		if (a.attr('id')) {
			eval(a.attr('id')+'("loadedit");');
		} else {
			document.location = document.location;
		}
	});
}

function moveblock(id,iddom,vect,sortarr) {
	$.post("/block/move/?id="+id+"&root=clear", {v: vect, sss: sortarr}, function(data) {
		//alert(data);
		a = $('#'+iddom).parent();
		iclass = a.attr('class');
		if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
			for (i=0;i<50;i++) {
				b = a.parent();
				a = b;
				iclass = b.attr('class');
				if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
					break;
				}
			}
		}
		eval(a.attr('id')+'("loadedit");');
	});
}

function resize(id,blockid,value){
	a = $('#'+id).parent();
	iclass = a.attr('class');
	if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
		for (i=0;i<50;i++) {
			b = a.parent();
			a = b;
			iclass = b.attr('class');
			if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
				break;
			}
		}
	}
	eval('size'+a.attr('id')+'("'+value+'");');
}

function next_autors(page,divid,kyky,autors,tag_id) {
	$.post("/block/commautors/?root=clear&page="+page, {ky: kyky, users: autors, tagid: tag_id}, function(data) {
		if (document.getElementById(divid)) {
			document.getElementById(divid).innerHTML=data;
		}
	});
}

function comm_agree(block_id,divid,kyky,autors,tag_id) {
	$.post("/block/addcomment/?blockid="+block_id+"&root=clear", {"tag": tag_id}, function(data) {
		a = $('#'+divid).parent();
		iclass = a.attr('class');
		if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
			for (i=0;i<50;i++) {
				b = a.parent();
				a = b;
				iclass = b.attr('class');
				if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
					break;
				}
			}
		}
		eval(a.attr('id')+'("load");');
	});
}

function forum_session(id,v) {
	saveall(0);
}
function forum_allbyname(id,v) {
	if (v) {
		all = document.getElementsByName(id);
		for(i=0;i<all.length;i++) {
			all[i].checked = true;
			all[i].disabled = true;
		}
	} else {
		all = document.getElementsByName(id);
		for(i=0;i<all.length;i++) {
			all[i].checked = false;
			all[i].disabled = false;
		}
	}
	saveall(0);
}
function saveall(type) {
	if (type == 0) {
		//Клик по галочке
		//Считать значения галочек
		all = $('#forum_menu').find('input');
		//Изменить ссылку
		myurl = document.URL;
		if (myurl.indexOf('?tab=forum')>0) myurl = myurl.substring(0,myurl.indexOf('?tab=forum')+10);
		else if (myurl.indexOf('?tab=links')>0) myurl = myurl.substring(0,myurl.indexOf('?tab=links')+10);
		else if (myurl.indexOf('?tab=albums')>0) myurl = myurl.substring(0,myurl.indexOf('?tab=albums')+11);
		else if (myurl.indexOf('?tab=tags')>0) myurl = myurl.substring(0,myurl.indexOf('?tab=tags')+9);
		else if (myurl.indexOf('?tab=mix')>0) myurl = myurl.substring(0,myurl.indexOf('?tab=mix')+9);
		else myurl='/?node=1';
		for(i=0;i<all.length;i++) {
			if (all[i].checked) {
				myurl += '&'+all[i].id+'=1';
			}
		}
		//Перегрузить
		document.location = myurl;
	} else {
		//Клик по ссылке
		myurl = document.URL;
		if (myurl.indexOf('?tab=forum')>0) myurl = myurl.substring(0,myurl.indexOf('?tab=forum')+10);
		else if (myurl.indexOf('?tab=links')>0) myurl = myurl.substring(0,myurl.indexOf('?tab=links')+10);
		else if (myurl.indexOf('?tab=albums')>0) myurl = myurl.substring(0,myurl.indexOf('?tab=albums')+11);
		else if (myurl.indexOf('?tab=tags')>0) myurl = myurl.substring(0,myurl.indexOf('?tab=tags')+9);
		else if (myurl.indexOf('?tab=mix')>0) myurl = myurl.substring(0,myurl.indexOf('?tab=mix')+9);
		else myurl='/?node=1';
		myurl += '&'+type+'=1';
		all = document.getElementsByName(type);
		for(i=0;i<all.length;i++) {
			myurl += '&'+all[i].id+'=1';
		}
		document.location = myurl;
	}
}

function relen(id,blockid,value){
	a = $('#'+id).parent();
	iclass = a.attr('class');
	if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
		for (i=0;i<50;i++) {
			b = a.parent();
			a = b;
			iclass = b.attr('class');
			if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
				break;
			}
		}
	}
	eval('relen'+a.attr('id')+'("'+value+'");');
}

function p(id,p,relen){
	a = $('#'+id).parent();
	iclass = a.attr('class');
	if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
		for (i=0;i<50;i++) {
			b = a.parent();
			a = b;
			iclass = b.attr('class');
			if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
				break;
			}
		}
	}
	eval('p'+a.attr('id')+'("'+p+'",'+relen+');');
}

function history(act,id,x,thisdata,p,relen){
	hideAllHB(act,id);
	a = $('#'+id).parent();
	iclass = a.attr('class');
	if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
		for (i=0;i<50;i++) {
			b = a.parent();
			a = b;
			iclass = b.attr('class');
			if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
				break;
			}
		}
	}
	eval('history'+a.attr('id')+'("'+act+'","'+id+'","'+x+'",\''+thisdata+'\','+p+','+relen+');');
}

function historymix(act,id,x,thisdata,p,relen,panel_id){
	hideAllHB(act,id);
	a = $('#'+id).parent();
	iclass = a.attr('class');
	if (iclass != 'comment' || !/\bcomments(.*)\b/.test(a.attr('id')) ) {
		for (i=0;i<50;i++) {
			b = a.parent();
			a = b;
			iclass = b.attr('class');
			if (iclass == 'comment' && /\bcomments(.*)\b/.test(a.attr('id'))) {
				break;
			}
		}
	}
	eval('history'+a.attr('id')+'("'+act+'","'+id+'","'+x+'",\''+thisdata+'\','+p+','+relen+',"'+panel_id+'");');
}

function historymix2(act,blockid,id,x,thisdata,p,relen,panel_id){
	hideAllHB(act,id);
	thispos = parseInt($('#pos'+blockid).val());
	
	//увеличиваем level
	afin = new Array();
	a = document.getElementsByName('panel'+panel_id+'_pos');
	for (i=0;i<a.length;i++) {
		if (parseInt(a[i].value)>=thispos) afin[parseInt(a[i].value)-thispos] = a[i];
	}
	iff = 1;
	for (i=0;i<afin.length;i++) {
		id = afin[i].id.replace('pos', '');
		if (parseInt(document.getElementById('panel'+panel_id+"_"+id).style.paddingLeft)==0) {
			if (iff==0) {
				break; 
			} else {
				iff = 0;
				level = (parseInt(document.getElementById('panel'+panel_id+"_"+id).style.paddingLeft)+5)/5;
				setLevel('panel'+panel_id+"_"+id,level);
				ccc = document.getElementById('panel'+panel_id+"_"+id).style.background;
				ccc = ccc.replace('&line[9]=','&line[10]=');
				ccc = ccc.replace('&line[8]=','&line[9]=');
				ccc = ccc.replace('&line[7]=','&line[8]=');
				ccc = ccc.replace('&line[6]=','&line[7]=');
				ccc = ccc.replace('&line[5]=','&line[6]=');
				ccc = ccc.replace('&line[4]=','&line[5]=');
				ccc = ccc.replace('&line[3]=','&line[4]=');
				ccc = ccc.replace('&line[2]=','&line[3]=');
				ccc = ccc.replace('&line[1]=','&line[2]=');
				ccc = ccc.replace('?line[0]=1','?line[0]=0&line[1]=0');
				ccc = ccc.replace('?line[0]=0','?line[0]=0&line[1]=0');
				document.getElementById('panel'+panel_id+"_"+id).style.background = ccc;
			}
		} else {
			level = (parseInt(document.getElementById('panel'+panel_id+"_"+id).style.paddingLeft)+5)/5;
			setLevel('panel'+panel_id+"_"+id,level);
			//alert('до:'+document.getElementById('panel'+panel_id+"_"+id).style.background);
			ccc = document.getElementById('panel'+panel_id+"_"+id).style.background;
			ccc = ccc.replace('&line[9]=','&line[10]=');
			ccc = ccc.replace('&line[8]=','&line[9]=');
			ccc = ccc.replace('&line[7]=','&line[8]=');
			ccc = ccc.replace('&line[6]=','&line[7]=');
			ccc = ccc.replace('&line[5]=','&line[6]=');
			ccc = ccc.replace('&line[4]=','&line[5]=');
			ccc = ccc.replace('&line[3]=','&line[4]=');
			ccc = ccc.replace('&line[2]=','&line[3]=');
			ccc = ccc.replace('&line[1]=','&line[2]=');
			ccc = ccc.replace('?line[0]=1','?line[0]=0&line[1]=0');
			ccc = ccc.replace('?line[0]=0','?line[0]=0&line[1]=0');
			document.getElementById('panel'+panel_id+"_"+id).style.background = ccc;
			//alert('после:'+document.getElementById('panel'+panel_id+"_"+id).style.background);
		}
	}
	//увеличили
	
	allpos = document.getElementsByName('panel'+panel_id+'_pos');
	for (i=0;i<allpos.length;i++) {
		if (allpos[i].value>=thispos) {
			allpos[i].value++;
		}
		//alert(allpos[i].id+' to '+allpos[i].value);
	}
	//alert('thispos: '+thispos);
	$.get('/ajax/addcomment/?root=clear&panel_id='+panel_id+'&parentblock='+panel_id+'&child_id='+blockid+'&pos='+thispos,function(data){
		$('#panel'+panel_id).html($('#panel'+panel_id).html()+data);
		moveAll('panel'+panel_id);
	});
}

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};
}

function openmain(sv_id, object_id) {
	//alert('Вывести меню с доступными мне пунктами для тэга '+object_id+' со связью '+sv_id);
	
	xcur = $('#x_cursor').val();
	ycur = $('#y_cursor').val();
	
	a = document.getElementById('main_'+sv_id+'_'+object_id);
	if (a) {
		a.parentNode.removeChild(a);
	} else {
		//Создать меню
		all = document.getElementsByName('main');
		for(i=0;i<all.length;i++) {
			all[i].parentNode.removeChild(all[i]);
		}
		//par = $("#button_"+sv_id+'_'+object_id).parent();
		//par.html('<div name="main" style="display:none;z-index:1;" id="main_'+sv_id+'_'+object_id+'" class="main"></div>'+par.html());
		$("body").append('<div name="main" style="display:none;z-index:1;" id="main_'+sv_id+'_'+object_id+'" class="main"></div>');
		a = document.getElementById('main_'+sv_id+'_'+object_id);
		//tmp = document.getElementById("button_"+sv_id+'_'+object_id);
		//p_webpos = WebForm_GetElementPosition(tmp);
		a.style.top = parseInt(ycur)+1;//p_webpos.height);//+parseInt(p_webpos.y);
		a.style.left = parseInt(xcur);//p_webpos.x);
		$.post("/main/view/"+sv_id+"/"+object_id+"?root=clear", {ky: 'main_'+sv_id+'_'+object_id}, function(data) {
			$(a).fadeIn('side');
			$(a).html(data);
		});
	}
}

function discopy(val,id) {
	if (val!='') {
		document.getElementById(id).disabled=false;
	} else {
		document.getElementById(id).disabled=true; 
	}
}

function opennewcomment(parent_id,panel_id) {
	if (panel_id==0) {
		eval('newcomment_'+panel_id+'_'+parent_id+'("load",\'void(0);\');');
	} else {
		setW(panel_id);
		eval('newcomment_'+panel_id+'_'+parent_id+'("load",\'moveAll("'+panel_id+'");\');');
	}
}

function delphoto (svid,parid,key) {
	$.get('/album/del_photo/?root=clear&sv_id='+svid+'&parent_id='+parid, function(data) {
		a = $("#"+key).parent();
		iclass = a.attr('class');
		if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
			for (i=0;i<50;i++) {
				b = a.parent();
				a = b;
				iclass = b.attr('class');
				if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
					break;
				}
			}
		}
		if (a.attr('id')) {
			eval(a.attr('id')+'("load");');
		} else {
			to_mix();
		}
	});
}

function copyphoto(svid,bodyid) {
	$.get('/album/copy_photo_form/?root=clear&sv_id='+svid+'&body_id='+bodyid, function(data) {
		$('#'+bodyid).html(data);
	});
}
function copyphoto2(albumid,name,svid,bodyid) {
	$('#'+bodyid).html('Копируется...');
	$.post('/album/copy_photo/?root=clear&sv_id='+svid+'&album_id='+albumid, {child: name}, function(data) {
		$('#'+bodyid).html('Скопировано');
		all = document.getElementsByName('main');
		for(i=0;i<all.length;i++) {
			all[i].parentNode.removeChild(all[i]);
		}
	});
}

function album_unhide(id) {
	aaa = document.getElementsByName("photo_in_"+id+"_hidden");
	for (i=0;i<aaa.length;i++) {
		aaa[i].style.display='inline';
	}
	$("#"+id+"_unhide").hide();
}

function save_mess(id){
	$.post($('#form'+id).attr("action"), {"text": $('#text'+id).val()}, function(data) {
		a = $('#'+id).parent();
		iclass = a.attr('class');
		if (iclass != 'block' || !/\bblock(.*)\b/.test(a.attr('id')) ) {
			for (i=0;i<50;i++) {
				b = a.parent();
				a = b;
				iclass = b.attr('class');
				if (iclass == 'block' && /\bblock(.*)\b/.test(a.attr('id'))) {
					break;
				}
			}
		}
		eval(a.attr('id')+'("load");');
	});
}

function addmess(panel,panel_id,mess_id,blockid,lvl,addurl) {
	idn = 'subcomment_'+panel+'_'+mess_id;
	$('#'+idn).show();
	$('#'+idn).load('/ajax/comm/?root=clear&id='+mess_id+addurl,function(){
		chi = $('#subs_'+blockid).children();
		pan = document.getElementById(panel);
		p_webpos = WebForm_GetElementPosition(pan);
		p_w = p_webpos.width;
		for (ai=0;ai<chi.length;ai++) {	
			id = chi[ai].id;
			if (navigator.appName != "Microsoft Internet Explorer") {
				/*if (!document.getElementById('newcomment_'+panel)) {
					alert('newcomment_'+panel);
				}*/
				//if (document.getElementById(id)) document.getElementById(id).style.width=(p_w-(parseInt(document.getElementById(id).style.paddingLeft))-1);
				if (document.getElementById(id)) document.getElementById(id).style.width=(p_w-(lvl*5)-1);
			} else {
				//if (document.getElementById(id)) document.getElementById(id).style.width=(p_w-(parseInt(document.getElementById(id).style.paddingLeft))-1);
				if (document.getElementById(id)) document.getElementById(id).style.width=(p_w-(lvl*5)-1);
			}
		}
		$('#n'+mess_id).slideDown('slow',function(){
			moveAll('panel'+panel_id);
		});
	});
}

function getPos(id) {
	return document.getElementById('pos'+id).value;
}
function setPos(id,pos) {
	return document.getElementById('pos'+id).value=pos;
}
function marginTo(id,margin) {
	start = parseInt(document.getElementById(id).style.marginTop);
	tim(id,10,((margin-start)/10),margin);
}
function tim(id,i,step,end) {
	document.getElementById(id).style.marginTop=parseFloat(document.getElementById(id).style.marginTop)+step;
	i--;
	if (i>0) {
		setTimeout('tim("'+id+'",'+i+','+step+','+end+')',20);
	} else {
		document.getElementById(id).style.marginTop=end;
	}
}
function setLevel(id,level) {
	start = parseInt(document.getElementById(id).style.paddingLeft);
	
	til(id,10,(((level*5)-start)/10),level*5);
}
function til(id,i,step,end,realw) {
	document.getElementById(id).style.paddingLeft=parseFloat(document.getElementById(id).style.paddingLeft)+step;
	if (navigator.appName != "Microsoft Internet Explorer") {
		document.getElementById(id).style.width=parseFloat(document.getElementById(id).style.width)-step;
	}
	i--;
	if (i>0) {
		setTimeout('til("'+id+'",'+i+','+step+','+end+')',60);
	} else {
		document.getElementById(id).style.paddingLeft=end;
	}
}
function setW(panelid) {
	pan = document.getElementById(panelid);
	p_webpos = WebForm_GetElementPosition(pan);
	p_w = p_webpos.width;
	
	a = document.getElementsByName(panelid+'_pos');
	
	for (i=0;i<a.length;i++) {
		id = a[i].id.replace('pos', '');
		if (navigator.appName != "Microsoft Internet Explorer") {
			if (!document.getElementById('newcomment_'+panelid+"_"+id)) {
				alert('newcomment_'+panelid+"_"+id);
			}
			document.getElementById(panelid+"_"+id).style.width=(p_w-(parseInt(document.getElementById(panelid+"_"+id).style.paddingLeft))-1);
			document.getElementById('newcomment_'+panelid+"_"+id).style.width=(p_w-(parseInt(document.getElementById(panelid+"_"+id).style.paddingLeft))-6);
			if (document.getElementById('anons_'+panelid+"_"+id)) document.getElementById('anons_'+panelid+"_"+id).style.width=(p_w-(parseInt(document.getElementById(panelid+"_"+id).style.paddingLeft))-6);
		} else {
			document.getElementById(panelid+"_"+id).style.width=(p_w-1);
			document.getElementById('newcomment_'+panelid+"_"+id).style.width=(p_w-(parseInt(document.getElementById(panelid+"_"+id).style.paddingLeft))-1);
			if (document.getElementById('anons_'+panelid+"_"+id)) document.getElementById('anons_'+panelid+"_"+id).style.width=(p_w-(parseInt(document.getElementById(panelid+"_"+id).style.paddingLeft))-1);
		}
	}
}

function set_width_by_width(id,byid) {
	pan = document.getElementById(byid);
	p_webpos = WebForm_GetElementPosition(pan);
	document.getElementById(id).style.width=(p_webpos.width)+'px';
}

function moveAll(panelid) {
	pan = document.getElementById(panelid);
	p_webpos = WebForm_GetElementPosition(pan);
	p_w = p_webpos.width;
	
	a = document.getElementsByName(panelid+'_pos');
	all = new Array();
	allpos = new Array();
	for (i=0;i<a.length;i++) {
		id = a[i].id.replace('pos', '');
		all[a[i].value] = id;
		allpos[allpos.length] = a[i].value;
		if (!document.getElementById(panelid+"_"+id)) {
			alert('685 строка block.js: '+panelid+"_"+id);	
		}
		document.getElementById(panelid+"_"+id).style.width=(p_w-(parseInt(document.getElementById(panelid+"_"+id).style.paddingLeft))-1);
	}
	for (ia=0;ia<allpos.length;ia++) {
		if (all[allpos[ia]]) {
			x_h = 0;
			for (i=0;i<allpos.length;i++) {
				if (parseInt(allpos[ia])<parseInt(allpos[i])) {
					if (all[allpos[i]]) {
						elem = document.getElementById(panelid+"_"+all[allpos[i]]);
						x_webpos = WebForm_GetElementPosition(elem);
						x_h += x_webpos.height;
					}
				}
			}
			marginTo(panelid+"_"+all[allpos[ia]],x_h);
		}
	}
	all_h = 0;
	for (i=0;i<allpos.length;i++) {
		if (all[allpos[i]]) {
			elem = document.getElementById(panelid+"_"+all[allpos[i]]);
			x_webpos = WebForm_GetElementPosition(elem);
			all_h += x_webpos.height;
		}
	}
	document.getElementById(panelid).style.height=all_h;
	setW(panelid);
}
function moveToPos(oldxid,x) {
	if (getPos(oldxid) != x) {
		a = document.getElementsByName(panelid+'_pos');
		ids = new Array();
		yids = new Array();
		oldx = 0;
		xid = 0;
		max = 0;
		for (i=0;i<a.length;i++) {
			id = a[i].id.replace('pos', '');
			ids[a[i].value] = id;
			if (id==oldxid) {
				oldx = a[i].value;
			} else if (a[i].value==x) {
				xid = id;
			}
			max++;
		}
		if (oldx) {
			if (oldx<x) {
				for (i=x;i>oldx;i--) {
					if (ids[i]) yids[yids.length] = ids[i];
				}
				elem = document.getElementById(oldxid);
				oldx_webpos = WebForm_GetElementPosition(elem);
				oldx_h = oldx_webpos.height;
				for (i=0;i<yids.length;i++) {
					marginTo(yids[i],(elem.style.marginTop+oldx_h));
				}
				x_h = 0;
				for (i=(x+1);i<=max;i++) {
					if (ids[i]!=oldxid && ids[i]) {
						elem = document.getElementById(ids[i]);
						x_webpos = WebForm_GetElementPosition(elem);
						x_h += x_webpos.height;
					}
				}
				marginTo(oldxid,x_h);
				setPos(oldxid,x);
				for (i=0;i<yids.length;i++) {
					ypos = getPos(yids[i]);
					setPos(yids[i],parseInt(ypos)+1);
				}
			} else if (oldx>x) {
				for (i=x;i<oldx;i++) {
					if (ids[i]) yids[yids.length] = ids[i];
				}
				elem = document.getElementById(oldxid);
				oldx_webpos = WebForm_GetElementPosition(elem);
				oldx_h = oldx_webpos.height;
				for (i=0;i<yids.length;i++) {
					marginTo(yids[i],(elem.style.marginTop-oldx_h));
				}
				x_h = 0;
				for (i=x;i<=max;i++) {
					if (ids[i]!=oldxid && ids[i]) {
						elem = document.getElementById(ids[i]);
						x_webpos = WebForm_GetElementPosition(elem);
						x_h += x_webpos.height;
					}
				}
				marginTo(oldxid,x_h);
				setPos(oldxid,x);
				for (i=0;i<yids.length;i++) {
					ypos = getPos(yids[i]);
					setPos(yids[i],parseInt(ypos)-1);
				}
			}
		} else alert('error');
	}
}

function ifenter(evt) {
	if (evt) {
		charCode = (evt.charCode) ? evt.charCode :
                   ((evt.keyCode) ? evt.keyCode :
                   ((evt.which) ? evt.which : 0)); 
        //alert(charCode);
        if (charCode==13) return 1;
	}
}

function hideAllHB(name,id) {
	a = document.getElementsByName(name+'_'+id);
	if (a) {
		for (i=0;i<a.length;i++) {
			a[i].style.display = 'none';
		}
	}
}

function WinDiv(url, width, height){
	var resx=screen.availWidth, resy=screen.availHeight;
	var tp=Math.floor((resy-height-20)/2);tp=(tp<0)?0:tp;
	var lt=Math.floor((resx-width-10)/2);lt=(lt<0)?0:lt;
	
	if(height>resx || width>resx){
	height=resy-80
	width=resx-60;
	}
	
	$(document.body).append($("<div id='windiv' style='position:absolute;width:"+width+";height:"+height+";top:"+tp+";left:"+lt+";'><iframe src='"+url+"'></iframe></div>"));
//	$.get(url, function(data){
//		$('#windiv').html("<frame>"+data+"</frame>");
//	});
}

function xbyid(id) {
	nnn = document.getElementById(id);
	p_webpos = WebForm_GetElementPosition(nnn);
	return p_webpos.x;
}
function ybyid(id) {
	nnn = document.getElementById(id);
	p_webpos = WebForm_GetElementPosition(nnn);
	return p_webpos.y;
}

function WebForm_GetElementPosition(element) {
var result = new Object();
result.x = 0;
result.y = 0;
result.width = 0;
result.height = 0;
if (element.offsetParent) {
result.x = element.offsetLeft;
result.y = element.offsetTop;
var parent = element.offsetParent;
while (parent) {
result.x += parent.offsetLeft;
result.y += parent.offsetTop;
var parentTagName = parent.tagName.toLowerCase();
if (parentTagName != "table" &&
parentTagName != "body" &&
parentTagName != "html" &&
parentTagName != "div" &&
parent.clientTop &&
parent.clientLeft) {
result.x += parent.clientLeft;
result.y += parent.clientTop;
}
parent = parent.offsetParent;
}
}
else if (element.left && element.top) {
result.x = element.left;
result.y = element.top;
}
else {
if (element.x) {
result.x = element.x;
}
if (element.y) {
result.y = element.y;
}
}
if (element.offsetWidth && element.offsetHeight) {
result.width = element.offsetWidth;
result.height = element.offsetHeight;
}
else if (element.style && element.style.pixelWidth && element.style.pixelHeight) {
result.width = element.style.pixelWidth;
result.height = element.style.pixelHeight;
}
return result;
}

///COLORED

idt=0;
//dt=new Array("rgb(43, 88, 122)", "rgb(43, 88, 122)", "rgb(43, 88, 122)", "rgb(43, 88, 122)", "rgb(64, 96, 110)", "rgb(85, 104, 98)", "rgb(106, 113, 86)", "rgb(127, 122, 74)", "rgb(148, 130, 62)", "rgb(169, 138, 50)", "rgb(190, 146, 38)", "rgb(211, 154, 25)", "rgb(232, 162, 13)", "rgb(254, 171, 0)", "rgb(254, 171, 0)", "rgb(254, 171, 0)", "rgb(254, 171, 0)", "rgb(254, 171, 0)", "rgb(232, 162, 13)", "rgb(211, 154, 25)", "rgb(190, 146, 38)", "rgb(169, 138, 50)", "rgb(148, 130, 62)", "rgb(127, 122, 74)", "rgb(106, 113, 86)", "rgb(85, 104, 98)", "rgb(64, 96, 110)", "rgb(43, 88, 122)", "rgb(43, 88, 122)", "rgb(43, 88, 122)", "rgb(43, 88, 122)");
dt=new Array("#2B587A", "#2B5884", "#2B588d", "#2B5897", "#2B58a1", "#2B58ab", "#2B58b2", "#2B58ba", "#2B58bc",
"#2B58d8", "#2B58e1", "#2B58d8", "#2B58bc", "#2B58ba", "#2B58b2", "#2B58ab", "#2B58a1", "#2B5897",
"#2B588d", "#2B5884", "#2B587A",
"#2B587A", "#2B6183", "#2B698b", "#2B7294", "#2B7a9c", "#2B83a5", "#2B8bad", "#2B94b7", "#2B9cbf",
"#2B94b7", "#2B8bad", "#2B83a5", "#2B7a9c", "#2B7294", "#2B698b", "#2B6183", "#2B587A");
function colored() {
	coloredall = document.getElementsByName('colored');
	idt++;
	for(i=0;i<coloredall.length;i++) {
		coloredall[i].style.color = dt[idt];
	}
	if (idt>=(dt.length-1)) idt=0;
	setTimeout("colored()",30);
}

//--------

function centerdiv(url) {
	all = document.getElementsByName('main');
	for(i=0;i<all.length;i++) {
		if (all[i]) all[i].parentNode.removeChild(all[i]);
	}
	all = document.getElementsByName('centerdiv');
	for(i=0;i<all.length;i++) {
		if (all[i]) all[i].parentNode.removeChild(all[i]);
	}
	$("body").append('<div style="display:none;" class="bgimg" name="centerdiv" id="centerdiv_bgr"></div>');
	$('#centerdiv_bgr').fadeIn('side',function(){
		$.get(url,function(data){
			$("body").append('<div style="display:none;" class="main" id="centerdiv" name="centerdiv">'+data+'</div>');
			$('#centerdiv').show();
			MoveCenterScreen('centerdiv');
		});
	});
}
function centerdiv2(url) {
	all = document.getElementsByName('main');
	for(i=0;i<all.length;i++) {
		if (all[i]) all[i].parentNode.removeChild(all[i]);
	}
	all = document.getElementsByName('centerdiv2');
	for(i=0;i<all.length;i++) {
		if (all[i]) all[i].parentNode.removeChild(all[i]);
	}
	$("body").append('<div style="display:none;" class="bgimg" name="centerdiv2" id="centerdiv2_bgr"></div>');
	$('#centerdiv2_bgr').fadeIn('side',function(){
		$.get(url,function(data){
			$("body").append('<div style="display:none;" class="main" id="centerdiv2" name="centerdiv2">'+data+'</div>');
			$('#centerdiv2').show();
			MoveCenterScreen('centerdiv2');
		});
	});
}
function topcenterdiv(url) {
	all = document.getElementsByName('main');
	for(i=0;i<all.length;i++) {
		if (all[i]) all[i].parentNode.removeChild(all[i]);
	}
	all = document.getElementsByName('centerdiv');
	for(i=0;i<all.length;i++) {
		if (all[i]) all[i].parentNode.removeChild(all[i]);
	}
	$("body").append('<div style="display:none;" class="bgimg" name="centerdiv" id="centerdiv_bgr"></div>');
	$('#centerdiv_bgr').fadeIn('side',function(){
		$.get(url,function(data){
			$("body").append('<div style="display:none;" class="main" id="centerdiv" name="centerdiv">'+data+'</div>');
			$('#centerdiv').show();
			MoveCenterScreen_top('centerdiv');
		});
	});
}
function closealldivcenter() {
	all2 = document.getElementsByName('centerdiv2');
	for(i=0;i<all2.length;i++) {
		if (all2[i]) $(all2[i]).fadeOut('side',function(){
			$("[name='centerdiv2']").remove();
		});
	}
	if (!all2[0]) {
		all = document.getElementsByName('centerdiv');
		for(i=0;i<all.length;i++) {
			if (all[i]) $(all[i]).fadeOut('side',function(){
				$("[name='centerdiv']").remove();
			});
		}
	}
}
function MoveCenterScreen(objID) 
{ 
var innerHeight_ = window.innerHeight ? window.innerHeight : document.documentElement.offsetHeight; 
var obj = document.getElementById(objID);
obj.style.left = (document.body.clientWidth/2 - obj.clientWidth/2 + document.body.scrollLeft - 15) + 'px'; 
obj.style.top = (document.documentElement.scrollTop + innerHeight_ / 2 - obj.clientHeight / 2 + document.body.scrollTop) + 'px'; 
}
function MoveCenterScreen_top(objID) 
{ 
var innerHeight_ = window.innerHeight ? window.innerHeight : document.documentElement.offsetHeight; 
var obj = document.getElementById(objID);
obj.style.left = (document.body.clientWidth/2 - obj.clientWidth/2 + document.body.scrollLeft - 15) + 'px'; 
obj.style.top = (document.documentElement.scrollTop + innerHeight_ / 6 - obj.clientHeight / 2 + document.body.scrollTop) + 'px'; 
}