//<script>

var fieldComuni;

var valueComuni;


function loadComuni(item1, _field){
	
    fieldComuni = _field;
    valueComuni = '';
	http1.onreadystatechange = getComuni;
	http1.open('GET','funzioniaj.php?azione=cm&pv='+item1, true);
	//http1.onreadystatechange = getComuni;//lasciare per compatibilit� con ie
	http1.send(null);
	
}
function loadComuniVal(item1, _field, val){
	//alert(item1);
    fieldComuni = _field;
    valueComuni = val;
	http1.onreadystatechange = getComuni;
	http1.open('GET','funzioniaj.php?azione=cm&pv='+item1, true);
	//http1.onreadystatechange = getComuni;//lasciare per compatibilit� con ie
	http1.send(null);
	
}

function getComuni(){

   // var field = 'usr_';
    field = fieldComuni;
    
    var newOption;
	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
	var City = document.getElementById(field + 'comune');

	while (City.options.length) {
		City.remove(0);
	}

	el = document.getElementById(field + 'provincia');
	id = el.value;


	if(id == ''){
		document.getElementById(fieldComuni+'comune').disabled = true;
		newOption = document.createElement("option");
		newOption.value = '';
		newOption.text = 'Seleziona una Provincia';
		City.add(newOption, where);
	} else {
		if(http1.readyState == 4){
			if (http1.status == 200) {
				var response = http1.responseText;
				if(response == ''){
					document.getElementById(field+'comune').disabled = true;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Nessuna voce';
					City.add(newOption, where);
				}else{
					var coppia = response.split(',');
					var max = coppia.length;
					var val='';
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Seleziona un Comune';
					City.add(newOption, where);
					for(var x=0;x<max;x++){
						val = coppia[x].split('-');
						newOption = document.createElement("option");
						newOption.value = val[0];
						newOption.text = val[1];

						City.add(newOption, where);
					}
					document.getElementById(field+'comune').disabled = false;
					//if(flag){
					//	flag=false;
						//SettaComune('nas');
					//}
					document.getElementById(field+'comune').focus();
					
					if(valueComuni!='') document.getElementById(field+'comune').value = valueComuni;
				}
			}
		}
	}
	City=null;
	newOption=null;
}

//------------------------------------------------------------------------------

var allowCookies = 0;
var useLocalStorage = 1;

if (typeof(Storage) !== "undefined") {
    
    } else {
    useLocalStorage = 0;
}

function cookiesOk() {

	var scadenza = new Date();
	var adesso = new Date();
	scadenza.setTime(adesso.getTime() + (2*86400000));
	//document.cookie =  'cookiesOk =' + adesso.getTime() + '; expires=' + scadenza.toGMTString() + '; path=/';
	
        localStorage.allowCookies = 1+';'+scadenza;  
        
	hidelayer('cookiesbanner');
}

function checkCookiesOk() {
	
	var userCookies = 0;// = leggiCookie('cookiesOk');
        
        var allowC = localStorage.allowCookies;
        
        if(allowC!='') {
            
            userCookies=1; 
            
            if(allowC!='0') allowCookies = 1;
            //gestire la scadenza
            
        }
        
        console.log(allowC);
	
	if(userCookies>0) hidelayer('cookiesbanner');
	
}

function cookiesKO()
{
    localStorage.allowCookies = 0;
    hidelayer('cookiesbanner');
}

function init()
{
    
}
//</script>