var tmid;
var tmid2;
var scrltp;
dom = (document.getElementById) ? 1 : 0;
ie = (navigator.appName != "Netscape" && document.all) ? 1 : 0;
opera = (navigator.appName == "Opera") ? 1 : 0;
netscape= (navigator.appName == "Netscape") ? 1 : 0;

var sPop2 = false;
var sPop1 = false;


function doLoad(layer,url) {

/*
    // Create new JsHttpRequest object.
    var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            // Write result to page element ($_RESULT become responseJS). 
            document.getElementById('layer').innerHTML = req.responseText;
            // Write debug information too (output become responseText).
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, url, true);
    // Send data to backend.
//    req.send( { q: value } );
*/
}

function wop(href, width, height)
{
var left=(window.screen.width-width)/2;
var top=(window.screen.height-height)/2;
r=window.open(href, '', 'toolbar=no, scrollbars=yes, menubar=no, directories=no, status=no, resizable=yes, width=' + width + ', height=' + height + ', left=' + left + ', top='+top);
return r;
}

function reload_blk_reports(offs)
{

    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('reports').innerHTML = req.responseText;
        }
    }

    req.open(null, '/ajax.php5?a=reload_blk_reports&offset='+offs, true);
	req.send();
//    req.send( { 'file': value } );


}

function blk_community_next(offs)
{
blk_community_prev(offs-40);
}
function blk_community_prev(offs)
{
    var req = new JsHttpRequest();
    req.onreadystatechange = function() {

        if (req.readyState == 4) {
            document.getElementById('community').innerHTML = req.responseText;
        }
    }

    req.open(null, '/ajax.php5?a=blk_community_prev&offset='+offs, true);
	req.send();

}

function do_vote()
{
   var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('vote').innerHTML = req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5', true);

    // Send whole form data to backend.
    req.send( { 'form': document.getElementById('vote_frm') } );

}

function voteres(id)
{
   var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('vote').innerHTML = req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5?a=voteres&id='+id, true);

    // Send whole form data to backend.
    req.send();

}

function forum_reply(id,replyto,quote)
{

   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('forum_reply_form').innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=forum_reply&id='+id+'&replyto='+replyto+'&quote='+quote, true);
    req.send();

}

function do_search_user(value)
{
   if(value.length>2)
	{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('user_search_results').innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=search_allnight_user', true);
    req.send( {srch: value} );
	}

}

function iPopMenu(url,width,height,scrl)
{
	scrltp=getScrollY(window);

	document.getElementById('popLayer').innerHTML='';
	document.getElementById('popLayer').style.display='none';
	document.getElementById('popLayer').style.visibility='hidden';

	document.getElementById('popLayer').style.overflow=(scrl)?'auto':'';

	

	resize_popup(width,height);
   var ppm = new JsHttpRequest();

    ppm.onreadystatechange = function() {
        if (ppm.readyState == 4) {
	document.getElementById('popLayer').innerHTML=ppm.responseText;

	if(ppm.responseJS)
	{
	if(ppm.responseJS.width&&ppm.responseJS.height) resize_popup(ppm.responseJS.width,ppm.responseJS.height);
	if(ppm.responseJS.scroll) document.getElementById('popLayer').style.overflow='auto';
	}
	




		document.getElementById('popLayer').style.display='inline';
		document.getElementById('popLayer').style.visibility='visible';

        }
    }
    ppm.open(null, url, true);
    ppm.send({q: 'a'});

}

function iPopMenu2(url,width,height,scrl)
{

	scrltp=getScrollY(window);

	document.getElementById('popLayer2').innerHTML='';
	document.getElementById('popLayer2').style.display='none';
	document.getElementById('popLayer2').style.visibility='hidden';

	document.getElementById('popLayer2').style.overflow=(scrl)?'auto':'';

	

	resize_popup2(width,height);
	show_popup2();
   var ppm = new JsHttpRequest();

    ppm.onreadystatechange = function() {
        if (ppm.readyState == 4) {

	document.getElementById('popLayer2').innerHTML=ppm.responseText;

	if(ppm.responseJS)
	{
	if(ppm.responseJS.width&&ppm.responseJS.height) resize_popup2(ppm.responseJS.width,ppm.responseJS.height);
	if(ppm.responseJS.scroll) document.getElementById('popLayer2').style.overflowY='scroll';

	}
	




		document.getElementById('popLayer2').style.display='inline';
		document.getElementById('popLayer2').style.visibility='visible';

        }
    }
    ppm.open(null, url, true);
    ppm.send({q: 'a'});


}


function resize_popup(width,height)
{
//		if(isNC4){
//			lr=layerFrom("popLayer",null)
//		}else{
//			lr=layer("popLayer",null)
//		}

	lr=layer('popLayer');


	lft=(getWindowWidth(false)/2)-width/2;
	tp=getScrollY()+(getWindowHeight(false)/2)-height/2;


	if(lft<0) lft=0;
	if(tp<0) tp=0;
	lr.moveTo(lft,tp);
	lar=document.getElementById('popLayer');

	if(opera||netscape) {width=width-20; height=height-20;}
	if(width<1) width=1;
	if(height<1) height=1;
	lar.style.width=width;
	lar.style.height=height;

}

function resize_popup2(width,height)
{
//		if(isNC4){
//			lr=layerFrom("popLayer",null)
//		}else{
//			lr=layer("popLayer",null)
//		}

	lr=layer('popLayer2');


	lft=(getWindowWidth(false)/2)-width/2;
	tp=getScrollY()+(getWindowHeight(false)/2)-height/2;


	if(lft<0) lft=0;
	if(tp<0) tp=0;
	lr.moveTo(lft,tp);
	lar=document.getElementById('popLayer2');

	if(opera||netscape) {width=width-20; height=height-20;}
	if(width<1) width=1;
	if(height<1) height=1;
	lar.style.width=width;
	lar.style.height=height;

}


function umenu(id)
{
iPopMenu('/ajax.php5?a=iPopup&mode=userinfo&id='+id,500,300,false);
}

function edit_msg(id)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('forum_reply_form').innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=forum_edit_msg&id='+id, true);
    req.send();

}

function delete_msg(id)
{

	if(!confirm('Действительно удалить сообщение?')) return false;
	
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('msg'+id).innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=forum_delete_msg&id='+id, true);
    req.send();

}

function reload_default_form(id)
{
   var rq = new JsHttpRequest();
	
    rq.onreadystatechange = function() {
        if (rq.readyState == 4) {
            document.getElementById('forum_reply_form').innerHTML = rq.responseText;
        }
    }
    rq.open(null, '/ajax.php5?a=reload_default_form&id='+id, true);
    rq.send();

}

function reload_default_community_form(id)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('community_post_form').innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=reload_default_community_form&id='+id, true);
    req.send();

}

function go_edit_forum_msg()
{
   var req = new JsHttpRequest();
   var id = document.getElementById('efm').id.value;

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {

//            document.getElementById('forum_reply_form').innerHTML= req.responseJS.rep;
	
            document.getElementById('forum_reply_form').innerHTML='';
		document.getElementById('msg'+id).innerHTML = req.responseText;
	    tmid=setTimeout("reload_default_form("+req.responseJS.rep+")",1);
//	    document.location='#msg'+id;


        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5', true);

    // Send whole form data to backend.
    req.send( { 'form': document.getElementById('efm') } );

}

function community_post(id)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('community_post_form').innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=community_post&id='+id, true);
    req.send();

}

function get_cut(mode,id)
{
	if(mode=='forum') reload_forum_message(id);
	if(mode=='community') reload_community_message(id);
	if(mode=='f_community') f_reload_community_message(id);
	if(mode=='comments') reload_comment(id);
	if(mode=='journals') reload_diary(id);
	if(mode=='album') reload_album(id);
	if(mode=='message') reload_pim(id);
	if(mode=='report') reload_report(id);
	if(mode=='party') reload_party(id);
	if(mode=='text') reload_text(id);
	if(mode=='news') reload_news(id);
}

function reload_album(id)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('alb'+id).innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=reload_album&id='+id, true);
    req.send();

}

function reload_pim(id)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('pm'+id).innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=reload_pim&id='+id, true);
    req.send();

}



function reload_diary(id)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('jr'+id).innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=reload_diary&id='+id, true);
    req.send();

}

function reload_comment(id)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('comment'+id).innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=reload_comment&id='+id, true);
    req.send();

}

function reload_forum_message(id)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('msg'+id).innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=reload_forum_msg&id='+id, true);
    req.send();

}

function reload_community_message(id)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('comr'+id).innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=reload_community_msg&id='+id, true);
    req.send();

}

function f_reload_community_message(id)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('comr'+id).innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=reload_community_msg&id='+id+'&mode=friends', true);
    req.send();

}


function edit_community_msg(id)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('community_post_form').innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=edit_community_msg_form&id='+id, true);
    req.send();

}

function community_edit_post_go()
{
   var req = new JsHttpRequest();
   var id = document.getElementById('ecm').id.value;

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {

		reload_default_community_form(req.responseJS.rep);
		document.getElementById('comr'+id).innerHTML=req.responseText;
//		document.location='#comr'+id;

        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5', true);

    // Send whole form data to backend.
    req.send( { 'form': document.getElementById('ecm') } );
	
}

function del_community_msg(id)
{
	if(!confirm('Действительно удалить сообщение?')) return false;
	
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('comr'+id).innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=community_delete_msg&id='+id, true);
    req.send();

}

function close_popup()
{
	lr=document.getElementById('popLayer');
	lr.style.display='none';
	lr.style.visibility='hidden';
	lr.innerHTML='';
}

function get_comments(id,mode)
{
	iPopMenu('/ajax.php5?a=iPopup&mode=get_comments&section='+mode+'&id='+id,600,500,true);
}

function get_journal_comments(id,mode,acc)
{

	iPopMenu('/ajax.php5?a=iPopup&mode=get_comments&section='+mode+'&id='+id+'&acc='+acc,600,500,true);
}


function add_comment_form(id,type)
{
	sPop1=true;
	iPopMenu('/ajax.php5?a=iPopup&mode=get_comments_form&id='+id+'&type='+type,530,290,false);
}

function add_journals_comment_form(id,type,acc)
{
	iPopMenu('/ajax.php5?a=iPopup&mode=get_comments_form&id='+id+'&type='+type+'&acc='+acc,530,290,false);
}

function add_comments_form_go()
{
	var cid=document.getElementById('cmf').content_id.value;
	var type=document.getElementById('cmf').type.value;

   var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
//		iPopMenu(req.responseText,600,500,true);

	var width=600;
	var height=500;

	document.getElementById('popLayer').innerHTML='';
	document.getElementById('popLayer').style.display='none';
	document.getElementById('popLayer').style.visibility='hidden';
	document.getElementById('popLayer').style.overflow='auto';



		if(isNC4){
			lr=layerFrom("popLayer",null)
		}else{
			lr=layer("popLayer",null)
		}


	lft=(getWindowWidth(false)/2)-width/2;
	tp=getScrollY()+(getWindowHeight(false)/2)-height/2;


	lr.moveTo(lft,tp);
	lar=document.getElementById('popLayer');

	lar.style.width=width;
	lar.style.height=height;

	document.getElementById('popLayer').innerHTML=req.responseText;

		document.getElementById('popLayer').style.display='inline';
		document.getElementById('popLayer').style.visibility='visible';

	

        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5', true);

    // Send whole form data to backend.
    req.send( { 'form': document.getElementById('cmf') } );
	
}

function edit_comment(id)
{
	sPop1=true;
	iPopMenu('/ajax.php5?a=iPopup&mode=get_comments_form_edit&id='+id,530,290,false);
}

function delete_comment(id)
{
	if(!confirm('Действительно удалить сообщение?')) return false;
	
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('comment'+id).innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=del_comment&id='+id, true);
    req.send();
	
}

function join_community(id)
{
	if(!confirm('Вы действительно хотите присоединиться к этому сообществу?')) return false;
	
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
//            document.getElementById('community_post_form').innerHTML = req.responseText;
		reload_community_common(req.responseText);
		reload_default_community_form(req.responseText);

        }
    }
    req.open(null, '/ajax.php5?a=join_community&id='+id, true);
    req.send();
	
}

function leave_community(id)
{
	if(!confirm('Вы действительно хотите выйти из этого сообщества?')) return false;
	
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
//            document.getElementById('community_post_form').innerHTML = req.responseText;

		if(req.responseJS) alert(req.responseJS.message); else 		
		{
		reload_community_common(req.responseText);
		reload_default_community_form(req.responseText);
		}

        }
    }
    req.open(null, '/ajax.php5?a=leave_community&id='+id, true);
    req.send();

}

function reload_community_common(id)
{

   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('community_common').innerHTML = req.responseText;

        }
    }
    req.open(null, '/ajax.php5?a=reload_community_common&id='+id, true);
    req.send();
	
}

function journal_post()
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('journal_post_form').innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=journal_post_form', true);
    req.send();

}

function edit_journal(id)
{

   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('jr'+id).innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=journal_post_form_edit&id='+id, true);
    req.send();


}

function del_journal(id)
{
	if(!confirm("Вы действительно желаете удалить запись?")) return false;
//	document.getElementById('jr'+id).style.border='1px solid red';

   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('jr'+id).innerHTML = req.responseText;
//	document.getElementById('jr'+id).style.border='';
	document.getElementById('jr'+id).style.display='none';

        }
    }
    req.open(null, '/ajax.php5?a=del_journal&id='+id, true);
    req.send();

}

function edit_journal_go(id)
{
   var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		document.getElementById('jr'+id).innerHTML=req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5', true);

    // Send whole form data to backend.
    req.send( { 'form': document.getElementById('jfm'+id) } );

}

function show_popup()
{
document.getElementById('popLayer').style.display='block';
document.getElementById('popLayer').style.visibility='visible';
}

function hide_popup()
{
sPop1=false;
document.getElementById('popLayer').style.display='none';
document.getElementById('popLayer').style.visibility='hidden';
clearTimeout(tmid);
tmid=false;
}

function show_popup2()
{
document.getElementById('popLayer2').style.display='block';
document.getElementById('popLayer2').style.visibility='visible';

}

function hide_popup2()
{
sPop2=false;
document.getElementById('popLayer2').style.display='none';
document.getElementById('popLayer2').style.visibility='hidden';
clearTimeout(tmid2);
tmid2=false;
}


function get_user_foto(id)
{
	if(document.getElementById('uf'+id)) document.getElementById('uf'+id).className='ufoto_sel';
	iPopMenu('/ajax.php5?a=get_user_foto&id='+id,500,500,false);
}

function get_report_foto(id)
{
	if(document.getElementById('rf'+id)) document.getElementById('rf'+id).className='ufoto_sel';
	iPopMenu('/ajax.php5?a=get_report_foto&mode=zoom&id='+id,500,500,false);
}


function get_user_foto_zoom(id)
{
	if(document.getElementById('uf'+id)) document.getElementById('uf'+id).className='ufoto_sel';
	iPopMenu('/ajax.php5?a=get_user_foto&id='+id+'&mode=zoom',500,500,false);
}

function get_report_foto_zoom(id)
{
	if(document.getElementById('rf'+id)) document.getElementById('rf'+id).className='ufoto_sel';
	iPopMenu('/ajax.php5?a=get_report_foto&id='+id+'&mode=zoom',500,500,false);
}


function unset_user_foto_selected(id)
{
	if(document.getElementById('uf'+id)) document.getElementById('uf'+id).className='ufoto';

}

function unset_report_foto_selected(id)
{
	if(document.getElementById('rf'+id)) document.getElementById('rf'+id).className='ufoto';

}


function del_album(id)
{
	if(!confirm("Вы действительно желаете удалить весь альбом?")) return false;


   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('albs'+id).innerHTML = req.responseText;
		document.getElementById('album_plus').innerHTML='';

        }
    }
    req.open(null, '/ajax.php5?a=del_album&id='+id, true);
    req.send();

}

function srch_user(srch)
{

   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('search_results').innerHTML = req.responseText;
	    if(req.responseJS) document.getElementById('total_found').innerHTML='Всего найдено: <b>'+req.responseJS.found+'</b>';
	tmid=false;
        }
    }
    req.open(null, '/ajax.php5?a=search_user', true);
    req.send( { 's' : document.getElementById('search').value } );
	
}



function launch_search(value)
{
	clearTimeout(tmid);
	tmid=false;

	if(!tmid) tmid=setTimeout('srch_user("'+value+'");',600);
}

function search_pim(value)
{
	clearTimeout(tmid);
	tmid=false;

	if(!tmid) tmid=setTimeout('srch_pim("'+value+'");',200);
}

function send_pim()
{
	if(!document.getElementById('to').value) {document.getElementById('pms').subm.disabled=false; alert('Не выбран ни один адресат!'); return false;}

   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		if(req.responseJS) {alert(req.responseJS.message); document.getElementById('pms').subm.disabled=false;} else document.getElementById('pim_send').innerHTML=req.responseText;
        }
    }
    req.open(null, '/ajax.php5', true);
    req.send( {'form': document.getElementById('pms')} );
	
}

function del_pm(id,mode)
{
	if(!confirm('Действительно удалить сообщение?')) return false;
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		document.getElementById('read_msg').innerHTML=req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=del_pm&id='+id+'&mode='+mode, true);
    req.send();

}

function save_pim(id)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		document.getElementById('read_msg').innerHTML=req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=save_pim&id='+id, true);
    req.send();

}


function add_pim_user(value)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		if(req.responseJS) alert(req.responseJS.message);

		document.getElementById('pim_to').innerHTML=req.responseText;
		search_pim(document.getElementById('sr').value);
        }
    }
    req.open(null, '/ajax.php5?a=add_pim_user', true);
    req.send( {'user': value, 'to_users': document.getElementById('to').value} );
}

function add_pim_users(value)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		if(req.responseJS) alert(req.responseJS.message);
		document.getElementById('pim_to').innerHTML=req.responseText;
		search_pim(document.getElementById('sr').value);
        }
    }
    req.open(null, '/ajax.php5?a=add_pim_user', true);
    req.send( {'user': 0, 'to_new': value, 'to_users': document.getElementById('to').value} );
}


function del_pim_user(value)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		if(req.responseJS) alert(req.responseJS.message);
		document.getElementById('pim_to').innerHTML=req.responseText;
		search_pim(document.getElementById('sr').value);
        }
    }
    req.open(null, '/ajax.php5?a=del_pim_user', true);
    req.send( {'user': value, 'to_users': document.getElementById('to').value} );

}
function del_pim_users(value)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		if(req.responseJS) alert(req.responseJS.message);
		document.getElementById('pim_to').innerHTML=req.responseText;
		search_pim(document.getElementById('sr').value);
        }
    }
    req.open(null, '/ajax.php5?a=del_pim_user', true);
    req.send( {'del_all': true } );

}



function launch_srch_com(value,com)
{
	clearTimeout(tmid);
	tmid=false;

	if(!tmid) tmid=setTimeout('srch_users_community("'+value+'",'+com+');',600);
}

function launch_com_search(value)
{
	clearTimeout(tmid);
	tmid=false;

	if(!tmid) tmid=setTimeout('com_search("'+value+'");',600);

}

function srch_pim(value)
{
   var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('pim_users').innerHTML = req.responseText;
        }
    }
    req.open(null, '/ajax.php5?a=get_pim_users', true);
    req.send( {'s': value, 'grp': document.getElementById('grp').value, 'to_users': document.getElementById('to').value} );
}

function change_friend(id)
{
	if(!confirm('Ты уверен?')) return false;
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		if(req.responseJS) alert(req.responseJS.message); else document.getElementById('friend'+id).innerHTML = req.responseText;
	tmid=false;
        }
    }
    req.open(null, '/ajax.php5?a=change_friend&id='+id, true);
    req.send();

}

function recognize(id)
{
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('recf'+id).innerHTML = req.responseText;
	tmid=false;
        }
    }
    req.open(null, '/ajax.php5?a=recognize&id='+id, true);
    req.send();

}

function party_visit()
{
   var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('party_v').innerHTML = req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5', true);
    // Send whole form data to backend.
    req.send( {'form': document.getElementById('prt')} );

}

function show_visitors(id)
{
   var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('party_v').innerHTML = req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5?a=party_v&mode=full&id='+id, true);
    req.send();

}

function check_scroll(ob)
{
//	if(document.getElementById('popLayer').style.display=="inline"&&document.getElementById('popLayer').style.overflow=="auto") window.scrollTo(0,scrltp);
//	return false;

	if(document.getElementById('popLayer').style.display=="inline"&&(document.getElementById('popLayer').style.overflow=="auto"||sPop1))
		{
			movePopup();
		}

	if(document.getElementById('popLayer2').style.display=="inline"&&(document.getElementById('popLayer2').style.overflow=="auto"||sPop2))
		{
			movePopup2();
		}

}

function movePopup()
{
	
	lr=layer('popLayer');
	ht=getWindowHeight();
	wht=lr.getHeight();
	ny=ht/2-wht/2+getScrollY();
	x=lr.getLeft();
	if(!tmid) tmid=setTimeout("slide(lr,x,ny);",10);
}

function movePopup2()
{
	lr2=layer('popLayer2');
	ht2=getWindowHeight();
	wht2=lr2.getHeight();
	ny2=ht2/2-wht2/2+getScrollY();
	x2=lr2.getLeft();
	if(!tmid2) tmid2=setTimeout("slide2(lr2,x2,ny2);",10);
}


function slide(lr,x,y)
{
	clearTimeout(tmid);
	tmid=false;

	diff=Math.abs(lr.getTop()-y);
	offs=(diff/2);
	offs=Math.round(offs);

	if(lr.getTop()!=y)
	{
	sign=(lr.getTop()>y)?-1:1;
	lr.moveTo(x,lr.getTop()+offs*sign);
	movePopup();
	}
	
}

function slide2(lr2,x2,y2)
{
	clearTimeout(tmid2);
	tmid2=false;

	diff2=Math.abs(lr2.getTop()-y2);
	offs2=(diff2/2);
	offs2=Math.round(offs2);

	if(lr2.getTop()!=y2)
	{
	sign2=(lr2.getTop()>y2)?-1:1;
	lr2.moveTo(x2,lr2.getTop()+offs2*sign2);
	movePopup2();
	}
	
}



function reload_read_blk(skip)
{
   var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('read').innerHTML = req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5?a=reload_read_blk&skip='+skip, true);
    req.send();

}

function symbleft(obj,mx)
{
	var lft;
	lft=mx-obj.value.length;
	if(lft>=0) document.getElementById('symbleft').innerHTML="Максимум - "+mx+" символов. Осталось: "+lft; else document.getElementById('symbleft').innerHTML="<span class=an>Лимит длины описания превышен! Лишних букаф: "+(-lft)+". Отрежем ведь :)</span>";
	
}

function srch_users_community(srch,com)
{

   var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('com_srch_results').innerHTML = req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5?a=srch_com_users&s='+srch+'&com='+com, true);
    req.send();

}

function com_moder(com,id)
{
   var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		if(req.responseJS) alert(req.responseJS.message); else document.getElementById('moders_list').innerHTML = req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5?a=add_com_moder&com='+com+'&user='+id, true);
    req.send();
}

function del_com_moder(id,com)
{
   var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		if(req.responseJS) alert(req.responseJS.message); else document.getElementById('moders_list').innerHTML = req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5?a=del_com_moder&com='+com+'&id='+id, true);
    req.send();
}

function del_com_user(id,com)
{
	if(!confirm('Действительно удалить пользователя?')) return false;
   var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		if(req.responseJS) alert(req.responseJS.message); else document.getElementById('cmu'+id).innerHTML = req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5?a=del_com_user&com='+com+'&id='+id, true);
    req.send();

}

function com_search(value)
{
   var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		document.getElementById('com_search_results').innerHTML = req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5?a=com_search&s='+value, true);
    req.send();

}

function forum_edit_subject(subj)
{
   var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		document.getElementById('forum_reply_form').innerHTML = req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5?a=subject_edit_form&id='+subj, true);
    req.send();	
}

function refresh_forum_top()
{
document.getElementById('forum').disabled=true;
   var req = new JsHttpRequest();
	
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		document.getElementById('forum').innerHTML = req.responseText;
		document.getElementById('forum').disabled=false;

        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5?a=refresh_forum_top', true);
    req.send();	
	
}

function refresh_online()
{

	document.getElementById('online').disabled=true;
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
		document.getElementById('online').innerHTML = req.responseText;
		document.getElementById('online').disabled=false;

	        }}
    req.open(null, '/ajax.php5?a=refresh_online', true);
    req.send();	
	
}

function online_full(id)
{
	document.getElementById('online_full').disabled=true;
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
		document.getElementById('online').style.display='none';
		document.getElementById('online_full').innerHTML = req.responseText;
		document.getElementById('online_full').disabled=false;
		document.getElementById('online').style.display='block';

	        }}
    req.open(null, '/ajax.php5?a=online_full&id='+id, true);
    req.send();	
}

function mark_forum_read(id)
{
document.getElementById('forum').disabled=true;
   var req = new JsHttpRequest();
	
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		document.getElementById('forum').innerHTML = req.responseText;
		document.getElementById('forum').disabled=false;

        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php5?a=refresh_forum_top&mark=true', true);
    req.send();	

}


function init_hide_popup()
{
	clearTimeout(tmid);
	tmid=false;

	if(!tmid) tmid=setTimeout('hide_popup();',600);

}

function cancel_hide_popup()
{
	clearTimeout(tmid);
	tmid=false;
}

function init_hide_popup2()
{
	clearTimeout(tmid2);
	tmid2=false;

	if(!tmid2) tmid2=setTimeout('hide_popup2();',600);

}

function cancel_hide_popup2()
{
	clearTimeout(tmid2);
	tmid2=false;
}

function get_karma(mode,id)
{

	var dv;
	if(mode==1) dv='fk';
	if(mode==2) dv='ck';
	if(mode==3) dv='dk';
	if(mode==4) dv='mpk';
	if(mode==5) dv='cmk';
	if(mode==6) dv='albkv';

	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
			resize_popup2(150,80);

			lsy=layer(dv+id);
			lsrp=layer('popLayer2');

			document.getElementById('popLayer2').innerHTML=req.responseText;
			lsrp.moveTo(lsy.getAbsoluteLeft()-40,lsy.getAbsoluteTop());
			show_popup2();
	        }}
    req.open(null, '/ajax.php5?a=get_karma&mode='+mode+'&id='+id, true);
    req.send();	
}


function set_karma(mode,id,karma)
{
	if(karma>0)
			{
				if(!confirm('Точно поощрить пользователя?')) return false;
			}
			else
			{
				if(!confirm('Точно покарать пользователя?')) return false;
			}
	var km;
	var lr;

	if(mode==1) {km='msgk'+id; lr='fk'+id;}
	if(mode==2) {km='crk'+id; lr='ck'+id;}
	if(mode==3) {km='drk'+id; lr='dk'+id;}
	if(mode==4) {km='mp3k'+id; lr='mpk'+id;}
	if(mode==5) {km='cmtk'+id; lr='cmk'+id;}
	if(mode==6) {km='albk'+id; lr='albkv'+id;}

	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
			if(req.responseText) document.getElementById(km).innerHTML=req.responseText;
			if(req.responseJS) document.getElementById(lr).innerHTML=req.responseJS.karma;
	        }}
    req.open(null, '/ajax.php5?a=set_karma&mode='+mode+'&id='+id+'&karma='+karma, true);
    req.send();	

}

function get_user_karma(id)
{
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
			document.getElementById('profile_plus').innerHTML=req.responseText;
	        }}
    req.open(null, '/ajax.php5?a=get_user_karma&id='+id, true);
    req.send();	

}

function show_forum_message(id)
{
	iPopMenu('/ajax.php5?a=show_forum_message&id='+id,540,300);
}

function show_community_message(id)
{
	iPopMenu('/ajax.php5?a=show_community_message&id='+id,540,300);
}

function show_comment(id)
{
	iPopMenu('/ajax.php5?a=show_comment&id='+id,540,300);
}

function edit_foto(id)
{
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
			document.getElementById('fte'+id).innerHTML=req.responseText;
			document.getElementById('fte_title'+id).focus();
	        }}
    req.open(null, '/ajax.php5?a=edit_foto', true);
    req.send( { 'id': id, 'title': document.getElementById('fte_title'+id).value});	


}

function del_foto(id)
{
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
			document.getElementById('fte'+id).innerHTML=req.responseText;
	        }}
    req.open(null, '/ajax.php5?a=del_foto', true);
    req.send( { 'id': id } );

}


function get_uimg(picture,zoom,alt)
{
	iPopMenu('/ajax.php5?a=get_uimg&picture='+picture+'&zoom='+zoom+'&alt='+escape(alt),400,400);
}



function chk_pim(id)
{
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {

	        }}
	req.open(null, '/ajax.php5?a=chk_pim', true);
	req.send( { 'id': id } );

}

function chk_pim_all()
{
	ids=new Array;
	frm=document.getElementById('pml');
	ckd=frm.chk_all.checked;
	for(k=0;k<frm.length;k++)
	{
		if(frm[k].type=="checkbox"&&frm[k].name!="chk_all")
			{
			if(frm[k].checked!=ckd)
				{
				frm[k].checked=ckd;
				ids.push(frm[k].value);
				}
			}
	}
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {

	        }}
	req.open(null, '/ajax.php5?a=chk_pim', true);
	req.send( { 'ids': ids.toString() } );

}

function clean_chk()
{
	if(!confirm('Информация о выделенных сообщениях сохраняется на всех страницах лички.\n\nЧтобы очистить выделение на всех страницах нажми кнопочку OK.')) return false;
	frm=document.getElementById('pml');
	ckd=frm.chk_all.checked;
	for(k=0;k<frm.length;k++)
	{
		if(frm[k].type=="checkbox")
			{
			frm[k].checked=false;
			}
	}
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {

	        }}
	req.open(null, '/ajax.php5?a=clean_chk_pm', true);
	req.send();

}

function pm_clean(mode)
{
	if(!confirm('Действительно удалить все сообщения?')) return false;
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
			document.getElementById("pm_list").innerHTML=req.responseText;
	        }}
	req.open(null, '/ajax.php5?a=clean_pm&mode='+mode, true);
	req.send();
	
}

function reload_party(id)
{
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
			document.getElementById("party"+id).innerHTML=req.responseText;
	        }}
	req.open(null, '/ajax.php5?a=reload_party&id='+id, true);
	req.send();
	
}

function reload_report(id)
{
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
			document.getElementById("report"+id).innerHTML=req.responseText;
	        }}
	req.open(null, '/ajax.php5?a=reload_report&id='+id, true);
	req.send();
	
}

function reload_text(id)
{
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
			document.getElementById("text_"+id).innerHTML=req.responseText;
	        }}
	req.open(null, '/ajax.php5?a=reload_text&id='+id, true);
	req.send();
}

function reload_news(id)
{
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
			document.getElementById("news_"+id).innerHTML=req.responseText;
	        }}
	req.open(null, '/ajax.php5?a=reload_news&id='+id, true);
	req.send();
}


function del_recognize_moder(id)
{
	if(!confirm('Ты уверен?')) return false;
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
			document.getElementById("recognize"+id).innerHTML=req.responseText;
	        }}
	req.open(null, '/ajax.php5?a=del_recognize_moder&id='+id, true);
	req.send();

}

function fotoday_upload()
	{
	var req=new JsHttpRequest();
	req.onreadystatechange=function()
		{
		if(req.readyState==4)
			{
			if(req.responseJS)
			{
			alert(req.responseJS.message);
			document.getElementById('fotoday_up').subm.disabled=false;

			}
			else document.getElementById("fotoday_upload").innerHTML=req.responseText;

			}

		}
	req.open(null,'/ajax.php5',true);
	req.send({'form':document.getElementById('fotoday_up')});
	}

function get_fotoday(id)
	{
	iPopMenu('/ajax.php5?a=get_fotoday&id='+id,800,600,false);
	}

function lcd(dv)
	{
	clearTimeout(tmid);
	tmid=false;
	if(!tmid) tmid=setTimeout('collapse_div("'+dv+'");',1);
	}

function collapse_div(dv)
	{
	document.getElementById(dv).style.overflow='hidden';
	lr=layer(dv);
	hgt=lr.getHeight();
	document.getElementById(dv).style.height=hgt-20;
	if((hgt-20)>20) lcd(dv); else document.getElementById(dv).style.display='none';
	}

function mark_glam(id,mark)
	{
	var req=new JsHttpRequest();
	req.onreadystatechange=function()
		{
		if(req.readyState==4)
			{
			document.getElementById('mark_glam'+id).innerHTML=req.responseText;
			}
		}
	req.open(null,'/ajax.php5?a=mark_glam&id='+id+'&mark='+mark,true);
	req.send();
	}

function launch_com_invite_srch(s,id)
{
	clearTimeout(tmid);
	tmid=false;
	if(!tmid) tmid=setTimeout('com_invite_search("'+s+'","'+id+'");',600);
	
}

function com_invite_search(s,id)
{
	if(s.length < 3) return false;


	var req=new JsHttpRequest();
	req.onreadystatechange=function()
		{
		if(req.readyState==4)
			{
			document.getElementById('invite_users').innerHTML=req.responseText;
			}
		}
	req.open(null,'/ajax.php5?a=invite_users&s='+escape(s)+'&id='+id,true);
	req.send();

}

function invite_user(id,community)
{

	var req=new JsHttpRequest();
	req.onreadystatechange=function()
		{
		if(req.readyState==4)
			{
				if(req.responseJS) alert(req.responseJS.message);
			}
		}
	req.open(null,'/ajax.php5?a=invite_users&id='+community+'&user='+id,true);
	req.send();


}

function report_spam(tick)
{
   if(!confirm('Вы действительно хотите пометить это сообщение как спам?')) return false;
	
   var req = new JsHttpRequest();

    req.onreadystatechange = function() {
        if (req.readyState == 4) {

		alert(req.responseJS.message)
        }
    }
    req.open(null, '/ajax.php5?a=report_spam&tick='+tick, true);
    req.send();


}


function cleanUpForIE() {

  if (document.getElementsByTagName) {
    //Get all the tags of type object in the page.
    var objs = document.getElementsByTagName("object");
    for (i=0; i<objs.length; i++) {
      // Clear out the HTML content of each object tag
      // to prevent an IE memory leak issue.
      objs[i].outerHTML = "";
    }
  }


	var spans = document.getElementsByTagName("a");
	for (var i = 0; i < spans.length; ++i)
		spans[i].onclick = null;
};
window.onunload = cleanUpForIE;

window.onload = function(){
  if (document.getElementsByTagName) {
    // Get all the tags of type object in the page.
      var objs = document.getElementsByTagName("object");
      for (i=0; i<objs.length; i++) {
        // Get the HTML content of each object tag
        // and replace it with itself.
        objs[i].outerHTML = objs[i].outerHTML;
      }
   }
}

