// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 0;
PositionY = 0;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
close();		
}}

function checkLunghezza(id,nomecampo,lunghezzamin) {
messaggio="Compila tutti i campi obbligatori: il campo "+nomecampo+" è vuoto";
	if (document.all){
		if(document.all[id].value.length < lunghezzamin){
			alert(messaggio);
			document.all[id].focus();
			return false;
		}
	}

	else if (document.getElementById){

		if(document.getElementById(id).value.length < lunghezzamin) {
			alert(messaggio);
			document.getElementById(id).focus();
			return false;
		}

	}

return true;
}

function IsNumeric(sText) {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function checkContatto()
{
	if (document.getElementById('consms').checked==false && document.getElementById('conmail').checked==false && document.getElementById('contel').checked==false ) {
		alert("Seleziona il metodo con cui vuoi essere contattato");
		return false;
	}
	return true;
}

function checkEmail(id) {
messaggio="L'indirizzo E-mail che hai inserito non è valido";
email = document.getElementById(id).value
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
			
	for(i=0; i < email.length ;i++){
		if(ok.indexOf(email.charAt(i))<0){
			alert(messaggio);
			document.getElementById(id).focus();
			return false;
		}		
	}
	if (email.indexOf("@") <= 0 || email.indexOf(".") <= 0) {
			alert(messaggio);
			document.getElementById(id).focus();
			return false;
	}
return true
}


function checkValueNumeric(id,nomecampo) {
messaggio="Nel campo "+nomecampo+" sono consentiti solo numeri";
	if (document.all){
		if(!IsNumeric(document.all[id].value)){
			alert(messaggio);
			document.all[id].focus();
			return false;
		}
	}

	else if (document.getElementById){

		if(!IsNumeric(document.getElementById(id).value)) {
			alert(messaggio);
			document.getElementById(id).focus();
			return false;
		}

	}

return true;
}

function checkValue(id,nomecampo) {
messaggio="Compila tutti i campi obbligatori: il campo "+nomecampo+" è vuoto";
	if (document.all){
		if(document.all[id].value == ''){
			alert(messaggio);
			document.all[id].focus();
			return false;
		}
	}

	else if (document.getElementById){

		if(document.getElementById(id).value == '') {
			alert(messaggio);
			document.getElementById(id).focus();
			return false;
		}

	}

return true;
}

function checkPrivacy() {
if (document.getElementById('privacy').checked==true) {
	return true
} else {
	alert("Per procedere è necessario dare l'autorizzazione al trattamento dei dati personali immessi nel modulo");
	return false;
}
}

function checkUnsubscribe() {
if (document.getElementById('unsubscribe').checked==true) {
	return true
} else {
	return false;
}
}

function checkSelect(id,nomecampo) {
messaggio="Seleziona un valore per il campo "+nomecampo;
	if (document.all){
		if(document.all[id].value <= 0){
			alert(messaggio);
			document.all[id].focus();
			return false;
		}
	}

	else if (document.getElementById){

		if(document.getElementById(id).value <= 0) {
			alert(messaggio);
			document.getElementById(id).focus();
			return false;
		}

	}

return true;
}

function ModificaPreferenzeValidation() {
	
	if (checkUnsubscribe()==false) {
		if (checkValue('nome','nome')==false) {
			return false;
			};
		if (checkValue('cognome','cognome')==false) {
			return false;
			};
		if (checkValue('azienda','azienda')==false) {
			return false;
			};
		if (checkValue('telefono','telefono')==false) {
			return false;
			};
		if (checkValueNumeric('telefono','telefono')==false) {
			return false;
			};
		if (checkEmail('email')==false) {
			return false;
			};
		if (checkContatto()==false) {
				return false;
			};
		if 	(checkPrivacy()==false) {
			return false;
		};
	
	}
	else {
		if (checkValue('nome','nome')==false) {
			alert("Per disiscriverti dal servizio devi riempire i campi nome,cognome,azienda"); 
			return false;
			};
		if (checkValue('cognome','cognome')==false) {
			alert("Per disiscriverti dal servizio devi riempire i campi nome,cognome,azienda"); 
			return false;
			};
		if (checkValue('azienda','azienda')==false) {
			alert("Per disiscriverti dal servizio devi riempire i campi nome,cognome,azienda"); 
			return false;
			};
	}
	
}

function RichiestaImmobileValidation() {
	if (checkValue('nome','nome')==false) {
		return false;
		};
	if (checkValue('cognome','cognome')==false) {
		return false;
		};
	if (checkValue('azienda','azienda')==false) {
		return false;
		};
	if (checkValue('telefono','telefono')==false) {
		return false;
		};
	if (checkValueNumeric('telefono','telefono')==false) {
		return false;
		};
	if (checkEmail('email')==false) {
		return false;
		};
	if (checkSelect('tipo_offerta','Tipologia offerta')==false) {
		return false;
		};
	if (checkSelect('tipo_immobile','Tipologia immobile')==false) {
		return false;
		};
			if (checkContatto()==false) {
				return false;
			};
		if (checkPrivacy()==false) {
		return false;
		};
}

function RichiestaInfoValidation() {
	if (checkValue('nome','nome')==false) {
		return false;
		};
	if (checkValue('cognome','cognome')==false) {
		return false;
		};
	if (checkValue('azienda','azienda')==false) {
		return false;
		};
	if (checkValue('telefono','telefono')==false) {
		return false;
		};
	if (checkValueNumeric('telefono','telefono')==false) {
		return false;
		};
	if (checkEmail('email')==false) {
		return false;
		};
		if (checkPrivacy()==false) {
		return false;
		};
}

function OffertaValidation() {

	if (checkValue('nome','nome')==false) {
		return false;
		};
	if (checkValue('cognome','cognome')==false) {
		return false;
		};
	if (checkValue('azienda','azienda')==false) {
		return false;
		};
	if (checkValue('telefono','telefono')==false) {
		return false;
		};
	if (checkValueNumeric('telefono','telefono')==false) {
		return false;
		};
	if (checkEmail('email')==false) {
		return false;
		};
	if (checkSelect('tipo_offerta','Tipologia offerta')==false) {
		return false;
		};
	if (checkSelect('tipo_immobile','Tipologia immobile')==false) {
		return false;
		};
	if (checkValue('metri','Metri quadri')==false) {
		return false;
		};
	if (checkValueNumeric('metri','Metri quadri')==false) {
		return false;
		};
	if (checkValue('zona','zona')==false) {
		return false;
		};
	if (checkValue('via','via')==false) {
		return false;
		};
	if (checkValue('cap','cap')==false) {
		return false;
		};
	if (checkValueNumeric('cap','cap')==false) {
		return false;
		};
	if (checkValue('comune','comune')==false) {
		return false;
		};
	if (checkValue('provincia','provincia')==false) {
		return false;
		};
	if (checkPrivacy()==false) {
		return false;
		};
}

function PeriziaValidation() {

	if (checkValue('nome','nome')==false) {
		return false;
		};
	if (checkValue('cognome','cognome')==false) {
		return false;
		};
	if (checkValue('azienda','azienda')==false) {
		return false;
		};
	if (checkValue('telefono','telefono')==false) {
		return false;
		};
	if (checkValueNumeric('telefono','telefono')==false) {
		return false;
		};
	if (checkEmail('email')==false) {
		return false;
		};
	if (checkSelect('tipo_offerta','Tipologia offerta')==false) {
		return false;
		};
	if (checkSelect('tipo_immobile','Tipologia immobile')==false) {
		return false;
		};
	if (checkValue('metri','Metri quadri')==false) {
		return false;
		};
	if (checkValueNumeric('metri','Metri quadri')==false) {
		return false;
		};
	if (checkValue('zona','zona')==false) {
		return false;
		};
	if (checkValue('via','via')==false) {
		return false;
		};
	if (checkValue('cap','cap')==false) {
		return false;
		};
		if (checkValueNumeric('cap','cap')==false) {
		return false;
		};
	if (checkValue('comune','comune')==false) {
		return false;
		};
	if (checkValue('provincia','provincia')==false) {
		return false;
		};
	if (checkPrivacy()==false) {
		return false;
		};
}
