function _navigate(url){
	window.location=url;
}

function new_navigate(url){
	nw=open(url);
}

function get_ajax(url){
	if (window.XMLHttpRequest) {
		var xmlhttp = new XMLHttpRequest();
	}else{
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.open("GET", "http://"+document.location.host+url, false);
	xmlhttp.send("request");
	return xmlhttp.responseText;
}

function clickact(id){
	i=document.getElementById("acts"+id);
	window.location=i.value;
}

function actions(id,acts){
	var a,i;
	a=acts.split("\n");
	document.write("<select id=\"acts"+id+"\" style=\"font-size:8pt\">");
	for(i=0;i<a.length;i++){
		b=a[i].split("\t");
		document.write("<option value=\""+b[0]+"\">"+b[1]+"</option>");
	}
	document.write("</select>&nbsp;");
	document.write("<input type=\"button\" value=\" Go \" onclick=\"clickact("+id+")\">");
}


function askform(text,id){
	if(confirm(text)){
		f=document.getElementById(id);
		f.submit();
	}
}

function askkill(id){
	f=document.getElementById(id);
	if(confirm("Удалить выбранные элементы?")){
		f.submit();
	}
}

function submitform(el,id){
	el.disabled=true;
	f=document.getElementById(id);
	f.contentEditable=false;
	f.submit();
}

function askdo(text,url){
	if(confirm(text)){
		_navigate(url);
	}
}

function view_topics(){
	l=document.getElementById("topiclist");
	list=l.value;

	v=document.getElementById("topicview");
	txt=get_ajax("/blog-listtopics/?list="+list);
	v.innerHTML=txt;
}

function add_topiclist(id){
	l=document.getElementById("topiclist");
	list=l.value;
	txt=get_ajax("/blog-addlist/?list="+list+"&id="+id);
	l.value=txt;

	view_topics();
}

function add_topic(){
	h=document.getElementById("id_topic_hint");
	topic=h.value;
	txt=get_ajax("/blog-topicinfo/?topic="+escape(h.value));
	x=txt.split("|");
	if(x[0]=="0"){
		if(!confirm("Эта тема еще не была использована в других блогах.\r\nВы уверены, что список тем не содержит подходящей темы и поэтому нужно создать новую?\r\nЕсли нет, то попытайтесь поискать подходящую тему в подборе, используя другие ключевые слова.")) return;
	}
	txt=get_ajax("/blog-gettopic/?topic="+escape(h.value));
	x=txt.split("|");
	if(x[0]=="1"){
		topic_id=x[1];
		add_topiclist(topic_id);
		h.value="";
	}else{
		alert("Ошибка при выборе темы!");
	}
}

function remove_topic(id){
	if(!confirm("Исключить тему из списка тем этой заметки?")) return;
	l=document.getElementById("topiclist");
	list=l.value;
	txt=get_ajax("/blog-removelist/?list="+list+"&id="+id);
	l.value=txt;

	view_topics();
}

function topic_hint_do(){
	h=document.getElementById("id_topic_hint");
	topic=h.value;
	txt=get_ajax("/blog-topichint/?topic="+escape(h.value));

	hd=document.getElementById("topichint");
	hd.innerHTML=txt;
}

var thtime;

function topic_hint(){
	clearTimeout(thtime);
	thtime=setTimeout("topic_hint_do()",1000);
}

function pick_topic(txt){
	h=document.getElementById("id_topic_hint");
	h.value=txt;
}

