﻿/*
'
'**************************************
' Visuddhi - http://visuddhi.com
' Copyright (c) 2006 - Visuddhi
' All right reserved. 
'**************************************
'
*/

// funzione di invio mail
function mail(utente, dominio) {
  location.href = 'mailto:' + utente + '@' + dominio
}

// indicazione di campo
function TipRiferimento() {
  var alt = document.getElementById('rifaltro');
  switch(document.getElementById('riferimento').value) {
    case 'Fotolaboratorio':
      alt.value = 'inserire nome del fotolaboratorio'; alt.focus(); alt.select(); break;
    case 'Tau Visual':
      alt.value = 'inserire il codice Tau Visual'; alt.focus(); alt.select(); break;
    case 'Workshop':
      alt.value = 'inserire nome del workshop'; alt.focus(); alt.select(); break;
    case 'Altro':
      alt.value = 'inserire il riferimento'; alt.focus(); alt.select(); break;
    default:
      break;
  }  
}

// indicazione di campo
function TipAttivita() {
  var alt = document.getElementById('attaltro');
  switch(document.getElementById('attivita').value) {
    case 'Altro':
      alt.value = 'inserire il tipo di attività svolta'; alt.focus(); alt.select(); break;
    default:
      break;
  }  
}

// controlli sul form di contatto
function CheckFormContatti(){
  var lenNome = document.getElementById('nome').value.length;
  var lenEmail = document.getElementById('email').value.length;
  var lenOggetto = document.getElementById('oggetto').value.length;
  var lenTesto = document.getElementById('testo').value.length;
  if (lenNome<1 || lenEmail<1 || lenOggetto <1 || lenTesto<1){ 
    alert('Nome ed indirizzo e-mail del mittente, oggetto e testo obbligatori!'); 
    return false;
  }
  var valEmail = document.getElementById('email').value;
  filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  if (!filter.test(valEmail)) {
    alert("Controllare l'indirizzo e-mail inserito");
    return false;
  }
  return true;
}

// controlli sul form di contatto
function CheckFormIscrizione(){
  var lenRiferimento = document.getElementById('riferimento').value.length;
  var lenCorso = document.getElementById('corso').value.length;
  var lenAttivita = document.getElementById('attivita').value.length;
  var lenRagione = document.getElementById('ragione').value.length;
  var lenNome = document.getElementById('nome').value.length;
  var lenCognome = document.getElementById('cognome').value.length;
  var lenIncarico = document.getElementById('incarico').value.length;
  var lenIndirizzo = document.getElementById('indirizzo').value.length;
  var lenCap = document.getElementById('cap').value.length;
  var lenComune = document.getElementById('comune').value.length;
  var lenProvincia = document.getElementById('provincia').value.length;
  var lenFisso = document.getElementById('fisso').value.length;
  var lenMobile = document.getElementById('mobile').value.length;
  var lenEmail = document.getElementById('email').value.length;
  var lenRivenditore = document.getElementById('rivenditore').value.length;
  var lenLocalita = document.getElementById('localita').value.length;
  var bolPulizia = document.getElementById('pulizia').checked;
  var lenModello = document.getElementById('modello').value.length;
  var lenMatricola = document.getElementById('matricola').value.length;
  var lenGiorno = document.getElementById('giorno').value.length;
  var lenMese = document.getElementById('mese').value.length;
  var lenAnno = document.getElementById('anno').value.length;
  if (lenRiferimento<1 || lenCorso<1 || lenAttivita<1 || lenIncarico<1 || lenIndirizzo<1 || lenCap<1 || lenComune<1 || lenProvincia<1 || lenEmail<1 || lenRivenditore<1 || lenLocalita<1 || lenGiorno<1 || lenMese<1 || lenAnno<1){
    alert('Tutti i campi contrassegnati con un asterisco sono obbligatori!'); 
    return false;
  }
  var rife = document.getElementById('riferimento')
  var rifa = document.getElementById('rifaltro')
  var lenRifaltro = rifa.value.length;
  if ((rife.value == 'Fotolaboratorio' || rife.value == 'Tau Visual' || rife.value == 'Workshop' || rife.value == 'Altro') && lenRifaltro.length<1){
    alert('Inserire il dettaglio del riferimento scelto!'); 
    return false;
  }
  var atti = document.getElementById('attivita')
  var atta = document.getElementById('attaltro')
  var lenAttaltro = atta.value.length;
  if ((atti.value == 'Altro') && lenAttaltro.length<1){
    alert('Inserire il tipo di attività svolta!'); 
    return false;
  }  
  if (lenRagione<1 && (lenNome<1 || lenCognome<1)){
    alert('La ragione sociale o il nome e cognome sono obbligatori!'); 
    return false;
  }
  if (lenFisso<1 && lenMobile<1){
    alert('Un numero di telefono, fisso o mobile, è obbligatorio!'); 
    return false;
  }
  var optTessere = document.getElementById('tessereboh').checked;
  var optUsato = document.getElementById('usatoboh').checked;
  var optAccessori = document.getElementById('accessoriboh').checked;
  var optVendita = document.getElementById('venditaboh').checked;
  var optSviluppo = document.getElementById('sviluppoboh').checked;
  var optServizifoto = document.getElementById('servizifotoboh').checked;
  if (optTessere || optUsato || optAccessori || optVendita || optSviluppo || optServizifoto){
      alert('Le informazioni sull\'attività sono obbligatorie!'); 
      return false;
  }
  var tipoTotale = 0;
  for (i=1;i<=10;i++){ tipoTotale += Number(document.getElementById('tipo' + i).value); }
  if (tipoTotale != 100){
    alert('La somma del tipo di servizi fotografici deve dare 100!'); 
    return false;
  }
  var lenTipo10 = document.getElementById('tipo10').value.length;
  var lenTipoaltro = document.getElementById('tipoaltro').value.length;
  if (lenTipo10>0 && lenTipoaltro<1){
    alert('Inserire il tipo di servizi fotografici indicati come \'Altro\'!'); 
    return false;
  }
  var marcaTotale = 0;
  for (i=1;i<=8;i++){ marcaTotale += Number(document.getElementById('marca' + i).value); }
  if (marcaTotale != 100){
    alert('La somma della marca di attrezzatura usata deve dare 100!'); 
    return false;
  }
  var lenMarca8 = document.getElementById('marca8').value.length;
  var lenMarcaaltro = document.getElementById('marcaaltro').value.length;
  if (lenMarca8>0 && lenMarcaaltro<1){
    alert('Inserire la marca di attrezzatura indicata come \'Altro\'!'); 
    return false;
  }
  if (bolPulizia && (lenModello<1 || lenMatricola<1)){
    alert('Per prenotare la pulizia del sensore sono obbligatori il modello di fotocamera e la matricola!'); 
    return false;
  }
  var valEmail = document.getElementById('email').value;
  filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  if (!filter.test(valEmail)) {
    alert('Controllare l\'indirizzo e-mail inserito!');
    return false;
  }
  return true;
}


// posiziona il tooltip
function col(cosa){ 
  var altrocosa = document.getElementById('ToolTip'); altrocosa.style.display='block';
  altrocosa.style.top=(AnchorPosition_getPageOffsetTop(cosa)-151)+'px';
  altrocosa.style.left=(AnchorPosition_getPageOffsetLeft(cosa)-78)+'px';
  mes(cosa.id, altrocosa);
  var altroid = cosa.getAttribute('id');
}

// elimina il tooltip
function dec(cosa){ 
  var altrocosa = document.getElementById('ToolTip'); altrocosa.style.display='none';
  var altroid = cosa.getAttribute('id');
}

// funzioni di servizio per il tooltip
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft; while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }	return ol; }
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop; while((el=el.offsetParent) != null) { ot += el.offsetTop; } return ot; }

// imposta il messaggio del tooltip
function mes(cosa, chi){ switch(cosa) {
    case 'Visuddhi':
      chi.innerHTML='<a href="http://www.visuddhi.com/" title="Visuddhi..." onclick="this.target=\'_blank\';"><img src="Images/v.gif" alt="Visuddhi Logo" /></a>'; break;
    default:
      chi.style.display='none'; } }
