
function AddToCart (tov_id) {
	CartListUpdate('add', tov_id);
};


function DelFromCart (tov_id) {
	CartListUpdate('del', tov_id);
};


function NotifyTovAvailable (tov_id) {	
	var el = document.getElementById('TR_NotifyTovAvailable');
	var email = prompt('Сообщить на Email:', '');
	
	if (! email) { return; };
	
	var Ob = GetAjaxObj();    
  Ob.open('POST', '/index.cgi', true);
  Ob.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  
  Ob.onreadystatechange = function() {
      if (Ob.readyState == 4) {
          if (el) el.style.display = 'none';
      };
  };
  
  Ob.send('action=ajax|notify_tov_available&ID=' + escape(tov_id) + '&email=' + escape(email));
};


function CartListUpdate (operation, tov_id) {	
	var el = document.getElementById('CART_LOADING');
	if (el) el.style.display = '';
	
	var Ob = GetAjaxObj();    
  Ob.open('POST', '/index.cgi', true);
  Ob.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  
  Ob.onreadystatechange = function() {
      if (Ob.readyState == 4) {
          CartListUpdate_data(Ob.responseText);
      };
  };
  
  Ob.send('action=ajax|cart_data&op=' + escape(operation) + '&ID=' + escape(tov_id));
};

function CartListUpdate_data (resp_text) {
	var el = document.getElementById('CART');
	var res = AjaxGetResult(resp_text);
	if (el) el.innerHTML = res;
	
	var el_loading = document.getElementById('CART_LOADING');
	if (el_loading) el_loading.style.display = 'none';
};


function ShowCartRowOptions (tov_id) {
	var el = document.getElementById('CART_TOV_' + tov_id);
	if (el) el.style.display = '';
};

function HideCartRowOptions (tov_id) {
	var el = document.getElementById('CART_TOV_' + tov_id);
	if (el) el.style.display = 'none';
};
