var loading = '';

function popup(id) {
	var win_opt = "toolbar=0,location=0,menubar=0,scrollbars=1,resizable=1,width=570,height=500";
	newWindow = window.open('', '_not' + id, win_opt);
	if (newWindow != null) {
		if (newWindow.opener == null) newWindow.opener = self;
		if (newWindow.focus) newWindow.focus();
	}
}

// Create the XML HTTP request object.
function createXmlHttpReq() {
	var xmlhttp = null;
	try {
		xmlhttp = new XMLHttpRequest();
		try {
			// Fix for some version of Mozilla browser.
				xmlhttp.overrideMimeType('text/xml');
		} catch(e) {}
	} catch(e) {
		try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlhttp;
}

function receiveData() {
	if (xReq.readyState == 4 && xReq.status == 200 && xReq.responseText != null && loading != '') {
		var div = document.getElementById(loading);
		div.innerHTML = xReq.responseText;
		loading = '';
		scroll(0, findPosY(div) - 20);
	}
}

function apri_pag(pag, id) {
	if (loading != '') return;
	var div = document.getElementById(id);
	div.innerHTML = "<div class='attendere'><img src='/icone/clessidra.gif' align='absmiddle' alt='Attendere prego' border='0'>&nbsp;Caricamento in corso...</div>";
	xReq = createXmlHttpReq();
	if (xReq != null) {
		loading = id;
		xReq.open("GET", "index.php?az=" + id + "&pag=" + pag + "&y=" + Math.random());
		xReq.onreadystatechange = receiveData;
		xReq.send(null);
	}
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curtop += obj.offsetTop
		}
	}
	return curtop;
}

function cambiacitta(citta) {
	var url = window.location.pathname + "?c=" + citta;
	if (document.getElementById('memorizza').checked) {
		url += "&m=1";
	}
	window.location = url;
}

var cc=true, cs=true;

function oncambiacitta(div) {
	var pos = getpos(div); // Si trova in menu.js !!!
	var sel = document.getElementById('selcitta');
	sel.style.left = (pos.x - 120) + 'px';
	sel.style.top = (pos.y - 5) + 'px';
	sel.style.display = "block";
}

function noncambiacitta(tipo) {
	if (tipo == 'div') cc=true; else cs=true;
	setTimeout("if (cc && cs) document.getElementById('selcitta').style.display='none';", 1);
}