// requires utilities.js for the addOnloadEvent/addOnunloadEvent
  
// re:prefix for all global RailEurope variables
var reMapIcons = [];
var reMapKeyHash = [];
var reMaps = [];

// publicz.raileurope.com (on windows)
reMapKeyHash["publicz.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxSQL6ghSHO8GK2V5qHibSBva3phrRSIosQ8b9-74L1l1HAlD8wxnLLMZw";

// Public US
reMapKeyHash["publicx.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxT8IqSE8q6EyJLccf5G6VNWdObA-xTvpgSdYgojCzYaPV2Pdkt_R3HaSQ";
reMapKeyHash["www.raileurope.com"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRzNAFZJMtiUE5CMtqCc9IclchtXBQtYIXK4E1VZjCsO-Khe31NtJceaA";
reMapKeyHash["publicx.raileurope.com:7976"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRR1RZUO9y6u8m_pckFKrLfI2mWfxScwIGQh_9gCBnIfsIEsB0rZW7KNg";
reMapKeyHash["publicx.raileurope.com:7978"]="ABQIAAAAcqR3d1xk1djKX59fNj1Q9RQWSEWBzwu_6YpBjLCN4_g4pn-u_RT5EAhPTzCEy7AR9WmPNaBbtVPlog";
reMapKeyHash["publicx.raileurope.com:7982"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShQ3zEWo5gPKc84v1Fd7wNImDWmodBSgqPn2kj0WnE6MhW3GePdvlg8NUg";
reMapKeyHash["publicx.raileurope.com:7984"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShSGXV7oc1UaXaAuvuK0v5vaSoaQxRSsknF5BjONvDzEIcQQu7swXPmlrA";
reMapKeyHash["publicx.raileurope.com:7990"]="ABQIAAAALSzvtw6mKXVv8H8c9rcmExSdK8xtXUTKFcr07K-iLaPKPZP7ThSvMnQ1w4LYdmbwFxAC92bAa_QElA";
reMapKeyHash["publicx.raileurope.com:7996"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShQI8g1IZwEqcGIg9-RIxX3pBJIyvxQJ8FWHARwHdFXSy-s95upsvWaVLg";
reMapKeyHash["publicx.raileurope.com:8080"]="ABQIAAAALSzvtw6mKXVv8H8c9rcmExTLYjQ7gKVqvNHeam41o1Z3rs_xbRTQEARiGHWT9pReRhhzetlTHGB0eQ";
reMapKeyHash["publicx.raileurope.com:8082"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShTs0cvCGPkUaiz-0oeRgcq6x0MeFBQ5H5jSQEARndMMYkZWRsaI3-cu-g";
reMapKeyHash["publicx.raileurope.com:8084"]="ABQIAAAAcqR3d1xk1djKX59fNj1Q9RSRibs8issd8ydoJSO6dAKHmUQ_9BSK1RdmQYKtvDFcD5MA4jkKTIWoMw";
reMapKeyHash["publicx.raileurope.com:8098"]="ABQIAAAAcqR3d1xk1djKX59fNj1Q9RSC_bSrevZp0duhL56iN7d4EDLiPhQTOWv1M8K9aOu6nvU-wj2RhEGMCg";
reMapKeyHash["publicx.raileurope.com:7980"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxQ0h5SrA9cWSvUZZskGV3hMBbTnWhRVBCB-hocnqD66XsPhFVbiZfe1pw";
reMapKeyHash["publiccax.raileurope.com:7980"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxSJZsZVX6ULefY1-RtGzWPTdYYiDRSJm5ObY7k1su2GvUg_TykCTRg58w";
reMapKeyHash["mpublicx.raileurope.com:7988"]="ABQIAAAAO2bg-cbAJ0t-EDmOgczbxxQRpKC15BfCYe89UrM-CaVkgFPWNRSPGhbC9pAtrlpIrLbClu31frjJNw";
reMapKeyHash["mpublicx.raileurope.com:8080"]="ABQIAAAAO2bg-cbAJ0t-EDmOgczbxxS39iURmmuzVYggWBccmkWVWWs2mBQcV9fjlG43R1NYPTN9KDlwlIJMIg";
reMapKeyHash["mpublicx.raileurope.com:8082"]="ABQIAAAAO2bg-cbAJ0t-EDmOgczbxxTDUuxdTCqhYlFaChBYIZcmQDWCbxTRvCLTN3h_O3p-R1Z9uj0B6a0DAA";
reMapKeyHash["mpubliccax.raileurope.com:8082"]="ABQIAAAAO2bg-cbAJ0t-EDmOgczbxxQDmuaRRyienpGAUrIvWQhZHRoqlBQG8YvaKuPdR22Wrt2gS2obV7neDA";
reMapKeyHash["m.raileurope.com"]="ABQIAAAAO2bg-cbAJ0t-EDmOgczbxxTgfwFekDaZnoRUwtxjElKWZUNj4BRvvrKHsq0KAjX-MYUXfVQUaH7avQ";
reMapKeyHash["m.raileurope.ca"]="ABQIAAAAO2bg-cbAJ0t-EDmOgczbxxTgPeOLXtrZAGH7HMoG0a8l2i1NMxRQGqPVlsUjR9pOwySpp_BlmjXRMw";


// Public Canada
reMapKeyHash["publiccax.raileurope.com"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShSysD4tD1US1xqloUcnZcP9BURQTBTCaBp_NgEw0XgVvLS8zyqIGGbHbQ";                   
reMapKeyHash["www.raileurope.ca"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShQhnceF-KdfA0pkDOj1fzzVtwWngxTBLiv9ukd9UR6mNOzxLmwk5QzVFQ";
reMapKeyHash["publiccax.raileurope.com:7976"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShQ03j9PN1hJV4GF3O5JC-dgqKIADBSjLndIgSldQZcrEpDR7x1yNag7uQ";
reMapKeyHash["publiccax.raileurope.com:7982"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShQR2wP4GS64_4F1X39TiTYm0aLN1hQd2yHLb_eE3OxgdKFI86IVtws1_g";
reMapKeyHash["publiccax.raileurope.com:7984"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRquDfQDk74sy-shhEoREjspllmFxQniZgxzKzI3m-jM8Lj10iFsixvAA";
reMapKeyHash["publiccax.raileurope.com:7996"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRUmz0MHhNtbag-nFIcXpGWPr-6FhS_fxgB96IOmH9f7ysYGD7-DbPe0A";
reMapKeyHash["publiccax.raileurope.com:8080"]="ABQIAAAALSzvtw6mKXVv8H8c9rcmExToPR51afKqwNl4zJsVjnptJhFomhScGwdlGj5dUM3N96x9Ate0GwSkQQ";
reMapKeyHash["publiccax.raileurope.com:8082"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShSO0DTax-Q3Flu8rzpo5WRPyBQpbBQ01DeTWENX5uIsxrUvRwzS4ag-WA";
reMapKeyHash["publiccax.raileurope.com:8084"]="ABQIAAAAcqR3d1xk1djKX59fNj1Q9RS9Z07sNSYTdLYxNN2Q1HOr_uMF7RTs8PPByFzym34L44icUF2Mtu-CtQ";
reMapKeyHash["publiccax.raileurope.com:8098"]="ABQIAAAAcqR3d1xk1djKX59fNj1Q9RSfueUS_Cwqy2j5sGiql4KfE0IjLRQycSQOUy0XlDPejaSEVHMT2S5Daw";

// Myswitzerland
reMapKeyHash["myswitzerlandx.raileurope.com"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShSNWZjkdDXwLD9kp0YeoHKDM05C4BTHTHf69rUmDrOAOsrnuchB-sY4UA";
reMapKeyHash["traintickets.myswitzerland.com"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShQRLYC_3Hrmw_rr0yJUiD0VDOW3tRS5pxhQJxhFWPV91h49oklL0oeGHA";
reMapKeyHash["myswitzerlandx.raileurope.com:7976"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRsxbkhQnlukzULF-px0NsZwUqExBSO_t_mcUe_mQjrhVx1I3_Q_sun6Q";
reMapKeyHash["myswitzerlandx.raileurope.com:7982"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRnzaqLmUFwA4z8RQg7yIo3wHBTXhSwvkPBdWh7ZD9HHZKTqZ-zftzOIw";
reMapKeyHash["myswitzerlandx.raileurope.com:8080"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRaIDE4FEcoLmG6puEtal7TlIuVLBTxMUOyCDRi5oov96SkkVWz5C7RSA";
reMapKeyHash["myswitzerlandx.raileurope.com:8082"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRUmNENcTDC_6mYsHDQ04n_lVArUBSn1nuabqAgnQsa134yJTKZQ1_LeA";
reMapKeyHash["myswitzerlandx.raileurope.com:8084"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRUgHVc0i8QBatpjG5zVUWAXKtyaBQtQxB_0RMCUTHh1ElcTzgAqXm8Nw";
reMapKeyHash["myswitzerlandx.raileurope.com:8098"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShQZ_tQQJNIQ5oRs1WsZ1Y1aCyTiaxT37aO2HIvfYxKmo1DFI4Q2ni1L4w";

// Agent  
reMapKeyHash["agentx.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxTYasKIKmKBW3t_4T4LYXigieYaxxQM-_OBNyo4n9aTyaoHnFvGFAX-rQ";
reMapKeyHash["agent.raileurope.com"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShTrYV_BuhzIK0ekYox01biDYpj3YRQSRgQAYh5nKWv2vgBGgHSW4UT-jQ";
reMapKeyHash["agentx.raileurope.com:7976"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRV0HUvsOpl9Pqo6SMQhE3mdY4BpBRj_cS2tU1tPJpg9uIdrkcgqYL3Dg";
reMapKeyHash["agentx.raileurope.com:7982"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShT9OwLhKvaqdkLutcfQBB9F6ibpTRT6IhcbC3zVLjjDgHa5wlfMllYxoA";
reMapKeyHash["agentx.raileurope.com:8080"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShTIYoO0tM-a3_g_8Sky3gugehr8oxQX2Zh1MLkU8ouHIrrkV0mO8RJP7g";
reMapKeyHash["agentx.raileurope.com:8082"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShTb-i5WapaqqeLyNTA_MGhMtq3yVRSQZe2rJTM8mQTJPygl7gIUCVO4BA";
reMapKeyHash["agentx.raileurope.com:8084"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShQmNKcREmZ1HB8hJFL7am-AK9Nl1BSrhi9pPJTV6UEwjBaO5vqSN1bsBA";
reMapKeyHash["agentx.raileurope.com:8098"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRv3Fys-c5qRuJ7ucLD6gCzAsN26RRt5qSTxRODV79Ar7VQjW9UZto-3Q";

// Agentca
reMapKeyHash["agentcax.raileurope.com"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRAZT-CgH3b8TsxcNKCO9Po1bR2yBRtkABSZz1x2BP2fkhUDrb6ZUm7PA";
reMapKeyHash["agent.raileurope.ca"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShQaz_gMbqM-FnPQv0VgqDGpp1M89xSR5XxXofJBxPVSlKbfhaYb0IxfCA";
reMapKeyHash["agentcax.raileurope.com:7976"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShSpCxYHbKiaGSVVdOG4QmF50kPb1xR-ZttL4mYd4KQMXU5Mcqavp2iqbA";
reMapKeyHash["agentcax.raileurope.com:7982"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShTYFVx8aMl6BZtU0SGnCI4cGO4alhQ0L2ukGmR-gA-GeBIeGPB9itc_Rg";
reMapKeyHash["agentcax.raileurope.com:8080"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShTTomBiteAN0PVkGXHODqPBGagt0BRiu6ZNMJeGVnq0_mL_m-2xZuojXQ";
reMapKeyHash["agentcax.raileurope.com:8082"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShQD1AK3UQDOza_rtOuwNN1-81CjhRTW3q1glk83CYgGlVpA8pejEJPzLg";
reMapKeyHash["agentcax.raileurope.com:8084"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShSneqLnLpuB5GSkMlp9MSYP8MZ8BBTaWZX0LoQA0JWvZi64MQ0LAbLz2Q";
reMapKeyHash["agentcax.raileurope.com:8098"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRqd_aJ7DaVhYleq3Mb95Tq86YtkhTfyGP6poDulOJb02ATKP9Sigb9SQ";

// Travelocity
reMapKeyHash["travelocityx.raileurope.com:8098"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxQFmPaA_TaI0zFHc6IrFVszN8PDzBRg4YDGYFM0EoYIf05uvcMhlMe9GA";
reMapKeyHash["travelocityx.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxRgIhZRHQTca3WNi9FXHGwzWe5-4hR9gyMK7CnusumT7YUn7t31ppZTLA";
reMapKeyHash["travelocitycax.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxRIjjeSqiNg8OFdwcbVME3IhCZvXhRsCiblXUpsL1ZD1Vs5cFrPM0fawQ";
reMapKeyHash["travelocity.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxSKh7mNs4NBGFhoOJTmY9Z9x9NKIBTAMtXNhUptfiQftDTiuJiPKZizwQ";
reMapKeyHash["travelocity.raileurope.ca"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxRSBxuG9RBFWg3wlX1hymATjn1GmxSPFlvsMmcHxwvgTUW5KscyNzsAfg";

// Linkparis
reMapKeyHash["linkparisx.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxTAUmD3IDhNxWb_Z6TTRHADHBUNSRR7gEsWAtrAMyrbQ8ea1nZjiUf6mQ";
reMapKeyHash["linkparis.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxRCIiWSw7ln-IaCrsnPfRoBbfyroRRkypKqN5kKQUawoEL_0bvk1p0d2w";

// Oct 15 launch cobrands
reMapKeyHash["autoeuropex.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxTJEqmq8DzlLW2GvvcWJL0DcgzNNhT07uDIVp9VkmP0CzJWN97_V4cRNQ";
reMapKeyHash["autoeurope.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxRdkw869KOdlw-Ppm4UT1mhXF-3uBS6iQJqFMnm_pmhPz24LK4GBWA3Qg";

reMapKeyHash["travelcutscax.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxQcpOj6y1Ux0fGp8fjsP9z1Kqw8AxQTt5jPQShcieGzNGCm0NFNnZ3nmA";
reMapKeyHash["travelcutsca.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxS5o86tRkdHO83IEOdZhiIiXbS-vhSLtB6dZxFsSdlqY7evCds8UCNnMg";

reMapKeyHash["travelcutsusx.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxR50aKJAgVhzAMQGBbI2PwWT9Qo2RSDcApunUAOYlx6ZwxVGxOEE2IO_w";
reMapKeyHash["travelcutsus.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxROkQbd0yhZD-UlkEmAlC5GXluDqBSNt0AbZXFuXzjhbwGyHNZDQ59OLA";

reMapKeyHash["vacationsbyrailx.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxRSGj_4m87VxSI-HE2S5YlnlakNoRQegpsvx25tRwSdwnHTMuMLrW1smQ";
reMapKeyHash["vacationsbyrail.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxSvLj9i72LOQnPgGgxQNvXt1MWAJRRV7T88FsJlycb8Mrd2xrI6PDvNzg";

reMapKeyHash["autoeurope.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxRdkw869KOdlw-Ppm4UT1mhXF-3uBS6iQJqFMnm_pmhPz24LK4GBWA3Qg";
reMapKeyHash["travelcutsca.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxS5o86tRkdHO83IEOdZhiIiXbS-vhSLtB6dZxFsSdlqY7evCds8UCNnMg";
reMapKeyHash["travelcutsus.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxROkQbd0yhZD-UlkEmAlC5GXluDqBSNt0AbZXFuXzjhbwGyHNZDQ59OLA";
reMapKeyHash["vacationsbyrail.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxSvLj9i72LOQnPgGgxQNvXt1MWAJRRV7T88FsJlycb8Mrd2xrI6PDvNzg";

// Oct 29 launch cobrands
reMapKeyHash["aaa.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxRy5CKxNuEjD6OytubuUr48dUM8JRQ5SbY0dMvaiQ6VMWCAOdx76GAnHQ";
reMapKeyHash["aaapublicx.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxQ9N2UujM9AeBidRMWO8cZhVImaqRSRDLrIubECCvHAW0Gjec9chSIO_w";

reMapKeyHash["aaapubliccax.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxT_o-Wfrq3TMw3Msf9IGPXNewCHvBQWMjaVab0Ec0Tg1cRwDitM8rt9fA";
reMapKeyHash["aaa.raileurope.ca"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxQ77RLTKGC3ohrAaCBHtCtBDT02SRSaudk-p3RNwx1__a_1YNsp_Np4Bw";

reMapKeyHash["rickstevesx.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxTW7lO-KgYBV-xDsYRHw32DnsS5TBQSnKyKp1Dxj7tIDH69RG0XXdH0PQ";
reMapKeyHash["ricksteves.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxS_zlhOXC-XPfeKXrT826nMT5WghBQdKww48wfslVsCLgvmFCNkJp19kA";

// espanol
reMapKeyHash["espanolx.raileurope.com:7982"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRG2j4nq-aggC5vCikHv5T5zEjxaBSJZZK2oQC5ReVbZ2V9aBDbP413qg";
reMapKeyHash["espanolx.raileurope.com:8098"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxRwDT9rkRk9lb1ZreMUSCKMwn1X8hT-Xzl6V-56J8OGxjoets_Dw710jg";
reMapKeyHash["espanolx.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxRv3_PpWyxS97qaoo6z3w0O-yPfVBQaFjibnm3bL8-Ga_KjdJHBvEtWnw";
reMapKeyHash["espanol.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxQOB_uMFtjxnNQc7-hhj3cVOuHzUhS807RVyS1r9S9AjAeDdHF6_MS4Tw";
reMapKeyHash["www.raileurope.com.mx"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxSEQO9PRyHyOZZ4b9e7xjG2SVWW-RTIUnfn90p49IKGIPxJeipfSd5nBA";

// onetravel
reMapKeyHash["onetravelx.raileurope.com:8082"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShQeX1SYXxrH-83sIOfdnEjeu7YqmBTeM5eNGYP8PxC-g1wuuztCwZ_UKg";
reMapKeyHash["onetravel.raileurope.com"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShSzI9qeubm_g1UcoH-rwRutVK6YkhSomavJH_cAEshHNIIQmqwssrbFgg";
  
// vacationsbyplaza
reMapKeyHash["vacationsbyplazax.raileurope.com:8082"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShTpj-3ClFOT2Jk_0oNjhhNlaji6VBRvybU9CSJwqslFXfCJKedz2W6T9w";
reMapKeyHash["vacationsbyplaza.raileurope.com"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShRJIx3kkZBzZI9HhV045vUp_xRT_RTXzq9Ry6vD9f8V7zTYy_4yiGxBxQ";

// railtrains
reMapKeyHash["railtrainsx.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxTEmk_p1ydmAQ63K4vT10DwyXyyLhTFY9Y_JbWPqGY4P_VjZg9z_Tp97w";
reMapKeyHash["railtrains.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxR1ZDfl4xIU5AWu6iY6GFvtnlIa8RQmDKoNcX6HW3zGNaGgj9fICEjMCQ";

// gemut
reMapKeyHash["gemutx.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxQqHkVhhJECWvzB4FKUig61y6eYQBTvDfs9-H6s1jlZLQ5auLyczvfw8g";
reMapKeyHash["gemut.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxROxTAQ2WqEWlv1kVOMdb8pgYn9_RTjrXfjvG-4C8Gyi5O_VmKeH7rxyQ";

// britishrail
reMapKeyHash["britishrailx.raileurope.com:7982"]="ABQIAAAA870VeoE0UwGR_0-gdeBLShSKHbTdF3q6G-s6VM9sDB71F2zvvxQ1dkSdKmQeX70xTFqECN-dlnbXFw";
reMapKeyHash["britishrailx.raileurope.com:8082"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxR3WAs5SWoxfUE3MUT3EGUOkGuEZxSDuskm4pi7dCHOYDx416CwK7IJ3A";
reMapKeyHash["britishrailx.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxS8JDourCDvM5kNvptaZbKBvGLNAhQiLG9DsF_rkT4YY8Wwd2IpN1c3kg";
reMapKeyHash["britishrail.raileurope.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxQw2rXbkMlEe0uk41esa9-8tYk5UhQkJyObA8u1_wOExdy_9nwNANxSNA";
reMapKeyHash["traintickets.britishrail.com"]="ABQIAAAAXV43FzD9UR1_ru5EPXuHAxQ8fGKGf9YfHiXZr_TZo32icOzdnBRu3kDxb-83XJ-0TPxPs_E8k-_5Hw";

var reMapKey = getRegMapKey();
//alert("key="+reMapKey);
if ((reMapKey == null) || ('https:' == document.location.protocol)){
	//do nothing
//  alert commented, since this file is now included on the secure pages - NK	
//  alert("There is no Google Maps API key avaiable for this web site " +
//    window.location.host +
//    ".\nYou can generate a new key at http://code.goo"+
//    "gle.com/apis/maps/signup.html");
}
else {
  document.write(unescape("%3Cscript src='http://maps.goo"+
    "gle.com/maps?file=api&amp;v=2&amp;key=" + reMapKey + 
    "' type='text/javascript'%3E%3C/script%3E"));
}
  
// Provides a layer of abstraction to get the REG map key
function getRegMapKey() {
  return reMapKeyHash[window.location.host];
}

/** ======================================================================
 * Adds an icon type to the icon collection
 * ======================================================================*/  
function setupIcons() {
  reMapIcons["start"]= new GIcon(G_DEFAULT_ICON, "/img/maps/colour086.png"); // yellow
  reMapIcons["end"]  = new GIcon(G_DEFAULT_ICON, "/img/maps/colour108.png"); // purple
  reMapIcons["mid"]  = new GIcon(G_DEFAULT_ICON, "/img/maps/colour125.png"); // white  
  reMapIcons[0]=true; // an indicator that the array has been initialized
}
  
/** ======================================================================
 * This fuction serves as an example of the multiple maps on a page.
 * It is called when the page is loaded - uses div id="map0" and id="map1"
 * ======================================================================*/
function mapExample() {
  setupMap(0);
  setupMap(1);
}

/** ======================================================================
 * Creates and draws the map with points and polyline on the given div
 * It is called when the page is loaded
 * ======================================================================*/
function setupMap( index ) {
  if ( reMapKey!=null && GBrowserIsCompatible() ) 
  {
    var divName = "map"+index;
  
    var points = []; // array of points GLatLng(lat,lng)
    points["london"]  = new GLatLng(51.503186376638006,-0.113983154296875);
    points["ashford"] = new GLatLng(51.14510969340906,0.8704948425292969);
    points["dover"]   = new GLatLng(51.114084037020504,1.3128662109375);
    points["calais"]  = new GLatLng(50.91299128345898,1.8051910400390625);
    points["lille"]   = new GLatLng(50.62768660650907,3.044586181640625);
    points["paris"]   = new GLatLng(48.865618158309374,2.3490142822265625);
    
    var stations = [];
    stations["london"]  = '["Train station", "Attriactions", "Hotels"],["<b>St. Pancras train station</b><br/> is located in a central London","There are countless turist attractions<br/> but not limited to  <li>galleries</li><li>museums</li><li>concerts</li>","Seach for hotel in <a href=\\"http://www.raileurope.com/us/hotels/index.htm?countryCode=GB&cityName=London\\">London</a><br/><img src=\\"image.jpg\\"/>"]';
    stations["ashford"] = '<b>Ashford</b> station in England.';
    stations["dover"]   = '<b>Dover</b> station in England.';
    stations["calais"]  = '["Tab label"],["<b>Calais</b> station in France.<br/> has a plain info with no tabs"]';
    stations["lille"]   = '["Train station", "Info"],["<b>Lille</b> station in France.<br/> has a great newly build train terminal<br/>with many great restaurants and caffe shops", "Its the time to decide to go <br>to Paris or Amsterdam"]';
    stations["paris"]   = '["One","Two","Three","Four"],["Tab 1 contents", "Tab 2 contents","Tab 3 contents","Tab 4 contents"]';
  
    // create the markers
    var markers = [];
    markers.push(getMarker('London', 'start', points["london"], stations["london"]));
    markers.push(getMarker('Ashford', 'mid', points["ashford"], stations["ashford"]));
    markers.push(getMarker('Dover', 'mid', points["dover"], stations["dover"]));
    markers.push(getMarker('Calais', 'mid', points["calais"], stations["calais"]));
    markers.push(getMarker('Lille', 'mid', points["lille"], stations["lille"]));
    markers.push(getMarker('Paris', 'end', points["paris"], stations["paris"]));
    
    createMap(divName, markers);
  }
}
  
/** ======================================================================
 * Creates and draws the ptp map with points and polyline on the given div
 * ======================================================================*/  
function createPtpMap(divName, markers) { 
  if (!validMarkers(markers)) {
    displayNoPtpMap(divName);
    return null;
  }
  
  // create the polyline
  var color = "#10C3F7"; var weight = 5; var opacity = 0.6;
  var polyline = createPolyline(markers, color, weight, opacity);
  var bounds = polyline.getBounds();
  
  // create the map
  var map = new GMap2(document.getElementById(divName));
  map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
  
  // Attached the poliline parameters to map
  map.poliColor = color;
  map.poliWeight = weight;
  map.poliOpacity = opacity;
  
  // Sets the map type
  map.addMapType(G_PHYSICAL_MAP);
  map.setMapType(G_PHYSICAL_MAP);
  
  map.removeMapType(G_NORMAL_MAP);     // removes default road type
  map.removeMapType(G_SATELLITE_MAP);  // removes satelite
  map.removeMapType(G_HYBRID_MAP);     // removes hybrid
  
  // Add controls
  map.addControl(new GSmallZoomControl3D());

  // Draw markers on the map
  for( var i=0; i< markers.length ; i++) {
    map.addOverlay(markers[i]);
  }
  
  // Draw the polyline
  var drawPoli = (createPtpMap.arguments[2]!=null)? 
    createPtpMap.arguments[2]:  true;
  
  if( drawPoli ) map.addOverlay(polyline);
  
  // Saves map reference
  reMaps.push(map);
  return map;
}
  
/** ======================================================================
 * Creates and draws the map with points and polyline on the given div
 * ======================================================================*/
function createMap(divName, markers) 
{ 
  // alert("Entering createMap with divName="+divName+".")
  // create the polyline
  var color = "#FF0000"; var weight = 6; var opacity = 0.5;
  var polyline = createPolyline(markers, color, weight, opacity);
  var bounds = polyline.getBounds();
  
  // create the map
  var map = new GMap2(document.getElementById(divName));
  map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
  
  // Sets the map type
  map.addMapType(G_PHYSICAL_MAP);
  map.setMapType(G_PHYSICAL_MAP);
  
  // keep the normal map for country name in the overview (small) window
  // map.removeMapType(G_NORMAL_MAP);   // removes default road type
  map.removeMapType(G_SATELLITE_MAP);   // removes satelite
  map.removeMapType(G_HYBRID_MAP);      // removes hybrid
  
  // Add controls
  map.addControl(new GMenuMapTypeControl(true)); // displays selection
  // map.addControl(new GMapTypeControl());    // displays all map types 
  // map.addControl(new GScaleControl());      // displays scale 
  
  //map.addControl(new GLargeMapControl());
  map.addControl(new GSmallMapControl());
  //map.addControl(new GOverviewMapControl());
  var mini = new GOverviewMapControl();   //Set up overview control
  map.addControl(mini);                   //Add overview control 
  mini.hide();                            //minimize overview

  // Sets options
  // map.enableGoogleBar();
  // map.enableScrollWheelZoom();
  
  // Draw markers on the map
  for( var marker in markers) {
    map.addOverlay(markers[marker]);
  }
  
  // Draw the polyline  
  map.addOverlay(polyline);
  
  // Saves map reference
  reMaps.push(map);
  return map;
}
  
/** ======================================================================
 * A function to add a marker for a given city, icon type, point and description
 * Based on the icon type (start, mid, end) a different icon is drawn
 * ======================================================================*/
function getMarker( city, type, point, html ) {
  // alert("Entering getMarker() with city="+city+", type="+type+", point="+ point+", html="+html+".");
  // Create an associative array of GIcons()
  if( reMapIcons.length == 0 ) setupIcons();
  
  var icon = reMapIcons[type];
  var index = html.indexOf("],[");
  if( index == -1) return createMarker(point, icon, html, city);
  
  var labels = html.substring(0, index+1); //alert("labels="+labels);
  var htmls= html.substring(index+2);      //alert("htmls="+htmls);
  return createTabbedMarker(point, icon, eval(htmls), eval(labels), city);
}
  
/** ======================================================================
 * A function to create the marker and set up the event window
 * at specified point with given icon, html and name
 * ======================================================================*/
function createMarker(point, icon, html, name) {
  //creates a marker with specified icon
  var marker = new GMarker(point, {icon:icon, title:name});
  // add event handler for 'click'
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
  });
  return marker;
}

 /** ======================================================================
 * A function to validate the given markers for correct Lat and Long
 * Returns true is all markers are valid, false otherwise
 * ======================================================================*/
function validMarkers(markers) {
  var result = typeof (markers)!='undefined' && markers;
  
  for (var i=0; i<markers.length; i++) {
    var latLng = markers[i].getLatLng();
    var lat = latLng.lat();
    var lng = latLng.lng();
    if (!validNonZeroGeo(lat) || !validNonZeroGeo(lng) ) {
      result = false;
      break;
    }
  }
  return result;
} 

/** ======================================================================
 * A function to validate the given geo location
 * Returns true is goe-location is non-zeronumber, false otherwise
 * ======================================================================*/
function validNonZeroGeo(num) {
  var number = num*1.0;
  var result = !isNaN(number) && number!=0;
  //alert("inside validNonZeroGeo with number="+ number+ ", result="+ result)
  return result;
}
  
/** ======================================================================
 * A function to display the image if a map is not available
 * ======================================================================*/
function displayNoPtpMap(divName) {
 var code = '<img src="/redesign/images/map-not-available.gif">';
 $('#'+divName).html(code);
}
  
/** ======================================================================
 * A function to create a tabbed marker and set up the event window,
 * accepts a variable number of tabs, passed in arrays of labels and htmls
 * ======================================================================*/
function createTabbedMarker(point, icon, htmls, labels, name) {
  var marker = new GMarker(point, {icon:icon, title:name});
  GEvent.addListener(marker, "click", function() {
    // adjust the width so that the info window is big enough for many tabs
    if (htmls.length > 2) {
      htmls[0] = '<div style="width:'+htmls.length*88+'px">'+htmls[0] +'</div>';
    }
    var tabs = [];
    for (var i=0; i<htmls.length; i++) {
      tabs.push(new GInfoWindowTab(labels[i],htmls[i]));
    }
    marker.openInfoWindowTabsHtml(tabs);
  });
  return marker;
}
  
/** ======================================================================
 * A function to create a polyline (does not draw one)
 * Accepts an array of markers (not vertexes) and other display arguments
 * ======================================================================*/
function createPolyline(markers, color, weight, opacity) {
  var size = (markers==null)? 0 : markers.length;
  if(size < 2) return;
  
  // This code is for a line with two and more points
  var vertexes = [];
  for( var i=0; i<markers.length; i++) {
    vertexes.push(markers[i].getLatLng());
  }
  return new GPolyline( vertexes, color, weight, opacity );
}


/** ======================================================================
 * Creates and draws the map with points on the given div
 * It is called for cms map, needs Lon and Lat for a give city or station
 * ======================================================================*/

function createCmsMap(lon, lat) {
  if (reMapKey!=null && GBrowserIsCompatible() ) {
    var map = new GMap2(document.getElementById("cms_map"),
    { size: new GSize(256,256) } );
    map.setCenter(new GLatLng(lon,lat), 11);  
  }
}


