
///////////////////////////////////////////////////////////
// Cidade Por Uf///////////////////////////////////////////
///////////////////////////////////////////////////////////
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject();


function pesquisarCidadesUfConvenios(valor, tipoConvenio)
{	


	if(tipoConvenio == 'hoteis')
	{
		parametros = 'PT_FUNCAO=VerificaHoteis&PT_COMBO=cboCidadeHoteis';
	}
	else
	{		
		parametros = 'PT_FUNCAO=VerificaAtividadePorCidade&PT_COMBO=cboCidade';
	}
	
	
	
	http.open("GET", "site_beneficio_simulador_convenios_consultar_cidades_convenio.php?PT_UF=" + valor + "&" + parametros, true);
	
  	http.onreadystatechange = handleHttpResponseCidades;
  	http.send(null);
}

function handleHttpResponseCidades()
{
  if (http.readyState == 4) 
  {
	
    document.getElementById('camadaCidades').innerHTML = http.responseText;
    limpaFormGeral();
	limpaFormGeralHoteis();
  }
  
}

///////////////////////////////////////////////////////////
// Verifica as modalidades por CIDADE///////////////////////////////////////////
///////////////////////////////////////////////////////////

function VerificaAtividadePorCidade(idCidade)
{
	
  
  ufStr = document.frmConvenios.cboUf.value; 	
  uf = RetornaIdUf(document.frmConvenios.cboUf.value);  
  http.open("GET", "site_beneficio_simulador_convenios_consulta_modalidade_cidade.php?PT_UF="+uf+"&PT_CIDADE="+idCidade, true);
  http.onreadystatechange = handleHttpResponseAtividadePorCidade;
  http.send(null);
}

function handleHttpResponseAtividadePorCidade()
{
  if (http.readyState == 4) 
  {
     document.getElementById("camadaConvenios").innerHTML = http.responseText;
     //limpaFormGeral();
	limpaElemento('detalhesConvenio');
	limpaConvenio();
	limpaElemento('camadaAtividade');
  }
}


//Consulta Convenios
function VerificaConveniosPorAtividade(atividade)
{
 	
  document.getElementById("camadaAtividade").innerHTML = 'Carregando ...';
  uf 		= RetornaIdUf(document.frmConvenios.cboUf.value);
  cidade 	= document.frmConvenios.cboCidade.value;
  siglaUf	= document.frmConvenios.cboUf.value;
  descUf	= retorna_Estado(document.frmConvenios.cboUf.value);
	
  http.open("GET", "site_beneficio_simulador_convenios_consultar_atividade_estado.php?PT_UF="+uf+"&PT_ATIVIDADE="+atividade+"&PT_CIDADE="+cidade+"&PT_ESTADO="+siglaUf+"&PT_ESTADO_DESC="+descUf, true);
  http.onreadystatechange = handleHttpResponseConveniosPorAtividade;
  http.send(null);
}


function handleHttpResponseConveniosPorAtividade()
{
  if (http.readyState == 4) 
  {
    document.getElementById("camadaAtividade").innerHTML = http.responseText;
	limpaConvenio();
  }
}

function setEstado(uf,nomeForm)
{
	document.nomeForm.cboUf.value = uf;
}
 
function retorna_Estado(strUF)
{
	switch(strUF.toUpperCase())
	{
		case 'AC':
					$estadoDefault='Acre';
					break;
		case 'AL':
					$estadoDefault='Alagoas';					
					break;	
		case 'AM':
					$estadoDefault='Amanozas';
					break;										
		case 'AP':
					$estadoDefault='Amapá';
					break;		
		case 'BA':
					$estadoDefault='Bahia';
					break;		
		case 'CE':
					$estadoDefault='Ceará';
					break;											
		case 'DF':
					$estadoDefault='Distrito Federal';
					break;
		case 'ES':
					$estadoDefault='Espírito Santo';
					break;	
		case 'GO':
					$estadoDefault='Goiás';
					break;	
		case 'MA':
					$estadoDefault='Maranhão';
					break;	
		case 'MG':
					$estadoDefault='Minas Gerais';
					break;	
		case 'MS':
					$estadoDefault='Mato Grosso do Sul';
					break;	
		case 'MT':
					$estadoDefault='Mato Grosso';
					break;		
		case 'PA':
					$estadoDefault='Pará';
					break;	
		case 'PB':
					$estadoDefault='Paraíba';
					break;
		case 'PE':
					$estadoDefault='Pernambuco';
					break;		
		case 'PI':
					$estadoDefault='Piauí';
					break;	
		case 'PR':
					$estadoDefault='Paraná';
					break;	
		case 'RJ':
					$estadoDefault='Rio de Janeiro';
					break;
		case 'RN':
					$estadoDefault='Rio Grande do Norte';
					break;	
		case 'RO':
					$estadoDefault='Rondônia';
					break;		
		case 'RR':
					$estadoDefault='Roraima';
					break;	
		case 'RS':
					$estadoDefault='Rio Grande do Sul';
					break;		
		case 'SC':
					$estadoDefault='Santa Catarina';
					break;		
		case 'SE':
					$estadoDefault='Sergipe';
					break;		
		case 'SP':
					$estadoDefault='São Paulo';
					break;
		case 'TO':
					$estadoDefault='Tocantins';
					break;																																																							
	}
	return $estadoDefault;
}


function mostraDetalhesConvenioGeral(PT_CON_ID)
{
  document.getElementById("detalhesConvenio").innerHTML = 'Carregando Detalhes do Convênio...';
  http.open("GET", "site_beneficio_simulador_convenios_hoteis_detalhes.php?PT_CON_ID="+PT_CON_ID, true);
  http.onreadystatechange = respondeDetalhesConvenio;
  http.send(null);
}


function respondeDetalhesConvenio()
{
  if (http.readyState == 4) 
  {
    document.getElementById("detalhesConvenio").innerHTML = http.responseText;
  }
}

function limpaFormGeral(){
	limpaElemento('detalhesConvenio');
	limpaConvenio();
	limpaModalidade();
	limpaElemento('camadaAtividade');
	
}

//limpa o formulario para nova selecao de UF
function limpaFormGeralHoteis(){
	limpaElemento('detalhesConvenio');
	limpaHoteisLista();
}

function limpaElemento(id)
{
	if(document.getElementById(id))
	{
		document.getElementById(id).innerHTML = "";
	}
}


function limpaConvenio()
{
	if(document.getElementById("detalhesConvenio"))
	{
		document.getElementById("detalhesConvenio").innerHTML = "";
	}
}

function limpaHoteisLista()
{
	if(document.getElementById("CamadaConvenios"))
	{
		document.getElementById("CamadaConvenios").innerHTML = '<select name="lstHoteis" class="inputListSIMUtecnoPrev"></select>';
	}
}


/*
// limpa o convenio quando uma nova UF é selecionada
function limpaConvenio()
{
    if(document.getElementById("detalhesConvenio"))
	{
		document.getElementById("detalhesConvenio").innerHTML = "";
	}
}
*/
function limpaModalidade()
{
	if(document.getElementById("camadaConvenios"))
	{
		document.getElementById("camadaConvenios").innerHTML = '<select name="cboConveios" class="inputListSIMUtecnoPrev" onChange="VerificaConveniosPorAtividade(this.value)"></select>';
	}
}


function limpaHoteisLista()
{
	document.getElementById("CamadaConvenios").innerHTML = '<select name="lstHoteis" class="inputListSIMUtecnoPrev"></select>';
}

function ocultarCamada() 
{ 
	if (document.getElementById) 
	{ 
		document.getElementById('descricaoConveniosHoteis').style.visibility = 'hidden'; 
	} 
	else 
	{ 
		if (document.layers) 
		{ // Netscape 4 
			document.descricaoConveniosHoteis.visibility = 'hidden'; 
		} 
		else 
		{ // IE 4 
			document.all.descricaoConveniosHoteis.style.visibility = 'hidden'; 
		} 
	} 
} 

function mostarCamada() 
{ 
	if (document.getElementById) 
	{ // DOM3 = IE5, NS6 
		document.getElementById('descricaoConveniosHoteis').style.visibility = 'visible'; 
	} 
	else 
	{ 
		if (document.layers) 
		{ // Netscape 4 
		document.descricaoConveniosHoteis.visibility = 'visible'; 
		} 
		else 
		{ // IE 4 
		document.all.descricaoConveniosHoteis.style.visibility = 'visible'; 
		} 
	} 
} 



function RetornaIdUf(strUF)
{
	switch(strUF.toUpperCase())
	{
		case 'AC': $ufId=23646;	break;
		case 'AL': $ufId=23653;	break;	
		case 'AM': $ufId=23649;	break;										
		case 'AP': $ufId=23656;	break;		
		case 'BA': $ufId=23637;	break;		
		case 'CE': $ufId=23662;	break;																						
		case 'DF': $ufId=23657;	break;
		case 'ES': $ufId=23645;	break;
		case 'GO': $ufId=23654;	break;
		case 'MA': $ufId=23639;	break;	
		case 'MG': $ufId=23660;	break;
		case 'MS': $ufId=23659;	break; 
		case 'MT': $ufId=23661;	break;		
		case 'PA': $ufId=23655;	break;
		case 'PB': $ufId=23641;	break;																									
		case 'PE': $ufId=23651;	break;		
		case 'PI': $ufId=23648;	break;	
		case 'PR': $ufId=23658;	break;
		case 'RJ': $ufId=23638;	break;
		case 'RN': $ufId=23644;	break;	
		case 'RO': $ufId=23652;	break;	
		case 'RR': $ufId=23650;	break;
		case 'RS': $ufId=23643;	break;		
		case 'SC': $ufId=23640;	break;	
		case 'SE': $ufId=23663;	break;	
		case 'SP': $ufId=23642;	break;
		case 'TO': $ufId=23647;	break;																																																						
	}
	return $ufId;
}

///////////////////////////////////////////////////////////
//Consulta Convenios
///////////////////////////////////////////////////////////
function VerificaHoteis(atividade)
{
  uf 		= RetornaIdUf(document.frmHoteis.cboUfHoteis.value);
  cidade 	= document.frmHoteis.cboCidadeHoteis.value;
  siglaUf	= document.frmHoteis.cboUfHoteis.value;
  descUf	= retorna_Estado(document.frmHoteis.cboUfHoteis.value);
  http.open("GET", "site_beneficio_simulador_convenios_consultar_atividade_estado.php?PT_UF="+uf+"&PT_ATIVIDADE=19&PT_CIDADE="+cidade+"&PT_ESTADO="+siglaUf+"&PT_ESTADO_DESC="+descUf, true);
  http.onreadystatechange = handleHttpResponseHoteis;
  http.send(null);
}


function handleHttpResponseHoteis()
{
  if (http.readyState == 4) 
  {
    document.getElementById("CamadaConvenios").innerHTML = http.responseText;
	limpaElemento('detalhesConvenio');
  }
}
