function addListener(element, type, expression, bubbling) {
	bubbling = bubbling || false;
	
	if (typeof(element) == 'string')
		element = document.getElementById(element);
			
	if(window.addEventListener)	{ // Standard
		element.addEventListener(type, expression, bubbling);
		return true;
	} 
	else if(window.attachEvent) { // IE
		element.attachEvent('on' + type, expression);
		return true;
	} 
	else 			
		return false;
}

//Alterar isto para uma so funcao
function paraPT() {
	for (var elementName in langPT) {
		var id = document.getElementById(elementName);
		if (id) 
			id.innerHTML = langPT[elementName];		
	}
}

function paraENG() {
	for (var elementName in langENG) {
		var id = document.getElementById(elementName);
		if (id) 
			id.innerHTML = langENG[elementName];		
	}
}
//Desta maneira o utilizador so ve estas bandeiras se o javascript estiver ligado
function createFlags() {
	var langid = document.getElementById('langsEscolher');
	
	var hrefPT = document.createElement('a');
	var hrefENG = document.createElement('a');
	
	hrefPT.setAttribute('href','#');
	hrefPT.setAttribute('id','langEscolhePT');
	
	hrefENG.setAttribute('href','#');
	hrefENG.setAttribute('id','langEscolheENG');
	
	var imgPT = document.createElement('img');
	var imgENG = document.createElement('img');
	
	/*
	<img border="0" src="images/bandeiras/wpt.gif" width="20" height="12" /></a>
    	<a id="" href="#"><img border="0" src="images/bandeiras/small_flag_of_united_kingdom.gif" width="20" height="12" /></a>
        <noscript>
	*/
	imgPT.setAttribute('src','images/bandeiras/wpt.gif');
	imgPT.setAttribute('width','20');
	imgPT.setAttribute('height','12');	
	imgPT.setAttribute('border','0');
	imgPT.setAttribute('alt','PT');
	
	imgENG.setAttribute('src','images/bandeiras/small_flag_of_united_kingdom.gif');
	imgENG.setAttribute('width','20');
	imgENG.setAttribute('height','12');
	imgENG.setAttribute('border','0');
	imgENG.setAttribute('alt','ENG');
	
	hrefPT.appendChild(imgPT);
	
	hrefENG.appendChild(imgENG);
	
	langid.appendChild(hrefPT);
	langid.appendChild(document.createTextNode(' '));
	langid.appendChild(hrefENG);
}

addListener(window,'load',function() {
							createFlags();							   
							addListener('langEscolhePT','click',paraPT);
							addListener('langEscolheENG','click',paraENG);
						});