function populateOceans(){
	var country = $('country');
	alert(country.id);
}
	
var addItems = function(oceans, field){		
	oceans.each(function(theocean) {			

		var o = new Element('option', {
                        'value':theocean.ocean_id,
                        'html':theocean.ocean_name
                    });

		o.inject($(field));
		
	});
};


var addItems2 = function(categories, field){		
	categories.each(function(thecategory) {			

		var o = new Element('option', {
                        'value':thecategory.category_id,
                        'html':thecategory.category_name
                    });

		o.inject($(field));
		
	});
};

window.addEvent('domready', function() {
	if ($('groupcategory') != null){
		var list3 = $('groupcategory');
		list3.addEvent('change', function(){
			//alert(list.value);
			new Request.JSON({url: "index.php?export=categories&lang="+lang+"&groupcategory_id="+list3.value, onComplete: function(category){
				
				$('category').getChildren().each(function(item){
					if (item.get('value') != ''){
						item.dispose();
					}
				});
				
			    addItems2(category.category, 'category');
			}}).send();
		});
	}
	if ($('country') != null){
		var list = $('country');
		list.addEvent('change', function(){
			//alert(list.value);
			new Request.JSON({url: "index.php?export=oceans&lang="+lang+"&country_id="+list.value, onComplete: function(oceans){
				
				$('ocean').getChildren().each(function(item){
					if (item.get('value') != ''){
						item.dispose();
					}
				});
				
			    addItems(oceans.ocean, 'ocean');
			}}).send();
		});
		
		new Request.JSON({url: "index.php?export=oceans&lang="+lang+"&country_id="+list.value, onComplete: function(oceans){
				
			$('ocean').getChildren().each(function(item){
				if (item.get('value') != ''){
					item.dispose();
				}
			});
			
		    addItems(oceans.ocean, 'ocean');
		}}).send();
	}
	
	
	if ($('country_advanced') != null){
		var list2 = $('country_advanced');
		list2.addEvent('change', function(){
			//alert(list.value);
			new Request.JSON({url: "index.php?export=oceans&lang="+lang+"&country_id="+list2.value, onComplete: function(oceans){
				
				$('ocean_advanced').getChildren().each(function(item){
					if (item.get('value') != ''){
						item.dispose();
					}
				});
				
			    addItems(oceans.ocean, 'ocean_advanced');
			}}).send();
		});
		
		new Request.JSON({url: "index.php?export=oceans&lang="+lang+"&country_id="+list2.value, onComplete: function(oceans){
				
			$('ocean_advanced').getChildren().each(function(item){
				if (item.get('value') != ''){
					item.dispose();
				}
			});
			
		    addItems(oceans.ocean, 'ocean_advanced');
		}}).send();
	}

});

