/* * Commented out code sets the options back to their defaults. This * ensures that the options are correctly retained when the page is * entered via the back button. Unfortunately, this has the undesirable * effect of allowing a user to select an invalid country. Since the latter * is more undesirable than the former the code has been commented out. */ /* var COUNTRIES; var COUNTRIES_INDEX; */ var ADJOINED_COUNTRIES= new Array(); ADJOINED_COUNTRIES["Austria"]= new Array("Germany", "Hungary", "Italy", "Slovenia/Croatia", "Switzerland"); ADJOINED_COUNTRIES["Benelux"]= new Array("France", "Germany"); ADJOINED_COUNTRIES["Denmark"]= new Array("Germany", "Norway", "Sweden"); ADJOINED_COUNTRIES["Finland"]= new Array("Germany", "Sweden"); ADJOINED_COUNTRIES["France"]= new Array("Benelux", "Germany", "Ireland", "Italy", "Spain", "Switzerland"); ADJOINED_COUNTRIES["Germany"]= new Array("Austria", "Benelux", "Denmark", "Finland", "France", "Sweden", "Switzerland"); ADJOINED_COUNTRIES["Greece"]= new Array("Italy", "Serbia/Montenegro/Bulgaria"); ADJOINED_COUNTRIES["Hungary"]= new Array("Austria", "Romania", "Slovenia/Croatia", "Serbia/Montenegro/Bulgaria"); ADJOINED_COUNTRIES["Ireland"]= new Array("France"); ADJOINED_COUNTRIES["Italy"]= new Array("Austria", "France", "Greece", "Slovenia/Croatia", "Spain", "Switzerland"); ADJOINED_COUNTRIES["Norway"]= new Array("Denmark", "Sweden"); ADJOINED_COUNTRIES["Portugal"]= new Array("Spain"); ADJOINED_COUNTRIES["Spain"]= new Array("France", "Italy", "Portugal"); ADJOINED_COUNTRIES["Sweden"]= new Array("Denmark", "Finland", "Germany", "Norway"); ADJOINED_COUNTRIES["Switzerland"]= new Array("Austria", "France", "Germany", "Italy"); ADJOINED_COUNTRIES["Romania"]= new Array("Hungary", "Serbia/Montenegro/Bulgaria"); ADJOINED_COUNTRIES["Slovenia/Croatia"]= new Array("Austria", "Hungary", "Italy", "Serbia/Montenegro/Bulgaria"); ADJOINED_COUNTRIES["Serbia/Montenegro/Bulgaria"]= new Array("Greece", "Hungary", "Romania", "Slovenia/Croatia"); var N_SELECT_COUNTRIES= 5; /* Given the index [1..N_SELECT_COUNTRIES] of the current selection, * set the next country selection to a list of legal countries and all * remaining country selections to an empty set of countries. */ function setSelects(form, currentSelect) { var selectToFill= currentSelect + 1; for (i= selectToFill; i <= N_SELECT_COUNTRIES; i++) { //empty out options. form.elements["selCountry" + i].options.length= 2; form.elements["selCountry" + i].options[0].selected= true; } var countries= getCountries(form, selectToFill - 1); if (countries.length > 0) fillBox(form, selectToFill, countries); /* var select= form.elements["selCountry" + currentSelect]; var selectCountry= select.options[select.selectedIndex].value; select.options.length= 2; for (var i= 0; i < COUNTRIES.length; i++) { var c= COUNTRIES[i]; select.options[select.options.length]= new Option(c, c); } var selectedIndex= COUNTRIES_INDEX[selectCountry] + 2; for (var i= 0; i < select.options.length; i++) { select.options[i].selected= (i == selectedIndex); } */ } /* Return the union of the countries adjacent to the selected countries * with indexes in [1..lastSelectIndex] minus the selected countries. */ function getCountries(form, lastSelectIndex) { //var form= document.forms[0]; var selectedCountries= new Array(); for (var i= 1; i <= lastSelectIndex; i++) { var select= form.elements["selCountry" + i]; selectedCountries[select.options[select.selectedIndex].value]= 1; } var countries= new Array(); for (var i= 1; i <= lastSelectIndex; i++) { var select= form.elements["selCountry" + i]; if (select.selectedIndex < 2) select.selectedIndex = 2; var selectCountry= select.options[select.selectedIndex].value; var adjCountries= ADJOINED_COUNTRIES[selectCountry]; for (var j= 0; j < adjCountries.length; j++) { var c= adjCountries[j]; if (!selectedCountries[c]) { var found= 0; for (var k= 0; k < countries.length; k++) { if (countries[k] == c) { found= 1; break; } } if (!found) countries[countries.length]= c; } } } return countries.sort(); } function fillBox(form, selectToFill, countries) { var select= form.elements["selCountry" + selectToFill]; for (var i= 0; i < countries.length; i++) { select.options[select.options.length]= new Option(countries[i], countries[i]); } } function onLoadSetup(formName) { /* COUNTRIES= new Array(); for (var c in ADJOINED_COUNTRIES) { COUNTRIES[COUNTRIES.length]= c; } COUNTRIES.sort(); COUNTRIES_INDEX= new Array(); for (var i= 0; i < COUNTRIES.length; i++) { COUNTRIES_INDEX[COUNTRIES[i]]= i; } */ formName = 'ProductForm'; setSelects(document[formName], 1); }