﻿var request = false;
var can_ajax=true;

function create_ajax() //Create object to ajax requests
{
 try {
    request = new XMLHttpRequest();
  } catch (trymicrosoft) {
   try {
      request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (othermicrosoft) {
      try {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (failed) {
        request = false;
      }
    }
  }
 }
create_ajax();  //Create object to ajax requests
if (!request){
    //  alert("Ошибка инициализации обьекта XMLHttpRequest!\n Просмотр страниц будет происходить в обычном режиме!");
	  can_ajax=false;
	}
preloadimages('/sourses/ajax.gif');//preload preloader image to show
///////////////////////////////////////////////////////////////////////////
timerajax=null;
function gettingdate(url)//Send request to server with delay 1 sec
{       
     request.open("POST", url, true);	       
     request.onreadystatechange = updatePage;
	 timerajax=null;
     request.send('');
	 
}
var URL_tec='';
function GetContent(url)
{    
 if(can_ajax)
  { 
   if(timerajax!=null) {clearTimeout(timerajax);}  
	 dr=dURL;
	 dURL='http://isachenkov.com/'+url;	
	 strok_='<div style="padding-right:100px"><img src="/sourses/ajax.gif" width="16" height="16"><font style="font-size:12px;"><b> ЗАГРУЗКА...</b></font></div>';
	 elements('title').innerHTML=strok_; 
     elements('content').innerHTML='';
     URL_tec = escape(url);
	 unFocus.History.addHistory(escape(url));//<------------------------------	 
     timerajax=setTimeout('gettingdate("'+url+'")',1000);     
  }
else
  {
    if(!request)
     {
       document.location=url; 
     }   
   }   
  return false;
}

function updatePage()
 {   
     if (request.readyState == 4) {       
       if (request.status == 200) {
         var response = request.responseText;
		  elements('title').innerHTML=title(response);
          elements('content').innerHTML=content(response)+liveinternet();  		  
          top.document.title=pagetitle(response);      
       } else  {
	   if((request.status == 12031)||(request.status == 504)||(request.status == 503)||(request.status == 502)||(request.status == 504))
	    {
		  if(timerajax==null) 
		    {timerajax=setTimeout('gettingdate("'+unescape(URL_tec)+'")',10000);}
		}
	   else
	    {
	     if(request.status==404){alert('Запрашиваемая страница не найдена');
		  } else {
		 if(request.status==403){alert('Доступ запрещен');
		 }else{
		 alert("Ошибка! server status is " + request.status);}
		 }
        } 
		
     }
	}
  }
//---------------------------------------------------------------------------------------  
function pagetitle(response)
{
str='<title>';
start=response.indexOf(str);
num1=start+str.length;
str='</title>';
fine=response.indexOf(str);
return response.substring(num1,fine);
}
function title(response)
{
str='<!--!longtitle! -->';
start=response.indexOf(str);
num1=start+str.length;
str='<!--!/longtitle! -->';
fine=response.indexOf(str);
return response.substring(num1,fine);
}
function content(response)
{
str='<!-- !Content! -->';
start=response.indexOf(str);
num1=start+str.length;
str='<!-- !/Content! -->';
fine=response.indexOf(str);
return response.substring(num1,fine);

}
//------------------------------------------------------------

function parseUrl()
{
location_=document.location.hash;
num=location_.indexOf('#');
len=location_.length;
if(num==0){location_=location_.substring(1,len);}
location_=unescape(location_);
if(location_!=''){URL_tec=escape(location_);GetContent(location_); }
}
//------------------------------------------------------------
if(URL_tec==''){
mainDocument=document.location+'';
st_=mainDocument.lastIndexOf('/');
len=mainDocument.length
mainDocument=mainDocument.substring(st_,len);
}else{
mainDocument='/';
}
if(mainDocument==''){mainDocument='/';}
function URL_tec_()
{
return URL_tec;
}
function Listener() {
	this.historyListener = function(historyHash) {
	     f=unescape(historyHash+'');
		 if(f!=unescape(URL_tec_())){
		 if(f==''){GetContent(mainDocument);
		 }else{
		 GetContent(unescape(historyHash));
		 }
		}
	};
	unFocus.History.addEventListener('historyChange', this.historyListener);	
};

dr=document.referrer;
dURL=document.URL;

 function liveinternet(){
str_="<div style='visibility:hidden'><a href='http://www.liveinternet.ru/click' "+
"target=_blank><img src='http://counter.yadro.ru/hit?t14.1;r"+escape(dr)+((typeof(screen)=="undefined")?"":
";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+";u"+escape(dURL)+
";"+Math.random()+"' alt='' title='LiveInternet: показано число просмотров за 24"+
" часа, посетителей за 24 часа и за сегодня' "+"border=0 width=88 height=31><\/a></div>";

return str_;
   }

