function getAjax(){
  if (window.ActiveXObject) { // для IE 
     return new ActiveXObject("Microsoft.XMLHTTP");
  } else if (window.XMLHttpRequest){
     return new XMLHttpRequest();
  } else {
     alert("Browser does not support AJAX.");
     return null;
    }
}
function loadcards(cid){
  document.getElementById('cards').style.display="block";
  document.getElementById('wrapper').style.filter="alpha(opacity=50)";
  document.getElementById('wrapper').style.opacity="0.5";
    ajax=getAjax();
      if (ajax != null) {    
        ajax.open("GET", "include/shop.php?cid="+cid,true);
        ajax.send(null);
        ajax.onreadystatechange = function(){
          if (ajax.responseText == "false"){
             alert('Произошол сбой при добавление товара, попробуйте добавить товар позднее.');
          }
        }
      }
  setTimeout("niloop()", 3000);
}

function loadcards2(cid){
  document.getElementById('cards').style.display="block";
  document.getElementById('wrapper').style.filter="alpha(opacity=50)";
  document.getElementById('wrapper').style.opacity="0.5";
    ajax=getAjax();
      if (ajax != null) {    
        ajax.open("GET", "include/shop.php?cid="+cid,true);
        ajax.send(null);
        ajax.onreadystatechange = function(){
          if (ajax.responseText == "false"){
             alert('Произошол сбой при добавление товара, попробуйте добавить товар позднее.');
          }else{
			location.replace("/bag.php");
		  }
        }
		
      }
  setTimeout("niloop()", 3000);
}

function niloop(){
  show_ajax1('count_item','count');
  show_ajax('count_price','price');
  document.getElementById('cards').style.display="none";
  document.getElementById('wrapper').style.filter="100";
  document.getElementById('wrapper').style.opacity="100";
}

function show_ajax(IDC,ACT){
  aja=getAjax();
    if (aja != null) {    
    aja.open("GET", "include/shop.php?action="+ACT,true);
    aja.send(null);
    aja.onreadystatechange = function(){
      document.getElementById(IDC).innerHTML=aja.responseText;
    }
  }
}
function show_ajax1(IDC,ACT){
  ajax=getAjax();
    if (ajax != null) {    
    ajax.open("GET", "include/shop.php?action=count",true);
    ajax.send(null);
    ajax.onreadystatechange = function(){
      document.getElementById('count_item').innerHTML=ajax.responseText;
    }
  }
}
