<?php
include_once(_DIR_TO_CLASS.'/c_page.php') ;
class c_page_cab_test_window extends c_page
{
  public $h1='Тестирование открытия дополнительных окон' ;
    public $free_access=1 ;


  function block_main()
  {
      $this->page_title() ;
      if (!$this->filter['width']) $this->filter['width']=1920 ;
      if (!$this->filter['height']) $this->filter['height']=1000 ;
      if (!$this->filter['left']) $this->filter['left']=0 ;
      if (!$this->filter['top']) $this->filter['top']=0 ;

      ?><script type="text/javascript">
          $j('a.new_window2').on('click',function()
          {   var width=<?echo $this->filter['width'];?> ;
              var height=<?echo $this->filter['height'];?> ;
              var left=<?echo $this->filter['left'];?> ;
              var top=<?echo $this->filter['top'];?> ;
              var str='width='+width+',height='+height+',left='+left+',top='+top ;
              $j('#debug').val(str) ;
              var newWin=window.open($j(this).attr('href'),$j(this).attr('title'),'status=1,dependent=1,'+str+', resizable=1, scrollbars=yes') ;
              newWin.focus() ;
              return(false) ;
          }) ;

          $j('a.new_window_center').on('click',function()
          {   var width=<?echo $this->filter['width'];?> ;
              var height=<?echo $this->filter['height'];?> ;
              var str=popup_params(width,height) ;
              $j('#debug').val(str) ;
              var newWin=window.open($j(this).attr('href'),$j(this).attr('title'),'status=1,dependent=1,'+str+', resizable=1, scrollbars=yes') ;
              newWin.focus() ;
              return(false) ;
          }) ;

          $j('a.new_window_full').on('click',function()
          {   var width=window.screen.width ;
              var height=window.screen.height ;
              var left=<?echo $this->filter['left'];?> ;
              var top=<?echo $this->filter['top'];?> ;
              var str='width='+width+',height='+height+',left='+left+',top='+top ;
              $j('#debug').val(str) ;
              var newWin=window.open($j(this).attr('href'),$j(this).attr('title'),'status=1,dependent=1,'+str+', resizable=1, scrollbars=yes') ;
              newWin.leftWindowBoundry = -left ; // делаем смещение для окна
              newWin.focus() ;
              return(false) ;
          }) ;


          function popup_params(width, height) {
              var a = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft;
              var i = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop;
              var g = typeof window.outerWidth!='undefined' ? window.outerWidth : document.documentElement.clientWidth;
              var f = typeof window.outerHeight != 'undefined' ? window.outerHeight: (document.documentElement.clientHeight - 22);
              var h = (a < 0) ? window.screen.width + a : a;
              var left = parseInt(h + ((g - width) / 2), 10);
              var top = parseInt(i + ((f-height) / 2.5), 10);
              var str= 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',scrollbars=1';
              console.log(str) ;
              return(str) ;
          }

        </script>

     <div id="panel_filter">
          <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo _CUR_CAB_DIR?>">
               <fieldset>
                   <div class="row">
                       <section class="col col-1">
                          <label class="label">width</label>
                          <label class="input">
                              <input type="text" name="filter[width]" value="<?echo $this->filter['width']?>">
                          </label>
                       </section>
                       <section class="col col-1">
                           <label class="label">height:</label>
                           <label class="input">
                               <input type="text" name="filter[height]" value="<?echo $this->filter['height']?>">
                           </label>
                       </section>
                       <section class="col col-1">
                           <label class="label">left:</label>
                           <label class="input">
                               <input type="text" name="filter[left]" value="<?echo $this->filter['left']?>">
                           </label>
                       </section>
                       <section class="col col-1">
                           <label class="label">top:</label>
                           <label class="input">
                               <input type="text" name="filter[top]" value="<?echo $this->filter['top']?>">
                           </label>
                       </section>
                   </div>
               </fieldset>
              <div id="panel_buttons"><input type="submit" class="button v2" cmd="set_filter" value="Применить"></div>
           </form>
        </div>
        <ul>
            <li><a href="" class="new_window2" title="test2">Открыть окно заданных размеров по указанной позиций </a></li>
            <li><a href="" class="new_window_center" title="test2">Открыть окно заданных размеров по центру</a></li>
            <li><a href="" class="new_window_full" title="test2">Открыть окно на весь экран</a></li>
        </ul>
      <br>
        <textarea id="debug" style="width:800px;height:50px;"></textarea>
      <?
  }
}




?>