function set_txtrow(e,pidtxt)
{
     var xvar=document.getElementById(pidtxt).value;
     if(e.keyCode==32){document.getElementById(pidtxt).value=xvar.replace('  ',' ');}

     var cols=document.getElementById(pidtxt).getAttribute('cols');
     var lentxt=xvar.trim().length;
     var rows=Math.ceil(lentxt/cols)+0;
     if(lentxt===0){rows=1;}
     document.getElementById(pidtxt).setAttribute('rows',rows);
}




function get_color(color,destino)
{
  var xurl,json,obj,colordescri;
  color=color.replace('#','');
    xurl='https://www.thecolorapi.com/id?format=json&hex='+color;
          $.ajax({
               url:xurl,
               async:true, 
               type:'GET',
               success:function(dato, textStatus, jqXHR)
               {
                    console.log(dato);
                    colordescri=dato.name.value;
                    if(document.getElementById(destino))
                    {if(document.getElementById(destino).value=='')
                    {document.getElementById(destino).value=colordescri;}}
               },
               error:function(jqXHR,textStatus,errorThrown )
               {console.log(jqXHR.status);}
          });	
  
  
  return colordescri;
}



function getOS()
{
  var userAgent = window.navigator.userAgent,
      platform = window.navigator.platform,
      macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
      windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'],
      iosPlatforms = ['iPhone', 'iPad', 'iPod'],
      os = null;

          if (macosPlatforms.indexOf(platform) !== -1) {os = 'Mac OS';}
     else if (iosPlatforms.indexOf(platform) !== -1) {os = 'iOS';}
     else if (windowsPlatforms.indexOf(platform) !== -1) {os = 'Windows';}
     else if (/Android/.test(userAgent)) {os = 'Android';}
     else if (!os && /Linux/.test(platform)) {os = 'Linux';}

  return os;
}

function sleep(milliseconds)
{
     const date = Date.now();
     let currentDate = null;
     do {currentDate = Date.now();}
     while (currentDate - date < milliseconds);
}

function data_maes(tabla,codigo,desti)
{
  var data = new FormData();
  var script='data_maes.php';
  if(desti=='' || desti===undefined){desti=tabla;}
  
  data.append('script',script);
  data.append('tabla',tabla);
  data.append('codigo',codigo);
//   alert(data+desti);
  exe_ajax(data,desti);
    
}

function get_para()
{
   getappv = navigator.appVersion;
   getempr = window.location.hostname.substring(0,4);
   gethost = window.location.hostname;
   getini = window.location.search.substring(1);
   if(getini.indexOf('=')>0){getini='';}	
   if(getini.indexOf('#')>0){getini=getini.substring(1,getini.indexOf('#'));}	

   var params = window.location.search.substr(1).split("&");
   $get={};
   for (var idx=0; idx<params.length; idx++)
   {
      var parat = params[idx].split("=");
      $get[decodeURIComponent(parat[0])] = decodeURIComponent(parat[1]);
   }
     
}

function exe_script(pscript,pdest='',pwait=0)
{
   if(pscript==undefined){return;}
   if(pwait==undefined){pwait=0;}
   if(pscript.indexOf('.php')<0){pscript=pscript+'.php';}
   
//    _urlinker='../_lib/_linker.php';
   var params = window.location.search.substr(1).split("&");

   $get = {};
   data = new FormData();	
   data.append('script',pscript);
   for (var idx=0; idx<params.length; idx++)
   {
      parat = params[idx].split("=");
      $get[decodeURIComponent(parat[0])] = decodeURIComponent(parat[1]);
      data.append(decodeURIComponent(parat[0]),decodeURIComponent(parat[1]));
   }
   rdata=exe_ajax(data,pdest,pwait);
}

function exe_func(phpfunc,pdest='',pwait=0)
{
	console.log('PHP F1 => '+phpfunc+' : '+Date());
	var msgalert='',pant1='',res1='',xdato;
     if(phpfunc==undefined){return;}
     if(pwait===undefined){pwait=0;}
	if(pdest===undefined){pdest='';}

     var data = new FormData();
	var rdata;
	data.append('script',phpfunc);
	rdata=exe_ajax(data,pdest,pwait)

// 	if(document.getElementById(pdest))
// 	{document.getElementById(pdest).innerHTML=rdata;}
	console.log('PHP F2 => '+phpfunc+' : '+Date());
  
	return rdata;
	
}


function exe_ajax(pdata,pdest='',pwait=0)
{
//      color='f9f9f9';
//      xurl='https://www.thecolorapi.com/id?format=json&hex='+color;
//      _urlinker=xurl;
   document.body.style.cursor = 'default';
   var msgalert,msgerror,msgsistemas;
   xasync=true;
   if(pwait==undefined){pwait=0;}
   
	if(pwait==0){xasync=true;}
	if(pwait==1){xasync=false;}
	var rdata;
     console.log('***  Exe_ajax ==> '+Date());
     console.log(_urlinker);
	$.ajax({
            data:pdata,
            url:_urlinker,
            type:'post',
            async:xasync,
            cache:false,
            contentType:false,
            processData:false,
            beforeSend: function(jqXHR, textStatus)
            {
//                  if(pwait==1)
                 {document.body.style.cursor='wait';}
                 console.log('*** Before exe_ajax ==> '+Date());
            }, 
            success:function(dato, textStatus, jqXHR)
            {
               console.log('*** Success exe_ajax ==> '+Date());
               console.log(dato);
               document.body.style.cursor = 'default';	
               rdata=dato;
               msgalert=$(dato).find("msgalert").text();
               msgerror=$(dato).find("msgerror").text();
               msgsistemas=$(dato).find("msgsistemas").text();

              if(msgalert!=='' && msgalert!='undefined'){alert(msgalert);}
              if(msgerror!=='' && msgerror!='undefined'){alert(msgerror);}
              if(msgsistemas!=='' && msgsistemas!='undefined'){console.log(msgsistemas);}
               
               if(pdest=='' || pdest==undefined)
               {
                    if(document.getElementById('result'))
                    {document.getElementById('result').innerHTML=rdata;}
               } 

               if(document.getElementById(pdest))
               {document.getElementById(pdest).innerHTML=rdata;}

               if($get.print==1)
               {document.body.innerHTML=rdata;}

            },
            error:function(jqXHR,textStatus,errorThrown )
            {
               document.body.style.cursor = 'default';
               console.log('*** ERROR exe_ajax ==> '+jqXHR.status+' : '+Date());
//                console.log(exception);
            }, 
            complete:function(jqXHR, textStatus)
            {if(textStatus==='success'){} console.log('*** Complete ==> '+Date()); },
            timeout:60000
   		});

   document.body.style.cursor = 'default';	   
   
   return rdata;
}



;