//*******************************************************
// Prodottto : WSC PRINTER PRO		   																							                                                                         
// Versione : 2.1                                       																						                                                                        
// Release : 03/2008                                   																					                                                                          
// Autore : Dynamicsoft di Luca Michele Ingenito                      
// Web Site : www.dynamicsoft.it                    
// Email : info@dynamicsoft.it                      																							                                                                          
//*******************************************************
// LOGIN AND USER REGISTER FUNCTION 
//*******************************************************
// LOGIN 
function  FORMLOGIN()
{
	if (document.Login.Email=="")
		{
		alert("Inserisci email ! ");
		document.Login.Email.focus();
		return false;
		}
	if (document.Login.Email.value.indexOf("@") == -1)
	   {
	   alert("Email non valida ! ");
	   document.Login.Email.focus();            
	   return false;
	   }
	if (document.Login.Email.value.indexOf(".") == -1)
	   {
	   alert("Email non valida ! ");
	   document.Login.Email.focus();            
	   return false;
	   } 
	if (document.Login.password.value=="") 
		{
		alert("Inserisci password ! ");
		document.Login.password.focus();
		return false;
		}
}
//VERIFY EMAIL USER
  var ricerca_pro;
  function verificauser()
{
	var re_empty = new RegExp("[ ]");
	var re_login_pwd = new RegExp("[^a-zA-Z0-9\_\.]");
	var User = document.Register.Email.value;
	if (document.Register.Email=="")
		{
		alert("Inserisci email");
		document.Register.Email.focus();
		return false;
		}
	if (document.Register.Email.value.indexOf("@") == -1)
	   {
	   alert("Email non valida");
	   document.Register.Email.focus();            
	   return false;
	   }
	if (document.Register.Email.value.indexOf(".") == -1)
	   {
	   alert("Email non valida");
	   document.Register.Email.focus();            
	   return false;
	   } 
    var valorecampo = document.Register.Email.value;
	
	if (window.XMLHttpRequest) 
		{
		ricerca_pro = new XMLHttpRequest();
		ricerca_pro.onreadystatechange = ricevi;
		ricerca_pro.open("GET", "default.asp?PagePart=VerificaUser&reg="+valorecampo,true);
		ricerca_pro.send(null);
		
		// per IE 
		} 
	else if (window.ActiveXObject)
	{
		ricerca_pro = new ActiveXObject("Microsoft.XMLHTTP");
			if (ricerca_pro) 
			{
			ricerca_pro.onreadystatechange = ricevi;
			ricerca_pro.open("GET", "default.asp?PagePart=VerificaUser&reg="+valorecampo,true);
			ricerca_pro.send();
			}
	}
	
}
  function ricevi() {   
	var strRes;       
	var arrValori;      
	  if (ricerca_pro.readyState == 4 && ricerca_pro.status == 200) {	    
		  strRes=ricerca_pro.responseText;
		  //alert(strRes)
		if (strRes==0){
		    //alert("libero")
			document.getElementById("Box-RegistrazioneUtente-Box-VerificaUtente").innerHTML = ""
			document.getElementById("Box-RegistrazioneUtente-Box-VerificaUtenteNo").style.display="none";
			document.getElementById("Box-RegistrazioneUtente-Box-VerificaUtente").style.display="inline";
			}else if (strRes==1){
			 //alert("occupato")
			document.getElementById("Box-RegistrazioneUtente-Box-VerificaUtenteNo").innerHTML = "Attenzione ! Indirizzo email gi&aacute; presente."
			document.getElementById("Box-RegistrazioneUtente-Box-VerificaUtente").style.display="none";
			document.getElementById("Box-RegistrazioneUtente-Box-VerificaUtenteNo").style.display="inline";
			document.Register.Email.value="";
			document.Register.Email.focus();
			return false;
			}		 
		 }
	}

//CONTROLLO PARTITA IVA 
function partitaIVA(sz_Codice)
   {
   var n_Val,n_Som1=0,n_Som2=0,lcv;
   if (sz_Codice.length!=11 || isNaN(parseFloat(sz_Codice)) || parseFloat(sz_Codice)<parseFloat(0))
	  return false;
   
   for (lcv=0;lcv<9;lcv+=2)
   {
	  n_Val=parseInt(sz_Codice.charAt(lcv));
	  n_Som1+=n_Val;
	  n_Val=parseInt(sz_Codice.charAt(lcv+1));
	  n_Som1+=Math.floor(n_Val/5) + (n_Val<<1) % 10;
   }
   n_Som2 = 10 - (n_Som1 % 10);
   n_Val=parseInt(sz_Codice.charAt(10));
   if (n_Som2==n_Val)
	  return true;
   return false;
   }	
//REGISTRAZIONE UTENTE PRIVATO
function  FORMREGISTERPRIVATO()
{
	if (document.Register.CF.value=="") 
		{
		alert("Inserisci Codice Fiscale!");
		document.Register.CF.focus();
		return false;
		}
	if (document.Register.Indirizzo.value=="") 
		{
		alert("Inserisci indirizzo!");
		document.Register.Indirizzo.focus();
		return false;
		}
    var re_not_number = new RegExp("[^0-9]");
    var Cap = document.Register.Cap.value;
    if((re_not_number.Cap || Cap.length < 5))
		{
		alert("Il CAP inserito deve contenere 5 numeri");
		document.Register.Cap.focus();
		return false;
        }
	if (document.Register.Citta.value=="") 
		{
		alert("Inserisci cittą !");
		document.Register.Citta.focus();
		return false;
		}
	if (document.Register.Provincia.value=="") 
		{
		alert("Inserisci provincia !");
		document.Register.Provincia.focus();
		return false;
		}
	if (document.Register.Email=="")
		{
		alert("Inserisci email!");
		document.Register.Email.focus();
		return false;
		}
	if (document.Register.Email.value.indexOf("@") == -1)
	   {
	   alert("Email non valida!");
	   document.Register.Email.focus();            
	   return false;
	   }
	if (document.Register.Email.value.indexOf(".") == -1)
	   {
	   alert("Email non valida!");
	   document.Register.Email.focus();            
	   return false;
	   } 
	var re_empty = new RegExp("[ ]");
	var re_login_pwd = new RegExp("[^a-zA-Z0-9\_\.]");
	var PasswordUno = document.Register.PasswordUno.value;
	if (re_empty.PasswordUno || PasswordUno.length < 4 || PasswordUno.length > 8)
		{
		alert("La password deve essere min 4 max 8 caratteri ");
		document.Register.PasswordUno.focus();
		return false;
		}
	if(re_login_pwd.PasswordUno)
		{
		alert("La password puo\' contenere solo lettere, numeri, \"_\" o \".\"");
		document.Register.PasswordUno.focus();
		return false;
		}
//Controllo sulla Password2
	var PasswordDue = document.Register.PasswordDue.value;
	if (PasswordDue != PasswordUno)
		{
		alert("Le due Password inserite non corrispondono");
		document.Register.PasswordDue.focus();
		return false;
		}
//Controllo sulla KeyWord
	var FrmSecurityWordValue = document.Register.FrmSecurityWordValue.value;
	var FrmSecurityWord = document.Register.FrmSecurityWord.value;

	if (FrmSecurityWord != FrmSecurityWordValue)
		{
		alert("I caratteri inseriti non corrispondono con quelli dell'immagine!");
		document.Register.FrmSecurityWord.focus();
		return false;
		}
	if(eval(document.Register.InfoPrivacy[0].checked))
		{
		alert("Attenzione per registrarsi si devono accettare le condizione indicate nella informativa! ");
		return false;
		}
        document.Register.TipologiaRegistrazione.value=1
		document.Register.submit()
}			  						
//REGISTRAZIONE AZIENDA
function  FORMREGISTERAZIENDA()
{
	if (document.Register.CF.value=="") 
		{
		alert("Inserisci Codice Fiscale!");
		document.Register.CF.focus();
		return false;
		}
    var PIvaOk=partitaIVA(document.Register.Piva.value)
    if (PIvaOk==false)
	   {
	   alert("Partita IVA errata");
	   document.Register.Piva.focus();
	   return false;
	   }
	if (document.Register.Indirizzo.value=="") 
		{
		alert("Inserisci indirizzo!");
		document.Register.Indirizzo.focus();
		return false;
		}
    var re_not_number = new RegExp("[^0-9]");
    var Cap = document.Register.Cap.value;
    if((re_not_number.Cap || Cap.length < 5))
		{
		alert("Il CAP inserito deve contenere 5 numeri");
		document.Register.Cap.focus();
		return false;
        }
	if (document.Register.Citta.value=="") 
		{
		alert("Inserisci cittą !");
		document.Register.Citta.focus();
		return false;
		}
	if (document.Register.Provincia.value=="") 
		{
		alert("Inserisci provincia !");
		document.Register.Provincia.focus();
		return false;
		}
	if (document.Register.Email=="")
		{
		alert("Inserisci email!");
		document.Register.Email.focus();
		return false;
		}
	if (document.Register.Email.value.indexOf("@") == -1)
	   {
	   alert("Email non valida!");
	   document.Register.Email.focus();            
	   return false;
	   }
	if (document.Register.Email.value.indexOf(".") == -1)
	   {
	   alert("Email non valida!");
	   document.Register.Email.focus();            
	   return false;
	   } 
	var re_empty = new RegExp("[ ]");
	var re_login_pwd = new RegExp("[^a-zA-Z0-9\_\.]");
	var PasswordUno = document.Register.PasswordUno.value;
	if (re_empty.PasswordUno || PasswordUno.length < 4 || PasswordUno.length > 8)
		{
		alert("La password deve essere min 4 max 8 caratteri ");
		document.Register.PasswordUno.focus();
		return false;
		}
	if(re_login_pwd.PasswordUno)
		{
		alert("La password puo\' contenere solo lettere, numeri, \"_\" o \".\"");
		document.Register.PasswordUno.focus();
		return false;
		}
//Controllo sulla Password2
	var PasswordDue = document.Register.PasswordDue.value;
	if (PasswordDue != PasswordUno)
		{
		alert("Le due Password inserite non corrispondono");
		document.Register.PasswordDue.focus();
		return false;
		}
//Controllo sulla KeyWord
	var FrmSecurityWordValue = document.Register.FrmSecurityWordValue.value;
	var FrmSecurityWord = document.Register.FrmSecurityWord.value;

	if (FrmSecurityWord != FrmSecurityWordValue)
		{
		alert("I caratteri inseriti non corrispondono con quelli dell'immagine!");
		document.Register.FrmSecurityWord.focus();
		return false;
		}
	if(eval(document.Register.InfoPrivacy[0].checked))
		{
		alert("Attenzione per registrarsi si devono accettare le condizione indicate nella informativa! ");
		return false;
		}
	    document.Register.TipologiaRegistrazione.value=2	
		document.Register.submit()
}
function  FORMREGISTER()
{
	if (document.Register.Nome.value=="") 
		{
		alert("Inserisci nome!");
		document.Register.Nome.focus();
		return false;
		}
	if (document.Register.Cognome.value=="") 
		{
		alert("Inserisci cognome!");
		document.Register.Cognome.focus();
		return false;
		}
	var RagSoc=	document.Register.RagSoc.value
	if (RagSoc=="")
	   {
	   //alert("Privato!");
	   document.getElementById("Box-RegistrazioneUtente-Box-TipoUtente").innerHTML = "Registrazione privato"
	   FORMREGISTERPRIVATO();
	   return true;
	   } 
	   else if (RagSoc!="")
	   {
		document.getElementById("Box-RegistrazioneUtente-Box-TipoUtente").innerHTML = "Registrazione azienda"
		//alert("Azienda!");
		FORMREGISTERAZIENDA();
		return true;
	   }
}	
		  

