var comunidadAbierta=0;
var provinciaAbierta=0;
function abreComunidad(id) {
	if (comunidadAbierta>0) {
		document.getElementById("comunidad-"+comunidadAbierta).style.display="none";
	}
	if (provinciaAbierta>0) {
		document.getElementById("provincia-"+provinciaAbierta).style.display="none";
	}
	document.getElementById("comunidad-"+id).style.display="block";
	comunidadAbierta=id;
}
function abreProvincia(id) {
	if (provinciaAbierta>0) {
		document.getElementById("provincia-"+provinciaAbierta).style.display="none";
	}
	document.getElementById("provincia-"+id).style.display="block";
	provinciaAbierta=id;
}

function tellamamos(tel,lang,facebook,pagina) {

if(isTelefono(tel) || isMovil(tel) || isTelefonoPortugal(tel) || isMovilPortugal(tel)) {
	window.open("/contenido/llamar.php?telefono="+tel+"&facebook="+facebook+"&pagina="+pagina+"&lang="+lang,"llamar_"+Math.floor(Math.random()*9999),"location=0,status=0,scrollbars=0,width=450,height=450");
}
else {
	if(lang=='es') alert('El teléfono que has indicado no parece válido, compruébalo.\nTambién puedes llamarnos al 902 25 25 25 o contactar mediante el formulario.');
	else if(lang=='pt') alert('O telefone que você mencionou não parece ser válido, verifique.\nVocê pode chamar 707 25 25 25 ou contacte-nos através do formulário.');
}

}


function createDynamicDropdown(val,dropdown2,dropDown3) {
 /* dropdown1 = lists all the countries 
    dropdown2 = this drop down is not used by users. Think of it as just a struture that holds ALL the cities for ALL countries from dropdown1. 
    dropdown3 = is a dynamically generated dropdown list which changes based on what is selected in dropdown1. the <option> nodes are copied out from dropdown2 and dynamically rendered in dropdown3.
*/
	dropDown2 = document.getElementById(dropdown2);
	dropDown3 = document.getElementById(dropDown3);
	var allDropDown2Elements = dropDown2.childNodes; // 'childNodes' used so you can also include <optgroup label="xxxxxxx" name="xxx"/> in dropDown2 if required

	// remove all <option>s in dropDown3
	while (dropDown3.hasChildNodes()) {
		dropDown3.removeChild(dropDown3.firstChild);
	}  

	// loop though and insert into dropDown3 all of the city <option>s in dropdown2 that relate to the country value selected in dropdown1
	for(var i = 0; i < allDropDown2Elements.length; i++){
			if (allDropDown2Elements[i].nodeType == 1 && allDropDown2Elements[i].getAttribute("name") == val) {
				newDropDown3Element = allDropDown2Elements[i].cloneNode(true);
				dropDown3.appendChild(newDropDown3Element);
			}    
	}

	// if '-- Country --' is selected insert the 'default' node into dropDown3
	if(val == '') {
		dropDown3.style.visibility='hidden';
		dropDown3.value='';
	}
	else {
		dropDown3.style.visibility='visible';
	}

	// (if you have server side logic that adds selected="selected" in dropdown2) extra code for IE to display the correct 'slected="selected"' value in the select box dropdown3
	if(navigator.userAgent.indexOf('MSIE') !=-1){
		for (var i=0; i < dropDown3.length; i++) {
			if(dropDown3[i].value == dropDown2.value) {
				dropDown3[i].selected = true;
			}
		}
	}
 
}



