function ApriImmagini(file)
{
  var prop = "top=20, left=20, width=1, height=1,scrollbars=yes";
  mywin = window.open(file, null, prop);
 // mywin.focus();
}

function popUpWindow(URLStr, left, top, width, height, toscroll){
	var popUpWin=0;
  if(popUpWin){
    if(!popUpWin.closed) popUpWin.focus();
  }
	if (toscroll == ""){
		toscroll = 'no';
	}	
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+toscroll+',resizable='+toscroll+',copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.overflow=v;}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function openLayer(layerID){
	if (document.all[layerID].style.overflow == "hidden" ){
		document.all[layerID].style.overflow = "visible"
		MM_swapImage('img_'+layerID,'','/img/layer_close.gif',1);
	}else{	
		document.all[layerID].style.overflow = "hidden"
		MM_swapImage('img_'+layerID,'','/img/layer_open.gif',1);
	}
}

function open_window( n )
{
	mywin = window.open(n , 'mywin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=700,height=800,left=0,top=0,screenX=0,screeny=0');
	mywin.focus();
}

function open_window_auto( n )
{
	mywin = window.open(n , 'mywin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=150,left=0,top=0,screenX=0,screeny=0');
	mywin.focus();
}

function controllaformLogin(theForm){
	if (theForm.UserID.value == ""){
		alert("Inserire un valore per il campo \"username\".");
		theForm.UserID.focus();
		return (false);
	}
	if (theForm.Password.value == ""){
		alert("Inserire un valore per il campo \"password\".");
		theForm.Password.focus();
		return (false);
	}
	return (true);
}

function controllaformImmobili(theForm){
	if (theForm.riferimento.value == ""){
		alert("Inserire un valore per il campo \"Riferimento\".");
		theForm.riferimento.focus();
		return (false);
	}	
	if (theForm.id_motivazione.value == "0"){
		alert("Inserire un valore per il campo \"Contratto\".");
		theForm.riferimento.focus();
		return (false);
	}	
	if (theForm.id_categoria.value == "0"){
		alert("Inserire un valore per il campo \"Categoria\".");
		theForm.riferimento.focus();
		return (false);
	}	
	if (theForm.id_tipologia.value == "0"){
		alert("Inserire un valore per il campo \"Tipologia\".");
		theForm.riferimento.focus();
		return (false);
	}	
	if (theForm.id_agenzia.value == ""){
		alert("Inserire un valore per il campo \"Nome Agenzia\".");
		theForm.id_agenzia.focus();
		return (false);
	}
	if (theForm.provincia.value == ""){
		alert("Inserire un valore per il campo \"Provincia\".");
		theForm.provincia.focus();
		return (false);
	}	
	if (theForm.comune.value == "" || theForm.comune.value == "undefined"){
		alert("Inserire un valore per il campo \"Comune\".");
		theForm.comune.focus();
		return (false);
	}

   var contratto = theForm.id_motivazione.value;
   var prezzo = theForm.prezzo.value;
   var fascia_prezzo = theForm.fascia_prezzo.value;

	var b = controllaFasciaPrezzo(contratto,prezzo,fascia_prezzo);
                           
	if (!b){
		alert("Inserire un valore congruente per il campo \"Fascia Prezzo\".");
		theForm.fascia_prezzo.focus();
		return (false);
	}

   var ipe = theForm.ipe.value;
   var classe = theForm.classe_energetica.value;
   var um = theForm.ipe_um.value;

	var b = controllaIPE(ipe,classe);
                      
	if (!b){
		var azione = confirm("Non è stato inserito un valore per il campo Classe Energetica e \"I.P.E.\".\nClicca su OK per confermare comunque l'inserimento.\nClicca su 'Annulla' per inserire i dati mancanti");
		if (!azione) {
         theForm.ipe.focus();
         return (false);
      }
	}

   var b = controllaUM(ipe,um);
	if (!b){
		alert("Inserire un valore per il campo \"UM\".");
		theForm.ipe_um.focus();
		return (false);
	}

	var b = controllaCLASSE(ipe,classe);                           
	if (!b){
		alert("Inserire un valore congruente per il campo \"Classe Energetica\".");
		theForm.classe_energetica.focus();
		return (false);
	}

/*
	var b = controllaIPECLASSE(ipe,classe);
                           
	if (!b){
		alert("Inserire un valore congruente per il campo \"Classe Energetica\".");
		theForm.classe_energetica.focus();
		return (false);
	}
*/
	
	if (theForm.descrizione.value == ""){
		alert("Inserire un valore per il campo \"Descrizione\".");
		theForm.descrizione.focus();
		return (false);
	}
	
//	if ((theForm.sospeso.checked == false) && (theForm.pubblica_portali.checked == false) && (theForm.solo_sito.checked == false)) {
	if (theForm.chkSospeso.value == '0'){
		if ((theForm.pubblica_portali.checked == false) && (theForm.solo_sito.checked == false)) {
			alert("Inserire un valore per la sezione \"Scegli dove pubblicare\".");
			theForm.pubblica_portali.focus();
			return (false);
		}
	}
	else{
		if ((theForm.sospeso.checked == false) && (theForm.pubblica_portali.checked == false) && (theForm.solo_sito.checked == false)) {
			alert("Inserire un valore per la sezione \"Scegli dove pubblicare\".");
			theForm.pubblica_portali.focus();
			return (false);
		}
	}

	
//	var azione = confirm("CONFERMA PUBBLICAZIONE IMMOBILE\n\nClicca su OK per confermare l'inserimento e attendi di essere indirizzato alla pagina di pubblicazione seguente")	
//	if (azione){
//		document.getElementById('scheda_immobile').style.overflow = "hidden";
//		document.getElementById('attendi').style.overflow = "visible";	
//		return (true);
//	}else{
//		return (false);
//	}

}

function controllaformImmobiliMod(theForm){
	if (theForm.riferimento.value == ""){
		alert("Inserire un valore per il campo \"Riferimento\".");
		theForm.riferimento.focus();
		return (false);
	}	
	if (theForm.id_motivazione.value == "0"){
		alert("Inserire un valore per il campo \"Contratto\".");
		theForm.riferimento.focus();
		return (false);
	}	
	if (theForm.id_categoria.value == "0"){
		alert("Inserire un valore per il campo \"Categoria\".");
		theForm.riferimento.focus();
		return (false);
	}	
	if (theForm.id_tipologia.value == "0"){
		alert("Inserire un valore per il campo \"Tipologia\".");
		theForm.riferimento.focus();
		return (false);
	}	
	if (theForm.id_agenzia.value == ""){
		alert("Inserire un valore per il campo \"Nome Agenzia\".");
		theForm.id_agenzia.focus();
		return (false);
	}
	if (theForm.provincia.value == ""){
		alert("Inserire un valore per il campo \"Provincia\".");
		theForm.provincia.focus();
		return (false);
	}	
	if (theForm.comune.value == "" || theForm.comune.value == "undefined"){
		alert("Inserire un valore per il campo \"Comune\".");
		theForm.comune.focus();
		return (false);
	}

   var contratto = theForm.id_motivazione.value;
   var prezzo = theForm.prezzo.value;
   var fascia_prezzo = theForm.fascia_prezzo.value;

	var b = controllaFasciaPrezzo(contratto,prezzo,fascia_prezzo);
                           
	if (!b){
		alert("Inserire un valore congruente per il campo \"Fascia Prezzo\".");
		theForm.fascia_prezzo.focus();
		return (false);
	}

   var ipe = theForm.ipe.value;
   var classe = theForm.classe_energetica.value;
   var um = theForm.ipe_um.value;

	var b = controllaIPE(ipe,classe);
                      
	if (!b){
		var azione = confirm("Non è stato inserito un valore per il campo Classe Energetica e \"I.P.E.\".\nClicca su OK per confermare comunque l'inserimento.\nClicca su 'Annulla' per inserire i dati mancanti");
		if (!azione) {
         theForm.ipe.focus();
         return (false);
      }
	}

   var b = controllaUM(ipe,um);
	if (!b){
		alert("Inserire un valore per il campo \"UM\".");
		theForm.ipe_um.focus();
		return (false);
	}

	var b = controllaCLASSE(ipe,classe);                           
	if (!b){
		alert("Inserire un valore congruente per il campo \"Classe Energetica\".");
		theForm.classe_energetica.focus();
		return (false);
	}

/*
	var b = controllaIPECLASSE(ipe,classe);                           
	if (!b){
		alert("Inserire un valore congruente per il campo \"Classe Energetica\".");
		theForm.classe_energetica.focus();
		return (false);
	}
*/
	
	if (theForm.descrizione.value == ""){
		alert("Inserire un valore per il campo \"Descrizione\".");
		theForm.descrizione.focus();
		return (false);
	}
//	var azione = confirm("CONFERMA PUBBLICAZIONE IMMOBILE\n\nClicca su OK per confermare l'inserimento e attendi di essere indirizzato alla pagina di pubblicazione seguente")	
//	if (azione){
//		document.getElementById('scheda_immobile').style.overflow = "hidden";
//		document.getElementById('attendi').style.overflow = "visible";	
//		return (true);
//	}else{
//		return (false);
//	}
}

function controllaFasciaPrezzo(contratto,prezzo,fascia_prezzo) {

   var fascia_prezzo_giusta;

	if ((prezzo != "") && (prezzo != "0")){
      contratto = parseInt(contratto);
      prezzo = parseInt(prezzo);
      fascia_prezzo = parseInt(fascia_prezzo);
      if (contratto == 1) {

         if (fascia_prezzo == 7) return(true);

	      if (prezzo > 0 && prezzo <= 100000){
		      fascia_prezzo_giusta=1;
	      }
	      else if (prezzo > 100000 && prezzo <= 150000){
		      fascia_prezzo_giusta=2;
	      }
	      else if (prezzo > 150000 && prezzo <= 200000){
		      fascia_prezzo_giusta=3;
	      }
	      else if (prezzo > 200000 && prezzo <= 300000){
		      fascia_prezzo_giusta=4;
	      }
	      else if (prezzo > 300000 && prezzo <= 500000){
		      fascia_prezzo_giusta=5;
	      }
	      else if (prezzo > 500000){
		      fascia_prezzo_giusta=6;
	      }
      }
      else if (contratto == 2) {

         if (fascia_prezzo == 6) return(true);

	      if (prezzo > 0 && prezzo <= 500){
		      fascia_prezzo_giusta=1;
	      }
	      else if (prezzo > 500 && prezzo <= 1000){
		      fascia_prezzo_giusta=2;
	      }
	      else if (prezzo > 1000 && prezzo <= 1500){
		      fascia_prezzo_giusta=3;
	      }
	      else if (prezzo > 1500 && prezzo <= 2000){
		      fascia_prezzo_giusta=4;
	      }
	      else if (prezzo > 2000){
		      fascia_prezzo_giusta=5;
	      }
      }

   }
   else{
	   return(true);
	} 
   
   return (fascia_prezzo_giusta == fascia_prezzo);

}

function controllaIPE(ipe,classe) {

   if (classe != "9"){
	   if ((ipe == "") || (ipe == "0")){
	      return(false);
      }
   }
   return(true);

}

function controllaUM(ipe,um) {

	if ((ipe == "") || (ipe == "0")) {                            
	   return(true);
   }
   else {
      if ((um == "") || (um == "0")){ 
	      return(false);
      }
      else { 
	      return(true);
      }
   }

}

function controllaCLASSE(ipe,classe) {

   if ((ipe != "") && (ipe != "0")){
      return(classe != "0");
   }
   return(true);
}

function controllaIPECLASSE(ipe,classe) {

   var classe_giusta;
   var fipe;
   fipe = parseFloat(ipe.replace(",","."));

	if (classe != "0"){

      classe = parseInt(classe);

	      if (fipe > 0 && fipe <= 30){
		      return (classe < 3);
	      }
	      else if (fipe > 30 && fipe <= 50){
		      classe_giusta=3;
	      }
	      else if (fipe > 50 && fipe <= 70){
		      classe_giusta=4;
	      }
	      else if (fipe > 70 && fipe <= 90){
		      classe_giusta=5;
	      }
	      else if (fipe > 90 && fipe <= 120){
		      classe_giusta=6;
	      }
	      else if (fipe > 120 && fipe <= 160){
		      classe_giusta=7;
	      }
	      else if (fipe > 160){
		      classe_giusta=8;
	      }
	      else {
		      return(true);
	      }         

   }
   else{
	   return((ipe == "") || (ipe == 0));
	}
   
   return (classe_giusta == classe);

}

// -------------------------------------------------------------------------------------------------
// ------------------------------------ STATS ------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// Define the location of count.asp
// Using a path, you may use this code in any subfolder
var file='/statcountex/count.asp';

var d=new Date(); 
var s=d.getSeconds(); 
var m=d.getMinutes();
var x=s*m;
f='' + escape(document.referrer);
if (navigator.appName=='Netscape'){b='NS';} 
if (navigator.appName=='Microsoft Internet Explorer'){b='MSIE';} 
if (navigator.appVersion.indexOf('MSIE 3')>0) {b='MSIE';}
u='' + escape(document.URL); w=screen.width; h=screen.height; 
v=navigator.appName; 
fs = window.screen.fontSmoothingEnabled;
if (v != 'Netscape') {c=screen.colorDepth;}
else {c=screen.pixelDepth;}
j=navigator.javaEnabled();
info='w=' + w + '&h=' + h + '&c=' + c + '&r=' + f + '&u='+ u + '&fs=' + fs + '&b=' + b + '&x=' + x;
document.write('<img src="' + file + '?'+info+ '" width=1 height=1 border=0><br>');

// #################################################################################################
// #################################################################################################

function stop_indesidered_keys_numeri(pwd) {
	if ((event.keyCode >=48 && event.keyCode <=57)) {
		return true
	} else {
		if(pwd == 1){alert("Carattere '" + String.fromCharCode(event.keyCode) + "' non consentito")};
		return false		
	}
}

function stop_indesidered_keys_prezzo(pwd) {
	if (event.keyCode == 44 || (event.keyCode >=48 && event.keyCode <=57) ) {
		return true
	} else {
		if(pwd == 1){alert("Carattere '" + String.fromCharCode(event.keyCode) + "' non consentito")};
		return false		
	}
}

function stop_indesidered_keys_double(pwd) {
	if (event.keyCode == 44 || (event.keyCode >=48 && event.keyCode <=57) ) {
		return true
	} else {
		if(pwd == 1){alert("Carattere '" + String.fromCharCode(event.keyCode) + "' non consentito")};
		return false		
	}
}

function stop_indesidered_keys_nr_immobili(pwd) {
	if  (event.keyCode >=48 && event.keyCode <=57) {
		return true
	} else {
		if(pwd == 1){alert("Carattere '" + String.fromCharCode(event.keyCode) + "' non consentito")};
		return false		
	}
}

function stop_indesidered_keys(pwd) {
	if (event.keyCode==45 || event.keyCode == 46 || event.keyCode == 64 || event.keyCode == 95 || (event.keyCode >=65 && event.keyCode <=90) || (event.keyCode >=97 && event.keyCode <=122) || (event.keyCode >=48 && event.keyCode <=57)|| (event.keyCode >=1 && event.keyCode <=31)) {
		return true
	} else {
		if(pwd == 1){alert("Carattere '" + String.fromCharCode(event.keyCode) + "' non consentito")};
		return false		
	}
}

