function mostraAlertSpedizione() {
    $.fancybox(
        document.getElementById('alert_spedizione_estero').innerHTML,
        {
            'autoDimensions': false,
            /*'width': '700',
            'height': '522',*/
            'autoDimensions' : true,
            'transitionIn': 'fade',
            'transitionOut': 'fade',
            'speedIn': 1000,
            'hideOnOverlayClick': false
            }
        );
}

function dueCifre(x)
{
    window.alert(x + ' lung: ' + x.length);
    if(x.length==1)
        return '0'+x;
    else
        return x;
}

function formatText(index, panel) { return index+''; } 

    function dg(x) { return document.getElementById(x); }
    function dgv(x) { return document.getElementById(x).value; }
    function toggleCheckBox(qualeCheckBox, qualeDiv)
    {
        if(qualeCheckBox.checked)
        {
            dg(qualeDiv).style.display='none';
        }
        else
        {
            dg(qualeDiv).style.display='';
        }
    }
    
    function toggleValore(bolValore, qualeDiv)
    {
        if(bolValore)
        { qualeDiv.style.display=''; }
        else
        { qualeDiv.style.display='none'; }
    }
    
    
    
function ahah(url, target, delay) {
//window.open(url);
document.getElementById(target).innerHTML = 'attendere...<br>';
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req != undefined) {
req.onreadystatechange = function() {ahahDone(url, target, delay);};
req.open("GET", url, true);
req.send("");
}
} 

function ahahDone(url, target, delay) {
if (req.readyState == 4) { // only if req is "loaded"
if (req.status == 200) { // only if "OK"
document.getElementById(target).innerHTML = req.responseText;
} else {
document.getElementById(target).innerHTML="Errore:\n"+req.statusText;
}
if (delay != undefined) {
setTimeout("ahah(url,target,delay)", delay); // resubmit after delay
      //server should ALSO delay before responding
}
}
}

var counterFile = 2;

var counterImmagini = 2;
var counterImmaginiMax = 5;
function aggiungiDocumento(qualeDiv, primaParteDelNome)
{
    counterFile++;
    if(counterImmaginiMax==counterFile)
        {   
            dg('link_aggiunta_img').style.display='none'; }

    var newdiv = document.createElement('div');
    newdiv.setAttribute('id','div_aggiuntivo_' + counterFile);
    newdiv.setAttribute('class','divisioneDashed');
    dg(qualeDiv).appendChild(newdiv);
    
    dg(qualeDiv).appendChild(document.createTextNode("Descrizione: "));

    var newTextInput = document.createElement('input');
    newTextInput.setAttribute('type','text');
    newTextInput.setAttribute('maxlength','255');
    newTextInput.setAttribute('size','30');
    newTextInput.setAttribute('id',primaParteDelNome + 'descrizione_' + counterFile);
    newTextInput.setAttribute('name',primaParteDelNome + 'descrizione_' + counterFile);
    dg(qualeDiv).appendChild(newTextInput);
    
    var newInput = document.createElement('input');
    newInput.setAttribute('type','file');
    newInput.setAttribute('id',primaParteDelNome + counterFile);
    newInput.setAttribute('name',primaParteDelNome + counterFile);
    dg(qualeDiv).appendChild(document.createElement('br'));
    dg(qualeDiv).appendChild(document.createTextNode("File: "));
    dg(qualeDiv).appendChild(newInput);
}

function aggiungiImmagine(qualeDiv, primaParteDelNome)
{
    counterImmagini++;
    var newInput = document.createElement('input');
    newInput.setAttribute('type','file');
    newInput.setAttribute('id',primaParteDelNome + counterImmagini);
    newInput.setAttribute('name',primaParteDelNome + counterImmagini);
    dg(qualeDiv).appendChild(document.createElement('br'));
    dg(qualeDiv).appendChild(newInput);
}

var counterPagine;
counterPagine=1;
function aggiungiPagina(qualeDiv,primaParteDelNome)
{
    counterPagine++;
    var newInputTR = document.createElement('tr');

    newInputTD = document.createElement('td');
    newInputTD.innerHTML='<input name="' + primaParteDelNome + counterPagine + '" id="' + primaParteDelNome + counterPagine + '" type="text" value="" maxlength="50" size="20" />';
    newInputTR.appendChild(newInputTD);

    newInputTD2 = document.createElement('td');

    var selettore;
    selettore = dg('fIdNewsSelect').cloneNode(true);
    selettore.id='fIdNewsNuova_' + counterPagine;
    selettore.name='fIdNewsNuova_' + counterPagine;
    
    newInputTD2.appendChild(selettore);
    newInputTR.appendChild(newInputTD2);
    //vuoto:
    newInputTR.appendChild(document.createElement('td'));

    dg(qualeDiv).appendChild(newInputTR);
}

function mostra(quale,elemento)
{
    var daChiudere = document.getElements

    if(document.getElementById('menu_scomparsa_' + quale).style.display=='none')
    {
        //elemento.style.backgroundImage='immagini/freccina.png';
        //background-position:186px 6px;
        elemento.className='titolo_categoria frecciaGiu';
        
        /* olivino
        Effect.SlideDown('menu_scomparsa_' + quale, { duration: 0.6 });
        */
        $('#menu_scomparsa_' + quale).slideDown(500);
        $.ajax({ type: "GET", url: "memoMenu.asp?menu=" + quale + "&v=S" });
        //window.open('memoMenu.asp?menu=' + quale + '&v=N');
        //$.ajax('memoMenu.asp?menu=' + quale + '&v=S', { type:'get' });
    }
    else
    {
        elemento.className='titolo_categoria frecciaSu';
        //Effect.SlideUp('menu_scomparsa_' + quale, { duration: 0.3 });
        $('#menu_scomparsa_' + quale).slideUp(500);
        $.ajax({ type: "GET", url: "memoMenu.asp?menu=" + quale + "&v=N" });
        //$.ajax('memoMenu.asp?menu=' + quale + '&v=N', { type:'get' });
    }    
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function submitIndirizzo()
{
    var email = document.getElementById('form_indirizzo_newsletter').value;
    if (!email.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/))
    {
        window.alert('L\'indirizzo email inserito non è valido.');
        return false;
    }
      
    if(window.confirm('I dati inviati saranno trattati secondo quanto riportato\nnell\'informativa sulla privacy.\nContinuare?'))
    {
        //window.open('newsletter_submit.asp?foo=' + dummy + '&email=' + document.getElementById('form_indirizzo_newsletter').value);
        $.ajax({ type: "GET", url: 'newsletter_submit.asp?foo=' + dummy + '&email=' + document.getElementById('form_indirizzo_newsletter').value });
        //new Ajax.Request('newsletter_submit.asp?foo=' + dummy + '&email=' + document.getElementById('form_indirizzo_newsletter').value, { method:'get' });
        document.getElementById('form_indirizzo_newsletter').value='indirizzo email';
        window.alert('L\'iscrizione è avvenuta correttamente.');
    }
    else
    { return false; }
}

/* slideshow immagini prodotti e lightbox: */
function loadProxGalleria()
{
    proxGalleria();
    temphref=document.getElementById('area_ingrandimento0').href;
    tempTitle=document.getElementById('area_ingrandimento0').title;
    for(i=0;i<FotoQuante-1;i++)
    {
        document.getElementById('area_ingrandimento' + i).href=document.getElementById('area_ingrandimento' + (i+1)).href;
        document.getElementById('area_ingrandimento' + i).title=document.getElementById('area_ingrandimento' + (i+1)).title;
    }

    document.getElementById('area_ingrandimento' + i).href=temphref;
    document.getElementById('area_ingrandimento' + i).title=tempTitle;
}

function loadPrecGalleria()
{
    precGalleria();
    temphref=document.getElementById('area_ingrandimento' + (FotoQuante-1)).href;
    tempTitle=document.getElementById('area_ingrandimento' + (FotoQuante-1)).title;
    
    for(i=0;i<FotoQuante-1;i++)
    {
        document.getElementById('area_ingrandimento' + ((FotoQuante-1)-i)).href=document.getElementById('area_ingrandimento' + ((FotoQuante-2)-i)).href;
        document.getElementById('area_ingrandimento' + ((FotoQuante-1)-i)).title=document.getElementById('area_ingrandimento' + ((FotoQuante-2)-i)).title;
    }

    document.getElementById('area_ingrandimento0').href=temphref;
    document.getElementById('area_ingrandimento0').title=tempTitle;
}
function formatText(index, panel) { return index + ""; }
