var vkinited=false;
function ge(e){return document.getElementById(e)} 
function httpReq(b)
{
  var a = !1;
  if(window.XMLHttpRequest) {
    a = new XMLHttpRequest, a.overrideMimeType && a.overrideMimeType("text/html; charset=windows-1251")
  }else {
    if(window.ActiveXObject) {
      try {
        a = new ActiveXObject("Msxml2.XMLHTTP")
      }catch(c) {
        try {
          a = new ActiveXObject("Microsoft.XMLHTTP")
        }catch(d) {
        }
      }
    }
  }
  if(!a)return;
  a.onreadystatechange = function() {
    //if(a.readyState==4&&a.status==200)dosomething();
  };
  a.open("GET",b,!0);
  a.send(null)
}
function onChange(num,last_comment,date,sign)
{
  httpReq('/comms.php?n='+num+'&c='+encodeURIComponent(last_comment)+'&d='+encodeURIComponent(date)+'&s='+sign+'&p='+pid+'&s2='+phash);
}
function authInfo(response)
{
  var isauth=response.session;
  ge('needauth').style.display=(isauth?'none':'');
  if(isauth){
    initComments();
  }else{
	VK.UI.button('login_button');
  }
}
function initVk()
{
  VK.init({apiId:2121467});
  vkinited=true;
}
function initComments()
{
  if(!vkinited)initVk();
  VK.Widgets.Comments("vk_comments", {limit:10,attach: "*",autoPublish:1,onChange:onChange});
  if(location.hash=='#comments')setTimeout(function(){
    document.body.scrollTop+=1000;
  },1000);
  VK.Widgets.Like("vk_like",{type:"10",verb:"1",pageTitle:window.xtitle?xtitle:'',pageDescription:window.xdesc?xdesc:''});
}
/*VK.Auth.getLoginStatus(authInfo);*/

function setCookie(name, value, days, domain)
{
  if(!days)days=60;
  if(days<0)days=0;
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  if(!domain)domain=location.host;
  document.cookie = name+"="+escape(value)+expires+"; path=/"+(domain ? '; domain='+domain : '');
}

function delCookie(name)
{
  domain=location.host;
  expires="; expires="+(new Date(0).toGMTString());
  document.cookie = name+"=0"+expires+"; path=/"+(domain ? '; domain='+domain : '');
}
