// Newsky Group (c) 2007 - Tutti i diritti riservati
// Ultima revisione: 12/11/2006

if ( document.location.search.length > 0 )
{ alert("Si è verificato un errore. :-(") ; location.replace("rapido.htm") }

function initialize()
{
document.modulo.OK.disabled = document.modulo.name1.disabled = document.modulo.name2.disabled = false
score = Math.ceil(new Date().getMilliseconds() % 250)
if ( IE )
{ drawHeartIE(0,4)
window.setTimeout("document.getElementById('h0').outerHTML = \"<img id='h0' border='0' src='_/0.gif' width='30' height='30'>\"",160) }
else
{ drawHeartFx(1,0.25)
window.setTimeout("drawHeartFx(0,0)",160) }
}

function precalculate()
{
if ( document.modulo.name1.value == "" || document.modulo.name2.value == "" )
{ alert("Non hai inserito i vostri due nomi!") }
else
{
document.modulo.OK.disabled = document.modulo.name1.disabled = document.modulo.name2.disabled = true
document.getElementById("heartsx").innerHTML = '<img id="h0" border="0" src="_/0.gif" width="30" height="30"><img id="h1" border="0" src="_/0.gif" width="30" height="30"><img id="h2" border="0" src="_/0.gif" width="30" height="30"><img id="h3" border="0" src="_/0.gif" width="30" height="30"><img id="h4" border="0" src="_/0.gif" width="30" height="30"><img id="h5" border="0" src="_/0.gif" width="30" height="30"><img id="h6" border="0" src="_/0.gif" width="30" height="30"><img id="h7" border="0" src="_/0.gif" width="30" height="30"><img id="h8" border="0" src="_/0.gif" width="30" height="30"><img id="h9" border="0" src="_/0.gif" width="30" height="30">'
scrollTo(0,500)
write("Attendere...",0)
write("Connessione psichica in corso...",500)
write("Lettura delle carte in corso...",2500)
write("Osservazione delle congiunzioni stellari e planetarie in corso...",4000)
write("Analisi del pendolino in corso...",7500)
write("Divinazione dei fondi di tè in corso...",8000)
write("Elaborazione dei dati in corso...",9000)
write("Ci siamo quasi...",12500)
window.setTimeout("calculate()",13500)
}
}

function write(text,delay)
{
window.setTimeout('document.getElementById("verdict").innerHTML = "<img src=\'../../_/extra/fs.gif\' align=\'absmiddle\' width=\'5\' height=\'5\'> ' + text + ' <img src=\'../../_/extra/fd.gif\' align=\'absmiddle\' width=\'5\' height=\'5\'>"',delay)
}

function calculate()
{
score = Math.floor(20*(1+Math.atan((score-125)/85)))/4
document.getElementById("verdict").innerHTML = "Cari <b>" + document.modulo.name1.value + "</b> e <b>" + document.modulo.name2.value + "</b>, la vostra è una <span id='levx'>affinità " + levels[Math.floor(score)][0] + "</span>&nbsp;(<a href='javascript:levelsList(" + Math.floor(score) + ")'>a che livello siamo?</a>)"
document.getElementById("commx").innerHTML = levels[Math.floor(score)][1]
drawHearts(score+0.25)
}

function drawHearts(num)
{
if ( IE )
switch ( Math.floor(num) )
{
case 10: window.setTimeout("drawHeartIE(9,4)",1440)
case 9: window.setTimeout("drawHeartIE(8,4)",1280)
case 8: window.setTimeout("drawHeartIE(7,4)",1120)
case 7: window.setTimeout("drawHeartIE(6,4)",960)
case 6: window.setTimeout("drawHeartIE(5,4)",800)
case 5: window.setTimeout("drawHeartIE(4,4)",640)
case 4: window.setTimeout("drawHeartIE(3,4)",480)
case 3: window.setTimeout("drawHeartIE(2,4)",320)
case 2: window.setTimeout("drawHeartIE(1,4)",160)
case 1: drawHeartIE(0,4)
default: window.setTimeout("drawHeartIE(" + Math.floor(num) + "," + (num%1)*4 + ")",160*Math.floor(num))
}
else
{ drawHeartFx(num,0.25) }
}

function drawHeartIE(heart,parts)
{
switch ( parts )
{
case 4: window.setTimeout("document.getElementById('h" + heart + "').outerHTML = \"<img id='h" + heart + "' border='0' src='_/4.gif' width='30' height='30'>\"",120)
case 3: window.setTimeout("document.getElementById('h" + heart + "').outerHTML = \"<img id='h" + heart + "' border='0' src='_/3.gif' width='30' height='30'>\"",80)
case 2: window.setTimeout("document.getElementById('h" + heart + "').outerHTML = \"<img id='h" + heart + "' border='0' src='_/2.gif' width='30' height='30'>\"",40)
case 1: document.getElementById("h"+heart).outerHTML = "<img id='h" + heart + "' border='0' src='_/1.gif' width='30' height='30'>"
default: return
}
}

function drawHeartFx(num,i)
{
if ( i > num ) return
text = ""
for ( j = 0 ; j < Math.floor(i) ; j++ ) { text += "<img border='0' src='_/4.gif' width='30' height='30'>" }
if ( i%1 != 0 ) { text += "<img border='0' src='_/" + (i%1)*4 + ".gif' width='30' height='30'>" }
for ( j = 0 ; j < 10-Math.ceil(i) ; j++ ) { text += "<img border='0' src='_/0.gif' width='30' height='30'>" }
window.setTimeout("document.getElementById('heartsx').innerHTML = text;drawHeartFx("+num+","+(i+0.25)+")",40)
}

function levelsList(level)
{
n = level == null ? "" : "?" + level
window.open("livelli.htm"+n,"livelli","height=275,width=250,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,resizable=no")
}