 //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>carrengando ...</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 validacpf () {
if (checaCPF(document.getElementById('CPF').value)) {

}
else {
errors="1";
if (errors) alert('O CPF digitado é inválido!');
document.MM_returnValue = (errors == '');
document.getElementById('CPF').value="";
}
}

function checaCPF (CPF) {
	
if (CPF.length == 0) return true;	
if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
CPF == "88888888888" || CPF == "99999999999")
return false;
soma = 0;
for (i=0; i < 9; i ++)
soma += parseInt(CPF.charAt(i)) * (10 - i);
resto = 11 - (soma % 11);
if (resto == 10 || resto == 11)
resto = 0;
if (resto != parseInt(CPF.charAt(9)))
return false;
soma = 0;
for (i = 0; i < 10; i ++)
soma += parseInt(CPF.charAt(i)) * (11 - i);
resto = 11 - (soma % 11);
if (resto == 10 || resto == 11)
resto = 0;
if (resto != parseInt(CPF.charAt(10)))
return false;

return true;
}



 
	

/***
* Descriçao.: formata um campo do formulário de
* acordo com a máscara informada...
* Parâmetros: - objForm (o Objeto Form)
* - strField (string contendo o nome
* do textbox)
* - sMask (mascara que define o
* formato que o dado será apresentado,
* usando o algarismo "9" para
* definir números e o símbolo "!" para
* qualquer caracter...
* - evtKeyPress (evento)
* Uso.......: <input type="textbox"
* name="xxx".....
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);">
* Observaçao: As máscaras podem ser representadas como os exemplos abaixo:
* CEP -> 99.999-999
* CPF -> 999.999.999-99
* CNPJ -> 99.999.999/9999-99
* Data -> 99/99/9999
* Tel Resid -> (99) 999-9999
* Tel Cel -> (99) 9999-9999
* Processo -> 99.999999999/999-99
* C/C -> 999999-!
* E por aí vai...
***/

function txtBoxFormat(objForm, 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;
} else if(document.getElementById) { // FireFox
nTecla = evtKeyPress.which;
}

sValue = objForm[strField].value;

// Limpa todos os caracteres de formataçao 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++;
}

objForm[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;
}
}
//Fim da Funçao Máscaras Gerais


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function CarregaMapa(id){
	
	
		ajaxHTML('mapaCarrega','templates/internas/mapa'+id+'.htm');
		
	
	}


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 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=noticias&modulo=buscanoticia&buscanoticia='+document.getElementById('buscanoticia').value);
		
	}
function BuscaTodasNoticias(){
		
		ajaxHTMLon('conteudo','index_internas.php?secao=noticias&modulo=todas');
		
	}
	
function BuscaNoticiaId(id){
		var id;
		ajaxHTMLon('conteudo','index_internas.php?secao=noticias&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 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);
	}
	
	}
