var fila = new Array();
var atual;
var animate = new Array();
var idFocus;
var req;

function autonum(nome) {
   var num = nome.value.length;
   var newNum = '';
   for (var i=0; i<num; i++) {
      if ((!(isNaN(nome.value.substr(i,1))) && (nome.value.substr(i,1) != ' ')) || nome.value.substr(i,1) == ',') {
         newNum = newNum + nome.value.substr(i,1);
      }
   }
   nome.value = newNum;
}

function validacaoTdLeftSpan() {
   //limpar className das tdLeftSpan
   for (var i=1; i<=15; i++) {
      var orig = 'idTdLeftSpan'+i;
      if (document.getElementById(orig) != null) document.getElementById(orig).className= '';
      else break;
   }
}

function changeClassName(dest, className) {
   if (document.getElementById(dest) != null && className != null) {
      document.getElementById(dest).className = className;
   }
}


//chamada normal
function refreshPage(url, d, animate, focusIdField, concatText) {
   idFocus = focusIdField;
   if (concatText == null) concatText = 0;
   //exibir idLoading
   if (document.getElementById(d) != null) {
      var content = new Array(url, d, animate, concatText);
      //adiciona na fila
      fila.push(content);
      if (animate!=0) document.getElementById(d).innerHTML = "<div style='text-align:left;'><div id=idLoadingImg>"+stringsPSA.s11+"</div></div>"+document.getElementById(d).innerHTML;
      //inicia loadXMLDoc
      processNext();
   }
}

function processNext() {
   //pegar na fila
   if (fila.length > 0) {
      if (atual == null || atual == '') {
         var aux = fila.pop();
         atual = aux[1];
         //encontrado
         loadXMLDoc(aux[0], aux[1], aux[2], aux[3]);
      }
   }
}


function loadXMLDoc(url, d, a, c) {
   req = null;
   div = d;
   anime = a;
   concat = c;
   if (window.XMLHttpRequest) {
      // Procura por um objeto nativo (Mozilla/Safari)
      req = new XMLHttpRequest();
   } else if (window.ActiveXObject) {
      // Procura por uma versao ActiveX (IE)
      req = new ActiveXObject("Microsoft.XMLHTTP");
   }
   if (req) {
      req.onreadystatechange = processReqChange;
      req.open("POST", url, true);
      req.setRequestHeader('Content-Type', "application/x-www-form-urlencoded; charset=Windows-1252");
      req.send(null);
   } else {
      alert("Seu browser não sporta AJAX.");
   }
   
}


function processReqChange() {
   // apenas quando o estado for "completado"
   try {
      if (req.readyState == 4) {
         // apenas se o servidor retornar "OK"
         switch(anime) {
            case 'slide':
               //slide
               ElementSlideUpDown(div, 1, 'slow');
               ElementClear(div);
            break;
            case 'fade':
               //fade
               ElementFadeInOut(div, 1, 'slow');
               ElementClear(div);
            break;
            default:
               //default
               ElementShowHiddenSimple(div, '1');
               ElementClear(div);
            break;
         }
         if (req.status == 200) {
            if (div != null) {
               // retornado nela, como texto HTML
               if (concat != 1) document.getElementById(div).innerHTML = req.responseText;
               else document.getElementById(div).innerHTML += req.responseText+"<br>\r\n";
            } else {
               return req.responseText;
            }
            //receber focu
            if (idFocus) ElementFocus(idFocus);
         } else {
            if (div != null) {
               if (concat != 1) document.getElementById(div).innerHTML = "Houve um problema ao obter os dados<br>"+document.getElementById(div).innerHTML;
               else document.getElementById(div).innerHTML += "Houve um problema ao obter os dados<br>"+document.getElementById(div).innerHTML+"<br>\r\n";
            } else {
               return "Houve um problema ao obter os dados";
            }
         }
         //remover lista de atual
         atual = '';
         //processar proximo da fila
         processNext();
      }
   } catch (e) {
      alert('Houve um problema ao obter os dados');
   }
   
}


 
   function ElementClassShowHidden(dest, option, mode) {
      if (mode == null) var mode = "slow";
      if (jQuery("."+dest)!=null) {
         if (option == 'show' || option == '1') {
            jQuery("."+dest).hide(mode);
            jQuery("."+dest).show(mode);
         } else {
            jQuery("."+dest).hide(mode);
         }
      }
   }
  
   //funcao para esconder e mostrar automaticamente
   function ElementShowHiddenSimple(dest, option, mode) { 
      if (mode == null) var mode = "slow";
      if (document.getElementById(dest)!=null) {
         if (option == 'show' || option == '1') {
            document.getElementById(dest).style.display = 'block';
         } else {
            document.getElementById(dest).style.display = 'none';
         }
      }
   }
   
   
   function ElementShowHiddenNormal(dest, option) { 
      if (document.getElementById(dest)!=null) {
         if (option == 'show' || option == '1') {
            document.getElementById(dest).style.display = "block";
         } else {
            document.getElementById(dest).style.display = "none";
         }
      }
   }
   
   function ElementShowHiddenTime(dest) { 
      if (dest != null) {
         document.getElementById(dest).style.display = "none";
      }
   }
   
   //funcao para esconder e mostrar
   function ElementClassShowHidden(dest, option, mode) { 
      var cont = 1;
      if (mode == null) var mode = "slow";
      if (jQuery("#"+dest)!=null) {
         if (option == 'show' || option == '1') {
            jQuery("#"+dest).slideDown(mode);
         } else {
            jQuery("#"+dest).slideUp(mode);
         }
      }
   }
   
   //funcao para esconder e mostrar
   function ElementClassShowHiddenLooping(dest, option) { 
      var cont = 1;
      if (mode == null) var mode = "slow";
      if (jQuery("#"+dest)!=null) {
         if (option == 'show' || option == '1') {
            jQuery("#"+dest).slideDown('slow');
         } else {
            jQuery("#"+dest).slideUp();
         }
      }
   }
   
   //funcao para esconder e mostrar automaticamente
   function ElementClassShowHiddenLoopingAuto(dest) { 
      var cont = 1;
      if (mode == null) var mode = "slow";
      if (jQuery("#"+dest)!=null) {
         if (jQuery("#"+dest).css('display') == 'none') {
            jQuery("#"+dest).slideDown('slow');
         } else {
            jQuery("#"+dest).slideUp();
         }
      }
   }
   
   //funcao para esconder e mostrar automaticamente
   function ElementShowHidden(dest, option, mode) { 
      if (mode == null) var mode = "slow";
      if (jQuery("#"+dest)!=null) {
         if (option == 'show' || option == '1') {
            jQuery("#"+dest).slideUp(mode);
            jQuery("#"+dest).show(mode);
         } else {
            jQuery("#"+dest).hide(mode);
         }
      }
   }
   
   //funcao para esconder e mostrar automaticamente
   function ElementShowHiddenAuto(dest){ 
      if (mode == null) var mode = "slow";
      if (jQuery("#"+dest)!=null) {
         if (jQuery("#"+dest).css('display') == '' || jQuery("#"+dest).css('display') == 'none') {
            ElementShowHidden(dest, 1);
         } else {
            ElementShowHidden(dest, 0);
         }
      }
   }
   
   
   function ElementShowHidden_auto(dest){ 
      ElementShowHiddenAuto(dest);
   }
   
   //funcao para esconder e mostrar automaticamente
   function ElementShowHidden_chk_auto(dest){ 
      if (mode == null) var mode = "slow";
      if (jQuery("#"+dest)!=null) {
         if (jQuery("#"+dest).css('display') == '') {
            jQuery("#"+dest).hide(mode);
            return true;
         } else {
            jQuery("#"+dest).hide(mode);
            jQuery("#"+dest).show(mode);
            return false;
         }
      }
      return false;
   }
   
   
     //funcao para esconder e mostrar automaticamente
   function ElementFadeInOut(dest, option, mode) { 
      if (mode == null) var mode = "slow";
      if (jQuery("#"+dest)!=null) {
         if (option == 'show' || option == '1') {
            jQuery("#"+dest).fadeIn(mode);
         } else {
            jQuery("#"+dest).fadeOut(mode);
         }
      }
   }
   
   //funcao para esconder e mostrar automaticamente
   function ElementSlideUpDown(dest, option, mode){ 
      if (mode == null) var mode = "slow";
      if (jQuery("#"+dest)!=null) {
         if (option == 'show' || option == '1') {
            jQuery("#"+dest).slideDown(mode);
         } else {
            jQuery("#"+dest).slideUp(mode);
         }
      }
   }
   
   
   function ElementHiddenFocusTime(dest, second) {
      if (second==null) second = false;
      if (second == true) {
         alert(document.getElementById(dest).focus());
      } else {
         setTimeout("ElementHiddenFocusTime('"+dest+"', '1')", 2000);
      }
   }
   
   function ElementShowHiddenUlChild(dest, option, cN) {
      if (dest.getElementsByTagName('ul')[0] != null) {
         if (option) {
            dest.getElementsByTagName('ul')[0].style.display = 'block';
            dest.className = cN+' nivelFilho2';
         } else { 
            dest.getElementsByTagName('ul')[0].style.display = 'none';
            dest.className = cN+' nivelFilho';
         }
      }
   }
   
   function ElementDisable(destino, option, mode, clNm) { 
      if (mode == null) var mode = "slow";
      if (clNm == null) var clNm = '';
      if (document.getElementById(destino)!=null) {
         doc = document.getElementById(destino);
         if (option == '1') {
            doc.disabled = true;
            if (clNm) doc.className = clNm;
         } else {
            doc.disabled = false;
            if (clNm) doc.className = clNm;
         }
      }
   }
   
   //funcao para limpar dados dentro do determinado getElementeById
   function ElementClear(dest) {
      if (jQuery("#"+dest)!=null) {
         jQuery("#"+dest).text('');
      }
   }
   
   //funcao para limpar dados dentro do determinado getElementeById
   function ElementClearValue(dest) {
      if (document.getElementById(dest)!=null) {
         document.getElementById(dest).value = '';
      }
   }
   
   //funcao para limpar dados dentro do determinado getElementeById
   function ElementClearContent(dest) {
      if (jQuery("#"+dest)!=null) {
         jQuery("#"+dest).value('');
      }
   }
   
   function ElementInner(dest, conteudo) {
      if (conteudo == null) conteudo = '';
      if (jQuery("#"+dest)!=null) {
         jQuery("#"+dest).text(conteudo);
      }
   }
   
   function ElementInnerValue(dest, conteudo) {
      if (conteudo == null) conteudo = '';
      if (document.getElementById(dest)!=null) {
         document.getElementById(dest).value = conteudo;
      }
   }
   
   function ElementPositionY(dest, orig, comp) {
      if (comp != null) comp = parseInt(comp);
      else comp = 0;
      jQuery('#'+dest).css('top', jQuery('#'+orig).position().top+comp);
   }
   
   function ElementPositionX(dest, orig, comp) {
      if (comp != null) comp = parseInt(comp);
      else comp = 0;
      jQuery('#'+dest).css('left', jQuery('#'+orig).position().left+comp);
   }
   
   function ElementCheck(dest) {
      if (document.getElementById(dest)) {
         return true;
      } else {
         return false;
      }
   }
   
     
   function ElementClassChange(dest, className) {
      if (document.getElementById(dest) != null && className != null) {
         document.getElementById(dest).className = className;
      }
   }
   
   function ElementFocus(dest) {
      if (document.getElementById(dest)!=null) {
         document.getElementById(dest).focus();
      }
   }
   
   function ElementPageCenter(div, displayFullScreen) {
      var top = ((document.documentElement.scrollTop + document.documentElement.clientHeight) / 2) - (jQuery('#'+div).height() / 2);
      var left = (document.documentElement.clientWidth / 2) - (jQuery('#'+div).width() / 2);
      if (displayFullScreen != null) {
         //fullscreen
         ElementFullScreen(displayFullScreen);
      }
      jQuery('#'+div).css({display:"block",'z-index':'1002',position:"absolute",top:top,left:left});
      
   }
   
   function ElementFullScreen(div) {
      var width = (document.documentElement.offsetWidth + document.documentElement.clientWidth) + document.documentElement.scrollLeft;
      var height = (document.documentElement.offsetHeight) + document.documentElement.scrollTop;
      if (div == null) div = 'idFullScreen';
      jQuery('#'+div).css({display:"block",'z-index':'1001',position:"absolute",top:0,left:0,width:width,height:height, "opacity":0.8});
   }
   
   function limpar(){
		//alert(1);
		jQuery('input[type=text]').val('');
	}


var arrQtdeDiasMeses=new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);var arrDatasPSA=new Array();function fcnAdicionar(){objForm=document.frDataPSA;objDia=objForm.txtDia;objMes=objForm.txtMes;objAno=objForm.txtAno;objPSA=objForm.txtPSA;bCampoVazio=false;if(objPSA.value==''||!objPSA.value.match(/^[0-9\.,]*$/)){fcnChangeClassName('PSA','adv');bCampoVazio=true;var objFocus=objPSA}else{fcnChangeClassName('PSA','')}if(objAno.value==''||!objAno.value.match(/^[0-9]{4}$/)){fcnChangeClassName('Ano','adv');bCampoVazio=true;var objFocus=objAno}else{fcnChangeClassName('Ano','')}if(objMes.value==''||!objMes.value.match(/^[0-9]*$/)||Math.ceil(objMes.value)<1||Math.ceil(objMes.value)>12){fcnChangeClassName('Mes','adv');bCampoVazio=true;var objFocus=objMes}else{fcnChangeClassName('Mes','')}if(objDia.value==''||!objDia.value.match(/^[0-9]*$/)){fcnChangeClassName('Dia','adv');bCampoVazio=true;var objFocus=objDia}else{if(objFocus!=objMes&&objFocus!=objAno){if(Math.ceil(objMes.value)==2)if(Math.ceil(objAno.value)%400==0||(Math.ceil(objAno.value)%4==0&&Math.ceil(objAno.value)%100!=0))arrQtdeDiasMeses[Math.ceil(objMes.value)]=29;else arrQtdeDiasMeses[Math.ceil(objMes.value)]=28;if(Math.ceil(objDia.value)<0||Math.ceil(objDia.value)>arrQtdeDiasMeses[Math.ceil(objMes.value)]){fcnChangeClassName('Dia','adv');bCampoVazio=true;var objFocus=objDia}else fcnChangeClassName('Dia','')}else fcnChangeClassName('Dia','')}if(!bCampoVazio){strDia=objDia.value.length==1?'0'+objDia.value:objDia.value;strMes=objMes.value.length==1?'0'+objMes.value:objMes.value;strAno=objAno.value;strData=strDia+'/'+strMes+'/'+strAno;strPSA=objPSA.value.replace(',','.');strPSA=strPSA.substring(strPSA.length-1,strPSA.length)=='.'?strPSA+'0':strPSA;strPSA=strPSA.substring(0,1)=='.'?'0'+strPSA:strPSA;strPSA=strPSA.match(/\./)?strPSA:strPSA+'.0';if(arrDatasPSA.length){for(var i=0;i<arrDatasPSA.length;i++){if(Date.ConvertToYear(strData)==Date.ConvertToYear(arrDatasPSA[i][0])&&parseFloat(strPSA)==0){alert(stringsPSA.s1);return}else if(Date.ConvertToYear(strData)==Date.ConvertToYear(arrDatasPSA[i][0])&&parseFloat(strPSA)!=0){alert(stringsPSA.s2);return}else if(Date.ConvertToYear(strData)!=Date.ConvertToYear(arrDatasPSA[i][0])&&parseFloat(strPSA)==0){alert(stringsPSA.s3);return}}}else{if(parseFloat(strPSA)==0){alert(stringsPSA.s3);return}}inLinha=arrDatasPSA.length;arrDatasPSA[inLinha]=new Array(1);arrDatasPSA[inLinha][0]=strData;arrDatasPSA[inLinha][1]=strPSA;for(var i=0;i<arrDatasPSA.length;i++){for(j=i+1;j<arrDatasPSA.length;j++){if(Date.ConvertToYear(arrDatasPSA[i][0])>Date.ConvertToYear(arrDatasPSA[j][0])){xData=arrDatasPSA[i][0];arrDatasPSA[i][0]=arrDatasPSA[j][0];arrDatasPSA[j][0]=xData;xPSA=arrDatasPSA[i][1];arrDatasPSA[i][1]=arrDatasPSA[j][1];arrDatasPSA[j][1]=xPSA}else if((Date.ConvertToYear(arrDatasPSA[i][0])==Date.ConvertToYear(arrDatasPSA[j][0]))&&arrDatasPSA[i][1]>arrDatasPSA[j][1]){xPSA=arrDatasPSA[i][1];arrDatasPSA[i][1]=arrDatasPSA[j][1];arrDatasPSA[j][1]=xPSA}}}objSelDatas=objForm.slcListaDatas;var opts=objSelDatas.options;for(var i=opts.length-1;i>=0;i--){objSelDatas.removeChild(opts[i])}for(var i=0;i<arrDatasPSA.length;i++){var objOption=document.createElement('option');objOption.innerHTML=arrDatasPSA[i][0]+' | PSA: '+arrDatasPSA[i][1].replace('.',',');objSelDatas.appendChild(objOption)}objDia.value=objMes.value=objAno.value=objPSA.value='';objDia.focus()}else objFocus.focus()}Date.ConvertToYear=function(strData){arrData=strData.split('/');strData=arrData[1]+'/'+arrData[0]+'/'+arrData[2];var minutos=1000*60;var horas=minutos*60;var dias=horas*24;var anos=dias*365;intQtdeAnos=Date.parse(strData)/anos;return intQtdeAnos};Date.ConvertToDay=function(strData){arrData=strData.split('/');strData=arrData[2]+'/'+arrData[1]+'/'+arrData[0];intQtdeDias=Date.parse(strData)/(1000*60*60*24);return intQtdeDias};function fcnChangeClassName(id,className){if(id!=null&&className!=null&&document.getElementById(id)!=null)document.getElementById(id).className=className}function fcnValidaData(obj){objForm=document.frDataPSA;var texto=new String();if(obj.value.length==4){var char123=obj.value.substring(0,3);var char4=obj.value.substring(3,4);if(!char4.match(/[0-9]/))char4='';texto=char123+char4}else if(obj.value.length==3){var char12=obj.value.substring(0,2);var char3=obj.value.substring(2,3);if(!char3.match(/[0-9]/))char3='';texto=char12+char3}else if(obj.value.length==2){var char1=obj.value.substring(0,1);var char2=obj.value.substring(1,2);if(!char2.match(/[0-9]/))char2='';texto=char1+char2;if(texto.length==2){}}else{var char1=obj.value;if(char1.match(/[0-9]/))texto=char1}obj.value=texto}function fcnValidaPSA(obj){var texto=new String();if(obj.value.length==1){var char1=obj.value;if(char1=='.')char1=',';if(char1.match(/^[0-9,]$/))texto=char1}else{var char1=obj.value.substring(0,obj.value.length-1);var char2=obj.value.substring(obj.value.length-1,obj.value.length);if(char2=='.')char2=',';if(char1.match(/[\.,]/)&&char2==',')char2='';else if(!char2.match(/^[0-9,]$/))char2='';texto=char1+char2}obj.value=texto}function fcnRemover(){objForm=document.frDataPSA;objDia=objForm.txtDia;objSelDatas=objForm.slcListaDatas;var opts=objSelDatas.options;if(opts.length>0){arrDatasPSA.splice(objSelDatas.selectedIndex,1);objSelDatas.removeChild(opts[objSelDatas.selectedIndex])}objDia.focus()}function fcnLimpar(){objForm=document.frDataPSA;objDia=objForm.txtDia;objSelDatas=objForm.slcListaDatas;var opts=objSelDatas.options;for(var i=opts.length-1;i>=0;i--){objSelDatas.removeChild(opts[i])}arrDatasPSA.splice(0,arrDatasPSA.length);fcnLimparTextos();objDia.focus()}function fcnCalcular(){var intQtdeDias=0;var SomaPSA=0;var SomaLNPSA=0;var intQtdeDatas=arrDatasPSA.length;if(intQtdeDatas>1){fcnLimparTextos();for(var i=0;i<intQtdeDatas;i++){var Data1=arrDatasPSA[i][0];var Data2=arrDatasPSA[0][0];var PSA=parseFloat(arrDatasPSA[i][1]);intQtdeDias+=Date.ConvertToDay(Data1)-Date.ConvertToDay(Data2);SomaPSA+=PSA;SomaLNPSA+=Math.log(PSA)}var Xm=intQtdeDias/(30.4375*intQtdeDatas);var Ym=SomaPSA/intQtdeDatas;var Zm=SomaLNPSA/intQtdeDatas;var Numerador=0;var NumeradorInclinacaoCurva=0;var VelocidadePSA=0;var InclinacaoCurva=0;var strNumeradorInclinacaoCurva=new String();var objVelocidadePSA=document.createElement('span');var objInclinacaoCurva=document.createElement('span');for(var i=0;i<intQtdeDatas;i++){var Data1=arrDatasPSA[i][0];var Data2=arrDatasPSA[0][0];var PSA=parseFloat(arrDatasPSA[i][1]);var X=(Date.ConvertToDay(Data1)-Date.ConvertToDay(Data2))/30.4375;var Y=PSA;var Z=Math.log(PSA);Numerador+=((X-Xm)*(Y-Ym));NumeradorInclinacaoCurva+=((X-Xm)*(Z-Zm));VelocidadePSA+=(X-Xm)*(X-Xm);InclinacaoCurva+=(X-Xm)*(X-Xm)}VelocidadePSA=Numerador/VelocidadePSA;InclinacaoCurva=NumeradorInclinacaoCurva/InclinacaoCurva;var TempoDuplicacao=0.693147181/InclinacaoCurva;document.getElementById('psaTempoDupM').innerHTML='<strong>'+fcnCasasDecimais(TempoDuplicacao,2)+'</strong> ';document.getElementById('psaTempoDupM').innerHTML+=TempoDuplicacao>-1.9&&TempoDuplicacao<1.9?stringsPSA.s4:stringsPSA.s5;document.getElementById('psaVelM').innerHTML='<strong>'+fcnCasasDecimais(VelocidadePSA,2)+'</strong> '+stringsPSA.s6;document.getElementById('psaTempoDupA').innerHTML='<strong>'+fcnCasasDecimais(TempoDuplicacao/12,2)+'</strong> ';document.getElementById('psaTempoDupA').innerHTML+=TempoDuplicacao/12>-1.9&&TempoDuplicacao/12<1.9?stringsPSA.s7:stringsPSA.s8;document.getElementById('psaVelA').innerHTML='<strong>'+fcnCasasDecimais(VelocidadePSA*12,2)+'</strong> '+stringsPSA.s9}else{alert(stringsPSA.s10)}}function fcnCasasDecimais(numero,casas){var posDecimal=String(numero).indexOf('.');if(parseInt(String(numero).substring(posDecimal+casas,posDecimal+casas+1))>=5)numero+=0.01;var resultado=new String(posDecimal>-1?parseFloat(String(numero).substring(0,posDecimal+1+casas)):numero);return resultado.replace(/\./,',')}function fcnLimparTextos(){document.getElementById('psaTempoDupM').innerHTML='';document.getElementById('psaVelM').innerHTML='';document.getElementById('psaTempoDupA').innerHTML='';document.getElementById('psaVelA').innerHTML=''}function instrucoes(){col02.style.height=col02.firstChild.style.height='auto';var instrucoes=document.getElementById('instrucoes');var tabela_instrucoes=document.getElementById('tabela_instrucoes');instrucoes.className=tabela_instrucoes.className=instrucoes.className=='visivel'?'':'visivel'}
