var languages = {
	de: 'Deutsch',
	en: 'English',
	es: 'Espa&ntilde;ol',
	fr: 'Fran&ccedil;ais',
	nl: 'Nederlands',
	pt: 'Português',
	sq: 'Shqip',
	sv: 'Svenska',
	zh: '&#20013;&#25991;'
}

function createCookie(name,value,days){
        if (days)
        {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name){
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++)
        {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
}

function selectLanguage() {
	language = document.getElementById('language').value;
	createCookie("edt_language", language, 300);
	var loc = window.location.toString();
	window.location = loc.replace(/_[A-Z]{2}.html/gi, '_' + language + '.html');
}




function init() {
	var loc = window.location.toString();
	var newloc = loc;
	if (loc != newloc.replace(/_[A-Z]{2}.html/gi, '_' + language + '.html')) {
		window.location = loc.replace(/_[A-Z]{2}.html/gi, '_' + language + '.html');
		return;
	}
	if (loc != newloc.replace(/index.html/gi, 'index_' + language + '.html')) {
		window.location = loc.replace(/index.html/gi, 'index_' + language + '.html');
		return;
	}

	var div = document.createElement('div');
	var head = '';

	head += '<select id="language" onchange="selectLanguage()" style="float:right">';
	for (i in languages) {
		head += '<option value="' + i + '"';
		if (i == language) {
			head+= ' selected="true"';
		}
		head += '>' + languages[i] + '</option>';
	}
	head += '</select>';
	div.innerHTML = head;
	document.getElementById("page").insertBefore(div, document.getElementById("page").firstChild);
}

var language = readCookie('edt_language');
if (language == null) {
	language = 'en';
}
window.onload=init;
