<!--
function arrayUnique(a) {
	tmp = new Array(0);
	for(i=0;i<a.length;i++){
		if(!contains(tmp, a[i])){
			tmp.length+=1;
			tmp[tmp.length-1]=a[i];
		}
	}
	return tmp;
}
function arrayContains(a, e) {
	for(j=0;j<a.length;j++)if(a[j]==e)return true;
	return false;
}




function expand(o){
	if(o.style.display == 'none'){
		o.style.display = '';
	}else{
		o.style.display = 'none';
	}
}

function disable(o){
	if(o.disabled == true){
		o.disabled = false;
	}else{
		o.disabled = true;
	}
}

function openWin(page, wname, width, height)
{
Win=open('', wname,'toolbar=no,scrollbars=yes,status=yes,resizable=yes,height='+height+',width='+width);

if (!(Win.sms)){
                                if(!width) width=420;
                                if(!height) height=200;
                                Win=open(page, wname,   'toolbar=no,scrollbars=yes,status=yes,height='+height+',width='+width);
                                Win.focus();
                                }
}
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

///////////////// New DOM model /////////////////////

function delEntry(id, sk){
	if(confirm("Вы действительно хотите удалить эту запись?")){
		$('<iframe></iframe').attr('src', "/bgscript/delete_entry.html?id="+id+"&sk="+sk).appendTo('body');
	}else{
		alert("Не хотите, как хотите...");
	}
}

function favorites(eid, sk, act, del_cont){
	//common.window.location.href="/bgscript/favorites.html?id="+id+"&sk="+sk^;
	setWaitDialog(true, "Редактируем избранное");
	doLoadParser(true, 
		{'eid': eid, 'sk': sk, 'act' : act},
		'/bgscript/favorites.html', 
		function(debug,res){ 
			var sp = document.getElementById('favor'+eid);
			sp.removeChild(sp.childNodes[0]);
			act = act=='add'?'del':'add';
			var lab = act=='add'?'Добавить в избранное':'Удалить из избранного';
			sp.appendChild(document.createTextNode(lab));
			sp.setAttribute('href', "JavaScript: favorites("+eid+", '"+sk+"', '"+act+"', "+del_cont+")");
			
			if(del_cont){
				var cont = document.getElementById("entry_cont_"+eid);
				cont.style.display='none';
			}
			if(act == 'add'){ // act was changed above, so 'add' in this case means 'del'
				var elm_array=document.getElementsByTagName("span");
				for(var i = 0; i < elm_array.length; i++){
					if(elm_array[i].getAttribute("idgroup") == "entry_cnt"){
						var counter_div = elm_array[i];
						counter_div.innerHTML = parseInt(counter_div.childNodes[0].data)-1;
					}
				}
			}
			setWaitDialog(false);
		}
	);
}


function unsubscribe(eid, sk){
	if(confirm('Вы более не хотите получать извещения в системном логе о комментариях к этой записи?')){
		setWaitDialog(true, "Отписка от сообщения");
		doLoadParser(true, 
			{'eid': eid, 'sk': sk}, 
			'/bgscript/unsubscr_entry.html', 
			function(debug,res){ 
				var sp = document.getElementById('subscribe'+eid);
				sp.removeChild(sp.childNodes[0]);
				sp.appendChild(document.createTextNode("Подписаться"));
				sp.setAttribute('href', "JavaScript: subscribe("+eid+", '"+sk+"')");
				setWaitDialog(false);
			}
		);
		
	}
}
function subscribe(eid, sk){
	if(confirm('Вы хотите получать извещения в системном логе о комментариях к этой записи?')){
		setWaitDialog(true, "Подписка на сообщение");
		doLoadParser(true, 
			{'eid': eid, 'sk': sk}, 
			'/bgscript/subscr_entry.html', 
			function(debug,res){ 
				var sp = document.getElementById('subscribe'+eid);
				sp.removeChild(sp.childNodes[0]);
				sp.appendChild(document.createTextNode("Отписаться"));
				sp.setAttribute('href', "JavaScript: unsubscribe("+eid+", '"+sk+"')");
				setWaitDialog(false);
			}
		);
	}
}

function friendAuthreq(fuid, sk){
	var ifr = createIframe();
	ifr.setAttribute('src', "/bgscript/friend_authreq.html?fuid="+fuid+"&sk="+sk);
}

function notYourFriend(fuid, sk){
	var ifr = createIframe();
	ifr.setAttribute('src', "/bgscript/friend_delref.html?fuid="+fuid+"&sk="+sk);
}

function friendDel(fuid, sk){
	var ifr = createIframe();
	ifr.setAttribute('src', "/bgscript/friend_del.html?fuid="+fuid+"&sk="+sk);
}

function friendAcceptreq(fuid, sk){
	var ifr = createIframe();
	ifr.setAttribute('src', "/bgscript/friend_acceptreq.html?fuid="+fuid+"&sk="+sk);
}

function log_in(){
	var af = document.getElementById('auth_form');
	doLoadParser(true, 
		{'login': af.login.value, 'password': af.password.value, 'secure': af.secure.checked?1:0}, 
		'/auth/login_ajax.html', 
		function(debug,res){ 
			if(res.ok == 1){
			    window.location.reload();
			}else{
				alert(res.error);
			}
		}
	);
	return false;
}

function doLoadParser(force, data, backend_uri, ok_func) {
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			if (req.responseJS) {
				//alert(req.responseJS.ok);
				ok_func(req.responseText, req.responseJS);
			}
			//alert(req.responseText);
		}
	}
	req.caching = false;
	req.open('POST', backend_uri, true);
	req.send( data );
}

function setWaitDialog(sw, msg){
	var dlg = document.getElementById('waitDialog');
	if(sw){
		dlg.style.display = '';
		var textNode = dlg.childNodes[1];
		if(textNode.childNodes[0] != null) textNode.removeChild(textNode.childNodes[0]);
		textNode.appendChild(document.createTextNode(msg));
		moveWaitDialog();
	}else{
		dlg.style.display = 'none';
	}
}

function moveWaitDialog(){
	var height = (document.all) ? document.body.clientHeight : window.innerHeight;
	var width  = (document.all) ? document.body.clientWidth : window.innerWidth;
	var myScroll = (document.all) ? document.body.scrollTop : window.pageYOffset;
	objCSS = document.getElementById('waitDialog');
	oldtop = parseFloat(objCSS.style.top);
	if (oldtop){}else{oldtop = 0;}
	newtop = (height/2-50 + myScroll);
	objCSS.style.top = Math.round(newtop - (newtop - oldtop) * 0.8);
	objCSS.style.left = width/2-100;
	if(objCSS.style.display == 'none') return;
	setTimeout("moveWaitDialog()",80);
	return;
}

function createIframe(){
	var ifr = document.createElement('iframe');
	document.getElementsByTagName('body')[0].appendChild(ifr);
	ifr.style.display="none";
	return ifr;
}

function incEntryCounter(){
	modifyEntryCounter(1)
}
function decEntryCounter(){
	modifyEntryCounter(-1)
}

function modifyEntryCounter(value){
	var counter_div=document.getElementById("entry_cnt");
	if(counter_div){
		counter_div.innerHTML = parseInt(counter_div.childNodes[0].data)+value;
	}
}

//-->