<?php
include("encabezado.php");
include("funciones.php");
//include("coneximpo.php");
include("constantes.php");
$link = Conectarse();

function compararFechas($primera, $segunda) {
    $valoresPrimera = explode("-", str_replace('/', '-', $primera));
    $valoresSegunda = explode("-", str_replace('/', '-', $segunda));
    $diaPrimera = $valoresPrimera[2];
    $mesPrimera = $valoresPrimera[1];
    $anyoPrimera = $valoresPrimera[0];
    $diaSegunda = $valoresSegunda[2];
    $mesSegunda = $valoresSegunda[1];
    $anyoSegunda = $valoresSegunda[0];
    $diasPrimeraJuliano = gregoriantojd($mesPrimera, $diaPrimera, $anyoPrimera);
    $diasSegundaJuliano = gregoriantojd($mesSegunda, $diaSegunda, $anyoSegunda);
    if (!checkdate($mesPrimera, $diaPrimera, $anyoPrimera)) {
        // "La fecha ".$primera." no es válida";   
        return 0;
    } elseif (!checkdate($mesSegunda, $diaSegunda, $anyoSegunda)) {
        // "La fecha ".$segunda." no es válida";   
        return 0;
    } else {
        return $diasPrimeraJuliano - $diasSegundaJuliano;
    }
}
?>

<script>
    function fix(fixNumber, decimalPlaces)
    {
        var div = Math.pow(10, decimalPlaces);
        fixNumber = Math.round(fixNumber * div) / div;
        return fixNumber.toFixed(2);
    }


    function calculos_dimension(indice, indice_top) {
        /*var a_alto = $("input[name^=alto]");
         var a_ancho = $("input[name^=ancho]");
         var a_largo = $("input[name^=largo]");
         var a_numero_bultos = $("input[name^=numero_bultos]");
         var a_volumen = $("input[name^=volLinea]"); */

        var a_alto = $("#table" + indice_top).find("input[name^=alto]");
        var a_ancho = $("#table" + indice_top).find("input[name^=ancho]");
        var a_largo = $("#table" + indice_top).find("input[name^=largo]");
        var a_numero_bultos = $("#table" + indice_top).find("input[name^=numero_bultos]");
        var a_volumen = $("#table" + indice_top).find("input[name^=volLinea]");
        // indice es el indice de cada input como ancho
        // indice top es el indice de cada tabla creada dinamicamente

        //alert($("#table"+indice_top).find("input[name^=alto]").val());
        //alert(indice);
        //alert(a_volumen.length);
        //alert('ind '+indice);alert('ind  top '+indice_top);
        //alert('volumen fila 0 tabla 1 '+at_volumen.eq(0).attr("value")); 

        if (a_alto.eq(indice).val() * 1 >= 230 || a_largo.eq(indice).val() * 1 >= 590 || a_ancho.eq(indice).val() * 1 >= 230
                || document.getElementById('peso' + indice_top).value * 1 >= 3500) {
            document.getElementById('sobredimension' + indice_top).checked = true;
        } else {
            document.getElementById('sobredimension' + indice_top).checked = false;
        }
        var a_numero_bul = $("#table1").find("input[id^=numero_bultos]");
        var at_volumen = $("#table" + indice_top).find("input[name^=volLinea]");
        //alert('ind 1 id '+a_numero_bultos.eq(1).attr("id"));				alert('ind 1 name '+a_numero_bultos.eq(1).attr("name"));


        //alert('ind 1 valor '+a_numero_bultos.eq(1).val());

        /* alert('ind 0  valor '+a_numero_bultos.eq(0).attr("value"));
         
         alert('ind 0 id '+a_numero_bultos.eq(0).attr("id"));				alert('ind 0 name '+a_numero_bultos.eq(0).attr("name"));*/


        if (a_alto.eq(indice).val() * 1 != 0 && a_ancho.eq(indice).val() * 1 != 0 && a_largo.eq(indice).val() * 1 != 0 && a_numero_bultos.eq(indice).val() * 1 != 0) {
            /*alert(a_alto.eq(indice).val());
             alert(a_ancho.eq(indice).val());
             alert(a_largo.eq(indice).val());
             alert(a_numero_bultos.eq(indice).val());*/

            producto = (a_alto.eq(indice).val() / 100) *
                    (a_ancho.eq(indice).val() / 100) *
                    (a_largo.eq(indice).val() / 100) *
                    (a_numero_bultos.eq(indice).val());
            //alert(producto) 
            a_volumen.eq(indice).val(fix(producto, 2));
        }
        tmp = 0;
        for (k = 0; k < at_volumen.length; k++) {
            //alert('n bultos valor '+a_numero_bultos.eq(k).attr("value"));
            tmp += at_volumen.eq(k).val() * 1;
        }

        tmpB = 0;
        for (k = 0; k < at_volumen.length; k++) {
            //alert('n bultos valor '+a_numero_bultos.eq(k).attr("value"));
            tmpB += a_numero_bultos.eq(k).val() * 1;
        }

        document.getElementById('volumen' + indice_top).value = fix(tmp, 2);
        document.getElementById('bultos' + indice_top).value = tmpB;
    }

</script>
<?php
$link = Conectarse();
$q_embalajes = mysqli_query($link, "select * from embalajes   order by nombre_embalaje");

while ($rq_embalajes = mysqli_fetch_array($q_embalajes)) {
    $embalajes[] = $rq_embalajes["nombre_embalaje"];
}

/*$cfs = mysqli_query($link, "SELECT * FROM pickups where pickupplace<>'' and pickupplace<>'.' order by pickupplace  ");
while ($rcfs = mysqli_fetch_array($cfs)) {
    $Apickupplace[] = $rcfs[pickupplace];
    $Apickupaddress[] = $rcfs[pickupaddress];
    $Apickupcity[] = $rcfs[pickupcity];
    $Apickupstate[] = $rcfs[pickupstate];
    $Apickupzip[] = $rcfs[pickupzip];
    $Apickupcontact[] = $rcfs[pickupcontact];
    $Apickuptelephone[] = $rcfs[pickuptelephone];
    $Apickupemail[] = $rcfs[pickupemail];
    $Alocation_code[] = $rcfs[location_code];
}*/
?>

<style>
    table {
        border-collapse:collapse;
        color:#fff;
        font-size: 13px;
        font-family: Arial, Helvetica, sans-serif;
        font-size:13px;}

    td, th {
        color:#000;
    }
    td { 

    }

    thead th, tfoot th { 
        background:rgb(166,172,181);

        font-size: 11px;
    }

    tbody th, tbody td { 

        font-size: 12px;
    }

    /* roScripts
    Table Design by Mihalcea Romeo
    www.roscripts.com
    ----------------------------------------------- */

    table.cargas {
        border-collapse:collapse;
        background:#EFF4FB; /* url(images/teaser.gif) repeat-x;*/
        border-left:1px solid #686868;
        border-right:1px solid #686868;
        font:0.8em/145% 'Trebuchet MS',helvetica,arial,verdana;
        color: #333;
    }

    table.cargas td, th {
        padding:5px;
    }
    table  tr.cargas {
        border-bottom: dotted 1px #333;
    }
    table.cargas caption {
        padding: 0 0 .5em 0;
        text-align: left;
        font-size: 1.4em;
        font-weight: bold;
        text-transform: uppercase;
        color: #333;
        background: transparent;
    }

    /* =links
    ----------------------------------------------- */

    table.cargas  a {
        color:#950000;
        text-decoration:none;
    }

    table.cargas a:link {}

    table.cargas a:visited {
        font-weight:normal;
        color:#666;
        text-decoration: line-through;
    }

    table.cargas a:hover {
        border-bottom: 1px dashed #bbb;
    }

    /* =head =foot
    ----------------------------------------------- */

    table.cargas thead th, tfoot th, tfoot td {
        background:#333; /* url(http://www.roscripts.com/images/llsh.gif) repeat-x;*/
        color:#fff
    }

    table.cargas tfoot td {
        text-align:right
    }

    /* =body
    ----------------------------------------------- */

    table.cargas tbody tr {
        border-bottom: dotted 1px #333;
    }

    table.cargas tbody th {
        white-space: nowrap;
    }

    table.cargas tbody th a {
        color:#333;
    }

    .odd {}

    table.cargas tbody tr:hover {
        background:#fafafa
    }

</style>	
</head>

<style>
    #dhtmltooltip{
        position: absolute;
        width: 150px;
        border: 2px solid black;
        padding: 2px;
        background-color: lightyellow;
        visibility: hidden;
        z-index: 100;
        /*Remove below line to remove shadow. Below line should always appear last within this CSS*/
        filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135);
    }
</style>
<div id="dhtmltooltip"></div>
<?php include("tooltip.php"); ?>
<body>

    <?php $hoy = date("d/m/Y"); ?>


    <div style="margin-left:5%; ">


        <script type="text/javascript" src="nogray_js/TO/ng_all.js"></script>
        <script type="text/javascript" src="nogray_js/TO/components/timepicker.js"></script>
        <SCRIPT type="text/javascript" src="js/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js?random=20060118"></script>
        <link type="text/css" rel="stylesheet" href="js/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css" media="screen"></LINK>

        <script type="text/javascript" src="https://softinternal.com/js/autocomplete_ronline/jquery.js"></script>
        <script type="text/javascript" src="https://softinternal.com/js/autocomplete_ronline/jquery.autocomplete.js"></script>
        <link type="text/css" rel="stylesheet" href="https://softinternal.com/js/autocomplete_ronline/jquery.autocomplete.css" media="screen"></LINK>


        <script src="https://intralogs.com.mx/js/windowfiles/dhtmlwindow.js" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="https://intralogs.com.mx/js/windowfiles/dhtmlwindow.css" media="all" /> 

        <script>
    function addRow(tableID) {

        var table = document.getElementById(tableID);
        var rowCount = table.rows.length;
        var row = table.insertRow(rowCount);
        zzz = rowCount;
        var cell1 = row.insertCell(0);
        var element1 = document.createElement("input");
        element1.type = "checkbox";
        cell1.appendChild(element1);
        var cell2 = row.insertCell(1);
        var element2 = document.createElement("input");
        element2.type = "text";
        element2.id = 'marcas' + zzz;
        element2.name = 'marcas' + zzz;
        cell2.appendChild(element2);
        var cell3 = row.insertCell(2);
        var element3 = document.createElement("input");
        element3.readOnly = true;
        element3.type = "text";
        element3.size = 5;
        element3.id = 'bultos' + zzz;
        element3.name = 'bultos' + zzz;
        element3.addEventListener("mouseover", function () {
            ddrivetip('Es igual a la suma de Num Bultos que complete en dimensiones. Por favor Agregar dimensiones.', 'yellow', 450)
        });
        element3.addEventListener("mouseout", function () {
            hideddrivetip()
        });
        cell3.appendChild(element3);
        /* var cell4 = row.insertCell(3);
         
         var element4 = document.createElement("input");
         
         element4.type = "text";
         
         element4.size = 7;
         
         element4.id = 'tipo'+zzz;
         
         element4.name = 'tipo'+zzz;
         
         cell4.appendChild(element4);
         */

        var cell4 = row.insertCell(3);
        var element4 = document.createElement("select");
        element4.type = "text";
        element4.id = 'tipo' + zzz;
        element4.name = 'tipo' + zzz;
        var option = document.createElement("option");
        option.value = "";
        option.text = "";
        element4.appendChild(option);
<?php for ($i = 0; $i < count($embalajes); $i++) { ?>
            var option = document.createElement("option");
            option.value = "<?= $embalajes[$i] ?>";
            option.text = "<?= $embalajes[$i] ?>";
            element4.appendChild(option);
<?php } ?>
        cell4.appendChild(element4);
        var cell5 = row.insertCell(4);
        var element5 = document.createElement("textarea");
        element5.type = "textarea";
        element5.cols = 45;
        element5.rows = 5;
        element5.id = 'descripcion' + zzz;
        element5.name = 'descripcion' + zzz;
        cell5.appendChild(element5);
        ///////////////////////////////////// DATOS DE IMO
        var cell6 = row.insertCell(5);
        var element6 = document.createElement("select");
        element6.id = 'imo' + zzz;
        element6.name = 'imo' + zzz;
        var option = document.createElement("option");
        option.value = "";
        option.text = "";
        element6.appendChild(option);
        var option = document.createElement("option");
        option.value = "SI";
        option.text = "SI";
        element6.appendChild(option);
        var option = document.createElement("option");
        option.value = "NO";
        option.text = "NO";
        element6.appendChild(option);
        element6.addEventListener("change", function () {
            if (element6.value == 'SI') {
                elementClaseImo.style.visibility = 'visible';
            } else {
                elementClaseImo.style.visibility = 'hidden';
            }
        });
        cell6.appendChild(element6);
        var sp = document.createElement("span");
        sp.innerHTML = '&nbsp;';
        cell6.appendChild(sp);
        var elementClaseImo = document.createElement("select");
        elementClaseImo.id = 'clase_imo' + zzz;
        elementClaseImo.name = 'clase_imo' + zzz;
        elementClaseImo.style.visibility = 'hidden';
        var option = document.createElement("option");
        option.value = "";
        option.text = "";
        elementClaseImo.appendChild(option);
        var option = document.createElement("option");
        option.value = "2.1";
        option.text = "2.1";
        elementClaseImo.appendChild(option);
        var option = document.createElement("option");
        option.value = "2.2";
        option.text = "2.2";
        elementClaseImo.appendChild(option);
        var option = document.createElement("option");
        option.value = "3";
        option.text = "3";
        elementClaseImo.appendChild(option);
        var option = document.createElement("option");
        option.value = "4.1";
        option.text = "4.1";
        elementClaseImo.appendChild(option);
        var option = document.createElement("option");
        option.value = "5.1";
        option.text = "5.1";
        elementClaseImo.appendChild(option);
        var option = document.createElement("option");
        option.value = "6.1";
        option.text = "6.1";
        elementClaseImo.appendChild(option);
        var option = document.createElement("option");
        option.value = "8";
        option.text = "8";
        elementClaseImo.appendChild(option);
        var option = document.createElement("option");
        option.value = "9";
        option.text = "9";
        elementClaseImo.appendChild(option);
        elementClaseImo.addEventListener("mouseover", function () {
            ddrivetip('Complete clase imo', 'yellow', 130)
        });
        elementClaseImo.addEventListener("mouseout", function () {
            hideddrivetip()
        });
        cell6.appendChild(elementClaseImo);
        /////////////////////////////////////



        var cell7 = row.insertCell(6);
        var element7 = document.createElement("input");
        element7.type = "text";
        element7.size = 7;
        element7.id = 'peso' + zzz;
        element7.name = 'peso' + zzz;
        cell7.appendChild(element7);
        var cell8 = row.insertCell(7);
        var element8 = document.createElement("input");
        element8.type = "text";
        element8.readOnly = true;
        element8.size = 7;
        element8.id = 'volumen' + zzz;
        element8.name = 'volumen' + zzz;
        element8.addEventListener("mouseover", function () {
            ddrivetip('Es igual a la suma de los volúmenes calculados según las medidas ingresadas en dimensiones. Por favor Agregar dimensiones.', 'yellow', 450)
        });
        element8.addEventListener("mouseout", function () {
            hideddrivetip()
        });
        cell8.appendChild(element8);
        var cell9 = row.insertCell(8);
        var element9 = document.createElement("input");
        element9.type = "text";
        element9.size = 7;
        element9.id = 'arancel' + zzz;
        element9.name = 'arancel' + zzz;
        cell9.appendChild(element9);
        var cell10 = row.insertCell(9);
        var elementsp = document.createElement('span')
        var newDiv = document.createElement("div");
        newDiv.id = 'div' + zzz;
        elementsp.id = zzz;
        elementsp.innerHTML = 'Agregar dimensiones';
        elementsp.style.cursor = 'pointer';
        elementsp.style.color = "#0088cc";
        elementsp.style.textDecoration = "underline";
        elementsp.style.fontSize = "12px";
        elementsp.addEventListener("mouseover", function () {
            ddrivetip('<P>DECLARAR MEDIDAS EN CENTIMETROS</P>EJ: 1.20 x 1.00 x 1.10', 'yellow', 250);
        });
        elementsp.addEventListener("mouseout", function () {
            hideddrivetip()
        });
        elementsp.addEventListener("click", function () {
            ajax_dimensiones_ronline(newDiv.id, 'mostrar_dimensiones.php', newDiv.id)
        });
        cell10.appendChild(elementsp);
        //agrego checkboxs de carga no estibable y sobredimension
        var br1 = document.createElement("br");
        cell10.appendChild(br1);
        var elementCargaConSobredimension = document.createElement("input");
        elementCargaConSobredimension.type = "checkbox";
        elementCargaConSobredimension.id = 'sobredimension' + zzz;
        elementCargaConSobredimension.name = 'sobredimension' + zzz;
        elementCargaConSobredimension.addEventListener("mouseover", function () {
            ddrivetip('SELECCIONAR LA OPCION SI SE CUMPLEN UNA O MAS DE LAS SIGUIENTES CONDICIONES:<p></p><p>&ordm; LA ALTURA DEL BULTO ES IGUAL O SUPERIOR A 230CMS</p><p>&ordm; EL LARGO DEL BULTO ES IGUAL O SUPERIOR A 590CMS</p><p>&ordm; EL ANCHO DEL BULTO ES IGUAL O SUPERIOR A 230CMS</p><p>&ordm; EL PESO DEL BULTO ES IGUAL O SUPERIOR A 3500KGS</p>', 'yellow', 450);
        });
        elementCargaConSobredimension.addEventListener("mouseout", function () {
            hideddrivetip()
        });
        cell10.appendChild(elementCargaConSobredimension);
        var elementspanCargaConSobredimension = document.createElement('span')
        elementspanCargaConSobredimension.innerHTML = ' Carga sobredimensionada';
        elementspanCargaConSobredimension.style.fontSize = "12px";
        cell10.appendChild(elementspanCargaConSobredimension);
        var br1 = document.createElement("br");
        cell10.appendChild(br1);
        var elementCargaNoestibable = document.createElement("input");
        elementCargaNoestibable.type = "checkbox";
        elementCargaNoestibable.id = 'no_estibable' + zzz;
        elementCargaNoestibable.name = 'no_estibable' + zzz;
        elementCargaNoestibable.addEventListener("mouseover", function () {
            ddrivetip('A PISO Y NADA ENCIMA', 'yellow', 160)
        });
        elementCargaNoestibable.addEventListener("mouseout", function () {
            hideddrivetip()
        });
        cell10.appendChild(elementCargaNoestibable);
        var elementspanCargaNoestibable = document.createElement('span')
        elementspanCargaNoestibable.innerHTML = ' No estibable';
        elementspanCargaNoestibable.style.fontSize = "12px";
        cell10.appendChild(elementspanCargaNoestibable);
        //agrego div de ajax de dimensiones
        cell10.appendChild(newDiv);
        element7.addEventListener("keyup", function () {

            if (element7.value * 1 >= 3500) {
                elementCargaConSobredimension.checked = true;
            } else {
                elementCargaConSobredimension.checked = false;
            }
        });
    }

    function addRow1(tableID, num_partida) {
        var table = document.getElementById(tableID);
        var rowCount = table.rows.length;
        var row = table.insertRow(rowCount);
        yyy = rowCount;
        var cell1 = row.insertCell(0);
        var element1 = document.createElement("input");
        element1.id = 'chk1';
        element1.style.display = 'none';
        element1.type = "checkbox";
        cell1.appendChild(element1);
        var elementpartida = document.createElement("input");
        elementpartida.type = "hidden";
        elementpartida.size = 5;
        elementpartida.id = 'numero_partida[]';
        elementpartida.name = 'numero_partida[]';
        elementpartida.value = num_partida;
        cell1.appendChild(elementpartida);
        var elementspan1 = document.createElement('span')
        elementspan1.innerHTML = '[+]';
        elementspan1.style.cursor = 'pointer';
        elementspan1.style.color = "#0088cc";
        elementspan1.addEventListener("click", function () {
            addRow1(tableID, num_partida)
        });
        cell1.appendChild(elementspan1);
        var elementspan2 = document.createElement('span')
        elementspan2.id = 'span#' + yyy;
        elementspan2.innerHTML = '[-]';
        elementspan2.style.cursor = 'pointer';
        elementspan2.style.color = "#0088cc";
        elementspan2.addEventListener("click", function () {
            deleteRow1(tableID, elementspan2.id)
        });
        cell1.appendChild(elementspan2);
        elementspan1.addEventListener("mouseover", function () {
            ddrivetip('Hacer click en [+] y [-] para agregar y borrar l&iacute;neas', 'yellow', 330);
        });
        elementspan1.addEventListener("mouseout", function () {
            hideddrivetip()
        });
        elementspan2.addEventListener("mouseover", function () {
            ddrivetip('Hacer click en [+] y [-] para agregar y borrar l&iacute;neas', 'yellow', 330);
        });
        elementspan2.addEventListener("mouseout", function () {
            hideddrivetip()
        });
        var cell2 = row.insertCell(1);
        cell2.align = 'center';
        var element2 = document.createElement("input");
        element2.type = "text";
        element2.size = 5;
        element2.index = element2.length;
        element2.id = 'numero_bultos[]';
        element2.name = 'numero_bultos[]';
        /*element2.addEventListener("keypress", function () { //alert('keypress')
         fun_AllowOnlyAmountInteger(element2.value); 
         });*/

        element2.addEventListener("keypress", function () {
            return fun_AllowOnlyAmountInteger(element2.value);
        }, false);
        element2.addEventListener("keyup", function () {
            //alert(element2.index)
            if (rowCount - 1 == -1) {
                indice = 0;
            } else {
                indice = rowCount - 1;
            }
            //alert(indice)
            calculos_dimension(indice, num_partida);
        });
        cell2.appendChild(element2);
        var cell3 = row.insertCell(2);
        cell3.align = 'center';
        var element3 = document.createElement("input");
        element3.type = "text";
        element3.size = 5;
        element3.id = 'largo[]';
        element3.name = 'largo[]';
        element3.addEventListener("keypress", function () {
            return fun_AllowOnlyAmountAndDot(element3.value);
        }, false);
        element3.addEventListener("keyup", function () {
            if (rowCount - 1 == -1) {
                indice = 0;
            } else {
                indice = rowCount - 1;
            }

            calculos_dimension(indice, num_partida);
        });
        cell3.appendChild(element3);
        var cell4 = row.insertCell(3);
        cell4.align = 'center';
        var element4 = document.createElement("input");
        element4.type = "text";
        element4.size = 5;
        element4.id = 'ancho[]';
        element4.name = 'ancho[]';
        element4.addEventListener("keypress", function () {
            return fun_AllowOnlyAmountAndDot(element4.value);
        }, false);
        element4.addEventListener("keyup", function () {
            if (rowCount - 1 == -1) {
                indice = 0;
            } else {
                indice = rowCount - 1;
            }

            calculos_dimension(indice, num_partida);
        });
        cell4.appendChild(element4);
        var cell5 = row.insertCell(4);
        cell5.align = 'center';
        var element5 = document.createElement("input");
        element5.type = "text";
        element5.size = 5;
        element5.id = 'alto[]';
        element5.name = 'alto[]';
        element5.addEventListener("keypress", function () {
            return fun_AllowOnlyAmountAndDot(element5.value);
        }, false);
        element5.addEventListener("keyup", function () {
            if (rowCount - 1 == -1) {
                indice = 0;
            } else {
                indice = rowCount - 1;
            }

            calculos_dimension(indice, num_partida);
        });
        cell5.appendChild(element5);
        var cell6 = row.insertCell(5);
        cell6.align = 'center';
        var element6 = document.createElement("input");
        element6.readOnly = true;
        element6.type = "text";
        element6.size = 5;
        element6.id = 'volLinea[]';
        element6.name = 'volLinea[]';
        cell6.appendChild(element6);
    }

    function deleteRow1(tableID, fila) {
        fil = fila.split('span#');
        fil1 = fil[1];
        var table = document.getElementById(tableID);
        var row = table.rows[fil1];
        var primera = row.cells[1].childNodes[0];
        var segunda = row.cells[2].childNodes[0];
        var tercera = row.cells[3].childNodes[0];
        var cuarta = row.cells[4].childNodes[0];
        primera.value = '';
        segunda.value = '';
        tercera.value = '';
        cuarta.value = '';
        /*var chkbox = row.cells[0].childNodes[0];
         
         if(null != chkbox && true == chkbox.checked) {
         
         table.deleteRow(i);
         
         rowCount--;
         
         i--;
         
         }*/




    }


    /*function deleteRow1(tableID,fila) {
     
     try {
     
     var table = document.getElementById(tableID);
     
     var rowCount = table.rows.length;
     
     
     
     for(var i=0; i<rowCount; i++) {
     
     var row = table.rows[i];
     
     //var chkbox = row.cells[0].childNodes[0];
     var elemen = document.getElementsByName('chk1')
     //alert(chkbox.checked)
     //if(null != chkbox && true == chkbox.checked) {
     //alert(elemen[i].checked)
     if(elemen[i]){	
     if(elemen[i].checked){
     table.deleteRow(i);
     
     rowCount--;
     
     i--;
     
     }
     }
     
     }
     var rowCount = table.rows.length;
     
     
     
     }catch(e) {
     
     alert(e);
     
     }
     
     }*/

    function quita_blancos(valor) { //,input
        value_no_blank = valor.replace(/\s+/gi, '')
        //document.getElementById(input).value=value_no_blank
        return value_no_blank.length
    }


    var zzz = 1;
    var yyy = 1;
    ng.ready(function () {
        ng.ready(function () {
            var tmpkr1 = new ng.TimePicker({
                input: 'desde'
            });
            var tmpkr2 = new ng.TimePicker({
                input: 'hasta'
            });
        });
    });
    $().ready(function () {
        $("#pickupplace").autocomplete("lista_de_pickups.php", {
            extraParams: {
                usu: function () {
                    return document.getElementById('txtcustomeremail').value;
                }
            },
            delay: 100,
            cacheLength: 0,
            width: 620,
            matchContains: true,
            selectFirst: false,
            max: 150
        });
        $("#pickupplace").result(function (event, data, formatted) {
            //$("#pickupplace").val(data[0]);
            $("#pickupaddress").val(data[1]);
            $("#pickupcity").val(data[2]);
            $("#pickupstate").val(data[3]);
            $("#pickupzip").val(data[4]);
            $("#pickupcity").val(data[5]);
            $("#pick_up_contact").val(data[6]);
            $("#pick_up_telephone").val(data[7]);
            $("#pickupemail").val(data[8]);
			//if(data[9]!='SIN RESULTADOS'){
            $("#pickupplace").val(data[9]);
			//}
			$("#idpickupplace").val(data[10]);
        });
        $("#customsagent").autocomplete("lista_de_agentes_aduanales.php", {
            width: 420,
            matchContains: true,
            selectFirst: false,
            cacheLength: 0,
            max: 150
        });
        $("#customsagent").result(function (event, data, formatted) {

            $("#customsagent").val(data[3]);
            $("#customstel").val(data[1]);
            $("#idagente_aduanal").val(data[2]);
            $("#patente").val(data[4]);
        });
        $("#customscontact").autocomplete("lista_de_agentes_aduanales_contactos.php", {
            extraParams: {
                idagente: function () {
                    return document.getElementById('idagente_aduanal').value;
                }
            },
            width: 420,
            matchContains: true,
            selectFirst: false,
            cacheLength: 0,
            max: 150
        });
        $("#customscontact").result(function (event, data, formatted) {

            $("#customscontact").val(data[0]);
            $("#customsemail").val(data[1]);
        });
    });

    function validaDecimales(event, max) {
        var valor = $(event.path[0]).val();
        var punto = 0;
        if (valor < max) {
            if ((event.charCode >= 48 && event.charCode <= 57) || event.key == '.') {
                if (event.key == '.') {
                    punto++;
                }
                if (punto <= 1) {
                    return true;
                } else {
                    return false
                }

            }
        }else{
            alert('Valor máximo '+ (max - 0.1))
        }

        return false;
    }
    
    function valida_maximo(event, max){
        var valor = $(event.path[0]).val();
        if (valor < max) {
            return true
        }else{
            $(event.path[0]).val('');
            return false;
        }
    }
        </script>

        <?php
        $idbooking = $_POST[idbooking] != '' ? $_POST[idbooking] : $_GET[idbooking];

//echo 'idbooking A '. $idbooking;

        $datos = mysqli_query($link, "select * from usuarios_reservacion_online where username='" . $_SESSION[user] . "'");
        $rdatos = mysqli_fetch_array($datos);
        $txtcustomercontact = $rdatos[pater];
        $txtcustomeremail = $rdatos[email];

        $cliente = mysqli_query($link, "select * from customerexpint_n where id = '" . $rdatos[id_empresa] . "' limit 1");
        $rbuscar = mysqli_fetch_array($cliente);
        $id_empresa = $rbuscar[id];
        $txtcustomer = $rbuscar["socialreason"];
        $txtcustomercity = $rbuscar["city"];
        $txtcustomertel = $rbuscar["tel1"];

        if ($idbooking != '') {
            $query = mysqli_query($link, "select * from bookingexpint where idbooking = '$idbooking'");
            $row = mysqli_fetch_array($query);


            if ($row[files] != 'RONLINE') {
                $master = mysqli_query($link, "select * from datosexpint where files = '" . $row[files] . "'");
                $rMaster = mysqli_fetch_array($master);
                $viaje = $rMaster[voyage];
                $barco = $rMaster[vessel];
                $zarpe = $rMaster[ets];
                $cierredoctos = $rMaster[closingdocs];
                $cierreimo = $rMaster[closingdocs2];
                $ets = $rMaster[closingcargoes] != '' ? $rMaster[closingcargoes] : $rMaster[ets];
                $etafinaldest = $rMaster[eta];
                $from = $rMaster[pol] . ', ' . $rMaster[pol_country];
                $to = $row[finaldestination];

                $cierreimo = $cierreimo == '' ? (isset($_GET[cierreimo]) ? $_GET[cierreimo] : $_POST[cierreimo]) : $cierreimo;
                $cierredoctos = $cierredoctos == '' ? (isset($_GET[cierredoctos]) ? $_GET[cierredoctos] : $_POST[cierredoctos]) : $cierredoctos;
                $ets = $ets == '' ? (isset($_GET[ets]) ? $_GET[ets] : $_POST[ets]) : $ets;
                $tt = $tt == '' ? (isset($_GET[tt]) ? $_GET[tt] : $_POST[tt]) : $tt;
                if ($tt * 1 != 0) {
                    $etafinaldest = $etafinaldest == '' ? (isset($_GET[eta]) ? $_GET[eta] : $_POST[etafinaldest]) : $etafinaldest;
                    // sumarDias(str_replace('/','-',$ets),$tt);
                }
            } else {
                $viaje = $row[ronline_viaje];
                $barco = $row[ronline_barco];
                $zarpe = $row[ronline_zarpe];
                $cierreimo = $row[ronline_cierreimo];
                $cierredoctos = $row[ronline_cierredoctos];
                $ets = $row[ronline_ets];
                $via = $row[ronline_via];
                $from = $row[ronline_from];
                $to = $row[finaldestination];
                $etafinaldest = $row[etafinaldest];
            }
        }


        $txtcustomer = $txtcustomer != '' ? $txtcustomer : $row[customer];
        $txtcustomercity = $txtcustomercity != '' ? $txtcustomercity : $row[sucursal];
        $txtcustomercontact = $txtcustomercontact != '' ? $txtcustomercontact : $row[customercontact];
        $txtcustomertel = $txtcustomertel != '' ? $txtcustomertel : $row[customertel];
        $txtcustomeremail = $txtcustomeremail != '' ? $txtcustomeremail : $row[customeremail];
        $uncode_pickup_city = $uncode_pickup_city != '' ? $uncode_pickup_city : $row[uncode_pickup_city];

        $barco = $barco == '' ? (isset($_GET[barco]) ? $_GET[barco] : $_POST[barco]) : $barco;
        $from = $from == '' ? (isset($_GET[from]) ? $_GET[from] . ', MEXICO' : $_POST[from]) : $from;
        $via = $via == '' ? (isset($_GET[via]) ? $_GET[via] : $_POST[via]) : $via;
        $to = $to == '' ? (isset($_GET[to]) ? $_GET[to] : $_POST[to]) : $to;
        $viaje = $viaje == '' ? (isset($_GET[viaje]) ? $_GET[viaje] : $_POST[viaje]) : $viaje;
        $zarpe = $zarpe == '' ? (isset($_GET[zarpe]) ? $_GET[zarpe] : $_POST[zarpe]) : $zarpe;
        $cierreimo = $cierreimo == '' ? (isset($_GET[cierreimo]) ? $_GET[cierreimo] : $_POST[cierreimo]) : $cierreimo;
        $cierredoctos = $cierredoctos == '' ? (isset($_GET[cierredoctos]) ? $_GET[cierredoctos] : $_POST[cierredoctos]) : $cierredoctos;
        $ets = $ets == '' ? (isset($_GET[ets]) ? $_GET[ets] : $_POST[ets]) : $ets;
        $tt = $tt == '' ? (isset($_GET[tt]) ? $_GET[tt] : $_POST[tt]) : $tt;
        if ($tt * 1 != 0) {
            //$etafinaldest=sumarDias(str_replace('/','-',$ets),$tt);
            $etafinaldest = $etafinaldest == '' ? (isset($_GET[eta]) ? $_GET[eta] : $_POST[etafinaldest]) : $etafinaldest;
        }

        $mensaje = '';

        if (isset($_POST[submit])) {

            if ($idbooking != '') {
                $query_dim = mysqli_query($link, "select * from dimensiones_ronline where booking = 'BKG" . $idbooking . "'");
                //echo "select * from dimensiones_ronline where booking = 'BKG".$idbooking ."'";
                $query_dim1 = mysqli_query($link, "select * from detailcargaexpint where bookingno = 'BKG" . $idbooking . "'");
                //echo "select * from detailcargaexpint where bookingno = 'BKG".$idbooking ."'";	 
            }
            $uncode_pickup_city = $_POST[uncode_pickup_city];
            $pickupaddress = $_POST[pickupaddress];
            $txtpick_up_contact = trim(strtoupper($_POST[pick_up_contact]));
            $txtpickuptime_from = trim($_POST[desde]);
            $txtpickuptime_till = trim($_POST[hasta]);
            $txtpickupcity = trim(strtoupper($_POST[pickupcity]));
            $txtpickupstate = trim(strtoupper($_POST[pickupstate]));
            $txtpickupplace = trim(strtoupper($_POST[pickupplace]));
            $txtpickupzip = trim(strtoupper($_POST[pickupzip]));
            $txtpick_up_telephone = trim(strtoupper($_POST[pick_up_telephone]));
            $txtpickupemail = trim(strtoupper($_POST[pickupemail]));
            $txtpickupdate = trim(strtoupper($_POST[pickupdate]));
            //$txttransport_comments=trim(strtoupper($_POST[pick_up_comments]));


            $txtforwarder_reference = trim(strtoupper($_POST[forwarder_reference2]));

            $txtcustomsagent = trim(strtoupper($_POST[customsagent]));

            if ($txtcustomsagent == 'INTERTEAM S.A. DE C.V.') {
                $patente = ' ';
            } else {
                $patente = trim(strtoupper($_POST[patente]));
            }
            $txtcustomscontact = trim(strtoupper($_POST[customscontact]));
            $txtcustomstel = trim(strtoupper($_POST[customstel]));
            $txtcustomsemail = trim(strtoupper($_POST[customsemail]));


            $barco = trim(strtoupper($_POST[barco]));
            $from = trim(strtoupper($_POST[from]));
            $via = trim(strtoupper($_POST[via]));
            $to = trim(strtoupper($_POST[to]));
            $viaje = trim(strtoupper($_POST[viaje]));
            $zarpe = trim(strtoupper($_POST[zarpe]));
            $cierreimo = trim(strtoupper($_POST[cierreimo]));
            $cierredoctos = trim(strtoupper($_POST[cierredoctos]));
            $ets = trim(strtoupper($_POST[ets]));
            $etafinaldest = trim(strtoupper($_POST[etafinaldest]));

            $instrucciones_especiales = trim(strtoupper($_POST[instrucciones_especiales]));

            $flete_maritimo = $_POST[flete_maritimo2];
            $idagente_aduanal = $_POST[idagente_aduanal];

            $TMP = explode(',', $to);

            if ($idbooking == '' and $mensaje == '') {
                ///////////////// guardo la reservacion para obtener su ID 


                if ($idbooking == '' and trim($TMP[0]) != '' and trim($TMP[1]) != '') {
                    mysqli_query($link, "INSERT INTO bookingexpint (files) Values ('RONLINE')");
                    $idbooking = mysqli_insert_id($link);

                    mysqli_query($link, "INSERT INTO hblexpint (files,hbl,booking) Values ('RONLINE','HBL" . $idbooking . "','BKG" . $idbooking . "')");

                    mysqli_query($link, "INSERT INTO detailcargaexpint (files,bookingno) Values ('RONLINE','BKG" . $idbooking . "')");
                }

                if (strpos($from, 'ALTAMIRA') !== false) {
                    $uncode_pol = 'ATM';
                } elseif (strpos($from, 'MANZANILLO') !== false) {
                    $uncode_pol = 'ZLO';
                } elseif (strpos($from, 'VERACRUZ') !== false) {
                    $uncode_pol = 'VER';
                }


                $result1 = mysqli_query($link, "SELECT iata_code FROM puertos_k where (international_name = '" . trim($TMP[0]) . "' 
							or name_without_diacritics = '" . trim($TMP[0]) . "' ) and country<>'' and (country = '" . trim($TMP[1]) . "' or country = '" . trim($TMP[2]) . "') 
							and (iata_code<>'')");

                $R1 = mysqli_fetch_array($result1);
                $uncode_pod = $R1[iata_code];

                $booking_interteam = 'EXIT' . $uncode_pol . $uncode_pod . $idbooking;


                mysqli_query($link, "UPDATE bookingexpint SET 
							files='RONLINE',
							booking='BKG" . $idbooking . "',
							customer='$txtcustomer',customertel='$txtcustomertel',customeremail='$txtcustomeremail',customercontact='$txtcustomercontact',
							finaldestination='$to',
							customsagent='$txtcustomsagent',patente='$patente',
							customstel='$txtcustomstel',
							customsemail='$txtcustomsemail',
							customscontact='$txtcustomscontact',
							pickupdate='$txtpickupdate',
							pickuptime_from='$txtpickuptime_from',
							pickuptime_till='$txtpickuptime_till', 
							pickupaddress='$pickupaddress',
							pick_up_contact='$txtpick_up_contact', 
							pickupemail='$txtpickupemail',pickupstate='$txtpickupstate',pickupplace='$txtpickupplace',
							pickupcity='$txtpickupcity',pickupzip='$txtpickupzip',pick_up_telephone='$txtpick_up_telephone',
							sucursal='$sucursal',pickupplace2='$txtpickupplace2',
							booking_interteam=if(booking_interteam='','" . trim($booking_interteam) . "',booking_interteam),
							booking_interteam_nuevo=if(booking_interteam_nuevo='','" . trim($booking_interteam) . "',booking_interteam_nuevo), 
							fechaRegistro = '" . date("Y-m-d") . "',
							forwarder_reference = '$txtforwarder_reference',
							guardo_usuario='RESERVACION ONLINE',
							horaRegistro='" . date("H:i:s") . "',
							commentbooking='$instrucciones_especiales',
							ronline_barco='$barco',
							ronline_from='$from',
							ronline_via='$via',
							ronline_viaje='$viaje',
							ronline_zarpe='$zarpe',
							ronline_cierreimo='$cierreimo',
							ronline_cierredoctos='$cierredoctos',
							ronline_ets='$ets',
							ronline_flete_maritimo='$flete_maritimo',
							etafinaldest='" . str_replace('-', '/', $etafinaldest) . "',
							idagente_aduanal='$idagente_aduanal'
							WHERE  idbooking ='$idbooking' "); //
            } elseif ($idbooking != '') {
                $query_dim1 = mysqli_query($link, "select * from detailcargaexpint where bookingno = 'BKG" . $idbooking . "'");
//echo "select * from detailcargaexpint where bookingno = 'BKG".$idbooking ."'";
                // actualizacion de la reservacion
                if (strpos($from, 'ALTAMIRA') !== false) {
                    $uncode_pol = 'ATM';
                } elseif (strpos($from, 'MANZANILLO') !== false) {
                    $uncode_pol = 'ZLO';
                } elseif (strpos($from, 'VERACRUZ') !== false) {
                    $uncode_pol = 'VER';
                }


                $result1 = mysqli_query($link, "SELECT iata_code FROM puertos_k where (international_name = '" . trim($TMP[0]) . "' 
						or name_without_diacritics = '" . trim($TMP[0]) . "' ) and country<>'' and (country = '" . trim($TMP[1]) . "' or country = '" . trim($TMP[2]) . "') and (iata_code<>'')");

                $R1 = mysqli_fetch_array($result1);
                $uncode_pod = $R1[iata_code];
                $status_mensaje = '';
                $booking_interteam = 'EXIT' . $uncode_pol . $uncode_pod . $idbooking;
                //	transport_comments='$txttransport_comments',
                mysqli_query($link, "UPDATE bookingexpint SET 
							booking_interteam=if(booking_interteam='','" . trim($booking_interteam) . "',booking_interteam),
							booking_interteam_nuevo=if(booking_interteam_nuevo='','" . trim($booking_interteam) . "',booking_interteam_nuevo),
							finaldestination='$to',
							customsagent='$txtcustomsagent',	patente='$patente',
							customstel='$txtcustomstel',
							customsemail='$txtcustomsemail',
							customscontact='$txtcustomscontact',
							pickupdate='$txtpickupdate',
							pickuptime_from='$txtpickuptime_from',
							pickuptime_till='$txtpickuptime_till', 
							pickupaddress='$pickupaddress',
							pick_up_contact='$txtpick_up_contact', 
							pickupemail='$txtpickupemail',pickupstate='$txtpickupstate',pickupplace='$txtpickupplace',
							pickupcity='$txtpickupcity',pickupzip='$txtpickupzip',pick_up_telephone='$txtpick_up_telephone',
							forwarder_reference = '$txtforwarder_reference',pickupplace2='$txtpickupplace2',
							commentbooking='$instrucciones_especiales', 
							ronline_barco='$barco',
							ronline_from='$from',
							ronline_via='$via',
							ronline_viaje='$viaje',
							ronline_zarpe='$zarpe',
							ronline_cierreimo='$cierreimo',
							ronline_cierredoctos='$cierredoctos',
							ronline_ets='$ets',
							ronline_flete_maritimo='$flete_maritimo',
							etafinaldest='" . str_replace('-', '/', $etafinaldest) . "',
							idagente_aduanal='$idagente_aduanal'
							WHERE  idbooking ='$idbooking' ");

                $status_mensaje = mysqli_affected_rows($link) > 0 ? 'CAMBIO DESCRIPCION DEL BOOKING' : '';


                $largo1 = 0;
                if (isset($_POST['numero_partida'])) {
                    foreach ($_POST['numero_partida'] as $value) {
                        $numero_partida[] = $value;

                        $largo1++;
                    }
                    foreach ($_POST['numero_bultos'] as $value) {
                        $numero_bultos[] = $value;
                    }
                    foreach ($_POST['largo'] as $value) {
                        $largo[] = $value;
                    }
                    foreach ($_POST['ancho'] as $value) {
                        $ancho[] = $value;
                    }
                    foreach ($_POST['alto'] as $value) {
                        $alto[] = $value;
                    }

                    ##########################################################
                    ## REVISO SI LA CARGA CAMBIO 
                    ########################################################## 


                    $partidas = mysqli_query($link, 'select COUNT(bookingno) from detailcargaexpint WHERE bookingno="BKG' . $idbooking . '" ');
                    $CANTIDAD_PARTIDAS = mysqli_num_rows($partidas);
                    if ($largo1 != $CANTIDAD_PARTIDAS) {
                        $status_mensaje.='<BR>CAMBIO CANTIDAD DE REGISTROS DE LA CARGA';
                    }

                    for ($k = 0; $k < $largo1; $k++) {
                        $partidas = mysqli_query($link, 'select * from detailcargaexpint WHERE bookingno="BKG' . $idbooking . '"
										and bulk = "' . $_POST['bultos' . $k] . '" and type="' . strtoupper($_POST['tipo' . $k]) . '" and cargo="' . procesa($descripcion) . '"
										and weight="' . $_POST['peso' . $k] . '" and measurement="' . $_POST['volumen' . $k] . '" and markandnos="' . procesa($marcas) . '"
										and imo="' . strtoupper($_POST['imo' . $k]) . '" and ams="' . strtoupper($_POST['arancel' . $k]) . '" and
										no_estibable="' . ($_POST['no_estibable' . $k] == $k ? 'on' : '') . '" 
										and sobredimension="' . ($_POST['sobredimension' . $k] == $k ? 'on' : '') . '"
										and clase_imo="' . strtoupper($_POST['clase_imo' . $k]) . '" and bookingno="BKG' . $idbooking . '" ');

                        if (mysqli_num_rows($partidas) < 1) {
                            $status_mensaje.='<BR>CAMBIO DEFINICION DE LA CARGA';
                        }
                    }
                    ##########################################################
                    ## FIN DE REVISO SI LA CARGA CAMBIO 
                    ########################################################## 
                    //echo 'larg '.$largo1;
                    mysqli_query($link, "delete from detailcargaexpint where bookingno='BKG" . $idbooking . "'");
                    mysqli_query($link, "delete from dimensiones_ronline where booking='BKG" . $idbooking . "'");

                    for ($k = 0; $k < $largo1; $k++) {
                        if ($numero_bultos[$k] * 1 != 0 and $largo[$k] * 1 != 0 and $ancho[$k] * 1 != 0 and $alto[$k] * 1 != 0) {
                            mysqli_query($link, 'INSERT INTO dimensiones_ronline (numero_partida,booking ,numero_bultos ,largo ,ancho ,alto)
										VALUES ("' . $numero_partida[$k] . '","BKG' . $idbooking . '", "' . $numero_bultos[$k] . '","' . $largo[$k] . '",
										"' . $ancho[$k] . '","' . $alto[$k] . '")');
                            /* echo 'INSERT INTO dimensiones_ronline (numero_partida,booking ,numero_bultos ,largo ,ancho ,alto)
                              VALUES ("'.$numero_partida[$k].'","BKG'.$idbooking.'", "'.$numero_bultos[$k].'","'.$largo[$k].'",
                              "'.$ancho[$k].'","'.$alto[$k].'")';
                              echo mysqli_error($link); */
                        }
                    }
                }




                for ($k = 1; $k <= 100; $k++) {
                    if (trim($_POST['marcas' . $k]) != '') {
                        /* if($_POST['no_estibable'.$k]==$k){
                          $descripcion='NON STACKABLE CARGO. '.$descripcion;
                          }

                          if($_POST['sobredimension'.$k]==$k){
                          $descripcion='OVERDIMENSIONED CARGO. '.$descripcion;
                          } */

                        $marcas = strtoupper($_POST['marcas' . $k]);
                        $marcas = procesa($marcas);
                        $descripcion = strtoupper($_POST['descripcion' . $k]);
                        $descripcion = procesa($descripcion);
                        mysqli_query($link, "insert into detailcargaexpint (files, bookingno, bulk, type, cargo, weight,
											measurement, markandnos, imo,ams,no_estibable,sobredimension,clase_imo) values
											('RONLINE','BKG" . $idbooking . "','" . $_POST['bultos' . $k] . "','" . strtoupper($_POST['tipo' . $k]) . "','" . $descripcion . "',
											'" . $_POST['peso' . $k] . "','" . $_POST['volumen' . $k] . "',
											'" . $marcas . "','" . strtoupper($_POST['imo' . $k]) . "','" . strtoupper($_POST['arancel' . $k]) . "',
											'" . ($_POST['no_estibable' . $k] == $k ? 'on' : '') . "','" . ($_POST['sobredimension' . $k] == $k ? 'on' : '') . "',
											'" . strtoupper($_POST['clase_imo' . $k]) . "')");

                        echo mysqli_error($link);
                    } else {
                        $k = 101;
                    }
                }

                if ($status_mensaje != '') {
                    mysqli_query($link, "UPDATE bookingexpint set status_booking_mensaje='RONLINE: " . $status_mensaje . "',
											status_booking='UPDATED',
											fecha_updated_ronline='" . date("Y-m-d H:i:s") . "' 
											WHERE booking = 'BKG" . $idbooking . "' ");
                }
            }

            if ($idbooking == '') {
                if ($barco == '') {
                    $mensaje.='<p style="color:RED; FONT-SIZE:12PX">LA RESERVACION NO SE GUARDARA PORQUE AUN NO HA ELEGIDO EL VIAJE</P>';
                }
            } else {
                if (trim($_POST["flete_maritimo2"]) == '') {
                    $mensaje.='<p style="color:RED; FONT-SIZE:12PX">INGRESE FLETE MARITIMO.</P>';
                }

                // control de datos de la mercancia
                $k = 1;
                while ($k <= 100) {
                    if (isset($_POST['marcas' . $k])) {
                        if (trim($_POST['marcas' . $k]) == '' or trim($_POST['bultos' . $k]) == '' or trim($_POST['tipo' . $k]) == '' or trim($_POST['descripcion' . $k]) == ''
                                or trim($_POST['peso' . $k]) == '' or trim($_POST['volumen' . $k]) == '') {
                            $mensaje.='<p style="color:RED; FONT-SIZE:12PX">INGRESE LOS DATOS FALTANTES EN DETALLES DE LA CARGA. AGREGUE DIMENSIONES DE LA CARGA. EXISTEN DATOS SIN COMPLETAR. </P>';
                        }
                    } else {
                        break;
                    }
                    if ($mensaje != '')
                        break;
                    $k++;
                }
                // control de datos de flete terrestre
                if ($_POST[completa_ft] == 'on' and ( trim($_POST[pickupdate]) == '' or trim($_POST[desde]) == '' or trim($_POST[hasta]) == ''
                        or trim($_POST[pickupplace]) == '' or trim($_POST[pickupaddress]) == '' or trim($_POST[pickupcity]) == '' or trim($_POST[pickupstate]) == ''
                        or trim($_POST[pickupzip]) == '' or trim($_POST[pick_up_contact]) == '' or trim($_POST[pick_up_telephone]) == '' or trim($_POST[pickupemail]) == '')) {
                    $mensaje.='<p style="color:RED; FONT-SIZE:12PX">INGRESE LOS DATOS FALTANTES DE FLETE TERRESTRE. EXISTEN DATOS SIN COMPLETAR. </P>';
                }

                $query_dim = mysqli_query($link, "select * from dimensiones_ronline where booking = 'BKG" . $idbooking . "'");
                $query_dim1 = mysqli_query($link, "select * from detailcargaexpint where bookingno = 'BKG" . $idbooking . "'");
                //echo "select * from detailcargaexpint where bookingno = 'BKG".$idbooking ."'";
                $query_cargo = mysqli_query($link, "select * from detailcargaexpint where bookingno = 'BKG" . $idbooking . "' and imo='SI'");
                $qarchivos_imo = mysqli_query($link, "select * from archivos_imo_ronline where idbooking = '$idbooking' order by idarchivo");

                if ($_POST[completa_ft] == 'on') {
                    //echo mysqli_num_rows($query_dim).'  '.mysqli_num_rows($query_dim1);
                    if (mysqli_num_rows($query_dim1) > 0) {
                        if (mysqli_num_rows($query_dim1) > mysqli_num_rows($query_dim)) {
                            $mensaje.='<p style="color:RED; FONT-SIZE:12PX">HA SELECCIONADO FLETE TERRESTRE, INGRESE LAS DIMENSIONES DE CADA PARTIDA DE LA CARGA</P>';
                        }
                    }
                }

                if (mysqli_num_rows($query_cargo) > 0) {
                    if (mysqli_num_rows($qarchivos_imo) < mysqli_num_rows($query_cargo)) {
                        $mensaje.='<p style="color:RED; FONT-SIZE:12PX">FALTA SUBIR ARCHIVOS IMO DE LAS PARTIDAS CON CARGA PELIGROSA</P>';
                    }
                }

                // control de datos del agente aduanal
                if (trim($_POST[customsagent]) == '' or trim($_POST[customscontact]) == '' or trim($_POST[customstel]) == '' or trim($_POST[customsemail]) == ''
                        or ( trim($_POST[patente]) == '' and trim($_POST[customsagent]) != 'INTERTEAM S.A. DE C.V.')) {
                    $mensaje.='<p style="color:RED; FONT-SIZE:12PX">INGRESE LOS DATOS FALTANTES DEL AGENTE ADUANAL. EXISTEN DATOS SIN COMPLETAR. </P>';
                }

                // si el agente aduanal es INTERTEAM controlo que suba archivos del agente aduanal
                /* if(trim($_POST[customsagent])=='INTERTEAM S.A. DE C.V.'){
                  $query_archivos_despacho=mysqli_query($link,"SELECT * FROM archivos_agente_aduanal_ronline where idbooking = '".$idbooking ."'");
                  if(mysqli_num_rows($query_archivos_despacho)<1){
                  $mensaje.='<p style="color:RED; FONT-SIZE:12PX">FALTAN SUBIR ARCHIVOS CON INSTRUCCIONES DEL DESPACHO ADUANAL.</P>';
                  }
                  } */
            }

            echo $mensaje;
        }
        if ($idbooking != '') {
            $query = mysqli_query($link, "select * from bookingexpint where idbooking = '$idbooking'");
            $row = mysqli_fetch_array($query);
        }
//echo  ' idb '.$idbooking .' num rows dim '.mysqli_num_rows($query_dim1);
        if ($mensaje == '' and $idbooking != '' and mysqli_num_rows($query_dim1) > 0) {
            ?>

            <p style="color:green; font-size:12px">SU SOLICITUD DE BOOKING TIENE LA REFERENCIA <?= $row[booking_interteam] ?>. EN BREVE SERA PROCESADA Y RECIBIRA CONFIRMACION DE BOOKING POR CORREO ELECTRONICO.</p> 
            <?php mysqli_query($link, "update bookingexpint set ronline_completado=1 where idbooking = '$idbooking'"); ?>

            <?php if ($row[files] != 'RONLINE') { ?>
                <p style="color:red; font-size:12px">SU SOLICITUD DE BOOKING ESTA CONFIRMADA Y YA NO SE PUEDE MODIFICAR: <?= $row[booking_interteam] ?>.</p>
            <?php } ?>
            <?php if ($_POST[completa_imo] == 'on') { ?>
                <p style="color:green; font-size:12px">LA CARGA IMO SERA GESTIONADA ANTE LA LINEA NAVIERA PARA SU ACEPTACION TAN PRONTO SE ENVIE LA CONFIRMACION DE BOOKING POR CORREO ELECTRONICO.</p>
            <?php } ?>
            <?php if ($_POST[completa_ft] == 'on') { ?>
                <p style="color:green; font-size:12px">LA SOLICITUD TERRESTRE SERA REVISADA PARA SU PROGRAMACION.</p>
            <?php } ?>
            <?php if ($_POST[datos_aa] == 'on') { ?>
                <p style="color:green; font-size:12px">HA INDICADO QUE INTERTEAM REALIZA EL SERVICIO DE DESPACHO ADUANAL.</p>
            <?php } ?>
        <?php } ?>  

        <form target="_self"  name="formu" id="formu" method="post" enctype="multipart/form-data" action="reservar.php" >

            <input type="hidden" id="linea" name="linea">


            <input type="hidden" id="txtcustomer" style="text-transform:uppercase" name="txtcustomer" value="<?= $txtcustomer ?>" />
            <input type="hidden" id="txtcustomercity" style="text-transform:uppercase" name="txtcustomercity" value="<?= $txtcustomercity ?>" /> 
            <input type="hidden" id="txtcustomercontact" style="text-transform:uppercase" name="txtcustomercontact" value="<?= $txtcustomercontact ?>" /> 
            <input type="hidden" id="txtcustomertel" style="text-transform:uppercase" name="txtcustomertel" value="<?= $txtcustomertel ?>"/>
            <input type="hidden" id="txtcustomeremail" name="txtcustomeremail" value="<?= $txtcustomeremail ?>" />
            <table width="1091">
                <tr>
                    <td colspan="10" style="color:#0088cc; font-weight:bold; ">DATOS DE EMBARQUE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                        <?php if ($row[files] == 'RONLINE' or $row[files] == '') { ?>
                            <a href="<?= "https://" . $_SERVER["SERVER_NAME"] ?>/itinerarios2/index.php" style="color:#0088cc; font-weight:bold; text-decoration:underline" target="_self">IR A ITINERARIOS - SELECCIONAR SALIDA</a>
                        <?php } ?>
                    </td>
                </tr>
                <tr>
                    <td ><input id="seed" name="seed" type="hidden" value="<?= $_GET[seed] != '' ? $_GET[seed] : $_POST[seed] ?>" /></td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td colspan="2" >&nbsp;</td>
                </tr>

                <tr>
                    <td >PUERTO DE CARGA</td>
                    <td >&nbsp;</td>
                    <td >
                        <strong><?= $from ?></strong>
                        <input type="hidden" id="from" name="from" value="<?= $from ?>"/>
                    </td>
                    <td >&nbsp;</td>
                    <td >PUERTO DE DESCARGA/VIA</td>
                    <td > 
                        <strong><?= $via ?> </strong>
                        <input type="hidden" id="via" name="via" value="<?= $via ?>" size="20"/>
                    </td>
                    <td >&nbsp;</td>
                    <td >DESTINO FINAL</td>
                    <td colspan="2" > 
                        <strong><?= $to ?></strong>
                        <input type="hidden" id="to" name="to" value="<?= $to ?>"/>
                    </td>
                </tr>
                <tr>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td colspan="2" >&nbsp;</td>
                </tr>
                <tr>
                    <td >BUQUE</td>
                    <td >&nbsp;</td>
                    <td > 
                        <strong><?= $barco ?></strong>
                        <input type="hidden" id="barco" name="barco" value="<?= $barco ?>"/>
                    </td>
                    <td >&nbsp;</td>
                    <td >VIAJE</td>
                    <td > 
                        <strong>
                            <?= $viaje ?>
                            <input type="hidden" id="viaje" name="viaje" value="<?= $viaje ?>"/>
                        </strong></td>
                    <td >&nbsp;</td>
                    <td >FECHA ESTIMADA DE ZARPE</td>
                    <td colspan="2" > 
                        <strong>
                            <?= $zarpe ?>
                            <input type="hidden" id="zarpe" name="zarpe" value="<?= $zarpe ?>" />
                        </strong></td>
                </tr>
                <tr>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td colspan="2" >&nbsp;</td>
                </tr>
                <tr>
                    <td >CIERRE DOCS IMO&nbsp;&nbsp;    
                    </td>
                    <td >&nbsp;</td>
                    <td > 
                        <strong>
                            <?= $cierreimo ?>
                            <input type="hidden" id="cierreimo" name="cierreimo" value="<?= $cierreimo ?>" />
                        </strong>

                    </td>
                    <td >&nbsp;</td>
                    <td >CIERRE DOCS &nbsp;&nbsp;</td>
                    <td > 
                        <strong>
                            <?php //$cierredoctos='2021/02/22';  ?>
                            <?= $cierredoctos ?>
                            <input type="hidden" id="cierredoctos" name="cierredoctos" value="<?= $cierredoctos ?>" />
                        </strong>
                        <?php
                        $diferencia = compararFechas($cierredoctos, date("Y/m/d"));
                        ?> 
                    </td>
                    <td >&nbsp;</td>
                    <td >CIERRE DESPACHO
                    </td>
                    <td ><strong>
                            <?= $ets ?>
                            <input type="hidden" id="ets" name="ets" value="<?= $ets ?>" />
                        </strong></td>
                    <td >&nbsp;</td>
                </tr>
                <tr>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                </tr>
                <tr>
                    <td >FECHA ESTIMADA DE ARRIBO</td>
                    <td >&nbsp;</td>
                    <td >
                        <strong>
                            <?= str_replace('-', '/', $etafinaldest) ?>
                            <input type="hidden" id="etafinaldest" name="etafinaldest" readonly value="<?= str_replace('-', '/', $etafinaldest) ?>" />
                        </strong></td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                    <td >&nbsp;</td>
                </tr>
            </table>
            <BR />
            <table>

                <!--ID BOOKING (ES UN NUMERO)--><input type="hidden" readonly  id="idbooking" name="idbooking" value="<?= $idbooking ?>" />

                <!--
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                </tr>-->

                <?php
                $booking_interteam_conf = $row[booking_interteam];
                if ($idbooking != '') {
                    ?>
                    <?php if ($row[ronline_completado] == 1) { ?>
                        <tr>
                            <td>NUMERO DE BOOKING</td>
                            <td>&nbsp;</td>
                            <td ><input type="text" readonly   value="<?= $row[booking_interteam] ?>" /></td>
                        </tr>

                        <tr >
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                    <?php } ?>
                    <tr>
                        <td>INGRESE FORWARDER REFERENCE</td>
                        <td>&nbsp;</td>
                        <td > 
                            <input type="text" style="text-transform:uppercase" id="forwarder_reference2" name="forwarder_reference2" value="<?= $row[forwarder_reference] == '' ? $_POST[forwarder_reference] : $row[forwarder_reference] ?>"  onmouseover="ddrivetip('Ingresar referencia de control interno para identificar el embarque. La misma referencia aparecerá en la factura.', 'yellow', 330)" onMouseOut="hideddrivetip()" />
                        </td>
                    </tr>
                    <tr  <?= ($idbooking == '') ? 'style="display:none"' : '' ?>>
                        <td colspan="3" style="color:#0088cc; font-weight:bold; ">&nbsp;</td>
                    </tr>
                    <tr  <?= ($idbooking == '') ? 'style="display:none"' : '' ?>>
                        <td>INGRESE FLETE MARITIMO</td>
                        <td>&nbsp;</td>
                        <td ><select name="flete_maritimo2" id="flete_maritimo2" >
                                <option value="" <?= $_POST[flete_maritimo2] == '' ? 'SELECTED="SELECTED"' : ($row[ronline_flete_maritimo] == '' ? 'selected="selected"' : '') ?> ></option>
                                <option value="PREPAID" <?= $_POST[flete_maritimo2] == 'PREPAID' ? 'SELECTED="SELECTED"' : ($row[ronline_flete_maritimo] == 'PREPAID' ? 'selected="selected"' : '') ?>>PREPAID</option>
                                <option value="COLLECT" <?= $_POST[flete_maritimo2] == 'COLLECT' ? 'SELECTED="SELECTED"' : ($row[ronline_flete_maritimo] == 'COLLECT' ? 'selected="selected"' : '') ?>>COLLECT</option>
                            </select>
                            <?= (isset($_POST['flete_maritimo2']) and trim($_POST['flete_maritimo2']) == '') ? '<P style="color:red; font-size:12px">INGRESE FLETE MARITIMO</P>' : '' ?> 

                        </td>
                    </tr >
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                <?php } ?>
            </table>
            <?php if ($idbooking != '') { ?>
                <table width="1179" border="1"  >
                    <tr>
                        <td colspan="11" style="color:#0088cc; font-weight:bold; ">DETALLES DE LA CARGA


                        </td>
                    </tr>
                    <tr>
                        <td width="305" >&nbsp;</td>
                        <td colspan="2" >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td width="203" >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                </table>


                <?php if ($row[files] == 'RONLINE') { ?>
                    <INPUT type="button" value="Agregar partida" onClick="addRow('dataTable');" />



                    <INPUT type="button" value="Borrar partida" onClick="deleteRow('dataTable');" />
                <?php } ?>

                <?php
                $query_mercancia = mysqli_query($link, "select * from detailcargaexpint where bookingno = 'BKG" . $idbooking . "' order by id");
                ?>
                <div class="table-responsive">
                    <TABLE id="dataTable"  class="cargas table " width="100%">
                        <TR>
                            <td></td>
                            <td>Marcas </td>
                            <td>Cantidad de bultos <span style="color:red">*</span></td>
                            <td>Tipo de bultos <span style="color:red">*</span></td>
                            <td>Descripción de la mercancía <span style="color:red">*</span></td>
                            <td>IMO <span style="color:red">*</span></td>
                            <td>Peso bruto (KGS) <span style="color:red">*</span></td>
                            <td>Volumen total (CBM) <span style="color:red">*</span></td>
                            <td>Fracción arancelaria</td>
                            <td>Dimensiones<br /></td>
                        </TR>
                        <?php
                        //echo mysqli_num_rows($query_mercancia);
                        if (mysqli_num_rows($query_mercancia) < 1) {
                            ?>
                            <TR>
                                <TD><INPUT type="checkbox" NAME="chk"/></TD>
                                <td><input type="text" name="marcas1" id="marcas1" />
                                    <?= (isset($_POST['marcas1']) and trim($_POST['marcas1']) == '') ? '<P style="color:red; font-size:12px">INGRESE MARCAS</P>' : '' ?>
                                    <?= (!isset($_POST['submit'])) ? '<P style="color:red; font-size:12px">INGRESE MARCAS</P>' : '' ?>
                                </td>
                                <td><input type="text" readonly name="bultos1" id="bultos1" size="5" onMouseover="ddrivetip('Es igual a la suma de Num Bultos que complete en dimensiones. Por favor Agregar dimensiones.', 'yellow', 450)" onMouseout="hideddrivetip()"/> <?= (isset($_POST['bultos1']) and trim($_POST['bultos1']) == '') ? '<P style="color:red; font-size:12px">INGRESE CANTIDAD DE BULTOS</P>' : '' ?> <?= (!isset($_POST['submit'])) ? '<P style="color:red; font-size:12px">INGRESE CANTIDAD DE BULTOS</P>' : '' ?></td>
                                <td>

                                    <select name="tipo1" id="tipo1"  />
                            <option value=""></option>
                            <?php
                            for ($k = 0; $k <= count($embalajes); $k++) {
                                ?>
                                <option value="<?= $embalajes[$k] ?>"><?= $embalajes[$k] ?></option>

                            <?php } ?>
                            <?php if ($_POST['tipo1'] != '') { ?>
                                <option value="<?= $_POST['tipo1'] ?>" selected="selected"><?= $_POST[tipo1] ?></option>
                            <?php } ?>
                            </select>
                            <?= (isset($_POST['tipo1']) and trim($_POST['tipo1']) == '') ? '<P style="color:red; font-size:12px">INGRESE TIPO DE BULTOS</P>' : '' ?><?= (!isset($_POST['submit'])) ? '<P style="color:red; font-size:12px">INGRESE TIPO DE BULTOS</P>' : '' ?></td>
                            <td><textarea name="descripcion1" id="descripcion1" cols="45" rows="5"></textarea><?= (isset($_POST['descripcion1']) and trim($_POST['descripcion1']) == '') ? '<P style="color:red; font-size:12px">INGRESE DESCRIPCION DE LA MERCANCIA</P>' : '' ?><?= (!isset($_POST['submit'])) ? '<P style="color:red; font-size:12px">INGRESE DESCRIPCION DE LA MERCANCIA</P>' : '' ?></td>
                            <td>
                                <select name="imo1" id="imo1" onChange="
                                                if (this.value == 'SI') {

                                                    document.getElementById('clase_imo1').style.visibility = 'visible';
                                                } else {

                                                    document.getElementById('clase_imo1').style.visibility = 'hidden';
                                                }"  />
                            <option value="" ></option>
                            <option value="SI" >SI</option>
                            <option value="NO" >NO</option>
                            </select> 

                            <select name="clase_imo1" id="clase_imo1" style="<?= (isset($_POST['imo1']) and trim($_POST['imo1']) == 'SI' ) ? 'visibility:visible' : 'visibility:hidden' ?>" onMouseover="ddrivetip('Complete clase imo', 'yellow', 130)" onMouseout="hideddrivetip()"/>
                            <option value=""  ></option>
                            <option value="2.1">2.1</option>
                            <option value="2.2">2.2</option>
                            <option value="3">3</option>
                            <option value="4.1">4.1</option>
                            <option value="5.1">5.1</option>
                            <option value="6.1">6.1</option>
                            <option value="8">8</option>
                            <option value="9">9</option>
                            </select> 

                        <!--<span id="span_imo1" style="cursor:pointer;color:#0088cc; <?= (isset($_POST['imo1']) and trim($_POST['imo1']) == 'SI' ) ? 'visibility:visible' : 'visibility:hidden' ?>;;font-size:12px; text-decoration:underline" onMouseover="ddrivetip('DGD & MSDS en inglés y español','yellow', 260)" onMouseout="hideddrivetip()">Subir archivos</span>  
                        <SPAN id="archivos_imo1"></SPAN>-->
                            <?= (isset($_POST['imo1']) and trim($_POST['imo1']) == 'SI' and $_POST['clase_imo1'] == '') ? '<P style="color:red; font-size:12px">INGRESE CLASE/IMO</P>' : '' ?>
                            <?php //=(isset($_POST['imo1']) and trim($_POST['imo1'])=='SI' and $_POST['archivos_imo1']=='') ? '<P style="color:red; font-size:12px">FALTAN ARCHIVOS IMO</P>' : ''  ?>
                            </td>

                            <td>

                                <input  name="peso1" id="peso1" type="number" step="any" min="1" max="10000" size="7" onkeypress="return validaDecimales(event, 10000)" onblur="return valida_maximo(event, 10000)"
                                       onKeyUp="
                                                       if (this.value * 1 >= 3500) {
                                                           document.getElementById('sobredimension1').checked = true;
                                                       } else {
                                                           document.getElementById('sobredimension1').checked = false;
                                                       }
                                                       valida" />
                                <?= (isset($_POST['peso1']) and trim($_POST['peso1']) == '') ? '<P style="color:red; font-size:12px">INGRESE PESO BRUTOS (KGS)</P>' : '' ?><?= (!isset($_POST['submit'])) ? '<P style="color:red; font-size:12px">INGRESE PESO BRUTO (KGS)</P>' : '' ?></td>
                            <td><input readonly type="text" onMouseover="ddrivetip('Es igual a la suma de los volúmenes calculados según las medidas ingresadas en dimensiones. Por favor Agregar dimensiones.', 'yellow', 450)" onMouseout="hideddrivetip()"  name="volumen1" id="volumen1" size="7" /><?= (isset($_POST['volumen1']) and trim($_POST['volumen1']) == '') ? '<P style="color:red; font-size:12px">INGRESE VOLUMEN TOTAL(CBM)</P>' : '' ?><?= (!isset($_POST['submit'])) ? '<P style="color:red; font-size:12px">INGRESE VOLUMEN TOTAL (CBM)</P>' : '' ?></td>


                            <td><input type="text" name="arancel1" id="arancel1" size="7"  onkeypress="return validaDecimales(event, 1000000000)" onBlur="return valida_maximo(event, 1000000000)" /></td>

                            <td>
                                <span onMouseover="ddrivetip('<P>DECLARAR MEDIDAS EN CENTIMETROS</P>EJ: 1.20 x 1.00 x 1.10', 'yellow', 250)" onMouseout="hideddrivetip()" style="color: #0088cc; cursor:pointer; font-size:12px; text-decoration:underline"  

                                      onclick="ajax_dimensiones_ronline('div1', 'mostrar_dimensiones.php', 'div1')">Agregar dimensiones</span> <BR />

                                <INPUT type="checkbox" NAME="sobredimension1" id="sobredimension1" onMouseover="ddrivetip('SELECCIONAR LA OPCION SI SE CUMPLEN UNA O MAS DE LAS SIGUIENTES CONDICIONES:<p></p><p>&ordm; LA ALTURA DEL BULTO ES IGUAL O SUPERIOR A 230CMS</p><p>&ordm; EL LARGO DEL BULTO ES IGUAL O SUPERIOR A 590CMS</p><p>&ordm; EL ANCHO DEL BULTO ES IGUAL O SUPERIOR A 230CMS</p><p>&ordm; EL PESO DEL BULTO ES IGUAL O SUPERIOR A 3500KGS</p>', 'yellow', 450)" onMouseout="hideddrivetip()"/> Carga sobredimensionada <BR />
                                <INPUT type="checkbox" NAME="no_estibable1" id="no_estibable1" onMouseover="ddrivetip('A PISO Y NADA ENCIMA', 'yellow', 160)" onMouseout="hideddrivetip()"/> No estibable
                                <div id="div1"></div>
                            </td>

                            </TR>
                        <?php } else { ?>     





                            <?php
                            //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
                            //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ya tiene carga %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                            //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
                            $rm = 1;
                            while ($row_mercancia = mysqli_fetch_array($query_mercancia)) {
                                ?>

                                <TR>
                                    <TD><INPUT type="checkbox" NAME="chk"/></TD>
                                    <td><input type="text" name="marcas<?= $rm ?>" id="marcas<?= $rm ?>" value="<?= $row_mercancia[markandnos] == '' ? trim($_POST['marcas' . $rm]) : $row_mercancia[markandnos] ?>" /><?= (isset($_POST['marcas' . $rm]) and trim($_POST['marcas' . $rm]) == '') ? '<P style="color:red; font-size:12px">INGRESE MARCAS</P>' : '' ?></td>
                                    <td><input type="text"
                                               onMouseover="ddrivetip('Es igual a la suma de Num Bultos que complete en dimensiones. Por favor Agregar dimensiones.', 'yellow', 450)" onMouseout="hideddrivetip()"
                                               name="bultos<?= $rm ?>" readonly id="bultos<?= $rm ?>" size="5" value="<?= $row_mercancia[bulk] == '' ? trim($_POST['bultos' . $rm]) : $row_mercancia[bulk] ?>"/><?= (isset($_POST['bultos' . $rm]) and trim($_POST['bultos' . $rm]) == '') ? '<P style="color:red; font-size:12px">INGRESE CANTIDAD DE BULTOS</P>' : '' ?></td>
                                    <td>
                                        <select name="tipo<?= $rm ?>" id="tipo<?= $rm ?>" />
                                <option value=""></option>
                                <?php
                                for ($k = 0; $k <= count($embalajes); $k++) {
                                    ?>
                                    <option value="<?= $embalajes[$k] ?>"><?= $embalajes[$k] ?></option>

                                <?php } ?>
                                <?php if ($row_mercancia[type] != '') { ?>
                                    <option value="<?= $row_mercancia[type] == '' ? trim($_POST['tipo' . $rm]) : $row_mercancia[type] ?>"  selected="selected"><?= $row_mercancia[type] == '' ? trim($_POST['tipo' . $rm]) : $row_mercancia[type] ?></option>
                                <?php } ?>

                                </select>
                                <?= (isset($_POST['tipo' . $rm]) and trim($_POST['tipo' . $rm]) == '') ? '<P style="color:red; font-size:12px">INGRESE TIPO DE BULTOS</P>' : '' ?></td>
                                <td><textarea name="descripcion<?= $rm ?>" id="descripcion<?= $rm ?>" cols="45" rows="5"><?= $row_mercancia[cargo] == '' ? trim($_POST['descripcion' . $rm]) : $row_mercancia[cargo] ?></textarea><?= (isset($_POST['descripcion' . $rm]) and trim($_POST['descripcion' . $rm]) == '') ? '<P style="color:red; font-size:12px">INGRESE DESCRIPCION DE LA MERCANCIA</P>' : '' ?></td>
                                <td>
                                    <select name="imo<?= $rm ?>" id="imo<?= $rm ?>" onChange="
                                                        if (this.value == 'SI') {
                                    <?php //if($row_mercancia[imo]=='SI' or $_POST['imo'.$rm]=='SI'){ ?>
                                                            document.getElementById('span_imo<?= $rm ?>').style.visibility = 'visible';
                                    <?php //} ?>
                                                            document.getElementById('clase_imo<?= $rm ?>').style.visibility = 'visible';
                                                        } else {
                                    <?php //if($row_mercancia[imo]=='SI' or $_POST['imo'.$rm]=='SI'){?>
                                                            document.getElementById('span_imo<?= $rm ?>').style.visibility = 'hidden';
                                    <?php //}  ?>
                                                            document.getElementById('clase_imo<?= $rm ?>').style.visibility = 'hidden';
                                                        }"  />
                                <option value=""   <?= $row_mercancia[imo] == '' ? 'selected="selected"' : ( (isset($_POST['imo' . $rm]) and $_POST['imo' . $rm] == '') ? 'selected="selected"' : '') ?>></option>
                                <option value="SI" <?= $row_mercancia[imo] == 'SI' ? 'selected="selected"' : ( (isset($_POST['imo' . $rm]) and $_POST['imo' . $rm] == 'SI') ? 'selected="selected"' : '') ?>>SI</option>
                                <option value="NO" <?= $row_mercancia[imo] == 'NO' ? 'selected="selected"' : ( (isset($_POST['imo' . $rm]) and $_POST['imo' . $rm] == 'NO') ? 'selected="selected"' : '') ?>>NO</option>
                                </select> 

                                <select name="clase_imo<?= $rm ?>" id="clase_imo<?= $rm ?>" style="<?= (isset($_POST['imo' . $rm]) and trim($_POST['imo' . $rm]) == 'SI' ) ? 'visibility:visible' : 'visibility:hidden' ?>" onMouseover="ddrivetip('Complete clase imo', 'yellow', 130)" onMouseout="hideddrivetip()"/>
                                <option value="" <?= $row_mercancia[clase_imo] == '' ? 'SELECTED="SELECTED"' : ( (isset($_POST['clase_imo' . $rm]) and $_POST['clase_imo' . $rm] == '') ? 'SELECTED="SELECTED"' : '') ?>></option>
                                <option value="2.1"  <?= $row_mercancia[clase_imo] == '2.1' ? 'SELECTED="SELECTED"' : ( (isset($_POST['clase_imo' . $rm]) and $_POST['clase_imo' . $rm] == '2.1') ? 'SELECTED="SELECTED"' : '') ?>>2.1</option>
                                <option value="2.2" <?= $row_mercancia[clase_imo] == '2.2' ? 'SELECTED="SELECTED"' : ( (isset($_POST['clase_imo' . $rm]) and $_POST['clase_imo' . $rm] == '2.2') ? 'SELECTED="SELECTED"' : '') ?>>2.2</option>
                                <option value="3" <?= $row_mercancia[clase_imo] == '3' ? 'SELECTED="SELECTED"' : ( (isset($_POST['clase_imo' . $rm]) and $_POST['clase_imo' . $rm] == '3') ? 'SELECTED="SELECTED"' : '') ?>>3</option>
                                <option value="4.1" <?= $row_mercancia[clase_imo] == '4.1' ? 'SELECTED="SELECTED"' : ( (isset($_POST['clase_imo' . $rm]) and $_POST['clase_imo' . $rm] == '4.1') ? 'SELECTED="SELECTED"' : '') ?>>4.1</option>
                                <option value="5.1" <?= $row_mercancia[clase_imo] == '5.1' ? 'SELECTED="SELECTED"' : ( (isset($_POST['clase_imo' . $rm]) and $_POST['clase_imo' . $rm] == '5.1') ? 'SELECTED="SELECTED"' : '') ?>>5.1</option>
                                <option value="6.1" <?= $row_mercancia[clase_imo] == '6.1' ? 'SELECTED="SELECTED"' : ( (isset($_POST['clase_imo' . $rm]) and $_POST['clase_imo' . $rm] == '6.1') ? 'SELECTED="SELECTED"' : '') ?>>6.1</option>
                                <option value="8" <?= $row_mercancia[clase_imo] == '8' ? 'SELECTED="SELECTED"' : ( (isset($_POST['clase_imo' . $rm]) and $_POST['clase_imo' . $rm] == '8') ? 'SELECTED="SELECTED"' : '') ?>>8</option>
                                <option value="9" <?= $row_mercancia[clase_imo] == '9' ? 'SELECTED="SELECTED"' : ( (isset($_POST['clase_imo' . $rm]) and $_POST['clase_imo' . $rm] == '9') ? 'SELECTED="SELECTED"' : '') ?>>9</option>
                                </select> 

                                <?php $qarchivos_imo = mysqli_query($link, "select * from archivos_imo_ronline where idbooking = '$idbooking' and idpartida='$rm' order by idarchivo"); ?>

                                <span id="span_imo<?= $rm ?>" style="cursor:pointer;color:#0088cc; <?= (isset($_POST['imo' . $rm]) and trim($_POST['imo' . $rm]) == 'SI' ) ? 'visibility:visible' : 'visibility:hidden' ?>;;font-size:12px; text-decoration:underline" onMouseover="ddrivetip('DGD & MSDS en inglés y español', 'yellow', 260)" onMouseout="hideddrivetip()" 
                                      onClick="dhtmlwindow.open('Box<?= $rm ?>', 'iframe', 'archivos_imo_cargar.php?idbooking=<?= $idbooking ?>&idpartida=<?= $rm ?>', 'SUBIR ARCHIVOS DE IMO', 'width=850px,height=600px,resize=1,scrolling=1,center=1', 'recal')">Subir archivos</span> 
                                <SPAN id="archivos_imo<?= $rm ?>"></SPAN>
                                <?= (isset($_POST['imo' . $rm]) and trim($_POST['imo' . $rm]) == 'SI' and $_POST['clase_imo' . $rm] == '') ? '<P style="color:red; font-size:12px">INGRESE CLASE/IMO</P>' : '' ?>
                                <?= (isset($_POST['imo' . $rm]) and trim($_POST['imo' . $rm]) == 'SI' and mysqli_num_rows($qarchivos_imo) < 1) ? '<P style="color:red; font-size:12px">FALTAN ARCHIVOS IMO</P>' : '' ?>
                                </td>
                                <td><input type="text" name="peso<?= $rm ?>" id="peso<?= $rm ?>"  onkeypress="return validaDecimales(event, 10000)" onBlur="return valida_maximo(event, 10000)"
                                           onKeyUp="if (this.value * 1 >= 3500) {
                                                                   document.getElementById('sobredimension<?= $rm ?>').checked = true;
                                                               } else {
                                                                   document.getElementById('sobredimension<?= $rm ?>').checked = false;
                                                               }" size="7" value="<?= $row_mercancia[weight] == '' ? trim($_POST['peso' . $rm]) : $row_mercancia[weight] ?>"/><?= (isset($_POST['peso' . $rm]) and trim($_POST['peso' . $rm]) == '') ? '<P style="color:red; font-size:12px">INGRESE PESO BRUTO (KGS)</P>' : '' ?></td>
                                <td><input type="text" onMouseover="ddrivetip('Es igual a la suma de los volúmenes calculados según las medidas ingresadas en dimensiones. Por favor Agregar dimensiones.', 'yellow', 450)" onMouseout="hideddrivetip()" readonly name="volumen<?= $rm ?>" id="volumen<?= $rm ?>" size="7" value="<?= $row_mercancia[measurement] == '' ? trim($_POST['volumen' . $rm]) : $row_mercancia[measurement] ?>"/> <?= (isset($_POST['volumen' . $rm]) and trim($_POST['volumen' . $rm]) == '') ? '<P style="color:red; font-size:12px">INGRESE VOLUMEN TOTAL (CBM)</P>' : '' ?></td>
                                <td><input type="text" name="arancel<?= $rm ?>" id="arancel<?= $rm ?>" size="7" value="<?= $row_mercancia[ams] == '' ? trim($_POST['ams' . $rm]) : $row_mercancia[ams] ?>"  onkeypress="return validaDecimales(event, 1000000000)" onBlur="return valida_maximo(event, 1000000000)"/></td>

                                <?php
                                $query_dim = mysqli_query($link, "select * from dimensiones_ronline where booking = '" . ($row[booking] == '' ? 'BKG' . $idbooking : $row[booking]) . "' and numero_partida = '$rm' order by id");
                                ?>

                                <td><span onMouseover="ddrivetip('<P>DECLARAR MEDIDAS EN CENTIMETROS</P>EJ: 1.20 x 1.00 x 1.10', 'yellow', 250)" onMouseout="hideddrivetip()" style="cursor:pointer;color:#0088cc;font-size:12px; text-decoration:underline"  onclick="ajax_dimensiones_ronline('div<?= $rm ?>', 'mostrar_dimensiones.php', 'div<?= $rm ?>')">Agregar dimensiones</span><br /> 
                                    <INPUT type="checkbox" NAME="sobredimension<?= $rm ?>"  id="sobredimension<?= $rm ?>" value="<?= $rm ?>" <?= $row_mercancia[sobredimension] == 'on' ? 'checked="checked"' : '' ?> onMouseover="ddrivetip('SELECCIONAR LA OPCION SI SE CUMPLEN UNA O MAS DE LAS SIGUIENTES CONDICIONES:<p></p><p>&ordm; LA ALTURA DEL BULTO ES IGUAL O SUPERIOR A 230CMS</p><p>&ordm; EL LARGO DEL BULTO ES IGUAL O SUPERIOR A 590CMS</p><p>&ordm; EL ANCHO DEL BULTO ES IGUAL O SUPERIOR A 230CMS</p><p>&ordm; EL PESO DEL BULTO ES IGUAL O SUPERIOR A 3500KGS</p>', 'yellow', 450)" onMouseout="hideddrivetip()"/> Carga sobredimensionada <br />
                                    <INPUT type="checkbox" NAME="no_estibable<?= $rm ?>" id="no_estibable<?= $rm ?>" value="<?= $rm ?>" <?= $row_mercancia[no_estibable] == 'on' ? 'checked="checked"' : '' ?> onMouseover="ddrivetip('A PISO Y NADA ENCIMA', 'yellow', 160)"  onMouseout="hideddrivetip()"/> No estibable

                                    <?= ($row_mercancia[sobredimension] == 'on' and mysqli_num_rows($query_dim) < 1) ? '<P style="color:red; font-size:12px">HA SELECCIONADO SOBREDIMENSION, INGRESE LAS DIMENSIONES</P>' : '' ?>

                                    <div id="div<?= $rm ?>">
                                        <?php if (mysqli_num_rows($query_dim) > 0) { ?><!--<div align="center">Dimensiones</div>-->
                                            <table border="1" id="table<?= $rm ?>" >

                                                <tr>
                                                  <td><!--<input type="checkbox" name="chk1" id="chk1" style="display:none"/>--></td>
                                                    <td>Num bultos</td>
                                                    <td>Largo (cms)</td>
                                                    <td>Ancho (cms)</td>
                                                    <td>Alto (cms)</td>
                                                    <td>Vol</td>
                                                </tr>

                                                <?php
                                                $fila = 1;
                                                $contador = 0;
                                                while ($row_dim = mysqli_fetch_array($query_dim)) {
                                                    ?>
                                                    <tr>
                                                        <td> 
                                                            <input type="hidden" name="numero_partida[]" id="numero_partida[]" size="5" value="<?= $row_dim[numero_partida] ?>"  />
                                                            <!--<INPUT type="checkbox" NAME="chk1" id="chk1" />--><span onMouseover="ddrivetip('Hacer click en [+] para agregar l&iacute;neas', 'yellow', 330)" onMouseout="hideddrivetip()" style="color: #0088cc; cursor:pointer"  onclick="addRow1('table<?= $rm ?>', '<?= $rm ?>')">[+]</span></td>
                                                        <td align="center">
                                                            <input type="text" name="numero_bultos[]" id="numero_bultos[]" size="5"   value="<?= $row_dim[numero_bultos] ?>" 

                                                                   onkeypress="return fun_AllowOnlyAmountInteger(this.value);" 
                                                                   onKeyUp="calculos_dimension('<?= $contador ?>', '<?= $rm ?>');
                                                                   "  />
                                                        </td>
                                                        <td align="center">
                                                            <input type="text" name="largo[]" id="largo[]" size="5"  value="<?= $row_dim[largo] ?>" 
                                                                   onKeyUp="calculos_dimension('<?= $contador ?>', '<?= $rm ?>');
                                                                   "  
                                                                   onkeypress="return fun_AllowOnlyAmountAndDot(this.value);"/>
                                                        </td>
                                                        <td align="center">
                                                            <input type="text" name="ancho[]" id="ancho[]" size="5" value="<?= $row_dim[ancho] ?>" 
                                                                   onKeyUp="calculos_dimension('<?= $contador ?>', '<?= $rm ?>');
                                                                   " 
                                                                   onkeypress="return fun_AllowOnlyAmountAndDot(this.value);"/>
                                                        </td>



                                                        <td align="center">
                                                            <input type="text" name="alto[]" id="alto[]" size="5"  value="<?= $row_dim[alto] ?>" 
                                                                   onKeyUp="calculos_dimension('<?= $contador ?>', '<?= $rm ?>');"  
                                                                   onkeypress="return fun_AllowOnlyAmountAndDot(this.value);" />
                                                        </td>
                                                        <td align="center"> 
                                                            <input type="text" name="volLinea[]" id="volLinea[]" size="5" 
                                                                   value="<?=
                                                                   ($row_dim[numero_bultos] * 1 != 0 and $row_dim[largo] * 1 != 0 and $row_dim[ancho] * 1 != 0 and $row_dim[alto] * 1 != 0) ?
                                                                           number_format(($row_dim[numero_bultos] * ($row_dim[largo] / 100) * ($row_dim[ancho] / 100) * ($row_dim[alto] / 100)), 2, '.', '') : ''
                                                                   ?>" readonly />
                                                        </td>
                                                    </tr>
                                                    <?php
                                                    $fila++;
                                                    $contador++;
                                                }
                                                ?>
                                            </table>
                                        <?php } ?>
                                    </div>
                                </td>

                                </TR>


                                <?php
                                $rm++;
                            }
                        }
                        ?>

                    </TABLE>

                </div>
                <table width="1179" border="1" id="trImo"  style="display:none"> 
                    <tr>
                        <td colspan="5" >&nbsp;</td>
                        <td colspan="2" >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td colspan="3" >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr >
                        <td colspan="3" >CLASE/IMO<span style="border:none">
                                <input type="text" style="text-transform:uppercase" id="clase_imo" name="clase_imo" value="<?= $row[ronline_clase_imo] ?>" size="10" />
                            </span></td>
                        <td colspan="3" >NUMERO UN<span style="border:none">
                                <input type="text" style="text-transform:uppercase" id="numero_imo" name="numero_imo" value="<?= $row[ronline_numero_imo] ?>" size="10"/>
                            </span></td>
                        <td colspan="3" >GRUPO DE EMBALAJE <span style="border:none">
                                <input type="text" style="text-transform:uppercase" id="grupo_embalaje_imo" name="grupo_embalaje_imo" value="<?= $row[ronline_grupo_embalaje_imo] ?>" size="10"/>
                            </span></td>
                        <td colspan="3" >PROPER SHIPPING NAME<span style="border:none">
                                <input type="text" style="text-transform:uppercase" id="proper_shipping_name_imo" name="proper_shipping_name_imo" value="<?= $row[ronline_proper_shipping_name_imo] ?>" size="10"/>
                            </span></td>
                    </tr>
                </table>
                <script>
    <?php //if(trim($row[ronline_clase_imo])!='' or trim($row[ronline_numero_imo])!='' or trim($row[ronline_grupo_embalaje_imo])!='' or trim($row[ronline_proper_shipping_name_imo])!='') {   ?>
                    //document.getElementById('completa_imo').checked=true; 
                    //document.getElementById('trImo').style.display='block';
    <?php //}    ?>
                </script>

                <BR />

                <?php
                if (trim($row[pickupdate]) != '' or trim($_POST[pickupdate]) != '' or trim($row[pickuptime_from]) != '' or trim($_POST[desde]) != ''
                        or trim($row[pickuptime_till]) != '' or trim($_POST[hasta]) != '' or trim($row[pickupplace]) != '' or trim($_POST[pickupplace]) != ''
                        or trim($row[pickupaddress]) != '' or trim($_POST[pickupaddress]) != '' or trim($row[pickupcity]) != '' or trim($_POST[pickupcity]) != ''
                        or trim($row[pickupstate]) != '' or trim($_POST[pickupstate]) != '' or trim($row[pickupzip]) != '' or trim($_POST[pickupzip]) != ''
                        or trim($row[pick_up_contact]) != '' or trim($_POST[pick_up_contact]) != ''
                        or trim($row[pick_up_telephone]) != '' or trim($_POST[pick_up_telephone]) != '' or trim($row[pickupemail]) != '' or trim($_POST[pickupemail]) != '') {
                    $completa_ft = 'on';
                }
                ?>

                <table width="1179" border="1"  >
                    <tr>
                        <td colspan="6" >&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan="6" >&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan="6" >  
                            <input type="checkbox" name="completa_ft" id="completa_ft" 
                                   onclick="if (this.checked) {
                                                   document.getElementById('trFT').style.display = 'block';
                                                   document.getElementById('trFT2').style.display = 'block';
                                               } else {
                                                   $('#trFT').toggle(200);
                                                   $('#trFT2').toggle(200);
                                               }"/>&nbsp;<span style="color:#0088cc; font-weight:bold; font-size:12px;">SOLICITAR FLETE TERRESTRE</span> </td>
                    </tr>
                </table>

                <table border="1"  id="trFT"  style="display:block"   >

                    <tr >
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr >
                        <td >FECHA DE RECOLECCION</td>
                        <td >&nbsp;</td>
                        <td   > 
                            <input type="text"  id="pickupdate" name="pickupdate"  onClick="displayCalendar(document.getElementById('pickupdate'), 'yyyy/mm/dd', this)" readonly onDblClick="this.value = ''" value="<?= $row[pickupdate] ?>" />


                            <?= ($completa_ft == 'on' and trim($row['pickupdate']) == '') ? '<P style="color:red; font-size:12px">INGRESE FECHA DE RECOLECCION</P>' : '' ?></td>
                        <td >&nbsp;</td>
                        <td valign="baseline" >HORARIO DE ALMACEN</td>
                        <td >&nbsp;</td>
                        <td colspan="4"  >
                            DESDE 
                            <input type="text"   id="desde" name="desde" style="font-size:11px;" size="7" value="<?= $row[pickuptime_from] ?>" readonly onMouseover="ddrivetip('Horario abierto, sujeto a revisión', 'yellow', 330)" onMouseout="hideddrivetip()"/>

                            HASTA 
                            <input type="text"   id="hasta" name="hasta" style="font-size:11px;" size="7" value="<?= $row[pickuptime_till] ?>" readonly onMouseover="ddrivetip('Horario abierto, sujeto a revisión', 'yellow', 330)" onMouseout="hideddrivetip()"/>

                            <?= ($completa_ft == 'on' and trim($row['pickuptime_from']) == '') ? '<P style="color:red; font-size:12px">INGRESE HORARIO DE ALMACEN: DESDE</P>' : '' ?>
                            <?= ($completa_ft == 'on' and trim($row['pickuptime_till']) == '') ? '<P style="color:red; font-size:12px">INGRESE HORARIO DE ALMACEN: HASTA</P>' : '' ?>
                        </td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <?
                    $cfs = mysqli_query($link, "SELECT id FROM pickups where pickupplace<>'' and pickupplace<>'.'
					and pickupplace='".trim($row[pickupplace])."' and id*1<>0 order by pickupplace  ");
					 
				    $rcfs= mysqli_fetch_array($cfs);
					//echo mysqli_num_rows($cfs);
				    ?>
                    <tr>
                        <td >NOMBRE DE ALMACEN</td>
                        <td >&nbsp;</td>
                        <td colspan="9" > 
<input name="idpickupplace"  id="idpickupplace" type="hidden" value="<?= trim($rcfs[id])?>">
                            <input size="35" type="text" id="pickupplace" name="pickupplace"  value="<?= trim($row[pickupplace]) == '' ? ' ' : trim($row[pickupplace]) ?>" 
                                   style="text-transform:uppercase"  
                                   onmouseover="ddrivetip('En caso de no estar registrado el almacén, complete por favor OTRO ALMACEN', 'yellow', 330)" 
                                   onMouseOut="hideddrivetip()" 
                                   onKeyUp="document.getElementById('idpickupplace').value='';"
                                   onBlur="
                                   if(document.getElementById('idpickupplace').value*1==0){
                                   document.getElementById('pickupplace').value='';
                                   document.getElementById('pickupaddress').value='';
                                   document.getElementById('pickupcity').value='';
                                   }
                                    " />




                            <?= ($completa_ft == 'on' and trim($row['pickupplace']) == '') ? '<P style="color:red; font-size:12px">INGRESE NOMBRE DE ALMACEN</P>' : '' ?>
                            <input type="button" style="background-image:url(../../images/buscar.png); background-repeat:no-repeat; background-position:right; background-color:#D6D6D6" 
                                   onclick='dhtmlwindow.open("pickupsBox", "iframe", "pickups/pickups.php", "Choose Pickups",
                                                       & quot; left = 0, top = 0, width = 950
                                                       px, height = 600px, resize = 1, scrolling = 1, center = 0 & quot; , & quot; recal & quot;
                                                       )'
                                   value="Search     " />
                        </td>
                    </tr>
                    <tr>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr>
                      <td >OTRO ALMACEN</td>
                      <td >&nbsp;</td>
                      <td ><input type="text"  size="35"  id="pickupplace2" name="pickupplace2" value="<?= $row[pickupplace2] ?>" 
                                   style="text-transform:uppercase" onMouseOver="ddrivetip('En caso de no estar registrado el almacén, favor de ingresar el dato en este campo', 'yellow', 330)" onMouseOut="hideddrivetip()"  /></td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                    </tr>
                    <tr>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                      <td >&nbsp;</td>
                    </tr>
                    <tr>
                        <td >DOMICILIO</td>
                        <td >&nbsp;</td>
                        <td ><input type="text"  size="35" id="pickupaddress" name="pickupaddress" value="<?= $row[pickupaddress] ?>" 
                                    style="text-transform:uppercase"/>
                            <?= ($completa_ft == 'on' and trim($row['pickupaddress']) == '') ? '<P style="color:red; font-size:12px">INGRESE DOMICILIO</P>' : '' ?></td>
                        <td >&nbsp;</td>
                        <td >CIUDAD/MUNICIPIO</td>
                        <td >&nbsp;</td>
                        <td > <input type="text"  size="35"  id="pickupcity" name="pickupcity" value="<?= $row[pickupcity] ?>" style="text-transform:uppercase"/>
                            <input type="text"  size="5" readonly  id="uncode_pickup_city" name="uncode_pickup_city" value="<?= $row[uncode_pickup_city] ?>" 
                                   style="text-transform:uppercase"/>
                            <?= ($completa_ft == 'on' and trim($row['pickupcity']) == '') ? '<P style="color:red; font-size:12px">INGRESE CIUDAD/MUNICIPIO</P>' : '' ?></td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    
                    
                    <tr>
                        <td >ESTADO</td>
                        <td >&nbsp;</td>
                        <td > 
                            <input type="text"   size="35" id="pickupstate" name="pickupstate" value="<?= $row[pickupstate] ?>" 
                                   style="text-transform:uppercase"/>
                            <?= ($completa_ft == 'on' and trim($row['pickupstate']) == '') ? '<P style="color:red; font-size:12px">INGRESE ESTADO</P>' : '' ?></td>
                        <td >&nbsp;</td>
                        <td >CODIGO POSTAL</td>
                        <td >&nbsp;</td>
                        <td > 
                            <input type="text"   size="35" id="pickupzip" name="pickupzip" value="<?= $row[pickupzip] ?>" 
                                   style="text-transform:uppercase"/>
                            <?= ($completa_ft == 'on' and trim($row['pickupzip']) == '') ? '<P style="color:red; font-size:12px">INGRESE CODIGO POSTAL</P>' : '' ?></td>
                        <td >&nbsp;</td>
                        <td ><!--INSTRUCCIONES ESPECIALES--></td>
                        <td >&nbsp;</td>
                        <td ><!--<span style="border:none">
                          <input type="text"   id="pick_up_comments" name="pick_up_comments" value="<?php //=$row[transport_comments]  ?>" style="text-transform:uppercase"/>
                        </span>--></td>
                    </tr>
                    <tr>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr>
                        <td >CONTACTO LUGAR RECOLECCION</td>
                        <td >&nbsp;</td>
                        <td > 
                            <input type="text"   size="35" id="pick_up_contact" name="pick_up_contact" value="<?= $row[pick_up_contact] ?>" style="text-transform:uppercase"/>
                            <?= ($completa_ft == 'on' and trim($row['pick_up_contact']) == '') ? '<P style="color:red; font-size:12px">INGRESE CONTACTO LUGAR RECOLECCION</P>' : '' ?></td>
                        <td >&nbsp;</td>
                        <td >TELEFONO</td>
                        <td >&nbsp;</td>
                        <td > 
                            <input type="text"  size="35" id="pick_up_telephone" name="pick_up_telephone" value="<?= $row[pick_up_telephone] ?>" style="text-transform:uppercase"/>
                            <?= ($completa_ft == 'on' and trim($row['pick_up_telephone']) == '') ? '<P style="color:red; font-size:12px">INGRESE TELEFONO</P>' : '' ?></td>
                        <td >&nbsp;</td>
                        <td >CORREO ELECTRONICO</td>
                        <td >&nbsp;</td>
                        <td > 
                            <input type="text"   size="35" id="pickupemail" name="pickupemail" value="<?= $row[pickupemail] ?>" 
                                   style="text-transform:uppercase"/>

                            <?= ($completa_ft == 'on' and trim($row['pickupemail']) == '') ? '<P style="color:red; font-size:12px">INGRESE CORREO ELECTRONICO</P>' : '' ?></td>
                    </tr>

                </table>
                <br>  
                <br>
                <table border="1"  id="trFT2"  style="display:block"> 

                    <tr >
                        <td ><span style="color:#0088cc; font-weight:bold; font-size:12px;">SEGUIMIENTO TERRESTRE</span></td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr >
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr >
                        <td ><?= $row[pickupplace] == '' ? $row[pickupplace2] : $row[pickupplace] ?></td>
                        <td >&nbsp;</td>
                        <td ><?= $row[operador_terrestre] ?></td>
                        <td >&nbsp;</td>
                        <td ><?= $row[placas] ?></td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr >
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr >
                        <td > RECOLECCION EFECTIVA</td>
                        <td ><?= $row[fecha_recoleccion_efectiva] . ' ' . $row[hora_real_recoleccion] ?></td>
                        <td ><?= $row[recoleccion_efectiva] ?></td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr>
                        <td >FECHA ESTIMADA DE LLEGADA A PUERTO</td>
                        <td ><?= $row[fecha_estimada_llegada_a_puerto] . ' ' . $row[hora_estimada_arribo_puerto] ?></td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr>
                        <td >FECHA CONFIRMADA DE LLEGADA A PUERTO</td>
                        <td ><?= $row[fecha_confirmada_arribo_a_puerto] . ' ' . $row[hora_confirmada_arribo] ?></td>
                        <td ><?= $row[llegada_a_puerto] ?></td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr>
                        <td >FECHA INGRESO A RECINTO PORTUARIO</td>
                        <td ><?= $row[fecha_ingreso_efectiva] ?></td>
                        <td ><?= $row[ingreso_a_recinto_portuario] ?></td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                        <td >&nbsp;</td>
                    </tr>
                </table>


                <script>

    <?php if ($completa_ft == 'on') { ?>
                        document.getElementById('completa_ft').checked = true;
                        document.getElementById('trFT').style.display = 'block';
                        document.getElementById('trFT2').style.display = 'block';
    <?php } ?>
                </script>


                <table >
                    <tr>
                        <td height="24" colspan="7" style="color:#0088cc; font-weight:bold; ">&nbsp;</td>
                    </tr>
                    <tr>
                        <td height="24" colspan="7" style="color:#0088cc; font-weight:bold; ">&nbsp;</td>
                    </tr>
                    <tr>
                        <td height="24" colspan="7" style="color:#0088cc; font-weight:bold; ">DATOS DE AGENTE ADUANAL</td>
                    </tr>
                    <tr>

                        <td colspan="7" ><label>
                                <input type="checkbox" name="datos_aa" id="datos_aa" 
                                       onclick="if (this.checked) {
                                                       document.getElementById('span_agente_aduanal').style.visibility = 'visible';
                                                       document.getElementById('customsemail').readOnly = true;
                                                       document.getElementById('customstel').readOnly = true;
                                                       document.getElementById('customscontact').readOnly = true;
                                                       document.getElementById('customsagent').readOnly = true;
                                                       // document.getElementById('patente').readOnly=true;
                                                       document.getElementById('customsemail').value = 'despachosexpo@interteam.com.mx';
                                                       document.getElementById('customstel').value = '55149897 EXT 1409';
                                                       document.getElementById('customscontact').value = 'MARGARITA BELTRAN';
                                                       document.getElementById('customsagent').value = 'INTERTEAM S.A. DE C.V.';
                                                   } else {
                                                       document.getElementById('span_agente_aduanal').style.visibility = 'hidden';
                                                       document.getElementById('customsemail').readOnly = false;
                                                       document.getElementById('customstel').readOnly = false;
                                                       document.getElementById('customscontact').readOnly = false;
                                                       document.getElementById('customsagent').readOnly = false;
                                                       document.getElementById('patente').readOnly = false;
                                                       document.getElementById('customsemail').value = '';
                                                       document.getElementById('customstel').value = '';
                                                       document.getElementById('customscontact').value = ' ';
                                                       document.getElementById('customsagent').value = '';
                                                       document.getElementById('patente').value = '';
                                                   }"/>
                            </label>      Interteam realiza el servicio&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id="span_agente_aduanal" style="cursor:pointer;color:#0088cc; <?= ($row[customsagent] == 'INTERTEAM S.A. DE C.V.' and $idbooking != '') ? 'visibility:visible' : 'visibility:hidden' ?>;;font-size:12px; text-decoration:underline" onMouseover="ddrivetip('Documentos comerciales, fiscales y carta encomienda', 'yellow', 330)" onMouseout="hideddrivetip()" onClick="dhtmlwindow.open('BoxDA', 'iframe', 'archivos_despacho_aduanal_cargar.php?idbooking=<?= $idbooking ?>',
                                                'ARCHIVOS DE DESPACHO ADUANAL', 'width=850px,height=600px,resize=1,scrolling=1,center=1', 'recal')" target="_blank"><?php if (mysqli_num_rows($query_archivos_despacho) < 1) { ?>Subir archivos<?php } else { ?>VER archivos<?php } ?></span>
                        </td>
                    </tr>
                    <tr>
                        <td >&nbsp;</td>
                        <td ><span style="border:none">
                                <input type="hidden" id="idagente_aduanal" name="idagente_aduanal" value="<?= $row[idagente_aduanal] ?>" 
                                       size="30"/>
                            </span></td>
                        <td align="right" >&nbsp;</td>
                        <td align="center" >&nbsp;</td>
                        <td align="center" >&nbsp;</td>
                        <td align="center" >&nbsp;</td>
                        <td align="center" >&nbsp;</td>
                    </tr>
                    <tr>
                        <td >NOMBRE&nbsp;&nbsp;</td>
                        <td > 
                            <input type="text" style="text-transform:uppercase" id="customsagent" name="customsagent" value="<?= $row[customsagent] ?>" 
                                   size="30"  />

                            <?= (isset($_POST['customsagent']) and trim($_POST['customsagent']) == '') ? '<P style="color:red; font-size:12px">INGRESE NOMBRE</P>' : '' ?> 
                        <td >&nbsp;&nbsp;</td>
                        <td >CONTACTO&nbsp;&nbsp;</td>
                        <td > 
                            <input type="text"  id="customscontact" name="customscontact" value="<?= trim($row[customscontact]) == '' ? ' ' : trim($row[customscontact]) ?>" 
                                   style="text-transform:uppercase" size="30"/>
                            <?= (isset($_POST['customscontact']) and trim($_POST['customscontact']) == '') ? '<P style="color:red; font-size:12px">INGRESE CONTACTO</P>' : '' ?> </td>
                        <td >&nbsp;&nbsp;</td>
                        <td valign="baseline">TELEFONO&nbsp;&nbsp;</td>
                        <td > 
                            <input type="text"  id="customstel" name="customstel" value="<?= $row[customstel] ?>" 
                                   style="text-transform:uppercase" size="30"/>
                            <?= (isset($_POST['customstel']) and trim($_POST['customstel']) == '') ? '<P style="color:red; font-size:12px">INGRESE TELEFONO</P>' : '' ?></td>
                    </tr>
                    <tr>
                        <td align="right" >&nbsp;</td>
                        <td align="LEFT" >&nbsp;</td>
                        <td align="LEFT" >&nbsp;</td>
                        <td align="LEFT" >&nbsp;</td>
                        <td align="LEFT" >&nbsp;</td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td align="right" ><div align="left">EMAIL&nbsp;&nbsp;</div></td>
                        <td align="LEFT" ><input type="text"  id="customsemail" name="customsemail" value="<?= $row[customsemail] ?>" size="30"/>
                            <?= (isset($_POST['customsemail']) and trim($_POST['customsemail']) == '') ? '<P style="color:red; font-size:12px">INGRESE EMAIL</P>' : '' ?>    </td>
                        <td align="LEFT" >&nbsp;</td>
                        <td align="LEFT" >PATENTE</td>
                        <td align="LEFT" ><input type="text"  id="patente" name="patente" value="<?= $row[patente] ?>" size="30"/>

                            <?= (isset($_POST['patente']) and trim($_POST['patente']) == '' and $_POST['customsagent'] != 'INTERTEAM S.A. DE C.V.') ? '<P style="color:red; font-size:12px">INGRESE PATENTE</P>' : '' ?></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                </table>
                <br />
                <?php //echo 'agente adua '.$row[customsagent] ; // 'INTERTEAM S.A. DE C.V.';  ?>
                <script>
    <?php if (trim($row[customsagent]) == 'INTERTEAM S.A. DE C.V.') { ?>
                        /*document.getElementById('datos_aa').checked=true; 
                         document.getElementById('customsagent').readOnly=true; 
                         document.getElementById('customscontact').readOnly=true; 
                         document.getElementById('customstel').readOnly=true; 
                         document.getElementById('customsemail').readOnly=true; */
    <?php } ?>
                </script>
                <table width="1179" border="1"  >
                    <tr>
                        <td width="840" ><b>ESCRIBA AQUI INSTRUCCIONES ESPECIALES</b></td>
                        <td width="287" >&nbsp;</td>
                    </tr>
                    <tr>
                        <td ><label>
                                <textarea name="instrucciones_especiales" id="instrucciones_especiales" cols="65" rows="5"><?= $row[commentbooking] ?></textarea>
                            </label></td>
                        <td >&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan="3" >

                        </td>

                    </tr>
                </table>
                <input name="filas_mercancia" id="filas_mercancia" type="hidden" value="<?= mysqli_num_rows($query_mercancia) ?>"/>
                <input name="filas_dimensiones" id="filas_dimensiones" type="hidden" value="<?= mysqli_num_rows($query_dimensiones) ?>" />
            <?php } ?>
            <table>
                <tr>
                    <td>
                        <?php if ($diferencia < 0) { ?>
                            <br><p style="color:RED; FONT-SIZE:14PX">Estimado Cliente, si necesitara modificaciones por favor contactar a <a href="mailto:boookingsexpo@interteam.com.mx" target="_blank">
                                    boookingsexpo@interteam.com.mx</a> para la modificación del booking <?= $booking_interteam_conf ?> indicando los cambios que requiriera.
                            </p> 	
                        <?php } ?>
                        <?php
                        //echo 'difer '.$diferencia.' '.$row[files]; 
                        if (($row[files] == 'RONLINE' or $row[files] == '') or ( $diferencia >= 0)) {
                            ?>
                            <input type="submit" name="submit" id="submit" value="<?= $idbooking == '' ? 'GENERAR SOLICITUD' : 'GUARDAR SOLICITUD' ?>"  />
                        <?php } ?>
                    </td>
                </tr>
            </table>

            <div id="msg"></div>
            <br />
        </form>                    


        <?php //include("pie.php");  ?>


        <!-- Sticky Footer -->
        <footer class="sticky-footer">
            <div class="container my-auto">
                <div class="copyright text-center my-auto">
                    <span>intralogs.com | Copyright 2020 &copy; | Ciudad de México</span>
                </div>
            </div>
        </footer>
    </div>
    <!-- /.content-wrapper -->
</div>
<!-- /#wrapper -->
</body>
</html>