function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}

var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){

	closeWin();

	type = type.toLowerCase();

	if (type == "fullscreen"){
		strWidth = screen.availWidth;
		strHeight = screen.availHeight;
	}
	var tools="";
	if (type == "standard") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}

function doPopUp(e)
{
//set defaults - if nothing in rel attrib, these will be used
var t = "standard";
var w = "780";
var h = "580";
//look for parameters
attribs = this.rel.split(" ");
if (attribs[1]!=null) {t = attribs[1];}
if (attribs[2]!=null) {w = attribs[2];}
if (attribs[3]!=null) {h = attribs[3];}
//call the popup script
popUpWin(this.href,t,w,h);
//cancel the default link action if pop-up activated
if (window.event)
	{
	window.event.returnValue = false;
	window.event.cancelBubble = true;
	}
else if (e)
	{
	e.stopPropagation();
	e.preventDefault();
	}
}

function findPopUps()
{
var popups = document.getElementsByTagName("a");
for (i=0;i<popups.length;i++)
	{
	if (popups[i].rel.indexOf("popup")!=-1)
		{
		// attach popup behaviour
		popups[i].onclick = popups[i].onkeypress = doPopUp;
		// add popup indicator
		if (popups[i].rel.indexOf("noicon")==-1)
			{
			popups[i].style.backgroundImage = "url(pop-up.gif)";
			popups[i].style.backgroundPosition = "0 center";
			popups[i].style.backgroundRepeat = "no-repeat";
			popups[i].style.paddingLeft = "15px";
			}
		// add info to title attribute to alert fact that it's a pop-up window
		popups[i].title = popups[i].title + " [Opens in pop-up window]";
		}
	}
}

addEvent(window, 'load', findPopUps, false);



//$js_mappa
function trovaOggetti(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=trovaOggetti(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function visLivelli() {
  var i,p,v,obj,args=visLivelli.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=trovaOggetti(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function validate() {
 	if ( document.getElementById('ck1').checked && document.getElementById('ck2').checked)
 	{
 		document.getElementById('cat').value='Alberghi_Ristoranti';
 	}
 	else if ( document.getElementById('ck1').checked)
 	{
 		document.getElementById('cat').value='Alberghi';
 	}
 	else if ( document.getElementById('ck2').checked)
 	{
 		document.getElementById('cat').value='Ristoranti';
 	}
	else
 	{
 		document.getElementById('cat').value='';
 	}
}

//$js_affinita

function calc() {
first = document.loveform.name1.value.toUpperCase();
firstlength = document.loveform.name1.value.length;
second = document.loveform.name2.value.toUpperCase();
secondlength = document.loveform.name2.value.length;
var LoveCount=0;

for (Count=0; Count < firstlength; Count++) {

letter1=first.substring(Count,Count+1);

if (letter1=='B') LoveCount+=2;
if (letter1=='C') LoveCount+=2;
if (letter1=='D') LoveCount+=2;
if (letter1=='F') LoveCount+=1;
if (letter1=='G') LoveCount+=2;
if (letter1=='H') LoveCount+=3;
if (letter1=='L') LoveCount+=1;
if (letter1=='M') LoveCount+=3;
if (letter1=='Q') LoveCount+=3;
if (letter1=='R') LoveCount+=3;
if (letter1=='S') LoveCount+=1;
if (letter1=='V') LoveCount+=1;
if (letter1=='Z') LoveCount+=2;
if (letter1=='K') LoveCount+=1;
if (letter1=='J') LoveCount+=1;
}

for (Count=0; Count < secondlength; Count++) {
letter2=second.substring(Count,Count+1);
if (letter2=='T') LoveCount+=2;
if (letter2=='O') LoveCount+=2;
if (letter2=='P') LoveCount+=2;
if (letter2=='I') LoveCount+=2;
if (letter2=='N') LoveCount+=3;
if (letter2=='O') LoveCount+=1;
if (letter2=='U') LoveCount+=3;
}

amount=0;

if (LoveCount> 0) amount=  5-((firstlength+secondlength)/2)
if (LoveCount> 2) amount= 10-((firstlength+secondlength)/2)
if (LoveCount> 4) amount= 20-((firstlength+secondlength)/2)
if (LoveCount> 6) amount= 30-((firstlength+secondlength)/2)
if (LoveCount> 8) amount= 40-((firstlength+secondlength)/2)

if (LoveCount>10) amount= 50-((firstlength+secondlength)/2)

if (LoveCount>12) amount= 60-((firstlength+secondlength)/2)
if (LoveCount>14) amount= 70-((firstlength+secondlength)/2)
if (LoveCount>16) amount= 80-((firstlength+secondlength)/2)
if (LoveCount>18) amount= 90-((firstlength+secondlength)/2)
if (LoveCount>20) amount=100-((firstlength+secondlength)/2)
if (LoveCount>22) amount=110-((firstlength+secondlength)/2)
if (firstlength==0 || secondlength==0) amount= 'Err';
if (amount < 0) amount= 0;
if (amount >99) amount=100;

document.loveform.output.value=amount+"%";

}


//$js_popup_meteo no uso

function popUp(URL,largo,alto) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=largo,height=alto,left = 122,top = 109');");
}

function popChat(website) {
var windowprops='width=100,height=100,scrollbars=no,status=no,resizable=yes'
var heightspeed = 2; // vertical scrolling speed (higher = slower)
var widthspeed = 7;  // horizontal scrolling speed (higher = slower)
var leftdist = 10;    // distance to left edge of window
var topdist = 10;     // distance to top edge of window

if (window.resizeTo&&navigator.userAgent.indexOf("Opera")==-1) {
var winwidth = window.screen.availWidth - leftdist;
var winheight = window.screen.availHeight - topdist;
var sizer = window.open("","","left=" + leftdist + ",top=" + topdist +","+ windowprops);
for (sizeheight = 1; sizeheight < winheight; sizeheight += heightspeed)
sizer.resizeTo("1", sizeheight);
for (sizewidth = 1; sizewidth < winwidth; sizewidth += widthspeed)
sizer.resizeTo(sizewidth, sizeheight);
sizer.location = website;
}
else
window.open(website,'mywindow');
}

// popUP
function popUPimg(PAGINA,WW,HH,titolo)
{
  open (PAGINA, "Vivatorino", "height="+HH+", width="+WW+", scrollbars=1, resizable=1, status=0, menubar=0, toolbar=0 left=122,top=109")
  //settando i parametri a 1, le barre vengono visualizzate, a 0 no.
}

//$js_paginebianche

function trovaOggetti(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=trovaOggetti(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function visLivelli() { //v6.0
  var i,p,v,obj,args=visLivelli.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=trovaOggetti(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


//$js_form_button

var checkobj

function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}

function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Non hai riempito tutti i campi obbligatori!")
return false
}
}
}


//$js_form_check

function formCheck(formobj){
	//1) Enter name of mandatory fields
	var fieldRequired = Array("nome", "email");
	//2) Enter field description to appear in the dialog box
	var fieldDescription = Array("Nome", "e-mail");
	//3) Enter dialog message
	var alertMsg = "Non hai riempito tutti i campi richiesti\n";

	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}


//$js_form_check_login

function formCheckLogin(formobj){
	//1) Enter name of mandatory fields
	var fieldRequired = Array("utente", "pass");
	//2) Enter field description to appear in the dialog box
	var fieldDescription = Array("User", "Pass");
	//3) Enter dialog message
	var alertMsg = "Non hai riempito tutti i campi richiesti\n";

	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

//pulsante form completo

var iscomplete=false

function checkform() {
	iscomplete=true
	for (i=0;i<=document.mioform.elements.length-1;i++) {
		if (document.mioform.user.value=="") {iscomplete=false}
		if (document.mioform.uemail.value=="") {iscomplete=false}
		if (document.mioform.upsw.value=="") {iscomplete=false}
		if (document.mioform.upsw2.value=="") {iscomplete=false}
		if (document.mioform.unumcod.value=="") {iscomplete=false}
	}
	if (!iscomplete) {
		window.status="Per favore compila i campi!"
		if (document.layers) {
			document.mioform.submitbut.value="NO"
			iscomplete=false
			}
			else if (document.all) {
			submitbutton.style.visibility="HIDDEN"
			iscomplete=false
		}
		else if (document.getElementById) {
			document.mioform.submitbut.value="NO"
			iscomplete=false
		}
		}
	if (iscomplete) {
		window.status="Adesso puoi inviare il modulo"
	 if (document.layers) {
			document.mioform.submitbut.value="Invia"
			iscomplete=true
			}
			else if (document.all) {
			submitbutton.style.visibility="VISIBLE"
			iscomplete=true
			}
		else if (document.getElementById) {
			document.mioform.submitbut.value="Invia"
			iscomplete=true
		}

	}

	var timer= setTimeout("checkform()",200)
}

function oksubmit() {
	return iscomplete
	}

// check form num - txt
// onkeypress="return numeralsOnly(event)"
// onkeypress="return lettersOnly(event)"

	/*
     Script  tratto dal libro "JavaScript and DHTML Cookbook" - Capitolo 8-11
     Pubblicato da O'Reilly & Associates
     Copyright 2003 Danny Goodman
	  Riprodurre questa nota per qualunque riutilizzo del codice.
	*/
	function numeralsOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        alert("Puoi inserire solo numeri!");
        return false;
    }
    return true;
}

function lettersOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 65 || charCode > 90) &&
        (charCode < 97 || charCode > 122)) {
        alert("Puoi inserire solo lettere!");
        return false;
    }
    return true;
}

// conta txtarea

<!-- Dynamic Version by: Nannette Thacker -->
<!-- http://www.shiningstar.net -->
<!-- Original by :  Ronnie T. Moore -->
<!-- Web Site:  The JavaScript Source -->
<!-- Use one function for multiple text areas on a page -->
<!-- Limit the number of characters per textarea -->
<!-- Begin
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}
//  End -->

//popup volante in uso

var navigateur=navigator.appName;var abrege=navigateur.substring(0,2);
var ftx=450;var fty=380;
var fpx=0;var fpy=0;var fpxf=0;var fpxc=0;var tempobe=0;var toclose=0;var decax=0;var decay=0;var deplace=0;

/*function Mouvement() {
	Xpos = event.clientX+document.body.scrollLeft;
	Ypos = event.clientY+document.body.scrollTop;
  if (deplace!=0) {
  	if (deplace==1) {
  		decax=Xpos-fpx;
  		decay=Ypos-fpy;
  		deplace=2;
  	}
 	  fpx=Xpos-decax;
 	  fpy=Ypos-decay;
 	  document.all.fenetre.style.top=fpy;
 	  document.all.fenetre.style.left=fpx;
 	  return false;
  }
}

document.onmousemove = Mouvement;*/

function cliquer(flag) {
	deplace=flag;
	return false;
}

function beWindow(fpx,fpy,ftx,fty,ftitre,fichier) {
var ftxb=130;var hide="hidden";

fchaine=''
+'<div id="fenetre" style="position:absolute;visibility:hidden;z-index:50;top:'+fpy+'px;left:'+fpx+'px;width:'+ftx+'px;height:'+fty+'px;bgcolor:#0000ff;">'
+'<div id="window" style="position:absolute;z-index:50;top:21px;left:0px;width:'+(ftx)+'px;height:'+(fty)+'px;">'
+'<div id="hg" style="position:absolute;z-index:50;top:0px;left:0px;width:6px;height:6px;"><img src="img/images/hg.gif" width="6" height="6"></div>'
+'<div id="hd" style="position:absolute;z-index:50;top:0px;left:'+(ftx-6)+'px;width:6px;height:6px;"><img src="img/images/hd.gif" width="6" height="6"></div>'
+'<div id="bg" style="position:absolute;z-index:50;top:'+(fty-6)+'px;left:0px;width:6px;height:6px;"><img src="img/images/bg.gif" width="6" height="6"></div>'
+'<div id="bd" style="position:absolute;z-index:50;top:'+(fty-6)+'px;left:'+(ftx-6)+'px;width:6px;height:6px;"><img src="img/images/bd.gif" width="6" height="6"></div>'
+'<div id="h" style="position:absolute;z-index:50;top:0px;left:6px;width:1px;height:6px;"><img src="img/images/h.gif" width="'+(ftx-10)+'" height="6"></div>'
+'<div id="b" style="position:absolute;z-index:50;top:'+(fty-6)+'px;left:6px;width:1px;height:6px;"><img src="img/images/b.gif" width="'+(ftx-10)+'" height="6"></div>'
+'<div id="g" style="position:absolute;z-index:50;top:6px;left:0px;width:6px;height:1px;"><img src="img/images/g.gif" width="6" height="'+(fty-10)+'"></div>'
+'<div id="d" style="position:absolute;z-index:50;top:6px;left:'+(ftx-6)+'px;width:6px;height:1px;"><img src="img/images/d.gif" width="6" height="'+(fty-10)+'"></div>'
+'</div>'
+'<div id="titre" style="position:absolute;z-index:50;top:1px;left:0px;width:'+(ftx)+'px;height:21px;" onmousedown="return cliquer(1);" onmouseup="return cliquer(0);">'
+'<table CELLPADDING=0 CELLSPACING=0 border=0 width="'+(ftxb)+'" height="21"><tr><td background="img/images/tm.gif"><FONT FACE="verdana" SIZE=1><B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+ftitre+'</B></FONT></td></tr></table>'
+'<div style="position:absolute;z-index:50;top:0px;left:0px;"><a href="#" onclick="javascript:return closebe();"><IMG src="img/images/tg.gif" BORDER=0 WIDTH=21 HEIGHT=21></A></div>'
+'<div style="position:absolute;z-index:50;top:0px;left:'+(ftxb-4)+'px;"><IMG src="img/images/td.gif" BORDER=0 WIDTH=4 HEIGHT=21></div>'
+'</div>'
+'<div id="interieur" style="position:absolute;z-index:50;top:27px;left:6px;width:'+(ftx-12)+'px;height:'+(fty-12)+'px;">'
+'<iframe name="inbeos" TOP=0 LEFT=0 WIDTH='+(ftx-12)+' HEIGHT='+(fty-12)+' border=0 FRAMEBORDER=0 scrolling=AUTO src="'+fichier+'"></iframe>'
+'</DIV>'
+'</div>'
+'</div>'
document.write(fchaine);
}
function slidebe() {
	if (toclose!=3) {
    fpx+=fpxc;
    if ((fpx>fpxf) && (toclose==0)) {fpx=fpxf;fpxc=0;toclose=3;}
    if (toclose==1) {fpxc=fpxc-20;}
    document.all.fenetre.style.left=fpx;
    if (fpx<-700) {
      fpxc=0;fpx=700;toclose=3;
      inbeos.location.href="attesa.htm";
      document.all.fenetre.style.visibility="hidden";
    }
  }
  tempobe=setTimeout('slidebe();',5);
}
function apercu(fichier) {
if (abrege=="Mi"){
self.clearTimeout();self.clearInterval();
fpy=document.body.scrollTop+(document.body.clientHeight/2)-200;
document.all.fenetre.style.top=fpy;
document.all.fenetre.style.left=-700;fpx=-700;fpxf=(document.body.clientWidth/2)-200;fpxc=100;toclose=0;
document.all.fenetre.style.visibility="visible";
inbeos.location.href=fichier;
}
else {myWindow=open(fichier, "newWindow", "width=600,height=300,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");}
return false;
}
function closebe() {
fpxc=80;toclose=1;
return false;
}
function CreerFenetreBe() {
  if (abrege=="Mi"){beWindow(0,0,600,300,"&nbsp;&nbsp;VivaTorino","attesa.htm");slidebe();}
}

//GALLERY
function apri_foto(album)
{
    var altezza = (window.screen.height/2)-350;
    var larghezza = (window.screen.width/2)-350;
    window.open('http://www.vivatorino.it/popgallery/foto.php?album='+album,'Foto','width=700,height=700,left='+ larghezza +',top='+ altezza +'');
}
//CAPTPOPUP
function mediacenter(str) {
 var mcwnd = window.open(str,"MediaCenter","statusbar=0,width=600,height=480,top=10,left=10");
 mcwnd.focus();
}

//RAFFAPOPUP PAGINA INIZIALE
function locali(str) {
 var mcwnd = window.open(str,"locali","statusbar=0,width=800,height=480,top=10,left=10");
 mcwnd.focus();
}

//SILVANO POP UP
function PopupCentrata() {
   var w = 600;
   var h = 250;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
      window.open("width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
 }
