
// esegue l'highlight dell'immagine contenuta nel link objLink
function imageOn(imgId) {
    ele = document.getElementById(imgId);
    if (ele!=null) {
            src_img =ele.src; 
            src_nuova_img= src_img.replace("_off\.","_on.");
            ele.src=src_nuova_img;
    }

}
// disattiva l'highlight dell'immagine contenuta nel link objLink
function imageOff(imgId) {
    ele = document.getElementById(imgId);
    if (ele!=null) {
	    src_img =ele.src; 
	    src_nuova_img= src_img.replace("_on\.","_off.");
	    ele.src=src_nuova_img;
    }
}

function showElement(elId) {
   el = document.getElementById(elId);
   if (el!=null) {
       el.style.visibility = 'visible';
   }
}
// Hides an element

function hideElement(elId) {
   el = document.getElementById(elId);
   if (el!=null) {
       el.style.visibility = 'hidden';
   }
}
/*
function showMessage(elId,message) {
   el = document.getElementById(elId);
   if (el!=null) {
	   el.innerHTML = message;
   }
}
*/
var submenus = new Array();
var numSubmenus=0;
var popTimer = 0;

function hideAllBut(idx) {
    //nascondi popup localita
	info = document.getElementById('infolocalita')
    if (info!=null) {
        info.style.display='none';
    }
	//fine
	for(i=0; i<numSubmenus; i++) {
        if (submenus[i]!=null) {
            if (i+1 != idx) {
                submenus[i].style.visibility = "hidden";
            }
            else {
                submenus[i].style.visibility = "visible";
            }
        }
    }
}

function popOver(idx) {
    hideAllBut(idx);
    clearTimeout(popTimer);
}
function popOut(idx) {
	hideAllBut(idx);
    popTimer = setTimeout('hideAllBut(0)', 250);
}

function hideMenuSx() {
    hideAllBut(0);
}
function initMenuSx() {
    for(i=1; (menuItem = document.getElementById("menu-sx-"+i))!=null; i++) {
        subMenuItem = document.getElementById("submenu-sx-"+i);
        submenus[i-1]=subMenuItem;
        numSubmenus++;
    }
}


//da qui in poi ci sono funzioni inserite da lbranca------------------------------------------------------

function not_Empty_Id(id)
{ 
//RITORNA TRUE SE ALL' INTERNO DEL TAG IN QUESTIONE NON C'E' NULLA
var contenuto = document.getElementById(id).innerHTML;
	if(contenuto!='')	
		return true;
	else
    	return false;
}

function openPopupScheda(url) {
    win_name = 'p_' + (new Date()).getTime().toString();
    he=window.screen.availHeight;
    var attr = "resizable=no,scrollbars=yes,width="+675+",height="+250;
    var popup=window.open(url,win_name,attr);
    }
	
	
function alert_language(linguacorrente,testo,url) {
  //-------------------------------------------------------------------------------------
  //QUESTO IF E' UN RIPEGO PER IL MODULO AIUTACI CHE HA DUE LINGUE DISP ANZICHE UNA.....
  //-------------------------------------------------------------------------------------
  if (url=="aiutaci.php") 
  {
   	 if (linguacorrente!="italian" && linguacorrente!="english") 
   	 {	
    	alert(testo);
    	return false;
     }
     else
     {
   		location.href = url;
     }
  }
  //------------------------------------------------------------------------------------
  else
  {
	 if (linguacorrente!="italian") 
   	 {	
    	alert(testo);
    	return false;
     }
     else
     {
   		location.href = url;
     }
  }
  

}

function converti_select(obj){
//necessaria per InternetExplorer; restituisce il valore selezionato per un menu a tendina passato come paramtero
//esempio di utilizzo
//<select name= .... onChange="mm_da.value=converti_select(this);">
//fine

        var conversione;
        for (var i = 0; i < obj.length; i++) {
                if (obj.options[i].selected == true) {
                        conversione = obj.options[i].value
                }
        }
        return conversione
}

function check_radio(obj){

        for (var i = 0; i < obj.length; i++) {
                if (obj[i].checked == true) {
                        return true;
                }
        }
        return false;
}
function cambiaIn(valore){
//riporta il calore del campo in nel campo xin
geo_affina.xin.value=valore;
}

function campi_vuoti(formname,quali,testo){ 
//controlla che i campi di imput del form passato come parametro non siano vuoti. 
//esempio di utilizzo 
// controlla_vuoti(document.form,new Array('citta','comunicazione')); 
//fine 


//================================================================
//AFFINA RICERCA GEOGRAFICA
//================================================================
if(formname.name=='geo_affina')
{
	if (formname.geo_affina_citta.value != formname.dv.value){
		formname.dv.value="";
		formname.sp.value="";
		formname.of.value="";
		formname.dvc.value="";
		formname.xloc.value=formname.geo_affina_citta.value;
		//formname.xin.value=formname.in.value;
		formname.dv.value=formname.geo_affina_citta.value;
		formname.action="ricerca_geo.php";
		formname.method="POST";
	}	
}

//================================================================
//PG PRENOTA
//================================================================
if(formname.name=='pg_prenota')
{

	if(!formname.autorizzo[0].checked)
	{
		 alert("Attenzione, per ricevere informazioni circa l'adesione al servizio di prenotazione on line, e' necessario dare il consenso"); 
		 return false;
	}
	
	if(!check_radio(formname.cliente))
	{
		 alert(testo); 
		 return false;
	}
}

//================================================================
//POPUP CONTATTO
//================================================================
if(formname.name=='pcontatto')
{
  if(formname.fax.value=='' && formname.email.value=='')
  {              
	 alert(testo); 
     return false;
  } else if (formname.email.value!='')
  	{
    //Controlla la validita della email se inserita
    EmailAddr = formname.email.value;
    Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
    if (Filtro.test(EmailAddr))
      return true;
    else
      {
      alert(testo);
      formname.email.focus();
      return false;
      }
    }
}

//================================================================
//AREA PROFESSIONALE
//================================================================
if(formname.name=='area_professionale')
{
  if(formname.passwd.value!='' && formname.repasswd.value!='')
  { 
   if(formname.passwd.value != formname.repasswd.value)
   {
                alert("ATTENZIONE: Le password inserite non sono uguali"); 
                return false;
   }
  }
}

//================================================================
//RILEVAZIONE DATI
//================================================================

if(formname.name=='rilevazione_dati')
{

	prezzoexists = false;
  	form_elements_number = document.forms[formname.name].elements.length;
	for(i = 0; i < form_elements_number; i++)
	{
		if(document.forms[formname.name].elements[i].value != "")
		{
			
			id = document.forms[formname.name].elements[i].id;
	        var cerca = new RegExp("prezzo");

			if(cerca.test(id)) // se uno dei campi prezzo e' != "" esci dal ciclo
			{
				prezzoexists = true;
				break;
			}
	
		}
	}	
	
	if(!prezzoexists)
	{
		alert('Almeno uno tra i campi prezzi deve essere compilato');
		return false;
	}

   
   if(formname.ATIP_ACATEG.value.charAt(0) != "M")  // i campeggi non ce l hanno obbligatorio
   {
	   if(formname.ASTANZ.value=='' && formname.AAPPAR.value=='')
	   {
					alert("ATTENZIONE: E' obbligatorio indicare il numero di stanze e/o di appartamenti"); 
					return false;
	   }
   }  
}

//================================================================
//CONTROLLO CAMPI VUOTI
//================================================================
 
    var totale=quali.length; 

    var numero=formname.elements.length; 
    for(var a=0;a<totale;a++){ 
        for(var e=0;e<numero;e++){ 
            if(formname.elements[e].name==quali[a]){ 
                quali[a] = e; 
                e=1000; 
            } 
        } 
    } 
 
    for(var i=0;i<totale;i++){ 

        if ((formname.elements[quali[i]].type=="select-one")&&(converti_select(formname.elements[quali[i]])=="")){ 
         alert("ATTENZIONE: Non hai compilato tutti i campi obbligatori"); 
         return false; 
        }else{ 
                if ((formname.elements[quali[i]].type!="select-one")&&(formname.elements[quali[i]].value=="")){ 
                alert(testo); 
                return false;
        } 
        } 
    } 
    return true;
}

//=======================================================
//FUNZIONE PER SFOGLIARE LE PAGINE IN LISTATO E OFFERTE
//=======================================================
function sfoglia(pagina)
       {
		frm=document.sfoglia;
		frm['p_pag'].value=pagina;
	      frm.submit();
     	}

//===================================================================================================================================

//===================================================================================================================================
//FUNZIONE PER RICERCA AVANZATA
//====================================================================================================================================

function checkAdvancedSearch(str_param_ricerca_avanzata,str_aree)
{

if(document.forms['ricerca_avanzata'].elements['acitta'].value == '' &&
   document.forms['ricerca_avanzata'].elements['acodar'].value == '%' &&
   document.forms['ricerca_avanzata'].elements['aprov'].value == '%'  &&
   document.forms['ricerca_avanzata'].elements['areg'].value == '%'
   ) 

	{   
	
		if(document.forms['ricerca_avanzata'].elements['ACATENE'].value != '%')
		{
			return true;
		}
		else
		{
			alert(str_param_ricerca_avanzata);
			return false;
		}
	}
	
if((document.forms['ricerca_avanzata'].elements['acodar'].value != '%') &&
		(
			document.forms['ricerca_avanzata'].elements['aprov'].value != '%' ||
			document.forms['ricerca_avanzata'].elements['acitta'].value != '' ||
			document.forms['ricerca_avanzata'].elements['areg'].value != '%'	
		)   
   )

   {
		alert(str_aree);
		return false;
   }


return true;

}

//===================================================================================================================================


//===================================================================================================================================
//
//====================================================================================================================================


function checkInformativaBoxSearch(msg)
{

	if(!document.agreeform.txt_agree1.checked || !document.agreeform.txt_agree2.checked)
	{
	
		 alert(msg); 
		 return false;
	
	}
	else 
	{
	
		return true;
	
	}
	

}

//===================================================================================================================================


//===================================================================================================================================
//FUNZIONE PER RICERCHE. SE NESSUN PARAMETRO E' SELEZIONATO RESTITUISCE ALERT
//====================================================================================================================================
function checkfield(nomeform,valoredaskippare,alert_msg)
{

	var campi_vuoti = new Array();
	campi_vuoti[0] = 'all';    
    
	if(nomeform=='ricerca_avanzata')
	{   
	     
		 //la ricerca avanzata nn vuole il controllo su tutti i campi!!!
			bb = 9 
	    //qui aggiungo il controllo PREZZO/TIPOLOGIA
			prezzo = document.forms[nomeform].elements['prezzo'].value.substr(0,2);
			tipologia = document.forms[nomeform].elements['tipologia'].value.substr(0,2);
            somma = prezzo+tipologia;
			if (somma.length<4 && somma.length>1) //perche prezzo ha value "" e tipologia ha value %
			{
//				alert('I campi prezzo e tipologia devono essere entrambi compilati');
				alert(alert_msg);
				return false;
            }
			
	}
	else
	{
		bb = document.forms[nomeform].elements.length;
	}	
	for (i=0;i<bb;i++) 
    {

	 	if(document.forms[nomeform].elements[i].type=='hidden') //controllo necesario per gli hidden da saltare...
	 	{
	       // do nothing
	 	}
		
	 	else if(document.forms[nomeform].elements[i].type=='checkbox') //controllo necesario per i checkbox. da implementare...
	 	{
	 		if(document.forms[nomeform].elements[i].checked==true)
			{
		   		campi_vuoti[0] = 'not all';
			}
	 	}
	 
	    else if(document.forms[nomeform].elements[i].value!='' && document.forms[nomeform].elements[i].value!='%' && document.forms[nomeform].elements[i].value!=valoredaskippare)
     	{
   			 campi_vuoti[0] = 'not all';	
     	}
	 
     }

	//se nemmeno un campo e' compilato....
	if(campi_vuoti[0]=='all')
	{
	   	 if(nomeform=='ricerca_avanzata')
//		 	alert('Devi inserire almeno un parametro di ricerca tra quelli inseriti nella sezione sopra i prezzi');
			alert(alert_msg);
		 else
//		 	alert('Devi inserire almeno un parametro di ricerca');
			alert(alert_msg);
	   	 return false;
	}

}

function slink(acode)
{
	window.open('obj/statistiche.php?acode='+acode+'&case=slink','slink');
}


//=================================================================================================================================

function MM_swapImgRestore()
{
  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_preloadImages()
{
  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_findObj(n, d)
{
  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);
  }
  return x;
}

function MM_swapImage()
{
  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];
	}
  } // end for
}

// Trim whitespace from left and right sides of s.
function trim(s) {
    return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}


function autoResizePopup() {

	var body = document.getElementById("pframe");
	win_height= body.offsetHeight;
	maxHeight =window.screen.availHeight;
	win_height= Math.min(maxHeight,win_height);

    var fixed_width=690;

	var oheight, nheight, sheight
	var owidth, nwidth, swidth

	owidth = (window.innerWidth) ? window.innerWidth : document.body.offsetWidth;
	oheight = (window.innerHeight) ? window.innerHeight : document.body.offsetHeight;

	sheight = screen.availHeight
	swidth = screen.availWidth
	//window.resizeTo(swidth,sheight);
	window.resizeTo(fixed_width,sheight);

	nwidth = (window.innerWidth) ? window.innerWidth : document.body.offsetWidth;
	nheight = (window.innerHeight) ? window.innerHeight : document.body.offsetHeight;

	oheight = ((sheight - nheight) + oheight)
	owidth = ((swidth - nwidth) + owidth)

	//window.resizeTo(owidth,win_height)
	window.resizeTo(fixed_width,win_height)

	oleft = (window.screen.availWidth - fixed_width) / 2;
	otop = (window.screen.availHeight - oheight) / 2;
	//window.moveTo(oleft,otop);

}

function apriPopup(url,w,h) {
    win_name = 'p_' + (new Date()).getTime().toString();
    var attr = "resizable=yes,scrollbars=yes,width="+w+",height="+h;
    var popup=window.open(url,win_name,attr);
}

function apriPopupTematica(url,w,h) {
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
    win_name = 'p_' + (new Date()).getTime().toString();
    var attr = "resizable=yes,scrollbars=yes,location=no,width="+w+",height="+h+",left="+wleft+",top="+wtop;
    var popup=window.open(url,win_name,attr);
}


function apriStampaScheda(page,lang,acode) {
	w = 675;
	wleft = (screen.width - w) / 2;
    win_name = 'p_' + (new Date()).getTime().toString();
    var attr = "resizable=yes,scrollbars=yes,width="+w+",height=675,left="+wleft;
	urlEncoded = page+"?acode="+acode+"&lang="+lang+"&mod=print";
	//urlEncoded = page+"?acode="+escape(acode)+"&lang="+lang+"&mod=print";
	//urlEncoded = page+"?acode="+URLEncode(acode)+"&lang="+lang+"&mod=print";
	var popup=window.open(urlEncoded,win_name,attr);
}

function apriHelp(lang) {
    height=550;
    width=675;
    wleft = (screen.width - width) / 2;
    wtop = (screen.height - height) / 2;
    win_name = 'p_' + (new Date()).getTime().toString();
    var attr = "resizable=no,scrollbars=yes,top="+wtop+",left="+wleft+",width="+width+",height="+height;
    var popup=window.open("phelp.php?lang="+lang,win_name,attr);
}
function apriInfoGeo() {
    apriPopup("pinfogeo.php",300,600);
}
function apriHelpGeo() {
    h=600;
    w=600;
    wleft = (screen.width - w) / 2;
    win_name = 'p_' + (new Date()).getTime().toString();
    var attr = "resizable=no,scrollbars=no,top=0,left="+wleft+",width="+w+",height="+w+",left="+wleft;
    var popup=window.open("phelpgeo.php",win_name,attr);
}
function apriSchedaGeo(geocode) {
    apriPopup("scheda.php?geocode="+URLEncode(geocode)+"&mod=print",675,675);
}
function apriPedo(geocode) {
    apriPopup("percorso.php?geocode="+URLEncode(geocode)+"&tp=P",700,730);
}
function apriPercorso(geocode) {
    apriPopup("percorso.php?geocode="+URLEncode(geocode)+"&tp=C",700,730);
}
function apriMappa(geocode) {
    //apriPopup("pmappa.php?geocode="+URLEncode(geocode),675,675);
	apriPopup("pmappa.php?geocode="+geocode,700,730);
}

function Show_PGPRENOTA()
{
	document.getElementById('PGPRENOTA').style.display='block';
}

function Hide_PGPRENOTA()
{

	document.getElementById('PGPRENOTA').style.display='none';

}

function increment(fieldname)
{
	currentvalue = eval(fieldname.value);
    fieldname.value++;	
}

function decrement(fieldname)
{
	currentvalue = eval(fieldname.value);
	if(currentvalue>0)
	{
    	fieldname.value--;	
	}
}

function ripeti_ricerca(acodlo,acodfr) {

	frm=document.form_ripeti_ricerca;
	frm['acodlo'].value=acodlo;
	frm['acodfr'].value=acodfr;
	frm.submit();
}
//cambia la classe css di un oggetto
function clambiaClasse(objID, className){
	document.getElementById(objID).className=className;
}

function chiudilayer(name) {
obj=document.getElementById(name);   
obj.style.visibility = 'hidden';
}

function changelayervisibility(id) {
	//splitto gli oggetti se ce n'č pių di uno
	arrObj=id.split("|");

	//nasconso o visualizzo ogni oggetto nell'array
	for(i=0; i<arrObj.length; i++)
	{		
		if(document.getElementById(arrObj[i]).style.visibility == 'hidden') 
		{document.getElementById(arrObj[i]).style.visibility = 'visible';}				
		else {document.getElementById(arrObj[i]).style.visibility = 'hidden';}
	}

}

function changelayerdisplay(id) {
	//splitto gli oggetti se ce n'č pių di uno
	arrObj=id.split("|");

	//nasconso o visualizzo ogni oggetto nell'array
	for(i=0; i<arrObj.length; i++)
	{		
		if(document.getElementById(arrObj[i]).style.display == 'none') 
		{document.getElementById(arrObj[i]).style.display = 'block';}				
		else {document.getElementById(arrObj[i]).style.display = 'none';}
	}

}

function setLayerVisibility(id, newVisibility) {
	//splitto gli oggetti se ce n'č pių di uno
	arrObj=id.split("|");

	for(i=0; i<arrObj.length; i++)
	{		
		if(document.getElementById(arrObj[i]).style.visibility = 'hidden'){
		   document.getElementById(arrObj[i]).style.visibility = newVisibility;
		}	
	}

}

/* @lbranca
   SETTA AUTOMATICAMENTE 
   L ' ALTEZZA DI UN IFRAME 
   IN BASE ALLA GRANDEZZA DELLA
   PAGINA INCLUSA  
*/ 


function iFrameHeight(iframe) {
 if(document.getElementById && !(document.all)) {
  h = document.getElementById(iframe.id).contentDocument.body.scrollHeight;
  document.getElementById(iframe.id).height = h;
 }
 else if(document.all) {
  h = document.frames(iframe.id).document.body.scrollHeight;
  iframe.style.height = h;
 }
}


function inputSetValue(inputid,inputval){
	document.getElementById(inputid).value = inputval;
}


function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}



function alertSetteStelle(categoria){	
	if(categoria == 'A09'){
		alert('Alberghi di categoria 7 stelle sono presenti esclusivamente a Milano');	
	}
}