function Tarifada(){
    var current = this, 
		abasArray, 
		tarifasArray, 
		paxCount, 
		reserva, 
		bestBuy, 
		bestBuyGol, 
		listaSources, 
		//rfsh = new atualiza(), 
		t = new Template('scrs').aereo.reserva,
		//tAlertModal = new Template('main').structpage.alertModal,
		dialogModal = new AirAlertDialog();
		typeConditionLoad = new LoadEvents();
    
    this.tarifar = function(){
    //alert('tarifada');
        var priceItemArray = [];
        //var priceItemArray;
        var codOpcao;
        var codOpcaoMP;
        var abaId;
        var opcoesVooIt;
        var opcoesMPOpcoesVooIt;
        var novaOpcao = true;
        var opcoesVoo = [];
        //debugger
		//var jkl = mainControl.scope();
        
		abasArray = arrayGeral2;//mainControl.scope().disponibilidade().getAbas();
        
		//t.cnt_reserva_0_4.texto = 'Tarifando voos, aguarde...';
        //$('tarifada_ctn').innerHTML = t.cnt_reserva_0_4.getHtml();
        //$('tarifada').style.display = '';
        
        reserva = false;
        
        //Varre todas as abas, procurando alguma opcao a ser tarifada
        for (var i = 0; i < abasArray.length; i++) {
            //Pegando todas as opcoes a serem tarifas
            opcoesVoo = abasArray[i].getItemCarrinho().getOpcoes();
            
            //for (var j = 0; j < opcoesVoo.length; j++) {
            novaOpcao = true;
            
            //Entra caso seja para tarifar
           // if (abasArray[i].getItemCarrinho().getTarifar()) {Original fecha com -- no final
            
			 	var isLowFare = buscaPreco; //Verifica se eh lowFare
            
                //Verifica se eh airAvail ou LowFare
                if (!isLowFare) {//if (!abasArray[i].getLowFare()) { Original
                    abaId = i;//abasArray[i].getItemCarrinho().getAbaId(); // O id da Aba passo "0" para ida e 1 para "Volta".
                    codOpcao = opcoesVoo;
                    opcoesVooIt = abasArray[abaId].getOpcoesVooIt();
                    opcoesVooIt.findByKey(codOpcao);
                    
                    //Varre o priceItemArray, em busca de itens do mesmo gds
                    for (var k = 0; k < priceItemArray.length; k++) {
                        gdsCode = opcoesVooIt.row.sourceCode;
                        //Caso ache insere a opcao atual, no mesmo origindestination
                        if (priceItemArray[k].gdsCode == gdsCode) {
                            novaOpcao = false;
                            var origDestArr = getOriginDestinationArray(abaId, codOpcao);
                            
                            var selectedOption = new StructType('SelectedOption');
                            selectedOption.codAba = abaId;
                            selectedOption.codOpcao = codOpcao;
                            selectedOption.sourceName = priceItemArray[k].gdsCode;
                            
                            priceItemArray[k].selectedOptionArray.push(selectedOption);
                            //Pode ser que retorne mais de uma opcao, entao é necessário colocar todas.
                            for (var l = 0; l < origDestArr.length; l++) {
                                priceItemArray[k].originDestinationArray.push(origDestArr[l]);
                            }
                        }
                    }
                    //Se for novaOpcao coloca na lista
                    if (novaOpcao) {
                        var priceItem = getPriceItem(abaId, codOpcao);
                        priceItemArray.push(priceItem);
                    }
                }
                else {
                
                    abaId = i;//abasArray[i].getItemCarrinho().getAbaId();
                    codOpcaoMP = opcoesVoo;//codOpcaoMP = opcoesVoo[j];
                    opcoesMPOpcoesVooIt = abasArray[abaId].getOpcoesMPOpcoesVooIt();//abasArray[abaId].getOpcoesMPOpcoesVooIt();
                    opcoesMPOpcoesVooIt.findByKey(codOpcaoMP);
                    
                    while (opcoesMPOpcoesVooIt.hasNext()) {
                        codOpcao = opcoesMPOpcoesVooIt.row.codOpcaoDeVoo;
                        opcoesVooIt = abasArray[abaId].getOpcoesVooIt();
                        opcoesVooIt.findByKey(codOpcao);
                        
                        //Varre o priceItemArray, em busca de itens do mesmo gds
                        for (var k = 0; k < priceItemArray.length; k++) {
                            gdsCode = opcoesVooIt.row.sourceCode;
                            //Caso ache insere a opcao atual, no mesmo origindestination
                            if (priceItemArray[k].gdsCode == gdsCode) {
                                novaOpcao = false;
                                var origDestArr = getOriginDestinationArray(abaId, codOpcao);
                                
                                var selectedOption = new StructType('SelectedOption');
                                selectedOption.codAba = abaId;
                                selectedOption.codOpcao = codOpcao;
                                selectedOption.sourceName = priceItemArray[k].gdsCode;
                                
                                priceItemArray[k].selectedOptionArray.push(selectedOption);
                                //Pode ser que retorne mais de uma opcao, então é necessário colocar todas.
                                for (var l = 0; l < origDestArr.length; l++) {
                                    priceItemArray[k].originDestinationArray.push(origDestArr[l]);
                                }
                            }
                        }
                        //Se for novaOpcao coloca na lista
                        if (novaOpcao) {
                            var priceItem = getPriceItem(abaId, codOpcao);
                            priceItemArray.push(priceItem);
                        }
                        opcoesMPOpcoesVooIt.moveNext();
                    }
                }
                //}
            //}--
        }
        if (priceItemArray.length > 0) {
			//if (!isBuscaTrip) {
				//BookWebMethods.GetDadosAereoBuscaTrip(isBuscaTrip);
			//}
			//else {
				BookWebMethodsB2C.DoPrice(priceItemArray, current.callbacks.doPrice);
			//};
        }
        else {
            alert('Selecione ao menos um segmento para tarifar.');
            if (tarifasArray.length > 0) {
                buildTarifas();
            }
            else {
                $('tarifada').style.display = 'none';
            }
        }
    };
    
	//**** BuscaTrip
	/*
	this.isBuscaTrip = function(){
		var _btid; 
			//http://www.rapi10.com.br/tarifadaaereo.aspx?btid=2192447
			_btid = Request.queryString('btid');
			//$('txtBtid').value = _btid;
			if(!_btid){
				return _btid;
			};
	};*/
	//****
	
    this.tarifarNormal = function(){
        bestBuy = false;
        current.tarifar();
    };
    
    this.tarifarBestBuy = function(){
        bestBuy = true;
        current.tarifar();
    };
    
    var getPriceItem = function(abaId, codOpcao){
    
        var opcoesVooIt = abasArray[abaId].getOpcoesVooIt();
        opcoesVooIt.findByKey(codOpcao);
        
        //Verificando se e bestbuy gol
        bestBuyGol = (bestBuy && opcoesVooIt.row.sourceCode == 'GOL');
        
        //item
        var item = new StructType('PriceItem');
        item.passengerArray = getPassengerArray();
        item.negotiatedFareArray = getNegotiatedFareArray();
        item.originDestinationArray = getOriginDestinationArray(abaId, codOpcao);
        item.selectedOptionArray = getSelectedOptionArray(abaId, codOpcao, opcoesVooIt.row.sourceCode);
        item.directionInd = '';
        item.freeText = '';
        item.gdsCode = opcoesVooIt.row.sourceCode;
        item.getRules = true;
        item.isBestBuy = bestBuy;
        item.isLowerFare = false;
        item.loc = '';
        item.version = 0;
        
        return item;
    };
    
    var getPassengerArray = function(){
        var list = [];
        
        //item
        if (!reserva) {
            for (var i = 0; i < 3; i++) {
                var item = new StructType('Passenger');
                if (i == 0) {
                    item.age = 20;
                    item.passengerTypeCode = 'ADT';
                    item.givenName = 'Adulto';
                }
                if (i == 1) {
                    item.age = 10;
                    item.passengerTypeCode = 'CHD';
                    item.givenName = 'Crianca';
                }
                if (i == 2) {
                    item.age = 1;
                    item.passengerTypeCode = 'INF';
                    item.givenName = 'Bebe';
                }
                
                item.surname = 'Teste';
                item.surnamePrefix = 'MR';
                item.passengerTypeQuantity = 1;
                item.rph = i;
                
                list.push(item);
            }
        }
        else {
            var nomes = document.getElementsByName('nome');
            var sobrenomes = document.getElementsByName('sobrenome');
            var tipo = document.getElementsByName('tipopax');
            
            for (var i = 0; i < nomes.length; i++) {
                var item = new StructType('Passenger');
                if (tipo[i].value == 0) {
                    item.age = 20;
                    item.passengerTypeCode = 'ADT';
                }
                if (tipo[i].value == 1) {
                    item.age = 10;
                    item.passengerTypeCode = 'CHD';
                }
                if (tipo[i].value == 2) {
                    item.age = 1;
                    item.passengerTypeCode = 'INF';
                }
                item.givenName = nomes[i].value;
                item.passengerTypeQuantity = 1;
                item.rph = i;
                item.surname = sobrenomes[i].value;
                item.surnamePrefix = 'MR';
                list.push(item);
            }
        }
        
        return list;
    };
    
    var getNegotiatedFareArray = function(){//nao mandar acordo
        var list = [];
        
        var sources = document.getElementsByName('selSourceTarifada');
        var acordos = document.getElementsByName('txtAcordosTarifada');
        var tipos = document.getElementsByName('selTipoAcordoTarifada');
        var selsAcordo = document.getElementsByName('selAcordos');
        
        for (var i = 0; i < sources.length; i++) {
            //item
            var item = new StructType('NegotiatedFare');
            item.code = '';
            item.gdsCode = '';
            item.jumpTo = '';
            item.type = 0;
            
            //Se o usuario nao selecionou um acordo, monta de acodro com o textBox
            if (selsAcordo[i].value == -1) {
                item.code = acordos[i].value;
                item.gdsCode = sources[i].value;
                item.jumpTo = '';
                item.type = tipos[i].value;
            }
            else {
                //Se o usuario selecionou um acordo, busca os dados no dataset
                listaSources.tables.Table1.filter("CodAcordo", selsAcordo[i].value, filterMode.equals, caseType.CIAI);
                
                item.code = listaSources.tables.Table1.rows[0].Valor;
                item.gdsCode = listaSources.tables.Table1.rows[0].CodSource;
                item.jumpTo = listaSources.tables.Table1.rows[0].JumpTo;
                item.type = listaSources.tables.Table1.rows[0].CodTipoAcordo;
                
                listaSources.tables.Table1.unfilter(true);
            }
            list.push(item);
        }
        
        return list;
    };
    
    var getOriginDestinationArray = function(abaId, codOpcao){
        var list = [];
        var opcoesVooIt = abasArray[abaId].getOpcoesVooIt();
        
        opcoesVooIt.findByKey(codOpcao);
        
        //item
        var item = new StructType('OriginDestinationOption');
        item.flightSegmentArray = getFlightSegmentArray(abaId, codOpcao);
        item.freeText = opcoesVooIt.row.freeText;
        list.push(item);
        
        return list;
    };
    
	
    var getFlightSegmentArray = function(abaId, codOpcao){
        var list = [];
        var voosIt = abasArray[abaId].getVoosIt();
        var rph = 0;
        
        voosIt.findByKey(codOpcao);
        //debugger
        //item
        while (voosIt.hasNext()) {
            var item = new StructType('FlightSegment');
            var classesIt = abasArray[abaId].getClassesIt();
            
            classesIt.findByKey(voosIt.row.codVoo);
            
            getClassAndFareBasis(item, classesIt);
            
            item.arrivalAirport = voosIt.row.destino;
            item.arrivalDateTime = voosIt.row.dataHoraChegada;
            item.departureAirport = voosIt.row.origem;
            item.departureDateTime = voosIt.row.dataHoraSaida;
            item.equipment = voosIt.row.equipamento;
            item.flightNumber = voosIt.row.numero;
            item.forceBreak = false; //$('breaked').checked;
            item.freeText = voosIt.row.freeText;
            item.marketingAirline = voosIt.row.companhia;
            item.marriageDetail = 0;
            item.nonStop = false; //$('stop').checked;
            item.numberInParty = 3;
            item.rph = rph;
            item.stopOver = false; //$('over').checked;
            item.stopQuantity = voosIt.row.numParadas;
            item.waitList = false;//$('list').checked;
            
            rph++;
            
            list.push(item);
            voosIt.moveNext();
        };
        return list;
    };
    

    var getSelectedOptionArray = function(abaId, codOpcao, sourceName){
        var list = [];
        
        var item = new StructType('SelectedOption');
        item.codAba = abaId;
        item.codOpcao = codOpcao;
        item.sourceName = sourceName;
        
        list.push(item);
        
        return list;
    };
     var getClassAndFareBasis = function(item, classesIt){
        while (classesIt.hasNext()) {
			if(!classesIt.row.selecionada){
	            if (classesIt.row.classe) {
	                item.resBookDesigCode = classesIt.row.classe;
	                item.fareBasisCode = classesIt.row.baseTarifariaReferencia;
	            };
			}
			else{
	            if (classesIt.row.selecionada) {
	                item.resBookDesigCode = classesIt.row.classe;
	                item.fareBasisCode = classesIt.row.baseTarifariaReferencia;
					break;
	            };
			};
            classesIt.moveNext();
        }
		
		if (item.resBookDesigCode == null) {
			item.resBookDesigCode = '';
		};
		if(item.fareBasisCode == null){
			item.fareBasisCode = '';
		}
    };
	
	var refreshAtualiza = function(){
		rfsh = new atualiza();
		return rfsh;
	};
		
    var loadTarifas = function(){
    	refreshAtualiza.buildTarifas();//rfsh.buildTarifas();
        //setando divs
        
		var sb = new StringBuilder();
        
        if (tarifasArray.length == 0) {
            $('tarifada').style.display = 'none';
            //if ($('reserva').style.display == '') 
            //    $('reserva').style.display = 'none';
        }
        else {
            $('tarifada').style.display = '';
        }
        for (var i = 0; i < tarifasArray.length; i++) {
            sb.append(tarifasArray[i].getTarifasTable(i));
        }
        
        sb.append(t.cnt_reserva_0_0_0_2.getHtml());
        
        $('tarifada_ctn').innerHTML = sb.toString();
        
        if ($('chkTarifa_' + (tarifasArray.length - 1)) != null) {
            $('chkTarifa_' + (tarifasArray.length - 1)).checked = true;
        }
    };
	
    this.loadTarifasSite = function(){
		loadTarifas();
	};
	
	this.calcTarifa = function(){
		refreshAtualiza.refreshTotalTarifada();//rfsh.refreshTotalTarifada();	
	};/*
	this.calcTarifasSite = function(){
		calc
	};*/
    this.retiraTarifa = function(id){
        tarifasArray.remove(id);
        buildTarifas();
    };
    
    this.buildReserva = function(){
        $('reserva').style.display = '';
        t.cnt_reserva_0_0_0_3.dadosReserva = t.cnt_reserva_0_0_0_4.getHtml();
        //xxx.buildCredential();
        $('reserva').innerHTML = t.cnt_reserva_0_0_0_3.getHtml();
    };
    
    this.adicionaPax = function(){
        paxCount++;
        
        t.cnt_reserva_0_0_0_5.i = paxCount;
        t.cnt_reserva_0_0_0_5.i = paxCount;
        
        var div = document.createElement('div');
        div.id = 'pax_' + paxCount;
        $('passageiros').appendChild(div);
        
        $('pax_' + paxCount).innerHTML = t.cnt_reserva_0_0_0_5.getHtml();
    };
    
    this.retiraPax = function(paxId){
        $('passageiros').removeChild($('pax_' + paxId));
    };
    
    this.reservar = function(){
        var radArray = document.getElementsByName('radTarifa');
        var id;
        
        reserva = true;
        
        for (var i = 0; i < radArray.length; i++) {
            if (radArray[i].checked) {
                id = i;
            }
        }
        
        var bookItemArray = getBookItemArray(id);//
        
        t.cnt_reserva_0_4.texto = 'Reservando voos, aguarde...';
        $('dadosReserva').innerHTML = t.cnt_reserva_0_4.getHtml();
        
        if (bookItemArray.length > 0) {
            BookWebMethodsB2c.DoBook(bookItemArray, current.callbacks.doBook);
        }
    };
    /*
    var getBookItemArray = function(id){
    
        var bookItemArray = [];
        var sources = [];
		// dataset da tarifada  var bookItemArray = [];
        var rows = tarifasArray[id].getDsBook().tables.OpcoesSelecionadas.rows;
        
        for (var i = 0; i < rows.count(); i++) {
            if (!sources.contains(rows[i].sourceName)) 
                sources.push(rows[i].sourceName);
        }
        
        for (var i = 0; i < sources.length; i++) {
            var bookItem = new StructType('BookItem');
            
            bookItem.negotiatedFareArray = getNegotiatedFareArray();
            bookItem.bookingParams = getBookingParams(id, sources[i]);
            bookItem.gdsCode = sources[i];
            bookItem.freeText = '';
            bookItem.version = 1;
            
            bookItemArray.push(bookItem);
        }
        
        return bookItemArray;
    };
    */
	/*
    var getBookingParams = function(id, source){
    
        var opcoesSelecionadasIt = tarifasArray[id].getOpcoesSelecionadasIt();
        var abaId, codOpcao, origDestArray;
        var first = true;
        
        opcoesSelecionadasIt.findByKey(source);
        
        var bookingParams = new StructType('BookingParams');
        bookingParams.originDestinationArray = [];
        bookingParams.passengerArray = getPassengerArray();
        bookingParams.ssrArray = [];
        bookingParams.address = getAddress();
        bookingParams.priceInfo = getPriceInfo();
        bookingParams.responsible = getResponsible();
        bookingParams.searchType = 0;
        bookingParams.showCompleteRetrieve = true;
        bookingParams.ticketLimit = new Date();
        
        while (opcoesSelecionadasIt.hasNext()) {
        
            abaId = opcoesSelecionadasIt.row.codAba;
            codOpcao = opcoesSelecionadasIt.row.codOpcao;
            origDestArray = getOriginDestinationArray(abaId, codOpcao);
            for (var i = 0; i < origDestArray.length; i++) {
                bookingParams.originDestinationArray.push(origDestArray[i]);
            }
            
            opcoesSelecionadasIt.moveNext();
        }
        return bookingParams;
    };
    */
	/*
    var getAddress = function(){
        var address = new StructType('Address');
        
        address.cityName = 'Sao Paulo';
        address.countryName = 'Brasil';
        address.postalCode = '05501010';
        address.stateCode = 'SP';
        
        return address;
    };
    */
	/*
    var getPriceInfo = function(){
        //HardCode por enquanto
        var priceInfo = new StructType('PriceInfo');
        
        var priceInfoItemArray = [];
        
        var ticketing = new StructType('Ticketing');
        ticketing.ticketLimit = new Date();
        ticketing.ticketType = 'type';
        priceInfo.ticketing = ticketing;
        
        
        //priceinfoitem
        var priceInfoItem = new StructType('PriceInfoItem');
        
        var flightSegRefNumArray = [];
        var item = 'teste';
        flightSegRefNumArray.push(item);
        priceInfoItem.flightSegRefNumArray = flightSegRefNumArray;
        
        var passengerFare = new StructType('PassengerFare');
        passengerFare.baseFare = new StructType('Fare');
        passengerFare.totalFare = new StructType('Fare');
        passengerFare.rate = 0;
        passengerFare.baseFare.amount = 0;
        passengerFare.baseFare.currencyCode = '';
        passengerFare.totalFare.amount = 0;
        passengerFare.totalFare.currencyCode = '';
        priceInfoItem.passengerFare = passengerFare;
        
        var passengerTypeQuantity = new StructType('PassengerTypeQuantity');
        passengerTypeQuantity.code = 'teste';
        passengerTypeQuantity.quantity = 0;
        priceInfoItem.passengerTypeQuantity = passengerTypeQuantity;
        
        priceInfoItemArray.push(priceInfoItem);
        
        priceInfo.priceInfoItemArray = priceInfoItemArray;
        
        return priceInfo;
    };
    */
	/*
    var getResponsible = function(){
        var responsible = new StructType('Responsible');
        
        responsible.areaCityCode = '11';
        responsible.countryAccessCode = '55';
        responsible.givenName = 'Travel';
        responsible.phoneNumber = '3038 4040';
        responsible.surname = 'Master';
        responsible.surnamePrefix = '';
        responsible.travellerAreaCityCode = '11';
        responsible.travellerPhoneNumber = '3038 4040';
        
        return responsible;
    };
    */
    this.adicionarAcordos = function(){
    
        var sb = new StringBuilder();
        
        //Inclui os sources no combo		
        for (var i = 0; i < listaSources.tables.Table.rows.count(); i++) {
            t.cnt_reserva_0_1_2_0.source = listaSources.tables.Table.rows[i].Nome;
            sb.append(t.cnt_reserva_0_1_2_0.getHtml());
        }
        t.cnt_reserva_0_1_2.options = sb.toString();
        
        //Inclui o div com os acordos na tela
        var div = document.createElement('div');
        div.style.width = '100%';
        div.style.padding = '3px';
        div.style.cssFloat = 'left';
        div.innerHTML = t.cnt_reserva_0_1_2.getHtml();
        $('acordosTarifada').appendChild(div);
        
        if ($('removeAcordo').style.display == 'none') {
            $('removeAcordo').style.display = '';
        }
        
        //Adiciona no combo de sources a funcao para atualizar os acordos do source escolhido
        var comboSources = document.getElementsByName('selSourceTarifada');
        var btnManual = document.getElementsByName('btnAcordoManual');
        var divManual = document.getElementsByName('divAcordoManual');
        
        if (comboSources.length > 0) {
            var indiceControle = comboSources.length - 1;
            comboSources[indiceControle].onchange = this.buscarAcordosSource;
            divManual[indiceControle].display = function(){
                this.style.visibility = (this.style.visibility == "hidden") ? "visible" : "hidden";
            };
            btnManual[indiceControle].onclick = function(){
                divManual[indiceControle].display();
            };
        }
    }
    
    this.buscarAcordosSource = function(){
        var comboAcordos = document.getElementsByName('selAcordos');
        var comboSources = document.getElementsByName('selSourceTarifada');
        
        //Quando qualquer dos combos é alterado, eu percorro todos os combos
        //  atualizando as informacoes de acordos.
        // Isso nao seria necessario se eu tivesse em maos o numero do combo que foi alterado,
        //  mas essa possibilidade sera feita na proxima oportunidade
        for (var c = 0; c < comboSources.length; c++) {
        
            var codSource = listaSources.tables.Table.rows[comboSources[c].selectedIndex].CodConexaoSource;
            
            var sbAcordos = new StringBuilder();
            
            //Filtra os acordos daquela conexaoSource
            listaSources.tables.Table1.filter('CodConexaoSource', codSource, filterMode.equals, caseType.CIAI);
            
            //removo todos os itens do combo menos o primeiro que e "(selecione)"
            var numeroItens = comboAcordos[c].options.length;
            for (var i = 1; i < numeroItens; i++) {
                comboAcordos[c].options[1].remove();
            }
            
            
            for (var j = 0; j < listaSources.tables.Table1.rows.length; j++) {
            
                var newOption = new Option();
                newOption.value = listaSources.tables.Table1.rows[j].CodAcordo;
                newOption.text = listaSources.tables.Table1.rows[j].Valor + ' (' + listaSources.tables.Table1.rows[j].Nome + ')';
                comboAcordos[c].options.add(newOption);
            }
            listaSources.tables.Table1.unfilter(true);
        }
    }
    
    this.retirarAcordos = function(){
        $('acordosTarifada').removeChild($('acordosTarifada').lastChild);
        if ($('acordosTarifada').childNodes.length == 0) {
            $('removeAcordo').style.display = 'none';
        }
    };
    
    //Callbacks
    this.callbacks = {
        doPrice: function(res){
        
            if (res.error == null) {
                /*
                 var itemTarifada = new ItemTarifada();
                 itemTarifada.setDsBook(res.value);
                 tarifasArray.push(itemTarifada);
                 $('trace').innerHTML += res.value.tables.DadosGerais.rows[0].sessionToken;
                 */
                $('vxltxRQ').value = '<![CDATA[' + res.value.replace(/\"/g, '\'') + ']]>';;
                $('resultSearch').submit();
            }else {
                var msg = res.error.message.split('@');
                if (msg.length >= 2) {

                    $('trace').innerHTML += 'ErrPrice: ' + msg[1] + '<br />';
					
					if($('vxllowFare').value == "true"){
						typeConditionLoad.disableLoading("botaoTarifarClickMP");
						typeConditionLoad.lockUnlockButtons("botaoTarifarClickMP", "name", "unlock");
						$("dialog").innerHTML = dialogModal.buildDialog("fail","resultadovoosinter", msg[0]);
					}else{
						typeConditionLoad.disableLoading("fare");
						$("dialog").innerHTML = dialogModal.buildDialog("fail","resultadovoos", msg[0]);
					};

                }else {
					
					if($('vxllowFare').value == "true"){
						typeConditionLoad.disableLoading("botaoTarifarClickMP");
						$("dialog").innerHTML = dialogModal.buildDialog("fail","resultadovoosinter", res.error.message);						
						//alert(res.error.message);
					}else{
						typeConditionLoad.disableLoading("fare");
						$("dialog").innerHTML = dialogModal.buildDialog("fail","resultadovoos", res.error.message);						
	                    //alert(res.error.message);						
					};
                };
            };
        },
        
        doBook: function(res){
            if (res.error == null) {
                mainControl.getPedido(res.value[0]);
                mainControl.history().reg('scr=aereoRtrvIssue&codPed=' + res.value[0]);
                $('trace').innerHTML += res.value[1];
            }
            else {
                var msg = res.error.message.split('@');
                if (msg.length >= 2) {
                    $('trace').innerHTML += 'ErrBook: ' + msg[1] + '<br />';
                    alert(msg[0]);
                }
                else {
                    alert(res.error.message);
					typeConditionLoad.disableLoading("fare");
                }
                
                if (tarifasArray.length == 0) 
                    $('tarifada').style.display = 'none';
                $('reserva').style.display = 'none';
            }
        },
        
        getAvailGDS: function(res){
            /*
			if (res.value != null && res.value.tables != null) 
                listaSources = res.value;
            else 
                listaSources = null;
            
            
            
            res.value.tables.Table.sort('Nome');
            
            var availableSources = res.value;
            
            //Percorre a lista de conexoesSources montando o template de sources
            for (var i = 0; i < availableSources.tables.Table.rows.length; i++) {
                //                mainControl.tpl().aereo.reserva.cnt_reserva_0_6.source = availableSources.tables.Table.rows[i].Nome;
                //t.cnt_reserva_0_6.indice = i;
                
                var sbAcordos = new StringBuilder();
                //Filtra os acordos daquela conexaoSource
		                //res.value.tables.Table1.filter('CodConexaoSource', availableSources.tables.Table.rows[i].CodConexaoSource, filterMode.equals, caseType.CIAI);
                res.value.tables.Table1.filter('CodConexaoSource', availableSources.tables.Table.rows[i].CodConexaoSourceSearchBook, filterMode.equals, caseType.CIAI);
				for (var j = 0; j < availableSources.tables.Table1.rows.length; j++) {
                    sbAcordos.append('<option value="' + (availableSources.tables.Table1.rows[j].CodAcordo) + '">' + availableSources.tables.Table1.rows[j].Valor + '</option>');
                }
                availableSources.tables.Table1.unfilter();
                //coloca no template a lista de acordos
                t.cnt_reserva_0_1_2.listaAcordos = sbAcordos.toString();
                
                //sb.append(mainControl.tpl().aereo.reserva.cnt_reserva_0_6.getHtml());
                
                //O break é provisório ate eu descobrir como renderizar somente um source (o da tarifada)
                break;
            };
            //setando divs
            var sbSources = new StringBuilder();
            
            for (var i = 0; i < listaSources.tables.Table.rows.count(); i++) {
                t.cnt_reserva_0_1_2_0.source = listaSources.tables.Table.rows[i].Nome;
                sbSources.append(t.cnt_reserva_0_1_2_0.getHtml());
            };
            t.cnt_reserva_0_1_2.options = sbSources.toString();
            */
        }
    };
    
    this.constructor = new function(){
        tarifasArray = [];
        paxCount = 1;
        reserva = false;
        BaseMethodsB2C.getAvailGDS(current.callbacks.getAvailGDS);
    };
};

