function showElement(elementID) {
  self.document.getElementById(elementID).style.display = 'block';
}

function hideElement(elementID) {
  self.document.getElementById(elementID).style.display = 'none';
}

function buttonHighlight(elementID, className) {
  self.document.getElementById(elementID).className = className + '-sel';
}

function buttonLowlight(elementID, className) {
  self.document.getElementById(elementID).className = className;
}

function rowHighlight(elementID) {
  self.document.getElementById(elementID).className = 'sel';
}

function rowLowlight(elementID, className) {
  self.document.getElementById(elementID).className = className;
}

function writeCookieWarning() {  if ((typeof navigator.cookieEnabled != 'undefined') &&
    (navigator.cookieEnabled == false)) {    self.document.write(      '<p class="error_message"><br />\n' +      'Внимание! У Вашего браузера отключены ' +      '<a href="http://ru.wikipedia.org/wiki/HTTP-Cookies">HTTP-Cookies</a>. ' +      'Нормальная работа настоящего раздела сайта невозможна до тех пор, ' +      'пока их использование не будет разрешено.\n' +      '</p>\n'    );  }}

function menuItemHighlight(ind) {  self.document.getElementById('menu_item_top_' + ind).className = 'menu-item-top-sel';
  self.document.getElementById('menu_item_center_' + ind).className = 'menu-item-center-sel';
  self.document.getElementById('menu_item_bottom_' + ind).className = 'menu-item-bottom-sel';
}

function menuItemLowlight(ind) {  self.document.getElementById('menu_item_top_' + ind).className = 'menu-item-top';
  self.document.getElementById('menu_item_center_' + ind).className = 'menu-item-center';
  self.document.getElementById('menu_item_bottom_' + ind).className = 'menu-item-bottom';
}

function toggleCheckboxes(containerID, flag) {
  elements = self.document.getElementById(containerID).getElementsByTagName("input");

  for (i = 0; i < elements.length; i++) {
    elements[i].checked = flag;
  }
}

function queueDeleteSubmit(formID) {  if (confirm('Удалить отмеченные записи?')) {    self.document.getElementById(formID).submit();
    return true;
  } else {    return false;  }}

function noticeDeleteSubmit(formID) {
  if (confirm('Удалить выбранные объявления?')) {
    self.document.getElementById(formID).submit();
    return true;
  } else {
    return false;
  }
}

/* Функции для бета-версии */

function notReady() {  alert('Извините, данная возможность ещё не реализована.');
  return false;}

function loginTry() {  alert('Извините, возможность регистрации ещё не реализована.');
  return false;}

function searchTry() {
  alert('Извините, возможность расширенного поиска ещё не реализована. Воспользуйтесь простым поиском (нажмите на лупу).');
  return false;
}

/* Конец функций для бета-версии */

function starHighlight(ind) {  for (i = 1; i <= 5; i++) {
    if (ind >= i) {
      starClass = 'star';
    } else {
      starClass = 'star-empty';
    }

    self.document.getElementById('star_' + i).className = starClass;
  }
}

function starLowlight(rating) {  for (i = 1; i <= 5; i++) {
    if (rating >= i - 0.25) {
      starClass = 'star';
    } else {      if (rating >= i - 0.75) {
        starClass = 'star-half-empty';
      } else {        starClass = 'star-empty';      }
    }

    self.document.getElementById('star_' + i).className = starClass;
  }}

function insertText(objectId, text) {
 obj = self.document.getElementById(objectId);

 obj.focus();

 if (document.selection) {
   var s = document.selection.createRange();
   s.text = text;
   s.select();
	 return true;
 } else if (typeof(obj.selectionStart) == "number") {
   var start = obj.selectionStart;
   var end = obj.selectionEnd;

   obj.value = obj.value.substr(0, start) + text + obj.value.substr(end);
   obj.setSelectionRange(end, end);
   return true;
 }

 return false;
}

function submitForm(formID) {
  self.document.getElementById(formID).submit();
}

// Создание нового окна
function popupWindow(URL, name, width, height) {
  var left = parseInt((screen.availWidth/2) - (width/2));
  var top = parseInt((screen.availHeight/2) - (height/2));
  var winFeatures = 'width=' + width + ',height=' + height +
    ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top +
    ',toolbar=no,personalbar=no,location=no,directories=no,statusbar=no' +
    ',menubar=no,status=no,resizable=yes';

  return window.open(URL, name, winFeatures);
}

// Создание окна проигрывателя Rambler
function openRamblerPlayer(URL) {  return popupWindow(URL, 'ramblerAudioPlayer', 390, 100);
}

function enterChat(URL, chatRoomId) {  self.location.href = URL + self.document.getElementById(chatRoomId).value;}

function setRecipient(recipientFieldId, recipientLogin) {  if (self.document.getElementById(recipientFieldId) == null) {    alert('Чтобы оставлять сообщения в чате, необходимо выполнить авторизацию.');
  } else {    self.document.getElementById(recipientFieldId).value = recipientLogin;  }

  return false;}

function chatCheckErrors() {  if ((self.document.getElementById('recipientError').value == '1') ||
    (self.document.getElementById('messageError').value == '1') ||
    (self.document.getElementById('userAccessError').value == '1')) {
    if (self.document.getElementById('userAccessError').value == '1') {
      showElement('userAccessErrorText');
      hideElement('recipientErrorText');
      hideElement('messageErrorText');
    } else {
      hideElement('userAccessErrorText');

      if (self.document.getElementById('recipientError').value == '1') {
        showElement('recipientErrorText');
      } else {
        hideElement('recipientErrorText');
      }

      if (self.document.getElementById('messageError').value == '1') {
        showElement('messageErrorText');
      } else {
        hideElement('messageErrorText');
      }
    }

    showElement('errors');  } else {    hideElement('errors');  }}

function updateColorSelector(selectorId) {  var selector = self.document.getElementById(selectorId);

  selector.style.backgroundColor = '#' + selector.value;

  return true;}