
var LI = LI || {
    popup: function(html) {
	var w = 300;
	var h = 200;
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);

	TheNewWin = window.open('','name','toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+w+',height='+h+',top='+top+',left='+left);
	TheNewWin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd">');
	TheNewWin.document.write('<html xmlns="http:\/\/www.w3.org\/1999\/xhtml">');
	TheNewWin.document.write('<head><title>Popup<\/title><script><\/script><\/head>');
	TheNewWin.document.write('<body style="overflow:hidden" bgcolor="#ffffff">');
	TheNewWin.document.write(html);
	TheNewWin.document.write('<\/body><\/html>');
	return false;
    }
};

LI.regionDropdown = LI.regionDropdown || {
	refreshCountryOptions: function(field) {
		var form = $($(field).parents("form")[0]);
		var languageSelected = form.find(":input[name=language] option:selected").val();
		var countrySelected = form.find(":input[name=country] option:selected").val();
		var country = form.find(":input[name=country]");

		country.empty()
		if (LI.availability[languageSelected]) {
		  country.addOption(LI.availability[languageSelected],'');
        }
        country.sortOptions();
		if(LI.translations['any country']) {
			$(country).prepend('<option value="any">'+LI.translations['any country']+'</option>');
		} else {
			$(country).prepend('<option value="any">any country</option>');
		}
		country.selectOptions(LI.countryDefaults[languageSelected]);
		country.selectOptions(countrySelected);
		$("#edit-duration").val("any");
	},
	refreshRegionOptions: function(field) {
		var form = $($(field).parents("form")[0]);
		var languageSelected = form.find(":input[name=language] option:selected").val();
		if(languageSelected == null) {
		  //language might be hidden
		  languageSelected = form.find(":input[name=language]").val();
		}
		var countrySelected = form.find(":input[name=country] option:selected").val();
		var regionSelected = form.find(":input[name=city] option:selected").val();
		var region = form.find(":input[name=city]");

		region.empty();
		if (LI.regionData[languageSelected][countrySelected]) {
	  	  region.addOption(LI.regionData[languageSelected][countrySelected],''); 
        }
        region.sortOptions();
		if(LI.translations['any city']) {
			$(region).prepend('<option value="any">'+LI.translations['any city']+'</option>');
		} else {
			$(region).prepend('<option value="any">any city</option>');
		}
		region.selectOptions(LI.regionDefaults[countrySelected]);
		region.selectOptions(regionSelected);
	},
	defaultCountry: function() {
		$("#edit-country").selectOptions(LI.countryDefaults[$("#edit-language option:selected").val()]);
	},
	defaultRegion: function() {
		$("#edit-region").selectOptions(LI.regionDefaults[$("#edit-country option:selected").val()]);
	},
	showRegions: function(countryField) {
		if($(countryField).val() == 'any') {
		  $("#edit-region").hide();
		} else {
		  $("#edit-region").show();
		}
	}

};

/* Utilities */
function showInfo(id){
  e = $('#e-'+id+'');
  if (e) e.hide(); 
  i = $('#i-'+id+'')
  if (i) i.show();
}
function hideInfo(id){
  e = $('#e-'+id+'');
  if (e) e.show(); 
  i = $('#i-'+id+'')
  if (i) i.hide();
}

