<script type="text/javascript" src="/libraries/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/libraries/ckeditor/adapters/jquery.js"></script>
<script type="text/javascript" src="/libraries/jquery/sortable/sortable.js"></script>
<?
global $db;

ob_start();
?>
  <div id="settings-tabs">
    <ul class="resp-tabs-list settings-tabs">
      <li><i class="fa fa-file"></i>Treść</li>
      <li><i class="fa fa-wrench"></i>Ustawienia</li>
      <li><i class="fa fa-globe"></i>SEO</li>
      <li><i class="fa fa-share-alt"></i>Wyświetlanie</li>
      <li><i class="fa fa-file-image-o"></i>Galeria</li>
      <li><i class="fa fa-file-archive-o"></i>Załączniki</li>
    </ul>
    <div class="resp-tabs-container settings-tabs">
      <div>
        <div id="languages-main">
          <ul class="resp-tabs-list languages-main htabs">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
              <? if ( $lg['status'] ):?>
                <li><? if ( $lg['id'] == \front\factory\Languages::default_language() ) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> ';?><?= $lg['name'];?></a></li>
              <? endif;?>
            <? endforeach; endif;?>
          </ul>
          <div class="resp-tabs-container languages-main">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
              <?
                $languages = array();

                $languages[''] = '---- wersja językowa ----';
                if ( is_array( $this -> languages ) ) foreach ( $this -> languages as $lg_tmp )
                {
                  if ( $lg_tmp['id'] != $lg['id'] )
                    $languages[ $lg_tmp['id'] ] = $lg_tmp['name'];
                }
              ?>
              <? if ( $lg['status'] ):?>
                <div>
                  <?= \Html::select(
                              array(
                                'label'   => 'Wyświetlaj treść z wersji',
                                'name'    => 'copy_from[' . $lg['id'] . ']',
                                'values'  => $languages,
                                'value'   => $this -> article['languages'][ $lg['id'] ]['copy_from'],
                              )
                          );?>
                  <?= \Html::input(
                              array(
                                'label'   => 'Tytuł',
                                'name'    => 'title[' . $lg['id'] . ']',
                                'id'      => 'title_' . $lg['id'],
                                'value'   => $this -> article['languages'][ $lg['id'] ]['title'],
                                'inline'  => true
                              )
                          );?>
                  <?= \Html::input_icon( [
                        'label' => 'Zdjęcie tytułowe',
                        'name' => 'main_image[' . $lg['id'] . ']',
                        'id' => 'main_image_' . $lg['id'],
                        'value' => htmlspecialchars( $this -> article['languages'][ $lg['id'] ]['main_image'] ),
                        'icon_content' => 'przeglądaj',
                        'inline'  => true,
                        'icon_js' => "window.open ( '/libraries/filemanager-9.14.1/dialog.php?type=1&popup=1&field_id=main_image_" . $lg['id'] . "&akey=c3cb2537d25c0efc9e573d059d79c3b8', 'mywindow', 'location=1,status=1,scrollbars=1, width=1100,height=700');"
                    ] );
                  ?>
                  <?= \Html::textarea(
                              array(
                                'label'   => 'Wstęp',
                                'name'    => 'entry[' . $lg['id'] . ']',
                                'id'      => 'entry_' . $lg['id'],
                                'value'   => $this -> article['languages'][ $lg['id'] ]['entry'],
                                'inline'  => true
                              )
                          );?>
                  <?= \Html::textarea(
                              array(
                                'label'   => 'Treść',
                                'name'    => 'text[' . $lg['id'] . ']',
                                'id'      => 'text_' . $lg['id'],
                                'value'   => $this -> article['languages'][ $lg['id'] ]['text'],
                                'inline'  => true
                              )
                          );?>
                  <?= \Html::textarea( [
                    'label'   => 'Spis treści',
                    'name'    => 'table_of_contents[' . $lg['id'] . ']',
                    'id'      => 'table_of_contents_' . $lg['id'],
                    'value'   => $this -> article['languages'][ $lg['id'] ]['table_of_contents'],
                    'inline'  => true
                  ] );?>
                  <script type="text/javascript">
                    $( function() {
                      $( '#text_<?= $lg['id'];?>, #entry_<?= $lg['id'];?>, #table_of_contents_<?= $lg['id'];?>' ).ckeditor( {
                        toolbar : 'MyToolbar',
                        height:'250'
                      });
                    });
                  </script>
                </div>
              <? endif;?>
            <? endforeach; endif;?>
          </div>
          <div class="clear"></div>
        </div>
      </div>
      <div>
        <?= \Html::input_switch(
                    array(
                      'label'   => 'Opublikowany',
                      'name'    => 'status',
                      'checked' => $this -> article['status'] == 1 or !$this -> article['id'] ? true : false
                    )
                );?>
        <?= \Html::input_switch(
                    array(
                      'label'   => 'Pokaż tytuł',
                      'name'    => 'show_title',
                      'checked' => $this -> article['show_title'] == 1 ? true : false
                    )
                );?>
        <?= \Html::input_switch( [
          'label' => 'Pokaż spis treści',
          'name' => 'show_table_of_contents',
          'checked' => $this -> article['show_table_of_contents'] == 1 ? true : false
        ] );?>
        <?= \Html::input_switch(
                    array(
                      'label'   => 'Pokaż datę dodania',
                      'name'    => 'show_date_add',
                      'checked' => $this -> article['show_date_add'] == 1 ? true : false
                    )
                );?>
        <?= \Html::input_switch(
                    array(
                      'label'   => 'Pokaż datę modyfikacji',
                      'name'    => 'show_date_modify',
                      'checked' => $this -> article['show_date_modify'] == 1 ? true : false
                    )
                );?>
        <?= \Html::input_switch(
                    array(
                      'label'   => 'Powtórz wprowadzenie',
                      'name'    => 'repeat_entry',
                      'checked' => $this -> article['repeat_entry'] == 1 ? true : false
                    )
                );?>
        <?= \Html::input_switch(
                    array(
                      'label'   => 'Linki do portali społecznościowych',
                      'name'    => 'social_icons',
                      'checked' => $this -> article['social_icons'] == 1 ? true : false
                    )
                );?>
      </div>
      <div>
        <div id="languages-seo">
          <ul class="resp-tabs-list languages-seo htabs">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
              <? if ( $lg['status'] ):?>
                <li><? if ( $lg['id'] == \front\factory\Languages::default_language() ) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> ';?><?= $lg['name'];?></a></li>
              <? endif;?>
            <? endforeach; endif;?>
          </ul>
          <div class="resp-tabs-container languages-seo">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
              <? if ( $lg['status'] ):?>
                <div>
                  <?= \Html::input_icon(
                              array(
                                'label'         => 'Link SEO',
                                'name'          => 'seo_link[' . $lg['id'] . ']',
                                'id'            => 'seo_link_' . $lg['id'],
                                'value'         => $this -> article['languages' ][ $lg['id'] ]['seo_link'],
                                'icon_content'  => 'generuj',
                                'icon_js'       => 'generate_seo_links( "' . $lg['id'] . '", $( "#title_' . $lg['id'] . '" ).val(), ' . (int)$this -> article['id'] . ' );'
                              )
                          );?>
                  <?= \Html::input( [
                                'label' => 'Meta title',
                                'name' => 'meta_title[' . $lg['id'] . ']',
                                'id' => 'meta_title_' . $lg['id'],
                                'value' => $this -> article['languages'][ $lg['id'] ]['meta_title']
                              ]
                          );?>
                  <?= \Html::textarea(
                              array(
                                'label'   => 'Meta description',
                                'name'    => 'meta_description[' . $lg['id'] . ']',
                                'id'      => 'meta_description_' . $lg['id'],
                                'value'   => $this -> article['languages'][ $lg['id'] ]['meta_description']
                              )
                          );?>
                  <?= \Html::textarea(
                              array(
                                'label'   => 'Meta keywords',
                                'name'    => 'meta_keywords[' . $lg['id'] . ']',
                                'id'      => 'meta_keywords_' . $lg['id'],
                                'value'   => $this -> article['languages'][ $lg['id'] ]['meta_keywords']
                              )
                          );?>
                  <?= \Html::input_switch( [
                                'label'   => 'Blokuj indeksację',
                                'name' => 'noindex[' . $lg['id'] . ']',
                                'id'      => 'noindex_' . $lg['id'],
                                'checked' => $this -> article['languages'][ $lg['id'] ]['noindex'] == 1 ? 1 : 0
                              ]
                          );?>
                  <?= \Html::input_switch( [
                                'label'   => 'Blokuj bezpośredni dostęp',
                                'name'    => 'block_direct_access[' . $lg['id'] . ']',
                                'id'      => 'block_direct_access_' . $lg['id'],
                                'checked' => $this -> article['languages'][ $lg['id'] ]['block_direct_access'] == 1 ? 1 : 0
                              ] );?>
                </div>
              <? endif;?>
            <? endforeach; endif;?>
          </div>
          <div class="clear"></div>
        </div>
      </div>
      <div>
        <?
          $layouts[''] = '---- szablon domyślny ----';
          if ( is_array( $this -> layouts ) ): foreach ( $this -> layouts as $layout ):
            $layouts[ $layout['id'] ] = $layout['name'];
          endforeach; endif;
        ?>
        <?= \Html::select(
                    array(
                      'label'   => 'Szablon',
                      'name'    => 'layout_id',
                      'id'      => 'layout_id',
                      'values'  => $layouts,
                      'value'   => $this -> article['layout_id']
                    )
                );?>
        <div class="form-group">
          <label class="col-lg-4 control-label">Wyświetlaj na:</label>
          <div class="col-lg-8">
            <?
              if ( is_array( $this -> menus ) ) foreach ( $this -> menus as $menu )
              {
                ?>
                  <div class="menu_sortable">
                    <ol class="sortable" id="sortable_<?= $menu['id'];?>">
                      <li id="list_<?= $menu['id'];?>" class="menu_<?= $menu['id'];?>" menu="<?= $menu['id'];?>">
                        <div class="context_0 content content_menu" <? if ( !$menu['status'] ) echo 'style="color: #cc0000;"';?>>
                          <span class="disclose"><span></span></span>
                          Menu: <b><?= $menu['name'];?></b>
                        </div>
                        <?= \admin\view\Articles::subpages_list( \admin\factory\Pages::menu_pages( $menu['id'] ), $this -> article['pages'] );?>
                      </li>
                    </ol>
                  </div>
                <?
              }
            ?>
          </div>
          <div class="clear"></div>
        </div>
      </div>
      <div>
        <ul id="images-list">
          <?
            $images_count = 0;
            if ( is_array( $this -> article['images'] ) ): foreach ( $this -> article['images'] as $img ):
              ?>
                <li id="image-<?= $img['id'];?>">
                  <img class="article-image lozad" data-src="/libraries/thumb.php?img=<?= $img['src'];?>&w=300&h=300">
                  <a href="#" class="input-group-addon btn btn-danger article_image_delete" image-id="<?= $img['id'];?>">
                    <i class="fa fa-trash"></i>
                  </a>
                  <input type="text" class="form-control image-alt" value="<?= $img['alt'];?>" image-id="<?= $img['id'];?>" placeholder="atrybut alt...">
                </li>
              <?
              $images_count++;
            endforeach; endif;
          ?>
        </ul>
        <div id="images-uploader">You browser doesn't have Flash installed.</div>
      </div>
      <div>
        <ul id="files-list">
          <?
            $files_count = 0;
            if ( is_array( $this -> article['files'] ) ): foreach ( $this -> article['files'] as $file ):

              if ( $file['name'] )
                $name = $file['name'];
              else
              {
                $name = explode( '/', $file['src'] );
                $name = $name[ count( $name ) - 1 ];
              }
              ?>
                <li id="file-<?= $file['id'];?>">
                  <div class="input-group">
                    <input type="text" class="article_file_edit form-control" file_id="<?= $file['id'];?>" value="<?= $name;?>" />
                    <a href="#" class="input-group-addon btn btn-info article_file_delete" file_id="<?= $file['id'];?>">
                      <i class="fa fa-trash"></i>
                    </a>
                  </div>
                </li>
              <?
              $files_count++;
            endforeach; endif;
          ?>
        </ul>
        <div id="files-uploader">You browser doesn't have Flash installed.</div>
      </div>
    </div>
  </div>
<?
$out = ob_get_clean();

$grid = new \gridEdit;
$grid -> id               = 'article-edit';
$grid -> gdb_opt          = $gdb;
$grid -> include_plugins  = true;
$grid -> title            = 'Edycja artykułu';
$grid -> fields           = [
                              [
                                'db' => 'id',
                                'type' => 'hidden',
                                'value' => $this -> article['id']
                              ]
                            ];
$grid -> actions          = [
                              'save' => [ 'url' => '/admin/articles/article_save/', 'back_url' => '/admin/articles/view_list/' ],
                              'cancel' => [ 'url' => '/admin/articles/view_list/' ]
                            ];
$grid -> external_code    = $out;
$grid -> persist_edit     = true;
$grid -> id_param         = 'id';

echo $grid -> draw();
?>

<link type="text/css" rel="stylesheet" href="/libraries/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css" />

<script type="text/javascript" src="/libraries/plupload/plupload.js"></script>
<script type="text/javascript" src="/libraries/plupload/plupload.flash.js"></script>
<script type="text/javascript" src="/libraries/plupload/plupload.html5.js"></script>
<script type="text/javascript" src="/libraries/plupload/plupload.html4.js"></script>
<script type="text/javascript" src="/libraries/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<script type="text/javascript" src="/libraries/plupload/i18n/pl.js"></script>
<script type="text/javascript" src="/libraries/jquery-nested-sortable/jquery.mjs.nestedSortable.js"></script>
<script type="text/javascript" src="/libraries/jquery/lozad.js"></script>

<script type="text/javascript">
  var images_count  = <?= $images_count;?>;
  var files_count   = <?= $files_count;?>;

  $( function()
  {
    const observer = lozad();
    observer.observe();

    disable_menu();

    var el = document.getElementById( 'images-list' );
    var sortable = Sortable.create(el, {
      onEnd: function ( evt ) {
        var order = '';
        $( '#images-list li' ).each( function()
        {
          if ( order !== '' )
            order += ';';
          order += $( this ).children( 'a' ).attr( 'image-id' );
        });

        $.ajax(
        {
          type: 'POST',
          cache: false,
          url: '/admin/articles/gallery_order_save/',
          data:
          {
            article_id: '<?= $this -> article['id'];?>',
            order: order
          },
          beforeSend: function()
          {
            $( '#overlay' ).show();
          },
          success: function( data )
          {
            $( '#overlay' ).hide();

            response = jQuery.parseJSON( data );

            if ( response.status !== 'ok' )
              create_error( response.msg );
          }
        });
      }
    });

    $( "#images-uploader" ).pluploadQueue(
    {
      runtimes: 'html5,flash,html4',
      init:
      {
        Refresh: function(up)
        {
          $( ".plupload_buttons" ).css( "display", "inline" );
          $( ".plupload_upload_status" ).css( "display", "inline" );
          $( ".plupload_start" ).addClass( "plupload_disabled" );
          $( ".plupload_start" ).removeClass( "plupload_disabled" );
        },
        UploadComplete: function()
        {
          $( ".plupload_buttons" ).css( "display", "inline" );
          $( ".plupload_upload_status" ).css( "display", "inline" );
          $( ".plupload_start" ).addClass( "plupload_disabled" );
          $( ".plupload_start" ).removeClass( "plupload_disabled" );
        },
        FileUploaded: function( up, file, response )
        {
          data = jQuery.parseJSON( response.response );
          $( '#images-list' ).append(
                  '<li id="image-' + data.image_id + '">' +
                    '<img class="article-image lozad" data-src="/libraries/thumb.php?img=' +  data.data_link + '&w=300&h=300">' +
                      '<a href="#" class="input-group-addon btn btn-danger article_image_delete" image-id="' + data.image_id + '">' +
                        '<i class="fa fa-trash"></i>' +
                      '</a>' +
                      '<input type="text" class="form-control image-alt" value="" image-id="' + data.image_id + '" placeholder="atrybut alt...">' +
                  '</li>'
                );
          images_count++;
          observer.observe();
          $( 'html, body' ).animate({
            scrollTop: $( "#images-uploader" ).offset().top
          }, 1 );
        }
      },
      url: '/libraries/plupload/upload-articles-images.php',
      chunk_size: '1mb',
      unique_names: false,
      resize : {
        width : <?= $this -> settings['image_px'] ? $this -> settings['image_px'] : '1920';?>,
        height : <?= $this -> settings['image_px'] ? $this -> settings['image_px'] : '1920';?>,
        quality : 95
      },
      filters: [
        { title: "Obrazki", extensions : "jpg, gif, png, bmp, jpeg" }
      ],
      flash_swf_url: '/../libraries/plupload/plupload.flash.swf'
    });

    $( "#files-uploader" ).pluploadQueue(
    {
      runtimes: 'html5,flash,html4',
      init:
      {
        Refresh: function( up )
        {
          $( ".plupload_buttons" ).css( "display", "inline" );
          $( ".plupload_upload_status" ).css( "display", "inline" );
          $( ".plupload_start" ).addClass( "plupload_disabled" );
          $( ".plupload_start" ).removeClass( "plupload_disabled" );
        },
        FileUploaded: function( up, file, response )
        {
          data = jQuery.parseJSON( response.response );
          $( '#files-list' ).append(
                  '<li id="file-' + data.file_id + '">' +
                    '<div class="input-group">' +
                      '<input type="text" class="form-control article_file_edit" file_id="' + data.file_id + '" value="' + data.file_name + '" />' +
                      '<a href="#" class="input-group-addon btn btn-info article_file_delete" file_id="' + data.file_id + '">' +
                        '<i class="fa fa-trash"></i>' +
                      '</a>' +
                    '</div>' +
                  '</li>'
                );
          files_count++;
        }
      },
      url: '/libraries/plupload/upload-articles-files.php',
      chunk_size: '1mb',
      unique_names: false,
      filters: [
         { title: "Wszystkie pliki", extensions: "*" }
      ],
      flash_swf_url: '/../libraries/plupload/plupload.flash.swf'
    });

    $( '#settings-tabs' ).easyResponsiveTabs({
      width: 'auto',
      fit: true,
      tabidentify: 'settings-tabs',
      type: 'vertical'
    });

    $( '#languages-main' ).easyResponsiveTabs({
      width: 'auto',
      fit: true,
      tabidentify: 'languages-main'
    });

    $( '#languages-seo' ).easyResponsiveTabs({
      width: 'auto',
      fit: true,
      tabidentify: 'languages-seo'
    });

    $('ol.sortable').nestedSortable({
      forcePlaceholderSize: true,
			handle: 'div',
			helper:	'clone',
			items: 'li',
			opacity: .6,
			placeholder: 'placeholder',
			revert: 250,
			tabSize: 25,
			tolerance: 'pointer',
			toleranceElement: '> div',
			maxLevels: 3,
			isTree: true,
			expandOnHover: 700,
      isAllowed: function()
      {
        return false;
      }
		});

		$( '.disclose' ).on( 'click', function() {
			$( this ).closest( 'li' ).toggleClass( 'sort-collapsed' ).toggleClass( 'sort-expanded' );
		});

    $( '.disclose' ).mousedown( function(e) {
      if ( e.which === 1 ) {
        if ( $( this ).parent( 'div' ).hasClass( 'content_menu' ) )
        {
          var menu_id = $( this ).parent( 'div' ).parent( 'li' ).attr( 'menu' );

          $.ajax(
          {
            type: 'POST',
            cache: false,
            url: '/admin/ajax.php',
            data: {
              a: 'cookie_menus',
              menu_id:  menu_id
            }
          });
        }
        else
        {
          var page_id = $( this ).parent( 'div' ).parent( 'li' ).attr( 'id' );

          $.ajax(
          {
            type: 'POST',
            cache: false,
            url: '/admin/ajax.php',
            data: {
              a: 'cookie_pages',
              page_id:  page_id
            }
          });
        }
      }
    });

    <?php
      $array = unserialize( $_COOKIE[ 'cookie_pages' ] );
      if ( is_array( $array ) ): foreach ( $array as $key => $val ):
        if ( $val ):
          ?>$( '.<?= $key;?>' ).children( 'div' ).children( 'span.disclose' ).click();<?
        endif;
      endforeach; endif;

      $array = unserialize( $_COOKIE[ 'cookie_menus' ] );
      if ( is_array( $array ) ): foreach ( $array as $key => $val ):
        if ( $val ):
          ?>$( '.menu_<?= $key;?>' ).children( 'div' ).children( 'span.disclose' ).click();<?
        endif;
      endforeach; endif;
    ?>

    $( 'body' ).on( 'change', '.image-alt', function()
    {
      var image_alt = $( this ).val();
      var image_id  = $( this ).attr( 'image-id' );

      $.ajax(
      {
        type: 'POST',
        cache: false,
        url: '/admin/ajax.php',
        data:
        {
          a: 'article_image_alt_change',
          image_id: image_id,
          image_alt: image_alt
        },
        beforeSend: function()
        {
          $( '#overlay' ).show();
        },
        success: function( data )
        {
          $( '#overlay' ).hide();

          response = jQuery.parseJSON( data );

          if ( response.status !== 'ok' )
            create_error( response.msg );
        }
      });
    });

    $( 'body' ).on( 'change', '.article_file_edit', function()
    {
      var file_name = $( this ).val();
      var file_id   = $( this ).attr( 'file_id' );

      $.ajax({
        type: 'POST',
        cache: false,
        url: '/admin/ajax.php',
        data:
        {
          a: 'article_file_name_change',
          file_id: file_id,
          file_name: file_name
        },
        beforeSend: function()
        {
          $( '#overlay' ).show();
        },
        success: function( data )
        {
          $( '#overlay' ).hide();

          response = jQuery.parseJSON( data );

          if ( response.status !== 'ok' )
            create_error( response.msg );
        }
      });

    });

    $( 'body' ).on( 'click', '.article_file_delete', function()
    {
      $( this ).blur();
      var file_id = $( this ).attr( 'file_id' );

      $.prompt( 'Na pewno chcesz usunąć wybrany plik?', {
        title: 'Potwierdź?',
        submit: function(e,v,m,f)
        {
          if ( v === true )
          {
            $.ajax({
              type: 'POST',
              cache: false,
              url: '/admin/ajax.php',
              data:
              {
                a: 'article_file_delete',
                file_id: file_id
              },
              beforeSend: function()
              {
                $( '#file-' + file_id ).children( 'input' ).addClass( 'disabled' );
                $( '#file-' + file_id ).children( 'a' ).addClass( 'disabled' );
              },
              success: function( data )
              {
                response = jQuery.parseJSON( data );

                if ( response.status === 'ok' )
                  $( '#file-' + file_id ).remove();
                else
                  create_error( msg );
              }
            });
          }
        },
        buttons: {
          'tak': true,
          'nie': false
        },
        focus: 0
      });

    });

    $( 'body' ).on( 'click', '.article_image_delete', function()
    {
      $( this ).blur();
      var image_id = $( this ).attr( 'image-id' );

      $.prompt( 'Na pewno chcesz usunąć wybrane zdjęcie?',
      {
        title: 'Potwierdź?',
        submit: function(e,v,m,f)
        {
          if ( v === true )
          {
            $.ajax(
            {
              type: 'POST',
              cache: false,
              url: '/admin/ajax.php',
              data:
              {
                a: 'article_image_delete',
                image_id: image_id
              },
              beforeSend: function()
              {
                $( '#overlay' ).show();
              },
              success: function( data )
              {
                $( '#overlay' ).hide();
                response = jQuery.parseJSON( data );

                if ( response.status === 'ok' )
                  $( '#image-' + image_id ).remove();
                else
                  create_error( msg );
              }
            });
          }
        },
        buttons: {
          'tak': true,
          'nie': false
        },
        focus: 0
      });
      return false;
    });
  });

  function generate_seo_links( lang, title, article_id )
  {
    if ( title === '' )
      return false;

    $.ajax(
    {
      type: 'POST',
      cache: false,
      url: '/admin/ajax.php',
      data:
      {
        a: 'generate_seo_link',
        title:  title,
        article_id: article_id
      },
      beforeSend: function()
      {
        $( '#seo_link_' + lang ).parents( '.g-form-data' ).find( 'input, a' ).each( function()
        {
          $( this ).prop( 'disabled', true ).addClass( 'disabled' );
        });
      },
      success: function( data ) {

        $( '#seo_link_' + lang ).parents( '.g-form-data' ).find( 'input, a' ).each( function() {
          $( this ).prop( 'disabled', false ).removeClass( 'disabled' );
        });

        response = jQuery.parseJSON( data );

        if ( response.status === 'ok' )
          $( '#seo_link_' + lang ).val( response.seo_link );
        else
          create_error( response.msg );
      }
    });
  }
</script>
<script>CKEDITOR.dtd.$removeEmpty['span'] = false;</script>