var working=false;var http=false;var page=0;
function get_http(){   
 var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}   
var stplus=1;var hnick="";var hcity="";var hdata="";var pagev=new Array(); for(var i=0;i<100;i++)pagev[i]=0;
function ViewFights(pagech){
       // Получаем объект XMLHTTPRequest   
        if(!http){   
            http = get_http();   
            working = false;   
        }    
      // Запрос   
	  if(document.getElementById("city").selectedIndex<=0)return;
	  if(pagech==0)page=0;
	  if(pagech==-1){page-=15;if(page<0)page=0;}
	  if(pagech==1){page+=15;}	  
        if (!working && http) { 
 working = true;document.getElementById("infohere").innerHTML="загрузка информации...";
 url = "/lib_bk/fight_log/getfights.php?nick="+encodeURIComponent(document.getElementById("nick").value)+"&city="+encodeURIComponent(document.getElementById("city").options[document.getElementById("city").selectedIndex].value)+"&data="+encodeURIComponent(document.getElementById("data").value)+"&page="+page; 	
 if(hnick!=document.getElementById("nick").value||hcity!=document.getElementById("city").options[document.getElementById("city").selectedIndex].value||hdata!=document.getElementById("data").value){hnick=document.getElementById("nick").value;hcity=document.getElementById("city").options[document.getElementById("city").selectedIndex].value;hdata=document.getElementById("data").value;stw[0]=stw[1]=stw[2]=0; for(var i=0;i<100;i++)pagev[i]=0;}
 if(pagev[page/15]==1)stplus=0;else pagev[page/15]=1;
 
            http.open("GET", url, true);    
http.onreadystatechange = FightsPosted; 
            http.send(null);
        }   
        if(!http){   
              alert('Ошибка при создании XMLHTTP объекта!')   
        }   		
}    
function ViewFightsBK(pagech){
	  if(document.getElementById("city").selectedIndex<=0)return;
window.open("http://"+document.getElementById("city").options[document.getElementById("city").selectedIndex].value+".combats.com/zayavka.pl?logs="+encodeURIComponent(document.getElementById("data").value)+"&filter="+encodeURIComponent(document.getElementById("nick").value));
}    

function FightsPosted() {   
         if (http.readyState == 4) {  
             if(working != false){
					working = false;var data=http.responseText;					
					     pos=data.indexOf("#ENDAJAXREQUEST#",0);
						 if(pos!=-1)data=data.substr(0,pos);nuldate=1;
						 if(data.length == 0){document.getElementById("infohere").innerHTML="Ошибка загрузки!";return;}
						 //echo "#WINKOL#".$winkol."#NICHKOL#".$nichkol."#LOSEKOL#".$losekol."#END#";						 
						 pos=data.indexOf("#WINKOL#",0);if(pos!=-1){var spos=pos;pos+=8;						 
						 endpos=data.indexOf("#NICHKOL#",pos);if(stplus)stw[0]+=parseInt(data.substr(pos,endpos-pos));pos=endpos+9;
						 endpos=data.indexOf("#LOSEKOL#",pos);if(stplus)stw[1]+=parseInt(data.substr(pos,endpos-pos));pos=endpos+9;
						 endpos=data.indexOf("#END#",pos);if(stplus)stw[2]+=parseInt(data.substr(pos,endpos-pos));endpos+=5;
						 //alert(data.substr(spos,endpos-spos));
						 data=data.substr(0,spos)+data.substr(endpos);	nuldate=0;					 
						 }
						 document.getElementById("infohere").innerHTML=data;UpdStatwin();
					}
                     
                  }
            } 

var stw=new Array();stw[0]=stw[1]=stw[2]=0;var nuldate=0;
function UpdStatwin(){
s="Бои персонажа <b>"+hnick+"</b> по просмотренным страницам:<br><b>Побед:</b> "+stw[0]+"<br><b>Ничьих:</b> "+stw[1]+"<br><b>Поражений:</b> "+stw[2];
if(!hnick||nuldate)s="";
document.getElementById("statwin").innerHTML=s;stplus=1;
}	
			
function PrevPage(){
ViewFights(-1);
}
function NextPage(){
ViewFights(1);
}
