var countries=new Array();
var country_index = 0;
var language;
var allreadyCountry;
var allreadyRegion;

var country_selection = {
		en : 'Select...',
		el : 'Επιλέξτε...',
		de : 'L' + String.fromCharCode(228) + 'nderwahl...'
};
var all_selection = {
		en : 'All regions',
		el : 'Όλες οι περιοχές',
		de : 'Alle Regionen'
};

function Region(name,code) {
	this.name=name;
	this.code=code;
}

function addRegion(reg_name,reg_code) {
	this.regions[this.index] = new Region(reg_name,reg_code);
	this.index++;
}

function showRegions(obj) {
	//alert("mpike");
	for(var y=obj.options.length-1; y>=0; y--) {
		obj.options[y] = null;
	}
	
	obj.disabled = false;

	obj.options[0] = new Option(all_selection[language]);
	obj.options[0].value = "ALL";

	for(var i=1; i<=this.index; i++) {
		obj.options[i] = new Option(this.regions[i-1].name+"");
		obj.options[i].value = this.regions[i-1].code;
		
		if(allreadyRegion!=null) {
			if(allreadyRegion == this.regions[i-1].code) { // if allready exist coutry definition in session...
				obj.options[i].selected = true;
			}
		}
	}
}


function Country(code,name) {
	this.name = name;
	this.code = code;
	this.regions = new Array();
	this.index = 0;

	this.addRegion = addRegion;
	this.showRegions = showRegions;
}

function changeData(obj1,obj2) {
	if(obj1.selectedIndex == 0) {
		obj2.options[0].selected = true;
		obj2.disabled = true;
		return;
	}
	countries[obj1.selectedIndex-1].showRegions(obj2);
}

function showCountries(obj) {
	for(var y=0; y<obj.options.length; y++) {
		obj.options[y] = null;
	}

	obj.options[0] = new Option(country_selection[language]);
	obj.options[0].value = "ALL";

	for(var i=1; i<=country_index; i++) {
		obj.options[i] = new Option(countries[i-1].name+"");
		obj.options[i].value = countries[i-1].code;
		
		if(allreadyCountry == countries[i-1].code) { // if allready exist coutry definition in session...
			//alert(countries[i-1].code);
			obj.options[i].selected = true;
			changeData(obj,window.document.forma1.region);
		}
		
	}
}


function addCountry(c) {
	countries[country_index] = c;
	country_index++;
}