<?php
declare(strict_types=0);
//
{
// adrs
// enti
// docu idnum     
     
}


//      echo '===='.$docua['enti'];
// echo '====='.$zdocu.$zidnum;

if(empty($zdocu)){$zdocu='FC10';}
if(!empty($zidnum))
{
     $docua=data_docu($zdocu,$zidnum);
     $zcodigo=$docua['enti'];
}






$zcodigo=trim($zcodigo);
if(empty($zalign)){$zalign='left';}
$tdstyle='';

if($zobj==5){$zalign='';}
if(empty($zorient)){$zorient=0;}
if(empty($ztabla)){$ztabla='enti';}
if(empty($zid)){$zid=microtime()*1000000;}
if(empty($zobj)){$zobj=3;}
if(empty($zsize)){$zsize=1.5;}
if(!empty($zsize) and $zsize!=1){$zstyle.='font-size:'.($zsize).'em;';}
if(!empty($zcolor)){$zstyle.='background:'.$zcolor.';';}
if($zobj==5 and getPlatform()=='Android'){$zobj=1;}
if($zobj==5 or $zorient==1){$zfixh=0;}


$ztablai='img'.substr($ztabla,0,1);

if($ztcell>=2){$zstyle.='width:100%;';}

// count(item_tlla) as item_ctalla
// if(!empty($ztabla))
{
   $sql_address ='select * ';
   $sql_address.='from '.$ztabla.'0 ';
//    $sql_address.='left join '.$ztablai.'0 on '.$ztabla.'_codigo ='.$ztablai.'_'.$ztabla.' ';

//      $sql_address.='left join lsub0 on '.$ztabla.'_lsub=lsub_codigo ';
//      $sql_address.='left join prvc0 on '.$ztabla.'_prvc=prvc_codigo ';
     
   $sql_address.='where '.$ztabla.'_status not in ("O","X") ';
   $sql_address.='and '.$ztabla.'_codigo like "'.$zcodigo.'%" ';
   $sql_address.='and length(trim('.$ztabla.'_codigo))>=10 ';
     
//    $sql_address.='order by '.$ztablai.'_defa desc,'.$ztablai.'_idate desc ,'.$ztablai.'_codigo ';
//    $sql_address.='limit '.$i_limit;
   $res_address=msql_query($sql_address,$link_data);
     
}



if(msql_num_rows($res_address)!=0)
{
     msql_data_seek($res_address,0);
     $aso_address=msql_fetch_assoc($res_address);


     $domd0 = new DOMDocument();
          $domd0->encoding = 'utf-8';
          $domd0->xmlVersion = '1.0';
          $domd0->formatOutput = true;
     $elem0=$domd0;

     if(!empty($zdom)){$domd0=$zdom;}
     if(!empty($zele)){$elem0=$zele;}

     
     if($zobj==2)
     {
          if(substr($_SESSION['platform'],0,3)=='Win' and empty($zupld) and 1==1)
          {
               
               $buttons=$elem0->appendChild($domd0->createElement("div"));               
                    $buttons->setAttribute("style","margin-left:40%; float:;position:fixed;z-index:1;");
               
               $button1=$buttons->appendChild($domd0->createElement("button","➖"));
                    $button1->setAttribute("id","btn_z-");
                    $button1->setAttribute("onclick","document.getElementById('tbl_".$zid."').style.zoom=parseInt(document.getElementById('tbl_".$zid."').style.zoom)-50 +'%';");
               
               $button1=$buttons->appendChild($domd0->createElement("button","ZOOM"));
                    $button1->setAttribute("id","btn_z-");
                    $button1->setAttribute("onclick","document.getElementById('tbl_".$zid."').style.zoom='100%';");
               
               $button1=$buttons->appendChild($domd0->createElement("button","➕"));
                    $button1->setAttribute("id","btn_z+");
                    $button1->setAttribute("onclick","document.getElementById('tbl_".$zid."').style.zoom=parseInt(document.getElementById('tbl_".$zid."').style.zoom)+50 +'%';");
          }
     }
     
     if($ztcell>=2)
     {
          $element=$elem0->appendChild($domd0->createElement("td"));
               if(!empty($zid))
               {$element->setAttribute("id",$zid);}
               $element->setAttribute("valign","top");
     }
     else
     {
          $spandiv='div';

          $element=$elem0->appendChild($domd0->createElement($spandiv,""));
               if(empty($zdom))
               {$zstyle.="float:".$zalign.";";
               $element->setAttribute("style",$zstyle);}
          
//                if(empty($zdom))
//                {$element->setAttribute("style","float:".$zalign.";margin-left:".$zsize*(0.5)."em;margin-right:".$zsize*(0.5)."em;margin-bottom:".$zsize*(0)."em;");}
               if(empty($zdom))
               {$element->setAttribute("style","margin-left:".$zsize*(0.5)."em; margin-right:".$zsize*(0.5)."em; margin-bottom:".$zsize*(0)."em;". "font-family:Arial;");}

               if(!empty($zid))
               {$element->setAttribute("id",$zid);}
//                $element->setAttribute("img-span",'');
     }

     if(!empty($zhide)){$element->setAttribute("hide","");}
     
// echo '==============> '.$zcodigo;
     
     
          $table=$element->appendChild($domd0->createElement("table"," "));
               $table->setAttribute("border",'1');
               $table->setAttribute("id","tbl_".$zcodigo);
               $table->setAttribute("name",$zcodigo);
               $table->setAttribute("align","center");
               $table->setAttribute("cellpadding",'3px');
               $table->setAttribute("width",'100%');
               $table->setAttribute("style",'zoom:'.$zsize.';');
//                     if($zobj==2 and empty($zupld) and substr($_SESSION['platform'],0,3)=='Win' )
//                     {$table->setAttribute("style",'zoom:250%;');}

          $trow=$table->appendChild($domd0->createElement("tr",""));

          $tcell=$trow->appendChild($domd0->createElement("td",""));
               $tcell->setAttribute("colspan",'99');
               $tcell->setAttribute("align-c",'');
               $tcell->setAttribute("style","height:; background-color:gainsboro;");

          // header
          msql_data_seek($res_address,0);
          $aso_address=msql_fetch_assoc($res_address);
     
//           $hr=$tcell->appendChild($domd0->createElement("hr",""));
//                $hr->setAttribute("color",$empr0['empr_color1']);
//                $hr->setAttribute("size","5");
//                $hr->setAttribute("noshade","");

          $onclick='{window.location.href="?scri=ctlg_'.$ztabla.'3&buscar='.$zcodigo.'&format='.$format.'"}';
          $onclick2='{window.location.href="?scri=ctlg_'.$ztabla.'3&lsub='.$aso_address['lsub_codigo'].'&format='.$format.'"}';
          $onclick3='{window.location.href="?scri=ctlg_'.$ztabla.'3&prvc='.$aso_address['prvc_codigo'].'&format='.$format.'"}';
//           if($zobj!=2)
          {
               if($zobj!=4 and $zobj!=5)
               {
//                     $span=$tcell->appendChild($domd0->createElement("div",'DESTINATARIO'));
//                               $span->setAttribute("name",'codigo');
//                               $span->setAttribute("bold",'');
//                               $span->setAttribute("align-c",'');
//                               $span->setAttribute("onclick",$onclick);
//                               $span->setAttribute("style",'letter-spacing: 0.3em;');
//                     $div=$tcell->appendChild($domd0->createElement("div",$lsub_descri));
//                          $div->setAttribute("size80",'');
//                          $div->setAttribute("bold",'');
//                          $div->setAttribute("onclick",$onclick2);
                    
                    
               }

               
               $span=$tcell->appendChild($domd0->createElement("div",'DESTINATARIO'));
                         $span->setAttribute("name",'codigo');
                         $span->setAttribute("bold",'');
                         $span->setAttribute("style",'letter-spacing: 0.3em;');
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
                    $trow->setAttribute('height','auto');
                    $trow->setAttribute('style','height:auto;');
               $tcell=$trow->appendChild($domd0->createElement("td","Ced./RUC :"));
                    $tcell->setAttribute('align-r','');
//                $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_codigo']));
               $tcell=$trow->appendChild($domd0->createElement("td",''));
                    $codigo = $tcell->appendChild($domd0->createElement("a",$aso_address['enti_codigo']));
                    $xonclick='{regi_maes("enti","'.$aso_address['enti_codigo'].'");}';
                    $codigo->setAttribute('onclick',$xonclick);
//                     $codigo->setAttribute('style','color: inherit;');

               
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td","Raz.Social :"));
                    $tcell->setAttribute('align-r','');
               $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_razsoc']));
                    $tcell->setAttribute('bold','');
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td","Nom.Comercial:"));
                    $tcell->setAttribute('align-r','');
               $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_nomcom']));
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td","Dirección :"));
                    $tcell->setAttribute('align-r','');
               $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_direccion']));
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td","Prov./Ciudad :"));
                    $tcell->setAttribute('align-r','');
               $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_provincia'].' / '.$aso_address['enti_ciudad']));
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td","Teléfono :"));
                    $tcell->setAttribute('align-r','');
               $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_telefono']));
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td","e-Mail :"));
                    $tcell->setAttribute('align-r','');
               $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_email']));
               
          }

     
          $hr=$element->appendChild($domd0->createElement("hr",""));
//                $hr->setAttribute("color",$empr0['empr_color1']);
               $hr->setAttribute("size","1");
               $hr->setAttribute("noshade","");
     
     
//           echo '====='.$empr0['empr_ruc'];
          $sql_address=str_replace($zcodigo,$empr0['empr_ruc'],$sql_address);
          $res_address=msql_query($sql_address,$link_data);
     

          $table=$element->appendChild($domd0->createElement("table"," "));
               $table->setAttribute("border",'1');
               $table->setAttribute("id","tbl_".$zcodigo);
               $table->setAttribute("name",$zcodigo);
               $table->setAttribute("align","center");
               $table->setAttribute("cellpadding",'3px');
               $table->setAttribute("width",'100%');
               $table->setAttribute("style",'zoom:'.(int)$zsize*(.90).';');
//                     if($zobj==2 and empty($zupld) and substr($_SESSION['platform'],0,3)=='Win' )
//                     {$table->setAttribute("style",'zoom:250%;');}

          $trow=$table->appendChild($domd0->createElement("tr",""));

          $tcell=$trow->appendChild($domd0->createElement("td",""));
               $tcell->setAttribute("colspan",'99');
               $tcell->setAttribute("align-c",'');
               $tcell->setAttribute("style","height:; background-color:gainsboro;");

          // header
          msql_data_seek($res_address,0);
          $aso_address=msql_fetch_assoc($res_address);
     
//           $hr=$tcell->appendChild($domd0->createElement("hr",""));
//                $hr->setAttribute("color",$empr0['empr_color1']);
//                $hr->setAttribute("size","5");
//                $hr->setAttribute("noshade","");

          $onclick='{window.location.href="?scri=ctlg_'.$ztabla.'3&buscar='.$zcodigo.'&format='.$format.'"}';
          $onclick2='{window.location.href="?scri=ctlg_'.$ztabla.'3&lsub='.$aso_address['lsub_codigo'].'&format='.$format.'"}';
          $onclick3='{window.location.href="?scri=ctlg_'.$ztabla.'3&prvc='.$aso_address['prvc_codigo'].'&format='.$format.'"}';
//           if($zobj!=2)
          {
               if($zobj!=4 and $zobj!=5)
               {
//                     $span=$tcell->appendChild($domd0->createElement("div",'DESTINATARIO'));
//                               $span->setAttribute("name",'codigo');
//                               $span->setAttribute("bold",'');
//                               $span->setAttribute("align-c",'');
//                               $span->setAttribute("onclick",$onclick);
//                               $span->setAttribute("style",'letter-spacing: 0.3em;');
//                     $div=$tcell->appendChild($domd0->createElement("div",$lsub_descri));
//                          $div->setAttribute("size80",'');
//                          $div->setAttribute("bold",'');
//                          $div->setAttribute("onclick",$onclick2);
                    
                    
               }

               
               $span=$tcell->appendChild($domd0->createElement("div",'REMITENTE'));
                         $span->setAttribute("name",'codigo');
                         $span->setAttribute("bold",'');
                         $span->setAttribute("style",'letter-spacing: 0.3em;');
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
//                     $trow->setAttribute('hide','');
                    $trow->setAttribute('height','auto');
                    $trow->setAttribute('style','height:auto;');
               $tcell=$trow->appendChild($domd0->createElement("td","Ced./RUC :"));
                    $tcell->setAttribute('align-r','');
               $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_codigo']));
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td","Raz.Social :"));
                    $tcell->setAttribute('align-r','');
               $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_razsoc']));
                    $tcell->setAttribute('bold','');
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
                    $trow->setAttribute('hide','');
               $tcell=$trow->appendChild($domd0->createElement("td","Nom.Comer.:"));
                    $tcell->setAttribute('align-r','');
               $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_nomcom']));
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td","Dirección :"));
                    $tcell->setAttribute('align-r','');
               $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_direccion']));
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td","Ciudad :"));
                    $tcell->setAttribute('align-r','');
               $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_provincia'].' / '.$aso_address['enti_ciudad']));
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td","Teléfono :"));
                    $tcell->setAttribute('align-r','');
               $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_telefono']));
               
               $trow=$table->appendChild($domd0->createElement("tr",""));
                    $trow->setAttribute('hide','');
               $tcell=$trow->appendChild($domd0->createElement("td","e-Mail :"));
                    $tcell->setAttribute('align-r','');
               $tcell=$trow->appendChild($domd0->createElement("td",$aso_address['enti_email']));
               
          }
     
     
     
     
     
     
          // detail
          if(1==2)
          {
          if($zobj==2 and $zupld==1)
          {
               //input file
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td",""));
               $tcell->setAttribute("style","min-width:24em;");
               $tcell->setAttribute("colspan","2");
               
               $div=$tcell->appendChild($domd0->createElement("a","CODIGO : ".$img_codigo));
                    $div->setAttribute("bold","");
                    $div->setAttribute("style","color:".$empr0['empr_color1'].";");
                    $div->setAttribute("onclick",$onclick);
               
               $div=$tcell->appendChild($domd0->createElement("div",' '.$lsub_descri));
                    $div->setAttribute("bold",'');
                    $div->setAttribute("onclick",$onclick2);

               
               if($ver_tallas==0)
               {
                    $div=$tcell->appendChild($domd0->createElement("div"," "));
                    $input=$div->appendChild($domd0->createElement("input",""));
                    $input->setAttribute("id","ctlg".$zcodigo);
                    $input->setAttribute("type","checkbox");
                    $input->setAttribute("rel-left","");
                    if($item_ctlg==1)               
                    {$input->setAttribute("checked","");}
                    $input->setAttribute("onclick","save_chkbox('".$ztabla."','".$ztabla."_ctlg',".$zcodigo.",this.checked)");
                    $label=$div->appendChild($domd0->createElement("label","_Catálogo"));
                         $label->setAttribute("for","ctlg".$zcodigo);
                         $label->setAttribute("rel-left","");
                    $spant=$div->appendChild($domd0->createElement("div"," "));
                    $spant->setAttribute("style","height:1em;");
               }

               
               if($ver_tallas==2)
               {
                    msql_data_seek($res_tllas,0); 
                    $divt=$tcell->appendChild($domd0->createElement("div"," "));
                    while($aso_tllas=msql_fetch_assoc($res_tllas))
                    {
                         if((int)$aso_tllas['item_tlla']>0 or ((int)$aso_tllas['item_tlla']==0 and $ctllas==1) )
                         {
                              $zcodigo_tlla=$aso_tllas['item_codigo'];

                              $input=$divt->appendChild($domd0->createElement("input",""));
                              $input->setAttribute("id","ctlg".$zcodigo_tlla);
                              $input->setAttribute("type","checkbox");
                              $input->setAttribute("rel-left","");
                              if($aso_tllas['item_ctlg']==1)               
                              {$input->setAttribute("checked","");}
                              $input->setAttribute("onclick","save_chkbox('".$ztabla."','".$ztabla."_ctlg',".$zcodigo_tlla.",this.checked)");
                              $label=$divt->appendChild($domd0->createElement("label","_".$aso_tllas['tlla_descri']));
                                   $label->setAttribute("for","ctlg".$zcodigo_tlla);
                              $label->setAttribute("rel-left","");
                              $label->setAttribute("nowrap","");
                              
                              $spant=$divt->appendChild($domd0->createElement("div","."));
                              $spant->setAttribute("rel-left","");
                              $spant->setAttribute("style","min-width:1em;");
                         }
                    }
                    $spant=$divt->appendChild($domd0->createElement("div"," "));
                    $spant->setAttribute("style","height:1em;");
               }
               /////////
               $div=$tcell->appendChild($domd0->createElement("div"," "));
//                     $div->setAttribute("rel-left","");
                    $div->setAttribute("style","height:1em;");
               $divf=$tcell->appendChild($domd0->createElement("div"," "));
//                     $divf->setAttribute("rel-left","");
               $input=$tcell->appendChild($domd0->createElement("input",""));
               $input->setAttribute("id","if".$zcodigo);
               $input->setAttribute("type","file");
               $input->setAttribute("hide","");
               $input->setAttribute("multiple","");
               $input->setAttribute("accept","image/*");
               
//                echo '===>'.getPlatform();
//                if(substr(getPlatform(),0,7)!='Windows')
//                {$input->setAttribute("capture","camera");}
               
               $input->setAttribute("onchange","{document.getElementById('sf".$zcodigo."').value=this.files.length+' archivo(s)';}");
               
               $label=$divf->appendChild($domd0->createElement("label","Seleccionar Fotos : "));
                    $label->setAttribute("for","if".$zcodigo);
                    $label->setAttribute("rel-left","");
               
//                $div=$divf->appendChild($domd0->createElement("span",""));                         
//                     $div->setAttribute("rel-left","");
               $input=$divf->appendChild($domd0->createElement("input",""));     
                    $input->setAttribute("id","sf".$zcodigo);
                    $input->setAttribute("readonly","");
                    $input->setAttribute("sel-file","");
                    $input->setAttribute("onclick","{document.getElementById('if".$zcodigo."').click();}");
                    $input->setAttribute("rel-left","");
                    $input->setAttribute("placeholder","📂");
               

//                $div=$divf->appendChild($domd0->createElement("span",""));                         
//                     $div->setAttribute("rel-left","");
               
//                echo '<br>*/*/*'.$zcodigo;
               $button=$divf->appendChild($domd0->createElement("button","🔼Subir Fotos"));                         
                    $button->setAttribute("btn-file","");
                    $button->setAttribute("zoom80","");
                    $button->setAttribute("onclick","upld_address('".$ztablai."',".$zcodigo.",'if".$zcodigo."')");
                    $button->setAttribute("rel-left","");

               
               $trow=$table->appendChild($domd0->createElement("tr",""));
               
               if($cfotos==0)
               {
                    $tcell=$trow->appendChild($domd0->createElement("td","Sin Foto"));
                    $tcell->setAttribute('style','height:5em;');
               }
               
               
               
          }
               
          if($zobj==2 and $cfotos>=1)
          {
               if($zorient==0)
               {$trow=$table->appendChild($domd0->createElement("tr",""));}

               
               
               msql_data_seek($res_imgi,0);
               while($aso_imgi=msql_fetch_assoc($res_imgi))
               {
                    if($zorient==1)
                    {$trow=$table->appendChild($domd0->createElement("tr",""));}
                    $tcell=$trow->appendChild($domd0->createElement("td",""));
                         $tcell->setAttribute("style",'width:auto');
                         $tcell->setAttribute("id",'td'.$aso_imgi[$ztablai.'_codigo']);
                         if(empty($aso_imgi[$ztablai.'_file']))
                         {$tcell->setAttribute("hide"," ");}
                    
                    if($zupld==1)
                    {
                         $div=$tcell->appendChild($domd0->createElement("div"," "));                         
                         $div->setAttribute("style","border:1px;border-style:solid;border-color:black;background-color:".$empr0['empr_color2'].";");
                         $div->setAttribute("onclick","document.getElementById('rd".$aso_imgi[$ztablai.'_codigo']."').click();");
                         $div->setAttribute("title","Fijar Principal");
                         
                         $radio=$div->appendChild($domd0->createElement("input",""));                         
                         $radio->setAttribute("type",'radio');
                         $radio->setAttribute("name",$zcodigo);
                         $radio->setAttribute("id","rd".$aso_imgi[$ztablai.'_codigo']);
                         $radio->setAttribute("valign-t","");
                         if($aso_imgi[$ztablai.'_defa']==1)
                         {$radio->setAttribute("checked","");}
                         $radio->setAttribute("onclick","defa_address('".$ztablai."',".$aso_imgi[$ztablai.'_codigo'].")");
                         $radio->setAttribute("tabindex","-1");
                         
//                          echo '<br>*/*/'.$aso_imgi[$ztablai.'_defa'];
                    }
                    
                    $div=$tcell->appendChild($domd0->createElement("div"," "));
                         $div->setAttribute("img-bbott","");
                    
                    $image=$div->appendChild($domd0->createElement("img",""));
                         $image->setAttribute("id",'img_'.$aso_imgi[$ztablai.'_codigo']);
//                          $image->setAttribute("class",'fotito');
                         $image->setAttribute("src",'//'.$file_server.'/'.$cfg_empr.'/'.$ztablai.'/'.$aso_imgi[$ztablai.'_file']);
                    
                         $image->setAttribute("style",'width:auto');
                         if($zorient==0)
                         {
//                               $image->setAttribute("rel-left",'');
                              $image->setAttribute("style",'max-width:'.intval(12*$zsize).'em;' );
                         }
                    
                    if($zupld==1)
                    {
                         $div=$tcell->appendChild($domd0->createElement("div"," "));                         
                         $button=$div->appendChild($domd0->createElement("button","X"));                         
                         $button->setAttribute("tabindex","-1");
                         $button->setAttribute("btn-elim","");
                         $button->setAttribute("onclick","dele_address('".$ztablai."',".$aso_imgi[$ztablai.'_codigo'].")");
                    }
                    
                    
               }
          }

     
          if($zobj==2 and $zupld==1)
          {
//                //input file
               $trow=$table->appendChild($domd0->createElement("tr",""));
               $tcell=$trow->appendChild($domd0->createElement("td",""));
               $tcell->setAttribute("colspan",3);
//                $div=$tcell->appendChild($domd0->createElement("div",$img_descri));
//                     if(strlen($img_descri)>40){$div->setAttribute("size80",'');}
//                     if(strlen($img_descri)>60){$div->setAttribute("size60",'');}
          }
     
          if($zobj>2 and $cfotos>1)
          {    
               msql_data_seek($res_imgi,0);
               while($aso_imgi=msql_fetch_assoc($res_imgi))
               {
                    $div=$tcell->appendChild($domd0->createElement("div"," "));
//                          $div->setAttribute("style","border-bottom-style:solid; border-color:white; border width:200px;");
                         $div->setAttribute("img-bbott","");

                    $image=$div->appendChild($domd0->createElement("img",""));
//                          $image->setAttribute("class",'fotito');
                         $image->setAttribute("src",'//'.$file_server.'/'.$cfg_empr.'/'.$ztablai.'/'.$aso_imgi[$ztablai.'_file']);
                         $image->setAttribute("onmouseover","{document.getElementById('".$zcodigo."_img').src=this.src;}");
//                          $image->setAttribute("style",'max-width:'.intval(4*$zsize).'em;');
                         $image->setAttribute("style",'max-width:'.intval(4*$zsize).'em; border-bottom:4px solid;');
                         if(empty($aso_imgi[$ztablai.'_file']))
                         {$tcell->setAttribute("hide"," ");}
               }
          }
          
          }     
               
               
               
          // main
          if(1==2)
          if($zobj!=2)
          {
               msql_data_seek($res_imgi,0);
               $aso_imgi=msql_fetch_assoc($res_imgi);
               $img_file=$aso_imgi[$ztablai.'_file'];
               $img_stat=$aso_imgi[$ztablai.'_status'];
               
//                if(empty($img_file))
               if(empty($img_file) or $img_stat=='X')
               {
                    $tcell=$trow->appendChild($domd0->createElement("td"," "));
                    $div=$tcell->appendChild($domd0->createElement("div"," "));
                         $div->setAttribute("style","height:1em;");
                    $div=$tcell->appendChild($domd0->createElement("div","Sin Foto"));
                         $div->setAttribute("style","height:2em;");
                         if($zobj==4)
                         {$div->setAttribute("style","height:2em; width:21em;");}
                    $div=$tcell->appendChild($domd0->createElement("div"," "));
                         $div->setAttribute("style","height:1em;");
               }
               else
               {
                    $tcell=$trow->appendChild($domd0->createElement("td",""));
                         if($cfotos>1)
                         {$tdstyle.='min-width:'.intval(17*$zsize).'em;';}
                         else
                         {$tdstyle.='min-width:'.intval(21*$zsize).'em;';}
                         if($zobj==5)
                         {$tdstyle='width:'.intval(7*$zsize).'em; ';}
                    
                         if($zfixh==1)
                         {$trow->setAttribute("style","height:".intval(28*$zsize)."em;");}
                    
                         $tcell->setAttribute("style",$tdstyle);

                    $image=$tcell->appendChild($domd0->createElement("img",""));
                         $image->setAttribute("id",$zcodigo.'_img');
                         $image->setAttribute("ondblclick","{_clickimg('".$img_rfer."','".$ztabla."');}");
                         $image->setAttribute("src",'//'.$file_server.'/'.$cfg_empr.'/'.$ztablai.'/'.$img_file);
                         $istyle='width:'.intval(21*$zsize).'em; ';
                         
//                          if($zfixh==1)
                    
                    
                         if($zobj==5)
                         {$istyle='width:'.intval(4*$zsize).'em; ';}
                         $image->setAttribute("style",$istyle);
                    
//                          if(!empty($zfixh))
//                          {
//                               $istyle='width:auto; ';
//                               $istyle.='height:'.intval(12*$zsize).'em; ';
// //                               $istyle.='max-height:'.intval(21*$zsize).'em; ';
// //                               $istyle.='min-height:'.intval(4*$zsize).'em;';
//                          }
                    
                    
               }
          }

          // foot
          if(1==2)
          {
               
          msql_data_seek($res_address,0);
          $aso_address=msql_fetch_assoc($res_address);

          if($zobj==4 or $zobj==5)
          {$tcell=$trow->appendChild($domd0->createElement("td",""));}
     
//                if($cfotos>1)
//                {$tdstyle='min-width:'.intval(17*$zsize).'em;';}
//                else
//                {$tdstyle='min-width:'.intval(21*$zsize).'em;';}
     
               if($zobj==5)
               {$tdstyle='width:'.intval(21*$zsize).'em;';}

//                if($zobj==2 and $zupld==1)
               if($zobj==2 and $zorient==0)
               {$tdstyle='width:auto';}

               $tcell->setAttribute("style",$tdstyle);
     
//           if($zobj!=2)
          {
               if($zobj==4 or $zobj==5)
               {
                    $span=$tcell->appendChild($domd0->createElement("a",'CODIGO 1: '.$img_codigo));
                              $span->setAttribute("name",'codigo');
                              $span->setAttribute("bold",'');
                              $span->setAttribute("onclick",$onclick);

                    $div=$tcell->appendChild($domd0->createElement("div",' '.$lsub_descri));
                         $div->setAttribute("bold",'');
                         $div->setAttribute("style",'min-height:'.intval(4*$zsize).'em;');
                         $div->setAttribute("onclick",$onclick2);
                    
                    
                    if($empr0['empr_inmobil']==1)
                    {
                              $div=$tcell->appendChild($domd0->createElement("div",$prvc_descri));
                                   $div->setAttribute("bold",'');
                                   $div->setAttribute("size80",'');
                    }
                    
                    
               }

               if($zobj==5)
               {
                    $tcell=$trow->appendChild($domd0->createElement("td",""));
                    $tdstyle='width:'.intval(21*$zsize).'em; ';
                    $tcell->setAttribute("style",$tdstyle);
               }

               //DESCRIPCION
               if($zobj!=2 or $zupld==1)
               {

               if(!empty($mrca_descri))
               {
               $div=$tcell->appendChild($domd0->createElement("div",$mrca_descri));
                    $div->setAttribute("bold","");
                    $div->setAttribute("size80","");
               }
                    
               $div=$tcell->appendChild($domd0->createElement("div",htmlspecialchars($img_descri)));
                    $div->setAttribute("id",$zid.'_desc');
                    $div->setAttribute("bold","");
//                     $div->setAttribute("size80","");
                    
               if($zobj==4)
               {$div->setAttribute("style",'min-width:'.intval(21*$zsize).'em;'.'min-height:'.intval(4*$zsize).'em;');}
               else
               {
                    if(strlen($img_descri)>40){$div->setAttribute("size80",'');}
                    if(strlen($img_descri)>60){$div->setAttribute("size60",'');}
               }

               // ADICIONALES
               if(!empty($kldd_descri))
               {
                    $div=$tcell->appendChild($domd0->createElement("div",''.$kldd_descri.' /'.$item_composi));
                         if($zobj==4)
                         {$div->setAttribute("style",'min-height:'.intval(2*$zsize).'em;');}
                         else
                         {$div->setAttribute("size80",'');}
                         $div->setAttribute("italic",'');
               }

               if(strlen($clor_descri)>=3)
               {
                    $xclor='COLOR : '.$clor_descri;
                    if($zsize<1){$xclor=$clor_descri;  }
                    $div=$tcell->appendChild($domd0->createElement("div",$xclor));
                    $div->setAttribute("size80",'');
                    if(!empty($clor_hexa))
                    {
                         $div->setAttribute("bold",'');
                         $div->setAttribute("style",'border:4px solid;border-color:'.$clor_hexa.';');
                    }                         
               }

               if(!empty($tlla_descri2))
               {
                    $div=$tcell->appendChild($domd0->createElement("div",'TALLAS : '.$tlla_descri2));
                    if($zobj==4)
                    {$div->setAttribute("style",'min-height:'.intval(2*$zsize).'em;');}
                    else
                    {$div->setAttribute("size80",'');}
               }

               if(!empty($zstockv))
               {
                    $alertmsg='';
                    $sstyle='';
                    $maxcarr=(int)$zstock;
                    if($zstock>0)
                    {
                         if($zstockv==1){$valstock='STOCK : '.number_format($zstock,$item_duni).' '.$item_umdd;}
                         if($zstockv>=2){$valstock='DISPONIBLE';}
                         if($zstockv==3){$alertmsg="{_clickdispon('".$zid."_desc','".number_format($zstock,$item_duni).' '.$item_umdd."');}";}
                    }
                    else{$valstock='NO DISPONIBLE'; $sstyle='color:darkred;';}
                    
                    if($ztabla=='enti'){$valstock=' ';}
                    if($ztabla=='bbii'){$valstock=' ';}
                    

                    $div=$tcell->appendChild($domd0->createElement("div"," ".$valstock));
                         if($zobj==4)
                         {$div->setAttribute("style",'min-height:'.intval(3*$zsize).'em;');}
                         else
                         {$div->setAttribute("size80",'');}
                         $div->setAttribute("bold",'');
                         if(!empty($sstyle))
                         {$div->setAttribute("style",$sstyle);}
                         if(!empty($alertmsg))
                         {
                              $div->setAttribute("unselect",'');
                              $div->setAttribute("onclick",$alertmsg);
                         }
               }

               if(!empty($xprecio))
               {
                    $lblprecio='PVP : $ '.number_format($xprecio,$item_dpre);;
                    if(mb_stristr($zprecio,'puni')){$lblprecio='P.Uni : $ '.number_format($xprecio,$item_dpre).' +imp.';}
                    $div=$tcell->appendChild($domd0->createElement("div"," ".$lblprecio))     ;
                         if($zobj==4)
                         {$div->setAttribute("style",'min-height:'.intval(3*$zsize).'em;');}
                         else
                         {$div->setAttribute("size80",'');}
                         $div->setAttribute("bold",'');
               }

               if(!empty($zcarr) and !empty($user_codigo))
               {
                    if($zobj==5)
                    {
                         $tcell=$trow->appendChild($domd0->createElement("td"," "));
                         $tdstyle='width:'.intval(21*$zsize).'em; ';
                         $tcell->setAttribute("style",$tdstyle);
                    }

                    if($ver_tallas==0)
                    {
                         $sql_carr ='select cant from carr1 ';
                         $sql_carr.='left join carr2 on idnum1=idnum2 ';
                         $sql_carr.='left join item0 on item=item_codigo ';
                         $sql_carr.='where iuser="'.$user_codigo.'" ';
                         $sql_carr.='and item like "'.$zcodigo.'%"';
                         $sql_carr.='and docu like "'.$zdcarr .'%"';
                         $res_carr=msql_query($sql_carr,$link_data);
                         $cantcarr=msql_result($res_carr,0,'cant');
                         $idcantcarr=$zid.'_cant';

                         if(empty($item_umdd) or substr($item_umdd,0,2)=='UN')
                         {$cantcarr=(int)$cantcarr;}

          //                if($maxcarr>0)
                         {
                         $divt=$tcell->appendChild($domd0->createElement("div"," "));
//                               $divt->setAttribute("autocomplete","off");
//                               $divt->setAttribute("flex-center","");
                                                            
//                          $div=$divt->appendChild($domd0->createElement("label","Carrito : "));
//                               $div->setAttribute("for",$idcantcarr);
//                               $div->setAttribute("valign-m","");
                              
                         $button=$divt->appendChild($domd0->createElement("button","-"));
                              $button->setAttribute("onclick","$(this).next()[0].stepDown();$(this).next()[0].oninput();");
                              $button->setAttribute("valign-t","");
                              $button->setAttribute("style","width:3em;height:2em;");
                              
                         $div=$divt->appendChild($domd0->createElement("input",""));
                              $div->setAttribute("id",$idcantcarr);
                              $div->setAttribute("type","number");
                              $div->setAttribute("value",$cantcarr);
                              $div->setAttribute("autocomplete","off");
                              $div->setAttribute("cantcarr","");
                              $div->setAttribute("min","0");
                              $div->setAttribute("max",$maxcarr);
                              $div->setAttribute("oninput","{save_carr('".$zcodigo."',this.value);}");
                              $div->setAttribute("onchange","{val_minmax(this.id)}");
                              
                         $button=$divt->appendChild($domd0->createElement("button","+"));
                              $button->setAttribute("onclick","$(this).prev()[0].stepUp();$(this).prev()[0].oninput();");
                              $button->setAttribute("valign-t","");
                              $button->setAttribute("style","width:3em;height:2em;");
                              
                         }

                    }

                    if($ver_tallas==2)
                    {
                         msql_data_seek($res_tllas,0); 
                         while($aso_tllas=msql_fetch_assoc($res_tllas))
                         {
                              if((int)$aso_tllas['item_tlla']>0 or ((int)$aso_tllas['item_tlla']==0 and $ctllas==1) )
                              {
                              $sql_carr ='select cant from carr1 ';
                              $sql_carr.='left join carr2 on idnum1=idnum2 ';
                              $sql_carr.='left join item0 on item=item_codigo ';
                              $sql_carr.='where iuser="'.$user_codigo.'" ';
                              $sql_carr.='and item like "'.$aso_tllas['item_codigo'].'%"';
                              $res_carr=msql_query($sql_carr,$link_data);
                              $cantcarr=msql_result($res_carr,0,'cant');
                              $idcantcarr=$zid.'_cant';

                              if(empty($item_umdd) or substr($item_umdd,0,2)=='UN')
                              {$cantcarr=(int)$cantcarr;}

                              $divt=$tcell->appendChild($domd0->createElement("div"," "));
//                               $divt->setAttribute("style","margin-left:".$zsize*(0.5)."em;margin-right:".$zsize*(0.5)."em;margin-bottom:".$zsize*(0.0)."em; position:relative;float:left;");
                              $divt->setAttribute("style","margin-left:".$zsize*(0.5)."em;margin-right:".$zsize*(0.5)."em;margin-bottom:".$zsize*(0.0)."em;");
                              $divt->setAttribute("rel-left","");

                              $div=$divt->appendChild($domd0->createElement("label",$aso_tllas['tlla_descri']));
                                   $div->setAttribute("for",$idcantcarr);
                                   
                              $button=$divt->appendChild($domd0->createElement("button","+"));
                                   $button->setAttribute("onclick","$(this).next()[0].stepUp();$(this).next()[0].oninput();");
                                   $button->setAttribute("valign-t","");
                                   $button->setAttribute("style","width:4em;height:2em;display:block;color:grey;");
                                   
                              $div=$divt->appendChild($domd0->createElement("input",""));
                                   $div->setAttribute("cantcarr","");
                                   $div->setAttribute("id",$idcantcarr);
                                   $div->setAttribute("type","number");
                                   $div->setAttribute("min","0");
                                   $div->setAttribute("max","99");
                                   $div->setAttribute("value",$cantcarr);
                                   $div->setAttribute("oninput","{save_carr('".$aso_tllas['item_codigo']."',this.value);}");
                                   $div->setAttribute("style","width:3em;margin-bottom:0em;");
                                   $div->setAttribute("autocomplete","off");
                                   
                              $button=$divt->appendChild($domd0->createElement("button","-"));
                                   $button->setAttribute("onclick","$(this).prev()[0].stepDown();$(this).prev()[0].oninput();");
                                   $button->setAttribute("valign-t","");
                                   $button->setAttribute("style","width:4em;height:2em;display:block;color:grey;");
                              
                                   
                              }

                         }
                    }

                    if($ztotpvp>0)
                    {
                         $div=$tcell->appendChild($domd0->createElement("div",'Sub-Tot : $ '.number_format($ztotpvp,2)));
                         $div->setAttribute("bold"," ");
                         $div->setAttribute("style","clear:both;");
                         $div->setAttribute("onclick","{location.reload();}");
                    }

               }

                    
               if($empr0['empr_inmobil']==1)
               {
                    
                    if(empty($zprecio))
                    {
                         $vtalqu=' ';
                         if($aso_address['bbii_venta']==1){$vtalqu='VENTA';}
                         if($aso_address['bbii_alqui']==1){$vtalqu='ALQUILER';}
                         if($aso_address['bbii_venta']==1 and $aso_address['bbii_alqui']==1){$vtalqu='VENTA - ALQUILER';}

                         $div=$tcell->appendChild($domd0->createElement("div",$vtalqu))     ;
                              $div->setAttribute("bold",'');
                    }
                    
                    if(!empty($zprecio))
                    { 
                         $vtalqu=' ';
                         if($aso_address['bbii_venta']==1){$vtalqu='VENTA : $ ';    $vtalqu.=number_format($aso_address['bbii_pventa'],2);} 
                         $div=$tcell->appendChild($domd0->createElement("div",$vtalqu))     ;
                              $div->setAttribute("bold",'');
                         
                         $vtalqu=' ';
                         if($aso_address['bbii_alqui']==1){$vtalqu='ALQUILER : $ '; $vtalqu.=number_format($aso_address['bbii_palqui'],2);}
                         $div=$tcell->appendChild($domd0->createElement("div",$vtalqu))     ;
                              $div->setAttribute("bold",'');
                         
                    }

                    
                    {
                         $div=$tcell->appendChild($domd0->createElement("div",""));
                         
                              if($aso_address['bbii_plantas']>1)
                              {
                                   $lineadic=' / Plantas : '.number_format($aso_address['bbii_plantas'],0);
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                              if($aso_address['bbii_frente']>=1)
                              {
                                   $lineadic=' / Frente : '.number_format($aso_address['bbii_frente'],0).'m.';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                              if($aso_address['bbii_fondo']>=1)
                              {
                                   $lineadic=' / Fondo : '.number_format($aso_address['bbii_fondo'],0).'m.';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                         
                         $div=$tcell->appendChild($domd0->createElement("div",""));
                         
                              $lineadic=' / Terreno : '.number_format($aso_address['bbii_terreno'],0).'mt²';
                              $span=$div->appendChild($domd0->createElement("span",$lineadic));
                              $span->setAttribute("nowrap",'');
                         
                              if($aso_address['bbii_constru']>=1)
                              {
                                   $lineadic=' / Construcción : '.number_format($aso_address['bbii_constru'],0).'mt²';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }                         
                         
                         
                         
                         $div=$tcell->appendChild($domd0->createElement("div",""));
                         
                              if($aso_address['bbii_sala']==1)
                              {
                                   $lineadic=' / Sala ';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                              if($aso_address['bbii_estudio']==1)
                              {
                                   $lineadic=' / Estudio ';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                              if($aso_address['bbii_comedor']==1)
                              {
                                   $lineadic=' / Comedor ';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                              if($aso_address['bbii_cocina']==1)
                              {
                                   $lineadic=' / Cocina ';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                         $div=$tcell->appendChild($domd0->createElement("div",""));
                              if($aso_address['bbii_habitac']>=1)
                              {
                                   $lineadic=' /  Habitaciones : '.number_format($aso_address['bbii_habitac'],0).'';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }

                              if($aso_address['bbii_banio']>=1)
                              {
                                   $lineadic=' /  Baños : '.number_format($aso_address['bbii_banio'],0).'';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                              if($aso_address['bbii_banio2']>=1)
                              {
                                   $lineadic=' /  ½ Baños : '.number_format($aso_address['bbii_banio2'],0).'';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }                         

                         
                         
                         
                         $div=$tcell->appendChild($domd0->createElement("div",""));
                         
                              if($aso_address['bbii_patio']==1)
                              {
                                   $lineadic=' / Patio ';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                              if($aso_address['bbii_garage']==1)
                              {
                                   $lineadic=' / Garage ';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                              if($aso_address['bbii_terra']==1)
                              {
                                   $lineadic=' / Terraza ';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                              if($aso_address['bbii_vistamar']==1)
                              {
                                   $lineadic=' / Vista al Mar ';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                              if($aso_address['bbii_bbq']==1)
                              {
                                   $lineadic=' / BBQ ';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                              if($aso_address['bbii_piscina']==1)
                              {
                                   $lineadic=' / Piscina ';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                              if($aso_address['bbii_jacuzzi']==1)
                              {
                                   $lineadic=' / Jacuzzi ';
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
                                   $span->setAttribute("nowrap",'');
                              }
                         
                         
                         $div=$tcell->appendChild($domd0->createElement("div",""));
                         
                              if($aso_address['bbii_puntos']!=0)
                              {
                                   $lineadic='Ptos : '.$aso_address['bbii_puntos'];
                                   $span=$div->appendChild($domd0->createElement("span",$lineadic));
//                                    $span->setAttribute("size80",'');
                                   $span->setAttribute("bold",'');
                              }
                         
                         
                         
                    }
                    
                    
                    
               }
                    
                    
               }

          }

          $trow=$table->appendChild($domd0->createElement("tr",""));
          $tcell=$trow->appendChild($domd0->createElement("td",""));
               $tcell->setAttribute("colspan",'99');
     //           $tcell->setAttribute("style",'height:1em;');
//           $hr=$trow->appendChild($domd0->createElement("hr",""));
          $hr=$tcell->appendChild($domd0->createElement("hr",""));
               $hr->setAttribute("size","4");
               $hr->setAttribute("noshade","");
               if($zobj==5)
               {$hr->setAttribute("hide"," ");}

          }
               
          if(empty($zdom))
          {
               if($zxml==1){$zxml=$domd0->saveXML();}
               else{echo $domd0->saveXML();}
          }     

}

include ('ele_reset.php');

?>


<!-- 
<style type="text/css" media="print">
a {text-decoration: none; color: inherit;}    
<style>
      -->