function getComuni(oSelect,provincia){
    var ajax = getMEAjaxObj();
    
    function callback(response){
        fillComuniSelect(oSelect,response);
    }
    
    ajax.Request('POST',"/getElenchiGeografia.php?action=get_comuni&provincia="+provincia,callback);
}

function fillComuniSelect(oSelect,response){
    doc = response.responseXML;
    var comuni = doc.getElementsByTagName('item');
    var nome = doc.getElementsByTagName('comune');
    var codice_istat = doc.getElementsByTagName('codice_istat');
    oSelect.innerHTML = "";
    var option = document.createElement("option");
    option.setAttribute("value","");
    option.innerHTML = "seleziona";
    oSelect.appendChild(option);
    for (var i=0;i<comuni.length;i++){
        var comune = comuni[i];
        var option = document.createElement("option");
        cod = codice_istat[i].childNodes[0].nodeValue
        nom = nome[i].childNodes[0].nodeValue
        option.setAttribute("value",cod);
        option.innerHTML = nom;
        oSelect.appendChild(option);
    }
}


function askConfirmation(question) {
	var answer = confirm(question)
	if (answer){
		return true;
	}
	return false;
}

function hideAndChangeTxt(divId,oBtn){
	var oDiv = document.getElementById(divId);
	if (oDiv.style.display=="none" || oDiv.style.display==""){
		oDiv.style.display = 'block';
		oBtn.innerHTML = " - Nascondi";
	}else{
		oDiv.style.display = 'none';
		oBtn.innerHTML = " + Mostra";
	}
}

function pageBack(oForm){
	oForm.page.value = parseInt(oForm.page.value) - 1;
	oForm.azione.value = "cerca";
	oForm.submit();
}
function pageFwd(oForm){
	oForm.page.value = parseInt(oForm.page.value) + 1;
	oForm.azione.value = "cerca";
	oForm.submit();
}

function sortBy(oForm,field){
	var oSortField = oForm.sortField;
	var oSortDir = oForm.sortDir;
	var lastSortField = oSortField.value;
	var lastSortDir = oSortDir.value;
	if (lastSortField == field){
		 if (oSortDir.value == "DESC"){
			 oSortDir.value = "ASC";
		 }else{
			 oSortDir.value = "DESC";
		 }
	}else{
		 oSortField.value = field;
		 oSortDir.value = "DESC";
	}
	oForm.submit();
}

function clearSelect(sSelectId,nullText){
	iSelect = document.getElementById(sSelectId);
    if (iSelect){
		iSelect.innerHTML='';
		if (typeof nullText != "undefined" && nullText!=""){
			option = document.createElement('option');
			option.setAttribute('selected','selected');
			option.value = '';
			option.text = nullText;
		
			try {
				select.add(option, null); // standards compliant; doesn't work in IE
			}	
			catch(ex) {
			  select.add(option); // IE only
			}
		}
    }
}

function fillSelect(sSelectId,aOptions,nullText){
    iSelect = document.getElementById(sSelectId);
	if (iSelect){
		for (var i=0;i<aOptions.length;i++){
			var option = document.createElement('option');
			option.value = aOptions[i]["value"];
			option.text = aOptions[i]["text"];
			try {
			    iSelect.add(option, null); // standards compliant; doesn't work in IE
			}	
			catch(ex) {
				iSelect.add(option); // IE only
			}
		}
	}
}
