﻿


function getpagamento(){
    
    var val = 0;

    for( i = 0; i < document.forms[0].tipo_pagamento.length; i++ )
    {
        if( document.forms[0].tipo_pagamento[i].checked == true )
            val = document.forms[0].tipo_pagamento[i].value;
    }
    return val;    
    
}

function ValidaForm(){
 
    
    var actual = document.getElementById("ctl00_ConteudoPromo_contacto_telemovel").value;
    var pagamento = getpagamento();
    var validado = false;
    
    if (actual==""){        
        
        alert("Atenção: Por favor introduza um contacto telefónico para podermos melhor assistir o seu pedido.");        
        
    }else{ 
        
        if (pagamento!=null){
            
            if(pagamento=="cartaocredito"){
            
                if(document.getElementById("cartao_nome").value==""){
                    alert("Atenção: Por favor preencha o nome do cartão.");        
                }else if(document.getElementById("cartao_numero").value==""){
                    alert("Atenção: Por favor preencha o número do cartão.");        
                }else if(document.getElementById("cartao_mes").options[document.getElementById("cartao_mes").selectedIndex].value=="0"){
                    alert("Atenção: Por favor preencha o mês de expiração do cartão.");        
                }else if(document.getElementById("cartao_ano").options[document.getElementById("cartao_ano").selectedIndex].value=="0"){
                    alert("Atenção: Por favor preencha o ano de expiração do cartão.");        
                }else{
                    
                    validado=true;
                }
            
            } else {
            
                validado = true;
            } 
        }else{
            
            validado=true;
        }
        
    }
    
    if(validado){
         document.getElementById("ButtonSubmit").disabled  = true;        
         document.getElementById("ButtonSubmit").value  = 'aguarde por favor...'; 
         document.getElementById("ctl00_ConteudoPromo_Button1").click();        
    }

}

function ActualizaPrecoTotal(){
        

    p = document.getElementById("ctl00_ConteudoPromo_dropDatas").value;        
    i = p.indexOf('€');
                
    preco = parseInt(p.substring(p.indexOf('€')+1));
    actuais = parseInt(document.getElementById("nquartos").value);        
    //alert(actuais);    
    document.getElementById("ctl00_ConteudoPromo_lblPrecoTotal").innerHTML = actuais * (preco);
    //document.getElementById("ctl00_ConteudoPromo_lblDesconto").innerHTML = ((actuais * (preco))*0.02).toFixed(2);
        
    if (actuais==1){
            document.getElementById("ctl00_ConteudoPromo_lblPessoas").innerHTML = "1 pessoa";
    }else{
         document.getElementById("ctl00_ConteudoPromo_lblPessoas").innerHTML = actuais +" pessoas";
    }
}

function ActualizaQuartos(){
    
    var actuais = document.getElementById("nquartos").value;
    var antigos = document.getElementById("nquartosaux").value;
    var adicionar = actuais - antigos;
    
    if (adicionar>0){
        while(adicionar>0){    
            adicionar = adicionar -1;
            addRowTotable(0,false);
        }
    }else{
        while(adicionar<0){    
            adicionar = adicionar +1;
            removeRowFromtable();
        }
    }
    
    document.getElementById("nquartosaux").value = actuais;    
    if (actuais=="1"){
        alert("Atenção:  Um só passageiro implica aplicação de suplemento que encarece a viagem.");

    }       
    ActualizaPrecoTotal();
}  

function doBlink() {
  // Blink, Blink, Blink...
  var blink = document.all.tags("BLINK")
  for (var i=0; i < blink.length; i++)
    blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}

function startBlink() {
  // Make sure it is IE4
  if (document.all)
    setInterval("doBlink()",1000)
}



    function GoTop(){
        document.location=document.location + "#top";
    }
    function GoHome(){
        var b = document.getElementById('linkHome');        
        b.click();        
    }

    function EscolheDestino(val){        
        var t = document.getElementById('DestinoId');
        t.value=val;
        var b = document.getElementById('btnEscolher');
        b.click();        
    }
    
    function EscolhePromocao(val,val2){        
        
        var t = document.getElementById('PromocaoId');
        t.value=val;
        var t2 = document.getElementById('DestinoId');
        t2.value=val2;
        
        var b = document.getElementById('btnEscolherPromo');
        b.click();        
    }
    
    function GetTree(){        
        queroviagens.qvservice.GetTree(OnRequestComplete);
    }
 
    function OnRequestComplete(result)
    {
        var RsltElem = document.getElementById("jstree");
        RsltElem.innerHTML = result;        
    }
    
    
    
    
function toggleVisibility(id, NNtype, IEtype, WC3type) {
    if (document.getElementById) {
        eval("document.getElementById(id).style.visibility = \"" + WC3type + "\"");        
    } else {
        if (document.layers) {
            document.layers[id].visibility = NNtype;
        } else {
            if (document.all) {
                eval("document.all." + id + ".style.visibility = \"" + IEtype + "\"");             
            }
        }
    }
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function addRowTotable(rowSelected, disabled)
{
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  // select cell
  var cellRightSel = row.insertCell(0);
  var sel = document.createElement('select');
  sel.name = 'pax_tipo' + iteration;
  sel.options[0] = new Option('Adulto', 'adulto');  
  sel.options[1] = new Option('Criança', 'crianca');  
  sel.options[2] = new Option('Bébé', 'bebe');
  sel.selectedIndex = rowSelected;
  sel.disabled = disabled;
  var onchangeFunction = new Function("","ChangeVisibility(this.name,this.value);");    
  sel.onchange = onchangeFunction
  cellRightSel.appendChild(sel);
  
  // right cell
  var cellLeft = row.insertCell(1);
  var textNode = document.createTextNode('Nome: ');  
  cellLeft.appendChild(textNode);
  
  
  // right cell
  var rightLeft = row.insertCell(2);  
  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'pax_nome' + iteration;
  el.id = 'pax_nome' + iteration;
  el.size = 30;
  rightLeft.appendChild(el);
  
  var otherCell = row.insertCell(3);
    
  var tn = document.createTextNode('Data Nascimento: ');      
  var div = document.createElement('div');    
  div.id = 'pax_dt' + iteration;
  div.name = 'pax_dt' + iteration;  
  div.appendChild(tn)  
  
  if(rowSelected!=1)
  {
    div.style.visibility = 'hidden';
  }
  otherCell.appendChild(div);
  
  var otherCell2 = row.insertCell(4);
  var tn2 = document.createElement('input');  
  tn2.type = 'text';
  tn2.name = 'pax_idade' + iteration;
  tn2.id = 'pax_idade' + iteration;
  tn2.size = 12;  
  tn2.value = 'dd-mm-aaaa';
  
  var div2 = document.createElement('div');
  div2.id = 'pax_dt' + iteration+'2';
  div2.name = 'pax_dt' + iteration+'2';  
  div2.appendChild(tn2)
  
  if(rowSelected!=1)
  {
   div2.style.visibility = 'hidden';  
  }
  otherCell2.appendChild(div2);
   
}
function keyPressTest(e, obj)
{
  var validateChkb = document.getElementById('chkValidateOnKeyPress');
  if (validateChkb.checked) {
    var displayObj = document.getElementById('spanOutput');
    var key;
    if(window.event) {
      key = window.event.keyCode; 
    }
    else if(e.which) {
      key = e.which;
    }
    var objId;
    if (obj != null) {
      objId = obj.id;
    } else {
      objId = this.id;
    }
    displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
  }
}
function removeRowFromtable()
{
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  if (lastRow > 1) tbl.deleteRow(lastRow - 1);
}

function validateRow(frm)
{

  if (1==1) {
    var tbl = document.getElementById('tblSample');
    var lastRow = tbl.rows.length - 1;
    var i;
    for (i=1; i<=lastRow; i++) {
      var aRow = document.getElementById('pax_nome' + i);
      if (aRow.value.length <= 0) {
        alert('O nome do passageiro ' + i + ' é obrigatório.');
        return;
      }
    }
  }
}

function MostraOpinioes(){

        toggleVisibility('infOpinioes','show','visible','visible');     
        document.getElementById('infOpinioes').style.display = 'block';   
        toggleVisibility('selOpinioes','show','visible','visible');                      
        document.getElementById('selOpinioes').style.display = 'block'; 
        toggleVisibility('notOpinioes','hidden','hidden','hidden');
        document.getElementById('notOpinioes').style.display = 'none';            
    
        toggleVisibility('notPais','show','visible','visible');                      
        document.getElementById('notPais').style.display = 'block'; 
        toggleVisibility('infPais','hidden','hidden','hidden');
        document.getElementById('infPais').style.display = 'none';             
        toggleVisibility('selPais','hidden','hidden','hidden');
        document.getElementById('selPais').style.display = 'none';
    
        toggleVisibility('notDestino','show','visible','visible');                      
        document.getElementById('notDestino').style.display = 'block'; 
        toggleVisibility('infDestino','hidden','hidden','hidden');
        document.getElementById('infDestino').style.display = 'none';             
        toggleVisibility('selDestino','hidden','hidden','hidden');
        document.getElementById('selDestino').style.display = 'none';
        
        toggleVisibility('notImagens','show','visible','visible');                      
        document.getElementById('notImagens').style.display = 'block';               
        toggleVisibility('infImagens','hidden','hidden','hidden');
        document.getElementById('infImagens').style.display = 'none';
        toggleVisibility('selImagens','hidden','hidden','hidden');
        document.getElementById('selImagens').style.display = 'none'; 

}


function MostraPais(){
    
        toggleVisibility('infPais','show','visible','visible');     
        document.getElementById('infPais').style.display = 'block';   
        toggleVisibility('selPais','show','visible','visible');                      
        document.getElementById('selPais').style.display = 'block'; 
        toggleVisibility('notPais','hidden','hidden','hidden');
        document.getElementById('notPais').style.display = 'none';            
    
        toggleVisibility('notDestino','show','visible','visible');                      
        document.getElementById('notDestino').style.display = 'block'; 
        toggleVisibility('infDestino','hidden','hidden','hidden');
        document.getElementById('infDestino').style.display = 'none';             
        toggleVisibility('selDestino','hidden','hidden','hidden');
        document.getElementById('selDestino').style.display = 'none';
        
        toggleVisibility('notImagens','show','visible','visible');                      
        document.getElementById('notImagens').style.display = 'block';               
        toggleVisibility('infImagens','hidden','hidden','hidden');
        document.getElementById('infImagens').style.display = 'none';
        toggleVisibility('selImagens','hidden','hidden','hidden');
        document.getElementById('selImagens').style.display = 'none'; 

        toggleVisibility('notOpinioes','show','visible','visible');                      
        document.getElementById('notOpinioes').style.display = 'block'; 
        toggleVisibility('infOpinioes','hidden','hidden','hidden');
        document.getElementById('infOpinioes').style.display = 'none';             
        toggleVisibility('selOpinioes','hidden','hidden','hidden');
        document.getElementById('selOpinioes').style.display = 'none';             
 
}
function MostraDestino(){        
        
        toggleVisibility('infDestino','show','visible','visible');   
        document.getElementById('infDestino').style.display = 'block';             
        toggleVisibility('selDestino','show','visible','visible');                      
        document.getElementById('selDestino').style.display = 'block'; 
        toggleVisibility('notDestino','hidden','hidden','hidden');
        document.getElementById('notDestino').style.display = 'none';
        
        toggleVisibility('notPais','show','visible','visible');                      
        document.getElementById('notPais').style.display = 'block'; 
        toggleVisibility('infPais','hidden','hidden','hidden');
        document.getElementById('infPais').style.display = 'none';             
        toggleVisibility('selPais','hidden','hidden','hidden');
        document.getElementById('selPais').style.display = 'none';
        
        
        toggleVisibility('notImagens','show','visible','visible');                      
        document.getElementById('notImagens').style.display = 'block';               
        toggleVisibility('infImagens','hidden','hidden','hidden');
        document.getElementById('infImagens').style.display = 'none';
        toggleVisibility('selImagens','hidden','hidden','hidden');
        document.getElementById('selImagens').style.display = 'none';
        
        
        toggleVisibility('notOpinioes','show','visible','visible');                      
        document.getElementById('notOpinioes').style.display = 'block'; 
        toggleVisibility('infOpinioes','hidden','hidden','hidden');
        document.getElementById('infOpinioes').style.display = 'none';             
        toggleVisibility('selOpinioes','hidden','hidden','hidden');
        document.getElementById('selOpinioes').style.display = 'none';  
        
}
function MostraImagens(){

      toggleVisibility('infDestino','hidden','hidden','hidden');
      document.getElementById('infDestino').style.display = 'none';
      toggleVisibility('selDestino','hidden','hidden','hidden');
      document.getElementById('selDestino').style.display = 'none';
      toggleVisibility('notDestino','show','visible','visible');                      
      document.getElementById('notDestino').style.display = 'block';        
   
      toggleVisibility('infPais','hidden','hidden','hidden');
      document.getElementById('infPais').style.display = 'none';   
      toggleVisibility('selPais','hidden','hidden','hidden');
      document.getElementById('selPais').style.display = 'none';             
      toggleVisibility('notPais','show','visible','visible');                      
      document.getElementById('notPais').style.display = 'block'; 
   
      toggleVisibility('infImagens','show','visible','visible');   
      document.getElementById('infImagens').style.display = 'block';  
      toggleVisibility('selImagens','show','visible','visible');                      
      document.getElementById('selImagens').style.display = 'block'; 
      toggleVisibility('notImagens','hidden','hidden','hidden');
      document.getElementById('notImagens').style.display = 'none';    
      
      
        toggleVisibility('notOpinioes','show','visible','visible');                      
        document.getElementById('notOpinioes').style.display = 'block'; 
        toggleVisibility('infOpinioes','hidden','hidden','hidden');
        document.getElementById('infOpinioes').style.display = 'none';             
        toggleVisibility('selOpinioes','hidden','hidden','hidden');
        document.getElementById('selOpinioes').style.display = 'none';        
}

function ChangeVisibility(nome,value){
    
    var i = Right(nome,1);    
    
    if (value!='adulto'){
        toggleVisibility('pax_dt'+i,'show','visible','visible');
        toggleVisibility('pax_dt'+i+'2','show','visible','visible');         
        
    }else {
        toggleVisibility('pax_dt'+i,'hidden','hidden','hidden');
        toggleVisibility('pax_dt'+i+'2','hidden','hidden','hidden');
    }
}

function ChangeTB(){                        
    this.document.getElementById('divCC').style.display = 'none';
    this.document.getElementById('divCC').style.visibility = 'hidden';                   
    this.document.getElementById('divTB').style.display = 'block';
    this.document.getElementById('divTB').style.visibility = 'visible';                                                    
}
                    
function ChangeCC(){
    this.document.getElementById('divCC').style.display = 'block';
    this.document.getElementById('divCC').style.visibility = 'visible';                                               
    this.document.getElementById('divTB').style.display = 'none';
    this.document.getElementById('divTB').style.visibility = 'hidden';
}                    
