// Javascript document for language and country tooltips on splash page.

/* <![CDATA[ */
/* COUNTRY / LANGUAGE SELECTION */
  var selected_country = '';
  var selected_lang    = '';

  var langs = ['en','es','fr','nl','de'];
  var selections = { 'zz': ['en'],
					 'us': ['en','es'],
					 'ca': ['en','fr'],
					 'gb': ['en'],
					 'nl': ['nl'],
					 'de': ['de'],
					 'be': ['nl']
					 /*'ie': ['en']*/
				   };

/*
  UPDATED!!
  list of values:names for language pulldown
*/
 var lang_names = {
					'en' : 'English',
					'es' : 'Spanish',
					'fr' : 'French',
					'nl' : 'Dutch',
					'de' : 'German'
				   };
/*
  END UPDATED!!
*/

  initUI = function()
  {
	 $$('.controlset input').each(function(i) {Event.observe(i,'click',updateSelectionEvent);});
  }

  updateSelectionEvent = function(evt)
  {
	 var selected_country = Event.element(evt).value;
	 updateSelection(selected_country);
  }
  
  
  

  /*
	 UPDATED!!

	updateSelection
	 - updated to fix bugs with IE/Opera browsers
  */
  updateSelection = function(selected_country)
  {
	 //get collection of country radio buttons
	 var country_select = Form.getInputs('preferences_form','radio','country');

	 //loop thru collection and select the correct option
	 country_select.each(function(cc)
	 {
	   if (cc.value == selected_country) { cc.checked = true; }
	 });
	
	 //get language list of language select box
	 var lang_c = selections[selected_country];

	 //language <select> object
	 var lang_select = $('language');

	 //remove all language <option> tags
	 while (lang_select.firstChild) {lang_select.removeChild(lang_select.firstChild);}

	 //add options for selected country
	 var opt_count = 0;
	 //lang_select.options[0] = new Option('','');
	 $H(lang_names).each(function(op) { lang_c.each(function(i) { if (i == op.key) { lang_select.options[opt_count++] = new Option(op.value,op.key); return false; } }); });

   return false;
  }
/*
  END UPDATED!!
*/
  


  Event.observe(window,'load',initUI);
  /* ]]> */
