//use:
//getMsg( 'pt', 'sel_loc')
//getMsg( 'en', 'd_n_days1', "15")
//getMsg( 'en', 'id123',['replace #1#','replace #2#','replace #3#']));
//  ex: aMsg['pt']['limit_tickets123'] = 'Apenas pode comprar #1# #2# #3#';    // 5 bilhetes 3a idade (ex)

var aMsg = new Array('en','pt','fr');
aMsg['en'] = new Array();
aMsg['pt'] = new Array();
aMsg['fr'] = new Array();

// LANG: pt
aMsg['pt']['wait_d'] = 'Aguarde...a obter destinos...'; 
aMsg['pt']['sel_loc'] = 'Escolha uma localidade.'; 
aMsg['pt']['must_sel_o'] = 'Tem de seleccionar uma Origem.'; 
aMsg['pt']['must_sel_d'] = 'Tem de seleccionar um Destino.'; 
aMsg['pt']['different_od'] = 'O Destino não pode ser igual à Origem.'; 
aMsg['pt']['must_sel_ddep'] = 'Tem de seleccionar a data de partida.'; 
aMsg['pt']['bad_ddep'] = 'Data de partida inválida!'; 
aMsg['pt']['bad_dret'] = 'Data de volta inválida!'; 
aMsg['pt']['d_format_dmy'] = 'o formato correcto é DD/MM/AAAA'; 
aMsg['pt']['d_before_today'] = 'data anterior a hoje'; 
aMsg['pt']['d_before_ddep'] = 'anterior à data de partida'; 
aMsg['pt']['d_after_dret'] = 'posterior à data de chegada'; 
aMsg['pt']['d_n_days1'] = 'só pode seleccionar datas nos próximos #1# dias'; 
aMsg['pt']['no_depart'] = 'Viagem de Ida não disponível.'; 
aMsg['pt']['no_return'] = 'Viagem de Volta não disponível.'; 
aMsg['pt']['must_sel_depart'] = 'Tem de seleccionar a Ida.'; 
aMsg['pt']['must_sel_return'] = 'Tem de seleccionar a Volta.'; 
aMsg['pt']['bad_reservation'] = 'Reserva Inválida'; 
aMsg['pt']['lugar_help'] = 'Deve seleccionar primeiro o lugar a alterar. \nClique no lugar reservado que pretende alterar, seguido do novo lugar pretendido.'; 
aMsg['pt']['lugar_bus'] = 'O novo lugar tem de ser no mesmo expresso.'; 
aMsg['pt']['limit_tickets123'] = 'Apenas pode comprar #1# #2# #3#'; 
aMsg['pt']['tickets'] = 'bilhetes'; 
aMsg['pt']['ticket'] = 'bilhete'; 
aMsg['pt']['must_id'] = 'É obrigatório o preenchimento do nº de bilhete de identidade.'; 
aMsg['pt']['bad_id_format'] = 'Formato inválido para nº de bilhete de identidade - apenas são permitidos dígitos.'; 
aMsg['pt']['must_name'] = 'É obrigatório o preenchimento do nome.'; 
aMsg['pt']['must_email'] = 'É obrigatório o preenchimento do E-mail.'; 
aMsg['pt']['bad_email'] = 'E-mail inválido.'; 
aMsg['pt']['must_bdate'] = 'Os campos da data de nascimento são de preenchimento obrigatório.'; 
aMsg['pt']['bad_bdate'] = 'Data de nascimento inválida.'; 
aMsg['pt']['must_postcode'] = 'Os campos do código postal são de preenchimento obrigatório.'; 
aMsg['pt']['must_gender'] = 'O campo "Sexo" é de preenchimento obrigatório.'; 
aMsg['pt']['must_ntickets'] = 'Tem de seleccionar bilhetes.'; 
aMsg['pt']['must_addy'] = 'O campo "Morada" é de preenchimento obrigatório.'; 
aMsg['pt']['must_addyndoor'] = 'O campo "Nº" é de preenchimento obrigatório.'; 
aMsg['pt']['must_addyloc'] = 'O campo "Localidade" é de preenchimento obrigatório.'; 
aMsg['pt']['bad_postcode'] = 'Código postal inválido.'; 
aMsg['pt']['bad_phone'] = 'Número de telefone inválido'; 
aMsg['pt']['bad_cardn'] = 'Nº de cartão inválido.'; 
aMsg['pt']['bad_mobile'] = 'Número de telemóvel inválido.'; 
aMsg['pt']['must_mobile'] = 'O campo "Telemóvel" é de preenchimento obrigatório.'; 
aMsg['pt']['must_tos'] = 'Tem de aceitar os Termos e Condições Gerais.'; 
aMsg['pt']['must_pwd'] = 'Tem de preencher a password.'; 
aMsg['pt']['must_pwdcur'] = 'O campo "password actual" é de preenchimento obrigatório.'; 
aMsg['pt']['must_pwdconf'] = 'Tem de confirmar a nova password.'; 
aMsg['pt']['must_uname'] = 'Tem de preencher o Username.'; 
aMsg['pt']['must_captcha'] = 'O campo "Verificação de Palavras" é de preenchimento obrigatório.'; 
aMsg['pt']['must_cardn'] = 'Tem de preencher o nº do cartão.'; 
aMsg['pt']['must_actcod'] = 'Tem de preencher o código de activação.'; 
aMsg['pt']['bad_pwd_different'] = 'Usou passwords diferentes.'; 
aMsg['pt']['bad_pwd'] = 'Password inválida!'; 
aMsg['pt']['bad_pwdcur'] = 'Password actual inválida!'; 
aMsg['pt']['card_inactive'] = 'O seu cartão não se encontra activo!'; 
aMsg['pt']['bad_accdata'] = 'Dados de acesso incorrectos!'; 
aMsg['pt']['bad_logout'] = 'Erro no logout'; 
aMsg['pt']['ok_login'] = 'Iniciou sessão'; 

aMsg['pt']['err_upd_data'] = 'Erro ao actualizar dados!'; 
aMsg['pt']['ok_upd_data'] = 'Dados actualizados'; 
aMsg['pt']['err_upd_pwd'] = 'Erro ao alterar password!'; 
aMsg['pt']['ok_upd_pwd'] = 'Password alterada'; 

aMsg['pt']['err_upd_email'] = 'Erro ao alterar email!'; 
aMsg['pt']['ok_upd_email'] = 'Receberá no seu novo email uma mensagem para validar o mesmo. \nA alteração será efectiva a partir desse momento.'; 
aMsg['pt']['err_del_msg'] = 'Erro ao apagar mensagem!'; 
aMsg['pt']['ok_del_msg'] = 'Mensagem apagada.'; 
aMsg['pt']['check_delmsg'] = 'Apagar mensagem?'; 
aMsg['pt']['check_redo'] = 'Verifique e preencha de novo.';

aMsg['pt']['data_verify'] = "Antes de prosseguir para o pagamento da sua reserva, verifique e assegure-se\ndo correcto preenchimento e validade dos endereços de correio electrónico para\nrecepção dos respectivos bilhetes.\n\nO seu incorrecto preenchimento e/ou a sua não validade, impedirá a correcta\nrecepção dos bilhetes pelos respectivos passageiros.\n\nPara prosseguir para pagamento, prima 'OK'.";
aMsg['pt']['error_retry'] = 'Ocorreu um erro.\nPor favor volte a tentar.'
aMsg['pt']['check_langnew'] = 'Será redireccionado para o início do site. Deseja continuar?'

// LANG: en
aMsg['en']['wait_d'] = 'Please wait... getting destinations...'; 
aMsg['en']['sel_loc'] = 'Select a location'; 
aMsg['en']['must_sel_o'] = 'You must select the depart location.'; 
aMsg['en']['must_sel_d'] = 'You must select a destination.'; 
aMsg['en']['different_od'] = 'From and to locations can\'t be the same.'; 
aMsg['en']['must_sel_ddep'] = 'You must select the depart date'; 
aMsg['en']['bad_ddep'] = 'Invalid depart date!'; 
aMsg['en']['bad_dret'] = 'Invalid return date!'; 
aMsg['en']['d_format_dmy'] = 'correct format is DD/MM/YYYY'; 
aMsg['en']['d_before_today'] = 'date before today'; 
aMsg['en']['d_before_ddep'] = 'before depart date'; 
aMsg['en']['d_after_dret'] = 'after return date'; 
aMsg['en']['d_n_days1'] = 'you can only select dates within the next #1# days'; 
aMsg['en']['no_depart'] = 'Outward trip not available.'; 
aMsg['en']['no_return'] = 'Return trip not available.'; 
aMsg['en']['must_sel_depart'] = 'You must select the outward trip.'; 
aMsg['en']['must_sel_return'] = 'You must select the return trip.'; 
aMsg['en']['bad_reservation'] = 'Invalid Reservation'; 
aMsg['en']['lugar_help'] = 'Select the place to change. \nClick the reserved seat you want to change, and then the new seat.'; 
aMsg['en']['lugar_bus'] = 'The new seat must be selected in the same bus.'; 
aMsg['en']['limit_tickets123'] = 'ticket'; 
aMsg['en']['must_id'] = 'You must input the ID number.'; 
aMsg['en']['bad_id_format'] = 'Invalid format for the ID number - only numbers allowed.'; 
aMsg['en']['must_name'] = 'You must input the name.'; 
aMsg['en']['must_email'] = 'You must input the email.'; 
aMsg['en']['bad_email'] = 'Invalid email.'; 
aMsg['en']['must_bdate'] = 'You must input the birthdate.'; 
aMsg['en']['bad_bdate'] = 'Invalid birthdate.'; 
aMsg['en']['must_postcode'] = 'You must input the postal code.'; 
aMsg['en']['must_gender'] = 'You must input the gender.'; 
aMsg['en']['must_addy'] = 'You must input the address.'; 
aMsg['en']['must_addyndoor'] = 'You must input the number'; 
aMsg['en']['must_addyloc'] = 'You must input the city.'; 
aMsg['en']['bad_phone'] = 'Invalid phome number'; 
aMsg['en']['bad_mobile'] = 'Invalid mobile number.'; 
aMsg['en']['bad_cardn'] = 'Invalid card number.'; 
aMsg['pt']['must_mobile'] = 'You must input the mobile number.'; 
aMsg['en']['must_tos'] = 'You must accept the Terms of Service.'; 
aMsg['en']['must_pwd'] = 'You must input the password.'; 
aMsg['en']['must_pwdcur'] = 'You must input the current password.'; 
aMsg['en']['must_pwdconf'] = 'You must confirm the new password.'; 
aMsg['en']['must_uname'] = 'You must input the Username.'; 
aMsg['en']['must_captcha'] = 'You must enter the check characters.'; 
aMsg['en']['must_cardn'] = 'You must input the card number.'; 
aMsg['en']['must_actcod'] = 'You must input the activation code.'; 
aMsg['en']['bad_pwd_different'] = 'Invalid password!'; 
aMsg['en']['bad_pwdcur'] = 'Invalid current password!'; 
aMsg['en']['card_inactive'] = 'Your card is not active!'; 
aMsg['en']['bad_accdata'] = 'Bad access data!'; 
aMsg['en']['bad_logout'] = 'Bad logout'; 
aMsg['en']['err_upd_data'] = 'Error updating data!'; 
aMsg['en']['ok_upd_data'] = 'Data saved'; 
aMsg['en']['err_upd_pwd'] = 'Error updating password!'; 
aMsg['en']['ok_upd_pwd'] = 'Password updated'; 
aMsg['en']['err_upd_email'] = 'Error updating email!'; 
aMsg['en']['ok_upd_email'] = 'You will receive a message on your new email to validate it. \nThe change will be effective from then on.'; 
aMsg['en']['err_del_msg'] = 'Error deleting message!'; 
aMsg['en']['ok_del_msg'] = 'Message deleted.'; 
aMsg['en']['check_delmsg'] = 'Delete message?'; 
aMsg['en']['check_redo'] = 'Check and retry.'; 
aMsg['en']['ok_login'] = 'Logged In'; 
aMsg['en']['error_retry'] = 'An error has ocurred.\nPlease retry.';
aMsg['en']['data_verify'] = "Before proceding to payment,\nverify and assure the correct filling of your ticket's email address destination(s).\n\nIncorrect filling can lead to non ticket delivery to their destination.\n\nPress 'OK' to proceed to payment.";
aMsg['en']['must_ntickets'] = 'You must select tickets.'; 
aMsg['en']['check_langnew'] = 'You will be redirected to our homepage. Do you wish to proceed?'

// LANG: fr
aMsg['fr']['wait_d'] = '...'; 



// = = = = = = = =


function getMsg(lang, id, arg) {

    if (lang == '' )
        lang = 'pt';
    
    var t = aMsg[lang][id] + '';
            
    if( t === 'undefined' ) {
        if (aMsg['pt'][id] + '' != '' )
        return aMsg['pt'][id] + '';
        else    
        return 'ERROR';
    }
        
    
    
    if( typeof(arg) === 'undefined' )
        return t;
        
    if ( t.indexOf('#') == -1 )
        return t;
        
    return replaceLangArgs(t, arg);
}

function replaceLangArgs(str, arg) {

    if ( typeof(arg) === 'string' ) {
        var regexstring = '#1#'
        var rg = new RegExp(regexstring, 'g') 
        str = str.replace(rg, arg);
    }
    
    else if (arg instanceof Array ) {
        // array - replace each entry in the string (#1#, #2#, ..)
        var j=0;
        for (var i=0; i< arg.length; i++) {
            j=i+1;
            var regexstring = '#' + j + '#'
            var rg = new RegExp(regexstring, 'g') 
            str = str.replace(rg, arg[i]);
        }
    }
    return str;
} 




function doXML() {
//returns string with the LANG XML of the arrays

    var s = '<?xml version="1.0" encoding="ISO-8859-1" ?><LANGS file="jsmsg.xml">'

    // a = each lang
    for ( var a in aMsg ) { 
        if (a.length > 1) {     //returns also 0 1 ... ignore them
            s = s + '<LANG ID="' +  a + '">'

            // t = each msgID in language array
            for ( var t in aMsg[a] )  {
                s = s + '<TEXT ID="' + t + '">' + aMsg[a][t] + '</TEXT>'
            }
            s = s + '</LANG>'
        }
    }
    s = s + '</LANGS>'
        
    return s;
}

