function apri(section) 
{
	location.href="#top"
	if (controllo(section)) 
	{
		chiuditabella(section);
	}	
	else
	{
		apritabella(section);	
	}
}

function apritabella(section)
{
	var tbody = document.getElementById(section);
	if (tbody == null) return;
	tbody.style.display = "";

}

function chiuditabella(section)
{
	var tbody = document.getElementById(section);
	if (tbody == null) return;
	tbody.style.display = "none";
}

function controllo(section)
{
	var tbody = document.getElementById(section);
	if (tbody == null) return 0;
	return (tbody.style.display == "");
}



function cerca() {

var browser_str = window.navigator.userAgent.toUpperCase();
var browser = (browser_str.indexOf("MSIE")!=-1)


	if (browser==true) {
		comune=document.ricerca.comune.value;
	}
	else{
		comune=document.forms[1].comune.value
	}
	categoria=document.ricerca.categoria.value;
	provincia=document.ricerca.provincia.value;
	
	if ((categoria!="") && (provincia=="")){
		alert("Selezionare una Provincia!")
	}
	
	if ((categoria!="") && (provincia!="") && (comune=="")){
		location.href="bk-ric-"+categoria+"-provincia-"+provincia+".html"
	}	
	if ((categoria!="") && (provincia!="") && (comune!="")){
		location.href="bk-ric-"+categoria+"-"+comune+".html"
	}
	if ((categoria=="") && (provincia!="") && (comune=="")){
		location.href="bk-ric-provincia-"+provincia+".html"
	}	
	if ((categoria=="") && (provincia!="") && (comune!="")){
		location.href="bk-ric-"+comune+".html"
	}
	
}

/* parte dedicata al codice AJAX PER UN CARICAMENTO NORMALE*/

function Richiesta(pagina,responsediv){

	if (document.getElementById(responsediv).innerHTML!=''){
		document.getElementById(responsediv).innerHTML = '';
	}
	else {

 
		 url  = pagina +"&rand="+escape(Math.random())
		 var xmlHttpReq = false;
	    var self = this;
	    // Xhr per Mozilla/Safari/Ie7
	    if (window.XMLHttpRequest) {
	        self.xmlHttpReq = new XMLHttpRequest();
	    }
	    // per tutte le altre versioni di IE
	    else if (window.ActiveXObject) {
	        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    self.xmlHttpReq.onreadystatechange = function() {
	        if (self.xmlHttpReq.readyState == 4) {
				// Quando pronta, visualizzo la risposta del form
	            updatepage1(self.xmlHttpReq.responseText,responsediv);
	        }
			else{
				// In attesa della risposta del form visualizzo il msg di attesa
				updatepage1('<img src="../images/preload4.gif">',responsediv);
	
			}
	    }
	     self.xmlHttpReq.open('GET', url, true);
	    self.xmlHttpReq.send(null);
	    
	}
}


function updatepage1(str,responsediv){
    document.getElementById(responsediv).innerHTML = str;
}
/* FINE parte dedicata al codice AJAX PER UN CARICAMENTO NORMALE*/





/* parte dedicata al codice AJAX PER UN CARICAMENTO CON INVIO FORM*/

function xmlhttpPost(strURL,formname,responsediv,responsemsg) {




	    
		if (document.registra.nome.value.length < 2) {
			alert ("ATTENZIONE: inserire un Nome!");
			document.registra.nome.focus();
			return false;
		}


		if (document.registra.telefono.value.length < 5) {
			alert ("ATTENZIONE: inserire un numero di telefono valido!");
			document.registra.telefono.focus();
			return false;
		}

		
		if (document.registra.email.value.length < 3) {
			alert ("ATTENZIONE: inserire un E-Mail valida!");
			document.registra.email.focus();
			return false;
		}
		
		var okay = true;
		var atsign = document.registra.email.value;
		if (((atsign.indexOf('@') == -1) && (okay == true)) || ((okay == true) && (atsign == '')) || ((atsign.indexOf('.') == -1) && (okay == true)) ){
			alert ("ATTENZIONE: Specificare una E-mail valida!");
			okay = false;
			document.registra.email.focus();
			return false;
		}
		
		if (document.registra.messaggio.value.length < 10) {
			alert ("ATTENZIONE: Scrivere un messaggio da inviare alla struttura!");
			document.registra.messaggio.focus();
			return false;
		}		

		if (document.registra.privacy.checked!=true) {
			alert ("Per proseguire devi accettare l'informativa sulla Privacy");
			return false;
		}
				
	    

	    



	    var xmlHttpReq = false;
	    var self = this;
	    // Xhr per Mozilla/Safari/Ie7
	    if (window.XMLHttpRequest) {
	        self.xmlHttpReq = new XMLHttpRequest();
	    }
	    // per tutte le altre versioni di IE
	    else if (window.ActiveXObject) {
	        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    self.xmlHttpReq.open('POST', strURL, true);
	    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    self.xmlHttpReq.onreadystatechange = function() {
	        if (self.xmlHttpReq.readyState == 4) {
				// Quando pronta, visualizzo la risposta del form
	            updatepage(self.xmlHttpReq.responseText,responsediv);
	        }
			else{
				// In attesa della risposta del form visualizzo il msg di attesa
				updatepage(responsemsg,responsediv);
	
			}
	    }
	    
	    	self.xmlHttpReq.send(getquerystring(formname));
	    
	    

}


function getquerystring(formname) {
    var form = document.forms[formname];
	var qstr = "";

    function GetElemValue(name, value) {
        qstr += (qstr.length > 0 ? "&" : "")
            + escape(name).replace(/\+/g, "%2B") + "="
            + escape(value ? value : "").replace(/\+/g, "%2B");
			//+ escape(value ? value : "").replace(/\n/g, "%0D");
    }
	
	var elemArray = form.elements;
    for (var i = 0; i < elemArray.length; i++) {
        var element = elemArray[i];
        var elemType = element.type.toUpperCase();
        var elemName = element.name;
        if (elemName) {
            if (elemType == "TEXT"
                    || elemType == "TEXTAREA"
                    || elemType == "PASSWORD"
					|| elemType == "BUTTON"
					|| elemType == "RESET"
					|| elemType == "SUBMIT"
					|| elemType == "FILE"
					|| elemType == "IMAGE"
                    || elemType == "HIDDEN")
                GetElemValue(elemName, element.value);
            else if (elemType == "CHECKBOX" && element.checked)
                GetElemValue(elemName, 
                    element.value ? element.value : "On");
            else if (elemType == "RADIO" && element.checked)
                GetElemValue(elemName, element.value);
            else if (elemType.indexOf("SELECT") != -1)
                for (var j = 0; j < element.options.length; j++) {
                    var option = element.options[j];
                    if (option.selected)
                        GetElemValue(elemName,
                            option.value ? option.value : option.text);
                }
        }
    }
    return qstr;
}




function updatepage(str,responsediv){
    document.getElementById(responsediv).innerHTML = str;
}

/* FINE parte dedicata al codice AJAX PER UN CARICAMENTO CON INVIO FORM*/
