// JavaScript Document
// realizzato da Caleidos www.caleidos.ws
var hideSlider = true;
<!-- JAVASCRIPT ACCESSIBILE SOSTITUTIVO DEL "TARGET BLANK"
function apri(uri,nome,mnbar,tlbar,lcbar,drbar,stbar,scbar,rsz,wdt,hgt) {
    window.open(uri,nome,"menubar=" + mnbar + ",toolbar=" + tlbar + ",location=" + lcbar + ",directories=" + drbar + ",status=" + stbar + ",scrollbars=" + scbar + ",resizable=" + rsz + ",width=" + wdt + ",height=" + hgt);
}
// -->

function openShadowboxImage(url){
    Shadowbox.open({
	player:     'img',
	content:    url
    });
}

window.onload = function() {
    // e-mail
    if(document.getElementById) {
	var mailiago = document.getElementById('mailiago');
	if(mailiago) {
	    mailiago.innerHTML = '<a href="mailto:iago'+ '@'+'iago'+'.'+'com">iago'+ '@'+'iago'+'.'+'com</a>';
	}
	var mailiago2 = document.getElementById('mailiago2');
	if(mailiago2) {
	    mailiago2.innerHTML = '<a href="mailto:iago'+ '@'+'iago'+'.'+'com">iago'+ '@'+'iago'+'.'+'com</a>';
	}
	
	//$('#slider').hide();
    }

//var next=document.getElementById("next");
//var prev=document.getElementById("prev");
/*
    if(next != null){
	next.style.display = "block";
    }

    if(prev != null){
	prev.style.display = "none";
    }
    */
}

<!-- CAMBIA IMMAGINE SENZA REFRESHARE LA PAGINA -->
function cambiaImmagine(id, immagine){
    var img=document.getElementById(id);
    img.src=immagine;
}

<!-- CAMBIA IMMAGINE CON FADE SENZA REFRESHARE LA PAGINA -->
var sopra = "a";
var myImages=new Array();
var index=0;



function addImage(k, path){
    myImages[k] = path
}

function cambiaImmagineFade(id, indexImg, links, didascalia){
    index = indexImg;
    
    //alert(myImages[0]);
    var linkId = "link_imgBig";
    var linkId2 = "link_imgBig2";
    if(sopra == "a"){
	id = id+"S";
	
    }

    var dida1=document.getElementById("didascalia1");
    dida1.innerHTML = "<span>Clicca per ingrandire</span>"+didascalia;
    var dida2=document.getElementById("didascalia2");
    dida2.innerHTML = "<span>Clicca per ingrandire</span>"+didascalia;
    var img=document.getElementById(id);
    //var next=document.getElementById("next");
    //var prev=document.getElementById("prev");
    img.src=myImages[indexImg];
    if( (index+1) == myImages.length ){
    //next.style.display = "none";
    }else{
    //next.style.display = "block";
    }
    var linkImmagine=document.getElementById(linkId);
    linkImmagine.title = didascalia;
    var linkImmagine2=document.getElementById(linkId2);
    linkImmagine2.title = didascalia;
    
    if( (index) == 0 ){
    //prev.style.display = "none";
    }else{
    //prev.style.display = "block";
    }
    //alert(next.onclick);
    //next.onclick = setNext;
    //alert(next.onclick);
    if(sopra == "a"){
	sopra = "b";
	$("a.a").stop().animate({
	    "opacity": "0"
	}, "slow");
	$("a.b").stop().animate({
	    "opacity": "1"
	}, "slow");
    }else{
	sopra = "a";
	$("a.a").stop().animate({
	    "opacity": "1"
	}, "slow");
	$("a.b").stop().animate({
	    "opacity": "0"
	}, "slow");


    }

    var colS=document.getElementById("link_imgBig");
    colS.href = links;
    var colS=document.getElementById("link_imgBig2");
    colS.href = links;
}

function caricaNext(){
    //alert(myImages.length);
    var indexNext = index;
    if(indexNext< (myImages.length-1) ){
	indexNext = indexNext+1;
    }
    cambiaImmagineFade('imgBig',indexNext);
    return false;
}

function caricaPrev(){
    //alert(myImages.length);
    var indexNext = index;
    if(indexNext > 0 ){
	indexNext = indexNext-1;
    }
    cambiaImmagineFade('imgBig',indexNext);
    return false;
}

function cambiaImmagineFadeOld(id, immagine){
    if(sopra == "a"){
	id = id+"S";
    }
    var img=document.getElementById(id);
    img.src=immagine;
    if(sopra == "a"){
	sopra = "b";
	$("img.a").stop().animate({
	    "opacity": "0"
	}, "slow");
	$("img.b").stop().animate({
	    "opacity": "1"
	}, "slow");
    }else{
	sopra = "a";
	$("img.a").stop().animate({
	    "opacity": "1"
	}, "slow");
	$("img.b").stop().animate({
	    "opacity": "0"
	}, "slow");
    }
}

/***
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitchBig() {
    if(hideSlider){
	hideSlider = false;
	//$('#slider').show();
    }
    
    var $active = $('#slider a.active');

    if ( $active.length == 0 ) $active = $('#slider a:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
    : $('#slider a:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    
    $active.addClass('last-active');

    $next.css({
	opacity: 0.0
    })
    .addClass('active')
    .animate({
	opacity: 1.0
    }, 2000, function() {
	$active.removeClass('active last-active');
    });
}


function passwordChanged() {
    var strength = document.getElementById('strength');
    var strengthtxt = document.getElementById('strengthtxt');
    var enoughRegex = new RegExp("(?=.{6,}).*", "g");
    var enoughNumbRegex = new RegExp("(?=.*[0-9])", "g");
    var enoughSpecial = new RegExp("(?=.*[@'#.$;%^&+=!\"\"()*,-/:<>?])", "g");
    var pwd = document.getElementById("psw");

    if (false == enoughRegex.test(pwd.value)) {
	strength.innerHTML = '<span style="color:#a80049;margin: 0 0 0 5px;"><img src="../img/stop.gif" alt="error" /></span>';
	strengthtxt.innerHTML = '<span style="color:#a80049;margin:0 0 0 197px;"> Almeno 6 caratteri</span>';
    } else if ( (false==enoughNumbRegex.test(pwd.value)) &&   (false==enoughSpecial.test(pwd.value))  ) {
	strength.innerHTML = '<span style="color:#a80049;margin:0 0 0  5px;"><img src="../img/stop.gif" alt="error" /> </span>';
	strengthtxt.innerHTML = '<span style="color:#a80049;margin:0 0 0 197px;"> Almeno un numero o un carattere speciale</span>';
    } else{
	strength.innerHTML = '<span style="color:green;margin:0 0 0  5px;"><img src="../img/ok.gif" alt="ok" /></span>';
	strengthtxt.innerHTML = '<span style="color:orange"></span>';
    }
}

function passwordCompare() {
    var guess = document.getElementById("psw");
    var secret = document.getElementById("pswconf");
    var validity = document.getElementById('validity');

    if (guess.value == secret.value){
	validity.innerHTML = '<span style="color:green"><img src="../img/ok.png" alt="ok" /></span>';
    } else {
	validity.innerHTML = '<span style="color:red"><img src="../img/Stop.png" alt="error" /></span>';
    }
}

function Pasqua(yyyy) {
    // RITORNA DATA DELLA PASQUA fra il 1753 e il 2500
    var Ap, Bp, Cp, Dp, Ep, Fp, Mp;
    if (yyyy<100) yyyy = 1900 + yyyy;
    Ap = yyyy % 19;
    Bp = yyyy % 4;
    Cp = yyyy % 7;
    Dp = (19*Ap + 24) % 30;
    Fp = 0;            // correzione per secoli
    if (yyyy<2500) Fp=3;
    if (yyyy<2300) Fp=2;
    if (yyyy<2200) Fp=1;
    if (yyyy<2100) Fp=0;
    if (yyyy<1900) Fp=6;
    if (yyyy<1800) Fp=5;
    if (yyyy<1700) Fp=4;
    Ep = (2*Bp + 4*Cp + 6*Dp + Fp + 5) % 7;
    Ep = 22 + Dp + Ep;
    Mp = 3;
    if (Ep>31) {
	Mp = 4;
	Ep = Ep - 31;
    }
    return (new Date(yyyy, Mp-1, Ep));
}
// ' ----------------------------------------------------------- 
function isFest(data) {
    var s,d,p,ff,f
    // sabato
    s = (data.getDay()==6);
    // domenica
    d = (data.getDay()==0);
    // pasquetta
    pp = Pasqua(data.getFullYear());
    qq = data;
    qq.setDate(qq.getDate()-1);
    p = (date2str(qq) == date2str(pp));
    // FISSI
    ff = " 0101 0106 0425 0501 0602 0815 1101 1208 1225 1226 " 
    // PATRONO
    //ff += " 1030 " 
    // data in stringa
    ss = date2str(data);
    f = (ff.indexOf(ss.substr(4))>0);
    return (d || s || p || f);
}
// ' ----------------------------------------------------------- 
function date2str(dd) {
    return String(dd.getFullYear()*10000 + (dd.getMonth()+1)*100 + dd.getDate())
}

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}
