﻿function jViagem()
{
    var ListaPx = null ;
    
    var This=this;
    this.codViagem = null;
    this.codLocalidadeDe = null;
    this.codLocalidadePara = null;
    this.codTema = null;
    this.dataInicio = null;
    this.dataEmbarque = null;
    this.qtdDias = null;
    this.totPaxes = null;
    this.tema = null;
    this.numeroNoites = null;
    this.codTarifaIda = null;
    this.codTarifaVolta = null;
    
    this.Paxes = null;
    this.Pedido = null;
    
    this.codOpcaoSel = null;
    
    this.Pax = {};
    
    var sViagem;
//    this.addPaxes = function(pTotAdts, pTotChds, pTotInfs, pTotSnr){
//        for(var i=0; i < pTotAdts; i++){
//            This.Pax.push(new jPax());
//        }
//        
//        for(var i=0; i < pTotChds; i++){
//            This.Pax.push(new jPax());
//        }

//        for(var i=0; i < pTotInfs; i++){
//            This.Pax.push(new jPax());
//        }

//        for(var i=0; i < pTotSnr; i++){
//            This.Pax.push(new jPax());
//        }
//        
//    }
    
    this.sViagem = function(){
        var sVg = new StructType('sViagem');
        sVg.codViagem = This.codViagem;
        sVg.dataInicio = This.dataInicio;
        sVg.qtdDias = This.qtdDias;
        sVg.Paxes = This.Paxes;
        sVg.tema = This.tema;
        sVg.codLocalidadeDestino = This.codLocalidadeDe;
        sVg.codLocalidadePartida = This.codLocalidadePara;
        sVg.Pax = This.Pax;
        
        return sVg;
    };
    
/*    
    var addStructPax = function(pCodPax, pNome, pSobreNome, pSexoPax, pTipoPax, pIdGrupo)
    {
        var px = new jPaxes();
        var dtNascimento = '31/07/1970';
        
        px.addPax(pCodPax,dtNascimento, pIdGrupo, pNome, pSobreNome);         
    }
    
    this.Fechar = function()
    {
        var j=0;

        // Adts    
        for (var i=j; i<$('TipoPaxAdt').length; i++)
        {
          ListaPx = addStructPax(i, 'nome'+i, 'sobrenome'+i, 1, 1, 1);      
          j++;
        }
        // Chds
        for (var i=j; i<$('TipoPaxChd').length; i++)
        {
          ListaPx = addStructPax(i, 'nome'+i, 'sobrenome'+i, 1, 1, 1);      
          j++;
        }
        // Inf
        for (var i=j; i<$('TipoPaxInf').length; i++)
        {
          ListaPx = addStructPax(i, 'nome'+i, 'sobrenome'+i, 1, 1, 1);      
          j++;
        }

        //var Viagem = new jViagem() ;
        if ($('hd_localidadeDe').value == '')
            Viagem.codLocalidadeDe = 1846;
        else
            Viagem.codLocalidadeDe = $('hd_localidadeDe').value;
        
        if($('hd_localidadePara').value == '')    
            Viagem.codLocalidadePara = 1835;
        else
            Viagem.codLocalidadePara = $('hd_localidadePara').value;
            
            
        var DataIda = Date.parse($('dtIni').value,'dd/MM/yyyy');            

        Viagem.codTema = 1;
        Viagem.codViagem = 0 ;
        Viagem.dataInicio = DataIda;
        Viagem.qtdDias = $('selQtdeDias').value;
        Viagem.tema = 'aaa';
        Viagem.Paxes = ListaPx;

        $server.MontaViagem(Viagem.codLocalidadePara, Viagem.codLocalidadeDe, Viagem.codViagem, Viagem.codTema, Viagem.dataInicio, Viagem.qtdDias, Viagem.tema,Viagem.Paxes).value;
        
        location.href='Resultado.aspx';
    }
 
    this.render = function(pDivRef, pTipoRender)
    {
        //aqui
        var t = new Template('viagens');
        
        switch(pTipoRender)
        {
            case 'motorPortlet':
                var tmp = t.motor.baseMotor;
                document.getElementById(pDivRef).innerHTML = tmp.getHtml();

                break;
                
                
            case 'main':
                var tmp = t.motor.baseMotor;
                document.getElementById(pDivRef).innerHTML = tmp.getHtml();

                break;
                
        };
    };
    */
    
    this.constructor = new function()
    {
        This.codViagem = 1;
        This.dataInicio = Date.now();
        This.Paxes = new jPaxes();
        This.Pedido = new jPedido();
    };
    
};




