<?php
/**
  @licence GPL 2005-2011  The osCSS developers - osCSS Open Source E-commerce
  @portion code Copyright (c) 2002 osCommerce
  @package osCSS-2 <www http://www.oscss.org>
  @version 2.1.0
  @date  29/01/11, 11:25
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
*/
if(_cst_bool('AJAX_CART_MODE')) { ?>
  <script type="text/javascript">
  <!--/*--><![CDATA[//><!--
  function writebox(total_articles, total_box) {
      document.getElementById('ajaxcartSubTotal').innerHTML = '<?php echo '<a href="'.tep_href_link(FILENAME_SHOPPING_CART).'">'; ?>'+total_articles+'<?php echo ' '.SHOPPING_CART_PRODUCTS_NBS.'<br />'.SHOPPING_CART_TOTAL.' '; ?>'+total_box+'<?php echo '</a>'; ?>';
  }

  var cartidcorrectif = 0;
  var cartidhystory = new Array('0');
  function writedel(text, cart_id) {
          var cartDelId = 'ajaxcartProduct'+cart_id;
          document.getElementById(cartDelId).innerHTML = '';
          document.getElementById('ajaxcartSubTotal').innerHTML = '<?php echo '<span>' . SUB_TITLE_SUB_TOTAL .'</span> '; ?>'+text;
          this.cartidcorrectif++;
          this.cartidhystory.push(cart_id);
  }

  function changecartdel(cart_id) {
      if (confirm ("<?php echo TEXT_CART_DEL_CONFIRM; ?>")){
          cartidcorrection = cart_id;
          for ( i=0; i<this.cartidcorrectif; i++ ) {
              if ( this.cartidhystory[i+1] < cart_id ) {
                  cartidcorrection--;
              }
          }
          if(textdel = file('<?php echo tep_href_link('ajax_exe.php', 'action=shopping_cart').'&'; ?>cart_id='+escape(cartidcorrection))){
              updatedel = textdel.split('|');
              writebox(updatedel[0],updatedel[1]);
              writedel(updatedel[1], cart_id);
          }
      } else {
          var cartCheckId = 'cart_delete'+cart_id;
          eval("document.getElementById('cart_quantity')."+cartCheckId+".checked = false;");
      }
  }

  function writeqty(texte1, texte2, cart_id) {
      var cartPriceId = 'ajaxcartPrice'+cart_id;
      document.getElementById(cartPriceId).innerHTML = texte1;
      document.getElementById('ajaxcartSubTotal').innerHTML = '<?php echo '<span>' . SUB_TITLE_SUB_TOTAL .'</span> '; ?>'+texte2;
  }

  function changecartqty(cart_id) {
      var cartQtyId = 'cartQty'+cart_id;
      // var cartQty = document.getElementById('cart_quantity').eval(cartQtyId).value;
      eval("var cartQty = document.getElementById('cart_quantity')."+cartQtyId+".value;");
      if ( cartQty > 0) {
          cartidcorrection = cart_id;
          for ( i=0; i<this.cartidcorrectif; i++ ) {
              if ( this.cartidhystory[i+1] < cart_id ) {
                  cartidcorrection--;
              }
          }
          if(texte = file('<?php echo tep_href_link('ajax_exe.php', 'action=shopping_cart').'&'; ?>cart_id='+escape(cartidcorrection)+'&'+'product_qty='+eval(cartQty))){
              update = texte.split('|');
              writebox(update[0],update[2]);
              writeqty(update[1],update[2], cart_id);
          }
      }
  }

  //--> <!]]>*/
  </script>
<?php  } ?>