 //controla a fila de carregamento das solicitações
//Tenta criar o objeto xmlHTTP
try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}

//Fila de conexões
fila=[]
ifila=0

//Carrega via XMLHTTP a url recebida e coloca seu valor
//no objeto com o id recebido

function ajaxHTML(id,url){//sem o carregando
    //Carregando...
    //document.getElementById(id).innerHTML=""
    //Adiciona à fila
    fila[fila.length]=[id,url]
    //Se não há conexões pendentes, executa
    if((ifila+1)==fila.length)ajaxRun()
}
function ajaxHTMLon(id,url){//sem o carregando
    //Carregando...
    document.getElementById(id).innerHTML="<div align='center'></br></br>Carregando...</div>"
    //Adiciona à fila
    fila[fila.length]=[id,url]
    //Se não há conexões pendentes, executa
    if((ifila+1)==fila.length)ajaxRun()
}

//Executa a próxima conexão da fila
function ajaxRun(){
    //Abre a conexão
    xmlhttp.open("GET",fila[ifila][1],true);
    //Função para tratamento do retorno
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            //Mostra o HTML recebido
            retorno=unescape(xmlhttp.responseText.replace(/\+/g," "))
            document.getElementById(fila[ifila][0]).innerHTML=retorno
            //Roda o próximo
            ifila++
            if(ifila<fila.length)setTimeout("ajaxRun()",20)
        }
    }
    //Executa
    xmlhttp.send(null)
}

//fim do controle de carregamento
 
 
 
 
 function validaCNPJ() {
                CNPJ = document.getElementById('CNPJID').value;
                erro = new String;
				
				if (CNPJ.length == 0) return true;		
                 if (CNPJ.length < 18) erro = "CNPJ invalido! \n\n";
                 if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
                 if (erro.length == 0) erro = "CNPJ invalido! \n\n";
                }
                 //substituir os caracteres que não são números
               if(document.layers && parseInt(navigator.appVersion) == 4){
                       x = CNPJ.substring(0,2);
                       x += CNPJ. substring (3,6);
                       x += CNPJ. substring (7,10);
                       x += CNPJ. substring (11,15);
                       x += CNPJ. substring (16,18);
                       CNPJ = x;
               } else {
                       CNPJ = CNPJ. replace (".","");
                       CNPJ = CNPJ. replace (".","");
                       CNPJ = CNPJ. replace ("-","");
                       CNPJ = CNPJ. replace ("/","");
               }
               var nonNumbers = /\D/;
               if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n\n";
               var a = [];
               var b = new Number;
               var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
              for (i=0; i<12; i++){
                       a[i] = CNPJ.charAt(i);
                       b += a[i] * c[i+1];
 }
               if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
               b = 0;
               for (y=0; y<13; y++) {
                       b += (a[y] * c[y]);
               }
               if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
               if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
                       erro ="CNPJ invalido!!";
               }
               if (erro.length > 0){
                       alert(erro);
					   document.getElementById('CNPJID').value='';
                       return false;
               } else {
                       seila=2;
               }
           return true;
   }
   
  function alfanumerico(objForm, strField, sMask, evtKeyPress) {
      var i, nTecla;

      if(document.all) { // Internet Explorer
        nTecla = evtKeyPress.keyCode;
		 }
      else if(document.layers) { // Nestcape
        nTecla = evtKeyPress.which;
		
      }
	     if (sMask.charAt(i-1) == "a") { // apenas letras...
          return ((nTecla > 64) && (nTecla < 91) || (nTecla > 96) && (nTecla < 123) || (nTecla > 31) && (nTecla < 33)); }
		 if (sMask.charAt(i-1) == "0") { // alfanumerico ...
          return ((nTecla > 64) && (nTecla < 91) || (nTecla > 96) && (nTecla < 123)  || (nTecla > 31) && (nTecla < 33) || (nTecla > 47) && (nTecla < 58) || (nTecla > 43) &&  (nTecla < 47)); }
		 if (sMask.charAt(i-1) == "1") { // numeros e , e . e -...
          return ((nTecla > 47) && (nTecla < 58) || (nTecla > 43) &&  (nTecla < 47)); }
		  if (sMask.charAt(i-1) == "9") { // numeros ...
          return ((nTecla > 47) && (nTecla < 58)); }
		  	else { // qualquer caracter...
          		return true;
        } 
     
    }
	
	
	

//mascara numeros
function txtBoxFormat( strField, sMask, evtKeyPress) {
      var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

      if(document.all) { // Internet Explorer
        nTecla = evtKeyPress.keyCode; }
      else if(document.layers) { // Nestcape
        nTecla = evtKeyPress.which;
      }

      sValue = document.getElementById(strField).value;

      // Limpa todos os caracteres de formatação que
      // já estiverem no campo.
      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( ".", "" );
      sValue = sValue.toString().replace( ".", "" );
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( " ", "" );
      sValue = sValue.toString().replace( " ", "" );
      fldLen = sValue.length;
      mskLen = sMask.length;

      i = 0;
      nCount = 0;
      sCod = "";
      mskLen = fldLen;

      while (i <= mskLen) {
        bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
        bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

        if (bolMask) {
          sCod += sMask.charAt(i);
          mskLen++; }
        else {
          sCod += sValue.charAt(nCount);
          nCount++;
        }

        i++;
      }

      document.getElementById(strField).value = sCod;

      if (nTecla != 8) { // backspace
        if (sMask.charAt(i-1) == "9") { // apenas números...
          return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
        else { // qualquer caracter...
          return true;
        } }
      else {
        return true;
      }
    }

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function LiberaMotivo(){
	
	if ( document.getElementById('status_licitacao').value=='Encerrado [Negativo]'){
		//document.getElementById('motivo').disabled=false;
		ajaxHTML('mostramotivo','licitacao_motivo_opcoes.htm');
		}else{
			//document.getElementById('motivo').disabled=true;
			ajaxHTML('mostramotivo','licitacao_motivo_opcoes_clean.htm');
			}
	
	}
	
function MostraLicitacao(){
	
	
	if ( document.getElementById('status').value=='6'){
		ajaxHTML('mostralicitacao','licitacao_opcoes.htm');
		}else{
			ajaxHTML('mostralicitacao','licitacao_opcoes_clean.htm');
			}
	
	}


function VaiPara(link){
					this.window.location.href=link;
					return false;
				}
				
function GeraRelatorioCliente(){
	MM_openBrWindow('index.php?secao=relatorios&status='+document.getElementById('pesquisa_status').value+'&regiao='+document.getElementById('regiao').value+'&lista='+document.getElementById('lista').value+'&nome='+document.getElementById('nome_busca').value+'&razaosocial='+document.getElementById('razaosocial_busca').value+'&cnpj='+document.getElementById('cnpj').value,'','scrollbars=yes,resizable=yes,width=550,height=450')
	
	}
	
	
//assistencia tecnica

function BuscaMapa(uf){
	
		ajaxHTMLon('mapas','index_internas.php?secao='+uf);
		
	}
	
function MostraFalencia(id){
		var id;
		ajaxHTMLon('falencias','index_internas.php?secao=falenciasdet&id_falencia='+id);
		
	}
function BuscaEmail(id){
		var id;
		ajaxHTMLon('listaemails','index_internas.php?secao=emailslista&id_filial='+id);
		
	}
function BuscaFilial(id){
		var id;
		ajaxHTMLon('listafilial','index_internas.php?secao=filiallista&id_filial='+id);
		
	}
function BuscaMapaFilial(id){
		var id;
		ajaxHTMLon('listafilial','index_internas.php?secao=filiallistamapa&id_filial='+id);
		
	}
	

function Carrega(pagina){
		var pagina;
		ajaxHTMLon('conteudo','index_internas.php?secao='+pagina);
		
	}
	
	
function PerfilPro(pagina){
		var pagina;
		ajaxHTMLon('conteudo','index_internas.php?secao=perfil&modulo=&pagina='+pagina);
		
	}
	
function BuscaNoticia(){
		
		ajaxHTMLon('conteudo','index_internas.php?secao=pgNoticias&modulo=buscanoticia&buscanoticia='+document.getElementById('buscanoticia').value);
		
	}
function BuscaTodasNoticias(){
		
		ajaxHTMLon('conteudo','index_internas.php?secao=pgNoticias&modulo=todas');
		
	}
	
function BuscaNoticiaId(id){
		var id;
		ajaxHTMLon('conteudo','index_internas.php?secao=pgNoticias&id_noticia='+id);
		
	}	


function CadastraNews(){
	
	if ( document.getElementById('email').value=='' || document.getElementById('nome').value==''){
		alert('O campo NOME e E-MAIL são de preenchimento obrigatório! ');
		}else{
			MM_openBrWindow('acao.php?modulo=cadastrarnews&nome='+document.getElementById('nome').value+'&email='+document.getElementById('email').value,'','width=300,height=120')
			}
	
	}

function EnviaFormulario(){
	
	if ( document.getElementById('formemail').value=='' || document.getElementById('formnome').value==''){
		alert('O campo NOME e E-MAIL são de preenchimento obrigatório! ');
		}else{
			ajaxHTMLon('confirmaenvio','index_internas.php?secao=faleconoscoenviar&nome='+document.getElementById('formnome').value+'&email='+document.getElementById('formemail').value+'&comentario='+document.getElementById('formcomentario').value+'&endereco='+document.getElementById('formendereco').value+'&cidade='+document.getElementById('formcidade').value+'&uf='+document.getElementById('formuf').value);
			document.getElementById('formemail').value='' ;
			document.getElementById('formnome').value='' ;
			document.getElementById('formcomentario').value='' ;
			document.getElementById('formendereco').value='' ;
			document.getElementById('formcidade').value='' ;
			document.getElementById('formuf').value='' ;
			}
	
	}
	function Limpa(){
	
	document.getElementById('formemail').value='' ;
	document.getElementById('formnome').value='' ;
	document.getElementById('formcomentario').value='' ;
	document.getElementById('formendereco').value='' ;
			document.getElementById('formcidade').value='' ;
			document.getElementById('formuf').value='' ;
	
	}
	
function LimpaForense(){
	
	document.getElementById('formnumero').value='' ;
	document.getElementById('formpartes').value='' ;
	document.getElementById('formcomarca').value='' ;
	document.getElementById('formprazo').value='' ;
	document.getElementById('formservico').value='' ;
	document.getElementById('formcontato').value='' ;
			
	
	}
function EnviaForense(){
	
	
			ajaxHTMLon('confirmaenvio','index_internas.php?secao=forenseenviar&numero='+document.getElementById('formnumero').value+'&partes='+document.getElementById('formpartes').value+'&comarca='+document.getElementById('formcomarca').value+'&prazo='+document.getElementById('formprazo').value+'&servico='+document.getElementById('formservico').value+'&contato='+document.getElementById('formcontato').value);
			document.getElementById('formnumero').value='' ;
	document.getElementById('formpartes').value='' ;
	document.getElementById('formcomarca').value='' ;
	document.getElementById('formprazo').value='' ;
	document.getElementById('formservico').value='' ;
	document.getElementById('formcontato').value='' ;
		
	
	}
	
function EnviaCurriculo(){
	
	if ( document.getElementById('fnome').value=='' || document.getElementById('femail').value==''){
		alert('O campo NOME e E-MAIL são de preenchimento obrigatório! ');
		}else{
			document.form.submit();
			}
	
	}


function EnviaEnter(evtKeyPress){
	
	if(document.all) { // Internet Explorer
        nTecla = evtKeyPress.keyCode; }
      else if(document.layers) { // Nestcape
        nTecla = evtKeyPress.which;
      }
	if(nTecla == 13){
	
		ajaxHTMLon('assistecnica','templates/index.php?secao=assistecnica&nome='+document.getElementById('nome').value+'&cidade='+document.getElementById('cidade').value+'&uf='+document.getElementById('uf').value+'&regiao='+document.getElementById('regiao').value);
	}
	
	}

function buscaMapa(mapa){

	document.getElementById('mapa').innerHTML="<img src='images/fundos/"+mapa+".jpg' width='340' height='355' />";

	}