function windowOpener(html_file, display_frame) {               
        html_file = "" + html_file;                          
        open(html_file,display_frame,"toolbar=no,scrollbars=NO,resizable=no,width=450, height=400")
}
function stampa_articolo(html_file, display_frame) {               
        html_file = "" + html_file;                          
        open(html_file,display_frame,"toolbar=no,scrollbars=yes,resizable=yes,width=580, height=450")
}

function fotografie(html_file, display_frame) {               
        html_file = "" + html_file;                          
        open(html_file,display_frame,"toolbar=no,scrollbars=yes,resizable=yes,width=640, height=500")
}

function spedisci_registrazione()
{
if (document.FORM_REGISTRAZIONE.EMAIL_REGISTRAZIONE.value == "") {alert("Campo 'Indirizzo e-mail' vuoto."); return;} 
if (! check_email(document.FORM_REGISTRAZIONE.EMAIL_REGISTRAZIONE.value)) {alert("Non è stato inserito l'indirizzo di Email in maniera corretta."); return;} 

document.FORM_REGISTRAZIONE.action = "registrazione_mailinglist_salva.asp";
document.FORM_REGISTRAZIONE.submit();
}

function ricerca_sito()
{
if (document.FORM_RICERCA.KEYWORD.value == "") {alert("Inserire una parola per la ricerca."); return;} 

document.FORM_RICERCA.action = "risultati_ricerca.asp";
document.FORM_RICERCA.submit();
}



function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v3.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}




function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function check_email (stringa) {
    if((stringa.indexOf("@")==-1) || (stringa.indexOf(".")==-1)){        
        return false;
    }
    else{
	return true;
    }

}

function check_campi (stringa) {
    if( ( stringa.search(/[^a-z,0-9,.,_]/) ) != -1 ){
	return false;
    }
    else{
	return true;
    }
}

function check_interessi() {
    contatore=0;
    if (document.form1.int1.status == true) contatore++;
    if (document.form1.int2.status == true) contatore++;
    if (document.form1.int3.status == true) contatore++;
    if (document.form1.int4.status == true) contatore++;
    if (document.form1.int5.status == true) contatore++;
    if (document.form1.int6.status == true) contatore++;
    if (document.form1.int7.status == true) contatore++;
    if (document.form1.int8.status == true) contatore++;
    if (document.form1.int9.status == true) contatore++;
    if (document.form1.int10.status == true) contatore++;
    if (document.form1.int11.status == true) contatore++;
    if (document.form1.int12.status == true) contatore++;
    if (document.form1.int13.status == true) contatore++;
    if (document.form1.int14.status == true) contatore++;
    if (document.form1.int15.status == true) contatore++;
    if (document.form1.int16.status == true) contatore++;
    if (document.form1.int17.status == true) contatore++;
    if (document.form1.int18.status == true) contatore++;
    if (document.form1.int19.status == true) contatore++;
    if (document.form1.int20.status == true) contatore++;
    
    if (contatore >= 1 && contatore <=5) {
	return true;
    }
    else	{
	return false;
    }
}

function check_numeri (stringa) {
    if( ( stringa.search(/[^0-9]/) ) != -1 ) {
	return false;
    }
    else{
	return true;
    }
}

function check_first_tel(stringa){
    var c = stringa.charAt(0);
    if ( ( c.search(/[^0]/) == -1 ) ||( c.search(/[^3]/) == -1 ) ) {
	return true;
    }
    else {
	return false;
    }
}

function check_caratteri (stringa) {
    if( ( stringa.search(/[^a-z,A-Z, ,']/) ) != -1 ) {
	return false;
    }
    else{
	return true;
    }
}

function check_formal(stringa){
    var c = stringa.charAt(0);
    if ( c.search(/[^a-z]/) != -1 ) {
	return false;
    }
    else {
	return true;
    }
}

function check_consecutio(stringa)
{
    var n = stringa.search(/[.]{2}/);
    if ( n != -1 ) 
    {
    	return true;
    }
    else 
    {
	return false;
    }
}

function punto_finale(s)
{
    var c = s.length;
    var d = (s.charAt(c-1));
    if ( d.search(/[.]/) != -1 ) 
      { 
	  return true;
      }
      else
      {
	  return false;
      }
}

function check_nome_cognome(codfisc,nome,cognome)
{
    codfisc=codfisc.toUpperCase();
    nome=nome.toUpperCase();
    cognome=cognome.toUpperCase();
    nome=nome.replace(/ /g,"");
    cognome=cognome.replace(/ /g,"");
    nome=nome.replace(/'/g,"");
    cognome=cognome.replace(/'/g,"");

    var codfisc_nc=codfisc.substr(0,6);
    
    l = cognome.length;
    L = nome.length;
    var cogn_vocali= "";
    var cogn_consonanti= "";
    var nome_vocali= "";
    var nome_consonanti= "";
    var ris1="";
    var ris2="";
    var risultato = "";

    //controllo cognome
    for(i=0;i<l;i++) 
    {                                        
	var ch=cognome.charAt(i);
	if(ch =='A' || ch =='E' || ch =='I' || ch =='O' || ch == 'U' ){
	    cogn_vocali += ch;
	}
	else{
	    cogn_consonanti += ch;
	}
    }
    lung_c =cogn_consonanti.length;
    lung_v =cogn_vocali.length;
    if(lung_c >=3){
	ris1 = cogn_consonanti.charAt(0)+cogn_consonanti.charAt(1)+cogn_consonanti.charAt(2);
    }
    else if(lung_c == 2 && lung_v >= 1){
	ris1 = cogn_consonanti.charAt(0)+cogn_consonanti.charAt(1)+cogn_vocali.charAt(0);
    }
    else if(lung_c == 1 && lung_v > 1){
	ris1 = cogn_consonanti.charAt(0)+cogn_vocali.charAt(0)+cogn_vocali.charAt(1);
    }
    else if(lung_c == 1 && lung_v == 1){
	ris1 = cogn_consonanti.charAt(0)+cogn_vocali.charAt(0)+"X";
    }
    else if(lung_c == 0 && lung_v >= 3){
	ris1 = cogn_vocali.charAt(0)+cogn_vocali.charAt(1)+cogn_vocali.charAt(2);
    }
    else if(lung_c == 0 && lung_v == 2){
	ris1 = cogn_vocali.charAt(0)+cogn_vocali.charAt(1)+"X";
    }
    else if(lung_c == 0 && lung_v == 1){
	ris1 = cogn_vocali.charAt(0)+"X"+"X";
    }

    //controllo nome
    for(i=0;i<L;i++) 
    {
	var ch=nome.charAt(i);
	if(ch =='A' || ch =='E' || ch =='I' || ch =='O' || ch == 'U' ){
	    nome_vocali += ch;
	}
	else{
	    nome_consonanti += ch;
	}
    }
    lung_c =nome_consonanti.length;
    lung_v =nome_vocali.length;
    
    if(lung_c >= 4){
	ris2 = nome_consonanti.charAt(0)+nome_consonanti.charAt(2)+nome_consonanti.charAt(3);
    }
    if(lung_c == 3){
	ris2 = nome_consonanti.charAt(0)+nome_consonanti.charAt(1)+nome_consonanti.charAt(2);
    }
    if(lung_c == 2 && lung_v >= 1){
	ris2 = nome_consonanti.charAt(0)+nome_consonanti.charAt(1)+nome_vocali.charAt(0);
    }
    if(lung_c == 1 && lung_v >= 2){
	ris2 = nome_consonanti.charAt(0)+nome_vocali.charAt(0)+nome_vocali.charAt(1);
    }
    if(lung_c == 1 && lung_v == 1){
	ris2 = nome_consonanti.charAt(0)+nome_vocali.charAt(0)+"X";
    }
    if(lung_c == 0 && lung_v >= 3){
	ris2 = nome_vocali.charAt(0)+nome_vocali.charAt(1)+nome_vocali.charAt(2);
    }
    if(lung_c == 0 && lung_v == 2){
	ris2 = nome_vocali.charAt(0)+nome_vocali.charAt(1)+"X";
    }
    
    risultato = ris1+ris2;
    if(codfisc_nc == risultato)
    {
	return true;
    }
    else
    {
	return false;
    }
}

function check_data(giorno,mese,anno,codfisc,sesso)
{
  var codfisc_anno=codfisc.substr(6,2);
  var anno=anno.substr(2,2);
  if(anno != codfisc_anno){
      return false; 
  }  
  else{
      var codfisc_giorno=codfisc.substr(9,2);
      if(sesso == "F"){
          codfisc_giorno=codfisc_giorno-40;
      }
      if(giorno != codfisc_giorno){
          return false;
      }
      else{
          var codfisc=codfisc.toUpperCase();
          var codfisc_mese=codfisc.substr(8,1);
          if (mese == "01"){mese="A";}  
          if (mese == "02"){mese="B";}
          if (mese == "03"){mese="C";}
          if (mese == "04"){mese="D";}
          if (mese == "05"){mese="E";}
          if (mese == "06"){mese="H";}
          if (mese == "07"){mese="L";}
          if (mese == "08"){mese="M";}
          if (mese == "09"){mese="P";}
          if (mese == "10"){mese="R";}
          if (mese == "11"){mese="S";}
          if (mese == "12"){mese="T";}
	  if (mese == codfisc_mese){
             return true;
          }
          else{
             return false;
          }
      }
  }
}


function controllo_ultimo_carattere(cf2){
    
    //calcolo lettera di controllo:
    
    cf2 = cf2.toUpperCase();
    cfrid = cf2.substring(0, 15);
    controllo=cf2.substring(15,16);
    var tab_odd = [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];
    var sum = 0;
    var a="A";
    var acod =a.charCodeAt(0);
    var zero = "0";
    var zerocod = zero.charCodeAt(0);
    var nove = "9";
    var novecod = nove.charCodeAt(0);
   // calcola la somma

        for(j=0;j<15;j++)
        {
            var acod2=cfrid.charCodeAt(j);

            if ( (j+1) % 2 == 0 ) {
                if ( ( acod2 <= novecod) && ( acod2 >= zerocod ) ) {
                    sum = ( (sum*1) + (acod2 - zerocod) );
                }
                else {
                    sum=( (sum*1) + ( (acod2-acod) * 1) );
                }
            }
           else {
                if ( (acod2 <= novecod) && (acod2 >= zerocod) ) {
                    var index=(acod2 - zerocod);
                }
                else {
                    index=(acod2-acod);
                }
                sum+=tab_odd[index];
            }
        }

    var controllo_code = controllo.charCodeAt(0);
    var sum1=(sum % 26);

    var control_char = ( sum1 + acod);

    if (control_char==controllo_code) {
        return 1;
        //OK
        }
    else {
        return 0;
        //KO
        }
}

function less(s, max)
{
    var c = s.length;
    if (c < max ) return true;
    return false;
}

function equal16(s)
{
    var c = s.length;
    if (c!=16) return false;
    return true;
}


function equal5(s)
{
    var c = s.length;
    if (c!=5) return false;
    return true;
}


function equal4(s)
{
    var c = s.length;
    if (c!=4) return false;
    return true;
}


function is_netscape(){
    if (navigator.appName == "Netscape"){
	return true;
    }
    else {
	return false;
    }
}

function is_explorer(){
    if ((navigator.appName == "Microsoft Internet Explorer") && ((navigator.appVersion.indexOf("5.") != -1) || (navigator.appVersion.indexOf("6.") != -1))) {
	return true;
    }
    else {
	return false;
    }
}

function cattura()
{
  popup = window.open('/reg_pop.html','pop','width=400,height=300,scrollbars=no');
  popup.creator=self;
  popup.focus();
}

function invia()
{
  if (document.form1.condizioni[1].checked) {alert("Condizioni del contratto non accettate."); return;}
  if (navigator.platform=="Win32"){
      if (document.form1.homepage.checked) {
	  document.body.style.behavior='url(#default#homepage)'; 
	  document.body.setHomePage('http://www.inwind.it'); 
      }
  }
  else{
//      if (document.form1.homepage.checked) {
	//  alert("netscape!!!!!");
	//  netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
	//  navigator.preference("browser.startup.homepage","http://www.inwind.it");
	  //document.body.style.behavior='url(#default#homepage)'; 
	  //document.body.setHomePage('http://www.inwind.it'); 
//      }
}
  //if (document.form1.privacy[1].checked) {alert("Trattamento dati non accettato."); return;} 
  if ( less(document.form1.username.value, 4)) {alert("Il campo USERNAME contiene meno di quattro caratteri."); return;}
  if (! check_campi(document.form1.username.value)) {alert("Il campo USERNAME contiene caratteri non ammessi."); return;}
  if (! check_formal(document.form1.username.value)) {alert("Il campo USERNAME comincia con un carattere non ammesso."); return;}
  if (check_consecutio(document.form1.username.value)) {alert("Il campo USERNAME contiene caratteri non ammessi."); return;}
  if (punto_finale(document.form1.username.value)) {alert("Il campo USERNAME termina con un carattere non ammesso"); return;}
  if ( less(document.form1.password.value, 4)) {alert("Il campo PASSWORD contiene meno di quattro caratteri."); return;}
  if (! check_campi(document.form1.password.value)) {alert("Il campo PASSWORD contiene caratteri non ammessi."); return;}
  if (document.form1.risposta.value == "") {alert("Campo RISPOSTA SEGRETA vuoto."); return;}  
  if (document.form1.anno.value == "") {alert("Campo ANNO DI NASCITA vuoto."); return;} 
  if (! check_numeri(document.form1.anno.value)) {alert("Il campo ANNO DI NASCITA contiene caratteri non validi."); return;} 
  if (document.form1.anno.value < 1900) {alert("campo ANNO DI NASCITA errato"); return;} 
  if (document.form1.anno.value > 2001) {alert("campo ANNO DI NASCITA errato."); return;} 
  if (document.form1.nome.value == "") {alert("Campo NOME vuoto."); return;}  
  if (! check_caratteri(document.form1.nome.value)) {alert("Il campo NOME contiene caratteri non validi."); return;} 
  if (document.form1.cognome.value == "") {alert("Campo COGNOME vuoto."); return;}  
  if (! check_caratteri(document.form1.cognome.value)) {alert("Il campo COGNOME contiene caratteri non validi."); return;} 
  if (document.form1.comune.value == "") {alert("Campo CITTA' vuoto."); return;}
  if (! check_caratteri(document.form1.comune.value)) {alert("Il campo CITTA' contiene caratteri non validi."); return;}
  if (document.form1.provincia.selectedIndex == 0) {alert("Campo PROVINCIA vuoto."); return;}  
  if (document.form1.cap.value == "") {alert("Campo CAP vuoto."); return;}  
  if ( less(document.form1.cap.value, 5)) {alert("Il campo CAP contiene meno di CINQUE caratteri."); return;}
  if(! check_numeri(document.form1.cap.value)) {alert("Il campo CAP contiene caratteri non validi."); return;}
  if ((((navigator.platform=="Win32") && is_explorer()) ) && (!check_interessi())) {alert("Bisogna specificare almeno un interesse ed al massimo 5"); return;}  
  if (document.form1.password.value == document.form1.password2.value)
  {
      if (document.form1.accesso_internet.checked)
      {
	  if(!check_nome_cognome(document.form1.codice_fiscale.value,document.form1.nome.value, document.form1.cognome.value )){alert("Il CODICE FISCALE non corrisponde al nome e cognome immessi."); return;}
	  if(! check_data(document.form1.giorno.options[document.form1.giorno.selectedIndex].value,document.form1.mese.options[document.form1.mese.selectedIndex].value, document.form1.anno.value,document.form1.codice_fiscale.value, document.form1.sesso.options[document.form1.sesso.selectedIndex].value)){alert("Il CODICE FISCALE non corrisponde ai dati immessi nel campo data di nascita o nel campo sesso."); return;}

		  // if (document.form1.citta_numero_text.value == "") {alert("Campo POP vuoto."); return;}  
	  if (document.form1.codice_fiscale.value == "") {alert("Campo CODICE FISCALE vuoto."); return;}
	  if (! equal16 (document.form1.codice_fiscale.value)) {alert("Il CODICE FISCALE deve essere composto da 16 caratteri."); return;}

	  if (! controllo_ultimo_carattere (document.form1.codice_fiscale.value)) {alert("CODICE FISCALE non corretto."); return;}

		  if (document.form1.telefono.value == "") {alert("Campo TELEFONO vuoto."); return;}
	  if (! check_numeri(document.form1.telefono.value)) {alert("Il campo TELEFONO e' errato."); return;} 
	  if (less(document.form1.telefono.value, 6)) {alert("Il campo TELEFONO e' errato."); return;} 
	  if (! check_first_tel(document.form1.telefono.value)) {alert("Il campo TELEFONO e' errato."); return;} 
	 // if (document.form1.citta_numero_pop.value == "") {alert("Campi CITTA' e NUMERO POP vuoti."); return;} 
	 // if (document.form1.distretto_pop.value == "") {alert("Campo DISTRETTO POP vuoto."); return;}  
	 // document.form1.citta_numero_text.value = "Scegli un POP";
	  document.form1.submit();   
		  showLayerNumber(1);
     }
      else
      { 
	 // document.form1.citta_numero_text.value = "Scegli un POP"; 
	  document.form1.submit(); 
		  showLayerNumber(1);
      }
  }
  else
  {
      alert("I campi PASSWORD e CONFERMA PASSWORD non combaciano."); 
      return;
  }
}

