var HH = HH || {};

HH.Search = HH.Search || {};
HH.Search.Messages = HH.Search.Messages || {};

HH.Search.SwitchFav = function(element, vacancyid){
  jsx.require(['{jsxAjax}.XmlHttp'], function(){
    new jsxAjax.XmlHttp.Request('/applicant/switchVacancyFavorite.do?vacancyId=' + vacancyid, {
      method: 'get',
      onSuccess: jsx.bind(HH.Search, HH.Search.doSwitchFav, element)
    });
  });
};
HH.Search.doSwitchFav = function(element, transport){
  var isInFav = 0;
  isInFav = parseInt(transport.responseText);
  var img = element.getElementsByTagName('img')[0];
  if (isInFav > 0) {
    element.className = 'b-vs-favon';
    // variable on page from dictionary
    img.title = HH.Search.Messages.favOn || '';
  }
  else {
    element.className = 'b-vs-favoff';
    // variable on page from dictionary
    img.title = HH.Search.Messages.favOff || '';
  }
};

(function (){
  var expire;

  if (/#unpacked/.test(window.location.hash)){
    expire = new Date();
    expire.setTime(expire.getTime() + 3600000 * 24 * 365);
    document.cookie = 'unpacked=true;expires=' + expire.toGMTString() + ';path=/';
    window.location.hash='';
  } else if (/#packed/.test(window.location.hash)){
    expire = new Date();
    expire.setTime(expire.getTime() - 3600000 * 24 * 365);
    document.cookie = 'unpacked=true;expires=' + expire.toGMTString() + ';path=/';
    window.location.hash='';
  }
})();
(function (){
  if (/msie/.test(navigator.userAgent.toLowerCase()) || !/pyn\.ru/.test(window.location.host)){
    return;
  }
  var fragment = document.createElement('div');
  fragment.innerHTML = ''
    + '<table id="web" cellpadding="0" cellspacing="0" style="table-layout:fixed; border-collapse:collapse; position:absolute;left:0; top:0; height:5000px; width:100%; z-index:0; filter:alpha(opacity=20)">'
      + '<tbody>'
        + '<tr>'
          + '<td style="width:20%; padding-right:10px;">'
            + '<div style="float:left; height:5000px; width:20px; background:#f99;"> </div>'
            + '<div style="float:right; height:5000px; width:20px; background:#f99;"> </div>'
          +' </td>'
          + '<td style="width:80%">'
            + '<table id="web" cellpadding="0" cellspacing="0" style="table-layout:fixed; border-collapse:collapse; width:100%;">'
              + '<tbody>'
                + '<tr>'
                  + '<td>'
                    + '<div style="float:left; height:5000px; width:20px; background:#f99;"> </div>'
                    + '<div style="float:right; height:5000px; width:20px; background:#f99;"> </div>'
                  +' </td>'
                  + '<td style="padding-left:10px;">'
                    + '<div style="float:left; height:5000px; width:20px; background:#f99;"> </div>'
                    + '<div style="float:right; height:5000px; width:20px; background:#f99;"> </div>'
                  +' </td>'
                  + '<td style="padding-left:10px;">'
                    + '<div style="float:left; height:5000px; width:20px; background:#f99;"> </div>'
                    + '<div style="float:right; height:5000px; width:20px; background:#f99;"> </div>'
                  +' </td>'
                + '</tr>'
              + '</tbody>'
            + '</table>';
          + '</td>'
        + '</tr>'
      + '</tbody>'
    + '</table>';
  var web = fragment.firstChild;
  web.style.display = 'none';
  window.setTimeout(function() {document.body.appendChild(web);}, 1000);
  document.onkeydown = function(event){
    var hh = document.body.firstChild;
    while (hh){
      if (hh.nodeType == 1 && hh.className.indexOf('b-headhunter') >= 0){
        break;
      }
      hh = hh.nextSibling;
    }
    var web = document.getElementById('web');
    var e = event || window.event;
    if (e.keyCode == 109 || e.keyCode == 189){
      web.style.display = 'none';
      hh.style.position = 'static';
      hh.style.zIndex = '0';
      hh.style.opacity = '1';
    }
    if (e.keyCode == 107 || e.keyCode == 187 || e.keyCode == 61){
      web.style.display = '';
      hh.style.position = 'relative';
      hh.style.zIndex = '1';
      hh.style.opacity = '.8';
    }
    if (window.event){
      web.style.zIndex = '1000';
    }
  };
})();

//copy of /jslib/main.js - HHOld.showHideItem
HH.showHideItem = function (id) {
  var item = document.getElementById (id);
  var image = document.getElementById ("image_" + id);
  if (item) {
    if (item.style.display == "none") item.style.display = "block";
    else item.style.display = "none";
  }
  if (image) {
    if (item.style.display == "block")
      image.src = "/images/minus.gif";
    else
      image.src = "/images/plus.gif";
  }
  return false;
};

//copy of /jslib/main.js - HHOld.doClick
HH.doClick = function (actionVal) {
  var action = document.getElementById ("action");
  var form = document.getElementById ("form");
  if (action && form) {
    action.value = actionVal;
    form.submit ();
  }
};

document.cookie = 'GMT=' + -1 * (new Date().getTimezoneOffset() / 60) + ';path=/';

jsx.require(['Cookies'], function(){
  try {
    jsx.Cookies.set('regions', jsx.Cookies.get('regions').replace(/moscow/, '1').replace(/russia/, '113'), 24 * 365 * 10);
  }catch(e){}
});
