// FUNZIONI COMUNI (JavaScript)

// http://web.tiscali.it/fabioracco.simpson
// Author: Fabio Racco


// INIZIALIZZAZIONE
// anti-Tiscali Banner

var bannerHeight = 100;
var NObannerHeight = 0;

function bannerize()
{
   if (window != window.top)
   { if (top.document.getElementsByTagName('frameset').item(0).rows == (NObannerHeight + ',*,0'))
       top.document.getElementsByTagName('frameset').item(0).rows = bannerHeight + ',*,0';
       else top.document.getElementsByTagName('frameset').item(0).rows = NObannerHeight + ',*,0'; }
}

function bannerize_main()
{
   if (window.parent != window.top)
   { if (top.document.getElementsByTagName('frameset').item(0).rows == (NObannerHeight + ',*,0'))
       top.document.getElementsByTagName('frameset').item(0).rows = bannerHeight + ',*,0';
       else top.document.getElementsByTagName('frameset').item(0).rows = NObannerHeight + ',*,0'; }
}

function nobanner()
{
   if (window != window.top)
     top.document.getElementsByTagName('frameset').item(0).rows = NObannerHeight + ',*,0';
}

function init_popup()
{
   if (window != window.top)
   { top.document.getElementsByTagName('frameset').item(0).rows = NObannerHeight + ',*,0';
     if (!document.body.scroll) document.body.scroll = 'no'; }
}


// RIDEFINIZIONE
// anti-Tiscali Banner

function relink() {}

function rescan()
{
// for (var i=0;i<6;i++)
// { setTimeout("relink()", 1000); }
// if (window == window.top)
// { top.document.getElementsByTagName('frameset').item(0).rows='100,*,0'; }
}

function refresh()
{
   top.frames[0].location='/banner-tiscali/banner.html';
   top.frames[top.frames.length-1].location='/banner-tiscali/stats.html?userpage_fabioracco.simpson';
   chiamato = 1;
}



// SOTTOFINESTRA (popUp)

var Wnd = null;

function openwindow(url,windowName,width,height,options)
{
   height = height + NObannerHeight;
   options = "menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,top=10,left=10" + ",width=" + width + ",height=" + height + options;
   Wnd = window.open('about:blank',windowName,options+',width=100,height=100,top=10000,left=10000');
   Wnd.close();
   Wnd = null;
   Wnd = window.open(url,windowName,options);
   if (!Wnd.focused) Wnd.focus();
}



// RIDIMENSIONAMENTO (popUp)

function resizewindow(widthTo,heightTo,theWindow)
{ 
   if (!theWindow) theWindow = window.top;
   if ((browser_name == "Netscape") && (browser_version >= 3.0))
   {
     if ((theWindow.innerWidth != widthTo) || (theWindow.innerHeight != (heightTo + NObannerHeight)))
     { theWindow.innerWidth = widthTo;
       theWindow.innerHeight = (heightTo + NObannerHeight); }  
   }
   else if ((browser_name == "Microsoft Internet Explorer") && (browser_version >= 4.0))
   {
     if ((theWindow.document.body.clientWidth != widthTo) || (theWindow.document.body.clientHeight != (heightTo + NObannerHeight)))
     { theWindow.resizeTo(widthTo, heightTo + NObannerHeight);
       widthTo = widthTo + (widthTo - theWindow.document.body.clientWidth);
       heightTo = heightTo + (heightTo + NObannerHeight - theWindow.document.body.clientHeight);
       theWindow.resizeTo(widthTo, heightTo + NObannerHeight); }  
   }
}



// RIPOSIZIONAMENTO (popUp)

function movewindow(leftTo,topTo,theWindow)
{ 
   if (!theWindow) theWindow = window.top;
   theWindow.moveTo(leftTo,topTo);
}



// SOTTOFINESTRA IMMAGINE (popUp)

var imgWnd = null;

function imagewindow(imgSrc,imgTitle)
{
   var theImage = new Image();
       theImage.src = imgSrc;

   imgWnd = window.open(imgSrc,'imgwindow','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,top=5,left=5,width=100,height=100');
   imgWnd.document.body.leftMargin = 0;
   imgWnd.document.body.topMargin = 0;
   imgWnd.onLoad = resizewindow(theImage.width,theImage.height,imgWnd);
   if (imgTitle) imgWnd.document.title = imgTitle;
   if (!imgWnd.focused) imgWnd.focus();
}



// SOTTOFINESTRA CARD (popUp)

var crdWnd = null;

function cardwindow(cardSrc)
{
   cardSrc = "html/Card.htm?=" + cardSrc + "&";
   crdWnd = window.open(cardSrc,'cardwindow','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,top=5,left=5,width=385,height=550');
   if (!crdWnd.focused) crdWnd.focus();
}



// SELEZIONA FRAME (popUp)
// variabili da definire:
// var window_url = "frameset.htm";
// var window_name = "framewindow";
// var window_options = "menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,top=10,left=10,width=...,height=...";

function selectframe(frameName,frameSrc)
{
   if (Wnd && !Wnd.closed && (Wnd.frames.length>1))
   { if (Wnd.frames[1].frames[frameName])
       { Wnd.frames[1].frames[frameName].location = frameSrc; }
     else if (Wnd.frames[frameName])
       { Wnd.frames[frameName].location = frameSrc; } }
   else Wnd = window.open(window_url + '?=../' + frameSrc,window_name,window_options);
   if (!Wnd.focused) Wnd.focus();
}



// RE-INDIRIZZAMENTO FRAME

var urlString = location.search.substring(2);

function redirect(theFrame)
{
   if ((urlString!="") && (theFrame!=""))
     theFrame.location = urlString;
}



// FINESTRA PRINCIPALE

var sndWnd = null;

function mainwindow(url)
{
   if (window != window.top) sndWnd = window.top;
     else sndWnd = window;
   if (sndWnd.opener && !sndWnd.opener.closed)
     sndWnd.opener.location = url;
     else sndWnd.opener = window.open(url,'','');
   if (!sndWnd.opener.focused) sndWnd.opener.focus();
}



// FINESTRA SECONDARIA (focalizzazione)

function focuswindow()
{
   if (!window.focused) window.focus();
}



// VISUALIZZAZIONE TESTO

function text_viewer(idName)
{
   if ((document.all) && (eval("document.all." + idName)))
     if (eval("document.all." + idName + ".style.display") == 'none')
       eval("document.all." + idName + ".style.display = 'block'");
       else eval("document.all." + idName + ".style.display = 'none'");
}



// AVVISO NEWS ANTEPRIMA

function anteprime(url,width,height,options)
{
   if (confirm("Attenzione: si sta per visualizzare un'anteprima di un episodio non ancorra trasmesso in Italia. Continuare?"))
     openwindow(url,'newindow',width,height,options);
}



// SELEZIONE IMMAGINI
// variabili da definire (immagini):
// imageName = new Image(xxx,yyy);
// imageName.src = "nomefile.gif";
// imageNamex = new Image(,);
// imageNamex.src = "nomefile.gif";
// imageName0 = new Image(,);
// imageName0.src = "nomefile.gif";
// imageName1 = new Image(,);
// imageName1.src = "nomefile.gif";

var testVer = 0;
var browser_name = navigator.appName;
var browser_version = parseFloat(navigator.appVersion);

   if ((browser_name == "Netscape") && (browser_version >= 3.0))
     { testVer = 1; }
   else if ((browser_name == "Microsoft Internet Explorer") && (browser_version >= 4.0))
     { testVer = 1; }

function Change(imgName,imgNew)
{
   if (testVer == 1)
     document.images[imgName].src = eval(imgNew + ".src");
     document.images[imgName].width = eval(imgNew + ".width");
     document.images[imgName].height = eval(imgNew + ".height");
}

function Select(imgName)
{
   if (testVer == 1)
     document.images[imgName].src = eval(imgName + "x.src");
}

function Restore(imgName)
{
   if (testVer == 1)
     document.images[imgName].src = eval(imgName + "0.src");
}

function Switch(imgName)
{
   if (testVer == 1)
     if (document.images[imgName].src == eval(imgName + "x.src"))
       Restore(imgName);
       else Select(imgName);
}

function SwitchMore(imgName,imgNum)
{
   if (testVer == 1)
     for (i=0;i<imgNum;i++)
     if (document.images[imgName].src == eval(imgName + i + ".src"))
     { document.images[imgName].src = eval(imgName + (i+1) % imgNum + ".src");
       return; }
}



// RIPRODUZIONE SUONO
// campi da definire (in HEAD):
// <bgsound id="music" src="#" loop="1" autostart="true">

function playSound(srcSound)
{
   if ((document.all) && (document.all.music))
     document.all.music.src = srcSound;
}



// INDIRIZZO e-MAIL (anti-Spam)
// Original Code by:  John  Solis (john@johnsolis.com)
// This script and many more are available free online at
// The JavaScript Source!  http://javascript.internet.com

var mail_user = "fabioracco.simpson";
var mail_domain = "tiscali.it";
var mail_recipient = mail_user + "@" + mail_domain;

function myMail(options)
{
   if (options) options = "mailto:" + mail_recipient + options;
   else options = "mailto:" + mail_recipient;
   document.write(mail_recipient.link(options));
}



// SELEZIONE CASUALE ("STAR")

function randomStar()
{
   listStar = new Array("XFiles", "Barrymore", "Basingers", "Borgnine", "Brooks",
              "Brown", "Devito", "Elton", "Gere", "Gibson", "Pierce", "Hamill",
              "Hartman", "Howard", "Jones", "Mcartney", "Forkrusty", "Newhart",
              "Nimoy", "Obrien", "Pfeiffer", "Rockroll", "Britney", "Ringo",
              "Streep", "Turner", "West");

   location = listStar[rand(listStar.length)-1] + '.htm';
}



// SELEZIONE CASUALE ("GIOCHI INTERATTIVI")

function randomGame()
{
   listGame = new Array("tris", "memory", "puzzle", "hangman");

   location = listGame[rand(listGame.length)-1] + '.htm';
}



// GENERATORE NUMERI CASUALI
// The Central Randomizer v.1.3 (C) 1997
// by Paul Houle (houle@msc.cornell.edu)
// This script and many more are available free online at
// The JavaScript Source!  http://javascript.internet.com

rnd.today = new Date();
rnd.seed = rnd.today.getTime();

function rnd()
{ rnd.seed = (rnd.seed*9301+49297) % 233280;
  return rnd.seed/(233280.0); }

function rand(number)
{ return Math.ceil(rnd()*number); }



// GESTIONE DEL MOUSE
// variabili da definire e operazioni preliminari:
//   var yyns4 = window.Event?true:false;
//   var yy_ml = 0;
//   var yy_mt = 0;
//   if (yyns4) document.captureEvents(Event.MOUSEMOVE);
//   document.onmousemove = YY_Mousetrace;
//   yy_tracescript = '';

function YY_Mousetrace(evnt)
{
   if (yyns4)
   { if (evnt.pageX)
     { yy_ml=evnt.pageX;
       yy_mt=evnt.pageY; } }
   else
   { yy_ml=(event.clientX + document.body.scrollLeft);
     yy_mt=(event.clientY + document.body.scrollTop); }
   if (yy_tracescript) eval(yy_tracescript);
}

function YY_Layerfx(yyleft,yytop,yyfnx,yyfny,yydiv,yybilder,yyloop,yyto,yycnt,yystep)
{
   if ((document.layers)||(document.all))
   {  
     eval("myfunc=yyfnx.replace(/x/gi, yycnt)");
     with (Math) { yynextx = eval(myfunc); }
     eval("myfunc=yyfny.replace(/x/gi, yycnt)");
     with (Math) { yynexty = eval(myfunc); }
     yycnt = (yyloop && yycnt>=yystep*yybilder)?0:yycnt+yystep;
     if (document.layers)
     { eval(yydiv + ".top=" + (yynexty+yytop));
       eval(yydiv + ".left=" + (yynextx+yyleft)); }
     if (document.all)
     { eval("yydiv=yydiv.replace(/.layers/gi, '.all')");
       eval(yydiv + ".style.pixelTop=" + (yynexty+yytop));
       eval(yydiv + ".style.pixelLeft=" + (yynextx+yyleft)); }
     argStr = 'YY_Layerfx(' + yyleft + ',' + yytop + ',"' + yyfnx + '","' + yyfny + '","' + yydiv + '",' + yybilder + ',' + yyloop + ',' + yyto + ',' + yycnt + ',' + yystep + ')';
     if (yycnt<=yystep*yybilder)
     { eval(yydiv+".yyto=setTimeout(argStr,yyto)"); } }
}


// FUNZIONI COMUNI - Fine

