// JavaScript Document
function sendMailForm()
{
	var mailWin = window.open("https://owa.paginesi.it/owa");
	if (mailWin == null)
	{
		alert ("Non posso aprire la finestra: togliere eventuali blocchi pop-up e riprovare");
	}
}
function goLink(linkSpec)
{
	window.open (linkSpec);
}

flag_query_beagle = 0;
flag_query_elenco = 0;
flag_prov_elenco = 0;
flag_prov_beagle = 0;
flag_prov_guida = 0;

/*img1 = new Image();
img1.src = "img09/vivai.jpg";
img2 = new Image();
img2.src = "img09/borse.jpg";
img3 = new Image();
img3.src = "img09/pesi.jpg";
img4 = new Image();
img4.src = "img09/elenco.jpg";
img5 = new Image();
img5.src = "img09/stufa.jpg";*/

img6 = new Image();
img6.src = "img09/form_homecosaB.gif";
img7 = new Image();
img7.src = "img09/form_homeB.gif";
img8 = new Image();
img8.src = "img09/form_homechiB.gif";
img9 = new Image();
img9.src = "img09/ok-bianco-giallo.gif";
img10 = new Image();
img10.src = "img09/ok-bianco-rosso.gif";
img11 = new Image();
img11.src = "img09/ok-grigio.gif";


image = new Array();
// imageArray
image[0] = "url(img09/vivai.jpg)";
image[1] = "url(img09/borse.jpg)";
image[2] = "url(img09/pesi.jpg)";
image[3] = "url(img09/elenco.jpg)";
image[4] = "url(img09/stufa.jpg)";
n = 5;
increment = Math.floor(Math.random() * n);
v = 20;  // velocità di fading: valore più alto, velocità più bassa
d1 = 0.2;  // ammontare di trasparenza che varia da un passaggio all'altro per firefox
d2 = 20;  // ammontare di trasparenza che varia da un passaggio all'altro per IE

function assegna_sfondo(){
	//alert(increment);
	document.getElementById("thefoto").style.backgroundImage = image[increment];
	/*document.getElementById("thefoto").style.opacity = 0;
	document.getElementById("thefoto").style.filter = "alpha(opacity = 0)";
	fade_in(0, 0);
	var t2 = setTimeout("fade_out(1, 100)", 4630);	*/
	/*var t1 = setTimeout("assegna_sfondo()", 5000);
	++increment;
	if (increment == n){
		increment = 0;	
	}*/
}

function fade_out(k1, k2){
	//alert(k2);
	//rallenta();
	document.getElementById("thefoto").style.opacity = k1;
	document.getElementById("thefoto").style.filter = "alpha(opacity = " + k2 + ")";
	k1 = k1 - d1;
	k2 = k2 - d2;
	if (k2 >= -d2){
		var t3 = setTimeout("fade_out(" + k1 + ", " + k2 + ")", v);	
	}
}

function fade_in(c1, c2){
	//alert(k2);
	//rallenta();
	document.getElementById("thefoto").style.opacity = c1;
	document.getElementById("thefoto").style.filter = "alpha(opacity = " + c2 + ")";
	c1 = c1 + d1;
	c2 = c2 + d2;
	if (c2 <= 100){
		var t4 = setTimeout("fade_in(" + c1 + ", " + c2 + ")", v);	
	}
}

function onfocus_query()
{
	document.forms['form_ricerca'].memok.value = "1";
	document.getElementById('box').style.backgroundImage='url(img09/form_homecosaB.gif)';
	document.getElementById('b1').src='img09/ok-bianco-giallo.gif';
	if (!flag_query_beagle){this.value=''};
}

function onblur_query()
{
	document.getElementById('b1').src ='img09/ok-grigio.gif';
	//document.forms['form_ricerca'].memok.value = '';
	document.getElementById('box').style.backgroundImage='url(img09/form_homeB.gif)';
}

function onfocus_nome()
{
	document.forms['form_ricerca'].memok.value = "2";
	if (!flag_query_elenco){this.value=''};
	document.getElementById('box').style.backgroundImage='url(img09/form_homechiB.gif)';
	document.getElementById('b1').src='img09/ok-bianco-rosso.gif';
	//document.getElementById('b1').title= 'cerca una cosa';
}

function onblur_nome()
{
	document.getElementById('b1').src ='img09/ok-grigio.gif';
	//document.forms['form_ricerca'].memok.value = '';
	document.getElementById('box').style.backgroundImage='url(img09/form_homeB.gif)';
}

function onfocus_provinciacosa()
{
	document.forms['form_ricerca'].memok.value = "1";
	document.getElementById('box').style.backgroundImage='url(img09/form_homecosaB.gif)';
	document.getElementById('b1').src='img09/ok-bianco-giallo.gif';
}

function onblur_provinciacosa()
{
	document.getElementById('b1').src ='img09/ok-grigio.gif';
	//document.forms['form_ricerca'].memok.value = '';
	document.getElementById('box').style.backgroundImage='url(img09/form_homeB.gif)';
}

function onfocus_elenco_comune()
{
	document.forms['form_ricerca'].memok.value = "2";
	if (!flag_prov_elenco){this.value=''};
	document.getElementById('box').style.backgroundImage='url(img09/form_homechiB.gif)';
	document.getElementById('b1').src='img09/ok-bianco-rosso.gif';
}

function onblur_elenco_comune()
{
	document.getElementById('b1').src ='img09/ok-grigio.gif';
	//document.forms['form_ricerca'].memok.value = '';
	document.getElementById('box').style.backgroundImage='url(img09/form_homeB.gif)';
}

/*function query_onkeypress1(e) {
	var key;
	
	if(window.event) // IE
		{
		key = e.keyCode;
		}
	else if(e.which) // Netscape/Firefox/Opera
		{
		key = e.which;
		}
	
	if (key == 13)
	{
		return go_search(2);
	}
}*/
/*function execElenco()
{
	if (document.form2.nome.value.length < 1)
	{
		alert("Inserire nome o numero da ricercare");
		document.form_ricerca.nome.focus();
		return false;
	}
	form_ricerca.submit();
	return false;
}*/

function testalt()
{
	document.write("pulsante ok");
}

function mouseOver()
{
	if (document.forms['form_ricerca'].memok.value == 1){
		// prima cambiare title e poi src altrimenti non funziona
		document.getElementById("b1").title ="avvia ricerca";
		document.getElementById("b1").src ="img09/ok-giallo.gif";
	}
	if (document.forms['form_ricerca'].memok.value == 2){
		document.getElementById("b1").title ="avvia ricerca";
		document.getElementById("b1").src ="img09/ok-rosso.gif";
	}
}

function mouseOut()
{
	if (document.forms['form_ricerca'].memok.value == 1){
		document.getElementById("b1").src ="img09/ok-bianco-giallo.gif";
	}
	if (document.forms['form_ricerca'].memok.value == 2){
		document.getElementById("b1").src ="img09/ok-bianco-rosso.gif";
	}
}

var xmlHttp;
function createXMLHttpRequest(){
	if (window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
}

function startRequest(){
	//alert(document.forms[0].prov.value);
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("GET", "sugg_prov.asp?lettera=" + document.forms["form_ricerca"].provinciacosa.value + "&query=" + document.forms["form_ricerca"].query.value, true);
	xmlHttp.send(null);
	//alert(document.eleform.prov.value);
}

function handleStateChange(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			document.getElementById("result1").innerHTML = xmlHttp.responseText;
		}
	}
}

var xmlHttp1;
function createXMLHttpRequest1(){
	if (window.ActiveXObject){
		xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest){
		xmlHttp1 = new XMLHttpRequest();
	}
}

function startRequest1(){
	//alert(document.forms[0].prov.value);
	createXMLHttpRequest1();
	xmlHttp1.onreadystatechange = handleStateChange1;
	xmlHttp1.open("GET", "sugg_prov_ele.asp?lettera=" + document.forms["form_ricerca"].provinciachi.value + "&nome=" + document.forms["form_ricerca"].ricercabbonato.value, true);
	xmlHttp1.send(null);
	//alert(document.eleform.prov.value);
}

function handleStateChange1(){
	if(xmlHttp1.readyState == 4){
		if(xmlHttp1.status == 200){
			document.getElementById("result2").innerHTML = xmlHttp1.responseText;
		}
	}
}

var xmlHttp2;
function createXMLHttpRequest2(){
	if (window.ActiveXObject){
		xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest){
		xmlHttp2 = new XMLHttpRequest();
	}
}

function startRequest2(){
	//alert(document.forms[0].prov.value);
	createXMLHttpRequest2();
	xmlHttp2.onreadystatechange = handleStateChange2;
	xmlHttp2.open("GET", "sugg_prov_gui.asp?lettera=" + document.forms["form_ricerca"].provinciaguida.value, true);
	xmlHttp2.send(null);
	//alert(document.eleform.prov.value);
}

function handleStateChange2(){
	if(xmlHttp2.readyState == 4){
		if(xmlHttp2.status == 200){
			document.getElementById("result3").innerHTML = xmlHttp2.responseText;
		}
	}
}

function titolo1() {
	document.write("ITALCODE")
}
function titolo2() {
	document.write("MNEMOSYNE")
}
function titolo3() {
	document.write("DISTRIBUZIONE AUTOMATICA")
}
function titolo4() {
	document.write("CASA LIVORNO E PROVINCIA S.P.A.")
}
function testo1() {
	document.write("Sistemi RFID, stampanti, scanner")
}
function testo2() {
	document.write("CENTRO ARTI PESCHERIA")
}
function testo3() {
	document.write("Bevande calde fredde e snack")
}
function testo4() {
	document.write("Costruzione e gestione di alloggi di edilizia residenziale pubblica")
}
function centro1() {
	document.write("centrotende")
}
function link1() {
	document.write("scheda attività")
}
function link2() {
	document.write("Camilla Boemio")
}
function link3() {
	document.write("www.mdavending.it")
}
function link4() {
	document.write("www.casalp.com")
}
function goBanner(linkTo)
{
	var oWin = window.open("http://www.paginesi.it/bglredir.asp?caller=bannerhp&redir=" + linkTo, "", "", false);
	if (oWin == null)
	{
		alert ("Non posso aprire la finestra: togliere eventuali blocchi pop-up e riprovare");
	}
	return false;
}
function go_search(ok)
{
	if (ok == "1"){
		if (document.forms['form_ricerca'].query.value.length < 3)
		{
			alert("Inserire testo (almeno tre caratteri)");
			document.forms['form_ricerca'].query.focus();
			return false;
		}
		document.forms['form_ricerca'].specQuery.value = '';
		//document.forms['form_ricerca'].action = "beagle.asp";
		document.forms['form_ricerca'].action = "beagle.asp";
		document.forms['form_ricerca'].submit();
	}
	
	if (ok == "2"){
		if (document.forms['form_ricerca'].nome.value.length < 1)
		{
			alert("Inserire nome o numero da ricercare");
			document.forms['form_ricerca'].nome.focus();
			return false;
		}
		indiceda = document.forms['form_ricerca'].elenco_comune.value.indexOf("(");
		if (indiceda != -1){
			document.forms['form_ricerca'].elenco_comune.value = document.forms['form_ricerca'].elenco_comune.value.substr(0, indiceda);	
		}
		document.forms['form_ricerca'].action = "elenco.asp";
		document.forms['form_ricerca'].submit();
	}
	if (ok == "3"){
		//alert(document.forms['form_ricerca'].provinciaguida.value);
		/*document.forms['form_ricerca'].action = "beagle.asp";
		document.forms['form_ricerca'].submit();*/
		
		p = document.forms['form_ricerca'].provinciaguida.value;
		p = ftrim(p);
		p = p.toLowerCase();
		var x;
		var vp = new Array();
		var vp_sigla = new Array();
		vp[0] = "agrigento";
		vp[1] = "alessandria";
		vp[2] = "ancona";
		vp[3] = "aosta";
		vp[4] = "arezzo";
		vp[5] = "ascoli piceno";
		vp[6] = "asti";
		vp[7] = "avellino";
		vp[8] = "bari";
		vp[9] = "BAT";
		vp[10] = "belluno";
		vp[11] = "benevento";
		vp[12] = "bergamo";
		vp[13] = "biella";
		vp[14] = "bologna";
		vp[15] = "bolzano";
		vp[16] = "brescia";
		vp[17] = "brindisi";
		vp[18] = "cagliari";
		vp[19] = "caltanissetta";
		vp[20] = "campobasso";
		vp[21] = "carbonia iglesias";
		vp[22] = "caserta";
		vp[23] = "catania";
		vp[24] = "catanzaro";
		vp[25] = "chieti";
		vp[26] = "como";
		vp[27] = "cosenza";
		vp[28] = "cremona";
		vp[29] = "crotone";
		vp[30] = "cuneo";
		vp[31] = "enna";
		vp[32] = "ferrara";
		vp[33] = "firenze";
		vp[34] = "foggia";
		vp[35] = "forlì cesena";
		vp[36] = "frosinone";
		vp[37] = "genova";
		vp[38] = "gorizia";
		vp[39] = "grosseto";
		vp[40] = "imperia";
		vp[41] = "isernia";
		vp[42] = "l'aquila";
		vp[43] = "la spezia";
		vp[44] = "latina";
		vp[45] = "lecce";
		vp[46] = "lecco";
		vp[47] = "livorno";
		vp[48] = "lodi";
		vp[49] = "lucca";
		vp[50] = "macerata";
		vp[51] = "mantova";
		vp[52] = "massa carrara";
		vp[53] = "matera";
		vp[54] = "medio campidano";
		vp[55] = "messina";
		vp[56] = "milano";
		vp[57] = "modena";
		vp[58] = "napoli";
		vp[59] = "novara";
		vp[60] = "nuoro";
		vp[61] = "ogliastra";
		vp[62] = "olbia tempio";
		vp[63] = "oristano";
		vp[64] = "padova";
		vp[65] = "palermo";
		vp[66] = "parma";
		vp[67] = "pavia";
		vp[68] = "perugia";
		vp[69] = "pesaro urbino";
		vp[70] = "pescara";
		vp[71] = "piacenza";
		vp[72] = "pisa";
		vp[73] = "pistoia";
		vp[74] = "pordenone";
		vp[75] = "potenza";
		vp[76] = "prato";
		vp[77] = "ragusa";
		vp[78] = "ravenna";
		vp[79] = "reggio calabria";
		vp[80] = "reggio emilia";
		vp[81] = "rieti";
		vp[82] = "rimini";
		vp[83] = "roma";
		vp[84] = "rovigo";
		vp[85] = "salerno";
		vp[86] = "sassari";
		vp[87] = "savona";
		vp[88] = "siena";
		vp[89] = "siracusa";
		vp[90] = "sondrio";
		vp[91] = "taranto";
		vp[92] = "teramo";
		vp[93] = "terni";
		vp[94] = "torino";
		vp[95] = "trapani";
		vp[96] = "trento";
		vp[97] = "treviso";
		vp[98] = "trieste";
		vp[99] = "udine";
		vp[100] = "varese";
		vp[101] = "venezia";
		vp[102] = "verbania";
		vp[103] = "vercelli";
		vp[104] = "verona";
		vp[105] = "vibo valentia";
		vp[106] = "vicenza";
		vp[107] = "viterbo";
		vp_sigla[0] = "ag";
		vp_sigla[1] = "al";
		vp_sigla[2] = "an";
		vp_sigla[3] = "ao";
		vp_sigla[4] = "ar";
		vp_sigla[5] = "ap";
		vp_sigla[6] = "at";
		vp_sigla[7] = "av";
		vp_sigla[8] = "ba";
		vp_sigla[9] = "bt";
		vp_sigla[10] = "bl";
		vp_sigla[11] = "bn";
		vp_sigla[12] = "bg";
		vp_sigla[13] = "bi";
		vp_sigla[14] = "bo";
		vp_sigla[15] = "bz";
		vp_sigla[16] = "bs";
		vp_sigla[17] = "br";
		vp_sigla[18] = "ca";
		vp_sigla[19] = "cl";
		vp_sigla[20] = "cb";
		vp_sigla[21] = "ci";
		vp_sigla[22] = "ce";
		vp_sigla[23] = "ct";
		vp_sigla[24] = "cz";
		vp_sigla[25] = "ch";
		vp_sigla[26] = "co";
		vp_sigla[27] = "cs";
		vp_sigla[28] = "cr";
		vp_sigla[29] = "kr";
		vp_sigla[30] = "cn";
		vp_sigla[31] = "en";
		vp_sigla[32] = "fe";
		vp_sigla[33] = "fi";
		vp_sigla[34] = "fg";
		vp_sigla[35] = "fc";
		vp_sigla[36] = "fr";
		vp_sigla[37] = "ge";
		vp_sigla[38] = "go";
		vp_sigla[39] = "gr";
		vp_sigla[40] = "im";
		vp_sigla[41] = "is";
		vp_sigla[42] = "aq";
		vp_sigla[43] = "sp";
		vp_sigla[44] = "lt";
		vp_sigla[45] = "le";
		vp_sigla[46] = "lc";
		vp_sigla[47] = "li";
		vp_sigla[48] = "lo";
		vp_sigla[49] = "lu";
		vp_sigla[50] = "mc";
		vp_sigla[51] = "mn";
		vp_sigla[52] = "ms";
		vp_sigla[53] = "mt";
		vp_sigla[54] = "vs";
		vp_sigla[55] = "me";
		vp_sigla[56] = "mi";
		vp_sigla[57] = "mo";
		vp_sigla[58] = "na";
		vp_sigla[59] = "no";
		vp_sigla[60] = "nu";
		vp_sigla[61] = "og";
		vp_sigla[62] = "ot";
		vp_sigla[63] = "or";
		vp_sigla[64] = "pd";
		vp_sigla[65] = "pa";
		vp_sigla[66] = "pr";
		vp_sigla[67] = "pv";
		vp_sigla[68] = "pg";
		vp_sigla[69] = "pu";
		vp_sigla[70] = "pe";
		vp_sigla[71] = "pc";
		vp_sigla[72] = "pi";
		vp_sigla[73] = "pt";
		vp_sigla[74] = "pn";
		vp_sigla[75] = "pz";
		vp_sigla[76] = "po";
		vp_sigla[77] = "rg";
		vp_sigla[78] = "ra";
		vp_sigla[79] = "rc";
		vp_sigla[80] = "re";
		vp_sigla[81] = "ri";
		vp_sigla[82] = "rn";
		vp_sigla[83] = "rm";
		vp_sigla[84] = "ro";
		vp_sigla[85] = "sa";
		vp_sigla[86] = "ss";
		vp_sigla[87] = "sv";
		vp_sigla[88] = "si";
		vp_sigla[89] = "sr";
		vp_sigla[90] = "so";
		vp_sigla[91] = "ta";
		vp_sigla[92] = "te";
		vp_sigla[93] = "tr";
		vp_sigla[94] = "to";
		vp_sigla[95] = "tp";
		vp_sigla[96] = "tn";
		vp_sigla[97] = "tv";
		vp_sigla[98] = "ts";
		vp_sigla[99] = "ud";
		vp_sigla[100] = "va";
		vp_sigla[101] = "ve";
		vp_sigla[102] = "vb";
		vp_sigla[103] = "vc";
		vp_sigla[104] = "vr";
		vp_sigla[105] = "vv";
		vp_sigla[106] = "vi";
		vp_sigla[107] = "vt";
		trovato = 0;
		trovatos = 0;
		indice = -1;
		for (x in vp)
		{
			if (vp[x] == p){
				trovato = 1;	
			}
		}
		for (x in vp_sigla)
		{
			if (vp_sigla[x] == p){
				trovatos = 1;
				indice = x;
			}
		}
		if ((trovato == 0) && (trovatos == 0)){
			document.getElementById("alert").style.visibility = "visible";
		} else{
			if (trovatos == 1){
				p = vp[indice];
			}
			if (p == "l'aquila"){
				p = "laquila";
			}
			if (p == "ascoli piceno"){
				p = "ascoli";
			}
			if (p == "forli' cesena"){
				p = "forlicesena";
			}
			if (p == "forlì cesena"){
				p = "forlicesena";
			}
			if (p == "massa carrara"){
				p = "massa";
			}
			if (p == "pesaro urbino"){
				p = "pesaro";
			}
			p = p.replace(/ /, "");
			indirizzo = "http://www.paginesi.it/" + p + ".htm";
			//alert(document.forms['form_ricerca'].provinciaguida.value);
			window.location = indirizzo;
		}
	}
	return false;
}
function ftrim(p){
	while (p.indexOf(" ") == 0){
		p = p.substr(1);
	}
	while (p.lastIndexOf(" ") == (p.length - 1)){
		p = p.substr(0, p.length -1);
	}
	return p;
}
function query_onkeypress(e, ok) {
	var key;
	
	/*if (document.all)
		e = window.event;*/

	if(window.event) // IE
		{
		key = e.keyCode;
		}
	else if(e.which) // Netscape/Firefox/Opera
		{
		key = e.which;
		}
		//alert(key);
	
		//alert();
		if (key == 13)
		{
			if (ok == "3"){
				//alert(document.forms['form_ricerca'].provinciaguida.value);
				/*document.forms['form_ricerca'].action = "beagle.asp";
				document.forms['form_ricerca'].submit();*/
				p = document.forms['form_ricerca'].provinciaguida.value;
				p = p.toLowerCase();
				if (p == "l'aquila"){
					p = "laquila";
				}
				if (p == "ascoli piceno"){
					p = "ascoli";
				}
				if (p == "forli' cesena"){
					p = "forlicesena";
				}
				if (p == "massa carrara"){
					p = "massa";
				}
				if (p == "pesaro urbino"){
					p = "pesaro";
				}
				p = p.replace(/ /, "");
				indirizzo = "http://www.paginesi.it/" + p + ".htm";
				//alert(document.forms['form_ricerca'].provinciaguida.value);
				window.location = indirizzo;
			}else{
				//alert(key);
				return go_search(ok);
			}
		}
}
function query_onkeypress3(e) {
	var key;
	
	if(window.event) // IE
		{
		key = e.keyCode;
		}
	else if(e.which) // Netscape/Firefox/Opera
		{
		key = e.which;
		}
		//alert(key);
	
		//alert();
		if (key == 13)
		{
			
				return go_search("3");
		}
}
function query_onkeypress2(e) {
	var key;
	
	/*if (document.all)
		e = window.event;*/

	if(window.event) // IE
		{
		key = e.keyCode;
		}
	else if(e.which) // Netscape/Firefox/Opera
		{
		key = e.which;
		}
		//alert(key);
	
		//alert();
		if (key == 13)
		{
			
				return go_search("2");
		}
}
function query_onkeypress1(e) {
	var key;
	
	/*if (document.all)
		e = window.event;*/

	if(window.event) // IE
		{
		key = e.keyCode;
		}
	else if(e.which) // Netscape/Firefox/Opera
		{
		key = e.which;
		}
		//alert(key);
	
		//alert();
		if (key == 13)
		{
			
				return go_search("1");
		}
}
function query_onkeypress_prova(e) {
	var key;
	
	/*if (document.all)
		e = window.event;*/

	if(window.event) // IE
		{
		key = e.keyCode;
		}
	else if(e.which) // Netscape/Firefox/Opera
		{
		key = e.which;
		}
		//alert(key);
	
		//alert();
		if (key == 13)
		{
			
				return go_search(1);
		}
}