// JavaScript Document
var criteria_sc = document.getElementById("criteria_sc");
var country_sc = document.getElementById("country_sc");
var country_sc2 = document.getElementById("country_sc2");
var show_btn = document.getElementById("show_btn");

/*var areNotGreen = new Array(country_sc.options[0], country_sc.options[1], country_sc.options[3], country_sc.options[4], 
						 country_sc.options[5], country_sc.options[8], country_sc.options[9], country_sc.options[10], 
						 country_sc.options[11], country_sc.options[12], country_sc.options[13], country_sc.options[14], 
						 country_sc.options[15], country_sc.options[16], country_sc.options[17], country_sc.options[18], 
						 country_sc.options[21], country_sc.options[22], country_sc.options[23], country_sc.options[24], 
						 country_sc.options[25], country_sc.options[26], country_sc.options[31], country_sc.options[32], 
						 country_sc.options[33], country_sc.options[34], country_sc.options[35], country_sc.options[38],
						 country_sc.options[39], country_sc.options[40], country_sc.options[41], country_sc.options[42],
						 country_sc.options[46]);
var areGreen = new Array(country_sc.options[0], country_sc.options[2], country_sc.options[6], country_sc.options[7], 
						 country_sc.options[19], country_sc.options[20], country_sc.options[27], country_sc.options[28], 
						 country_sc.options[29], country_sc.options[30], country_sc.options[36], country_sc.options[37], 
						 country_sc.options[43], country_sc.options[44], country_sc.options[45]);
*/
var areNotGreen = new Array();
var areGreen = new Array();
var myOptions = country_sc.getElementsByTagName("option");
var myOptions2 = country_sc2.getElementsByTagName("option");
/*for(i=0; i<myOptions.length; i++){
	if(/areNotGreen/.test(myOptions[i].className)) {
		//alert(myOptions[i].value);
		areNotGreen.push(myOptions[i]);
	}
	else {
		if(myOptions[i].value != "0") {
			areGreen.push(myOptions[i]);
		}
	}
}*/
for(i=0; i<myOptions.length; i++){
	areGreen.push(myOptions[i]);
}
for(j=0; j<myOptions2.length; j++){
	areNotGreen.push(myOptions[j]);
}
/*for(i=0; i<areGreen.length; i++){
	alert(areGreen[i].value);
}*/
//Starting conditions
country_sc.style.display = "none";
criteria_sc.options[0].selected = true;
/*for(i=0; i<areNotGreen.length; i++){
	country_sc.options[i] = areNotGreen[i];
}*/

var alldivs = document.getElementsByTagName("div");
for(i=0; i<alldivs.length; i++){
	if(/section/.test(alldivs[i].className)) {
		alldivs[i].className += " hidden";
	}
}
var current;


function show(continent_mc, country_mc, isGreen) {
	//var Continent = document.getElementById(continent_mc);
	var Country = document.getElementById(country_mc + "_info");
	
	if(isGreen) {
		//criteria_sc.options[1].selected = true;
		//country_sc.style.display = "none";
		//country_sc2.style.display = "inline";
		/*for(i=0; i<areGreen.length; i++){
			//areGreen[i].style.display = "block";
			if(areGreen[i].value == country_mc) {
				areGreen[i].selected = true;
			}
			else {
				areGreen[i].selected = false;
			}
		}
		for(j=0; j<areNotGreen.length; j++){
			areNotGreen[j].style.display = "none";
		}*/
		//country_sc.options = areGreen;
	}
	else {
		//criteria_sc.options[0].selected = true;
		//country_sc.style.display = "inline";
		//country_sc2.style.display = "none";
		/*for(i=0; i<areNotGreen.length; i++){
			areNotGreen[i].style.display = "block";
			if(areNotGreen[i].value == country_mc) {
				areNotGreen[i].selected = true;
			}
			else {
				areNotGreen[i].selected = false;
			}
		}
		for(j=0; j<areGreen.length; j++){
			areGreen[j].style.display = "none";
		}*/
	}
	if(current) {
		current.className += " hidden";
	}
	current = Country;
	current.className = "section";
	
	/*if(/hidden/.test(Continent.className)) {
		if(selectedContinent != null) {
			selectedContinent.className += " hidden";
		}
		Continent.className = Continent.className.replace("hidden","");
		selectedContinent = Continent;
	}
	
	if(/hidden/.test(Country.className)) {
		if(selectedCountry != null) {
			selectedCountry.className += " hidden";
		}
		Country.className = Country.className.replace("hidden","");
		selectedCountry = Country;
		selectedCountry.scrollIntoView();
	}*/
}

function changeGroup() {
	if(criteria_sc.options[0].selected == true) {
		//alert(areGreen.length);
		country_sc.style.display = "none";
		country_sc2.style.display = "inline";
		/*for(i=0; i<areGreen.length; i++){
			areGreen[i].style.display = "block";
		}
		for(j=0; j<areNotGreen.length; j++){
			areNotGreen[j].style.display = "none";
		}*/
	}
	else {
		country_sc.style.display = "inline";
		country_sc2.style.display = "none";
		//alert(areNotGreen.length);
		/*for(k=0; k<areNotGreen.length; k++){
			areNotGreen[k].style.display = "block";
		}
		for(l=0; l<areGreen.length; l++){
			areGreen[l].style.display = "none";
		}*/
	}
	//country_sc.options[0].selected = true;
}
function showCountry() {
	var isGreen = false;
	if(criteria_sc.options[1].selected == true) {
		isGreen = true;
	}
	if(criteria_sc.options[0].selected == true) {
		var country_mc = country_sc2.options[country_sc2.selectedIndex].value;
	}
	else {
		var country_mc = country_sc.options[country_sc.selectedIndex].value;
	}
	//alert(isGreen);
	//alert(country_mc);
	show(null, country_mc, isGreen);
}

/*window.onload = function () {
	attachActions();
}*/
