var xmlHttp;
var NumeroCampo;
var NumeroCampo2;
var Lote;
var Iten;
var http_inicial = "http://www.cabedal.net/"
function MandaID(str,valor,numero){
	NumeroCampo = numero;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Este browser não suporta HTTP Request");
		return;
	}
	// Cidade
	if (valor == 1 ){
		var url=http_inicial+"seleciona_ajax.asp";
		url=url+"?sigla="+str;
		url=url+"&status=1";
		url=url+"&num="+NumeroCampo;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_Cid;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	// Gera as Naturezas Juridicas 
	if (valor == 2){
		var url=http_inicial+"seleciona_ajax.asp";
		url=url+"?RA="+str;
		url=url+"&status=2";
		url=url+"&num="+NumeroCampo;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_NJ;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
	// Gera as secoes 
	if (valor == 3){
		var url=http_inicial+"seleciona_ajax.asp";
		url=url+"?NJ="+str;
		url=url+"&status=3";
		url=url+"&num="+NumeroCampo;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_exibe_AT_Econ_Secao;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
	// Gera as Divisores 
	if (valor == 4){
		var url=http_inicial+"seleciona_ajax.asp";
		url=url+"?cod_secao="+str;
		url=url+"&status=4";
		url=url+"&num="+NumeroCampo;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_exibe_AT_Econ_Divisao;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
	// Gera os Grupos
	if (valor == 5){
		var url=http_inicial+"seleciona_ajax.asp";
		url=url+"?cod_divisao="+str;
		url=url+"&status=5";
		url=url+"&num="+NumeroCampo;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_exibe_AT_Econ_Grupo;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
	// Gera as Classes 
	if (valor == 6){
		var url=http_inicial+"seleciona_ajax.asp";
		url=url+"?cod_grupo="+str;
		url=url+"&status=6";
		url=url+"&num="+NumeroCampo;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_exibe_AT_Econ_Classe;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
	// Gera as Sub Classes
	if (valor == 7){
		var url=http_inicial+"seleciona_ajax.asp";
		url=url+"?cod_classe="+str;
		url=url+"&status=7";
		url=url+"&num="+NumeroCampo;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_exibe_AT_Econ_SubClasse;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
	// Verifica se Tem alguem com o CPF já cadastrado
	if (valor == 8){
		if (document.getElementById("cpf")){
			var email = document.getElementById("cpf").value;
			if (email == str){
				document.getElementById('C_CPF').className = '';
				document.getElementById('alerta_cpf').className = '';
				document.getElementById("alerta_cpf").innerHTML = '';
				if (document.getElementById('status_cpf')){
					document.getElementById('status_cpf').value = 0;
				}
				return;
			}
		}		
		var url=http_inicial+"verifica_ajax.asp";
		url=url+"?cpf="+str;
		url=url+"&status=1";
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_cpf;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	// Verifica se tem alguem como o CNPJ já cadastrado
	if (valor == 9){
		if (document.getElementById("cnpj")){
			var email = document.getElementById("cnpj").value;
			if (email == str){
				document.getElementById('C_CNPJ').className = '';
				document.getElementById('alerta_cnpj').className = '';
				document.getElementById("alerta_cnpj").innerHTML = '';
				if (document.getElementById('status_cnpj')){
					document.getElementById('status_cnpj').value = 0;
				}
				return;
			}
		}
		var url=http_inicial+"verifica_ajax.asp";
		url=url+"?cnpj="+str;
		url=url+"&status=2";
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_cnpj;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	// Verifica se tem alguem como o Login já cadastrado
	if (valor == 10){
		if (document.getElementById("login")){
			var login = document.getElementById("login").value;
			if (login == str){
				document.getElementById('C_LOGIN').className = '';
				document.getElementById('alerta_login').className = '';
				document.getElementById("alerta_login").innerHTML = '';
				if (document.getElementById('status_login')){
					document.getElementById('status_login').value = 0;
				}
				return;
			}
		}
		var url=http_inicial+"verifica_ajax.asp";
		url=url+"?login="+str;
		url=url+"&status=3";
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_login;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	// Verifica se tem alguem como o Email já cadastrado
	if (valor == 11){
		if (document.getElementById("email")){
			var email = document.getElementById("email").value;
			if (email == str){
				document.getElementById('C_EMAIL').className = '';
				document.getElementById('alerta_email').className = '';
				document.getElementById("alerta_email").innerHTML = '';
				if (document.getElementById('status_email')){
					document.getElementById('status_email').value = 0;
				}
				return;
			}
		}
		var url=http_inicial+"verifica_ajax.asp";
		url=url+"?email="+str;
		url=url+"&status=4";
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_email;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	// Pega o código do tipo do bem e gera a classificação
	if (valor == 12){
		var url=http_inicial+"verifica_ajax.asp";
		url=url+"?cod_tipo="+str;
		url=url+"&status=5";
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_tipo;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	// Pega o código do cnae para verificar se o mesmo existe e retornar o nome do cnae
	if (valor == 13){
		var url=http_inicial+"verifica_ajax.asp";
		url=url+"?cnae="+str;
		url=url+"&status=6";
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_cnae;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	// Verifica se tem alguem como o CNPJ já cadastrado
	if (valor == 14){
		var url=http_inicial+"verifica_ajax.asp";
		url=url+"?cnpj="+str;
		url=url+"&status=8";
		xmlHttp.onreadystatechange=stateChanged_cnpj;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}


function VerificaRA(cod_ra,cnae,numero){
	NumeroCampo2 = numero;
	xmlHttp2=GetXmlHttpObject();
	if (xmlHttp2==null){
		alert ("Este browser não suporta HTTP Request");
		return;
	}
	// Pega o código do ramo de atividade junto com cnae para verificar se o mesmo está de acordo com o ramo escolhido
	var url1=http_inicial+"verifica_ajax.asp";
	url1=url1+"?cnae="+cnae;
	url1=url1+"&cod_ra="+cod_ra;
	url1=url1+"&status=7";
	url1=url1+"&sid="+Math.random();
	xmlHttp2.onreadystatechange=stateChanged_cnae_ra;
	xmlHttp2.open("GET",url1,true);
	xmlHttp2.send(null);
}

function stateChanged_cnae_ra(){
	var retorno2;
	if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete"){
		retorno2=xmlHttp2.responseText;
		if ( retorno2 == "True"){
			document.getElementById('result_cnae_'+NumeroCampo2).className = '';
			document.getElementById('result_cnae_'+NumeroCampo2).className = '';
			document.getElementById('result_cnae_'+NumeroCampo2).innerHTML = 'Atividade Incompatível ou Cnae Inválido';
			if (document.getElementById('status_cnae'+NumeroCampo2)){
				document.getElementById('status_cnae'+NumeroCampo2).value = 1;
			}
		}else{
			document.getElementById('result_cnae_'+NumeroCampo2).className = '';
			document.getElementById('result_cnae_'+NumeroCampo2).className = '';
			document.getElementById('result_cnae_'+NumeroCampo2).innerHTML = retorno2;
		}			
	}
}

// funcao para gerar a lista de atividade de um produto
function BuscaLista(){
	xmlHttp3=GetXmlHttpObject();
	if (xmlHttp3==null){
		alert ("Este browser não suporta HTTP Request");
		return;
	}
		
	produtos = ramo = NG_ID = "";
	if (document.getElementById("produtos")){
		produtos= document.getElementById("produtos").value;
	}
		
	if (document.getElementById("ramo")){
		NG_ID = document.getElementById("ramo").value;
	}
	if (document.getElementById("NG_ID")){
		NG_ID = document.getElementById("NG_ID").value;
	}
	//else{
		//produto2 = ""
	//}
	// Pega o produto digitado e gera uma lista de atividades pertinentes aquele produtos
	var url2=http_inicial+"gerar_lista_atividade.asp";
	url2=url2+"?produtos="+produtos;
	url2=url2+"&ramo="+ramo;
	url2=url2+"&ng_id="+NG_ID;
	xmlHttp3.onreadystatechange=stateChanged_produto;
	xmlHttp3.open("GET",url2,true);
	xmlHttp3.send(null);
}

function stateChanged_produto(){
	if (xmlHttp3.readyState==4 || xmlHttp3.readyState=="complete"){
		document.getElementById("exibe_lista").innerHTML=xmlHttp3.responseText;
	}
}

// funcao que gera um lista de produtos que estao sendo pesquisados
function BuscaBem(){
	xmlHttp4=GetXmlHttpObject();
	if (xmlHttp4==null){
		alert ("Este browser não suporta HTTP Request");
		return;
	}
		
	nome = document.getElementById("B_nome").value;
	marca = document.getElementById("B_Marca").value;	
	//Objeto = document.getElementById("OBJ_Descricao").value;
	
	if (nome.length < 3){
		alert("Nome do produto deve conter no mínimo 3 caracteres.");
		return;
	}
	
	// Pega o produto,marca e objeto e gera um lista
	var url3=http_inicial+"busca.asp";
	url3=url3+"?nome="+nome;
	url3=url3+"&marca="+marca;
	//url3=url3+"&obj="+Objeto
	url3=url3+"&tipo=1";
	xmlHttp4.onreadystatechange=stateChanged_busca;
	xmlHttp4.open("GET",url3,true);
	xmlHttp4.send(null);
}

function stateChanged_busca(){
	if (xmlHttp4.readyState==4 || xmlHttp4.readyState=="complete"){
		document.getElementById("exibe_resultado").innerHTML=xmlHttp4.responseText;
	}
}


function stateChanged_Cid(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("AAT_Cidade_"+NumeroCampo).innerHTML=xmlHttp.responseText;
	}
}

function stateChanged_NJ(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("exibe_NJ_"+NumeroCampo).innerHTML=xmlHttp.responseText;
	}
}

function stateChanged_exibe_AT_Econ_Secao(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("exibe_AT_Econ_Secao_"+NumeroCampo).innerHTML=xmlHttp.responseText;
	}
}

function stateChanged_exibe_AT_Econ_Divisao(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("exibe_AT_Econ_Divisao_"+NumeroCampo).innerHTML=xmlHttp.responseText;
	}
}

function stateChanged_exibe_AT_Econ_Grupo(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("exibe_AT_Econ_Grupo_"+NumeroCampo).innerHTML=xmlHttp.responseText;
	}
}

function stateChanged_exibe_AT_Econ_Classe(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("exibe_AT_Econ_Classe_"+NumeroCampo).innerHTML=xmlHttp.responseText;
	}
}

function stateChanged_exibe_AT_Econ_SubClasse(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("exibe_AT_Econ_SubClasse_"+NumeroCampo).innerHTML=xmlHttp.responseText;
	}
}


function stateChanged_login(){
	var retorno;
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		retorno=xmlHttp.responseText;
		if ( retorno == "True"){
			if (document.getElementById('status_login')){
				document.getElementById('status_login').value = 1;
			}
			document.getElementById('C_LOGIN').className = 'erro';
			document.getElementById('alerta_login').className = 'errotexto';
			document.getElementById('alerta_login').innerHTML = 'Usuário Inválido.';
		}else{
			if (document.getElementById('status_login')){
				document.getElementById('status_login').value = 0;
			}
			document.getElementById('C_LOGIN').className = '';
			document.getElementById('alerta_login').className = 'textovalido';
			document.getElementById('alerta_login').innerHTML = 'Usuário Válido. Memorize';
		}			
	}
}

function stateChanged_email(){
	var retorno;
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		retorno=xmlHttp.responseText;
		if ( retorno == "True"){
			if (document.getElementById('status_email')){
				document.getElementById('status_email').value = 1;
			}
			document.getElementById('C_EMAIL').className = 'erro';
			document.getElementById('alerta_email').className = 'errotexto';
			document.getElementById('alerta_email').innerHTML = 'Email já Cadastrado.';
			
		}else{
			if (document.getElementById('status_email')){
				document.getElementById('status_email').value = 0;
			}
			document.getElementById('C_EMAIL').className = '';
			document.getElementById('alerta_email').className = '';
			document.getElementById("alerta_email").innerHTML = '';
		}			
	}
}

function stateChanged_cpf(){
	var teste;
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		teste=xmlHttp.responseText;
		if ( teste == "True"){
			if (document.getElementById('status_cpf')){
				document.getElementById('status_cpf').value = 1;
			}
			document.getElementById('C_CPF').className = 'erro';
			document.getElementById('alerta_cpf').className = 'errotexto';
			document.getElementById('alerta_cpf').innerHTML = 'CPF já Cadastrado';
		}else{
			if (document.getElementById('status_cpf')){
				document.getElementById('status_cpf').value = 0;
			}
			document.getElementById('C_CPF').className = '';
			document.getElementById('alerta_cpf').className = '';
			document.getElementById('alerta_cpf').innerHTML = '';
		}			
	}
}

function stateChanged_cnpj(){
	var teste;
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		teste=xmlHttp.responseText;
		if ( teste == "True"){
			if (document.getElementById('status_cnpj')){
				document.getElementById('status_cnpj').value = 1;
			}
			document.getElementById('C_CNPJ').className = 'erro';
			document.getElementById('alerta_cnpj').className = 'errotexto';
			document.getElementById('alerta_cnpj').innerHTML = 'CNPJ já Cadastrado';
		}else{
			if (document.getElementById('status_cnpj')){
				document.getElementById('status_cnpj').value = 0;
			}
			document.getElementById('C_CNPJ').className = '';
			document.getElementById('alerta_cnpj').className = '';
			document.getElementById('alerta_cnpj').innerHTML = '';
		}			
	}
}

function stateChanged_tipo(){
	var retorno;
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		var retorno = xmlHttp.responseText, i, codigo_class, nome_class;
      	nome_class = retorno.substring(0, (i = retorno.indexOf(',')));
	  	retorno = retorno.substring(++i);
		codigo_class = retorno.substring(0, (i = retorno.indexOf(',')));		
		//document.getElementById('titulo_classificacao').innerHTML = '* Classificação';
		document.getElementById('exibe_classificacao').innerHTML = nome_class;	
		document.getElementById('CL_ID').value = codigo_class;		
	}
}

function stateChanged_cnae(){
	var retorno;
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		retorno=xmlHttp.responseText;
		if ( retorno == "True"){
			document.getElementById('result_cnae_'+NumeroCampo).className = '';
			document.getElementById('result_cnae_'+NumeroCampo).className = '';
			document.getElementById('result_cnae_'+NumeroCampo).innerHTML = 'CNAE Inválido';
		}else{
			document.getElementById('result_cnae_'+NumeroCampo).className = '';
			document.getElementById('result_cnae_'+NumeroCampo).className = '';
			document.getElementById('result_cnae_'+NumeroCampo).innerHTML = retorno;
		}			
	}
}

// funcao que gera um lista de produtos que estao sendo pesquisados
function Multiplica(numlote,numiten,qtdItens){
	Lote = numlote;
	Iten = numiten;
	qtdeItens = qtdItens;
	xmlHttp5=GetXmlHttpObject();
	if (xmlHttp5==null){
		alert ("Este browser não suporta HTTP Request");
		return;
	}
	
	if (document.getElementById("IT_QTD_"+Lote+"_"+Iten) && document.getElementById("IT_P_UNIT_EST_"+Lote+"_"+Iten)){
		qtde = document.getElementById("IT_QTD_"+Lote+"_"+Iten).value;
		p_estimado = document.getElementById("IT_P_UNIT_EST_"+Lote+"_"+Iten).value;
	}
	if (document.getElementById("qtd_"+Lote+"_"+Iten) && document.getElementById("RS_ULT_P_UNIT_"+Lote+"_"+Iten)){
		qtde = document.getElementById("qtd_"+Lote+"_"+Iten).value;
		p_estimado = document.getElementById("RS_ULT_P_UNIT_"+Lote+"_"+Iten).value;
	}
	
	// Pega o produto,marca e objeto e gera um lista
	var url5=http_inicial+"calcula.asp";
	url5=url5+"?qtde="+qtde;
	url5=url5+"&p_estimado="+p_estimado;
	url5=url5+"&oper=multiplica";
	xmlHttp5.onreadystatechange=stateChanged_multiplica;
	xmlHttp5.open("GET",url5,true);
	xmlHttp5.send(null);
}

function stateChanged_multiplica(){
	var retorno;
	if (xmlHttp5.readyState==4 || xmlHttp5.readyState=="complete"){
		retorno=xmlHttp5.responseText;
		if (retorno != "False"){
			//document.getElementById('texto_total_estimado').innerHTML = 'Total Estimado:';
			//document.getElementById('result_precoXqtd_'+Lote+'_'+Iten).innerHTML ='R$ '+retorno;
			if (document.getElementById("IT_TOTAL_"+Lote+"_"+Iten)){
				document.getElementById('IT_TOTAL_'+Lote+'_'+Iten).value = retorno;
				if (document.getElementById("LT_VALOR_"+Lote)){
				//Chama função para Calcular o Total do Lote
					cal_lote(Lote);
				}else{
					if (document.getElementById("LI_VL_ITENS")){
						cal_lote(Lote);
					}
				}				
			}
			if (document.getElementById("RS_ULT_VALOR_"+Lote+"_"+Iten)){
				document.getElementById('RS_ULT_VALOR_'+Lote+'_'+Iten).value = retorno;
			}
		}else{
			//document.getElementById('texto_total_estimado').innerHTML = '';
			//document.getElementById('result_precoXqtd_'+Lote+'_'+Iten).innerHTML = '';
			if (document.getElementById("IT_TOTAL_"+Lote+"_"+Iten)){
				document.getElementById('IT_TOTAL_'+Lote+'_'+Iten).value = '';
			}
			if (document.getElementById("RS_ULT_VALOR_"+Lote+"_"+Iten)){
				document.getElementById('RS_ULT_VALOR_'+Lote+'_'+Iten).value = '';
			}
		}// fim do else
	}// fim do if
}

function BuscaUnid(){
	xmlHttp6=GetXmlHttpObject();
	if (xmlHttp6==null){
		alert ("Este browser não suporta HTTP Request");
		return;
	}
		
	UN_TIPO = document.getElementById("UN_TIPO").value;
	UN_DESC = document.getElementById("UN_DESC").value;
	// Pega o produto digitado e gera uma lista de atividades pertinentes aquele produtos
	var url6=http_inicial+"busca.asp";
	url6=url6+"?UN_TIPO="+UN_TIPO;
	url6=url6+"&UN_DESC="+UN_DESC;
	url6=url6+"&tipo=2";
	xmlHttp6.onreadystatechange=stateChanged_Unid;
	xmlHttp6.open("GET",url6,true);
	xmlHttp6.send(null);
}

function stateChanged_Unid(){
	var retorno;
	if (xmlHttp6.readyState==4 || xmlHttp6.readyState=="complete"){
		retorno=xmlHttp6.responseText;
		document.getElementById('exibe_result').innerHTML = retorno;		
	}// fim do if
}

// Funcao que calcula o vencimento dos documentos dos cliente
function Cal_Venc(num){
	NumeroCampo = num;
	xmlHttp7=GetXmlHttpObject();
	if (xmlHttp7==null){
		alert ("Este browser não suporta HTTP Request");
		return;
	}
		
	if (document.getElementById("D_DT_EMISSAO"+NumeroCampo) && document.getElementById("D_DT_VENC"+NumeroCampo)){
		var D_DT_EMISSAO = document.getElementById("D_DT_EMISSAO"+NumeroCampo).value;
		var D_DT_VENC = document.getElementById("D_DT_VENC"+NumeroCampo).value;
		var url7=http_inicial+"calcula.asp";
		url7=url7+"?D_DT_EMISSAO="+D_DT_EMISSAO;
		url7=url7+"&D_DT_VENC="+D_DT_VENC;
		url7=url7+"&oper=Calcula_Vencimento";
		xmlHttp7.onreadystatechange=stateChanged_Cal_Venc;
		xmlHttp7.open("GET",url7,true);
		xmlHttp7.send(null);
	}
}

function stateChanged_Cal_Venc(){
	var retorno;
	if (xmlHttp7.readyState==4 || xmlHttp7.readyState=="complete"){
		retorno=xmlHttp7.responseText;
		document.getElementById('Dias_Venc'+NumeroCampo).innerHTML = retorno;		
	}// fim do if
}


var tipoLicitacao = "";
function MOSTRA_PROVEDOR(valor){
	xmlHttprv=GetXmlHttpObject();
	if (xmlHttprv==null){
		alert ("Este browser não suporta HTTP Request");
		return;
	}
	
	tipoLicitacao = valor;
	// Pega o produto digitado e gera uma lista de atividades pertinentes aquele produtos
	var urlprv=http_inicial+"busca.asp";
	urlprv=urlprv+"?T_ID="+valor;
	urlprv=urlprv+"&tipo=5";
	xmlHttprv.onreadystatechange=stateChanged_PRV;
	xmlHttprv.open("GET",urlprv,true);
	xmlHttprv.send(null);
}

function stateChanged_PRV(){
	var retorno;
	if (xmlHttprv.readyState==4 || xmlHttprv.readyState=="complete"){
		retorno=xmlHttprv.responseText;
		document.getElementById('exibe_provedor').innerHTML = retorno;		
	}// fim do if
	mudaCadastroLicitacao(tipoLicitacao);
}

// funcao para gerar a lista de produtos na tela de cotacoes
function lista_produto(){
	xmlHttp_list_prd=GetXmlHttpObject();
	if (xmlHttp_list_prd==null){
		alert ("Este browser não suporta HTTP Request");
		return;
	}		
	produto = document.getElementById("B_DESCRICAO").value;
	data = document.getElementById("DATA").value;
	
	var url_list_prod=http_inicial+"gerar_lista_produtos.asp";
	url_list_prod=url_list_prod+"?produto="+produto;
	url_list_prod=url_list_prod+"&data="+data;
	xmlHttp_list_prd.onreadystatechange=stateChanged_lista_produto;
	xmlHttp_list_prd.open("GET",url_list_prod,true);
	xmlHttp_list_prd.send(null);
}

function stateChanged_lista_produto(){
	if (xmlHttp_list_prd.readyState==4 || xmlHttp_list_prd.readyState=="complete"){
		document.getElementById("lista_prod").innerHTML=xmlHttp_list_prd.responseText;
	}
}


// funcao para gerar a acotacao do produto, obtendo o codigo do mesmo e a data para cotacao
function gera_cotacao(B_ID,DATA){
	xmlHttp_cotacao=GetXmlHttpObject();
	if (xmlHttp_cotacao==null){
		alert ("Este browser não suporta HTTP Request");
		return;
	}		
	alert(B_ID);
	alert(DATA);
	var url_cotacao=http_inicial+"gera_cotacao.asp";
	url_cotacao=url_cotacao+"?B_ID="+B_ID;
	url_cotacao=url_cotacao+"&DATA="+DATA;	
	xmlHttp_cotacao.onreadystatechange=stateChanged_cotacao;
	xmlHttp_cotacao.open("GET",url_cotacao,true);
	xmlHttp_cotacao.send(null);
}

function stateChanged_cotacao(){
	if (xmlHttp_cotacao.readyState==4 || xmlHttp_cotacao.readyState=="complete"){
		document.getElementById("cotacao").innerHTML=xmlHttp_cotacao.responseText;
	}
}

// funcao para gerar a lista de licitacoes na tela de licitacoes programadas lic_programadas.asp
function Lista_Lic(){
	xmlHttp_list_lic=GetXmlHttpObject();
	if (xmlHttp_list_lic==null){
		alert ("Este browser não suporta HTTP Request");
		return;
	}
	var PR_ID;
	var LI_EDITAL;
	var LI_DT_INIC_DISPUTA;
	var TIPO_LIC;
	
	PR_ID=LI_EDITAL=LI_DT_INIC_DISPUTA=TIPO_LIC="";
	
	if (document.getElementById("PR_ID")){
		PR_ID = document.getElementById("PR_ID").value;
	}
	if (document.getElementById("LI_EDITAL")){
		LI_EDITAL = document.getElementById("LI_EDITAL").value;
	}
	if (document.getElementById("LI_DT_INIC_DISPUTA")){
		LI_DT_INIC_DISPUTA = document.getElementById("LI_DT_INIC_DISPUTA").value;
	}
	if (document.getElementById("TIPO_LIC")){
		TIPO_LIC = document.getElementById("TIPO_LIC").value;
	}
	if (document.getElementById("nome_prod")){
		NOME_PRODUTO = document.getElementById("nome_prod").value;
	}	
	
	if (PR_ID.length == 0 && LI_EDITAL.length == 0 && LI_DT_INIC_DISPUTA.length == 0  && TIPO_LIC.length == 0 && NOME_PRODUTO.length == 0){
		window.alert("Preencha pelo menos 1 campo para pesquisa.");
		return;
	}
	
	var url_list_lic=http_inicial+"gerar_lista_licitacoes.asp";
	url_list_lic=url_list_lic+"?PR_ID="+PR_ID;
	url_list_lic=url_list_lic+"&LI_EDITAL="+LI_EDITAL;
	url_list_lic=url_list_lic+"&LI_DT_INIC_DISPUTA="+LI_DT_INIC_DISPUTA;
	url_list_lic=url_list_lic+"&TIPO_LIC="+TIPO_LIC;
	url_list_lic=url_list_lic+"&NOME_PRODUTO="+NOME_PRODUTO;
	xmlHttp_list_lic.onreadystatechange=stateChanged_lista_licitaco;
	xmlHttp_list_lic.open("GET",url_list_lic,true);
	xmlHttp_list_lic.send(null);
}

function stateChanged_lista_licitaco(){
	var retorno;
	if (xmlHttp_list_lic.readyState==4 || xmlHttp_list_lic.readyState=="complete"){
		retorno = xmlHttp_list_lic.responseText;
		if (retorno == "False" ){
			window.alert("Nenhum registro encontrado.");
		}else{
			document.getElementById("lista_lic").innerHTML=xmlHttp_list_lic.responseText;
		}
	}
}


// funcao para gerar a natureza juridica no cadastro de promotor
function escolhe_natureza(cod_ramo,cod_modal){
	var mostrar_cod = "";
	// codigo da modalidade vazio
	if (cod_modal == "" ){
		alert("Selecione uma Modalidade");
		return;
	}
	xmlHttp_esc_nj=GetXmlHttpObject();
	if (xmlHttp_esc_nj==null){
		alert ("Este browser não suporta HTTP Request");
		return;
	}
	
	// Verificando se a modalidade = a 2 (publico) e o ramo !=1 (administracao publica)
	if (cod_modal == 2 && cod_ramo != 1 ){
		alert("Modalidade incompatível com o Ramo de Atividade");
		cod_ramo = "";
	}else{
		// Se a modalidade = 3 (privado) e o ramo = 1 (administracao publica)
		if (cod_modal == 3 && cod_ramo == 1 ){
			alert("Modalidade incompatível com o Ramo de Atividade");
			cod_ramo = "";
		}
	}
	if (document.getElementById("mostrar")){
		if (document.getElementById("mostrar").value == "nao")
			mostrar_cod = "nao";
	}
	
	var url_nj=http_inicial+"gerar_natureza.asp";
	url_nj=url_nj+"?RA_COD="+cod_ramo;
	url_nj=url_nj+"&mostrar="+mostrar_cod;	
	xmlHttp_esc_nj.onreadystatechange=stateChanged_esc_nj;
	xmlHttp_esc_nj.open("GET",url_nj,true);
	xmlHttp_esc_nj.send(null);
}

function stateChanged_esc_nj(){
	if (xmlHttp_esc_nj.readyState==4 || xmlHttp_esc_nj.readyState=="complete"){
		document.getElementById("combo_nj").innerHTML=xmlHttp_esc_nj.responseText;
	}
}


function GetXmlHttpObject(){
	var objXMLHttp=null;
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}