/* Country State Drop Downs v1.1. (c) Copyright 2006 by Down Home Consulting, Inc (www.DownHomeConsulting.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ //js file for international splash //country contains a string of sets of country codes and country names in the following format: // ES:Spain|GP:Guadeloupe|.....|UY:Uruguay //Note: Entries are separated by vertical bar. There is no vertical bar following the // final entry. var country = ""; //language contains a string of sets of country codes, each followed by all the language specifications //for that country. Each entry has the following format: // ES:CA,Catalan;EN,English;ES,Spanish|GP:EN,English;FR,French|......|UY:ES,Spanish //Note: Entries for each country are separated by vertical bar. There is no vertical bar following // the final entry. var language = ""; //Associative array, where the lookup key (array index value) is country code. Each element of the //array is an array of languages. Each element of the language array is itself an array, containing //language code and language. var countryLanguages = []; //empty two dimensional array (hash table) to map languages to each country //Provided by Down Home Consulting function TrimString(sInString) { if ( sInString ) { sInString = sInString.replace( /^\s+/g, "" );// strip leading return sInString.replace( /\s+$/g, "" );// strip trailing } } //Provided by Down Home Consulting //Populates the country select element with the countries from the country list //idName - the HTML id of the country select element. function populateCountry(idName) { var countryLineArray = country.split('|'); // Split into lines var selObj = document.getElementById( idName ); for (var loop = 0; loop < countryLineArray.length; loop++) { lineArray = countryLineArray[loop].split(':'); countryCode = TrimString(lineArray[0]); countryName = TrimString(lineArray[1]); if ( countryCode != '' ) { selObj.options[loop] = new Option(countryName, countryCode); } } } //Populates the options array of a language select element. //countrySelObj - the select element that contains a selected country code //langSelObj - the select element that is to be populated with languages for the selected country function populateLanguage(countrySelObj, langSelObj) { var countryCode = countrySelObj.options[countrySelObj.selectedIndex].value; var languageArray = countryLanguages[countryCode]; var langOptions = langSelObj.options; langOptions.length = 0; for (var i = 0; i < languageArray.length; i++) { langOptions[langOptions.length]= new Option( languageArray[i][1], languageArray[i][0]); } } //Initializes the countryLanguages associative array for looking up //a list of languages given a country code (see populateLanguage()above). function initLanguages() { var languageLineArray = language.split('|');//splits into lines for (var loop = 0; loop < languageLineArray.length; loop++) { lineArray = languageLineArray[loop].split(':'); countryCode = TrimString(lineArray[0]); countryLanguagesLine = TrimString(lineArray[1]); countryLanguagesLineArray = countryLanguagesLine.split(';');//array of lines, each containing languageCode,language //For each language, add a two element array to the list for this country. Each //two element array contains [0]=languageCode [1]=language countryLanguages[countryCode] = []; for (var i = 0; i < countryLanguagesLineArray.length; i++) { //creates an array of languageCode,language countryLanguages[countryCode][i] = countryLanguagesLineArray[i].split(',');//[i][0]=languageCode [i][1]=language } } } //Given a country code, select it in the country select element, and //cause the language select element to be appropriately populated. function selectCountry(countryCode, countrySelObj, langSelObj) { for(var i=0; i < countrySelObj.options.length; i++) { if (countrySelObj.options[i].value == countryCode) { countrySelObj.selectedIndex = i; populateLanguage(countrySelObj, langSelObj); } } }