var urlBB = 'indexbb.html?pmk=hpswu';
var urlNB = 'index.html?pmk=hpswu';
var defaultUrl = urlNB;
var connectionSpeed = "Connessione:NarrowBand";

/* animazione NEWS */
var n_tot = 3;
var delay = 3000;
var n_cor = 1;
var n_pre = n_tot;

function startnews(){

 	findLayer('art_'+n_pre).style.visibility = "hidden";
 	findLayer('art_'+n_cor).style.visibility = "visible";

	n_pre = n_cor;

	if (n_cor == n_tot) { n_cor = 1; } else { n_cor++; }
	setTimeout("startnews()", delay);
}
/*fine funzioni per animazione NEWS*/

function goSearch(dom, qs){
	if ( qs=='Cerca con Virgilio:' ){
		qs='';
	}
	document.location.href=('http://search.virgilio.it/search/cgi/search.cgi?dom=' + dom + '&f=hp&switch=0&offset=0&hits=10&qs=' + escape(qs));
	return false;
}

function checkScreen(){
	var w = screen.width;
	var h = screen.height;
	var ret = (w>=1024 && h>=768) ? true : false;
	return ret;
}


function genericPop(myUrl,myWinName,myWidth,myHeight,myPars) {
 var winl = (screen.width - myWidth) / 2;
 var wint = (screen.height - myHeight) / 2;
 parameters = myPars + '';
 if (parameters == '') parameters = ',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no';
 gwin=window.open(myUrl,myWinName,'width='+myWidth+',height='+myHeight+',left='+winl+',top='+wint+parameters);
 gwin.focus();
}


function openRAWindow(anchorObject){
	openRAWindowFromFlash(anchorObject);
	return false;
}

function openRAWindowFromFlash(o){
	var features = 'scrollbars=no,resizable=no,status=yes';
	if (screen.width==800 && screen.height==600){
		features = 'scrollbars=yes,resizable=no,status=yes';
	}
	if(o.getAttribute){
		window.open(o.getAttribute('href'),'',features);
	}else{
		window.open(o,'',features);
	}
}

function checkFlashVersion() {
  var reqVer=7;
  var plugin = (navigator.mimeTypes &&
  navigator.mimeTypes["application/x-shockwave-flash"]) ?
  navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
  var isVerOk=false;
  if (plugin) {
      var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	  var flaVer;
      for (var i = 0; i < words.length; i++){
          if (isNaN(parseInt(words[i]))){
              continue;
		  }
          flaVer = words[i];
		  break;
      }
      isVerOk = (flaVer >= reqVer);
  }
  else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)){
      try {
		var instance=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+reqVer);
		isVerOk = true;
	  }
      catch (e){isVerOk=false}
  }
  return isVerOk;
}

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_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_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 findLayer(layerID){
	if(document.getElementById){
		return document.getElementById(layerID);
	}else if(document.all){
		return document.all[layerID];
	}else if(document.layers){
		return document.layers[layerID];
	}
}

function loadBoxMail(){
	findLayer('mail').style.display = 'block';
}

function goToNB(){
	var scade = new Date();
	scade.setTime(scade.getTime() + 30*24*60*60*1000);
	SetCookie("UserChoice", "NB", scade, "/", null, null);

	document.location.href=urlNB;
}

function goToBB(){
	var scade = new Date();
	scade.setTime(scade.getTime() + 30*24*60*60*1000);
	SetCookie("UserChoice", "BB", scade, "/", null, null);

	document.location.href=urlBB;
}

function checkBB(){
	/* da chiamare solamente nella BB */
	var normalized  = GetCookie('Normalized');
	if(  !(normalized && normalized=='once')  ){
		if( !(checkFlashVersion() && checkScreen()) ){
			var mai = new Date();
			mai.setTime(mai.getTime() + 2000*24*60*60*1000);
			SetCookie ('Normalized', 'once', mai, "/", null, null);
			setUserChoiceCookie( 'NarrowBand' );
			document.location.href = urlNB;
		}
	}
}

function goToTab(tab){
	var path = document.location.pathname;
	if (path.indexOf('index')){
		path=path.substring(1, path.lastIndexOf('index')-1);
	}
	if(path=='home'){
		path='aliceoggi';
	}
	var userChoice = GetCookie('UserChoice');
	if (userChoice=='NB'){
		document.location.href='/'+tab;
	}else{
		var url = tab+'/indexbb.html';
		if (tab!=''){
			url = '/' + url;
		}
		document.location.href=url + '?pmkf=' + path;
	}
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function drawCSImageTag( fileLocation, fileSize, imgTagProperties, showImage, elementId) {
  var x = document.getElementById(elementId);
	var start = (new Date()).getTime();
	var loc = fileLocation + '?t=' + escape(start);
  var visible = "hidden";
  var showImage = 'checked' ? visible = "visible" : visible = "hidden";
	var imtest = new Image();
	imtest.src = loc;
	try{
		if(  !(navigator.userAgent.indexOf('Mac')>-1 && navigator.appVersion.indexOf('MSIE')>-1)   ){
			imtest.onload = function compute(){
				computeConnectionSpeed( start, fileSize );
			}
		}else{
			eval('imtest.onload = new function compute(){computeConnectionSpeed( start, fileSize );}');
		}
	}catch(e){
		// per baco IE5: esegue la funzione sull'onload ma lancia comunque un eccezione
	}

	return;
}

function connectionType(speed) {

	SLOW_MODEM = 15;
  //FAST_MODEM = 57;
	FAST_MODEM = 70;
	ISDN_MODEM = 120;
	ADSL_MODEM = 600;

	if (speed) {
		if (speed < FAST_MODEM) {
			return "NarrowBand";
		} else {
			return "BroadBand";
		}
	} else {
		return "NarrowBand";
	}
}

function computeConnectionSpeed( start, fileSize ) {
	var end = (new Date()).getTime();
	speed = (Math.floor((((fileSize * 8) / ((end - start) / 1000)) / 1024) * 10) / 10);
	connectionSpeed = 'Connessione:' + connectionType( speed );
	var mai = new Date();
	mai.setTime(mai.getTime() + 2000*24*60*60*1000);
    var cookie = connectionSpeed + '&start=' + start + '&end=' + end + '&ms=' + (end-start) + '&kbps=' + parseInt(speed) + '&bytes=' + fileSize;
    var img = new Image();
    img.src="/home/images/connspeed-out.jpg?" + cookie + "&rand=" + Math.floor(1000000*Math.random());

	SetCookie ("ConnParam", cookie, mai, "/", null, null);

	setUserChoiceCookie( connectionType(speed) );

}

function startDraw() {
	var x = GetCookie("ConnParam");
	var u = GetCookie("UserChoice");
	if (!x) {
		draw();
	} else {
		if (x && !u){
			setUserChoiceCookie( x );
		}

		connectionSpeed = x;
		var img = new Image();
		img.src = "/home/images/connspeed-in.gif?" + x + "&rand=" + Math.floor(1000000*Math.random());
	}
}

function draw() {
	drawCSImageTag("/home/images/connspeed.bmp", // Image filename
                  5194, // Image size
                  "height=54 width=123", "checked", "connspeed");
}

function setUserChoiceCookie(connSpeed){
	var scade = new Date();
	scade.setTime(scade.getTime() + 30*24*60*60*1000);
	if(connSpeed.indexOf('BroadBand') !=-1 && checkFlashVersion() && checkScreen() ){
		SetCookie("UserChoice", "BB", scade, "/", null, null);
	}else{
		SetCookie("UserChoice", "NB", scade, "/", null, null);
	}
}

function writeFlashObject(movie, qs, width, height){
	document.write(
	   '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"\n'+
	   ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"\n'+
	   ' WIDTH="' + width + '" HEIGHT="' + height + '">\n'+
	   ' <PARAM NAME=movie VALUE="' + movie + '">\n'+
	   ' <PARAM NAME=FlashVars VALUE="'+qs+'">\n'+
	   ' <PARAM NAME=quality VALUE=high>\n'+
	   ' <PARAM NAME=menu VALUE=false>\n'+
	   ' <PARAM name="wmode" VALUE="transparent">\n'+
	   ' <EMBED src="' + movie +'"\n'+
	   '  FlashVars="'+qs+'"\n'+
	   '  wmode="transparent" ' +
	   '  quality=high menu="false" WIDTH="' + width + '" HEIGHT="' + height +
	   '  TYPE="application/x-shockwave-flash"\n'+
	   '  PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>\n'+
	   '</OBJECT>');
}




//Contents for menu 1
var menu1 = new Array()
menu1[0] = '<a href="villa-grillaia.asp">La Villa</a>'
menu1[1] = '<a href="villa-grillaia-disposizioni-interne.asp">Disposizioni interne</a>'
menu1[2] = '<a href="villa-grillaia-prezzi.asp">Prezzi e Condizioni</a>'
menu1[3] = '<a href="/prenotazioni.aspx?v=Grillaia&qid=1&ln=www">Prenotazioni e Disponibilit&agrave;</a>'

var menu2 = new Array()
menu2[0] = '<a href="villa-belvedere.asp">La Villa</a>'
menu2[1] = '<a href="villa-belvedere-disposizioni-interne.asp">Disposizioni interne</a>'
menu2[2] = '<a href="villa-belvedere-prezzi.asp">Prezzi e Condizioni</a>'
menu2[3] = '<a href="/prenotazioni.aspx?v=Belvedere&qid=2&ln=www">Prenotazioni e Disponibilit&agrave;</a>'

var menu3 = new Array()
menu3[0] = '<a href="villa-casanova.asp">La Villa</a>'
menu3[1] = '<a href="villa-casanova-disposizioni-interne.asp">Disposizioni interne</a>'
menu3[2] = '<a href="villa-casanova-prezzi.asp">Prezzi e Condizioni</a>'
menu3[3] = '<a href="/prenotazioni.aspx?v=Casanova&qid=3&ln=www">Prenotazioni e Disponibilit&agrave;</a>'

var menu4 = new Array()
menu4[0] = '<a href="servizi-aggiuntivi.asp">Matrimoni, Ricevimenti...</a>'
menu4[1] = '<a href="tenuta-tartufo.asp">Il Tartufo nella Tenuta</a>'


var menu1b = new Array()
menu1b[0] = '<a href="villa-grillaia.asp">Description</a>'
menu1b[1] = '<a href="villa-grillaia-disposizioni-interne.asp">Inner Disposition</a>'
menu1b[2] = '<a href="villa-grillaia-prezzi.asp">Prices and Conditions</a>'
menu1b[3] = '<a href="prenotazioni.aspx?v=Grillaia&qid=1&ln=en">Reservations and Availability</a>'

var menu2b = new Array()
menu2b[0] = '<a href="villa-belvedere.asp">Description</a>'
menu2b[1] = '<a href="villa-belvedere-disposizioni-interne.asp">Inner Disposition</a>'
menu2b[2] = '<a href="villa-belvedere-prezzi.asp">Prices and Conditions</a>'
menu2b[3] = '<a href="prenotazioni.aspx?v=Belvedere&qid=2&ln=en">Reservations and Availability</a>'

var menu3b = new Array()
menu3b[0] = '<a href="villa-casanova.asp">Description</a>'
menu3b[1] = '<a href="villa-casanova-disposizioni-interne.asp">Inner Disposition</a>'
menu3b[2] = '<a href="villa-casanova-prezzi.asp">Prices and Conditions</a>'
menu3b[3] = '<a href="prenotazioni.aspx?v=Casanova&qid=3&ln=en">Reservations and Availability</a>'

var menu4b = new Array()
menu4b[0] = '<a href="servizi-aggiuntivi.asp">Weddings, Christenings...</a>'
menu4b[1] = '<a href="tenuta-tartufo.asp">The Truffle in Camugliano Estate</a>'


var menu1c = new Array()
menu1c[0] = '<a href="villa-grillaia.asp">Description</a>'
menu1c[1] = '<a href="villa-grillaia-disposizioni-interne.asp">Dispositions Int&eacute;rieur</a>'
menu1c[2] = '<a href="villa-grillaia-prezzi.asp">Prix et Conditions</a>'
menu1c[3] = '<a href="prenotazioni.aspx?v=Grillaia&qid=1&ln=fr">R&eacute;servations et disponibilit&eacute;</a>'

var menu2c = new Array()
menu2c[0] = '<a href="villa-belvedere.asp">Description</a>'
menu2c[1] = '<a href="villa-belvedere-disposizioni-interne.asp">Dispositions Int&eacute;rieur</a>'
menu2c[2] = '<a href="villa-belvedere-prezzi.asp">Prix et Conditions</a>'
menu2c[3] = '<a href="prenotazioni.aspx?v=Belvedere&qid=2&ln=fr">R&eacute;servations et disponibilit&eacute;</a>'

var menu3c = new Array()
menu3c[0] = '<a href="villa-casanova.asp">Description</a>'
menu3c[1] = '<a href="villa-casanova-disposizioni-interne.asp">Dispositions Int&eacute;rieur</a>'
menu3c[2] = '<a href="villa-casanova-prezzi.asp">Prix et Conditions</a>'
menu3c[3] = '<a href="prenotazioni.aspx?v=Casanova&qid=3&ln=fr">R&eacute;servations et disponibilit&eacute;</a>'

var menu4c = new Array()
menu4c[0] = '<a href="servizi-aggiuntivi.asp">Mariages, D&eacute;jeuners...</a>'
menu4c[1] = '<a href="tenuta-tartufo.asp">The Truffle in Camugliano Estate</a>'


var menu1d = new Array()
menu1d[0] = '<a href="villa-grillaia.asp">Beschreibung</a>'
menu1d[1] = '<a href="villa-grillaia-disposizioni-interne.asp">Raumaufteilung</a>'
menu1d[2] = '<a href="villa-grillaia-prezzi.asp">Preise und Bedingungen</a>'
menu1d[3] = '<a href="prenotazioni.aspx?v=Grillaia&qid=1&ln=de">Reservierung</a>'

var menu2d = new Array()
menu2d[0] = '<a href="villa-belvedere.asp">Beschreibung</a>'
menu2d[1] = '<a href="villa-belvedere-disposizioni-interne.asp">Raumaufteilung</a>'
menu2d[2] = '<a href="villa-belvedere-prezzi.asp">Preise und Bedingungen</a>'
menu2d[3] = '<a href="prenotazioni.aspx?v=Belvedere&qid=2&ln=de">Reservierung</a>'

var menu3d = new Array()
menu3d[0] = '<a href="villa-casanova.asp">Beschreibung</a>'
menu3d[1] = '<a href="villa-casanova-disposizioni-interne.asp">Raumaufteilung</a>'
menu3d[2] = '<a href="villa-casanova-prezzi.asp">Preise und Bedingungen</a>'
menu3d[3] = '<a href="prenotazioni.aspx?v=Casanova&qid=3&ln=de">Reservierung</a>'

var menu4d = new Array()
menu4d[0] = '<a href="servizi-aggiuntivi.asp">Mittagessen, Gemeinschaften...</a>'
menu4d[1] = '<a href="tenuta-tartufo.asp">Tr&#252;ffel Suche in Camugliano</a>'
		
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var horizontaloffset=2 //horizontal offset of menu from default location. (0-5 is a good value)

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width: 160px" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

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

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x-obj.offsetWidth < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move menu up?
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either? (position at top of viewable window then)
edgeoffset=dropmenuobj.y
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}

function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+horizontaloffset+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

function setLanguage(ln) {
    //USAGE: javascript:setLanguage("eng") o javascript:setLanguage("deu") javascript:setLanguage("fra")
    var loc = document.location.toString();
    var reg = new RegExp("http://[^/]+/([^/]+)/.*", "gim");
    var m = reg.exec(loc);
    if (m == null) {
        //Siamo in italiano
        var reg = new RegExp("(http://[^/]+)(/.*)", "gim");
        //var m = re.exec(document.demoMatch.subject.value);
        var curHost = loc.replace(reg, "$1");
        var curPg = loc.replace(reg, "$2");
        var newLoc = curHost + "/" + ln + curPg;
        window.open(newLoc, "_self"); //Vado in italiano
    }
    else {
        var curLn = loc.replace(reg, "$1");
        if (curLn == ln) {
            //nulla
            //alert("UGUALE")
        }
        else {
            //alert("diverso " + curLn + " " + ln);
            if (ln != "")
                window.open(loc.replace(curLn + "/", ln + "/"), "_self"); //Vado in italiano
            else
                window.open(loc.replace(curLn + "/", ""), "_self"); //Vado in altra lingua
        }
    }
}

