function trimma( text )
{
	p = text.indexOf(" ")
	while( p!= -1 )
	{
		t1 = text.substring(0,p)
		t2 = text.substring(p+1)
		text = t1+t2
		p = text.indexOf(" ") 
	}
	p = text.indexOf("'")
	while( p!= -1 )
	{
		t1 = text.substring(0,p)
		t2 = text.substring(p+1)
		text = t1+t2
		p = text.indexOf("'") 
	} 
	return text.toLowerCase()
}

function loadimgstato() {
		
		document.images["regione"].src="./pub/img_regioni/"+trimma(document.myform.s.value)+".gif";
		document.images["grecia"].src="/img/trasparente.gif";
		document.images["regione"].useMap = null;
		document.images["grecia"].useMap = null;
		
}

function loadimgregione(area) {
		//document.images["grecia"].src="/img/trasparente.gif";
		document.images["grecia"].src="./pub/img_regioni/"+trimma(document.myform.r.value)+".gif";
		document.images["grecia"].useMap = null;
		
}

function showzone(myreg) {
	document.images["regione"].src="./img/zone_" + myreg +".gif";
	document.images["regione"].tags
	document.images["regione"].useMap="#zone_" + myreg;
	return;
}


function gotoimage(myreg) {
	document.location.href = "#immagine";
	return;
}

function loadimgzona() {
		img = trimma(document.myform.z.value)+".gif"
		document.images["regione"].src="./pub/img_zone/"+img;
		document.images["regione"].useMap = null;
		return;
}
function detectxmlhttp() 
{
	var objhttpd=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try 	{
		objhttpd = new ActiveXObject("Msxml2.XMLHTTP");
	} 	catch (e) 	{
		try {
				objhttpd = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (E) 				{
				objhttpd=false;
				}
	}
	@end @*/
	if (!objhttpd && typeof XMLHttpRequest!='undefined') {
		try {
				objhttpd = new XMLHttpRequest();
				} catch (e) {
				objhttpd =false;
				}
			}
		if (!objhttpd && window.createRequest) {
			try {
				objhttpd= window.createRequest();
			} catch (e) {
				objhttpd =false;
			}
		}
					
		if (!objhttpd) {
			alert("E' necessario utilizzare un browser AJAX-aware...");
			exit;
		}
		return objhttpd;
}					


function appendOption(objform,objselect,optext,opvalore) {
	if (!document.all)
	{
		newOpt=new Option(optext,opvalore);
		eval("document."+objform+"."+objselect+".appendChild(newOpt)")
	}
	else 
	{
		var newOpt = document.createElement("OPTION");
		newOpt.text=optext;
		newOpt.value=opvalore;
		eval("document."+objform+"."+objselect+".add(newOpt)")
	}
}

function enableSelect(objform,objselect) {
	eval("document."+objform+"."+objselect+".disabled = false");
	eval("document."+objform+"."+objselect+".style.backgroundColor = '#ffffff'");
}

function disableSelect(objform,objselect) {
	eval("document."+objform+"."+objselect+".disabled = true");
	eval("document."+objform+"."+objselect+".style.backgroundColor = '#666666'");
}

function removeOption(objform,objselect) {
	eval("while (document."+objform+"."+objselect+".lastChild){document."+objform+"."+objselect+".removeChild(document."+objform+"."+objselect+".lastChild)}");
	eval("document."+objform+"."+objselect+".length = 0");
}


function changestato(stato) {
	//
	if(inhome) loadimgstato();
	//
xmlhttp = detectxmlhttp();
	enableSelect('myform','r');removeOption('myform','r');
	removeOption('myform','p');disableSelect('myform','p');
	removeOption('myform','z');disableSelect('myform','z');
	removeOption('myform','c');disableSelect('myform','c');
 serviceUrl = "/ajax/regionixml.asp?stato=" + stato;
 xmlhttp.open("GET", serviceUrl,true);
 xmlhttp.onreadystatechange=function() 
 {
  if (xmlhttp.readyState==4) 
  {
		//alert("xmlhttp.status "+xmlhttp.status);
		if (xmlhttp.status == 200) 
		{
			//alert(xmlhttp.responseText);
			res=xmlhttp.responseXML
			returntot = parseInt(res.getElementsByTagName('totale')[0].firstChild.data,10);
			appendOption('myform','r',"--------------------","0");
			for(i=0;i<returntot;i++)
			{
				testo=res.getElementsByTagName('regione')[i].firstChild.data;
				valore=testo;
				appendOption('myform','r',testo,valore);
			}
			if (returntot>0) enableSelect('myform','r');
			return false;
		}
		else {alert('Errore changestato nel recupero dei dati\n' + xmlhttp.status + ' : ' + xmlhttp.statusText);}
		xmlhttp.abort();
  }
 }
 xmlhttp.setRequestHeader('Accept','text/xml');
 xmlhttp.send(null);
}

function changeregione(id_regione) {
  //document.getElementById("loading").style.display="";
	removeOption('myform','p');disableSelect('myform','p');
	removeOption('myform','z');disableSelect('myform','z');
	removeOption('myform','c');disableSelect('myform','c');
	//
	if(inhome) loadimgregione();
	//
 xmlhttp = detectxmlhttp();
 serviceUrl = "/ajax/provinciexml.asp?regione=" + id_regione;
 //showLoading(true);
 xmlhttp.open("GET", serviceUrl,true);
 xmlhttp.onreadystatechange=function() 
 {
  if (xmlhttp.readyState==4) 
  {
		if (xmlhttp.status == 200) 
		{
			//showLoading(false);
			res=xmlhttp.responseXML
			returntot = parseInt(res.getElementsByTagName('totale')[0].firstChild.data,10);
			appendOption('myform','p',"--------------------","0");
			for(i=0;i<returntot;i++)
			{
				testo=res.getElementsByTagName('provincia')[i].firstChild.data;
				valore=res.getElementsByTagName('provincia')[i].firstChild.data;
				appendOption('myform','p',testo,valore);
			}
			if (returntot>0) enableSelect('myform','p');
			return false;
		}
		else {alert('Errore showprovince nel recupero dei dati\n' + xmlhttp.status + ' : ' + xmlhttp.statusText);}
		xmlhttp.abort();
  }
 }
 xmlhttp.setRequestHeader('Accept','text/xml');
 xmlhttp.send(null);
 

 xmlhttp1 = detectxmlhttp();
 serviceUrl = "/ajax/zonexml.asp?regione=" + id_regione;
 xmlhttp1.open("GET", serviceUrl,true);
 xmlhttp1.onreadystatechange=function() 
 {
  if (xmlhttp1.readyState==4) 
  {
		if (xmlhttp1.status == 200) 
		{
			res=xmlhttp1.responseXML;
			returntot = parseInt(res.getElementsByTagName('totale')[0].firstChild.data,10);
			appendOption('myform','z',"--------------------","0");
			for(i=0;i<returntot;i++)
			{
				testo=res.getElementsByTagName('zona')[i].firstChild.data;
				valore=res.getElementsByTagName('zona')[i].firstChild.data;
				appendOption('myform','z',testo,valore);	
			}
			if (returntot>0) enableSelect('myform','z');
			return false;
		}
		else {alert('Errore showzone nel recupero dei dati\n' + xmlhttp.status + ' : ' + xmlhttp.statusText);}
		xmlhttp1.abort();
  }
 }
 xmlhttp1.setRequestHeader('Accept','text/xml');
 xmlhttp1.send(null);
  //document.getElementById("loading").style.display="none";
}

function changeprovincia(provincia) {
	if(inhome) document.images["grecia"].src="./pub/img_regioni/"+trimma(document.myform.r.value)+".gif";
	document.myform.z.selectedIndex = 0
	disableSelect('myform','c');removeOption('myform','c');
 xmlhttp = detectxmlhttp();
 serviceUrl = "/ajax/comunixml.asp?provincia=" + provincia;
 xmlhttp.open("GET", serviceUrl,true);
 xmlhttp.onreadystatechange=function() 
 {
  if (xmlhttp.readyState==4) 
  {
		if (xmlhttp.status == 200) 
		{
			res=xmlhttp.responseXML
			returntot = parseInt(res.getElementsByTagName('totale')[0].firstChild.data,10);
			appendOption('myform','c',"--------------------","0");
			for(i=0;i<returntot;i++)
			{
				testo=res.getElementsByTagName('comune')[i].firstChild.data;
				valore=res.getElementsByTagName('comune')[i].firstChild.data;
				appendOption('myform','c',testo,valore);
			}
			if (returntot>0) enableSelect('myform','c');
			return false;
		}
		else {alert('Errore showcomuniprovincia nel recupero dei dati\n' + xmlhttp.status + ' : ' + xmlhttp.statusText);}
		xmlhttp.abort();
  }
 }
 xmlhttp.setRequestHeader('Accept','text/xml');
 xmlhttp.send(null);
}

function changezona(zona) {

	removeOption('myform','c');disableSelect('myform','c');
	if(inhome) loadimgzona();
	document.myform.p.selectedIndex = 0
	enableSelect('myform','c');removeOption('myform','c');
 xmlhttp = detectxmlhttp();
 serviceUrl = "/ajax/comunixml.asp?zona=" + zona;
 xmlhttp.open("GET", serviceUrl,true);
 xmlhttp.onreadystatechange=function() 
 {
  if (xmlhttp.readyState==4) 
  {
		if (xmlhttp.status == 200) 
		{
			res=xmlhttp.responseXML
			returntot = parseInt(res.getElementsByTagName('totale')[0].firstChild.data,10);
			appendOption('myform','c',"--------------------","0");
			for(i=0;i<returntot;i++)
			{
				testo=res.getElementsByTagName('comune')[i].firstChild.data;
				valore=res.getElementsByTagName('comune')[i].firstChild.data;
				appendOption('myform','c',testo,valore);
			}
			if (returntot>0) enableSelect('myform','c');
			return false;
		}
		else {alert('Errore showcomunizona nel recupero dei dati\n' + xmlhttp.status + ' : ' + xmlhttp.statusText);}
		xmlhttp.abort();
  }
 }
 xmlhttp.setRequestHeader('Accept','text/xml');
 xmlhttp.send(null);
 
}

