function addToBasket($idItem,$isbn)
{	
	var xmlHttp = createXmlHttpRequestObject()
	xmlHttp.open("GET", "ajax/addToBasket.php?idItem="+ $idItem +'&isbn='+ $isbn,false);   
    xmlHttp.send(null);    
    //alert("товар добавлен в корзину");
    if(xmlHttp.status == 200) 
      {                                  
        sElem = document.getElementById("addToBasket_button_"+$idItem)
	    sElem.innerHTML = '<div id="addToBasket_button_"'+ $idItem +'"><input type="button" style="margin-left:10px;width:150px;" class="button_inactive" value="Уже в корзине" /></div>'
	    updateCount();
      }  
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////// ФУНКЦИЯ ДОБАВЛЕНИЯ ТОВАРА ИЗ ПОЛНОГО ОПИСАНИЯ КНИГИ
////////////////////////////////////////////////////////////////////////////////////////////////////////
function addToBasketFull($idItem,$isbn)
{
  var xmlHttp = createXmlHttpRequestObject()
  xmlHttp.open("GET", "ajax/addToBasket.php?idItem="+ $idItem +'&isbn='+ $isbn,false);   
  xmlHttp.send(null);    
  alert("товар добавлен в корзину");
  if(xmlHttp.status == 200) 
  {                                  
    sElem = document.getElementById("addToBasket_button_"+$idItem)
    sElem.innerHTML = '<div id="addToBasket_button_"'+ $idItem +'"><input type="button" class="button_inactive" style="margin-top:20px;margin-bottom:5px;height:40px;width:160px;" value="Уже в корзине" /></div><a href="index.php?flag=basket">Кол-во товаров изменяется в корзине</a>'
    updateCount();
  }      
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////// ФУНКЦИЯ ДОБАВЛЕНИЯ ПРЕДЗАКАЗА
////////////////////////////////////////////////////////////////////////////////////////////////////////
function preorder()
{
    var xmlHttp = createXmlHttpRequestObject()
    name = document.getElementById("user_name").value    
    phone = document.getElementById("phone").value    
    email = document.getElementById("email").value    
    description = document.getElementById("description").value    
    number = document.getElementById("number").value    
    ean = document.getElementById("ean").value    
    
    xmlHttp.open("GET", "ajax/preorder.php?name="+encodeURIComponent(name)+"&phone="+encodeURIComponent(phone)+"&email="+encodeURIComponent(email)+"&description="+encodeURIComponent(description)+"&number="+number+"&ean="+ean,false);   
    xmlHttp.send(null);    
    if(xmlHttp.status == 200) 
    {
      alert(xmlHttp.responseText);
    }
}

  function updateCount()
  {
  	var xmlhttp = createXmlHttpRequestObject()
    xmlhttp.open("GET", "ajax/countItemBasket.php",false);
    xmlhttp.send(null); 
    if(xmlhttp.status == 200) 
      {  
   	    basketCountUp.innerHTML = '<div id="coo">Товаров: <b>'+xmlhttp.responseText+' шт.</b></div>'
      }
  }
  
  function go_order()
  {
  	if(document.getElementById('error'))
    { 
      alert("неправильно заполнено поле количества товара");     
    } 
    else
    {    	    	
    	window.location = url_to_order;
    }
  	
  }
  
  function go_order_no_login()
  {
  	if(document.getElementById('error'))
    { 
      alert("неправильно заполнено поле количества товара");     
    } 
    else
    {    	    	
    	window.location = url_to_order_no_login;
    }
  	
  }
    
   // var sesxmlHttp = createXmlHttpRequestObject();  
 
 /* 
  function displayCustomerInfo(sText,sId) {
   sElem = document.getElementById("countOrder"+sId)   
   sElem.innerHTML = sText
  }*/  
   
  function getRequest(sId,idUser) 
  {    	
   var xmlHttp = createXmlHttpRequestObject()
   var countOrder = document.getElementById("countOrder"+sId).value         	    
   xmlHttp.open("GET", "ajax/basket.php?id="+sId+"&count="+countOrder,false);   
   xmlHttp.send(null); 
     if(xmlHttp.status == 200) 
     {         	      
      getCountProduct();      
      getSumProduct(sId);       
      getFullSumOrder(idUser);       
      checkNumberSession(sId,countOrder);
     } 
  }
  
    
  function getCountProduct()
  {
  	var xmlHttp = createXmlHttpRequestObject()
    xmlHttp.open("GET", "ajax/count.php",false);
    xmlHttp.send(null); 
    if(xmlHttp.status == 200) 
     {        	  
   	  countOrderInBasket.innerHTML = xmlHttp.responseText  
   	  basketCountUp.innerHTML = "Товаров: <b>"+xmlHttp.responseText+"</b>"	 
     }    
  }
  
  
  function getSumProduct(sId)
  {
  	 var xmlhttp = createXmlHttpRequestObject()
  	 xmlhttp.open("GET", "ajax/sumProduct.php?id="+sId,false);
  	 xmlhttp.send(null);
     if(xmlhttp.status == 200) 
       {   	
  	 	  displaySumProduct(xmlhttp.responseText,sId);
       }
  }
  
  function displaySumProduct(sText,sId)
  {
  	sElem = document.getElementById("sumProduct"+sId)
  	sElem.innerHTML = sText
  }
  
  function getFullSumOrder(idUser)
  {  	
  	var xmlhttp = createXmlHttpRequestObject()
  	xmlhttp.open("GET", "ajax/ajax.php?flag=basketSessionFullSumOrder",false);
    xmlhttp.send(null);
  	if (xmlhttp.status == 200)
  	  {
  		displayFullSumOrder(xmlhttp.responseText);
  	  }  	  	
  }
  
  function displayFullSumOrder(sText)
  { 	
  	sElem = document.getElementById("fullSumOrder")
  	sElem.innerHTML = sText 
  	sElem = document.getElementById("fullSumOrder")
  	sElem.innerHTML = "Сумма: <b>"+sText+"</b>"
  	//alert("ya");
  }
  
////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////// ФУНКЦИЯ ОЧИСТКИ КОРЗИНЫ
////////////////////////////////////////////////////////////////////////////////////////////////////////
  function cleanBasket()
  {
	var xmlHttp = createXmlHttpRequestObject()
	xmlHttp.open("GET", "ajax/ajax.php?flag=cleanBasket",false);
	xmlHttp.send(null);   	
	displayEmptyBasket();    	   
  }

  function displayEmptyBasket()
  {		
	allBasket.innerHTML = "<table  id='allBasket' border='0' width='100%' cellpadding='0' cellspacing='0'><tr bgcolor='#239DDC' height='30px' align='center' style='color:white;font-weight:bold;'><td colspan='2'>наименование заказа</td><td>количество</td><td>цена, руб.</td><td width='100'>сумма, руб.</td><td>удалить</td></tr><tr><td colspan='6'><div class='basket_is_empty'>В корзине пока пусто</div></td></tr>"	
  }
  

////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////// ФУНКЦИЯ УДАЛЕНИЯ ТОВАРА
////////////////////////////////////////////////////////////////////////////////////////////////////////
  function deleteFromBasket(sId)
  {	
  var xmlHttp = createXmlHttpRequestObject()	
  xmlHttp.open("GET", "ajax/ajax.php?flag=deleteFromBasket&id="+sId,false);
  xmlHttp.send(null);
  if (xmlHttp.status == 200)
    {  	    		  	
       displayDeleteProduct(xmlHttp.responseText,sId);
  	   getBasketSessionFullSum();
  	   getBasketSessionCountProduct();  		  	 
    }
  
  }

  function displayDeleteProduct(sText,sId)
  {
	//alert(sId);	
	sElem = document.getElementById("delete"+sId+"_1")
	sElem.innerHTML = sText
	sElem = document.getElementById("delete"+sId+"_2")
	sElem.innerHTML = sText
	sElem = document.getElementById("delete"+sId+"_3")
	sElem.innerHTML = sText
	sElem = document.getElementById("delete"+sId+"_4")
	sElem.innerHTML = sText
	sElem = document.getElementById("delete"+sId+"_5")
	sElem.innerHTML = sText
	sElem = document.getElementById("delete"+sId+"_6")
	sElem.innerHTML = sText
	sElem = document.getElementById("delete"+sId+"_7")
	sElem.innerHTML = sText
  }
  
  /*СОХРАНЕНИЕ ИЗМЕНЕНИЙ ЗАКАЗА В АДМИНКЕ*/
  function saveOrder(id)
  {
    var xmlHttp = createXmlHttpRequestObject()	
    status_order = document.getElementById("status_order_"+id).value    
    delivery = document.getElementById("delivery_"+id).value    
    notation = document.getElementById("notation_"+id).value    
    payment = document.getElementById("payment_"+id).value     
          
    xmlHttp.open("GET", "../ajax/save_order.php?id="+id+"&status_order="+status_order+"&delivery="+delivery+"&notation="+notation+"&payment="+payment,false);
    xmlHttp.send(null);
    
    if (xmlHttp.status == 200)
    { /*         
      if (status_order == 5)
      {         
  	    document.getElementById("item_1_"+id).innerHTML = ""
  	    document.getElementById("item_2_"+id).innerHTML = ""
  	    document.getElementById("item_3_"+id).innerHTML = ""  	    
  	    alert(xmlHttp.responseText);
      }
      if (status_order == 6)
      {        
        document.getElementById("item_1_"+id).innerHTML = ""
  	    document.getElementById("item_2_"+id).innerHTML = ""
  	    document.getElementById("item_3_"+id).innerHTML = ""  	            
  	    alert(xmlHttp.responseText);
      }
      if (status_order == 7)
      {       
        document.getElementById("item_1_"+id).innerHTML = ""
  	    document.getElementById("item_2_"+id).innerHTML = ""
  	    document.getElementById("item_3_"+id).innerHTML = ""
  	    document.getElementById("item_4_"+id).innerHTML = ""
  	    document.getElementById("item_5_"+id).innerHTML = ""
  	    document.getElementById("item_6_"+id).innerHTML = ""
  	    document.getElementById("item_7_"+id).innerHTML = ""
  	    document.getElementById("item_8_"+id).innerHTML = ""
  	    document.getElementById("item_9_"+id).innerHTML = ""
  	    alert(xmlHttp.responseText);
      } */    
        alert(xmlHttp.responseText);
    }
    
  }
  
  /*СОХРАНЕНИЕ ВВЕДЁНЫЙ ЛОГИН И ПАРОЛЬ В СЕССИЮ*/
  function check_login()
  {
      var xmlHttp = createXmlHttpRequestObject()
      name = document.getElementById("name").value    
      password = document.getElementById("password").value  
      xmlHttp.open("GET", "ajax/check_login.php?name="+encodeURIComponent(name)+"&password="+encodeURIComponent(password),false);
      xmlHttp.send(null);
  }
  
  /*СОХРАНЕНИЕ ВВЕДЁНЫЙ ЛОГИН И ПАРОЛЬ В СЕССИЮ*/
  function check_login_2()
  {
      var xmlHttp = createXmlHttpRequestObject()
      name = document.getElementById("name_2").value    
      password = document.getElementById("password_2").value  
      xmlHttp.open("GET", "ajax/check_login.php?name="+encodeURIComponent(name)+"&password="+encodeURIComponent(password),false);
      xmlHttp.send(null);
  }
  
  /*СОХРАНЕНИЕ ПЕРСОНАЛЬНЫХ ДАННЫХ В СЕССИЮ*/
  function save_personal_data()
  {
      var xmlHttp = createXmlHttpRequestObject()
      name = document.getElementById("name").value    
      surname = document.getElementById("surname").value    
      phone = document.getElementById("phone").value    
      adres = document.getElementById("adres").value    
      town = document.getElementById("town").value   
      xmlHttp.open("GET", "ajax/check_personal_data.php?name="+encodeURIComponent(name)+"&surname="+encodeURIComponent(surname)+"&phone="+encodeURIComponent(phone)+"&adres="+encodeURIComponent(adres)+"&town="+encodeURIComponent(town),false);
      xmlHttp.send(null);
  }
  
