   


function initLabels() {
	labels = document.getElementsByTagName("label");
	for(i = 0; i < labels.length; i++) {
		Event.observe(labels[i], 'click', labelFocus, false);
	}
}

function initLinks() {
	lnks=document.getElementsByTagName('a');
	for(i = 0;i < lnks.length;i++) {
		lnks[i].onfocus=new Function("this.blur()");
	}
}

function showTip(title,text) {
	tp = document.getElementById('tooltip');
	tp.innerHTML = "<div class=\"titolo\">"+title+"</div><span class=\"testo\">"+text+"</span>";
}

function getAjax() {
	var result = null;
	if(typeof(XMLHttpRequest) != 'undefined')
		result = new XMLHttpRequest();
	else if(window.ActiveXObject) {
		var t = (navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? 'Microsoft' : 'Msxml2';
		result = new ActiveXObject(t + '.XMLHTTP');
	}
	if(result == null)
		__self.lastError = 'This browser does not support XML request.';
	return result;
}

function _getComuni(prov) {
	var select = document.getElementById("co");
	select.innerHTML = "";
	select.disabled=true;
	select.appendChild(_createOption(0,"Caricando..."));

	var bridge = getAjax();
	bridge.onreadystatechange = function() {
		if(bridge.readyState == 4) {
			select.innerHTML = "";
			select.disabled=false;
			eval(bridge.responseText);
		}
	}
	bridge.open('POST', 'JSONservice.php', true);
	bridge.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	bridge.setRequestHeader('Connection', 'close');

	if (prov) prov = "&prov="+prov;

	bridge.send('call=_getComuni' + prov);
}

function _createOption(val,text) {
	var new_option = document.createElement("option");
	var text = document.createTextNode(text);
	new_option.setAttribute("value",val);
	new_option.appendChild(text);
	return new_option;
}

function _openLoading(str) {
	var res = document.getElementById(str);
	if (res) { res.innerHTML = "<div id=\"loader\"><img src=\"img/loader.gif\" /></div>"; }
}

function _closeLoading(val,divname) {
	var res = document.getElementById(divname);
	if (res) {	res.innerHTML = val; }
}

function _doSearch(opt) {
	_openLoading("results");

	var request = new Object();
	var search = document.forms[0];

	if (opt=="search") {

		document.getElementById('opzione1').className=null;
		document.getElementById('opzione2').className=null;

		request.parola_chiave = search.parola_chiave.value;
	
		box = search.id_provincia;
		request.id_provincia = box.options[box.selectedIndex].value;
	
		box = search.id_comune;
		request.id_comune = box.options[box.selectedIndex].value;
	
		box = search.id_categoria_tematica;
		request.id_categoria_tematica = box.options[box.selectedIndex].value;
	
		box = search.id_regime_apertura;
		request.id_regime_apertura = box.options[box.selectedIndex].value;
	
		box = search.id_titolarita_giuridica;
		request.id_titolarita_giuridica = box.options[box.selectedIndex].value;
	
		box = search.id_tipo_apertura;
		request.id_tipo_apertura = box.options[box.selectedIndex].value;
	
		box = search.modalita_ingresso;
		request.modalita_ingresso = box.options[box.selectedIndex].value;

		box = search.id_servizio;
		request.id_servizio = box.options[box.selectedIndex].value;

	}else { 

		if (opt=="popular") { request.popular = "ok"; }
		else if (opt=="all") { request.all = "ok"; }

	}

	var bridge = getAjax();
	bridge.onreadystatechange = function() {
		if(bridge.readyState == 4) {
			_parseResults(JSON.parse(bridge.responseText));
		}
	}
	bridge.open('POST', 'JSONservice.php', true);
	bridge.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	bridge.setRequestHeader('Connection', 'close');
	bridge.send('call=_getMusei&lang=2&json='+JSON.stringify(request));
}

function _parseResults(records) {

	var html = "";

	if (records.count) {

		for (var i=0; i < records.count; i++) {
	
			html += "<div class=\"row_categoria\">";
			html += "<p class=\"titolo_categoria2\"><img src=\"img/freccia6.gif\" /> <a href=\"scheda_museo.html?id="+records[i].id_museo+"\" class=\"link5\" title=\""+records[i].ente_soggetto+"\">"+records[i].ente_soggetto+"</a></p>";
			html += (records[i].img) ? "<p class=\"img_container2\"><img src=\"foto/service.php?img="+records[i].img+"&mwidth=90\" width=\"90\" height=\"70\" alt=\""+records[i].img_titolo+"\" /></p>" : "";
			html += "<p class=\"text2\">"+records[i].descrizione+"</p>";
			html += "<img src=\"img/freccia7.gif\" /><a href=\"scheda_museo.html?id="+records[i].id_museo+"\" title=\"Vai alla scheda completa\" class=\"link1\">Vai alla scheda completa</a> &nbsp; ";
			html += "<img src=\"img/freccia7.gif\" /><a href=\"come_arrivare.html?id="+records[i].id_museo+"\" title=\"Entra nella mappa\" class=\"link1\">Entra nella mappa</a>";
			html += "<div class=\"puntinato\">&nbsp;</div>";
			html += "</div>";
	
		}

	}else {	html += "<div class=\"puntinato\">&nbsp;</div><h3>Nessun risultato</h3>"; }

	_closeLoading(html, "results");
}

function _callLocation(id) {

	_openLoading("dinamic");

	var request = new Object();
	request.id_museo = id;

	var bridge = getAjax();
	bridge.onreadystatechange = function() {
		if(bridge.readyState == 4) {
			_showLocation(JSON.parse(bridge.responseText));
		}
	}
	bridge.open('POST', 'JSONservice.php', true);
	bridge.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	bridge.setRequestHeader('Connection', 'close');
	bridge.send('call=_getMuseo&lang=2&json='+JSON.stringify(request));

}

function _showLocation(record) {

	pm = document.getElementById('path_museo');
	pm.innerHTML = ' > "' + record.ente_soggetto + '"';

	document.getElementById('static').style.display = 'none';

	var html = "";

	html += "<p class=\"titolo_categoria link5_big\"><img src=\"img/freccia6.gif\" width=\"7\" height=\"7\" /> " + record.ente_soggetto + "</p>";	
	html += "<p class=\"text2\">" + record.descrizione + "</p>";
	html += "<br class=\"clear\" /><div class=\"scheda_box\"><p><span class=\"link6 left\">In auto <img src=\"img/in_auto.gif\" width=\"18\" height=\"18\" /></span></p><div class=\"text2\">" + record.cm_autostrada + "</div><br class=\"clear\" /></div>";
	html += "<div class=\"scheda_box\"><p><span class=\"link6 left\">In treno <img src=\"img/in_treno.gif\" width=\"18\" height=\"18\" /></span></p><div class=\"text2\">" + record.cm_ferrovia + "</div><br class=\"clear\" /></div>";
	html += "<div class=\"scheda_box\"><p><span class=\"link6 left\">In autobus <img src=\"img/in_autobus.gif\" width=\"18\" height=\"18\" /></span></p><div class=\"text2\">" + record.cm_stazione + "</div><br class=\"clear\" /></div>";
	html += "<div class=\"scheda_box\"><p><span class=\"link6 left\">In aereo <img src=\"img/in_aereo.gif\" width=\"18\" height=\"18\" /></span></p><div class=\"text2\">" + record.cm_aereoporto + "</div><br class=\"clear\" /></div>";
	html += "<div class=\"scheda_box\"><p><span class=\"link6 left\">In nave <img src=\"img/in_barca.gif\" width=\"18\" height=\"18\" /></span></p><div class=\"text2\">" + record.cm_porto + "</div><br class=\"clear\" /></div>";
		
	_closeLoading(html,"dinamic");
}

function viewEntity(type) {

	var str = type;
	window.document.mainMovie.SetVariable("monitorObj.findInstance", str);

}

function getInfoMap() {

	var request = "";
	var search = document.forms[0];

		box = search.id_provincia;
		request += "id_provincia="+box.options[box.selectedIndex].value;
	
		box = search.id_comune;
		request += "&id_comune="+box.options[box.selectedIndex].value;
	
		box = search.id_categoria_tematica;
		request += "&id_categoria_tematica="+box.options[box.selectedIndex].value;
	
		box = search.id_regime_apertura;
		request += "&id_regime_apertura="+box.options[box.selectedIndex].value;
	
		box = search.id_titolarita_giuridica;
		request += "&id_titolarita_giuridica="+box.options[box.selectedIndex].value;
	
		box = search.id_tipo_apertura;
		request += "&id_tipo_apertura="+box.options[box.selectedIndex].value;
	
		box = search.modalita_ingresso;
		request += "&modalita_ingresso="+box.options[box.selectedIndex].value;

		box = search.id_servizio;
		request += "&id_servizio="+box.options[box.selectedIndex].value;

	window.document.mainMovie.SetVariable("monitorObj.findRicerca", request);

}
