// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}


// ****** SISTEMA PER POPUP Pagina Dei prezzi ******

//DHTML Window script- Copyright Dynamic Drive (http://www.dynamicdrive.com)
//For full source code, documentation, and terms of usage,
//Visit http://www.dynamicdrive.com/dynamicindex9/dhtmlwindow.htm

var dragapproved=false
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function iecompattest(){
return (document.compatMode!="BackCompat")? document.documentElement : document.body
}

function drag_drop(e){
if (ie5&&dragapproved&&event.button==1){
document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px"
}
else if (ns6&&dragapproved){
document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px"
}
}

function initializedrag(e){
offsetx=ie5? event.clientX : e.clientX
offsety=ie5? event.clientY : e.clientY
document.getElementById("dwindowcontent").style.display="none" //extra
tempx=parseInt(document.getElementById("dwindow").style.left)
tempy=parseInt(document.getElementById("dwindow").style.top)

dragapproved=true
document.getElementById("dwindow").onmousemove=drag_drop
}

function loadwindow(url,width,height){
if (!ie5&&!ns6)
window.open(url,"","width=width,height=height,left="+xMousePos+",top="+yMousePos+",resizable=no,scrollbars=1")
else{
document.getElementById("dwindow").style.display=''
document.getElementById("dwindow").style.width=initialwidth=width+"px"
document.getElementById("dwindow").style.height=initialheight=height+"px"
document.getElementById("dwindow").style.left=initialwidth=xMousePos
document.getElementById("dwindow").style.top=initialheight=yMousePos-340
//document.getElementById("dwindow").style.left="30px"
//document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+30+"px" : iecompattest().scrollTop*1+30+"px"
document.getElementById("cframe").src=url
}
}

function maximize(){
if (minrestore==0){
minrestore=1 //maximize window
document.getElementById("maxname").setAttribute("src","restore.gif")
document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px"
document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : iecompattest().clientHeight+"px"
}
else{
minrestore=0 //restore window
document.getElementById("maxname").setAttribute("src","max.gif")
document.getElementById("dwindow").style.width=initialwidth
document.getElementById("dwindow").style.height=initialheight
}
document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px"
document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px"
}

function closeit(){
document.getElementById("dwindow").style.display="none"
}

function stopdrag(){
dragapproved=false;
document.getElementById("dwindow").onmousemove=null;
document.getElementById("dwindowcontent").style.display="" //extra
}

function verificaEmail(posta){
	var c;
	var ok=0;
	var i;
	for(i=0; i < posta.length; i++){
		c=posta.charAt(i);
		if(c == '@'){
			ok++;
		}
	}
	if (ok > 1){
		return false;
	}
	if(posta.indexOf('@', 0) == -1)
	{
		return false;
	}
	else if(posta.indexOf('@', 0) == 0 || posta.indexOf('@', 0) == posta.length-1)
	{
		return false;
	}
	else if(posta.indexOf('.', 0) == 0 || posta.indexOf('.', 0) == posta.length-1)
	{
		return false;
	}
	else if(posta.indexOf('.', 0) == -1)
	{
		return false;
	}
	return true;
}

function verificaTelefono(tel){
	var ammessi = "0123456789";
	var c;
	var i;
	for(i=0; i<tel.length; i++){
		c=tel.charAt(i);
		if(ammessi.indexOf(c) == -1){
			return false;
		}
	}
	return true;
}

function checkDati(){
	if (document.sondaggio.con_nome.value == ""){
		alert("Prego inserisci il tuo Nome");
		document.sondaggio.con_nome.select();
		return false;
	}
	if (document.sondaggio.con_cognome.value == ""){
		alert("Prego inserisci il tuo Cognome");
		document.sondaggio.con_cognome.select();
		return false;
	}
	if (document.sondaggio.con_citta.value == ""){
		alert("Prego inserisci la Cittā dove abiti");
		document.sondaggio.con_citta.select();
		return false;
	}
	if (document.sondaggio.con_provincia.value == ""){
		alert("Prego inserisci la Provincia dove abiti");
		document.sondaggio.con_provincia.select();
		return false;
	}
	if (document.sondaggio.con_email.value == '') 
	{
		alert ("Prego scrivi il tuo indirizzo Email");
		document.sondaggio.con_email.focus();
		return false;
	}
	if (!verificaEmail(document.sondaggio.con_email.value)){
		alert ("L'indirizzo email non č valido, prego controllare.");
		document.sondaggio.con_email.focus();
		return false;
	}
	if (document.sondaggio.con_emailcheck.value == '') 
	{
		alert ("Prego scrivi ancora l'indirizzo email per verificare l'esattezza");
		document.sondaggio.con_emailcheck.focus();
		return false;
	}
	if (!verificaEmail(document.sondaggio.con_emailcheck.value)){
		alert ("L'indirizzo email di verifica non č valido, prego controllare.");
		document.sondaggio.con_emailcheck.focus();
		return false;
	}
	if (document.sondaggio.con_telefono.value == ""){
		alert("Prego inserisci un tuo numero di Telefono");
		document.sondaggio.con_telefono.select();
		return false;
	}
	/*
	if (!verificaTelefono(document.sondaggio.con_telefono.value)){
		document.sondaggio.con_telefono.focus();
		return false;
	}
	*/
	//********* PRIVACY
	if (!document.sondaggio.con_consenso.checked) 
	{
		alert ("E' necessario acconsentire al Trattamento dei Dati Personali per procedere.");
		return false;
	}
	//*********
	document.sondaggio.submit();
	return true;
}

function checkForm(){
	if (!document.sondaggio.snr_risposta1[0].checked
	&& !document.sondaggio.snr_risposta1[1].checked){
		alert("Prego rispondi alla prima domanda");
		return false;
	}
	if (!document.sondaggio.snr_risposta2[0].checked
	&& !document.sondaggio.snr_risposta2[1].checked
	&& !document.sondaggio.snr_risposta2[2].checked
	&& !document.sondaggio.snr_risposta2[3].checked){
		alert("Prego rispondi alla seconda domanda");
		return false;
	}
	if (!document.sondaggio.snr_risposta3[0].checked
	&& !document.sondaggio.snr_risposta3[1].checked
	&& !document.sondaggio.snr_risposta3[2].checked
	&& !document.sondaggio.snr_risposta3[3].checked){
		alert("Prego rispondi alla terza domanda");
		return false;
	}
	if (!document.sondaggio.snr_risposta4[0].checked
	&& !document.sondaggio.snr_risposta4[1].checked
	&& !document.sondaggio.snr_risposta4[2].checked
	&& !document.sondaggio.snr_risposta4[3].checked){
		alert("Prego rispondi alla quarta domanda");
		return false;
	}
	if (!document.sondaggio.snr_risposta5[0].checked
	&& !document.sondaggio.snr_risposta5[1].checked){
		alert("Prego rispondi alla quinta domanda");
		return false;
	}
	if (document.sondaggio.snr_risposta5[1].checked){
		if (!document.sondaggio.snr_risposta6[0].checked
		&& !document.sondaggio.snr_risposta6[1].checked
		&& !document.sondaggio.snr_risposta6[2].checked
		&& !document.sondaggio.snr_risposta6[3].checked
		&& !document.sondaggio.snr_risposta6[4].checked){
			alert("Prego rispondi alla sesta domanda");
			return false;
		}
	}
	document.sondaggio.submit();
	return true;
}

function abilitaRisposte(){
	if (document.sondaggio.snr_risposta5[0].checked){
		document.sondaggio.snr_risposta6[0].disabled=true;
		document.sondaggio.snr_risposta6[1].disabled=true;
		document.sondaggio.snr_risposta6[2].disabled=true;
		document.sondaggio.snr_risposta6[3].disabled=true;
		document.sondaggio.snr_risposta6[4].disabled=true;
	}
	if (document.sondaggio.snr_risposta5[1].checked){
		document.sondaggio.snr_risposta6[0].disabled=false;
		document.sondaggio.snr_risposta6[1].disabled=false;
		document.sondaggio.snr_risposta6[2].disabled=false;
		document.sondaggio.snr_risposta6[3].disabled=false;
		document.sondaggio.snr_risposta6[4].disabled=false;
	}

	return true;
}

// funzioni per il popup che mostra la piantina dei prezzi
function ShowPop(id)
{
   document.getElementById(id).style.visibility = "visible";
}

function HidePop(id)
{
   document.getElementById(id).style.visibility = "hidden";
}
