var scrmsg = "    Benvenuto nel sito della Proloco di Buccino    ";
var scrspacer = " ";
var scrpos = 0;
function ScrollMessage()
{
window.status = scrmsg.substring(scrpos, scrmsg.length) + scrspacer + scrmsg.substring(0,scrpos);
scrpos++;
if (scrpos > scrmsg.length) scrpos = 0;
window.setTimeout("ScrollMessage()", 150);
 }

ScrollMessage();

var msg="    Benvenuto nel sito della Proloco di Buccino    ";

var speed=200;

function ScrollTitle() {
document.title=msg;
msg=msg.substring(1,msg.length)+msg.charAt(0);
setTimeout("ScrollTitle()",speed);
 }
ScrollTitle();
/*  funzioni di controllo */
function func(num){
window.open('new.php?id='+num+'','news','width=370,height=400,toolbar=no,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=no');
}

function cambia(){
document.form.submit();
}

function informativa(){
window.open('informativa.php','informativa','width=370,height=240,toolbar=no,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=no');
}

function rievocazione(){
window.open('rievocazione.php','rievocazione','width=900,height=496,toolbar=no,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=no');
}

function invia(){
var testo=document.guestform.area.value;
if(testo == ''){
alert("riempire la textarea");
return false;
}
else{
document.guestform.submit();
}
}

function invia1(){
var titolo=document.news.titolo.value;
var testo=document.news.testo.value;
if(titolo == '' || testo == ''){
alert("riempire titolo e testo");
return false;
}
else{
document.news.submit();
}
}

function invia2(){
var oggetto=document.comunicazioni.oggetto.value;
var testo=document.comunicazioni.testo.value;
if(oggetto == '' || testo == ''){
alert("riempire oggetto e testo");
return false;
}
else{
document.comunicazioni.submit();
}
}

function rimuovi1(){
if(confirm("confermi l'eliminazione?")){
document.rim1.submit();
}
else{
return false;
}
}

function rimuovi2(){
if(confirm("confermi l'eliminazione?")){
document.rim2.submit();
}
else{
return false;
}
}

function rimuovi3(){
if(confirm("confermi l'eliminazione?")){
document.rim3.submit();
}
else{
return false;
}
}

function controlla() {
  var flag=true;
  var f = document.forms[0];
  var n=f.length;
  for(var i=0; i<n; i++){
  if(f.elements[i].value == ''){
  flag=false;
  break;
  }
  }
  if(flag){
  var email=f.elements[6].value;
  if(check(email)){
  document.dati.submit();
  }
  else{
  alert("L'indirizzo di posta elettronica\n"+"non ha un formato corretto");
  return false;
  }
  }
  else{
  alert("tutti i campi devono\n"+"essere riempiti");
  return false;
  }
}

function check(email) {
var caratteriNonValidi = " /:,;"
if (email == "") return false;
for (var i=0; i<caratteriNonValidi.length; i++) {
var noCar = caratteriNonValidi.charAt(i)
if (email.indexOf(noCar,0) > -1) return false;
}
//cerchiamo @
atPos = email.indexOf("@",1)
if (atPos == -1) return false;
//ci deve essere solo un simbolo @
if (email.indexOf("@",atPos+1) != -1) return false;
//cerchiamo il .
dotPos = email.indexOf(".",atPos)
if (dotPos == -1) return false;
//ci deve essere solo un punto
if (email.indexOf(".",dotPos+1) != -1) return false;
//ci devono essere da 2 a 3 caratteri dopo l'ultimo .
if (email.length - dotPos>4 || email.length - dotPos<3)
return false;
return true; 
}

function soloNumeri(campo, event) {
var tasto,carattereTasto;
if (window.event) //Modello ad eventi IE
tasto = window.event.keyCode;
else if (event) //Modello ad eventi NN
tasto = event.which;
else return true;
carattereTasto = String.fromCharCode(tasto);
// verifica tasti particolari tipo canc, invio, ...
if ((tasto==null) || (tasto==0) || (tasto==8) ||
(tasto==9) || (tasto==13) || (tasto==27) )
return true;
else if ((("0123456789").indexOf(carattereTasto) > -1))
{
window.status = ""; return true;
}
else
{
window.status = "Il campo accetta solo numeri";
return false; }
}
/* start img fader */
function slideshow(){
                 max_number_img = 22;
                 i = 3;
                 dispari = true;
                 timer_cambio_img = setInterval('rullo()', 5000);
            }
            function rullo(){
                browser = null;
                if (window.ActiveXObject) {
                    if (navigator.userAgent.toLowerCase().indexOf("msie 5") != -1) {
                        browser = "ie";
                    } else {
                        browser = "ie";
                    }
                }
                if (!browser && typeof(XMLHttpRequest) != 'undefined') {
                      browser = "ch";
                }
				
				src = "foto_" + i;
                
                timer_fade = setInterval('fade()', 100)
            }
            function fade(){
            if(browser == "ie"){
            if(dispari){
                        var valore1 = document.getElementById("box_01").filters.alpha.opacity;
                        var valore2 = document.getElementById("box_02").filters.alpha.opacity;
                        var incremento = 5;
                            if (valore1 < 100){
                                valore1 = valore1 + incremento;
                                document.getElementById("box_01").filters.alpha.opacity = valore1;
                                valore2 = valore2 - incremento;
                                document.getElementById("box_02").filters.alpha.opacity = valore2;
                            } else {
                                    stop_timer(timer_fade);
                                    dispari = false;
                                    document.getElementById("box_02").src = "images/fader/"+ src + ".jpg";
                                    if(i<max_number_img){
                                      i++;
                                    } else {
                                        i = 1;
                                    }

                            }
            } else {
                        var valore1 = document.getElementById("box_02").filters.alpha.opacity;
                        var valore2 = document.getElementById("box_01").filters.alpha.opacity;
                        var incremento = 5;
                            if (valore1 < 100){
                                valore1 = valore1 + incremento;
                                    document.getElementById("box_02").filters.alpha.opacity = valore1;
                                valore2 = valore2 - incremento;
                                    document.getElementById("box_01").filters.alpha.opacity = valore2;
                            } else {
                                    stop_timer(timer_fade);
                                    dispari = true;
                                    document.getElementById("box_01").src = "images/fader/"+ src + ".jpg";
                                    if(i<max_number_img){
                                      i++;
                                    } else {
                                        i = 1;
                                    }
                            }
            }
        } else {
            if(dispari){
                        var valore1 = document.getElementById("box_01").style.opacity;
                        var valore2 = document.getElementById("box_02").style.opacity;
                        var incremento = 0.1;
                            if (valore1 < 1){
                                valore1 = eval(valore1) + eval(incremento);
                                    document.getElementById("box_01").style.opacity = valore1;
                                valore2 = eval(valore2) - eval(incremento);
                                    document.getElementById("box_02").style.opacity = valore2;
                            } else {
                                    stop_timer(timer_fade);
                                    dispari = false;
                                    document.getElementById("box_02").src = "images/fader/"+ src + ".jpg";
                                    if(i<max_number_img){
                                      i++;
                                    } else {
                                        i = 1;
                                    }

                            }
            } else {
                        var valore1 = document.getElementById("box_02").style.opacity;
                        var valore2 = document.getElementById("box_01").style.opacity;
                        var incremento = 0.1;
                            if (valore1 < 1){
                                valore1 = eval(valore1) + eval(incremento);
                                    document.getElementById("box_02").style.opacity = valore1;
                                valore2 = eval(valore2) - eval(incremento);
                                    document.getElementById("box_01").style.opacity = valore2;
                            } else {
                                    stop_timer(timer_fade);
                                    dispari = true;
                                    document.getElementById("box_01").src = "images/fader/"+ src + ".jpg";
                                    if( i < max_number_img ){
                                      i++;
                                    } else {
                                        i = 1;
                                    }
                            }
            }
        }
    }
    function stop_timer(id){
        clearInterval(id);
    }
/* end img fader */	

