function swap(name)
{
   imgarray = document.images[name].src.split('.');
   if(imgarray[imgarray.length-2]=="off")
      imgarray[imgarray.length-2] = "on";
   document.images[name].src = imgarray.join('.');

   return true;
}

function rest(name)
{
   imgarray = document.images[name].src.split('.');
   if(imgarray[imgarray.length-2]=="on")
      imgarray[imgarray.length-2] = "off";
   document.images[name].src = imgarray.join('.');

   return true;
}

function pre(img)
{  var name = new Image();
   name.src = img;

   return true;
}

function zoom(e)
{
   // creo il nuovo nome immagine
   tmparray = document.images[img_id].src.split('.');
   tmparray[tmparray.length - 1] = 'zoom.jpg';
   newimg = tmparray.join('.');

   // mouse
   if(navigator.appName=="Netscape") {
      mouseX = e.clientX;
      mouseY = e.clientY;
   } else {
      mouseX = event.clientX;
      mouseY = event.clientY;
   }
   
   thislay = top.document.getElementById(layer_id);

   if(top.document.images['zoomimg'].src != newimg)
   {  top.document.images['zoomimg'].src = newimg;
   }

   // didascalia
   top.document.getElementById(span_id).innerHTML = document.images[img_id].alt;

   if(thislay.visibility == 'visible')
   {  thislay.visibility = 'hidden';
   }

   if(mouseY > (window.screen.availHeight/2) )
      mouseY = mouseY - (top.document.images['zoomimg'].height + 15);

   if(mouseX > (window.screen.availWidth/2) )
      mouseX = mouseX - (top.document.images['zoomimg'].width + 30);
      
   if(navigator.appName=="Netscape") {
      thislay.style.left = (mouseX+10) + "px";
      thislay.style.top = (mouseY-0) + "px";
   } else {
      thislay.style.left = (mouseX+10);
      thislay.style.top = (mouseY-0);
   }

   thislay.style.visibility = 'visible';
}

function zoom_exit(img_id)
{
   layer_id = 'zoomdiv';
   top.document.getElementById(layer_id).style.visibility = 'hidden';
   top.document.images['zoomimg'].src = 'img/wait.jpg';
}

function pclick()
{  //document.embeds[0].play();
}

function getEncode(txt)
{
   tmpArray = txt.split(' ');
   tmpString = tmpArray.join('+');
   return escape(tmpString);
}

function map_check()
{
   if(document.forms['fmap'].fromCom.value == "")
   {  alert('il campo \'citta\' non può essere vuoto');
      return false;
   }
   if(document.forms['fmap'].fromCap.value == "")
   {  alert('il campo CAP non può essere vuoto');
      return false;
   }
   if(document.forms['fmap'].fromVia.value == "")
   {  alert('il campo \'indirizzo\' non può essere vuoto');
      return false;
   }
   
   reqString = 'http://local.google.it/maps?daddr=' + getEncode(document.forms['fmap'].toVia.value) + ',+' + 
                                                      getEncode(document.forms['fmap'].toCap.value) + '+' + 
                                                      getEncode(document.forms['fmap'].toCom.value) + '&saddr=' + 
                                                      getEncode(document.forms['fmap'].fromVia.value) + ',+' +
                                                      getEncode(document.forms['fmap'].fromCap.value) + '+' + 
                                                      getEncode(document.forms['fmap'].fromCom.value);
                                                      
   // alert(reqString);
   open(reqString, 'map',  'width=800, height=600, scrollbars=yes');

   return false;
}

function SMSListCheck()
{
   if(!document.forms['SMSList'].privacy.checked) {
      alert('E\' necessario fornire il consenso per il trattamento dei dati personali per poter usufruire del servizio.');
      return false;
   }
   
   /* pulisco il campo cellulare da altri simboli */
   document.forms['SMSList'].cellnumber.value = document.forms['SMSList'].cellnumber.value.replace(/^\+\d\d/, '');
   document.forms['SMSList'].cellnumber.value = document.forms['SMSList'].cellnumber.value.replace(/\s/g, '');
   
   if(document.forms['SMSList'].cellnumber.value.length == 0 || document.forms['SMSList'].cellnumber.value.length > 15) {
      alert('lunghezza numero telefonico errata');
      return false;
   }
   
   if(!document.forms['SMSList'].cellnumber.value.match(/^\d+$/)) {
      alert('il numero telefonico inserito non risulta un numero consentito');
      return false;
   }
   
   if(!document.forms['SMSList'].email.value.match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/)) {
      alert('l\'indirizzo di email inserito non è un indirizzo valido');
      return false;
   }
   
   document.forms['SMSList'].submit();
   return false;
}


function SMSListUnsubscribeCheck()
{
   if(confirm('Confermi di voler eliminare la sottoscrizione al servizio SMSList sul numero ' + document.forms['SMSList'].cellnumber.value + ' ?') == false) 
      return false;
   
   /* pulisco il campo cellulare da altri simboli */
   document.forms['SMSList'].cellnumber.value = document.forms['SMSList'].cellnumber.value.replace(/^\+\d\d/, '');
   document.forms['SMSList'].cellnumber.value = document.forms['SMSList'].cellnumber.value.replace(/\s/g, '');
   
   if(document.forms['SMSList'].cellnumber.value.length == 0 || document.forms['SMSList'].cellnumber.value.length > 15) {
      alert('lunghezza numero telefonico errata');
      return false;
   }
   
   if(!document.forms['SMSList'].cellnumber.value.match(/^\d+$/)) {
      alert('il numero telefonico inserito non risulta un numero consentito');
      return false;
   }
   
   document.forms['SMSList'].submit();
   return false;
}