// TOP
// Numero di banner che sono contemporaneamente in rotazione
var nBanner = 2;
// Secondi tra la visualizzazione di un banner ed il successivo
var nInterval = 15;
// n rappresenta il numero del banner da cui iniziare la visualizzazione
var n;

function initBanner(){
  // n rappresenta il numero del banner da visualizzare
  n = (Math.ceil(Math.random(90) * nBanner));        
  eval("document.getElementById('banner0" + n + "').style.display = 'block';");
  if (nBanner > 1){
    setTimeout('rotationBanner()',nInterval * 1000);
  }
}

function rotationBanner(){   
if (n == nBanner)
  n = 1;
else
  n++;
for (i = 1; i <= nBanner; i++){
  if (i == n){        
	eval("document.getElementById('banner0" + i + "').style.display = 'block';");
  }
  else{                
	eval("document.getElementById('banner0" + i + "').style.display = 'none';");
  }
}
setTimeout('rotationBanner()',nInterval * 1000);
}
//FINE TOP

//LEFT
// Risoluzione verticate monitor
var vSize = screen.height;
function OverMenu(id){
	document.getElementById(id).style.backgroundColor = "#2f7100";
}
function OutMenu(id){
	document.getElementById(id).style.backgroundColor = "transparent";
}
function SwitchMenu(obj){
	var el = document.getElementById(obj);
	if(el.style.display == "block"){
		el.style.display = "none";
	}else{
		el.style.display = "block";
	}	
}
//FINE LEFT

//CONTROLLA VINCITE
var num_sel=0;
function selectNum(obj){	
	if (document.getElementById(obj.id).className=="numeri_sel_checkwin"){
		if (num_sel>0){
			document.getElementById(obj.id).className="numeri_unsel_checkwin"
			num_sel--;
		}
	}else{
		if (num_sel<10){
			document.getElementById(obj.id).className="numeri_sel_checkwin"
			num_sel++;
		}
	}
}
function showNum(elm, e){	
	if(!e) e=window.event;
	var vDoc=(document.documentElement && document.documentElement.scrollTop)?document.documentElement:document.body;
	document.getElementById("selectNumDiv").style.left=(e.pageX)?e.pageX:e.clientX+vDoc.scrollLeft;
	document.getElementById("selectNumDiv").style.top=(e.pageY)?e.pageY:e.clientY+vDoc.scrollTop;	
	
	if (document.getElementById("selectNumDiv").style.display=="none")
		document.getElementById("selectNumDiv").style.display="block"
	else
		document.getElementById("selectNumDiv").style.display="none"		
}
function selNum(num){
	document.getElementById("selectNumDiv").style.display="none"
	document.getElementById("n11").value=num
	document.getElementById("n21_td").innerHTML=num
}
var checked=0
function changeNum(val){
	document.getElementById("settypeDiv0").src="/images/setnum0_dis.png"
	document.getElementById("settypeDiv1").src="/images/setnum0_dis.png"
	document.getElementById("settypeDiv2").src="/images/setnum0_dis.png"
	document.getElementById("settypeDiv"+val).src="/images/setnum0.png"	
	checked = val
}
//FINE CONTROLLA VINCITE

//MAIN
//controlla formato
function checkFormat(obj){
	if (obj.value.search(/\D/)!= -1){
		alert("Inserire solo valori numerici!")
		obj.value = obj.value.substring(0,obj.value.length-1)
	}
}
//controlla i numeri ed invia
function checkNum(action){
	if (num_sel==10){
		j=1
		for (i=1;i<=20;i++){
			if (document.getElementById("n"+i+"_td").className=="numeri_sel_checkwin"){
				document.getElementById("n"+j).value=i;
				j++;
			}
		}		
	}else{
		if (num_sel==9)
			alert("Devi selezionare ancora 1 numero")
		else
			alert("Devi selezionare ancora "+(10-num_sel)+" numeri")
		return false;
	}	
	if (action!="")			
		document.formcheck.action=action	
	document.formcheck.submit();
}
//controlla il form di ricerca ed invia
function checkForm(){
	if (num_sel==10){
		j=1
		for (i=1;i<=20;i++){
			if (document.getElementById("n"+i+"_td").className=="numeri_sel_checkwin"){
				document.getElementById("n"+j).value=i;
				j++;
			}
		}		
	}else{
		if (num_sel==9)
			alert("Devi selezionare ancora 1 numero")
		else
			alert("Devi selezionare ancora "+(10-num_sel)+" numeri")
		return false;
	}	
	if (document.getElementById("n11").value=="" || document.getElementById("n11").value==0 || document.getElementById("n11").value>20){
		alert("Il numerone deve essere compreso tra 1 e 20")
		return false;
	}
	
	//controllo per numero e anno	
	if(checked==0){	
		if (document.getElementById("concorso").value==""  || document.getElementById("concorso").value == 0){
			alert("Il concorso deve essere un numero maggiore di uno");
			return false;
		}	
		//azzero data e ora		
		document.getElementById("data_concorso").value=""
		document.getElementById("ora_concorso").value=""
	}
	//controllo per data e ora
	if(checked==1){		
		data_attuale = new Date()
		anno_attuale = data_attuale.getFullYear()	
		data = document.formcheck.data_concorso.value
		if (data.length<10){
			alert("La data deve essere nel formato GG/MM/AAAA");
			return false;
		}
		dd = data.substring(0,2)
		mm = data.substring(3,5)
		yy = data.substring(6,10)	
		if (dd.search(/\D/)!= -1 || dd>31 || dd<1){
			alert("Il giorno deve essere compreso tra 1 e 31");
			return false;
		}
		if (mm.search(/\D/)!= -1 || mm>12 || mm<1){
			alert("Il mese deve essere compreso tra 1 e 12");
			return false;
		}
		if (yy.search(/\D/)!= -1 || yy<2009 || yy>anno_attuale){
			alert("L'anno deve essere compreso tra 2009 e " + anno_attuale);
			return false;
		}			
	}
	if(checked==2){	
		document.formcheck.action="/page/risultato_schedina_winforlife_ultimi_concorsi.asp"
	}
	document.formcheck.submit();
}
function CercaPerData(){	
	data_attuale = new Date()
	anno_attuale = data_attuale.getFullYear()	
	data = document.form1.data.value
	if (data.length<10){
		alert("La data deve essere nel formato GG/MM/AAAA");
		return false;
	}	
	dd = data.substring(0,2)
	mm = data.substring(3,5)
	yy = data.substring(6,10)	
	if (dd.search(/\D/)!= -1 || dd>31 || dd<1){
		alert("Il giorno deve essere compreso tra 1 e 31");
		return false;
	}
	if (mm.search(/\D/)!= -1 || mm>12 || mm<1){
		alert("Il mese deve essere compreso tra 1 e 12");
		return false;
	}
	if (yy.search(/\D/)!= -1 || yy<2009 || yy>anno_attuale){
		alert("L'anno deve essere compreso tra 2009 e " + anno_attuale);
		return false;
	}	
	window.open("/page/concorsi_winforlife.asp?data=" + data + "&search=s","_self");
}
function CercaPerConcorso(){	
	data = new Date()
	anno = data.getFullYear()
	if (document.form2.concorso.value == "" || document.form2.concorso.value == 0){
		alert("Il concorso deve essere un numero maggiore di uno");
		return false;
	}	
	if (document.form2.anno_concorso.value == "" || document.form2.anno_concorso.value<2009 || document.form2.anno_concorso.value>anno){
		alert("L'anno deve essere un anno compreso tra il 2009 e il " + anno);
		return false;
	}		
	concorso = document.form2.concorso.value
	anno = document.form2.anno_concorso.value
	window.open("../Page/colonna_vincente_winforlife.asp?concorso=" + concorso + "&anno_concorso=" + anno + "&search=s","_self");
}
//FINE MAIN

// JavaScript Document
function num(a){
	if ((a=="1")||(a=="2")||(a=="3")||(a=="4")||(a=="5")||(a=="6")||(a=="7")||(a=="8")||(a=="9")||(a=="0")){return true}	
	else{return false}
}
function check(){
	var msg = "";  
  
  // nome
  app = document.formNome.nome.value;
  var b = true;
  for(i=0;i<app.length;i++){				
    var a = app.substring(i,i+1)		
    if (num(a)){b=false}				
  }
  if ((app=="")||(b==false)){msg = "Inserire il proprio nome!";}
    
  if (msg == ""){
    // cognome
    app = document.formNome.cognome.value;
    var b = true;
    for(i=0;i<app.length;i++){				
      var a = app.substring(i,i+1)		
      if (num(a)){b=false}				
    }
    if ((app=="")||(b==false)){msg = "Inserire il proprio cognome!";}
  }
  
  if (msg == ""){
    // giorno
    app = document.formNome.giorno.value;
    var b = true;
    for(i=0;i<app.length;i++){				
      var a = app.substring(i,i+1)		
      if (!num(a)){b=false}				
    }
    if ((app=="")||(app>31)||(b==false)){msg = "Inserire il giorno di nascita!";}	
  }
  
  if (msg == ""){
    // mese
    app = document.formNome.mese.value;
    var b = true;
    for(i=0;i<app.length;i++){				
      var a = app.substring(i,i+1)		
      if (!num(a)){b=false}				
    }
    if ((app=="")||(app>12)||(b==false)){msg = "Inserire il mese di nascita!";}
  }
  
	// anno
  if (msg == ""){
    app = document.formNome.anno.value;
    var b = true;
    for(i=0;i<app.length;i++){				
      var a = app.substring(i,i+1)		
      if (!num(a)){b=false}				
    }
    if ((app=="")||(app.length<4)||(b==false)){msg = "Inserire l'anno di nascita!";}
  }
  
  if (msg == ""){
    // luogo
    app = document.formNome.luogo.value;
    var b = true;
    for(i=0;i<app.length;i++){				
      var a = app.substring(i,i+1)		
      if (num(a)){b=false}				
    }
    if ((app=="")||(b==false)){msg = "Inserire la località di nascita!";}
  }
	
	if (msg ==""){
    document.formNome.submit();
  }
	else{
    alert(msg);
  }
}
/////////////////
function cercaSmorfia(){
	if (document.form1.textFrase.value == ""){alert("Inserisci almeno una parola");}
	else{window.open("../Cerca/RisultatiSmorfia.asp?frase=" + document.form1.textFrase.value,"mainFrame");}
}
function cercaPerConcorso(){
	if (isNaN(document.form2.textConcorso.value) || document.form2.textConcorso.value == ""){alert("Numero Concorso non valido");document.form2.textConcorso.focus();}
	else{
		if (document.form2.selectAnno.value == ""){alert("Anno non valido");document.form2.selectAnno.focus();}
		else{window.open("../Page/colonna.asp?anno=" + document.form2.selectAnno.value + "&concorso=" + document.form2.textConcorso.value,"mainFrame");}
	}		
}
/////////////

// Funzione per determinare se è installato Flash
function flashInstalled() {     
  var v; 
  if (navigator.plugins && navigator.plugins.length > 0) { 
      var type = 'application/x-shockwave-flash'; 
      var mimeTypes = navigator.mimeTypes; 
      if (mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description) { 
          v = mimeTypes[type].enabledPlugin.description.replace(/^.*?([0-9]+)\.([0-9])+.*$/, '$1,$2').split(','); 
      } 
  } 
  else { 
      var flashObj = null; 
      try { flashObj = new ActiveXObject('ShockwaveFlash.ShockwaveFlash'); } catch (ex) { return false; } 
      if (flashObj != null) { 
          var fV; 
          try { fV = flashObj.GetVariable("$version"); } catch (err) { return false; } 
          v = fV.replace(/^.*?([0-9]+,[0-9]+).*$/, '$1').split(','); 
      } 
  } 
  if (v) { 
    return true; 
  } 
  return false; 
} 

var months = ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"]
var days = ["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]
var sett = ["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato"]
	

