  var loadingImage     = "<img src='/templates/admins/images/loading.gif'>";
  var loadingDotsImage = "<img src='/templates/admins/images/loading.dots.gif'>";
  var loadingTable     = "<table width='100%'><tr><td height='40' align='center'><img src='/templates/admins/images/loading.gif'></td></tr></table>";


  // выставим указанный язык сайта
  function setLanguage(language) { $.post('actions.php', { action: 'setLanguage', language: language }, setLanguageResponser); }
  function setLanguageResponser(response) { if (response=='1') document.location.href = document.location.href; }

  function alert(message)
  {
    $('#modalWindowHeader').html('Системное сообщение');
    $('#modalWindowBody').html("<table width='100%' cellpadding='0' cellspacing='0' border='0'><tr><td style='padding-top: 4px; padding-bottom: 8px'>" + message + "</td></tr><tr><td align='right' style='border-top: #c0c0c0 1px dotted'><a href='#' class='gb' onClick='$.modal.close(); return false;'>закрыть</a></td></tr></table>");
    $('#modalWindowLayer').modal({'minWidth': 300, onClose: openModalWindowClose});
  }

  function openModalWindow(header, content, width, closeButton)
  {
    $('#modalWindowHeader').html(header);
    windowBody = "<table width='100%' cellpadding='0' cellspacing='0' border='0'><tr><td style='padding-top: 4px; padding-bottom: 8px'>" + content + "</td></tr>";
    if (closeButton==1) windowBody = windowBody + "<tr><td align='right' style='border-top: #c0c0c0 1px dotted'><a href='#' class='gb' onClick='$.modal.close(); return false;'>закрыть</a></td></tr>";
    windowBody = windowBody + "</table>";
    $('#modalWindowBody').html(windowBody);
    $('#modalWindowLayer').modal({'minWidth': width, onClose: openModalWindowClose });
  }

  var modalCloseAction = '';
  function openModalWindowClose()
  {
    $.modal.close();
    if (modalCloseAction!='') { eval(modalCloseAction); modalCloseAction = ''; }
  }

  // обработчик ошибок ajax запросов
  function ajaxError(request, textStatus, errorThrown) { alert(errorThrown);  }

  // авторизация пользователя
  function userAuth() { $.ajax({ type: 'POST', url: '/actions.php', timeout: 30000, data: ({ action: 'userAuth', userEmail: $('#userAuth_userEmail').val(), userPasswd: $('#userAuth_userPasswd').val(), humanCode: $('#userAuth_humanCode').val() }), cache: false, dataType: 'text', success: userAuthResponser, error: ajaxError }); }
  function userAuthResponser(r)
  {
    r = r.split('///////');
    if (r[0]==0) { $('#userAuth_humanCodeImg').attr('src', '/image.php?' + new Date()); $('#'+r[1]).focus(); alert(r[2]); }
    if (r[0]==1) { document.location.href = '/news.php'; }
    if (r[0]==2) { $('#userAuth_humanCodeImg').attr('src', '/image.php?' + new Date()); alert(r[1]); }
  }

  // повторное отправление ссылки с активацией
  function reSendEmailVerificationLink(userId) { $('#reSendLinkLayer').html('отправляем ...'); $.ajax({ type: 'POST', url: '/actions.php', timeout: 30000, data: ({ action: 'reSendEmailVerificationLink', userId: userId }), cache: false, dataType: 'text', success: reSendEmailVerificationLinkResponser, error: ajaxError }); }
  function reSendEmailVerificationLinkResponser(r) { $('#reSendLinkLayer').html(r); }

  // выход пользователя
  function userLogout() { $.ajax({ type: 'POST', url: '/actions.php', timeout: 30000, data: ({ action: 'userLogout' }), cache: false, dataType: 'json', success: userLogoutResponser, error: ajaxError }); }
  function userLogoutResponser(json) { document.location.href = '/'; }

  // востановление пароля
  function passRecover() { $.ajax({ type: 'POST', url: 'actions.php', timeout: 3000, data: ({ action: 'passRecover', userEmail: $('#passRecover_userEmail').val(), questionId: $('#passRecover_questionId').val(), questionAnswer: $('#passRecover_questionAnswer').val() }), cache: false, dataType: 'json', success: passRecoverResponser, error: ajaxError }); }
  function passRecoverResponser(json)
  {
    if (json.resp.status==0) { $('#'+json.resp.focusField).focus(); $('#passRecover_errorLayer').html(json.resp.errorMessage); }
    if (json.resp.status==1) { $('#passRecover_errorLayer').html(''); alert('крута ;)') }
  }

  // регистрация пользователя
  function userRegistration() { $.ajax({ type: 'POST', url: '/registration.php', data: ({ action: 'userRegistration', userEmail: $('#userReg_userEmail').val(), accountType: $('#userReg_accountType').val(), userPasswd: $('#userReg_userPasswd').val(), userPasswd2: $('#userReg_userPasswd2').val(), questionId: $('#userReg_questionId').val(), questionAnswer: $('#userReg_questionAnswer').val() }), cache: false, dataType: 'text', success: userRegistrationResponser }); }
  function userRegistrationResponser(r)
  {
    r = r.split('///////');
    if (r[0]==0) { $('#'+r[1]).focus(); $('#userReg_errorLayer').html(r[2]); $('#userReg_errorLayer').show(); }
    if (r[0]==1) { $('#userReg_errorLayer').html(''); $('#userReg_errorLayer').hide(); alert(r[1]); }
  }

  // восстановление пароля
  function accountPasswdRepear() { $.ajax({ type: 'POST', url: '/registration.php', data: ({ action: 'accountPasswdRepear', userEmail: $('#passwdRepear_userEmail').val(), questionId: $('#passwdRepear_questionId').val(), questionAnswer: $('#passwdRepear_questionAnswer').val() }), cache: false, dataType: 'text', success: accountPasswdRepearResponser }); }
  function accountPasswdRepearResponser(r)
  {
    r = r.split('///////');
    if (r[0]==0) { $('#'+r[1]).focus(); $('#passwdRepear_errorLayer').html(r[2]); $('#passwdRepear_errorLayer').show(); }
    if (r[0]==1) { $('#passwdRepear_errorLayer').html(''); $('#passwdRepear_errorLayer').hide(); alert(r[1]); }
  }

  // новости на /news.php
  function getNewsPage(pageNum) { $.ajax({ type: 'POST', url: '/news.php', data: ({ action: 'getNewsPage', pageNum: pageNum }), cache: false, dataType: 'text', success: getNewsPageResponser }); }
  function getNewsPageResponser(r) { $('#newsPageContainer').html(r); }

  // просмотр инфы об объектах
  function showObj(theObj)
  {
    objDesc = '';
    if(theObj.constructor == Array || theObj.constructor == Object)
    {
      objDesc = objDesc + "объект:\n";
      for(var p in theObj)
      {
        if(theObj[p].constructor == Array || theObj[p].constructor == Object)
        {
          objDesc = objDesc + "   ["+p+"] => "+typeof(theObj)+"\n";
          objDesc = objDesc + "\n";
          print_r(theObj[p]);
          objDesc = objDesc + "объект:\n";
        }
        else
        {
          objDesc = objDesc + "   ["+p+"] => "+theObj[p]+"\n";
        }
      }
      objDesc = objDesc + "\n";
    }
    return objDesc;
  }


function makeMtsBill()
{
  $('#makeBillButton').hide();
  $('#waitImage').show();
  $.ajax({ type: 'POST', url: '/sppi/mts.bill.maker.php', timeout: 600000, data: ({ action: 'makeMtsBill', userMtsId: $('#mtsPhone').val(),
																			     paymentId: $('#spPaymentId').val(),
																			     goodPhone: $('#goodPhone').val(),
																				 prefix:    $('#prefix').val()
		  																	  }), cache: false, dataType: 'text', success: makeMtsResponser });
}

function makeMtsResponser(r)
{
  a = r;
  r = r.split("///////");
  //alert(r[0]);
  if (r[0]==0)
  {
	$('#instructionLayer').html("В течении минуты Вы получите смс-сообщение с инструкцией к оплате.");
    $('#waitImage').hide();
    return false;
  }
  if(r[0]==1)
  {
    alert("При выполнении произошла ошибка. Повторите процедуру заново или обратитесь в службу поддержки.");
    $('#makeBillButton').hide();
    $('#waitImage').hide();
    return false;
  }
}


