/*
  Çàãðóçêà... Ïîäîæäèòå...
*/
window.onload = function() {
	var loader = document.getElementById('loader');
	if (loader) {
		loader.parentNode.removeChild(loader);
	}
};

var buffer = null;

var wu = {

  Ajax: function (url, log, loading, complete) {
    var log = $(log).addClass('ajax-loading');
    var req = new Ajax(url, {
                    method: 'get',
                    update: log,
                    onComplete: function () {
                      if (loading) log.removeClass('ajax-loading');
                      if (complete != '') complete();
                      buffer = null;
                    }
                  }).request();
  },
  
  AjaxTimed: function (interval, url, log, loading, complete) {
    var log = $(log).addClass('ajax-loading');
    var action = function () {
      wu.Ajax(url, log, loading, complete);
    }
    buffer = (buffer == null) ? setTimeout(action, interval) : buffer;
  },
  
  buildOptions: function (defValue, defText, items, element) {

    element.empty();
    element.options[0] = new Option(defText, defValue);
    if (items.value != 0) {
      for (var i = 0; i < items.length; i++) {
        element.options[i+1] = new Option(items[i].name, items[i].id);
      }
    }

  }

};

/*
  ÎÁÍÎÂËÅÍÈÅ ÑÎÄÅÐÆÈÌÎÃÎ
*/
function contentUpdate(url, place, loading) {
  var place = $(place).addClass('ajax-loading');
  new Ajax(url, {
    method: 'get',
    update: place,
    onComplete: function (response) {
      if (loading) place.removeClass('ajax-loading');
    }
  }).request();
}

/*
  ÄÎÁÀÂËÅÍÈÅ ÍÎÂÎÃÎ ÏÎËÜÇÎÂÀÒÅËß
*/
window.addEvent('domready', function() {
  Check.start();
});

var Check = {
  
  start: function() {
    if ($('search_string')) Check.getUserByName($('search_string'));
    if ($('search_participants')) Check.getParticipantsByName($('search_participants'));
  },
  
  getUserByName: function (el) {
    el.addEvent('keyup', function(e) {
      var value = el.getValue();
      if (value.length > 2) {
        wu.Ajax('/2009/system/library/manage.user/remote.get.users.php?search=' + value, 'search_result', true, '');
      }
    });
  },
  
  getParticipantsByName: function (el) {
    el.addEvent('keyup', function(e) {
      var value = el.getValue();
      if (value.length > 2) {
        wu.Ajax('/2009/system/remote/search.participants.php?search=' + value, 'search_result', true, '');
      }
    });
  }
};

/*
  ÎÒÎÁÐÀÆÅÍÈÅ/ÇÀÊÐÛÒÈÅ ÊÀÊÎÃÎ-ËÈÁÎ ÎÊÍÀ
*/
function openWindow(action, rocid) {
    $('openWindow_' + rocid).setStyle('display', (action == 'show') ? 'block' : 'none');
}

/*
  ÄÐÅÂÎÂÈÄÍÀß ÑÒÐÓÊÒÓÐÀ Â ÑÏÈÑÊÅ ÊÎÌÏÀÍÈÉ
*/
function staff(id, show){
  $("staffOpen_" + id).setStyle('display', (show) ? 'none' : 'block');
  $("staffClose_" + id).setStyle('display', (show) ? 'block' : 'none');
  $("staff_" + id).setStyle('display', (show) ? 'block' : 'none');
}