

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;
}

if(from.indexOf('xml/xml/reg.php')>-1){
document.getElementById('img_code').innerHTML = req.responseJS.i;
}	



            // 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 doLoadchat(value,from,to,add) {
	
    // 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 = req.responseJS.q+document.getElementById(to).innerHTML;
}else{
document.getElementById(to).innerHTML = req.responseJS.q;
}


if(value.id!='empty_chat_form')
document.getElementById('mess').value = '';

            // 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 array_search(needle, haystack	, strict ) {
    var strict = !!strict;
 
    for(var key in haystack){
        if( (strict && haystack[key] === needle) || (!strict && haystack[key] == needle) ){
            return key;
        }
    }
     return false;
}

function show_foto(image,iw,ih) { 
var innerHeight_ = window.innerHeight ? window.innerHeight : document.documentElement.offsetHeight; 
var obj = document.getElementById('foto'); 
var prev = document.getElementById('prev'); 
var next = document.getElementById('next'); 
var img = document.getElementById('load_image'); 
var title_img= document.getElementById('title_img'); 
var scrl = document.getElementsByTagName('body')[0];

scrl.style.overflow = 'hidden';
arr_img_cur=array_search(image,arr_img,1);
cw=document.body.clientWidth;
ch=document.body.clientHeight;
obj.style.top = (document.documentElement.scrollTop + document.body.scrollTop) + 'px'; 
prev.style.top=(document.documentElement.scrollTop + document.body.scrollTop)+(ch/2)+ 'px';
next.style.top=(document.documentElement.scrollTop + document.body.scrollTop)+(ch/2)+ 'px';
title_img.style.top = (document.documentElement.scrollTop + document.body.scrollTop) + 'px'; 
title_img.innerHTML=document.getElementById(image).innerHTML; 
title_img.style.left ='0px'; 
prev.style.zIndex='100';
next.style.zIndex='100';
prev.style.display='';
prev.style.left ='0px'; 
next.style.left=(cw-50)+'px'; 
obj.style.left ='0px'; 
obj.style.width=document.body.clientWidth;
obj.style.height=document.body.clientHeight;
obj.style.zIndex='99';
obj.style.display='';
prev.style.display='';
next.style.display='';

//*******
/*title.style.position='absolute';
title.style.zIndex='100';
title.style.top=obj.style.top;
title.style.left='20px';
title.style.textAlign='center';
*/
////
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(){
	
	var scrl = document.getElementsByTagName('body')[0];
	
if (document.getElementById ('foto')){
scrl.style.overflow = 'auto';
document.getElementById('foto').style.display='none';	
document.getElementById('prev').style.display='none';	
document.getElementById('next').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){
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 open_close_comm(id, action){
//	alert('xml/xml/open_close_comm.php?id='+id+'&action='+action);
doLoad(document.getElementById('add_comm_form'),'xml/xml/open_close_comm.php?id='+id+'&action='+action,'open_close_comm_result',false);
}

function fix_theme(id, action){
//	alert('xml/xml/open_close_comm.php?id='+id+'&action='+action);
doLoad(document.getElementById('add_comm_form'),'xml/xml/fix_theme.php?id='+id+'&action='+action,'fixtheme_result',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;

if(news_id!=''){
doLoad(document.getElementById('add_comm_form'),'xml/xml/karma.php'+karma_add+news_id_add+comm_id_add,'karma_result',false);
}else{
doLoad(document.getElementById('add_comm_form'),'xml/xml/karma.php'+karma_add+news_id_add+comm_id_add,'karma_result_'+ comm_id,false);
}//if(news_id!=''){
}

function chat_load(){
//alert('test');
doLoadchat(document.getElementById('chat_form'),'xml/xml/chat_load.php','chat_result',true);	
}

function chat_load_timer(){
doLoadchat(document.getElementById('empty_chat_form'),'xml/xml/chat_load.php','chat_result',true);	
}

var interval;
function onchat(){
interval=setInterval(chat_load_timer,5000);
document.getElementById('onoffchat').innerHTML='<a href="#chat" onclick="offchat();">Выключить чат &raquo;</a>';	
document.getElementById('chat_result').style.height=200;
}

function offchat(){
clearInterval(interval);
document.getElementById('onoffchat').innerHTML='<a href="#chat" onclick="onchat();">Включить чат &raquo;</a>';	
document.getElementById('chat_result').style.height=0;

}

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;
}

function page_box_color(id){
if(!box_id) box_id=1;
if(box_id) document.getElementById('page_box_'+box_id).style.backgroundColor='#EDEEED';
document.getElementById('page_box_'+id).style.backgroundColor='#9eef12';
box_id=id;
}

function next_photo() {
//alert(arr_img[arr_img_cur]+arr_img_size_w[arr_img_cur]+arr_img_size_h[arr_img_cur] );	
arr_img_cur++;
if(arr_img_cur>arr_size-1){
	arr_img_cur=0;
	}
show_foto(arr_img[arr_img_cur],arr_img_size_w[arr_img_cur],arr_img_size_h[arr_img_cur]);

}

function prev_photo() {
//alert(arr_img[arr_img_cur]+arr_img_size_w[arr_img_cur]+arr_img_size_h[arr_img_cur] );	
arr_img_cur--;
if(arr_img_cur<0){
	arr_img_cur=arr_size-1;
	}
show_foto(arr_img[arr_img_cur],arr_img_size_w[arr_img_cur],arr_img_size_h[arr_img_cur])
}


document.onkeydown = checkKeycode;

function checkKeycode(e) {

var keycode;

if (window.event) {
keycode = window.event.keyCode;	
if(document.getElementById('foto')){
	if(document.getElementById('foto').style.display!='none'){
if (keycode==37) prev_photo();
if (keycode==39) next_photo();
	}//if(document.getElementById('foto').style.display!='none'){
}//if(document.getElementById('foto')){

}//if (window.event) {

}//function checkKeycode(e) {

