
var fxDelay = 750;
var effects = true;

function showResponse(req)
{
   html = req.responseXML.getElementsByTagName('html');
   $('cart').innerHTML = html[0].childNodes[0].data;
   
   msg = req.responseXML.getElementsByTagName('msg');
   if(msg) {
      alert(msg[0].childNodes[0].data);
   }
}
function addToCart(id, refresh) {
   quantity = $('ic' + id).value;
   if(quantity == '') quantity = '1';
   quantity = parseInt(quantity);
   var url = '/ajax/cart_add/' + id + '/' + quantity + '/' + refresh;
   if(!isNaN(quantity)) { 
      var myAjax = new Ajax.Request(
         url, 
         {
            method: 'post', 
            onComplete: showResponse
         });
      $('ic' + id).value = quantity;
   } else {
      alert('Įveskite skaičių');
      return false;
   }
   return false;   
}

function addToCart1(id, refresh) {
   quantity = $('ic' + id).value;
   if(quantity == '') quantity = '1';
   quantity = parseInt(quantity);
   if(!isNaN(quantity)) { 
      new Ajax.Updater('cart', '/ajax/cart_add/' + id + '/' + quantity + '/' + refresh, {asynchronous:true, onComplete: showResponseMsg});
      
      if(effects) {
         var cartfx = new fx.Opacity('cart', {duration: fxDelay});
         cartfx.custom(0, 1);
      }
      $('ic' + id).value = quantity;
      Element.setStyle('ic' + id, {borderColor:'#090', backgroundColor:'#f3f3f3'} );
   } else {
      alert('Įveskite skaičių');
      return false;
   }
   return false;   
}

function emptyCart(id) {
   new Ajax.Updater('cart', '/ajax/cart_empty', {asynchronous:true});
   if(effects) {
      cartfx = new fx.Opacity('cart', {duration: fxDelay});      
      cartfx.custom(0, 1);
   }
   return false;   
}

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
    window.location.reload();
}

function popup(url) 
{
   w = 450;
   h = 550;
   x = (screen.availWidth - w) / 2;
   y = (screen.availHeight - h) / 2 - 32;
   eval("page = window.open('/pop.php?u='+url, '', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + w + ",height=" + h + "')");
   page.document.close();
   page.moveTo(x, y);
   page.focus();  		
   return false;
}
