var contextName = "viaje-facil";

$(document).ready(function(){	
	$("#abreIframe").colorbox({width:"800px", height:"700px", iframe:true, overlayClose:false});
	
	$.ajaxSetup({
		cache : false,
		contentType: 'application/x-www-form-urlencoded;charset=UTF-8'
	});

});

function insertNewsletterMail(hotsite) {

	var newsletterMail = $("#newsletterMail").val();
	
	var urlPageTracker = "/"+ contextName +"/" + hotsite + "/newsletter/";

	var valido = validateMail('newsletterMail');
	
	if(valido){
	
		$.get('rga?cmd=Newsletter', { mail :newsletterMail	},
			function(data) {
				if (data == "true") {
					pageTracker._trackPageview(urlPageTracker + "success");
					$("#newsletterDiv").html("Cadastro realizado com sucesso");
				} else {
					pageTracker._trackPageview(urlPageTracker + "error");
					$("#newsletterDiv").append("<br/>Um erro ocorreu durante o cadastro, por favor tente novamente mais tarde");
				}
			}
		);
	
	} else {
		$("#newsletterDiv").html("Email invalido!");
	}
	
}

function submitInformacoesForm(hotsite) {

	$("#formBtn").hide();
	$("#msgAguardeOutrosDestinos").show();
	
	var urlPageTracker = "/"+ contextName +"/" + hotsite + "/informacoes/";
	
	var parameters = {
		nome :$("#nomeInformacoes").val(),
		telefone :$("#telefoneInformacoes").val(),
		dataEmbarque :$("#dataEmbarqueInformacoes").val(),
		dataRetorno :$("#dataRetornoInformacoes").val(),
		destino :$("#destinoInformacoes").val(),
		tipoApartamento :$("#tipoApartamentoInformacoes").val(),
		numeroAdultosInformacoes :$("#numeroAdultosInformacoes").val(),
		numeroCriancasInformacoes :$("#numeroCriancasInformacoes").val(),
		dddTelefoneInformacoes :$("#dddTelefoneInformacoes").val(),
		emailInformacoes :$("#emailInformacoes").val()
		
	};
	
	if((parameters.nome == "") || (parameters.telefone == "") || (parameters.destino == "")){
		
		$("#messageErrorOutrosDestinos").html("Preencha os campos obrigatórios");
		$("#msgAguardeOutrosDestinos").hide();
		$("#msgErroOutrosDestinos").show();
		
	} else {
	
		$.get('rga?cmd=Informacoes', parameters, function(html) {
			
			
			var params = {
					
					to: 'configuration',
					subject: '[ROUTE ONE] Solicitacao de Informacoes',
					html : html
			}
			
			$.post('rga?cmd=SendMail', params,	function(data) {
			
				if (data == "true") {
					pageTracker._trackPageview(urlPageTracker + "success");
					$("#msgAguardeOutrosDestinos").hide();
					$("#msgSucessoOutrosDestinos").show();
					
				} else {
					pageTracker._trackPageview(urlPageTracker + "error");
					$("#msgAguardeOutrosDestinos").hide();
					$("#messageErrorOutrosDestinos").html("Erro. Tente novamente mais tarde");
					$("#msgErroOutrosDestinos").show();
				}
			});
		});
	
	}
}

function faleConosco(hotsite) {

	$("#msgAguarde").show();
	
	var urlPageTracker = "/"+ contextName +"/" + hotsite + "/fale-conosco/";
	
	var parameters = {
		nome :$("#nome").val(),
		mail :$("#mail").val(),
		assunto :$("#assunto").val(),
		mensagem :$("#mensagemContato").val()
	};
	
	if((parameters.nome == "") || (parameters.mail == "") || (parameters.assunto == "") || (parameters.mensagem == "")){
		
		$("#messageErro").html("Preencha os campos obrigatórios");
		$("#msgAguarde").hide();
		$("#msgErro").show();
		
	} else {
	
		$.get('rga?cmd=FaleConosco', parameters,
			function(data) {
				if (data == "true") {
					pageTracker._trackPageview(urlPageTracker + "success");
					$("#msgAguarde").hide();
					$("#msgSucesso").show();
				} else {
					pageTracker._trackPageview(urlPageTracker + "error");
					$("#messageErro").html("Ocorreu um erro, tente novamente mais tarde.");
					$("#msgAguarde").hide();
					$("#msgErro").show();
				}
			}
		);
	
	}
}

function redirectToView(link){
	
	var pacoteID = $("#maisdatas").val();
	
	window.location = link + pacoteID;	
}

function rememberPassword (){
	
	$("#senhaErro").hide();
	$("#senhaSuccess").hide();
	$("#senhaAguarde").show();
	
	var parameters = {
		email :$("#enviaEmail").val()
	};
	
	if(parameters.email == ""){
		
		$("#senhaAguarde").hide();
		$("#messageErrorLogin").html("Preencha seu mail");
		$("#senhaErro").show();
		$("#senhaSolicitar").show();
		
	} else {
	
		$.get('rga?cmd=RememberPassword', parameters,
			function(data) {
				if (data == "true") {
					$("#senhaAguarde").hide();
					$("#senhaSuccess").show();
					$("#senhaSolicitar").show();
				} else {
					$("#senhaAguarde").hide();
					$("#messageErrorLogin").html(data);
					$("#senhaErro").show();
					$("#senhaSolicitar").show();
				}
			}
		);
	}
	
}

function showButtonInformacoes(){

	$("#msgErroOutrosDestinos").hide();
	$("#msgSucessoOutrosDestinos").hide();
	$("#formBtn").show();
		
}

function showButtonOrcamento(){

	$("#msgErroOrcamento").hide();
	$("#msgSucessoOrcamento").hide();
	$("#btnSolicitarOrcamento").show();
		
}

function alertPassageiroDocument(statusQuarto, statusPassageiro){
	
	var id = "_" + statusQuarto + "_" + statusPassageiro;
	
	var selectValue = $("#tipoDocumento" + id).val();
	
	if(selectValue == 'Passaporte'){
		$("#mensagemRG" + id).hide();
		$("#mensagemPassaporte" + id).show();
	} else {
		$("#mensagemPassaporte" + id).hide();
		$("#mensagemRG" + id).show();
	}			
}

function confirmReservaView(url){
	
	$("#aguardeConfirmReserva").show();
	$("#confirmReservaButton").hide();
	
	window.location=url;
	
}

function normalizeForm(formId) {
	
	var text;
	var value;
	
	$("#" + formId + " :input").each(function(){
		
		value = $(this).val();
		text = normalizeText(value);
		
		$(this).attr("value", text);
		
	});
	
	$("#" + formId + " :textarea").each(function(){
		
		value = $(this).val();
		text = normalizeText(value);
		
		$(this).attr("value", text);
		
	});
	
}
	
function normalizeText(text) {
	
	if(text == undefined) {
		return undefined;
	}
	
	text = text.replace(new RegExp('[áãâã]','gi'), 'a'); 
	text = text.replace(new RegExp('[éèê]','gi'), 'e'); 
	text = text.replace(new RegExp('[íìî]','gi'), 'i'); 
	text = text.replace(new RegExp('[óòôõ]','gi'), 'o'); 
	text = text.replace(new RegExp('[úùû]','gi'), 'u'); 
	text = text.replace(new RegExp('[ç]','gi'), 'c');
	
	text = text.replace(new RegExp('[ÁÃÂÃ]','gi'), 'A'); 
	text = text.replace(new RegExp('[ÉÈÊ]','gi'), 'E'); 
	text = text.replace(new RegExp('[ÍÌÎ]','gi'), 'I'); 
	text = text.replace(new RegExp('[ÓÒÔÕ]','gi'), 'O'); 
	text = text.replace(new RegExp('[ÚÙÛ]','gi'), 'U'); 
	text = text.replace(new RegExp('[Ç]','gi'), 'C');

	return text;
}; 
