// Обработчик для select и нажатия на кнопку
var forum_cur_id = 0;
var forum_item = '';
var forum_form_add   = '';
var forum_form_fombj = '';

function forum_insert_quote(nick){
	selected = '';	if (typeof window.getSelection != "undefined") {
		// Ветка для Gecko-браузеров
		selected = window.getSelection();

		//var
		selRange = selected.getRangeAt(0);
        selected = selRange.toString();
		//var obj = document.createElement("div");
		//obj.innerHTML = '<b>' + selRange.toString() + '</b>';
		//obj.style.display = 'inline';

		//selRange.deleteContents();
		//selRange.insertNode(obj);
	}
	else {
		// Ветка для IE
		selected = document.selection.createRange();
		selected = selected.text;
		//selected.text = '<b>' + selected.text + '</b>';
	}
	selected = '[quote=' + nick + ']' + selected + '[/quote]';
	obj = document.getElementById('comments');
	if (obj!=null) obj.value = obj.value + selected + "\n";
}

function forum_add_topic(){	if (init_ajax()==false) return;
	// Адрес скрипта обрабатывающего запросы
	url="/sources/forum/forum_ajax.php";
	//url=url+"?act=add&sid="+Math.random()
	par = "act=add_topic&sid="+Math.random();
    collect_data();
	//url = url+"&"+parr
	par = par+"&"+parr
	xmlHttp.onreadystatechange=sc_forum_add_topic;
    //document.getElementById("forum_but_add").disabled=true;
    $("forum_add_result").innerHTML='';
    $("forum_dbut").style.display = 'none';
    $("forum_loader").style.display = 'block';
    //alert(url)
    //alert(par)
	ajax_send_post(url,par);
	return
}

function forum_add_replay(){
	if (init_ajax()==false) return;
	// Адрес скрипта обрабатывающего запросы
	url="/sources/forum/forum_ajax.php";
	//url=url+"?act=add&sid="+Math.random()
	par = "act=add_replay&sid="+Math.random();
    collect_data();
	//url = url+"&"+parr
	par = par+"&"+parr
	xmlHttp.onreadystatechange=sc_forum_add_replay;
    //document.getElementById("forum_but_add").disabled=true;
    $("forum_add_result").innerHTML='';
    $("forum_dbut").style.display = 'none';
    $("forum_loader").style.display = 'block';
    //alert(par)
	ajax_send_post(url,par);
	return
}

function forum_save(id){
	if (init_ajax()==false) return;
	//forum_cur_id = id;
	// Адрес скрипта обрабатывающего запросы
	url="/sources/forum/forum_ajax.php";
	par = "act=save&sid="+Math.random();
    collect_data();
	par = par+"&"+parr
	xmlHttp.onreadystatechange=sc_forum_save
    //$("forum_add_result").innerHTML='';
    $("forum_dbut").style.display = 'none';
    $("forum_loader").style.display = 'block';
	//alert(par);
	ajax_send_post(url,par);
	return
}

function forum_edit_mess(id){
	if (init_ajax()==false) return;
	forum_cur_id = id;
	url="/sources/forum/forum_ajax.php"
	url=url+"?act=edit&id="+id+"&sid="+Math.random()
	xmlHttp.onreadystatechange=sc_forum_edit_mess
	//alert(url);
	ajax_send(url);
	return
}

function sc_forum_edit_mess(){	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		// Получаем данные, что вернул скрипт
		text = xmlHttp.responseText;
		//text_v = text.split('|');
		forum_item = "forum_message_"+forum_cur_id;
		document.getElementById(forum_item).innerHTML=text;
		forum_form_fombj = fombj;
		fombj = document.getElementById('forum_form_edit');
		obj = document.getElementById('forum_div_add');
		if (obj!=null){
			forum_form_add = obj.innerHTML;
			obj.innerHTML = '';
		}
	}
}

function sc_forum_add_topic(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		// Получаем данные, что вернул скрипт
		text = xmlHttp.responseText
		//alert(text)
		text_v = text.split('|');
		// Заполняем подчиненый селект
	    //document.getElementById("forum_add_result").innerHTML=text_v[1];
		if (text_v[0]=='success'){
		    document.getElementById("forum_div_add").innerHTML=text_v[1]
			url = text_v[2];
			//alert(text);
			window.location=url;
			//document.getElementById("add_from").innerHTML=''
		}
		else{
		    document.getElementById("forum_add_result").innerHTML=text_v[1]
		    document.getElementById("forum_dbut").style.display = 'block';
		    document.getElementById("forum_loader").style.display = 'none';
		}
	}
}

function sc_forum_add_replay(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		// Получаем данные, что вернул скрипт
		text = xmlHttp.responseText
		//alert(text)
		text_v = text.split('|');
		// Заполняем подчиненый селект
	    //document.getElementById("forum_add_result").innerHTML=text_v[1]
		if (text_v[0]=='success'){
		    document.getElementById("forum_div_add").innerHTML=text_v[1]
			url = text_v[2];
			//alert(text);
			//alert(url);
			window.location=url;
			//document.getElementById("add_from").innerHTML=''
		}
		else{
		    document.getElementById("forum_add_result").innerHTML=text_v[1]
		    document.getElementById("forum_dbut").style.display = 'block';
		    document.getElementById("forum_loader").style.display = 'none';
		}
	}
}

function sc_forum_save(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		text = xmlHttp.responseText
		forum_item = "forum_message_"+forum_cur_id;
	    document.getElementById(forum_item).innerHTML=text
   		obj = document.getElementById('forum_div_add');
		if (obj!=null){
			//alert(forum_form_fombj.id)
			obj.innerHTML = forum_form_add;
			fombj = document.getElementById(forum_form_fombj.id);
			//fombj = forum_form_fombj;
			forum_form_add = '';
		}
	}
}


