var page = document.getElementsByClassName("menu");

function clickAction() {
	for (var i = 0; i < page.length; i++) {
		page[i].addEventListener("click", insert);
	}
}

function insert(e) {
	var pageName = e.target.id;
	Object.values(page).forEach(e => e.className = "menu");
	e.target.className = "menu menu_clic";
	/*next lines changes the script that load different
	contents for different pages*/
	//first remove the old one
	var script = document.getElementById("pageScript");
	script.parentElement.removeChild(script);
	//then create the new one
	var scriptAdd = document.createElement('script');
	scriptAdd.type = 'text/javascript';
	scriptAdd.id = "pageScript";
	scriptAdd.defer = true;
	scriptAdd.src = 'javascript/' + pageName + '.js';
	document.head.appendChild(scriptAdd);
}

clickAction();
