// JavaScript Document
var cp = new cpaint();
cp.set_transfer_mode('get');
cp.set_response_type('xml');
cp.set_proxy_url('cpaint/cpaint2_proxy.php');
cp.set_debug(false);
cp.set_use_cpaint_api(false);
			
function getProv() 
	{	
	var doc=document.ricerca;
	var strRegione=doc.regione.options[doc.regione.options.selectedIndex].value;				
				
	if(strRegione.length==0)
		return false;
	arrRegione=strRegione.split(";");
	idRegione=arrRegione[0];										
	cp.call("http://www.agriturist.it/localita.php", '', response, 'idRegione=' + idRegione,'idProvincia=0');				
				}
function getComune() 
	{	
	var doc=document.ricerca;
	var idProvincia=doc.provincia.options[doc.provincia.options.selectedIndex].value;				
	if(idProvincia.length==0)
		return false;			
	cp.call("http://www.agriturist.it/localita.php", '', response, 'idProvincia=' + idProvincia);				
	}			
	
function response(result) 
	{
	var doc=document.ricerca;
	var xml=result;							
	var lstProvince=xml.getElementsByTagName("provincia");					
	if(lstProvince.length>0)
		{
		while (doc.provincia.options.length) 			
			doc.provincia.options[0]=null;	
		while (doc.comune.options.length) 			
			doc.comune.options[0]=null;					
		var indice=0;
		doc.provincia.options[indice++] = new Option ('Seleziona la provincia','');	
		doc.comune.options[0] = new Option ('Seleziona il comune','');
		for(var i=0;i<lstProvince.length;i++)
			{
			value=lstProvince[i].attributes[0].value;																						
			txt=lstProvince[i].firstChild.nodeValue;																	
			settaProvincia(txt,value,indice++);							
			}
		}	
	var lstComuni=xml.getElementsByTagName("comune");	
	if(lstComuni.length>0)
		{
		while (doc.comune.options.length) 			
			doc.comune.options[0]=null;				
		var indice=0;
		doc.comune.options[indice++] = new Option ('Seleziona il comune','');	
		for(var i=0;i<lstComuni.length;i++)
			{
			value=lstComuni[i].attributes[0].value;
			txt=lstComuni[i].firstChild.nodeValue;
			settaComune(txt,value,indice++)
			}
		}	
  	}
function settaProvincia(testo,valore,indice)
	{
	var doc=document.ricerca;																					
	doc.provincia.options[indice] = new Option (testo,valore);	
	}
function settaComune(testo,valore,indice)
	{
	var doc=document.ricerca;																					
	doc.comune.options[indice] = new Option (testo,valore);	
	}															
