function doLoad(value,from,to,add) {
	document.getElementById(to).innerHTML='Загрузка...';
    // 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). 
           
if(add){		  
document.getElementById(to).innerHTML = document.getElementById(to).innerHTML+req.responseJS.q;
}else{
document.getElementById(to).innerHTML = req.responseJS.q;
}
            // Write debug information too (output become responseText).
          //  document.getElementById(to).innerHTML = req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
	req.caching = false;
    req.open(null,from, true);
    // Send data to backend.
    req.send( { q: value } );
}

function CheckLoad()  {    
document.getElementById('load_bar').style.display='none';
document.getElementById('load_image').style.display='';
//alert('true');
}

function show_foto(image,iw,ih) { 
var innerHeight_ = window.innerHeight ? window.innerHeight : document.documentElement.offsetHeight; 
var obj = document.getElementById('foto'); 
var img = document.getElementById('load_image'); 
cw=document.body.clientWidth;
ch=document.body.clientHeight;
obj.style.top = ( document.documentElement.scrollTop + document.body.scrollTop) + 'px'; 
obj.style.left ='0px'; 
obj.style.width=document.body.clientWidth;
obj.style.height=document.body.clientHeight;
obj.style.zIndex='100';
obj.style.display='';
document.getElementById('load_image').style.display='none';
document.getElementById('load_bar').style.display='';
img.src='load_theme/files/'+image;
//CheckLoad();

ik=iw/ih;
ck=cw/ch;


k1=ch/ih;
k2=cw/iw;

if(k1<k2){
koof=k1;	
}else{
koof=k2;	
}



if(iw>cw || ih>ch){
img.style.height=-20+(ih*koof)+'px';
img.style.width=-20+(iw*koof)+'px';

}else{
img.style.height=ih;
img.style.width=iw;
}

} 

function hide_foto(){
	if (document.getElementById ('foto')){
 document.getElementById('foto').style.display='none';	
	}
}

window.onscroll= function() {
hide_foto();
}
window.onresize		= function() {
hide_foto();
}//function show_foto(image,iw,ih) { 

function del() 
{  
 return confirm("Вы действительно хотите удалить выбранную запись?");  
}  

function innet(){
document.getElementById('innet').innerHTML='';
}



function textadd(text1,text2)
{
    if ((document.selection)) 
     { 
       document.add_comm_form.comm.focus(); 
       document.add_comm_form.document.selection.createRange().text = text1+document.add_comm_form.document.selection.createRange().text+text2; 
     } else if(document.forms['add_comm_form'].elements['comm'].selectionStart != undefined) { 
         var element    = document.forms['add_comm_form'].elements['comm']; 
         var str     = element.value; 
         var start    = element.selectionStart; 
         var length    = element.selectionEnd - element.selectionStart; 
         element.value = str.substr(0, start) + text1 + str.substr(start, length) + text2 + str.substr(start + length); 
     } else document.add_comm_form.text.value += text1+text2; 
  }
  
function len(){
document.add_comm_form.dl.value=5000-document.add_comm_form.comm.value.length;
} 



function edit_comm(id){
//	alert(id);
document.getElementById('c'+id).style.display='none';
document.getElementById('e'+id).style.display='';
doLoad(document.getElementById('add_comm_form'),'xml/xml/edit_comm.php?id='+id,'e'+id,false);	
}	

function save_comm(id){
document.getElementById('e'+id).style.display='none';
document.getElementById('c'+id).innetHTML='';
document.getElementById('c'+id).style.display='';
doLoad(document.getElementById('edit_comm_form'+id),'xml/xml/save_comm.php?id='+id,'c'+id,false);	
}	

function del_comm(id){
if(confirm("Вы действительно хотите удалить выбранную запись?")){
doLoad(document.getElementById('add_comm_form'),'xml/xml/del_comm.php?id='+id,'c'+id,false);
}
}

function karma(news_id, comm_id, karma){
var 
news_id_add='';
comm_id_add='';
karma_add='';
if(news_id!=''){
news_id_add='&news_id='+news_id;
}
if(comm_id!=''){
comm_id_add='&comm_id='+comm_id;
}
karma_add='?karma='+karma;
doLoad(document.getElementById('add_comm_form'),'xml/xml/karma.php'+karma_add+news_id_add+comm_id_add,'karma_result',false);
//alert('xml/xml/karma.php'+karma_add+news_id_add+comm_id_add);
}

function edit_comm_cancel(id){
document.getElementById('c'+id).style.display='';
document.getElementById('e'+id).innerHTML='';

}	 

function showHideSpoiler(spoiler)
{
	var textArea = spoiler.parentNode.getElementsByTagName('div')[1];
    if (textArea.style.display=='block')
		textArea.style.display='none';
	  
    else if (textArea.style.display=='none')
		textArea.style.display='block';
	
	changeSpoilerImg(spoiler);
}
  
function changeSpoilerImg(spoiler)
{
	var img = spoiler.getElementsByTagName('a')[0].firstChild;
	var parts = img.src.split("/");
	var pic = "";
	parts[parts.length-1] = (parts[parts.length-1] == "expand.jpg") ? "collapse.jpg" : "expand.jpg";
	for (var j=0; j<parts.length; j++)
		pic += (j==0) ? parts[j] : "/" + parts[j];
	img.src = pic;
}
