/*
 * Funzione per la popolazione della combo Comuni
 */
function populateCombo(){
	
	//Creo un nuovo oggetto XMLHTTPRequest
	var req = createRequestObject();
	
	//Invio la richiesta
	req.open("POST", "php/populateCombo.php", true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		
	//Invio i dati POST
	req.send('');

	//Gestore dell'evoluzione dello stato dell'oggetto req
	req.onreadystatechange = handleXMLResponse(req, updateCombo);
} 
/*
 * XMLResult = Il risultato XML prodotto da handleResponse
 */
function updateCombo(XMLResult){
	//Gestisco il documento XML ricevuto e popolo la seconda SELECT
	var cityXML = XMLResult.getElementsByTagName('comune');
	
	//Recupero la seconda SELECT
	var cityCb = document.getElementById("Pos");
	
	//Scorro gli elementi
	for (var i = 0; i < cityXML.length; i++){
		//Recupero i vari elementi singoli
		var item = cityXML[i];
		
		//Creo il nuovo elemento OPTION da aggiungere nella seconda SELECT
		var NewOpt = document.createElement('option');
		NewOpt.value = item.getAttribute("value");
		NewOpt.text = item.firstChild.nodeValue;
		
		//Popolo la seconda SELECT
		try{
			cityCb.add(NewOpt, null); //Metodo Standard, non funziona con IE
		}catch(e){
			cityCb.add(NewOpt); // Funziona solo con IE
		}
	}
	// AGGIUNGO IL COMUNE "ALTRO"
	var NewOpt = document.createElement('option');
	NewOpt.value = "0";
	NewOpt.text = "ALTRO";

	try{
		cityCb.add(NewOpt, null); //Metodo Standard, non funziona con IE
	}catch(e){
		cityCb.add(NewOpt); // Funziona solo con IE
	}
}
<!--TRIM ALL LEADING AND FOLLOWING WHITESPACE IN A STRING-->
function trimString (str) {
	if (str != undefined)
	{
	  return str.replace(/^s+/g, '').replace(/s+$/g, '');
	}
}


function SelectImg(){
			var min = 1;
            var max = 12;
            nrimg = min + Math.round(Math.random()*(max-min));
				nomeimmagine="img/scoprilagioia"+nrimg+".gif";
				document.getElementById('gioiadidonare').style.backgroundImage="url('img/scoprilagioia"+nrimg+".png')";
				document.getElementById('header2').style.backgroundImage="url('img/testata"+nrimg+".jpg')";
				document.getElementById('BloccoSotto').style.backgroundImage="url('img/centralesotto"+nrimg+".jpg')";
		}

function SelectImgMsg(){
			var min = 1;
            var max = 12;
            nrimg = min + Math.round(Math.random()*(max-min));
				nomeimmagine="img/scoprilagioia"+nrimg+".gif";
				document.getElementById('gioiadidonare').style.backgroundImage="url('img/scoprilagioia"+nrimg+".png')";
				document.getElementById('header2').style.backgroundImage="url('img/testata"+nrimg+".jpg')";
				document.getElementById('BloccoSotto').style.backgroundImage="url('img/centralesotto_msg"+nrimg+".jpg')";
		}
		
function SelectImgStf(){
			var min = 1;
            var max = 12;
            nrimg = min + Math.round(Math.random()*(max-min));
				nomeimmagine="img/scoprilagioia"+nrimg+".gif";
				document.getElementById('gioiadidonare').style.backgroundImage="url('img/scoprilagioia"+nrimg+".png')";
				document.getElementById('header2').style.backgroundImage="url('img/testata"+nrimg+".jpg')";
				document.getElementById('BloccoSotto').style.backgroundImage="url('img/centralesotto_stf"+nrimg+".jpg')";
		}
