function send_http_request(args) {
 args = args || {};

 var is_timed_out = false;
 var timer = null;

 if (args.timeout) {
  timer = setTimeout(function () {
   is_timed_out = true;
   if (args.ontimeout) {
    args.ontimeout();
   }
   if (args.onfail) {
    args.onfail();
   }
   if (args.onfinish) {
    args.onfinish();
   }
  }, args.timeout);
 }

 var xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");

 xmlhttp.onreadystatechange = function () {
  if ((!is_timed_out) && (xmlhttp.readyState == 4)) {
   clearTimeout(timer);
   timer = null;
   if (xmlhttp.status == 200) {
    if (args.ontextready) {
     args.ontextready(xmlhttp.responseText);
    }
    if (args.ondataready) {
     var data = eval('res=' + xmlhttp.responseText + ';res');
     args.ondataready(data);
    }
    if (args.onfinish) {
     args.onfinish();
    }
   } else {
    if (args.onerror) {
     args.onerror(xmlhttp.status, xmlhttp.responseText);
    }
    if (args.onfail) {
     args.onfail();
    }
    if (args.onfinish) {
     args.onfinish();
    }
   }
  }
 };

 xmlhttp.open(args.method||'GET', args.url, args.async||true, args.user, args.passwd);
 xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
 xmlhttp.send(args.data||null);
}

function add_item(key, qty) {
var key = parseInt(key);
var qty = parseInt(qty);
send_http_request({
 url: '/catalog/add/'+key+'/'+qty+'/',
 timeout: 30000,
 method: 'GET',
 async: false,
 ontextready: function(response_text) {
    document.getElementById("info_"+key).style.display = '';
 }
 
});



return false;

}

function remove_item(key) {
var key = parseInt(key);
send_http_request({
 url: '/catalog/del/'+key+"/",
 timeout: 30000,
 method: 'GET',
 async: false,
 ontextready: function(response_text) {
    document.getElementById('row_'+key).style.display ="none";
    update_goods_info()
 }
 
});
return false;

}

function update_goods_info() {
send_http_request({
 url: '/catalog/price/',
 timeout: 30000,
 method: 'GET',
 async: false,
 ontextready: function(response_text) {
        obj = document.getElementById('full_price');
        if (obj) {
            obj.innerHTML = response_text+" á??Á.";
            if (parseInt(response_text) == 0) {
                obj = document.getElementById('order_link');
                if (obj) {
                    obj.innerHTML = '';
                    obj.style.display = 'none';
                }
            }
        }
    }
 
});

return false
}

function save_count(key, qty) {
var key = parseInt(key);
var qty = parseInt(qty);
if (qty == 'Nan') qty = 1;
send_http_request({
 url: '/catalog/del/'+key+'/',
 timeout: 30000,
 method: 'GET',
 async: false,
 ontextready: function(response_text) {
 }
});
send_http_request({
 url: '/catalog/add/'+key+'/'+qty+'/',
 timeout: 30000,
 method: 'GET',
 async: false,
 ontextready: function(response_text) {
    update_goods_info();
 }
 
});



return false;

}

