temp=new Array();
temp['cache']=new Array();
temp['q']=new Array();
temp['estrs']=new Array();
temp['sb']=false;
temp['curestrno']=0;
previousquery=false;
block=false;
blink=false;
hiding=new Array();
usecolor=false;

function xhttpconnect() {
xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}
}

function updatePage() {
  xmlHttp.readyState == 4 ? response=xmlHttp.responseText : null;
}
function getby(id) {
return document.getElementById(id);
}
function xhttpquery(query) {
xhttpconnect();
xmlHttp.open('post',url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", query.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(query);
}

// AJAX
function ajax_auth(act) {
dark();
if (act==1) xhttpquery('auth=true&login='+document.forms.login.elements.login.value+'&pass='+document.forms.login.elements.pass.value);
if (act==0) xhttpquery('act=logout');
xmlHttp.onreadystatechange = function() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
	getcontent('act=index&getsidebar=true');
	}
	}
dark();
}

function addcomment(postid) {
var form=document.forms.commentform.elements
var query="act=admin&ajax=true&q=add&type=comment&postid="+postid+"&comment="+form.comment.value
if (form.author.value!='false') xhttpquery(query+"&registered=true");
if (form.author.value=='false') xhttpquery(query+"&registered=false&name="+form.name.value+"&email="+form.email.value+"&url="+form.url.value);
xmlHttp.onreadystatechange = function() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
	getby('commentlist').innerHTML+=xmlHttp.responseText;
	form.comment.value='';
	if (getby('comments_num').innerHTML=='0') getby('commentlist').style.display='block';
	getby('comments_num').innerHTML++;
	}
	}
}

function ajax_changeset(n,v,i) {
var query="act=admin&ajax=true&q=changeset&name="+n+"&value="+v;
xhttpquery(query);
}

function ajax_deleting(id,next,what) {
dark();
if (!next) next=false;
xhttpquery("act=admin&ajax=true&q=delete&type="+what+"&id="+id);
xmlHttp.onreadystatechange = function() {
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		if (next) getcontent('act=index');
	}
	}
if (what=='page') setTimeout("window.location=window.location",750);
if (!next && what=='post') {
if (getby('post-row-'+id)) getby('post-row-'+id).style.display='none';
if (getby('post-space-'+id)) getby('post-space-'+id).style.innerHTML='none';
if (getby('post-row2-'+id)) {getby('post-row2-'+id).style.display='none';
getby('post-row2-'+id).style.innerHTML='none';}
if (getby('latest-title-'+id)) {getby('latest-title-'+id).style.display='none';
getby('latest-title-'+id).style.innerHTML='none';}
xmlHttp.onreadystatechange = function() {
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) getcontent('act=index');}
}
if (what=='link') getby('blogroll-link-id-'+id).style.display='none';
if (what=='comment') {
	getby('comm-'+id).style.display='none';
	getby('comments_num').innerHTML--;
	getby('comm-'+id).innerHTML='';
	if (getby('comments_num').innerHTML=='0') getby('commentlist').style.display='none';
	}
dark();
}
function ajax_deletepost(id, next) {
ajax_deleting(id,next,'post');
}
function ajax_deletelink(id) {
ajax_deleting(id,null,'link');
}
function ajax_deletecomment(id) {
ajax_deleting(id,null,'comment');
}

function getcontent(what) {
if (typeof temp['q'][what]=='undefined' || !temp['q'][what]) temp['q'][what]=true;
	if (typeof temp['n4sb']!='undefined') {getby('sidebar').innerHTML=temp['cache']['sidebar'];delete temp['cache']['sidebar'];delete temp['n4sb'];};
	if (what.indexOf('&post')>0 || what.indexOf('stamp')>-1) {temp['cache']['sidebar']=getby('sidebar').innerHTML;temp['n4sb']=true;what+='&getsidebar=true';};
	if (!block) {
	if (typeof temp['cache'][what]=='undefined') {
	delete temp['cache'][previousquery];
	temp['cache'][what]=true;
	previousquery=what;
	setTimeout("if (typeof temp['cache']['"+what+"']!='undefined') delete temp['cache']['"+what+"']",3000);
	dark();
	xhttpquery('contentonly=true&'+what);
	xmlHttp.onreadystatechange = function() {
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		updatePage();
		if (what.indexOf('getsidebar')>0) {getby('general').innerHTML="<div id='content'>"+response;initsb();}else{getby('content').innerHTML=response;};dark();
		}
	}
	}
	}
	}

function startedit(id) {
if (typeof temp['edit-'+id]=='undefined') {
temp['edit-'+id]=0;
xhttpquery('ajax=true&act=admin&q=edit&type=post&id='+id);
xmlHttp.onreadystatechange = function() {
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		updatePage();
		if (getby('entry-titlelink-'+id)) getby('entry-titlelink-'+id).rel='temp';
		getby('entry-body-'+id).innerHTML=response;
		getby('entry-title-'+id).innerHTML="<input type='text' value='"+getby('entry-title-'+id).innerHTML+"' class='postformfield entrytitle' id='title-area-"+id+"'/>";
		getby('post-time-'+id).innerHTML="<input type='text' value='"+getby('post-time-'+id).innerHTML+"' id='posttime-area-"+id+"' class='posttime'/>  <a href='javascript://' onclick='checkposttimeformat("+id+");'>[?]</a>";
		temp['edit-'+id]++;
		block=true;
		getby('entry-edit-'+id).focus();}
		}
		return true;
		}
if (typeof temp['edit-'+id]!='undefined' && temp['edit-'+id]>0) {
xhttpquery('ajax=true&act=admin&q=edit&type=post&id='+id+'&posttime='+getby('posttime-area-'+id).value+'&title='+getby('title-area-'+id).value+'&text='+getby('entry-edit-'+id).value);
xmlHttp.onreadystatechange = function() {
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		updatePage();
		getby('entry-body-'+id).innerHTML=response;
		getby('entry-title-'+id).innerHTML=getby('title-area-'+id).value;
		getby('post-time-'+id).innerHTML=getby('posttime-area-'+id).value;
		if (getby('entry-titlelink-'+id)) getby('entry-titlelink-'+id).rel='bookmark';
		delete temp['edit-'+id];
		block=false;
		}
		}
		return false;
}
}

function sendprofileinfo() {
var f=document.forms.profile.elements;
xhttpquery('act=account&q=edit&type=profile&publish=true&adm[nickname]='+f.adm_nickname.value+'&adm[email]='+f.adm_email.value+'&adm[url]='+f.adm_url.value+'&pass[0]='+f.pass0.value+'&pass[1]='+f.pass1.value);
xmlHttp.onreadystatechange = function() {
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		getcontent('act=account&q=edit&type=profile');
	}
	}
}

function showhide(id) {
if (getby(id).style.display!='none') {temp['sb']=false;getby(id).style.display='none';} else {if (getby(temp['sb']) && temp['sb']!=id) getby(temp['sb']).style.display='none';getby(id).style.display='block';if (id!=temp['sb']) temp['sb']=id;};
}
function expand(id) {
temp[id]=1;
getby(id).style.display!='block' ? setTimeout("showhide('"+id+"');",180) : null;
}
function hide(id) {
temp[id]=0;
typeof getby('"+id+"')!='undefined' ? hiding[id]=setInterval("getby('"+id+"') && getby('"+id+"').style.display!='none' && temp['"+id+"']==0 ? {showhide('"+id+"');clearInterval("+hiding[id]+");} : null;",660) : null;
}
function clrint() {clearInterval(hiding);}
function div2field(id) {
getby('br-link-'+id).innerHTML='<input type="text" id="field-br-link-'+id+'" value="'+getby('br-link-'+id).innerHTML+'" onmouseover="temp[&quot;cache-'+id+'&quot;]=true;" onmouseout="temp[&quot;cache-'+id+'&quot;]=false;"/>';
getby('link-text-'+id).innerHTML='<input type="text" id="field-link-text-'+id+'" value="'+getby('link-text-'+id).innerHTML+'" onmouseover="temp[&quot;cache-'+id+'&quot;]=true;" onmouseout="temp[&quot;cache-'+id+'&quot;]=false;"/>';
getby('link-title-'+id).innerHTML='<input type="text" id="field-link-title-'+id+'" value="'+getby('link-title-'+id).innerHTML+'" onmouseover="temp[&quot;cache-'+id+'&quot;]=true;" onmouseout="temp[&quot;cache-'+id+'&quot;]=false;"/>';
}
function field2div(id) {
getby('br-link-'+id).innerHTML=getby('field-br-link-'+id).value;
getby('link-text-'+id).innerHTML=getby('field-link-text-'+id).value;
getby('link-title-'+id).innerHTML=getby('field-link-title-'+id).value;
delete temp['cache-'+id];
}
/* Checkings */
function checkcommentform() {
var form=document.forms.commentform.elements
document.forms.commentform.elements.comment.value!='' ? form.submitbutt.disabled=false : form.submitbutt.disabled=true;
}
function checkposttimeformat(id) {
xhttpquery('act=admin&ajax=true&q=posttimecheck&posttime='+getby('posttime-area-'+id).value);
xmlHttp.onreadystatechange = function() {
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		updatePage();
		if (response=='1') {getby('posttime-area-'+id).className='correctvalue';ptv=true;} else {
			getby('posttime-area-'+id).className='incorrectvalue';ptv=false;}
	}
	}
}

function get_set_module(k) {
xhttpquery('act=admin&ajax=true&q='+k+'&type=set');
xmlHttp.onreadystatechange = function() {
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {updatePage();showhide(k+'_area');getby(k+'_area').innerHTML=response;
}}}
	function unset_module(k,d) {
	xhttpquery('act=admin&ajax=true&q='+k+'&type=save&'+d);showhide(k+'_area');
	}
/* Other */
function mozWrap(ta, open, close) {
	var selLength = ta.textLength;
	var selStart = ta.selectionStart;
	var selEnd = ta.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;

	var s1=(ta.value).substring(0,selStart);
	var s2=(ta.value).substring(selStart, selEnd)
	var s3=(ta.value).substring(selEnd, selLength);
	ta.value=s1+open+s2+close+s3;
	return;
}
function dark() {
var mydiv=getby("wall");
mydiv.style.display=="none" ? mydiv.style.display="block" : mydiv.style.display="none";
}
function undisplay(id) {
getby(id) ? getby(id).style.display='none' : null;
}

function initsb() {
undisplay('feeds');
undisplay('optslist');
undisplay('blogroll');
undisplay('lastentries');
undisplay('metalinks');
undisplay('profilebar');
undisplay('admbar');
}