var PlanoVS = 0;
var ValorFinal;
var Nc = 1;
var popUpsBlocked = false;
var DoNotShowPrice = false;

var DataNascFam = "<select size=\"1\" name=\"Dia_NascFam\"><option>Dia</option>"
for (i = 1; i < 32; i++)
{ 
	D = i;
	if (i < 10)	{D = "0" + i;}
	DataNascFam = DataNascFam + "<option>" + D + "</option>"
}
DataNascFam = DataNascFam + "</select>&nbsp;"
DataNascFam = DataNascFam + "<select size=\"1\" name=\"Mes_NascFam\"><option>Mês</option><option>Janeiro</option><option>Fevereiro</option><option>Março</option><option>Abril</option><option>Maio</option><option>Junho</option><option>Julho</option><option>Agosto</option><option>Setembro</option><option>Outubro</option><option>Novembro</option><option>Dezembro</option></select>&nbsp;"
DataNascFam = DataNascFam + "<select size=\"1\" name=\"Ano_NascFam\"><option>Ano</option>"
for (i = 7; i < 110; i++)
{ 
	DataNascFam = DataNascFam + "<option>" + (1900+i) + "</option>"
}
DataNascFam = DataNascFam + "</select>&nbsp;"

function VerPopup() {
//verifica se popup bloqueado - fora de uso agora

	var mine = window.open('','','width=1,height=1,left=0,top=0 ,scrollbars=no');
	if(mine == null)
		{
		popUpsBlocked = true;
		window.alert("Você está utilizando um bloqueador de popup.\rPara garantir o bom funcionamento do site, favor habilitá-lo.");
		}
	else
		{
		var popUpsBlocked = false;
		mine.close();
	}

}


//disable return key on form - validate_form or return false
function checkCR(evt) {
var evt  = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = checkCR;

function validaCPF(doc){
var i;
s = doc;
s = s.replace("-","");
s = s.replace(".","");
s = s.replace(".","");
var c = s.substr(0,9);
var dv = s.substr(9,2);
var d1 = 0;
for (i = 0; i < 9; i++)
{
d1 += c.charAt(i)*(10-i);
}
if (d1 == 0){
alert("CPF Inválido - verifique-o por favor!")
return false;
}
d1 = 11 - (d1 % 11);
if (d1 > 9) d1 = 0;
if (dv.charAt(0) != d1)
{
alert("CPF Inválido - verifique-o por favor!")
return false;
}
d1 *= 2;
for (i = 0; i < 9; i++)
{
d1 += c.charAt(i)*(11-i);
}
d1 = 11 - (d1 % 11);
if (d1 > 9) d1 = 0;
if (dv.charAt(1) != d1)
{
alert("CPF Inválido - verifique-o por favor!")
document.myform.CPF.focus();
return false;
}
return true;
}

function validate_form(pagto){
document.myform.Nome.value = document.myform.Nome.value.toUpperCase();
document.myform.Origem.value = document.myform.Origem.value.toUpperCase();
document.myform.Destino.value = document.myform.Destino.value.toUpperCase();
document.myform.Voo.value = document.myform.Voo.value.toUpperCase();
document.myform.email.value = document.myform.email.value.toUpperCase();

if ( VerifyIdaVolta() == false ) {
	return;
	}
if ( checkBenef() == false) {
	return;
	}
	
if ( document.myform.Nome.value == "" ) {
	alert ( "Informe o seu nome completo por favor." );
	document.myform.Nome.focus();
	return;
	}
if ( validaCPF(document.myform.CPF.value) == false ) {
	document.myform.CPF.focus()
	return;
	}
if ( document.myform.Dia_Nasc.selectedIndex == 0 ) {
	alert ( "Informe o dia de seu nascimento por favor." );
	document.myform.Dia_Nasc.focus();
	return;
	}
if ( document.myform.Mes_Nasc.selectedIndex == 0 ) {
	alert ( "Informe o mês de seu nascimento por favor." );
	document.myform.Mes_Nasc.focus();
	return;
	}
if ( document.myform.Ano_Nasc.selectedIndex == 0 ) {
	alert ( "Informe o ano de seu nascimento por favor." );
	document.myform.Ano_Nasc.focus();
	return;
	}
if ( calcular_idade((document.myform.Dia_Nasc.selectedIndex)+"/"+(document.myform.Mes_Nasc.selectedIndex)+"/"+(document.myform.Ano_Nasc.selectedIndex+1906)) < 14 ) {
	alert ( "Para segurados com menos de 14 anos haverá apenas o reembolso de despesas limitado ao valor de R$ 5.000,00, conforme estipulado em nossas condições gerais." );
	//document.myform.Ano_Nasc.focus();
	//return;
	}
if ( echeck(document.myform.email.value) == false ) {
	alert ( "O primeiro endereço de e-mail para envio do comprovante é inválido - verifique-o por favor." );
	document.myform.email.focus();
	return;
	}
if ( echeck(document.myform.emailCC.value) == false ) {
	alert ( "O segundo endereço de e-mail para envio do comprovante é inválido - verifique-o por favor." );
	document.myform.emailCC.focus();
	return;
	}
//if ( document.myform.DDD.value == "" ) {
//	alert ( "Informe o DDD de sua cidade por favor." );
//	document.myform.DDD.focus();
//	return;
//	}
//if ( document.myform.telefone.value == "" ) {
//	alert ( "Informe o seu telefone por favor." );
//	document.myform.telefone.focus();
//	return;
//	}
if ( document.myform.Origem.value == "" ) {
	alert ( "Informe a origem de sua viagem." );
	document.myform.Origem.focus();
	return;
	}
if ( document.myform.Destino.value == "" ) {
	alert ( "Informe o seu destino de viagem." );
	document.myform.Destino.focus();
	return;
	}
if ( PlanoVS > 4 && document.myform.DCode.selectedIndex == 0) {
	alert ( "Informe a região do destino de sua viagem." );
	document.myform.DCode.focus();
	return;
	}
if ( PlanoVS > 4 && pagto == "boleto bancário") {
	alert ( "O VoeSeguro Full Protection só pode ser contratado mediante pagamento com cartão de crédito." );
	document.myform.Adesao.focus();
	return;
	}
if ( document.myform.Adesao.checked == false ) {
	alert ( "Para continuar aceite o Termo de Adesão." );
	document.myform.Adesao.focus();
	return;
	}
	
document.myform.pagto.value = pagto;
document.myform.PlanoVS.value = PlanoVS;
document.myform.ValorFinal.value = ValorFinal;


if ( document.myform.Cadastrar.checked == true ) {
	document.myform.novocadastro.value = "sim";
	}

if (getCookie("lomadee%5Ftraffic") != null) { 
	//alert(getCookie("lomadee%5Ftraffic"));
	var newElement = document.createElement("input");
	newElement.setAttribute("type", "hidden");
	newElement.setAttribute("name", "lomadee");
	newElement.setAttribute("value", "1");
	document.myform.appendChild(newElement);
	};
	
if (pagto == "boleto bancário" || pagto == "american express" || pagto == "visaCC" || pagto == "visa electron" || pagto == "mastercard" || pagto == "diners") {
	document.myform.submit();
	if(popUpsBlocked)
	{
		//window.alert("Você está utilizando um bloqueador de popup.\rPara garantir o bom funcionamento do site, habilite esta opção quando solicitado por este navegador.");
	}

	if (pagto != "boleto bancário") {
		//alert ("Caso a conexão com a operadora de seu cartão de crédito apresente problemas volte à página de contratação e tente novamente, ou use outro meio de pagamento.");
	}
	//return true;
}
else
{
	alert ("Estamos finalizando a implantação dos meios de pagamento - já disponíveis: boleto bancário, american express, visa, visa electron, mastercard e diners."); 
}
	
		
}

function echeck(str) {

		if (Trim(str) == "") {
			// não obrigatorio
			return true
		}
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

		 if (str.indexOf(",")!=-1){
		    return false
		 }
		 
		if (str.indexOf(";")!=-1){
		    return false
		 }

		if (str.indexOf(":")!=-1){
		    return false
		 }


 		 return true					
	}

function Trim(str) {
	return str.replace(/^\s+|\s+$/g,"");
	}

function setToday()
{
var today = new Date()
document.myform.Dia_Ida.selectedIndex = today.getDate() - 1
document.myform.Mes_Ida.selectedIndex = today.getMonth() 
document.myform.Ano_Ida.selectedIndex = today.getFullYear() - 2009
enableRoundTrip();
PlanoVS = 5;
document.myform.Origem.value = "qualquer";
document.myform.Voo.value = "todos O.A.G";
document.myform.Destino.value = "qualquer";
document.myform.Origem.disabled = true;
document.myform.Voo.disabled = true;
document.myform.Destino.disabled = true;
document.myform.CiaAerea.selectedIndex = 0;
document.myform.CiaAerea.disabled = true;
}

function setNewDate(data)
{
var array_data = data.split("/");
document.myform.Dia_Ida.selectedIndex = parseInt(array_data[0])-1; 
document.myform.Mes_Ida.selectedIndex = parseInt(array_data[1])-1; 
document.myform.Ano_Ida.selectedIndex = parseInt(array_data[2]) - 2009;
document.myform.Dia_Volta.selectedIndex = parseInt(array_data[0])-1; 
document.myform.Mes_Volta.selectedIndex = parseInt(array_data[1])-1; 
document.myform.Ano_Volta.selectedIndex = parseInt(array_data[2]) - 2009;
disableRoundTrip();
}

function enableRoundTrip()
{
showFinalDate();
document.myform.Origem.disabled = false;
document.myform.Voo.disabled = false;
document.myform.Destino.disabled = false;
document.myform.CiaAerea.disabled = false;
document.myform.Origem.value = "";
document.myform.Voo.value = "";
document.myform.Destino.value = "";
//FinalDate(10);
//alert("Informe as datas de ida e volta, bem como as cidades de origem e destino de sua viagem.");
}

function disableRoundTrip()
{
hideFinalDate();
FinalDate(30);
}

function enableSemestral()
{
hideFinalDate();
FinalDate(184);
}

function enableAnual()
{
hideFinalDate();
FinalDate(365);
}

function hideFinalDate() {
	document.myform.Dia_Volta.disabled = true;
	document.myform.Mes_Volta.disabled = true;
	document.myform.Ano_Volta.disabled = true;
	document.getElementById("CFC").style.visibility = "hidden";
	document.myform.Origem.value = "qualquer";
	document.myform.Voo.value = "todos O.A.G";
	document.myform.Destino.value = "qualquer";
	document.myform.Origem.disabled = true;
	document.myform.Voo.disabled = true;
	document.myform.Destino.disabled = true;
	document.myform.CiaAerea.selectedIndex = 0;
	document.myform.CiaAerea.disabled = true;
}

function showFinalDate() {
	document.myform.Dia_Volta.disabled = false;
	document.myform.Mes_Volta.disabled = false;
	document.myform.Ano_Volta.disabled = false;
	document.getElementById("CFC").style.visibility = "visible";
}

function FinalDate(N)
{
var hDate = new Date;
var iDate = new Date;
//Bug Mozilla/Safari?
var BM = 0;
if (hDate.getYear() < 2000) {
	BM = 1900;
}
//verificar data de ida
iDate.setDate((document.myform.Dia_Ida.selectedIndex+1));
iDate.setMonth((document.myform.Mes_Ida.selectedIndex));  //jan=0
iDate.setYear((document.myform.Ano_Ida.selectedIndex+2009));
if (iDate < hDate) {
	//acertar
	document.myform.Dia_Ida.selectedIndex = (hDate.getDate()-1);
	document.myform.Mes_Ida.selectedIndex = (hDate.getMonth());
	document.myform.Ano_Ida.selectedIndex = (hDate.getYear()+BM-2009);
}
var fDate = new Date;
fDate.setMonth((document.myform.Mes_Ida.selectedIndex));  //jan=0
fDate.setYear((document.myform.Ano_Ida.selectedIndex+2009));
fDate.setDate((document.myform.Dia_Ida.selectedIndex+N));
document.myform.Dia_Volta.selectedIndex = (fDate.getDate()-1);
document.myform.Mes_Volta.selectedIndex = (fDate.getMonth());
document.myform.Ano_Volta.selectedIndex = (fDate.getYear()+BM-2009);
//acertar calendario
document.myform.inicio_contrato.value = (document.myform.Dia_Ida.selectedIndex+1)+"-"+(document.myform.Mes_Ida.selectedIndex+1)+"-"+(document.myform.Ano_Ida.selectedIndex+2009);
document.myform.fim_contrato.value = (document.myform.Dia_Volta.selectedIndex+1)+"-"+(document.myform.Mes_Volta.selectedIndex+1)+"-"+(document.myform.Ano_Volta.selectedIndex+2009);
}

// verificar datas de ida e volta -> tem de ser maiores que hoje
function VerifyIdaVolta() {
var hDate = new Date;
var iDate = new Date;
//Bug Mozilla/Safari?
var BM = 0;
if (hDate.getYear() < 2000) {
	BM = 1900;
}
//verificar data de ida
iDate.setDate((document.myform.Dia_Ida.selectedIndex+1));
iDate.setMonth((document.myform.Mes_Ida.selectedIndex));  //jan=0
iDate.setYear((document.myform.Ano_Ida.selectedIndex+2009));
if (iDate < hDate) {
	//acertar
	alert("A data de ida não pode anterior à de hoje.");
	document.myform.Dia_Ida.selectedIndex = (hDate.getDate()-1);
	document.myform.Mes_Ida.selectedIndex = (hDate.getMonth());
	document.myform.Ano_Ida.selectedIndex = (hDate.getYear()+BM-2009);
	document.myform.Dia_Ida.focus();
	showPrice();
	return false;
}
//verificar volta
iDate.setDate((document.myform.Dia_Volta.selectedIndex+1));
iDate.setMonth((document.myform.Mes_Volta.selectedIndex));  //jan=0
iDate.setYear((document.myform.Ano_Volta.selectedIndex+2009));
if (iDate < hDate) {
	//acertar
	alert("A data da volta tem de ser igual ou posterior à de ida.");
	document.myform.Dia_Volta.selectedIndex = (hDate.getDate()-1);
	document.myform.Mes_Volta.selectedIndex = (hDate.getMonth());
	document.myform.Ano_Volta.selectedIndex = (hDate.getYear()+BM-2009);
	document.myform.Dia_Volta.focus();
	showPrice();
	return false;
}
}

//retorno do calendario após a escolha da data
function LocalJS(N) {
	//alert("Local Javascript:"+N);
	// em campo (inicio_contrato ou fim_contrato) teremos a data no formato dd-mm-aaaa
	if (N == 0) {
		X = document.myform.inicio_contrato.value.split("-");
		document.myform.Dia_Ida.selectedIndex = X[0]-1;
		document.myform.Mes_Ida.selectedIndex = X[1]-1;
		document.myform.Ano_Ida.selectedIndex = 0;
		if (X[2] > 2007) {
			document.myform.Ano_Ida.selectedIndex = X[2]-2009;
			}
		FinalDate(30);
		}
		else {
		X = document.myform.fim_contrato.value.split("-");
		document.myform.Dia_Volta.selectedIndex = X[0]-1;
		document.myform.Mes_Volta.selectedIndex = X[1]-1;
		document.myform.Ano_Volta.selectedIndex = 0;
		if (X[2] > 2007) {
			document.myform.Ano_Volta.selectedIndex = X[2]-2009;
			}
		}
	showPrice();
}

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla, Safari;


	if(document.all) { // Internet Explorer
		nTecla = evtKeyPress.keyCode; }
	else {
	//if(document.layers) { // Nestcape
		nTecla = evtKeyPress.which;
	}
	
	sValue = objForm[strField].value;
	
	// Limpa todos os caracteres de formatação que
	// já estiverem no campo.
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( " ", "" );
	sValue = sValue.toString().replace( " ", "" );
	fldLen = sValue.length;
	mskLen = sMask.length;
	
	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;
	
	// Caso seja pressionado backspace, então ignora a verificação da máscara
	if (nTecla !=8){
	   while (i <= mskLen) {
		  bolMask = false;
		  bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
		  bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
	
		  if (bolMask) {
			 sCod += sMask.charAt(i);
			 mskLen++; 
		  } else {
			 sCod += sValue.charAt(nCount);
		     	 nCount++;
		  }
	
	       i++;
	   }	
	   objForm[strField].value = sCod;
	   
	}

	if (nTecla != 8) { // backspace
		if (sMask.charAt(i-1) == "9") { // apenas números...
			return ((nTecla > 47) && (nTecla < 58)); 
		} // números de 0 a 9
		else { // qualquer caracter...
			return true;
		} 
	} else {
		return true;
	}
}

function calcular_idade(data){

	//alert(data);
    //calculo a data de hoje
    hoje=new Date()
    //alert(hoje)

    //calculo a data que recebo
    //descomponho a data em um array
    var array_data = data.split("/")
    //se o array nao tem tres partes, a data eh incorreta
    if (array_data.length!=3) {return false; }

    //comprovo que o ano, mes, dia são corretos
    var ano
    ano = parseInt(array_data[2]);
    if (isNaN(ano)) { return false; }

    var mes
    mes = parseInt(array_data[1]);
    if (isNaN(mes)) { return false; }

    var dia
    dia = parseInt(array_data[0]);
    if (isNaN(dia)) { return false; }

    //subtraio os anos das duas datas
    
    idade=hoje.getYear()+ 1900 - ano - 1; //-1 porque ainda nao fez anos durante este ano
	
    //se subtraio os meses e for menor que 0 entao nao cumpriu anos. Se for maior sim ja cumpriu
    if (hoje.getMonth() + 1 - mes < 0) { //+ 1 porque os meses comecam em 0
       return idade;
       }
       
    if (hoje.getMonth() + 1 - mes > 0) {
       return idade+1;
       }

    //entao eh porque sao iguais. Vejo os dias
    //se subtraio os dias e der menor que 0 entao nao cumpriu anos. Se der maior ou igual sim que já cumpriu
    if (hoje.getUTCDate() - dia >= 0) {
       return idade + 1;
      	}

    return idade;
} 


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function Start(page) {
OpenWin = this.open(page, "Definitions", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=437,height=750");

}

function uppercase(e) {
	if(document.all) { // Internet Explorer
		key = e.keyCode;
  		if ((key > 0x60) && (key < 0x7B)) {
  				e.keyCode = key-0x20;

  			}
  		}
		else {
			//if(document.layers) { // Nestcape
			key = e.which;
			//this = this.toUpperCase();
			//alert (key-0x20);
		}
}

function FocusStart() {
//document.myform.Nome.focus();
}

function startBenef(){

}


function addContent(){
    //add a row
	if (document.getElementById('benef').rows.length == 1) {
   		alert("Informe o nome completo e percentual que caberá ao beneficiário.");
		}
    var x=document.getElementById('benef').insertRow(0)
    var y=x.insertCell(0)
    var z=x.insertCell(1)
    var t=x.insertCell(2)
    var x=document.getElementById('benef').rows
    var y=x[0].cells
    y[0].innerHTML="<input type=\"text\" name=\"NB\" size=\"32\" value=\"\">";
    y[1].innerHTML="<input type=\"text\" name=\"PB\" size=\"3\" value=\"\">%";
    var s = "<input type=\"button\" value=\"-\" onclick=\"deleteRow(this);\">";
    y[2].innerHTML=s
	document.myform.AB.value = "   +   ";
	document.myform.NB[0].focus();		//explorer only
}

function deleteRow(r){
	var i=r.parentNode.parentNode.rowIndex;
	document.getElementById('benef').deleteRow(i);
	if (document.getElementById('benef').rows.length == 1) {
   		document.myform.AB.value ="Alterar";
		}
}

function checkBenef() {		// ok for IE only
	if (document.getElementById('benef').rows.length > 1 && navigator.userAgent.toLowerCase().indexOf("gecko") == -1) {
		var T = 0;
		for (i = 0; i < document.getElementById('benef').rows.length -1; i++) {
			var x=document.getElementById('benef').rows
			var y=x[i].cells
			P = String(y[1].innerHTML).substring(y[1].innerHTML.indexOf("value="))
			P = String(P).substring(P.indexOf("=")+1)
			P = String(P).split(" ")
			y[0].innerHTML = y[0].innerHTML.toUpperCase(); 
			T += parseFloat(P[0]);
			}
		if (T != 100){
			alert("A somatória dos percentuais deve ser igual a 100% (o valor encontrado foi de " + T + "%)");
			return false;
			}
	}
	return true;
}

function addFamily(){
    //add a row
	if (document.getElementById('familia').rows.length == 1) {
   		//alert("Informe o nome, data de nascimento e cpf, identidade ou passaporte do familiar.");
		}
    
    var x=document.getElementById('familia').insertRow(0)
    var y=x.insertCell(0)
    var z=x.insertCell(1)
    var t=x.insertCell(2)
    var x=document.getElementById('familia').rows
    var y=x[0].cells
    y[0].innerHTML="Nome:";
    y[1].innerHTML="<input type=\"text\" name=\"NF\" size=\"25\" value=\"\">";
    var s = "<input type=\"button\" value=\"-\" onclick=\"deleteRowsFam(this);\">";
    y[2].innerHTML=s

    var x=document.getElementById('familia').insertRow(1)
    var y=x.insertCell(0)
    var z=x.insertCell(1)
    var t=x.insertCell(2)
    var x=document.getElementById('familia').rows
    var y=x[1].cells
    y[0].innerHTML="CPF, Identidade ou Passaporte:";
    y[1].innerHTML="<input type=\"text\" name=\"ID\" size=\"25\" value=\"\">";
    y[2].innerHTML="";
    
    var x=document.getElementById('familia').insertRow(2)
    var y=x.insertCell(0)
    var z=x.insertCell(1)
    var t=x.insertCell(2)
    var x=document.getElementById('familia').rows
    var y=x[2].cells
    y[0].innerHTML="Data de nascimento:";
    y[1].innerHTML=DataNascFam;
    y[2].innerHTML="";
    
	document.myform.AddF.value = "   +   ";
	Nc += 1;
	showPrice();
	document.myform.NF[0].focus();		//explorer only
}

function deleteRowsFam(r){
	var i=r.parentNode.parentNode.rowIndex;
	document.getElementById('familia').deleteRow(i+2);
	document.getElementById('familia').deleteRow(i+1);
	document.getElementById('familia').deleteRow(i);
	if (document.getElementById('familia').rows.length == 1) {
   		document.myform.AddF.value ="Adicionar";
		}
	Nc -= 1;
	showPrice();
}

function applyProm() {
	alert("Código promocional inválido - verifique-o!");
	return;
	//alert(document.myform.CPROM.value.toUpperCase());
	if (document.myform.CPROM.value.toUpperCase() == String.fromCharCode(76, 83, 77, 48, 57)  || (document.myform.CPROM.value.toUpperCase() == String.fromCharCode(76, 83, 74, 88, 57))) {
		alert("Ao final do processo você receberá o desconto referente a este código promocional (válido para os planos citados na propaganda).");
		}
	else
		{
		alert("Código promocional inválido - verifique-o!");
		}
	showPrice();
}

function applyBenef(Nome, Perc){
    var x=document.getElementById('benef').insertRow(0)
    var y=x.insertCell(0)
    var z=x.insertCell(1)
    var t=x.insertCell(2)
    var x=document.getElementById('benef').rows
    var y=x[0].cells
    y[0].innerHTML="<input type=\"text\" name=\"NB\" size=\"30\" value='" + Nome +"'>";
    y[1].innerHTML="<input type=\"text\" name=\"PB\" size=\"5\" value='" + Perc + "'>%";
    var s = "<input type=\"button\" value=\"-\" onclick=\"deleteRow(this);\">";
    y[2].innerHTML=s
	document.myform.AB.value = "   +   ";
}

// esconder instrução do cadastro
function hideCadastro() {
	document.getElementById("cadastro").style.display = "none";
}

// esconder solicitações Round Trip
function hideRTS() {
	document.getElementById("_origem").style.display = "none";
}

// esconder pagtos e/ou VEX
function VEX(){
	alert(sessionValue);
	if (sessionValue == "VEX") {
		alert ("A fim de agilizar sua contratação através deste hotspot VEX o único meio de pagamento possível será através de boleto bancário para daqui a 2 dias");
		hidePags();
	}
		else {
			hideVEX();
	}
}

function hidePags(){
	document.getElementById("_Pags").style.display = "none";
}

function hideVEX(){
	document.getElementById("_VEX").style.display = "none";
}

function showPrice() {
	// verifica plano escolhido e acerta data de retorno
	switch (PlanoVS)
		{ 
		case 2: { FinalDate(30); break; }
		case 3: { FinalDate(184); break; }
		case 4: { FinalDate(365); break; }
		}	
	var i;
	//calcular numero de dias
	var iDate = new Date();
	iDate.setDate((document.myform.Dia_Ida.selectedIndex+1));
	iDate.setMonth((document.myform.Mes_Ida.selectedIndex));  //jan=0
	iDate.setYear((document.myform.Ano_Ida.selectedIndex+2009));
	var vDate = new Date();
	vDate.setDate((document.myform.Dia_Volta.selectedIndex+1));
	vDate.setMonth((document.myform.Mes_Volta.selectedIndex));  //jan=0
	vDate.setYear((document.myform.Ano_Volta.selectedIndex+2009));
	var one_day=86400000
	i = Math.round((vDate.getTime()-iDate.getTime())/(one_day));
	i = i+1;
	if (i < 1)
		{
			i = 30;
			FinalDate(i);
		}
	document.getElementById('DIASC').innerHTML = i;
	//mínimo de dias para planos full protection
	if (PlanoVS == 9 && i < 3) { alert("No plano escolhido o mínimo de permanência é de 3 dias."); document.getElementById('DIASC').innerHTML = 3; FinalDate(3); }
	if (PlanoVS == 7 && i < 2) { alert("No plano escolhido o mínimo de permanência é de 2 dias."); document.getElementById('DIASC').innerHTML = 2; FinalDate(2); }
	if (i < 5 && (PlanoVS == 5 || PlanoVS == 6 || PlanoVS == 8)) { alert("No plano escolhido o mínimo de permanência é de 5 dias."); document.getElementById('DIASC').innerHTML = 5; FinalDate(5); }
	if (i<5)	{	i=5; }
	//calcular adicional aéreo
	AER=28;
	switch (PlanoVS)
		{
		case 1: { AER=17.9; i=0; ValorFinal = AER; break; }
		case 2: { AER=27.9; i=0; ValorFinal = AER; break; }
		case 3: { AER=159; i=0; ValorFinal = AER; break; }
		case 4: { AER=300; i=0; ValorFinal = AER; break; }
		case 5: { ValorFinal = ((i*11.5)+AER); break; }
		case 6: { ValorFinal = ((i*10.3)+AER); break; }
		case 7: { ValorFinal = ((i*7.3)+AER); break; }
		case 8: { ValorFinal = ((i*10.9)+AER); break; }
		case 9: { ValorFinal = ((i*4)+AER); break; }
		//case 10: { ValorFinal = (((parseInt(i/7)+1)*56)+AER); break; }
		//case 11: { ValorFinal = ((parseInt(i/367)+1)*1199); break; }
		}
	if (DoNotShowPrice == false)
		{
		document.getElementById('PP').innerHTML = (((i*11.5)+AER).toFixed(2)).replace(".",",");
		document.getElementById('PG').innerHTML = (((i*10.3)+AER).toFixed(2)).replace(".",",");
		document.getElementById('PS').innerHTML = (((i*7.3)+AER).toFixed(2)).replace(".",",");
		document.getElementById('PE').innerHTML = (((i*10.9)+AER).toFixed(2)).replace(".",",");
		document.getElementById('PB').innerHTML = (((i*4)+AER).toFixed(2)).replace(".",",");
		}
		
	//switch (PlanoVS)
	//	{
	//	case 5,6,7,8,9:
	//		{
	//		document.getElementById('PP').innerHTML = (((i*11.5)+AER).toFixed(2)).replace(".",",");
	//		document.getElementById('PG').innerHTML = (((i*10.3)+AER).toFixed(2)).replace(".",",");
	//		document.getElementById('PS').innerHTML = (((i*7.3)+AER).toFixed(2)).replace(".",",");
	//		document.getElementById('PE').innerHTML = (((i*10.9)+AER).toFixed(2)).replace(".",",");
	//		document.getElementById('PB').innerHTML = (((i*4)+AER).toFixed(2)).replace(".",",");
	//		}
		//case 10,11:
		//	{
		//	document.getElementById('PS').innerHTML = ((((parseInt(i/7)+1)*56)+AER).toFixed(2)).replace(".",",");
		//	document.getElementById('PM').innerHTML = (((parseInt(i/367)+1)*1199).toFixed(2)).replace(".",",");
		//	}
	//	}

	ValorFinal = ValorFinal * Nc;
	if (Nc > 1) { ValorFinal *= 0.9; }
	if (ValorFinal > 100)
		{
		document.getElementById("3xSJ").style.visibility = "visible";
		}
		else
		{
		document.getElementById("3xSJ").style.visibility = "hidden";
		}
	document.getElementById('PrF').innerHTML = (ValorFinal.toFixed(2)).replace(".",",");
}

function chgImgFP(img) {
clearAER();
switch (img)
      	{
		case "EXE": {	clearFP(); PlanoVS=5; document[img].src="marked.png"; document.getElementById('PPBG').style.backgroundColor='#CC0000'; break; }
		case "BUS": {	clearFP(); PlanoVS=6; document[img].src="marked.png";  document.getElementById('PGBG').style.backgroundColor='#CC0000'; break; }
		case "BAS": {	clearFP(); PlanoVS=7; document[img].src="marked.png";  document.getElementById('PSBG').style.backgroundColor='#CC0000'; break; }
		case "EUR": {	clearFP(); PlanoVS=8; document[img].src="marked.png";  document.getElementById('PEBG').style.backgroundColor='#CC0000'; break; }
		case "BRA": {	clearFP(); PlanoVS=9; document[img].src="marked.png";  document.getElementById('PBBG').style.backgroundColor='#CC0000'; break; }
		//case "STU": {	clearFPSM(); PlanoVS=10; document[img].src="marked.png";  document.getElementById('PSBG').style.backgroundColor='#CC0000'; break; }
		//case "MUL": {	clearFPSM(); PlanoVS=11; document[img].src="marked.png";  document.getElementById('PMBG').style.backgroundColor='#CC0000'; break; }
		}
hideFinalDate();
showFinalDate();
showPrice();
// mostrar preços
var aRows=document.getElementById('comp').rows;
aRows[34].style.display='';
aRows[36].style.display='';

}

function chgImgAER(img) {
if (DoNotShowPrice == false) {
	clearFP();
	}
clearAER();
document[img].src="marked_mini.png"
switch (img)
      	{
		case "RTR": {	PlanoVS=1; enableRoundTrip(); break;}
		case "MES": {	PlanoVS=2; disableRoundTrip(); break;}
		case "SEM": {	PlanoVS=3; enableSemestral(); break;}
		case "ANO": {	PlanoVS=4; enableAnual(); break;}
		}
showPrice();
var aRows=document.getElementById('comp').rows;
aRows[34].style.display='none';
}

function chgImgAER_2(img) {
clearFPSM();
clearAER();
document[img].src="marked_mini.png"
switch (img)
      	{
		case "RTR": {	PlanoVS=1; enableRoundTrip(); break;}
		case "MES": {	PlanoVS=2; disableRoundTrip(); break;}
		case "SEM": {	PlanoVS=3; enableSemestral(); break;}
		case "ANO": {	PlanoVS=4; enableAnual(); break;}
		}
showPrice();
var aRows=document.getElementById('comp').rows;
aRows[36].style.display='none';
}

function clearFP() {
	document["EXE"].src="nomarked.png"
	document["BUS"].src="nomarked.png"
	document["BAS"].src="nomarked.png"
	document["EUR"].src="nomarked.png"
	document["BRA"].src="nomarked.png"
	document.getElementById('PPBG').style.backgroundColor='#333333';
	document.getElementById('PSBG').style.backgroundColor='#333333';
	document.getElementById('PGBG').style.backgroundColor='#333333';
	document.getElementById('PEBG').style.backgroundColor='#333333';
	document.getElementById('PBBG').style.backgroundColor='#333333';
}

function clearFPSM() {
	document["STU"].src="nomarked.png"
	document["MUL"].src="nomarked.png"
	document.getElementById('PSBG').style.backgroundColor='#333333';
	document.getElementById('PMBG').style.backgroundColor='#333333';
}

function clearAER() {
	//document["RTR"].src="nomarked_mini.png"
	//document["MES"].src="nomarked_mini.png"
	//document["SEM"].src="nomarked_mini.png"
	//document["ANO"].src="nomarked_mini.png"
}

function expand() {
var aRows=document.getElementById('comp').rows;
for(var i=5; i<26; i++) { 
	aRows[i].style.display='';
    }
}

function collapse(A) {
var aRows=document.getElementById('comp').rows;
for(var i=5; i<26; i++) { 
	aRows[i].style.display='none';
    }
if (A != 1)		{	window.scrollTo(0,120); }

}

function VerifyDB() {
	if (document.myform.CPF.value == "") { alert("Informe o CPF do cliente"); return; }
	document.myform.PlanoVS.value = PlanoVS;
	document.myform.AgTur.value = "1";
	document.myform.target="";
	document.myform.action="Login.asp";
	document.myform.submit();
	document.myform.AgTur.value = "0";
	document.myform.action="email.asp";
	document.myform.target="_blank";
}

// Set Plano e datas ida e volta (login agetur)
function SetTripPlan(Plano,di,mi,ai,dv,mv,av) {
	document.myform.Dia_Ida.selectedIndex = di-1; 
	document.myform.Mes_Ida.selectedIndex = mi-1; 
	document.myform.Ano_Ida.selectedIndex = ai - 2009;
	document.myform.Dia_Volta.selectedIndex = dv-1; 
	document.myform.Mes_Volta.selectedIndex = mv-1; 
	document.myform.Ano_Volta.selectedIndex = av - 2009;
	PlanoVS = Plano;
	switch (PlanoVS)
	{
	case 1: { chgImgAER("RTR"); break; }
	case 2: { chgImgAER("MES"); break; }
	case 3: { chgImgAER("SEM"); break; }
	case 4: { chgImgAER("ANO"); break; }
	case 5: { chgImgFP("EXE"); break; }
	case 6: { chgImgFP("BUS"); break; }
	case 7: { chgImgFP("BAS"); break; }
	case 8: { chgImgFP("EUR"); break; }
	case 9: { chgImgFP("BRA"); break; }
	}
	window.scrollTo(0,350);
}

// Alerta programado
function setAlert(message) {
	alert(message);
	}
	
// Montar tabela do agente de viagens
function mountTable(i) {
		document.getElementById('DiasViagem').innerHTML = i;
		AER = 28;	
		document.getElementById('PP').innerHTML = (((i*11.5)+AER).toFixed(2)).replace(".",",");
		document.getElementById('PG').innerHTML = (((i*10.3)+AER).toFixed(2)).replace(".",",");
		document.getElementById('PS').innerHTML = (((i*7.3)+AER).toFixed(2)).replace(".",",");
		document.getElementById('PE').innerHTML = (((i*10.9)+AER).toFixed(2)).replace(".",",");
		document.getElementById('PB').innerHTML = (((i*4)+AER).toFixed(2)).replace(".",",");	
}

// Get Cookie
function getCookie(name) {
        var dc = document.cookie;
        var prefix = name + "=";
        var begin = dc.indexOf("; " + prefix);
        if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
        } else
        begin += 2;
        var end = document.cookie.indexOf(";", begin);
        if (end == -1)
        end = dc.length;
        return unescape(dc.substring(begin + prefix.length, end));
}

// voeseguro aéreo startup
function VSAereo() {
	PlanoVS = 2;
	DoNotShowPrice = true;
	showPrice();
	
}
