window.addEvent('domready', LCinit);

function LCinit() {
  LCstatus();
  LCstatus.periodical(300000);
}

function LCstatus() {
  new Ajax('/livechat/s/'+$random(1,100000)+'/', {
    method: 'get',
    onComplete: function(t) { if(t==1) $('livechat').addClass('live'); else $('livechat').removeClass('live'); }
  }).request();
}

function pimpa(i) {
  var p = $(i).getParent().getNext();
  if(p.getTag()!='span') return;
  p.setStyle('display', (p.getStyle('display').toLowerCase() == 'none' ? 'block' : 'none'));
}

function openlive() {
  window.open('http://livechat.profoto.by','livechat','scrollbars=yes,resizable=yes,width=400,height=350');
  return false;
}

function loadFeedBack(a) {
  a = $(a);
  new Ajax('/feedback/', {
    method: 'get',
    onComplete: function(t) {
      loadingp(0);
      return function(t, a) {
        var f=$('helperform');
        if(f) f.remove();
        f = new Element('div',{id:'helperform',styles:{position:'absolute',left:(a.getLeft()-24)+'px',top:(a.getTop()+10)+'px'}}).setHTML(t).inject('loading','after');
      }(t,a);
    }
  }).request();
  loadingp(1, a.getLeft()+50, a.getTop()-60);
}
function feedback(form) {
  form = $(form);
  var proposal = form.getElement('[name=proposal]')
  if(proposal.getValue() == '') {
    alert('Заполните Ваше предложение');
    proposal.focus();
    return false;
  }
  form.send({
    onComplete: function(d) {
      return function(d,f) {
        f.setHTML(d);
      }(d,form);
    }
  });
  return false;
}
