// -*- C++ -*- commento per la commutazione automatica di emacs in C++-mode

// -------------------------------------------------------------------------------------
// Gruppo di funzioni per la gestione grafica dei rollover, immagini menu, ecc.
// -------------------------------------------------------------------------------------
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];}
}
// -------------------------------------------------------------------------------------

// Funzione che in input richiede il nome dell'elemento e restituisce, indipendentemente 
// dal browser, il puntatore a quell'elemento nel documento corrente.
function getElement(elementName)
{
  if (document.getElementById)
    return document.getElementById(elementName)
      else if (document.all)
	return document.all[elementName]
	  else if (document.layers)	  
	    return document.layers[elementName]
}

// Funzione per l'evidenziazione nella barra di navigazione dell'immagine scelta.
function highlightImage(imgId) {
  for(var ii = 0; ii < imgHighlightStatus.length; ii++) {
    if (ii == imgId) {
      getElement("img_" + ii).width = 60;
      getElement("img_" + ii).height = 84;
    } else {
      getElement("img_" + ii).width = 50;
      getElement("img_" + ii).height = 70;
    }
  }
}

// Funzione per aprire una nuova finestra del browser per i siti linkati.
function openNewWindow(windowURL, windowName)
{
  // Variabili locali.
  var wf = "";
  wf = wf + "width=" + "800";
  wf = wf + ",height=" + "600";
  wf = wf + ",resizable=yes";
  wf = wf + ",scrollbars=yes";
  wf = wf + ",menubar=yes";
  wf = wf + ",toolbar=yes";
  wf = wf + ",directories=yes";
  wf = wf + ",location=yes";
  wf = wf + ",status=yes";
  
  var newWindow = window.open(windowURL,windowName,wf);
  newWindow.focus();
  
  return false;
}

// Funzione per aprire una finestra del browser per visualizzare informazioni addizionali.
function openDetailsWindow(windowURL, windowName, width, height)
{
  // Variabili locali.
  var wf = "";
  wf = wf + "width=" + width;
  wf = wf + ",height=" + height;
  wf = wf + ",resizable=yes";
  wf = wf + ",scrollbars=yes";
  wf = wf + ",menubar=no";
  wf = wf + ",toolbar=no";
  wf = wf + ",directories=no";
  wf = wf + ",location=no";
  wf = wf + ",status=no";
  
  var newDetailsWindow = window.open(windowURL,windowName,wf);
  newDetailsWindow.focus();
  
  return false;
}


/*
function fillDescField(action) {
  if (action == "cont")
    window.imgView.descIndex += 1;
  if (action == "back")
    window.imgView.descIndex -= 1;
  
  // Varaiabili locali.
  var imgViewWorkDesc = window.imgView.workDesc;
  var imgViewDescIndex = window.imgView.descIndex;

  if (imgViewWorkDesc.length > 1) {
    var descIndexToPrint = imgViewDescIndex + 1;
    window.getElement("descIndex").innerHTML = "<b>" + descIndexToPrint + "</b> di <b>" + imgViewWorkDesc.length + "</b>";
  }
  
  window.getElement("workDesc").innerHTML = "<span class=\"text2\">" + imgViewWorkDesc[imgViewDescIndex] + "</span>";  
  
  if (imgViewWorkDesc.length > 1) {
    if ((imgViewDescIndex + 1) < imgViewWorkDesc.length) {
      window.getElement("descNavButton").innerHTML = "<a href='#' onclick='fillDescField(\"cont\"); return false;'>continua...</a>";
    }
    else {
      window.getElement("descNavButton").innerHTML = "<a href='#' onclick='fillDescField(\"back\"); return false;'>indietro</a>";
    }
  }
  
  return;
}
*/

// Funzione per il controllo dei dati della form per i contatti.
function checkContactForm(contactForm) {

  // Test consistenza nome.
  if (contactForm.userName.value.length == 0) {
    alert("Il campo Nome non può essere vuoto!");
    return false;    
  }

  // Test consistenza email.
  if (contactForm.userEmail.value.length == 0) {
    alert("Il campo Email non può essere vuoto!");
    return false;    
  }

  // Test consistenza anti-spam.
  if (contactForm.strCheck.value.length == 0) {
    alert("Digitare nella casella di testo apposita la sequenza di caratteri che vedi nell'immagine al suo fianco.");
    return false;
  }

  return true;
}


// ------------------------------------------------------------------
// ***                                                            ***
// ***       SEZIONE FUNZIONI DEL MERCATINO                       ***
// ***                                                            ***
// ------------------------------------------------------------------

// Funzione per il controllo dei dati di login.
function checkLoginForm(loginForm) {
  // Test consistenza email.
  if (loginForm.userEmail.value.length == 0) {
    alert("Il campo email non può essere vuoto!");
    return false;    
  }

  // Test consistenza password.
  if (loginForm.userPwd.value.length == 0) {
    alert("Il campo password non può essere vuoto!");
    return false;    
  }

  return true;
}

// Funzione per il controllo dei dati personali immessi dall'utente.
function checkUserInfo(userInfoForm, action) {
  // Test consistenza nome.
  if (userInfoForm.userName.value.length == 0) {
    alert("Il campo Nome non può essere vuoto!");
    return false;    
  }

  // Test consistenza cognome.
  if (userInfoForm.userSurname.value.length == 0) {
    alert("Il campo Cognome non può essere vuoto!");
    return false;    
  }

  // Test consistenza indirizzo.
  if (userInfoForm.userAddress.value.length == 0) {
    alert("Il campo Indirizzo non può essere vuoto!");
    return false;    
  }

  // Test consistenza CAP.
  if (userInfoForm.userCAP.value.length == 0) {
    alert("Il campo CAP non può essere vuoto!");
    return false;    
  }

  // Test consistenza località.
  if (userInfoForm.userCity.value.length == 0) {
    alert("Il campo Località non può essere vuoto!");
    return false;    
  }

  // Test consistenza provincia.
  if (userInfoForm.userProvince.value.length == 0) {
    alert("Il campo Provincia non può essere vuoto!");
    return false;    
  }

  // Test consistenza email.
  if (userInfoForm.userEmail.value.length == 0) {
    alert("Il campo Email non può essere vuoto!");
    return false;
  }

  // Test consistenza anti-spam.
  if (action == "create" && userInfoForm.strCheck.value.length == 0) {
    alert("Digitare nella casella di testo apposita la sequenza di caratteri che vedi nell'immagine al suo fianco.");
    return false;
  }
  if (action == "modify" && userInfoForm.userPwd.value.length == 0) {
    alert("Occorre digitare la propria password per confermare le modifiche");
    return false;
  }

  return true;
}

/*
function checkDispAndPay(DAPForm) {

  // Controllo se è stato selezionato il metodo di spedizione.
  if (DAPForm.dispMode.value != 1 
      || DAPForm.dispMode.value != 2) {
    alert(DAPForm.dispMode.value + " Si prega di selezionare la modalità di spedizione nel campo apposito.");
    return false;
  }

  // Controllo se è stato selezionato il metodo di pagamento.
  if (DAPForm.payMode.value != 1 
      || DAPForm.payMode.value != 2 
      || DAPForm.payMode.value != 3 
      || DAPForm.payMode.value != 4) {
    alert(DAPForm.payMode.value + " Si prega di selezionare la modalità di pagamento nel campo apposito.");
    return false;
  }

  return true;
  }
*/

