// Script para a realização da Busca Instantanêa com Ajax
// Por Leandro Vieira Pinho, colunista iMasters (Dreamweaver)

//================================================================================================================
//dia 04/03/2009 foi criada a function fValidaDadosTrasladoAjax2 por Rafael
//================================================================================================================
var url;
function Trim(str){return str.replace(/^\s+|\s+$/g,"");}


	function fMascaraLogin(campo, evento){
		
		if((campo.name.substring(0,5).replace("L","l") == "login")||(campo.name.substring(0,5).replace("S","l") == "senha"))
		{
			if((campo.value == "login") && (evento == "focus")){
				campo.value = "";	
			}
			if((ConsisteCampoBranco(campo.value) == true) && (evento == "blur")){
				campo.value = "login";	
			}
		}
	}
	
	function fOcultaTxtCampo(campo, evento, texto)
	{				
		if((campo.value.toUpperCase() == texto.toUpperCase()) && (evento == "focus"))
		{
			campo.value = "";	
		}
		else
		{
			//campo.value = campo.value.toUpperCase()
		}
		if((campo.value != '') && (evento == "blur"))
		{
			campo.value = texto;	
		}		
		
	}

function pegarPosicaoX(objeto)
{
		var atual_left = 0;
		if (objeto.offsetParent) {
				while (objeto.offsetParent) {
						atual_left += objeto.offsetLeft
						objeto = objeto.offsetParent;
				}
		}
		return atual_left;
}

function pegarPosicaoY(objeto)
{
		var atual_top = 0;
		if (objeto.offsetParent) {
				while (objeto.offsetParent) {
						atual_top += objeto.offsetTop
						objeto = objeto.offsetParent;
				}
		}
		return atual_top;
}

// Função para iniciarmos o Ajax no browser do cliente.
function openAjax() {

	var ajax;
	
	try{
			ajax = new XMLHttpRequest(); // XMLHttpRequest para browsers decentes, como: Firefox, Safari, dentre outros.
	}catch(ee){
			try{
					ajax = new ActiveXObject("Msxml2.XMLHTTP"); // Para o IE da MS
			}catch(e){
					try{
							ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE da MS
					}catch(E){
							ajax = false;
					}
			}
	}
	return ajax;
}


function dataDiasNoites(tipo)
{	
		if (document.getElementById('pesq-checkin').value != "")
		{
			var dateAtual = Date.parse(transferDateString(document.getElementById('hoje').value));
			var novadata = new Date(transferDateString(document.getElementById('pesq-checkin').value));
			//if (document.getElementById('pesq-noites').value == "")
			//	document.getElementById('pesq-noites').value = "1";	
			var noites = document.getElementById('pesq-noites').value;			
			var date1 = Date.parse(transferDateString(document.getElementById('pesq-checkin').value));
			
			/*validação abaixo nao estava funcionando Fabricio*/
			/*if (date1 != "" && noites != "" && document.getElementById('pesq-checkout').value == "")
			{		
			
			
				novadata.setDate(novadata.getDate()+parseInt(noites));
				
			
				novadata.toLocaleDateString();
				if (novadata.getDate()<10)  dia = '0'+novadata.getDate();  else dia = novadata.getDate();
				if (novadata.getMonth()<9) mes = '0'+(novadata.getMonth()+1); else mes = (novadata.getMonth()+1);
				
				document.getElementById('pesq-checkout').value = dia+'/'+mes+'/'+novadata.getUTCFullYear();					
			}*/
			
			var date2 = Date.parse(transferDateString(document.getElementById('pesq-checkout').value));			
			
			if (tipo == 'data')
			{
				
				if (date1<dateAtual)
				{
					alert("A(s) data(s) deve(m) ser maior que hoje!");
					document.getElementById('pesq-checkin').value = "";
					document.getElementById('pesq-checkout').value = "";
					document.getElementById('pesq-noites').value = "";
					return;
				}
				if (date2<dateAtual)
				{
					alert("A(s) data(s) deve(m) ser maior que hoje!");
					//document.getElementById('pesq-checkin').value = "";
					document.getElementById('pesq-checkout').value = "";
					document.getElementById('pesq-noites').value = "";
					return;
				}
				
				if (date2 >= date1 && date1 != null && date2 != null) 
				{
					var difference = Math.round((date2 - date1)/1000/60/60/24);
					
					if (parseInt(difference) >= 30)
					{
							alert("A reserva não pode Ultrapassar 30 dias!");
							document.getElementById('pesq-checkout').value = "";
							document.getElementById('pesq-noites').value = "";	
							return;
					}
					document.getElementById('pesq-noites').value = difference;
				}	
				else if (date2 <= date1)
				{
					alert("A data de checkout tem que ser maior que a data de checkin!");
					//document.getElementById('pesq-checkout').focus();
					return;				
				}
			}
			else
			{
				if (date1 != "" && noites != "")
				{				
					
					if (parseInt(noites) >= 30 )
					{
							alert("A reserva não pode Ultrapassar 30 dias!");
							document.getElementById('pesq-checkout').value = "";
							document.getElementById('pesq-noites').value = "";	
							return;
					}
					
					novadata.setDate(novadata.getDate()+parseInt(noites));
					novadata.toLocaleDateString();
					
					if (novadata.getDate()<10)  dia = '0'+novadata.getDate();  else dia = novadata.getDate();
					if (novadata.getMonth()<9) mes = '0'+(novadata.getMonth()+1); else mes = (novadata.getMonth()+1);
					
					document.getElementById('pesq-checkout').value = dia+'/'+mes+'/'+novadata.getUTCFullYear();					
				}
			}	
		}
		else
		{
			document.getElementById('pesq-checkout').value = "";
			document.getElementById('pesq-noites').value = "";				
		}
}		

function transferDateString(orignalDate)
{
		var date =orignalDate.substring(0,orignalDate.indexOf("/"));
		var month = orignalDate.substring(orignalDate.indexOf("/")+1,orignalDate.lastIndexOf("/"));			
		var year = orignalDate.substring(orignalDate.lastIndexOf("/")+1);
		return month+"/"+date+"/"+year;
}
		
function CarregaCidades2(codigoPais){
	//var url = "buscaInstantanea.asp?sAcao=MENU&tipo="+tipo+"&titulo="+escape(titulo)+"&subtitulo="+escape(subtitulo)+"&cod_conteudo="+codigo;
	//fCarregaDivConteudoAjax(url, "divCorpo");
}
function CarregaCidades(codigoPais){
	var url = "detalhes.html?cod_pais="+codigoPais;	
	//$("#div-pais").load(url);
	fCarregaDivAjax(url,'conteudo');
}
function CarregaDiv(url, div){			
	fCarregaDivAjax(url,div);
}
		
function fCarregaDivAjax(url, campo){
	if(document.getElementById) { 
		var exibeResultado = document.getElementById(campo); 
		var ajax = openAjax(); 
		ajax.open("GET", url, true);
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 1) { // Quando estiver carregando, exibe: carregando...
				exibeResultado.innerHTML = "<span class='form_titulo'><font color='green'><strong>Carregando...</strong></font></span>";
			}
			if(ajax.readyState == 4) { 
				if(ajax.status == 200 || true) {
					var resultado = ajax.responseText; 
					resultado = resultado.replace(/\+/g," "); 
					resultado = unescape(resultado);
					exibeResultado.innerHTML = resultado;
				} else {
					exibeResultado.innerHTML = "";
				}
			}
		}
		ajax.send(null); 
	}
}

function fCarregaDivAjaxCidade(url, campo){
	if(document.getElementById) { 
		var exibeResultado = document.getElementById(campo); 
		var ajax = openAjax(); 
		ajax.open("GET", url, true);
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 1) { // Quando estiver carregando, exibe: carregando...
				//exibeResultado.innerHTML = "<span class='form_titulo'><font color='green'><strong>Carregando...</strong></font></span>";
				exibeResultado.innerHTML = "<p>Cidade:</p><select name='pesq-cidade' id='pesq-cidade' class='texto_DropDown pesq-cidade'><option value=''>Carregando...</option></select>"
			}
			if(ajax.readyState == 4) { 
				if(ajax.status == 200 || true) {
					var resultado = ajax.responseText; 
					resultado = resultado.replace(/\+/g," "); 
					resultado = unescape(resultado);
					exibeResultado.innerHTML = resultado;
				} else {
					exibeResultado.innerHTML = "";
				}
			}
		}
		ajax.send(null); 
	}
}

function AlertarUsuario(msg)
{
		var texto = '';
		texto = texto + '<div>';
		texto = texto + '	<table border="0" width="100%">';
		texto = texto + '		<tr>';
		texto = texto + '			<td rowspan="2" style="width:50px; text-align:center; vertical-align:middle">';
		texto = texto + '				<img src="../../portal/res07/imagens/alert_icon.png" />';
		texto = texto + '			</td>';
		texto = texto + '			<td style="text-align:left; vertical-align:middle">';
		texto = texto + '				<font style="font-size:16px; font-weight:bold;">'+msg+'</font>';
		texto = texto + '			</td>';
		texto = texto + '		</tr>';
		texto = texto + '		<tr>';
		texto = texto + '			<td style="text-align:right; vertical-align:middle">';
		texto = texto + '				<br><a onclick="$.unblockUI();"><img height="25" border="0" src="../../portal/res07/imagens/btn_ok.png" /></a>';
		texto = texto + '			</td>';
		texto = texto + '		</tr>';
		texto = texto + '	</table>';
		texto = texto + '</div>';
		$.blockUI({ 
		message: texto,						
		css: { 
				width: '300px', 
				border: 'none', 
				padding: '10px', 
				backgroundColor: '#000', 
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .8, 
				color: '#fff' 
		} ,
		overlayCSS: { backgroundColor: '' }
	});
}

function HomeLimpaDados(pagina)
{	 
	$("#hoteis").load("../../func/hotel/limpaSessoes.asp?str="+Date.parse(new Date()),function(){
		fCarregaSubSite(pagina);
	});
	
}

function proximoPasso(paginaURL)
{
	momentoAtual = new Date();
	
	if (paginaURL.indexOf("?")>0)
	{
		document.getElementById("url").value = paginaURL+"&str="+Date.parse(new Date());
		$("#conteudo").load(paginaURL+"&str="+Date.parse(new Date()));
	}
	else
	{
		document.getElementById("url").value = paginaURL+"?str="+Date.parse(new Date());
		$("#conteudo").load(paginaURL+"?str="+Date.parse(new Date()));
	}
	
}



function GuardaIdades(campo,valoridades, valoridades2)
{	
		document.getElementById(campo).value = "";
		
		for (i = 0; i<document.getElementsByName(valoridades).length; i++)
		{
			if (document.getElementById(campo).value == "")
				document.getElementById(campo).value = document.getElementsByName(valoridades)[i].value;
			else
				document.getElementById(campo).value = document.getElementById(campo).value +";"+document.getElementsByName(valoridades)[i].value;
				
			if (valoridades2 != "")
			{
				document.getElementById(campo).value = document.getElementById(campo).value +"|"+document.getElementsByName(valoridades2)[i].value;
			}
		}
		
		document.getElementById("divTwinCrianca").style.display = "none";		
}

function printPartOfPage(elementId)
{
	 var printContent = document.getElementById(elementId);
	 var windowUrl = 'about:blank';
	 var uniqueName = new Date();
	 var windowName = 'Print' + uniqueName.getTime();
	 var printWindow = window.open(windowUrl, windowName, 'left=0,top=0,width=755,height=450');
	
	 printWindow.document.write("<style>table{font-size:11px;}.noprint{display:none;}#orcamento{background-color:#3F80AE;}</style>"+printContent.innerHTML.replace("class='noprint'","style='display:none;'"));
	 printWindow.document.close();
	 printWindow.focus();
	 printWindow.print();
	 printWindow.close();
}
function ImprimeOrc(elementId)
{
	 var printContent = document.getElementById(elementId);
	 var windowUrl = '../../func/portal/impressaoOrc.asp?str='+Date.parse(new Date());
	 var uniqueName = new Date();
	 var windowName = 'Print' + uniqueName.getTime();
	 var printWindow = window.open(windowUrl, windowName, 'left=0,top=0,width=755,height=450');
	
	 printWindow.document.write("<style>table{font-size:11px;}.noprint{display:none;}#orcamento{background-color:#3F80AE;}</style>"+printContent.innerHTML.replace("class='noprint'","style='display:none;'"));
	 printWindow.document.close();
	 printWindow.focus();
	 printWindow.print();
	 printWindow.close();
}

function AntesEviarEmail(altura,largura)
{
	
		if (altura==null)
			altura = 320;
		if (largura==null)
			largura = 100;
			
		$('#divEmailEncaminhado').modal({			
			overlayCss: {
				backgroundColor: '#222',
				cursor: 'wait'
			},
			containerCss: {
				height: altura,
				width: largura,
				backgroundColor: '#000',
				border: '1px solid #CCC',
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .9, 
				color: '#FF0'
			}
		});
}

function emailOrc()
{
		
	 //var printContent = document.getElementById(elementId);
	 
	 var dados = "";
	 dados += "&empresaRem="+document.getElementById("campo_empresa").value;
	 dados += "&contatoRem="+document.getElementById("campo_contato").value;
	 dados += "&foneRem="+document.getElementById("campo_fone").value;
	 dados += "&emailRem="+document.getElementById("campo_email_contato").value;
	 dados += "&nomeDes="+document.getElementById("campo_nome").value;
	 dados += "&emailDes="+document.getElementById("campo_email").value;
	 dados += "&obsDes="+document.getElementById("emailObs").value;
	 
	 var windowUrl = '../../func/portal/emailOrc.asp?str='+Date.parse(new Date())+dados;
	 
	 var uniqueName = new Date();
	 var windowName = 'Print' + uniqueName.getTime();
	 var printWindow = window.open(windowUrl, windowName, 'left=0,top=0,width=755,height=450');
	
	 //printWindow.document.write("<style>table{font-size:11px;}.noprint{display:none;}#orcamento{background-color:#3F80AE;}</style>"+printContent.innerHTML.replace("class='noprint'","style='display:none;'"));
	 printWindow.document.close();
	 printWindow.focus();
	 //printWindow.print();
	 //printWindow.close();
	 $.modal.close();
}

function fAdicionaReserva(codhotel, local, token, cidade, pais, dataIni, dataFin,  noites, tipoQuartos, valoresQuartos, QuantQuartos, TaxesIncluded, moedaQuartos)
{
		momentoAtual = new Date();	
		var tempDta;
		var novaDtaIni;
		var novaDtaFin;
		//alertt();
		
		novaDtaIni = "";
		novaDtaFin = "";
		
		tempDta = dataIni.split("/")
		if (tempDta[0].length < 2)
			novaDtaIni = novaDtaIni + "0" + tempDta[0];
		else
			novaDtaIni = novaDtaIni + tempDta[0];
		if (tempDta[1].length < 2)
			novaDtaIni = novaDtaIni + "/" + "0" + tempDta[1];
		else
			novaDtaIni = novaDtaIni + "/" + tempDta[1];
		novaDtaIni = novaDtaIni + "/" + tempDta[2];
		
			
		tempDta = dataFin.split("/")
		if (tempDta[0].length < 2)
			novaDtaFin = novaDtaFin + "0" + tempDta[0];
		else
			novaDtaFin = novaDtaFin + tempDta[0];
		if (tempDta[1].length < 2)
			novaDtaFin = novaDtaFin + "/" + "0" + tempDta[1];
		else
			novaDtaFin = novaDtaFin + "/" + tempDta[1];
		novaDtaFin = novaDtaFin + "/" + tempDta[2];
		
		//FAZENDO VALIDAÇÃO PRA PEGAR OS VALORES DOS QUARTOS SELECIONADOS.
		//document.getElementById("check_1182_1").checked;
		var arrayQuantQuartos = QuantQuartos.split('|');
		var arrayTipoQuartos = tipoQuartos.split('|');
		var arrayValoresQuartos = valoresQuartos.split('|');
		var arrayMoedaQuartos = moedaQuartos.split('|');
		
		var idQuartos = "";
		var dscQuartos = "";
		QuantQuartos = "";
		tipoQuartos = "";
		valoresQuartos = "";
		moedaQuartos = "";
		var splitQuartos;
		
		splitQuartos = (document.getElementById("idQuartoExistentes_"+codhotel).value.substring(1)).split(',');
		
		/*foreach i (split(",", splitQuartos)){
			if (document.getElementById("check_"+codhotel+"_"+(i)).checked)
				{
					idQuartos = idQuartos + "|" + (i);
					dscQuartos = dscQuartos + "|" +document.getElementById("dscQuarto_"+codhotel+"_"+(i)).value;
					QuantQuartos = QuantQuartos + "|" + arrayQuantQuartos[i];
					tipoQuartos = tipoQuartos + "|" + arrayTipoQuartos[i];
					valoresQuartos = valoresQuartos + "|" + arrayValoresQuartos[i];
					moedaQuartos = moedaQuartos + "|" + arrayMoedaQuartos[i];
				}
		}*/
		
		for (i = 0; i < arrayQuantQuartos.length; i++) 
		{
				
				if (document.getElementById("check_"+codhotel+"_"+splitQuartos[i]).checked)
				{
					idQuartos = idQuartos + "|" + splitQuartos[i];
					dscQuartos = dscQuartos + "|" +document.getElementById("dscQuarto_"+codhotel+"_"+splitQuartos[i]).value;
					QuantQuartos = QuantQuartos + "|" + arrayQuantQuartos[i];
					tipoQuartos = tipoQuartos + "|" + arrayTipoQuartos[i];
					valoresQuartos = valoresQuartos + "|" + arrayValoresQuartos[i];
					moedaQuartos = moedaQuartos + "|" + arrayMoedaQuartos[i];
				}
    }
		
		idQuartos = idQuartos.substring(1);
		dscQuartos = dscQuartos.substring(1).replace(" ","_");
		QuantQuartos = QuantQuartos.substring(1);
		tipoQuartos = tipoQuartos.substring(1);
		valoresQuartos = valoresQuartos.substring(1);
		moedaQuartos = moedaQuartos.substring(1);
	
			
		//$.growlUI('Hotel Adicionado ao Carrinho', ''); 
		url = "../../func/hotel/dnet/politicaCancelamento.aspx?str="+Date.parse(new Date())+"&codReserva="+document.getElementById("A094_cod_reserva").value+"&token="+token+"&hotelId="+codhotel+"&quartoId="+idQuartos;
		//fCarregaDivAjax(url,"divPoliticaCanc2" );		
		//$("#divPoliticaCanc2").load(url, function(){																							
				fAdicionaReserva2(codhotel, local, token, novaDtaIni, novaDtaFin, pais, cidade, noites, tipoQuartos, valoresQuartos, QuantQuartos, idQuartos, dscQuartos, TaxesIncluded, moedaQuartos)
		//});
}

function fAddReserva(codhotel, local, token, cidade, pais, dataIni, dataFin,  noites, tipoQuarto, valoresQuarto, QuantQuarto, TaxesIncluded, moedaQuarto, idQuarto, dscQuarto, campoCheck, seqHotel, dscAlimentacao)
{
		var tempDta;
		var novaDtaIni;
		var novaDtaFin;
		
		var chekboxReserva;
		
		
		//verifica se o campo clicado é checkbox ou o link
		if (campoCheck.type == "checkbox")
			chekboxReserva = campoCheck
		else
			chekboxReserva = document.getElementById("checkQuarto_"+codhotel+"_"+idQuarto);
		
		
		//alert((campoCheck.innerHTML == "Incluir") || campoCheck.checked);
		if(document.getElementById("checkQuarto_"+codhotel+"_"+idQuarto) != null)
		{
			if(document.getElementById("linkIncluir"+codhotel+""+idQuarto).innerHTML == "Incluir") 
			{
				document.getElementById("linkIncluir"+codhotel+""+idQuarto).style.color = "blue";
				document.getElementById("linkIncluir"+codhotel+""+idQuarto).innerHTML = "Incluído";
				document.getElementById("checkQuarto_"+codhotel+"_"+idQuarto).checked = true;
				chekboxReserva.checked = true;
				
			}
			else
			{
				document.getElementById("linkIncluir"+codhotel+""+idQuarto).style.color = "";
				document.getElementById("linkIncluir"+codhotel+""+idQuarto).innerHTML = "Incluir";
				document.getElementById("checkQuarto_"+codhotel+"_"+idQuarto).checked = false;
				chekboxReserva.checked = false;
				
			}
		}
		
		novaDtaIni = "";
		novaDtaFin = "";
		
		tempDta = dataIni.split("/")
		if (tempDta[0].length < 2)
			novaDtaIni = novaDtaIni + "0" + tempDta[0];
		else
			novaDtaIni = novaDtaIni + tempDta[0];
		if (tempDta[1].length < 2)
			novaDtaIni = novaDtaIni + "/" + "0" + tempDta[1];
		else
			novaDtaIni = novaDtaIni + "/" + tempDta[1];
		novaDtaIni = novaDtaIni + "/" + tempDta[2];
		
		
		tempDta = dataFin.split("/")
		if (tempDta[0].length < 2)
			novaDtaFin = novaDtaFin + "0" + tempDta[0];
		else
			novaDtaFin = novaDtaFin + tempDta[0];
		if (tempDta[1].length < 2)
			novaDtaFin = novaDtaFin + "/" + "0" + tempDta[1];
		else
			novaDtaFin = novaDtaFin + "/" + tempDta[1];
		novaDtaFin = novaDtaFin + "/" + tempDta[2];
		
		
		if (chekboxReserva.checked)
		{
			
			fAdicionaReserva2(codhotel, local, token, novaDtaIni, novaDtaFin, pais, cidade, noites, tipoQuarto, valoresQuarto, QuantQuarto, idQuarto, dscQuarto, TaxesIncluded, moedaQuarto, dscAlimentacao)
			
		}
		else
		{
			
			fRemoveReserva(codhotel, seqHotel, local, token, novaDtaIni, novaDtaFin, pais, cidade, noites, tipoQuarto, valoresQuarto, QuantQuarto, TaxesIncluded,idQuarto )
		}
		//*/
}

function fAdicionaReserva2(codhotel, local, token, dataIni, dataFin, pais, cidade, noites, tipoQuartos, valoresQuartos, QuantQuartos, idQuartos, dscQuartos, TaxesIncluded, moedaQuartos, dscAlimentacao)
{
	var dados = "";
	var tempDta;
	var novaDtacCanc = "";
	
	url = ""
	momentoAtual = new Date();	
	
	
	
			
			//document.getElementById("divPoliticaCanc").value = document.getElementById("divPoliticaCanc2").innerHTML;
			//document.getElementById("idHotelReservado").value = document.getElementById("idHotelReservado").value + codhotel + ",";	
			/*	
			tempDta = document.getElementById("divPoliticaCanc2").innerHTML.substring(0,10).split("/")
			if (tempDta[0].length < 2)
				novaDtacCanc = novaDtacCanc + "0" + tempDta[0];
			else
				novaDtacCanc = novaDtacCanc + tempDta[0];
			if (tempDta[1].length < 2)
				novaDtacCanc = novaDtacCanc + "/" + "0" + tempDta[1];
			else
				novaDtacCanc = novaDtacCanc + "/" + tempDta[1];
			novaDtacCanc = novaDtacCanc + "/" + tempDta[2].substring(0,4);
		*/
			
			dados = dados + "&codhotel="+codhotel
			dados = dados + "&token="+token;
			dados = dados + "&datainicial="+dataIni.replace(" ","").substring(0,10);
			dados = dados + "&datafinal="+dataFin.replace(" ","").substring(0,10);
			//dados = dados + "&codPais="+pais;
			dados = dados + "&codCidade="+cidade;	
			dados = dados + "&noites="+noites;
			dados = dados + "&PolitCanc="+novaDtacCanc.replace(" ","").substring(0,10);
			
			dados = dados + "&tipoQuartos="+tipoQuartos;
			dados = dados + "&valoresQuartos="+valoresQuartos.replace(".","").replace(",",".");
			dados = dados + "&QuantQuartos="+QuantQuartos;
			dados = dados + "&idQuartos="+idQuartos;
			dados = dados + "&moedaQuartos="+moedaQuartos;
			dados = dados + "&dscQuartos="+dscQuartos;
			dados = dados + "&dscAlimentacao="+dscAlimentacao;
						
			
			//if (Trim(document.getElementById("pesq-categoria").options[document.getElementById("pesq-categoria").selectedIndex].value) != "")
			//	dados = dados + "&estrelas="+document.getElementById("pesq-categoria").options[document.getElementById("pesq-categoria").selectedIndex].value;
			
			dados = dados + "&TaxesIncluded="+escape(TaxesIncluded);
				
			quarto="";
			ValidaFiltroQuartos();
			
			dados = dados + quarto;
			if (document.getElementById("1CHD_Quarto") != null)
			{
				dados = dados + "&idadesCHD="+document.getElementById("1CHD_Quarto").value
				if (document.getElementById("2CHD_Quarto") != null)
					dados = dados +","+document.getElementById("2CHD_Quarto").value;
			}
			dados = trocaCaracter(dados," ","_");
				
			url = "../../func/hotel/AdicionaCarrinho.asp?acao=I&str="+Date.parse(new Date())+dados;
			document.getElementById("url").value = url;	
					
			$("#divReservaHotel").load(url,function(){					
					$.unblockUI();
					//$.blockUI({ message: "Verificando Política de Cancelamento!",
					$.blockUI({ message: "Adicionando item as Minhas Opções!",			
						css: { border: 'none', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .8, color: '#fff' },
						overlayCSS: { backgroundColor: '' }
					});	
					//REMOVIDO ABAIXO PRA RETIRAR A BUSCA DA POLITICA DE CANCELAMENTO NESSE MOMENTO
					//url = "../../func/hotel/dnet/politicaCancelamento.aspx?str="+Date.parse(new Date())+"&codReserva="+document.getElementById("A094_cod_reserva").value+"&token="+token+"&hotelId="+codhotel+"&quartoId="+idQuartos;
					//$("#divPoliticaCanc2").load(url, function(){ 
					//	$.unblockUI();
					//	$.blockUI({ message: "Adicionando item as Minhas Opções!",
					//		css: { border: 'none', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .8, color: '#fff' },
					//		overlayCSS: { backgroundColor: '' }
					//	});						
						if (local = 'pesquisa')
						{			
							dados = dados + "&NovaDataInicial="+dataFin.replace(" ","").substring(0,10);
							dados = dados + "&nomeHotel="+document.getElementById("nomeHotel").value;
							dados = dados + "&nomeLocalizacao="+document.getElementById("nomeLocalizacao").value;
							
							url = "../../func/hotel/filtro.asp?str="+Date.parse(new Date())+dados;
								
							$("#mostraFiltro").load(url,function(){									
								url = "../../func/portal/carrinho.asp?str="+Date.parse(new Date())+"";
								$("#mostraCarrinho").load(url,function(){									
									//fPesquisa(local);
									//COLOCANDO A DATA FINAL COMO DATA INICIAO E A QUANTIDADE DE NOITES E RECALCULANDO A DATA FINAL
									
								});
							});
							
						}
					//});
					
			});	
					
					
}

function fRemoveReserva(codhotel, seqhotel, local, token, dataIni, dataFin, pais, cidade, noites, tipoQuartos, valoresQuartos, QuantQuartos, Breakfast,idQuarto )
{
	document.getElementById("idHotelReservado").value = document.getElementById("idHotelReservado").value.replace(","+codhotel+",",",");
	
	var dados = "";
	dados = dados + "&codhotel="+codhotel
	dados = dados + "&seqhotel="+seqhotel;
	dados = dados + "&idQuarto="+idQuarto;
	
	//TODO: procurar um jeito de encontrar os id dos checkbox dos quartos.
	quant = 20;
	for(i=0;i<quant;i++)
	{
		// desmarncando os 20 checkbos do quarto caso exista.
		if(document.getElementById("checkQuarto_"+codhotel+"_"+i) != null)	
		{
			document.getElementById("checkQuarto_"+codhotel+"_"+i).checked = false;
			document.getElementById("linkIncluir"+codhotel+i).innerHTML = "Incluir";
			document.getElementById("linkIncluir"+codhotel+i).style.color = "";
		}
	}
	
	url = "../../func/hotel/AdicionaCarrinho.asp?str="+Date.parse(new Date())+"&acao=DH"+dados+quarto;
	url = trocaCaracter(url," ","_");
	
	document.getElementById("url").value = url;	
	$("#divReservaHotel").load(url, function(){				
				url = "../../func/portal/carrinho.asp?str="+Date.parse(new Date())+"";
				$("#mostraCarrinho").load(url,function(){
					$("#mostraFiltro").load(document.getElementById("urlPaginaFiltro").value+"?str="+Date.parse(new Date())+dados+quarto,function(){
					//fPesquisa(local); 
					});	
				});	
		});
	
}

function AdicionaValorHotel(campo,moeda, idhotel, idquarto)
{
		document.getElementById("idQuartoAdicionado_"+idhotel).value = document.getElementById("idQuartoAdicionado_"+idhotel).value + "," + idquarto;
		
		total = (document.getElementById("TOTAL_"+campo.value.substring(0,campo.value.length-6)).value);
		if (total == "")
			total = 0;
			
		valorCampo = parseFloat(document.getElementById(campo.value.substring(0,campo.value.length-4)).value.replace(".","").replace(",","."));
		  
		if (document.getElementById("check_"+campo.value.substring(0,campo.value.length-4)).checked)
			document.getElementById("TOTAL_"+campo.value.substring(0,campo.value.length-6)).value = parseFloat(total) + parseFloat(valorCampo);
		else
			document.getElementById("TOTAL_"+campo.value.substring(0,campo.value.length-6)).value = parseFloat(total) - parseFloat(valorCampo);
			
		document.getElementById("Total_hotel_"+campo.value.substring(0,campo.value.length-6)).innerHTML = moeda + " " + document.getElementById("TOTAL_"+campo.value.substring(0,campo.value.length-6)).value
		//alert(document.getElementById("TOTAL_"+campo.value.substring(0,campo.value.length-6)).value);
}

function fVerificaUsuarioLogado(idVendedor, paramUrl)
{
	
		if (idVendedor == "")
		{				
				proximoPasso('../../func/hotel/LoginAgencia.asp?logado='+paramUrl);
		}
		else
		{				
				proximoPasso('../../func/hotel/reserva.asp?logado=SIM'+paramUrl);
		}
}

function fValidaLogin()
{
	
		if(document.getElementById("aceite").checked == false){
			//alert("É necessário o aceite das condições gerais da Europamundo para efetuar a Reserva.");
			AlertarUsuario2("&Eacute; necess&aacute;rio o aceite das condi&ccedil;&otilde;es gerais da Europamundo para efetuar a Reserva.");
			return;
		}
	
		if((ConsisteCampoBranco(document.getElementById("login2").value) == true) || (document.getElementById("login2").value == "login" )){
			//alert("É necessário preencher o campo login.");
			AlertarUsuario2("&Eacute; necess&aacute;rio preencher o campo login.");
			//document.getElementById("login2").focus();
			return;
		}
	
		if((ConsisteCampoBranco(document.getElementById("senha2").value) == true) || (document.getElementById("senha2").value == "senha" )){
			//alert("É necessário preencher o campo senha.");
			AlertarUsuario2("&Eacute; necess&aacute;rio preencher o campo senha.");
			//document.getElementById("senha2").focus();
			return;
		}
	
		
		//chama a tela do valida vendedor pra validar somente vendedor
		// depois chama  o valida login normal de sempre
		$.post("../../func/portal/validaVendedor.asp?str="+Date.parse(new Date()),
			{idl: document.getElementById("login2").value, ids: document.getElementById("senha2").value},
			function(data){ 
				url = "../../func/portal/validaLogin.asp?str="+Date.parse(new Date())+"&origem=";						
				$("#conteudo-mesmo").load(url);
		   }
		);
		//url = "../../func/portal/validaLogin.asp?str="+Date.parse(new Date());
		//url = url + "&login="+document.getElementById("login2").value;
		//url = url + "&senha="+document.getElementById("senha2").value;
		//$("#conteudo-mesmo").load(url);
		
}

	function ValidaFiltroQuartos()
	{
			if (Trim(document.getElementById("pesq-qsgl").options[document.getElementById("pesq-qsgl").selectedIndex].value) != "")
			{
				quarto = quarto+"&SGL="+document.getElementById("pesq-qsgl").options[document.getElementById("pesq-qsgl").selectedIndex].value;
				selectQuarto = true;
			}
			if (Trim(document.getElementById("pesq-qtwn").options[document.getElementById("pesq-qtwn").selectedIndex].value) != "")
			{	
				quarto = quarto+"&TWN="+document.getElementById("pesq-qtwn").options[document.getElementById("pesq-qtwn").selectedIndex].value;
				selectQuarto = true;
			}
			if (Trim(document.getElementById("pesq-qdbl").options[document.getElementById("pesq-qdbl").selectedIndex].value) != "")
			{
				quarto = quarto+"&DBL="+document.getElementById("pesq-qdbl").options[document.getElementById("pesq-qdbl").selectedIndex].value;
				selectQuarto = true;
			}
			if (Trim(document.getElementById("pesq-qtpl").options[document.getElementById("pesq-qtpl").selectedIndex].value) != "")
			{
				quarto = quarto+"&TPL="+document.getElementById("pesq-qtpl").options[document.getElementById("pesq-qtpl").selectedIndex].value;
				selectQuarto = true;
			}
			if (Trim(document.getElementById("pesq-qqpl").options[document.getElementById("pesq-qqpl").selectedIndex].value) != "")
			{
				quarto = quarto+"&QDP="+document.getElementById("pesq-qqpl").options[document.getElementById("pesq-qqpl").selectedIndex].value;
				selectQuarto = true;
			}	
			    
			//pesq-qtwnc
			
			if (Trim(document.getElementById("pesq-qdblc").options[document.getElementById("pesq-qdblc").selectedIndex].value) != "")
			{
				quarto = quarto+"&DBL1XB="+document.getElementById("pesq-qdblc").options[document.getElementById("pesq-qdblc").selectedIndex].value;
				quarto = quarto+"&idadeDBL1XB="+document.getElementById("dbl_1CHD").value;
				selectQuarto = true;
			}
			if (Trim(document.getElementById("pesq-qdbl2c").options[document.getElementById("pesq-qdbl2c").selectedIndex].value) != "")
			{
				quarto = quarto+"&DBL2XB="+document.getElementById("pesq-qdbl2c").options[document.getElementById("pesq-qdbl2c").selectedIndex].value;
				quarto = quarto+"&idadeDBL2XB="+document.getElementById("dbl_2CHD").value;
				selectQuarto = true;
			}
			if (Trim(document.getElementById("pesq-qtplc").options[document.getElementById("pesq-qtplc").selectedIndex].value) != "")
			{
				quarto = quarto+"&TPL1XB="+document.getElementById("pesq-qtplc").options[document.getElementById("pesq-qtplc").selectedIndex].value;
				quarto = quarto+"&idadeTPL1XB="+document.getElementById("tpl_1CHD").value;
				selectQuarto = true;
			}	
	}		
	function fAtualizaOrdenacao(campo,local)
	{
		document.getElementById("ordena").value = campo.value;
		document.getElementById("paginaAtual").value = "0";
		//fPesquisa(local);
	
	}
	function fAtualizaQtdPagina(campo,local)
	{
		document.getElementById("qtdPagina").value = campo.value;
		document.getElementById("paginaAtual").value = "0";
		fPesquisa(local);
	
	}
	
	function fAtualizaEstrela(campo,local)
	{
		document.getElementById("paginaAtual").value = "0";
		document.getElementsByName(campo.id)[0].checked = campo.checked;
		//document.getElementsByName(campo.id);
		//fPesquisa(local);
	
	}
	function fPreencheHotel(campo)
	{
		
		document.getElementById("nomeHotel").value = campo.value;		
		campos = document.getElementsByName("nomeHotelFiltro").length
		for(i=0;i<campos;i++)
			document.getElementsByName("nomeHotelFiltro").item(i).value = campo.value;
		//fPesquisa(local);
	}
	function fPreencheLocalHotel(campo)
	{
		
		document.getElementById("nomeLocalizacao").value = campo.value;		
		campos = document.getElementsByName("nomeLocalFiltro").length
		for(i=0;i<campos;i++)
			document.getElementsByName("nomeLocalFiltro").item(i).value = campo.value;
		//fPesquisa(local);
	}
	function fMudaPagina(valor,local)
	{
		
		document.getElementById("paginaAtual").value = valor;
		fPesquisa(local);
	}
	
function trocaCaracter(string, de, por)
{
		var valorFinal = "";
		valorSplit = string.split(de);;
		for(i = 0; i < valorSplit.length; i++){
			valorFinal = valorFinal + por + valorSplit[i]; 
		}
		valorFinal = valorFinal.substring(1);
		return valorFinal;
}

function teste()
{
alert('existe uma funcao teste!!!!');

/*$(document).ready(function(){
	$("#conteudo").load(url);			
	//fCarregaDivAjax(url,"conteudo" );			
});
$(document).ready(function() {
	$().ajaxStart(function() { $('#textCarregando').show(); });
	$().ajaxStop(function() { $('#textCarregando').hide(); });
});
//*/
}
