//------------------------------------------------------------------------------
/** @author Бреславский А.В. (Joonte Ltd.) */
//------------------------------------------------------------------------------
function Logon($Event){
  //----------------------------------------------------------------------------
  if($Event){
    //--------------------------------------------------------------------------
    var $IsCtrl = $Event.ctrlKey;
    //--------------------------------------------------------------------------
    var $IsShift = $Event.shiftKey;
    //--------------------------------------------------------------------------
    var $Key = $Event.which;
  }else{
    //--------------------------------------------------------------------------
    var $IsCtrl = event.ctrlKey;
    //--------------------------------------------------------------------------
    var $IsShift = event.shiftKey;
    //--------------------------------------------------------------------------
    var $Key = event.keyCode;
  }
  //----------------------------------------------------------------------------
  if($IsCtrl && $IsShift){
    //--------------------------------------------------------------------------
    switch($Key){
      case 49:
        //----------------------------------------------------------------------
        if(GetCookie('Session')){
          //--------------------------------------------------------------------
          DeleteCookie('Session');
          GetURL(document.location);
        }else
          ShowAnswer('Пароль','Войти','',"AjaxCall('/API/Logon',{Password:__VALUE__},'Вход в систему','GetURL(document.location);');");
        //----------------------------------------------------------------------
      break;
      case 51:
        document.getElementById('LiveInternet').style.display = '';
      break;
      default:
        // No more...
    }
  }
}
//------------------------------------------------------------------------------
document.onkeydown = Logon;
//------------------------------------------------------------------------------
var $Image = new Image();
$Image.src = '/styles/azhukova/Images/Loading.gif';
//------------------------------------------------------------------------------
function Loading(){
  //----------------------------------------------------------------------------
  var $Loading = document.getElementById('Loading');
  //----------------------------------------------------------------------------
  if($Loading){
    //--------------------------------------------------------------------------
    $Loading.style.zIndex = GetMaxZIndex() + 1;
    //--------------------------------------------------------------------------
    return false;
  }
  //----------------------------------------------------------------------------
  $Color = '#FFFFFF';
  //----------------------------------------------------------------------------
  switch($BrouserID){
    case 'MSIE':
      return false;
    case 'Mozilla':
      //------------------------------------------------------------------------
      $Loading = document.createElement('DIV');
      //------------------------------------------------------------------------
      $Loading.style.backgroundColor = $Color;
    break;
    case 'Opera':
      //------------------------------------------------------------------------
      $LockPage = document.createElement('DIV');
      //------------------------------------------------------------------------
      $Loading.style.backgroundColor = $Color;
    break;
    case 'Chrome':
      //------------------------------------------------------------------------
      $LockPage = document.createElement('DIV');
      //------------------------------------------------------------------------
      $Loading.style.backgroundColor = $Color;
    break;
    default:
      //------------------------------------------------------------------------
      $Loading = document.createElement('DIV');
      //------------------------------------------------------------------------
      $Loading.style.backgroundImage = 'url(/styles/root/Images/Tranparent.gif)';
  }
  //----------------------------------------------------------------------------
  $Loading.id = 'Loading';
  //----------------------------------------------------------------------------
  $innerHTML = '<TABLE width="100%" height="100%">';
  $innerHTML += '<TR><TD align="center"><IMG alt="Загрузка" src="/styles/azhukova/Images/Loading.gif" />';
  $innerHTML += '</TD></TR></TABLE>';
  $Loading.innerHTML = $innerHTML;
  //----------------------------------------------------------------------------
  with($Loading.style){
    //--------------------------------------------------------------------------
    var $Body = document.body;
    //--------------------------------------------------------------------------
    left     = 0;
    top      = 0;
    position = 'absolute';
    height   = $Body.scrollHeight;
    width    = ($BrouserID == 'MSIE'?$Body.scrollWidth-10:$Body.scrollWidth);
    zIndex   = GetMaxZIndex() + 1;
  }
  //----------------------------------------------------------------------------
  document.body.appendChild($Loading);
  //----------------------------------------------------------------------------
  var $Loading = document.getElementById('Loading');
  //----------------------------------------------------------------------------
  SetAlpha($Loading,50);
  //----------------------------------------------------------------------------
  document.body.style.cursor = 'wait';
}
//------------------------------------------------------------------------------
function StopLoading(){
  //----------------------------------------------------------------------------
  var $Loading = document.getElementById('Loading');
  //----------------------------------------------------------------------------
  if($Loading)
    $Loading.parentNode.removeChild($Loading);
  //----------------------------------------------------------------------------
  document.body.style.cursor = 'auto';
}
//------------------------------------------------------------------------------
function TranslateEdit(){
  //----------------------------------------------------------------------------
  var $Form = document.forms['TranslateForm'];
  //----------------------------------------------------------------------------
  var $HTTP = new HTTP();
  //----------------------------------------------------------------------------
  if(!$HTTP.Resource){
    //--------------------------------------------------------------------------
    alert('Не удалось создать HTTP соединение');
    //--------------------------------------------------------------------------
    return false;
  }
  //----------------------------------------------------------------------------
  $HTTP.onLoaded = function(){
    //--------------------------------------------------------------------------
    HideProgress();
  }
  //----------------------------------------------------------------------------
  $HTTP.onAnswer = function($Answer){
    //--------------------------------------------------------------------------
    switch($Answer.Status){
      case 'Error':
        ShowAlert($Answer.Error.String,'Warning');
      break;
      case 'Exception':
        ShowAlert(ExceptionsStack($Answer.Exception),'Warning');
      break;
      case 'Ok':
        ShowTick('Файл сохранен');
      break;
      default:
        alert('Не известный ответ');
    }
  };
  //----------------------------------------------------------------------------
  var $Args = FormGet($Form);
  //----------------------------------------------------------------------------
  if(!$HTTP.Send('/API/Translate',$Args)){
    //--------------------------------------------------------------------------
    alert('Не удалось отправить запрос на сервер');
    //--------------------------------------------------------------------------
    return false;
  }
  //----------------------------------------------------------------------------
  ShowProgress('Сохранение файла');
}
//------------------------------------------------------------------------------
if($BrouserID != 'MSIE')
  var $InitPageIntervalID = window.setInterval("if(document.getElementById('Context')){FadeIn(document.getElementById('Context'),100);window.clearInterval($InitPageIntervalID);}",1);
//------------------------------------------------------------------------------
