function tipAuth() {
  Tips.hideAll();
  var menu = $('signin_menu');
  if (menu.hasClassName('offscreen')) {
	menu.toggleClassName('offscreen');
	$$('.header li.cabinet-list-item').first().toggleClassName('current');
  }
}

RelationForm = {
  init: function() {
	var tip_params = {
	  title: "Ошибка",
	  showOn: 'click',
	  hideOn: {element: 'closeButton', event: 'click'},
	  fixed: true,
	  hideOthers: true,
	  stem: 'bottomRight',
	  hook: {target: 'topMiddle', tip: 'bottomRight'}
	};

	var buytton_tooltip = $('buytton-tooltip');
	if (buytton_tooltip) {
	  $$('.buytton').each(function(el) {
		new Tip(el, buytton_tooltip.innerHTML, tip_params);
	  });
	} else {
	  $$('.buytton').invoke('observe', 'click', this.click.bindAsEventListener(this));
	}
	$$('.ware-qty input').invoke('observe', 'change', this.change.bindAsEventListener(this));
	this.counter = $('shopping-cart-ware-counter');
  },
  click: function(e) {
	e.stop();
	var el = e.element();
	var amount = el.up('td').previous().previous().down('input').getValue();
	var form = $$('.shopping-cart-relation-create').first();
	var amountInput = form.down('input');
	amountInput.setValue(amount);
	amountInput.next('input').setValue(el.up('tr').readAttribute('id'));
	if (el.hasClassName('add_once')) {
	  form.submit();
	} else {
	  form.request({
		onCreate: this.loading.bind(XMLHttpRequest, el.next(), el),
		onComplete: this.complete.bind(XMLHttpRequest, el.next(), el),
		onSuccess: this.success.bind(this, el.up('.ware-buyit'))
	  });
	}
  },
  loading: function(loader, target, request) {
	target.hide();
	loader.show();
  },
  complete: function(loader, target, request) {
	loader.hide();
	target.show();
  },
  success: function(target, response) {
	var new_counter = response.getHeader('Shopping-Cart-Ware-Counter');
	if (new_counter) {
	  this.counter.update(new_counter);
	  target.update(response.responseText)
	} else {
	  target.down('.buytton').setStyle({backgroundImage: "url(/images/error.png)"}).setAttribute('title', response.responseText);
	}
	//this.highlight.defer();
  },
  highlight: function() {
	  $('buy-success').highlight();
  },
  change: function(e) {
	e.stop();
	var el = e.element();
	var text = el.up('td').previous(1).innerHTML;
	var priceTextArray = text.split(' ');
	var price = parseInt(priceTextArray[0]);
	var val = el.getValue();
	if ((val > 0) && (Math.floor(val) == val)) {
	  priceTextArray[0] = price * val;
	} else {
	  priceTextArray[0] = parseInt(el.up('td').next().innerHTML);
	}
	text = '';
	for (var i=0; i<priceTextArray.length; i++) {
	  text += ' '+priceTextArray[i];
	}
	el.up('td').next().update(text);
  }
};

document.observe('dom:loaded', RelationForm.init.bind(RelationForm));

