function vaiajax(scriptUrl)  { 

	var AJAX = null; 
		if (window.XMLHttpRequest) {
			AJAX = new XMLHttpRequest();
		} else {
			if (window.ActiveXObject) {
				 AJAX = new ActiveXObject('MSXML2.XMLHTTP.3.0');
			}
		}
	        AJAX.onreadystatechange = function() { 
				if (AJAX.readyState == 4 && AJAX.status == 200) { 
					eval(AJAX.responseText);
				} 
			} 
	AJAX.open("GET", scriptUrl, true); 
	AJAX.send(null); 
}  
function ce(elemento) {
	return document.createElement(elemento);
}


function cambia_ordine(id,nuovoordine,tabella,chiave,valore,chiave1,valore1,chiave2,valore2,chiave3,valore3,chiave4,valore4) {
	var stringa='';
	if (chiave!=undefined) stringa="Chiave="+chiave+"&Valore="+valore;
	if (chiave1!=undefined) stringa+="&Chiave1="+chiave1+"&Valore1="+valore1;
	if (chiave2!=undefined) stringa+="&Chiave2="+chiave2+"&Valore2="+valore2;
	if (chiave3!=undefined) stringa+="&Chiave3="+chiave3+"&Valore1="+valore3;
	if (chiave4!=undefined) stringa+="&Chiave4="+chiave4+"&Valore4="+valore4;
	
	document.location="azioni-cambiaordine.php?Tabella="+tabella+"&Id="+id+"&Nuovoordine="+nuovoordine+"&"+stringa;
}
function ascolta_musica(id) {
	vaiajax("ajax-musica.php?Id="+id);
	var fo = new FlashObject("musica.swf?Medula="+Math.random(), "MEDULA", "300", "200", "8", "#E5E5E5");
	fo.addVariable("flashVarText", "w3c");
	fo.addParam("scale", "noscale");
	fo.addParam("menu", "false");
	fo.addParam("wmode", "transparent");
	fo.write("musica"); 

}

function apri_popup() {
	document.getElementById('blocca_sito').className='sfondo_aperto';
}

function chiudi_popup() {
	document.getElementById('blocca_sito').className='sfondo_chiuso';
}

function apri_chiudi(cosa) {
	if (document.getElementById(cosa).style.display=='none') {
		document.getElementById(cosa).style.display='block'
	} else {
		document.getElementById(cosa).style.display='none'
	}
}

function gid(elemento) {
	return document.getElementById(elemento);
}

function coordinate (element) {
	var coords = {x: 0, y: 0}; 
		while (element) { 
			coords.x += element.offsetLeft; 
			coords.y += element.offsetTop; 
			element = element.offsetParent; 
		} 
	return coords; 
} 

function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}



function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

function flash(qualeid,qualeswf,lunghezza,altezza,array_chiavi,array_valori) {
		var foxv = new FlashObject("/swf/"+qualeswf+".swf", "MEDULAX", lunghezza, altezza, "8", "#EDEDED");
		for (cont_i=0;cont_i<array_chiavi.length;cont_i++) {
				foxv.addVariable(array_chiavi[cont_i], array_valori[cont_i]);
		}
	
		foxv.addVariable("flashVarText", "w3c");
		foxv.addParam("scale", "noscale");
		foxv.addParam("menu", "false");
		foxv.addParam("wmode", "transparent");
		foxv.write(qualeid); 
}

function scegli_provincia() {
	gid('Id_comune').length=0
	id=gid('Id_provincia').value;
	rnd=Math.random();
	vaiajax('ajax-comuni-select.php?Id='+id+'&Medula='+rnd);
}
function scegli_comune(id,id_prov) {
	rnd=Math.random();
	vaiajax('ajax-comuni-select.php?Id='+id+'&Id_prov='+id_prov+'&Medula='+rnd);
}
function scegli_nazione() {
	if (gid('Nazione').value=="Italia") {
		gid('Div_indirizzo_completo').style.display='none';
		gid('Div_Comune').style.display='block';
		gid('Div_Provincia').style.display='block';
		gid('Div_Indirizzo').style.display='block';
		gid('Div_CAP').style.display='block';
	} else {
		gid('Div_Comune').style.display='none';
		gid('Div_Provincia').style.display='none';
		gid('Div_Indirizzo').style.display='none';
		gid('Div_CAP').style.display='none';
		gid('Div_indirizzo_completo').style.display='block';
	}
}
function scegli_comune_start(id,id_prov) {
	rnd=Math.random();
	vaiajax('ajax-comuni-select-start.php?Id='+id+'&Id_prov='+id_prov+'&Medula='+rnd);
}
function checkpopup()
{
   setTimeout(function() { window.scrollTo(0, 1)}, 100);
   var popupCookie = readCookie('popup');
    if (popupCookie == null) {
        alert("Premi il pulsante '+' in fondo allo schermo e scegli 'Aggiungi a Home' per creare un'icona sul desktop del tuo iPhone e accedere piu velocemente al sito mobile di Talia Salute e Benessere");
        createCookie('popuptalia', 1, 3650);
    }
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}