﻿//================================================================================================================
//dia 11/09/2009 por Rafael
//================================================================================================================
var url;
function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

/*********************************************************/
function fPesquisaSeguro(){
	//Aqui limpa as sessoes referentes até o passo 4.
	var urlSessao = "../../func/portal/limpa_sessao.asp?str="+Date.parse(new Date())+"&tipo=SEG";
	$("#mostraAlerta").load(urlSessao, function(){
		var param = "&nome_plano="+encodeURI(document.getElementById("pesq-NomPlano").value)+"&cidade_destino="+encodeURI(document.getElementById("pesq-Destino").value)+"&data_inicial="+document.getElementById("pesq-DiaDe").value+"&data_final="+document.getElementById("pesq-DiaAte").value+"&qtd_viajante="+document.getElementById("pesq-QtdViaj").value;
		f_carrega_passo(1,'conteudo-mesmo',param);
	});
}

//************************************************
//Função que carrega os planos
//CarregaPlanos()
//************************************************
function CarregaPlanos(div, nome_plano, cidade_destino, data_inicial, data_final, qtd_viajante){
	eff_SlideFade(div,"hide","fast");
	eff_SlideFade("#prog_menu_viajantes","hide","fast");

	var urlPlanos = "../../func/seguro/busca_planos.asp?nome_plano="+ nome_plano +"&cidade_destino="+ cidade_destino +"&data_inicial="+ data_inicial +"&data_final="+ data_final +"&qtd_viajante="+ qtd_viajante;
	$(div).slideUp("fast", function(){
		$(div).load(urlPlanos, function(){ 
				eff_SlideFade(div,"show","fast");
				//if(document.getElementById("carregaPasso2").value == "S")
				//CarregaRoteiro('#prog_menu_roteiros',document.getElementById("A014_cod_plano_SERIES").value, document.getElementById("A209_cod_grupo_SERIES").value, document.getElementById("A210_cod_subgrupo_SERIES").value, data, ordem, pais, pais_adic_1, pais_adic_2);
			}
		);
	});
}

//************************************************
//Função que carrega os viajantes
//CarregaViajante()
//************************************************
function CarregaViajante(div, cidade_destino, data_inicial, data_final, qtd_viajante, plano_escolhido){
	eff_SlideFade(div,"hide","fast");
	
	var urlViajantes = "../../func/seguro/busca_viajantes.asp?cidade_destino="+ cidade_destino +"&data_inicial="+ data_inicial +"&data_final="+ data_final +"&qtd_viajante="+ qtd_viajante + "&plano_escolhido=" + plano_escolhido;
	$(div).slideUp("fast", function(){
		$(div).load(urlViajantes, function(){eff_SlideFade(div,"show","fast")});
	});
}
/*********************************************************/

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 fRemoveCarrinho(pais, tipo_visto){

	$.blockUI({ message: "Removendo do Carrinho de Compras",
		css: { border: 'none', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .8, color: '#fff' },
		overlayCSS: { backgroundColor: '' }
	});
	
	var dados
	dados = "&A014_cod_plano="+pais;
	dados += "&A015_seq_vlr_plano="+tipo_visto;
	
	url = "../../func/vistos/AdicionaCarrinho.asp?acao=D&str="+Date.parse(new Date())+dados;
	document.getElementById("url").value = url;	
	
	//window.open(url);
						
	$("#divReservaVistos").load(url,function(){
			url = "../../func/portal/carrinho.asp?str="+Date.parse(new Date())+"";
			//window.open(url);
			$("#mostraCarrinho").load(url);
			
	});	
}

function fRemoveOrcamento(pais, tipo_visto){

	$.blockUI({ message: "Removendo do Carrinho de Compras",
		css: { border: 'none', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .8, color: '#fff' },
		overlayCSS: { backgroundColor: '' }
	});
	
	var dados
	dados = "&A014_cod_plano="+pais;
	dados += "&A015_seq_vlr_plano="+tipo_visto;
	
	url = "../../func/vistos/AdicionaCarrinho.asp?acao=D&str="+Date.parse(new Date())+dados;
	document.getElementById("url").value = url;	
	$("#OrcamentoCarrinho").load(url,function(responseText){
		if(responseText == "0"){
			window.location = "../../portal/vst03/default.asp";
		}
		else{
			$("#conteudo-mesmo").load("../../func/vistos/orcamento_vistos.asp?str="+Date.parse(new Date()));
		}
		
	});	
}


function fAdicionaReserva(indice)
{
	document.getElementById("botao_"+indice).innerHTML = "<img src='imagens/bt_incluir-cza.gif' width='111' height='18' border='0' />";
	
	url = ""
	momentoAtual = new Date();	
	
	$.blockUI({ message: "Adicionando ao Carrinho de Compras",
		css: { border: 'none', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .8, color: '#fff' },
		overlayCSS: { backgroundColor: '' }
	});
	
	//deve receber os parâmetros para gravar no arquivo adicionar carrinho
	var dados
	
	dados = "&A014_cod_plano="+document.getElementById("A014_cod_plano_"+indice).value;
	dados += "&A015_seq_vlr_plano="+document.getElementById("A015_seq_vlr_plano_"+indice).value;
	dados += "&A095_qtd_pessoas="+document.getElementById("A027_qtd_viajante_"+indice).value;
	dados += "&A095_vis_dta_embarque="+document.getElementById("A027_dat_inicial_"+indice).value;
	
	url = "../../func/vistos/AdicionaCarrinho.asp?acao=I&str="+Date.parse(new Date())+dados;
	document.getElementById("url").value = url;	
	
	//window.open(url);
						
	$("#divReservaVistos").load(url,function(){
			url = "../../func/portal/carrinho.asp?str="+Date.parse(new Date())+"";
			//window.open(url);
			$("#mostraCarrinho").load(url);
			
	});	
					
}

function FormataData(Campo, teclapres)
{
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	tam = vr.length + 1;
	if (tecla != 9 && tecla != 8 && tecla != 46) 
	{
		if (tam > 2 && tam < 5)
			Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
		if (tam >= 5 && tam <=10)
			Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,4);
	}
}

function VerificaData(digData) {        
	var bissexto = 0;        
	var data = digData;         
	var tam = data.length;        
	if (tam == 10)  {               
		var dia = data.substr(0,2)                
		var mes = data.substr(3,2)                
		var ano = data.substr(6,4)                
		if ((ano > 1900)||(ano < 2100)) {                        
			switch (mes) {                                
				case '01':                                
				case '03':                                
				case '05':                                
				case '07':                                
				case '08':                                
				case '10':                                
				case '12':                                        
					if (dia <= 31) {                                                
						return true;                                        
					}                                        
					break                                                                
				case '04':                                              
				case '06':                                
				case '09':                                
				case '11':                                        
					if  (dia <= 30) {                                                
						return true;                                        
					}                                        
					break                                
				case '02':  
				/* Validando ano Bissexto / fevereiro / dia */                                         
				if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0)) {                                                 
					bissexto = 1;                                         
				}                                         
				if ((bissexto == 1) && (dia <= 29)) {                                                 
					return true;                                                                     
				}                                         
				if ((bissexto != 1) && (dia <= 28)) {                                                 
					return true;                                         
				}                                                               
				break                                                                   
			}                
		}        
	}  
	
	return false;
}
			
function ComparaData(sDataIni,sDataFim){
	var DataIni = '';
  var DataFim = '';
  DataIni = sDataIni.substring(6,10)+sDataIni.substring(3,5)+sDataIni.substring(0,2);
  DataFim = sDataFim.substring(6,10)+sDataFim.substring(3,5)+sDataFim.substring(0,2);
  if (parseInt(DataIni)>parseInt(DataFim)){
  	return false;
  }
  else{  
    return true;
  }
}			
			
function ValidaNumeroInteiro(str) {
  var pattern = "0123456789"
  var i = 0;
  do {
    var pos = 0;
    for (var j=0; j<pattern.length; j++)
      if (str.charAt(i)==pattern.charAt(j)) {
        pos = 1;
        break;
      }
	  else{
		  if(str.charAt(i)=='-' && i==0){
			pos = 1;
			break;
		  }
	  }
    i++;
  } while (pos==1 && i<str.length)  
  if (pos==0) 
    return true;
  return false;
} 
			
var dateDif = {
	dateDiff: function(strDate1,strDate2){
	return (((Date.parse(strDate2))-(Date.parse(strDate1)))/(24*60*60*1000)).toFixed(0);
	}
}	

//Retorna a quantidade de dias entre duas datas considerando a data inicial como sendo um dia
//Ex: diferença entre 01/01/2010 até 02/01/2010 retorna 2 dias.
//param: data1 (dd/mm/aaaa), data2 (dd/mm/aaaa), campo (objeto), tipoRetorno (inteiro)
//	tipoRetorno = 1 - value (para campo text)
//	tipoRetorno = 2 - innerHTML (para campo div)
function diasEntreDatas(data1, data2, campo, tipoRetorno) {

	// Declarações de variáveis
	var mes, data, arrData1, arrData2, novaData1, novaData2, diasEntreDatas;
	// Lista dos meses em inglês
	mes = [];
	mes[0] = "January";
	mes[1] = "February";
	mes[2] = "March";
	mes[3] = "April";
	mes[4] = "May";
	mes[5] = "June";
	mes[6] = "July";
	mes[7] = "August";
	mes[8] = "September";
	mes[9] = "October";
	mes[10] = "November";
	mes[11] = "December";

	arrData1 = data1.split('/');
	novaData1 = mes[(arrData1[1] - 1)] + ' ' + arrData1[0] + ' ' + arrData1[2];

	arrData2 = data2.split('/');
	novaData2 = mes[(arrData2[1] - 1)] + ' ' + arrData2[0] + ' ' + arrData2[2];
	
	diasEntreDatas = dateDif.dateDiff(novaData1, novaData2);
	
	if (tipoRetorno == 1)
		campo.value = parseInt(diasEntreDatas) + 1;
	
	if (tipoRetorno == 2)
		campo.innerHTML = parseInt(diasEntreDatas) + 1;
}			

//funções usadas no filtro.
function dataDiasNoites(tipo)
{	
	if (document.getElementById('pesq-DiaDe').value != "")
	{
		var dateAtual = Date.parse(transferDateString(document.getElementById('hoje').value));
		var novadata = new Date(transferDateString(document.getElementById('pesq-DiaDe').value));
		if ((document.getElementById('pesq-QtdDias').value == "") && (document.getElementById('pesq-DiaAte').value == ""))
			document.getElementById('pesq-QtdDias').value = "1";	
		var noites = document.getElementById('pesq-QtdDias').value;			
		var date1 = Date.parse(transferDateString(document.getElementById('pesq-DiaDe').value));
		
		if (date1 != "" && noites != "" && document.getElementById('pesq-DiaAte').value == "")
		{					
			novadata.setDate(novadata.getDate()+parseInt(noites)-1);
			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-DiaAte').value = dia+'/'+mes+'/'+novadata.getUTCFullYear();					
		}
		
		var date2 = Date.parse(transferDateString(document.getElementById('pesq-DiaAte').value));			
		
		if (tipo == 'data')
		{
			if (date1<dateAtual)
			{
				f_AlertEXEC("A data De n&atilde;o deve ser menor que a data de hoje!", 120, 370,''); 			
				document.getElementById('pesq-DiaDe').value = "";
				document.getElementById('pesq-DiaAte').value = "";
				document.getElementById('pesq-QtdDias').value = "";
				return;
			}
			if (date2<dateAtual)
			{
				f_AlertEXEC("A data At&eacute; n&atilde;o deve ser menor que a data de hoje!", 120, 370,''); 			
				document.getElementById('pesq-DiaAte').value = "";
				document.getElementById('pesq-QtdDias').value = "";
				return;
			}
			if (date2 >= date1 && date1 != null && date2 != null) 
			{
				var difference = Math.round((date2 - date1)/1000/60/60/24);
				document.getElementById('pesq-QtdDias').value = parseInt(difference)+1;
			}	
			else if (date2 <= date1)
			{
				f_AlertEXEC("A data At&eacute; tem que ser maior que a data De!", 120, 370,''); 			
				document.getElementById('pesq-DiaAte').value = "";
				document.getElementById('pesq-QtdDias').value = ""; 
				return;				
			}
		}
		else
		{
			if (date1 != "" && noites != "")
			{				
				novadata.setDate(novadata.getDate()+(parseInt(noites)-1));
				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-DiaAte').value = dia+'/'+mes+'/'+novadata.getUTCFullYear();					
			}
		}	
	}
	else
	{
		f_AlertEXEC("Informe Data De para calcular os dias!", 120, 370,'document.getElementById("pesq-DiaDe").focus();');
		document.getElementById('pesq-DiaAte').value = "";
		document.getElementById('pesq-QtdDias').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 fValidaLogin()
{
	
		if((ConsisteCampoBranco(document.getElementById("login2").value) == true) || (document.getElementById("login2").value == "login" )){
			AlertarUsuario2("&Eacute; necess&aacute;rio preencher o campo login.");
			return;
		}
	
		if((ConsisteCampoBranco(document.getElementById("senha2").value) == true) || (document.getElementById("senha2").value == "senha" )){
			AlertarUsuario2("&Eacute; necess&aacute;rio preencher o campo senha.");
			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;
		//document.getElementById("url").value = url;
		//$("#conteudo-mesmo").load(url);

}			
			
			
			
			
			
			
			