//Controllo campi obbligatori
function formCheck(formobj){
	//1) Inserisci il nome che hai assegnato ai tuoi campi con name
	var fieldRequired = Array("tipo","titolo","tipologia");
	//2) Inserisci la descrizione del campo da riempire che appare nel messaggio a video
	var fieldDescription = Array("Inserire la tipologia: Catalogo o Promozione","Inserire il titolo del prodotto","La tipologia");
	//3) Inserisci il messagio che deve precedere l'elenco dei campi non inseriti.
	var alertMsg = "Per favore, riempi i seguenti campi:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

// Controllo lunghezza campi
function MaxCaratteri(Object,MaxLen)
{return (Object.value.length<=MaxLen);}

// Controllo indirizzo web
function ControllaUrl(){
   EmailAddr = document.modulo.url.value;
   Filtro =  Filtro = /(www).(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/; 
   if (Filtro.test(EmailAddr))
      return true;
   else
      {
		  if(EmailAddr != ""){
			  alert("Indirizzo 'Sito web' non valido! (Formato: www.nomesito.it)");
			  document.modulo.url.focus();
			  return false;
		}
      }
}

//Controllo email!
function ControllaMail(){
   EmailAddr = document.example.email.value;
   Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   if (Filtro.test(EmailAddr))
      return true;
   else
      {
		  if(EmailAddr != ""){
			  alert("Indirizzo e-mail non valido!");
			  document.example.email.focus();
			  return false;
		}
      }
}

//Testo Lampeggiante
var c1='EDF0C4'
var c2='000000'
function colore1(){
codice='<font style="background-color:#FFFF00" color=' + c1+ '><b>UTENTE SQUALIFICATO!</b></font>'
if(document.all)
{
document.all('testo').innerHTML=codice;
}
else if(document.getElementById){
document.getElementById("testo").innerHTML = codice
}
attesa = window.setTimeout("colore2()",500);
}
function colore2(){
codice='<font style="background-color:#FFFF00" color=' + c2 + '><b>UTENTE SQUALIFICATO!</b></font>'
if(document.all)
{
document.all('testo').innerHTML=codice;
}
else if(document.getElementById){
document.getElementById("testo").innerHTML =codice
}
attesa = window.setTimeout("colore1()",500)
}
function avvia()
{
attesa = window.setTimeout("colore1()",500);
}

//Popup a centro pagina
function centerPopUp( url, name, width, height, scrollbars ) {
if( scrollbars == null ) scrollbars = "0"
str = "";
str += "resizable=1,";
str += "scrollbars=" + scrollbars + ",";
str += "width=" + width + ",";
str += "height=" + height + ",";
if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;
var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;
str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}
window.open( url, name, str );
}


//controllo check box elmina foto

//Controllo elimina foto
//Foto 1
var checkobj
function agreesubmit1(el){
checkobj=el
if (document.all||document.getElementById){
	for (i=0;i<checkobj.form.length;i++){
	var tempobj=checkobj.form.elements[i]
		if(tempobj.name.toLowerCase()=="image1")
		tempobj.disabled=checkobj.checked}
		}
}
//Foto 2
var checkobj
function agreesubmit2(el){
checkobj=el
if (document.all||document.getElementById){
	for (i=0;i<checkobj.form.length;i++){
	var tempobj=checkobj.form.elements[i]
		if(tempobj.name.toLowerCase()=="image2")
		tempobj.disabled=checkobj.checked}
    	}
}
//Foto 3
var checkobj
function agreesubmit3(el){
checkobj=el
if (document.all||document.getElementById){
	for (i=0;i<checkobj.form.length;i++){
	var tempobj=checkobj.form.elements[i]
		if(tempobj.name.toLowerCase()=="image3")
		tempobj.disabled=checkobj.checked}
    	}
}
//Foto 4
var checkobj
function agreesubmit4(el){
checkobj=el
if (document.all||document.getElementById){
	for (i=0;i<checkobj.form.length;i++){
	var tempobj=checkobj.form.elements[i]
		if(tempobj.name.toLowerCase()=="image4")
		tempobj.disabled=checkobj.checked}
    	}
}
//foto 5

var checkobj
function agreesubmit5(el){
checkobj=el
if (document.all||document.getElementById){
	for (i=0;i<checkobj.form.length;i++){
	var tempobj=checkobj.form.elements[i]
		if(tempobj.name.toLowerCase()=="image5")
		tempobj.disabled=checkobj.checked}
    	}
}

//foto 6
var checkobj
function agreesubmit6(el){
checkobj=el
if (document.all||document.getElementById){
	for (i=0;i<checkobj.form.length;i++){
	var tempobj=checkobj.form.elements[i]
		if(tempobj.name.toLowerCase()=="image6")
		tempobj.disabled=checkobj.checked}
    	}
}

//foto 7
var checkobj
function agreesubmit7(el){
checkobj=el
if (document.all||document.getElementById){
	for (i=0;i<checkobj.form.length;i++){
	var tempobj=checkobj.form.elements[i]
		if(tempobj.name.toLowerCase()=="image7")
		tempobj.disabled=checkobj.checked}
    	}
}
//foto 8
var checkobj
function agreesubmit8(el){
checkobj=el
if (document.all||document.getElementById){
	for (i=0;i<checkobj.form.length;i++){
	var tempobj=checkobj.form.elements[i]
		if(tempobj.name.toLowerCase()=="image8")
		tempobj.disabled=checkobj.checked}
    	}
}

//foto 9
var checkobj
function agreesubmit9(el){
checkobj=el
if (document.all||document.getElementById){
	for (i=0;i<checkobj.form.length;i++){
	var tempobj=checkobj.form.elements[i]
		if(tempobj.name.toLowerCase()=="image9")
		tempobj.disabled=checkobj.checked}
    	}
}

//foto10
var checkobj
function agreesubmit10(el){
checkobj=el
if (document.all||document.getElementById){
	for (i=0;i<checkobj.form.length;i++){
	var tempobj=checkobj.form.elements[i]
		if(tempobj.name.toLowerCase()=="image10")
		tempobj.disabled=checkobj.checked}
    	}
}

//Popup a centro pagina
function centerPopUp( url, name, width, height, scrollbars ) {
if( scrollbars == null ) scrollbars = "0"
str = "";
str += "resizable=1,";
str += "scrollbars=" + scrollbars + ",";
str += "width=" + width + ",";
str += "height=" + height + ",";
if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;
var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;
str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}
window.open( url, name, str );
}

// Verifica del codice fiscale
function controlla_codice(campo){
   caratteri= new Array ("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
   pari= new Array (0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25)
   dispari=new Array (1,0,5,7,9,13,15,17,19,21,1,0,5,7,9,13,15,17,19,21,2,4,18,20,11,3,6,8,12,14,16,10,22,25,24,23)
   cod=campo.value.toLowerCase();
   check=true;
  
  if (cod.length==0){
     check=true
  }
  else
  {
   if (cod.length!=16){
      check=false
      }
     else
      {
      lettere=cod.substr(0,6)+cod.substr(8,1)+cod.substr(11,1)+cod.substr(15);
      numeri=cod.substr(6,2)+cod.substr(9,2)+cod.substr(12,3);
      for (i=0;i<10;i++){
         if (lettere.charCodeAt(i)<97 || lettere.charCodeAt(i)>122){
            check=false;}
      }
      for (i=0;i<8;i++){
         if (numeri.charCodeAt(i)<48 || numeri.charCodeAt(i)>57){
            check=false;
         }
      }   
     }
   //checksum del codice fiscale
   test=cod.substr(15,1);
   var somma=0
   for (i=0;i<16;i=i+2){ //dispari
       carattere=cod.substr(i,1)
       for (k=0;k<36;k++){
          if (carattere==caratteri[k]){
             somma=somma+dispari[k]
             break
          }
       }
    }
    for (i=1;i<15;i=i+2){ //pari
       carattere=cod.substr(i,1)
       for (k=0;k<36;k++){
          if (carattere==caratteri[k]){
             somma=somma+pari[k]
             break
          }
       }
    }
   resto=somma % 26;
   var lettera=String.fromCharCode(97+resto);            
   if (test != lettera){
      check=false;
      }   
 }
   if (check==false){
      alert("Codice fiscale errato!")
   document.modulo.cf.focus();
      }
   return check;
}


//Select dinamico
function changeLocation(menuObj) {
  var i = menuObj.selectedIndex;
  if(i > 0) {
    window.location.href = "index.php?page=10&select="+menuObj.options[i].value;
  }
}

//Select dinamico
function changeLocation2(menuObj) {
  var i = menuObj.selectedIndex;
  if(i > 0) {
    window.location.href = "index.php?page=11&select="+menuObj.options[i].value;
  }
}
