<?php
/**
  @licence GPL 2005-2010  The osCSS developers - osCSS Open Source E-commerce
  @package osCSS-2 <www http://www.oscss.org>
  @version 2.1.0
  @date  05/01/11, 11:51
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
  @brief block in balise html head.
*/

/**
* Placer ici les codes necessitant un chargement entre les balise head de chacune des pages. Ces codes seront chargée systématqiuement, et quelque soit le template
*/

/**
  Framewok
*/
  tep_include_file (DIR_WS_JS."jquery.fancybox/jquery.fancybox.css",true);
  if( ($css=tep_test_gab_ele("jquery-ui",'css')) !=false ) tep_include_file ($css,true);
  tep_include_file (DIR_WS_JS."jquery.dataTables/demo_table_jui.css",true);

  tep_include_file (DIR_WS_JS."jquery.min.js",true);

  tep_include_file ("includes/javascript/jquery-ui.min.js",true);
  tep_include_file ("includes/javascript/jquery.cookie.js",true);
  if ( ($lng=language::LangueSelected()) &&  $lng != 'en') tep_include_file ("includes/javascript/jquery-ui-i18n.min.js",true);

  tep_include_file (DIR_WS_JS."jquery.fancybox.pack.js",true);
  tep_include_file (DIR_WS_JS."jquery.form.js",true);

  tep_include_file (DIR_WS_JS."jquery.dataTables.min.js",true);

  if(defined('JSONSTATMENT')){
    //! plugin add tools table
    if( ($css=tep_test_gab_ele("TableTools",'css')) !=false ) tep_include_file ($css,true);
    tep_include_file (DIR_WS_JS."dataTables.TableTools/ZeroClipboard/ZeroClipboard.js",true);
    tep_include_file (DIR_WS_JS."dataTables.TableTools/js/TableTools.min.js",true);
  }
?>
<script type="text/javascript"><!--

/**  Init page  event js */
function post_load_page(){

  $('form.fancy,form.fancyView').ajaxForm({
    success: function(responseText){
      $.fancybox({'content':responseText});
    }
  });

  //! Fancy exe
  $('a.fancytext').fancybox({'overlayOpacity':0.6});
  $('a.buttonimg.fancy,a.button.fancy,a.buttonimg.fancyView,a.button.fancyView').fancybox({'overlayOpacity':0.6, autoDimensions:false, showCloseButton:false, changeSpeed:0, titleShow:false});

  //! Updat GET
  $('a.buttonimg.fancy,a.button.fancy,form.fancy').each(function(){
      if(this.action !=null) this.action +='&forceajax=true';
      else this.href +='&forceajax=true';
  });
  $('a.buttonimg.fancyView,a.button.fancyView,form.fancyView').each(function(){
      if(this.action !=null) this.action +='&forceview=true';
      else this.href +='&forceview=true';
  });

  // Tabs Exe
  $('#tabs, .tabs').tabs({cookie: {expires:30}}).find('.ui-tabs-nav').sortable({axis:'x'});
  $('.tabs_lang').tabs().find('.ui-tabs-nav').sortable({axis:'x'});

}


$(function() {

  //! slider block tirroir
  $('.tirroir').slideToggle('slow');
  $('h5').click(function () {$(this).next().slideToggle('slow');});
  $('.Ctrtirroir').click(function () {$(this).next().slideToggle('slow');});

  //   Tri de tableau
  <?php if(defined('JSONSTATMENT')) : ?>
  var asInitVals = new Array();

    /**  detail d'une ligne */
    <?php if(defined('AJAXSTATMENTDETAIL')) : ?>
      /* Formating function for row details */
      function fnFormatDetails ( nTr ) {
        var aData = oTable.fnGetData( nTr );

  $.get("<?php echo tep_get_http().DIR_WS_ADMIN ?>ajax.php?<?php echo AJAXSTATMENTDETAIL ?>",
    { 'class': "dataTableInnerHTML",funct: "display_view", action: "detail", forceajax: "true",  ID: aData[0] },
    function(data){
      $('#detail_'+aData[0] ).html(data);
      post_load_page();
    });
      }

      /* Event handler function */
      function fnOpenClose ( oSettings ) {
  $('td img.imgDetail', oTable.fnGetNodes() ).each( function () {
    $(this).click( function () {
      var nTr = this.parentNode.parentNode;
      if ( this.src.match('details_close') )
      {
        /* This row is already open - close it */
        this.src = "<?php echo tep_get_http().DIR_WS_ADMIN.DIR_WS_ICONS ?>details_open.png";
        /* fnClose doesn't do anything for server-side processing - do it ourselves :-) */
        var nRemove = $(nTr).next()[0];
        nRemove.parentNode.removeChild( nRemove );
      }
      else {
        var aData = oTable.fnGetData( nTr );
        /* Open this row */
        this.src = "<?php echo tep_get_http().DIR_WS_ADMIN.DIR_WS_ICONS ?>details_close.png";
        var res = '<table id="detail_'+aData[0] +'" cellpadding="5" cellspacing="0" border="0" style="padding:0 1em; width:100%;">' + '</table>';

        oTable.fnOpen( nTr, res , 'details' );
        fnFormatDetails(nTr);
      }
    });
  });

  post_load_page();
      }

    <?php endif; ?>
    TableToolsInit.sSwfPath="<?php echo  DIR_WS_JS ?>media/swf/ZeroClipboard.swf";

    /* Build the DataTable with third column using our custom sort functions */
    oTable =  $('.dataTable').dataTable( {
      "sDom": '<"top"flp<"toolbar"><"clear">>rt<"bottom"Tilp<"clear">>',
      "bStateSave": true,
      "bPaginate": true,
      "bLengthChange": true,
      "bFilter": true,
      "bSort": true,
      "bInfo": true,
      "bAutoWidth": true,
      "sPaginationType": "full_numbers",
      "bProcessing": true,
      "bServerSide": true,
      "oSearch": { "sSearch": "", "bEscapeRegex": true },
      "oLanguage": {
      "sLengthMenu": "<?php echo sprintf(TEXT_MAXI_ROW_BY_PAGE,"_MENU_")?>",
      "sZeroRecords": "Nothing found - sorry",
      "sInfo": "<?php echo sprintf(TEXT_DISPLAY_NUMBER_OF,"_START_","_END_","_TOTAL_")?>",
      "sInfoEmtpy": "Showing 0 to 0 of 0 records",
      "sInfoFiltered": "<?php echo sprintf(TEXT_FILTRED_ON,"_MAX_")?> ",
      "sSearch": "<?php echo IMAGE_SEARCH ?>",
      "oPaginate": {
	      "sFirst":    "<?php echo FIRST ?>",
	      "sPrevious": "<?php echo PREV  ?>",
	      "sNext":     "<?php echo NEXT ?>",
	      "sLast":     "<?php echo PREVIOUS ?>"
      }
      },
      <?php if( ($col=call_user_func(array(tep_extrac_querystring(JSONSTATMENT,'type'), 'tep_get_modele'))) && is_array($col)): ?>
      "aoColumns": [
  <?php $i=0; foreach($col as $k=>$sort):
        if($sort !=false) echo   ' { "bSortable":    true },'."\n";
        else echo   ' { "bSortable":    false },'."\n";
  $i++; endforeach; ?>
       ],
      <?php endif; ?>
      <?php if(defined('AJAXSTATMENTDETAIL')) : ?>
      "fnDrawCallback": fnOpenClose,
      "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
    /* Append img in row */
    $('td:eq(0)', nRow).html( '<img class="imgDetail" src="<?php echo tep_get_http().DIR_WS_ADMIN.DIR_WS_ICONS ?>details_open.png">' );
    return nRow;
  },
      <?php else: ?>
//       "fnInitComplete":post_load_page(),
      "fnDrawCallback": post_load_page,
      <?php endif; ?>

      "sAjaxSource": "<?php echo tep_get_http().DIR_WS_ADMIN ?>ajax.php?class=dataTableJsonStatment&funct=listItem&forceajax=true<?php echo '&'.JSONSTATMENT ?>",

        "fnServerData": function ( sSource, aoData, fnCallback ) {
    	  <?php if(isset($_REQUEST['sSearch'])): ?>
    	  if(aoData[5].value ==""){
    		    aoData.push( { "name": "sSearch",
              "value": "<?php echo $_REQUEST['sSearch']; ?>" } );
    	  }

        <?php endif; ?>

    	  $.ajax( {
                     "dataType": 'json',
    	               "type": "POST",
    	               "url": sSource,
    	               "data": aoData,
    	               "success": fnCallback
    		           } );
    		       }
      } );


      $('tfoot input').keyup( function () {
  /* Filter on the column (the index) of this element */
        oTable.fnFilter( this.value, $('tfoot input').index(this) );
      });
      /*
  * Support functions to provide a little bit of 'user friendlyness' to the textboxes in
  * the footer
  */
      $('tfoot input').each( function (i) {
        asInitVals[i] = this.value;
      } );

      $('tfoot input').focus( function () {
        if ( this.className == "search_init" ) {
          this.className = "";
          this.value = "";
        }
      });

      $('tfoot input').blur( function (i) {
        if ( this.value == "" ) {
          this.className = "search_init";
          this.value = asInitVals[$('tfoot input').index(this)];
        }
      });


    <?php if(defined('TOOLBAR')) : ?>
      $('div.toolbar').html('<?php echo TOOLBAR ?>');


//       function fnShowHide( iCol ) {
//        var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
//        oTable.fnSetColumnVis( iCol, bVis ? false : true );
//       }
    <?php endif; ?>





  <?php else: ?>
    $('.dataTable').dataTable( {
      "sDom": '<"top"flp<"toolbar"><"clear">>rt',
      "bStateSave": true,
      "bPaginate": false,
      "bLengthChange": false,
      "bFilter": true,
      "bSort": true,
      "bInfo": false,
      "bAutoWidth": false,
      "fnDrawCallback": post_load_page,
  //     "oLanguage": {
  //     "sUrl": "media/language/de_DE.txt"
  //     }
    });

  //init
  post_load_page();
  <?php endif; ?>



});


// --></script>
<?php
/**
    Appel script extension
    ex: echo $oscss->_call('dsrte','_head');
*/
  // editeur wisiwyg
if (isset($oscss))  echo $oscss->_call(BO_WISIWYG_SELECTED,'_head');

/** APPEL FILEBROSWER  */
echo tep_get_filebroswerserveur();
?>