scheda = Class.create();
	scheda.prototype = 
	{
		initialize: function()
		{
		oThis = this;
		this.provincia = $('idPro')
		this.comune = $('idCom');
		this.provincia.onchange = this.populate.bindAsEventListener(this);
	},
	
	populate: function(idcom)
	{
		var sel = new Array();
		var idcom = idcom;
		options = $A(this.provincia.options);
		options.each(function(opt){
			if (opt.selected)
			{
				sel.push(opt.value);
			}	
		})
		this.provincia.options[0] = null;
		function populateComune(r)
		{
			var json_data = r.responseText;
			
			try
			{
				eval("var jsonObject = ("+json_data+")");
				while(this.comune.hasChildNodes() == true)
				{
					this.comune.removeChild( this.comune.childNodes[0] );
				}
				
				for (var i=0; i < jsonObject.length; i++)
				{
					var childObj = jsonObject[i];
					var opt = document.createElement("option");
					opt.innerHTML = childObj.comune;
					opt.value = childObj.value;
					if (idcom>0)
						if (idcom ==  childObj.value) opt.selected = true;
					this.comune.appendChild(opt);
				}
				
			}
			catch(e)
			{
				alert("Errore sul Server:"+e);
			}
		}
		
		var ajax = new Ajax.Request( '../json.php', {
			onSuccess: populateComune.bind(this),
			method: 'get', 
			parameters: 'pgkey=getComune&pgvalue='+escape(sel.join("','"))
		});
	}
}
