<style>
    #guardarnew {
        background: #94b300;
        color: #fff;
        float: none;
        width: 100%;
        padding: 10px;
        border-radius: 8px;
        margin: 10px 0;
        font-weight: bold;
        max-width: 100%;
        display: inline-block;
        cursor: pointer;
        transition:.35s all ease;
    }
    #guardarnew:hover {
        background: #333;
        transition:.35s all ease;
        color: #fff;
    }
    .popUpStatus, .popUpStatus2 {
        position: fixed;
        width: 100%;
        height: 100%;
        top: 0;
        z-index: 99999;
        background: rgba(0,0,0,.65);
        display: none;
        text-align: center;
        overflow:auto;
    }
    .popUpNew {
        position: fixed;
        width: 100%;
        height: 100%;
        top: 0;
        z-index: 99999;
        background: rgba(0,0,0,.65);
        display: none;
        text-align: center;
        overflow:auto;
    }
    .tab-content {
    height: 0;
    overflow-y:hidden;
    display: inline-block;
    }
    .tab-content.note-tab-content {
    height: auto;
    overflow-y:hidden;
    display: inline-block;
    }
    .tab-content.active {
    height: auto;
    }

    #new .tab {
        padding: 10px;
        color: #fff;
        font-size: 16px;
        width: 50%;
        background: #b0b0b0;
        display: inline-block;
        margin: 0;
            margin-bottom: 0px;
        float: left;
        margin-bottom: 15px;
        border: 1px solid #fff;
    }

    #new .tab.active {
        background: #2b4365;
        font-weight:bold;
    }
    label.error {
        color: #dc3e3e !important;
        background: transparent !important;
    }
    .redbg{
        background:#dc3e3e!important;
    }
    .errormensaje {
        color: #dc3e3e;
        font-weight: bold;
        font-size: 13px !important;
    }
    #respuestanew h5 {
        font-weight: bold;
        color: green;
    }
    .statusenespera {
	color: #dc3545;
	font-weight: bold;
	background: url(/admin2/img/hide.svg);
	background-size: 20px;
	background-repeat: no-repeat;
	background-position: left center;
	min-height: 30px;
	display: inline-block;
	text-align: left;
	line-height: 1.1;
	padding: 10px;
	padding-left: 30px;
}
.statusentregado {
	color: #05AD00;
	font-weight: bold;
	padding: 10px;
	padding-left: 30px;
	background: url(/admin2/img/check.svg);
	background-size: 20px;
	background-repeat: no-repeat;
	background-position: left;
	min-height: 30px;
	display: inline-block;
	text-align: left;
	line-height: 1.1;
}
#formnew video {
    width: 100%;
    max-width: 300px;
}
#formnew .videodiv {
    position: relative;
}
.videodiv .video-upload label {
    background: #dae6ea;
    border-radius: 50%;
    padding: 10px;
    box-shadow: 1px 3px 10px #ccc;
    border: 3px solid #00b594;
} 
.image-upload, .video-upload {
        width: auto;
        display: inline-block;
        position: absolute;
        left: 160px;
        top: -10px;
    }

    .image-upload img, .video-upload img {
        width: 30px;
        cursor: pointer;
        transition: .35s all ease;
    }
    .video-upload img:hover {
        transition:.35s all ease;
        transform: scale(1.1);
    }

    .video-upload > input {
        display: block;
    }

    .video-upload > input {
        height: 0;
        opacity: 0;
        overflow: hidden;
    }
    .video-upload label {
        max-width: 55px;
    }
    .closepop {
        width: 32px;
        height: 32px;
        background: url(/admin2/img/multiply.svg);
        background-size: 100%;
        float: right;
        cursor: pointer;
        margin: 0px;
        /* margin-top: 100px; */
        /* top: 30px; */
        position: absolute;
        right: 20px;
    }

    i.circledraft {
        font-style: normal;
        color: #fff;
        background: #dc3545;
        padding: 1px;
        font-size: 12px;
        height: 20px;
        width: 20px;
        display: inline-block;
        border-radius: 50%;
        margin-left: 1px;
        transform: translateY(-5px);
    }

            
</style>
<div class="popUpNew" id="new">
    <div class="pocont">
      <div class="closepop" onclick="closeNew();"></div>
      <h3 style="margin-bottom: 10px;">Agregar <?php echo $newtext; ?></h3>
      
      <h5 id="instructionsh5" style="display: inline-block; font-size: 14px; margin: 0; margin-bottom:20px;">Ingrese los datos (ambos idiomas), a continuación de click en "Guardar" al final del formulario.</h5>
      
      
      <form class="formnew js-form-validate" id="formnew" enctype="multipart/form-data" autocomplete="off">
      <!-- Tabs -->
        <a id="tabes" href="#" data-lang="es" class="tab active" data-toggle-target=".tab-content-1">Español</a>
        <a id="taben" href="#" data-lang="en" class="tab" data-toggle-target=".tab-content-2">Inglés</a>

        <!-- Content -->
        <div class="tab-content tab-content-1 active">
            <div id="loadnewes"></div>
        </div>
        <div class="tab-content tab-content-2">
            <div id="loadnewen"></div>
        </div>
       

        <?php
        
            if($rol == "editor" || $rol == "admin"){

        ?>
                <input onclick="saveNew('guardar');" type="submit" id="guardarnew" style="width:50%" value="Guardar"/>
                <input onclick="saveNew('enviar');" type="submit" id="guardarnew" style="width:50%"  value="Enviar"/>

        <?php
            }
            else{
        
        ?>
            <input onclick="saveNew();" type="submit" id="guardarnew" value="Guardar"/>
        <?php
        }
        
        ?>

    </form>

    <div style="display:inline-block; width:100%; padding:10px; float:left;" id="respuestanew"></div>
    </div>
  </div>

  <div class="popUpStatus">
      <input type="hidden" id="currentstatus">
    <div class="pocont">
      <div class="closepop" onclick="closeStatus();"></div>
      <h3>Cambiar status</h3>
        <div class="statusicon" onclick="changeStatus('borrador', '<?php echo $modelo;?>');"><span class="statusenespera" googl="true">Oculto</span></div>
        <div class="statusicon" onclick="changeStatus('publicado', '<?php echo $modelo;?>');"><span class="statusentregado" googl="true">Visible en sitio</span></div>  

        <div style="display:inline-block; width:100%; padding:10px; float:left;" id="respuestastatus"></div>
    </div>
  </div>



  <div class="popUpStatus2">
      <input type="hidden" id="currentstatus2">
    <div class="pocont">
      <div class="closepop" onclick="closeStatus2();"></div>
      <h3>¿Confirmar publicación en el sitio?</h3>
        
        <div class="statusicon" onclick="changeStatus2('publicado', '<?php echo $modelo;?>');" style="width: 100%;"><span class="statusentregado" googl="true" >Confirmar</span></div> 
        
        <br>

        <p onclick="closeStatus2();" style="float: left;
width: 100%;
color: red;
font-size: 13px;
margin: 10px 0 !important;
cursor: pointer;">Cancelar</p>

        <div style="display:inline-block; width:100%; padding:10px; float:left;" id="respuestastatus2"></div>
    </div>
  </div>
  
  <div id="respuestadelete"></div>

  <script src="https://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>


  <script src="/admin2/vendor/jquery/jquery-migrate.min.js"></script>
  <script src="/admin2/vendor/bootstrap/js/bootstrap.min.js"></script>
  <script src="/admin2/vendor/easing/easing.min.js"></script>
  <script src="/admin2/vendor/sticky/sticky.js"></script>
  <script src="/admin2/vendor/aos/aos.js"></script>
  <script src="/admin2/vendor/owlcarousel/owl.carousel.min.js"></script>
  <script type="text/javascript" src="https://www.jerrylow.com/basictable/jquery.basictable.min.js"></script>
  <script src="/admin2/vendor/js/jquitelight.js"></script>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
 
  <!-- Main JS File -->
  <script src="/admin2/vendor/js/main.js"></script>
  <script src="https://cdn.jsdelivr.net/jquery.validation/1.15.0/jquery.validate.min.js"></script>
<script>

$('#new .tab').on('click', function(evt) {
  evt.preventDefault();
  $('#new .tab').removeClass('active');
  var sel = this.getAttribute('data-toggle-target');
  $('.tab-content').removeClass('active').filter(sel).addClass('active');
  $(this).addClass('active');
});   
function addNew(){
    $(".popUpNew").fadeIn();
    $('#new .tab-mnu li.active').click();
    $("#loadnewes").load("/admin2/new/<?php echo $newpage; ?>?lang=es");
    $("#loadnewen").load("/admin2/new/<?php echo $newpage; ?>?lang=en");
}

function closeNew(){
$(".popUpNew").fadeOut();

}

$('#new .tab-mnu > li').click(function(){
    $("#loadnewes").html("");
    $("#loadnewen").html("");
    var before = $('#new .tab-mnu li.active');
    before.removeClass('active');
    $(this).addClass('active');
    setTimeout(() => {
        var lang = $(this).attr('data-lang');
        if(lang == 'es'){
            
        }
        if(lang == 'en'){
            
        }

    }, 100);

});

function openStatus(id){
    $('#respuestastatus').html("");
    $(".popUpStatus").fadeIn();
    $("#currentstatus").val(id);
    console.log(id);
  }

  function closeStatus(){
    $(".popUpStatus").fadeOut();

  }


  function openStatus2(id){
    $('#respuestastatus2').html("");
    $(".popUpStatus2").fadeIn();
    $("#currentstatus2").val(id);
    console.log(id);
  }

  function closeStatus2(){
    $(".popUpStatus2").fadeOut();

  }

  function changeStatus(status, modelo){
    $(".statusicon").prop( "disabled", true );
    $(".statusicon").css("opacity", ".6");
    $(".statusicon").css("pointer-events", "none");
    var current = $("#currentstatus").val();
    console.log(current);
    console.log("id="+current+"&status="+status+"&modelo="+modelo);
    $.ajax({
        url : "/admin2/publish/aviso.php",
        type: "POST",
        data : "id="+current+"&status="+status+"&modelo="+modelo,
        success:function(data){
            $('#respuestastatus').html(data);
            setTimeout(() => {
              $(".statusicon").prop( "disabled", false );
              $(".statusicon").css("opacity", "1");
              $(".statusicon").css("pointer-events", "inherit");
        }, 1000);
      }
    });
  }


  function changeStatus2(status, modelo){
    $(".statusicon").prop( "disabled", true );
    $(".statusicon").css("opacity", ".6");
    $(".statusicon").css("pointer-events", "none");
    var current = $("#currentstatus2").val();
    console.log(current);
    console.log("id="+current+"&status2="+status+"&modelo2="+modelo);
    $.ajax({
        url : "/admin2/publish/publicar.php",
        type: "POST",
        data : "id="+current+"&status="+status+"&modelo="+modelo,
        success:function(data){
            $('#respuestastatus2').html(data);
            setTimeout(() => {
              $(".statusicon").prop( "disabled", false );
              $(".statusicon").css("opacity", "1");
              $(".statusicon").css("pointer-events", "inherit");
        }, 1000);
      }
    });
  }

  function deleteThis(id, modelo){
        if (confirm('¿Confirmar eliminación?')) {
            $.ajax({
                url : "/admin2/publish/aviso.php",
                type: "POST",
                data : "id="+id+"&status=eliminado&modelo="+modelo,
                success:function(data){
                    $('#respuestadelete').html(data);
                    setTimeout(() => {
                }, 1000);
            }
            });
        }
    }

    function PreviewVideoAdd(id) {
        if(document.getElementById(id).files[0].size > 50000000){
            alert("El peso del video excede 50 Mb. Comprime el video o selecciona uno diferente.");
            $("#video").val("");
        }
        else{
            var fileInput = document.getElementById(id);
            var fileUrl = window.URL.createObjectURL(fileInput.files[0]);
            $("#uploadPreview"+id).html('<video src="'+fileUrl+'" loop muted autoplay></video>');
            

        }
    };

    setTimeout(() => {
        $('.editor td[data-th="Status"]').css("pointer-events", "none");
        $('.editor td[data-th="Status"]').css("opacity", ".4");
        $('.editor td[data-th="Eliminar"]').css("pointer-events", "none");
        $('.editor td[data-th="Eliminar"]').css("opacity", ".4");
        $('.editor td[data-th="Visibilidad en sitio"]').css("pointer-events", "none");
        $('.editor td[data-th="Visibilidad en sitio"]').css("opacity", ".4");
        $('.editor td[data-th="Publicar"]').css("pointer-events", "none");
        $('.editor td[data-th="Publicar"]').css("opacity", ".4");
        $('.borradores td[data-th="Eliminar"]').css("pointer-events", "none");
        $('.borradores td[data-th="Eliminar"]').css("opacity", "0");
    }, 500);

    function switchTab(id){
        var tab = "table."+id;
        var tabc = ".tab-"+id;

        $("ul li").removeClass('activetab1');
        $("ul").find(tabc).addClass('activetab1');
        
        $("table").hide();
        $(tab).fadeIn();

        console.log(tab);

    }

    $(document).ready(function(){
    var text = document.body.textContent
        .replace(/\r?\n?/g, "") // removes lines
        .replace(/\s{2,}/g, " "), // removes duplicate spaces
        word = new RegExp("Listo para publicar", "gi");

        var number = text.match(word).length - 1;
        //alert(number);
        if(number > 0){
        $(".circledraft").text(number).fadeIn();
        }
        

    })

    function checkGuardado(lang){
        if ($('#guardaredit').length > 0) {
            // Exists.
            if(lang == 'es'){
                //saveEdit('guardar','es', 'no');
                $(".botonguarda").click();
                console.log("Guardado (es)");

            }

            if(lang == 'en'){

                //saveEdit('guardar','en', 'no');
                $(".botonguarda").click();
                console.log("Guardado (en)");
                
            }
        }
        
    }

</script>