//*******************************************************
// Prodottto : WSC PRINTER PRO		   																							                                                                         
// Versione : 4.0                                      																						                                                                        
// Release : 01/2010                                  																					                                                                          
// Autore : Dynamicsoft di Luca Michele Ingenito                      
// Web Site : www.dynamicsoft.it                    
// Email : info@dynamicsoft.it                      																							                                                                          
//*******************************************************
// LOGIN AND USER REGISTER FUNCTION 
//*******************************************************
//CONTROLLO sqlinjection
function sqlinjection(valore)
   {
    var s=valore ;
    while(s.indexOf("'")!=-1)s=s.replace("'","");
    while(s.indexOf("&")!=-1)s=s.replace("&","e");    
    while(s.indexOf("--")!=-1)s=s.replace("--","");
    while(s.indexOf("/*")!=-1)s=s.replace("/*","");
    while(s.indexOf("*/")!=-1)s=s.replace("*/","");
    while(s.indexOf("char")!=-1)s=s.replace("char","");
    while(s.indexOf("nchar")!=-1)s=s.replace("nchar","");
    while(s.indexOf("nvarchar")!=-1)s=s.replace("nvarchar","");
    while(s.indexOf("alter")!=-1)s=s.replace("alter","");
    while(s.indexOf("begin")!=-1)s=s.replace("begin","");
    while(s.indexOf("cast")!=-1)s=s.replace("cast","");
    while(s.indexOf("create")!=-1)s=s.replace("create","");
    while(s.indexOf("cursor")!=-1)s=s.replace("cursor","");
    while(s.indexOf("declare")!=-1)s=s.replace("declare","");
    while(s.indexOf("delete")!=-1)s=s.replace("delete","");
    while(s.indexOf("drop")!=-1)s=s.replace("drop","");
    while(s.indexOf("exec")!=-1)s=s.replace("exec","");
    while(s.indexOf("execute")!=-1)s=s.replace("execute","");
    while(s.indexOf("fetch")!=-1)s=s.replace("fetch","");
    while(s.indexOf("kill")!=-1)s=s.replace("kill","");
    while(s.indexOf("open")!=-1)s=s.replace("open","");
    while(s.indexOf("select")!=-1)s=s.replace("select","");
    while(s.indexOf("sys")!=-1)s=s.replace("sys","");
    while(s.indexOf("sysobjects")!=-1)s=s.replace("sysobjects","");
    while(s.indexOf("syscolumns")!=-1)s=s.replace("syscolumns","");
    while(s.indexOf("table")!=-1)s=s.replace("table","");
    while(s.indexOf("update")!=-1)s=s.replace("update","");
    valore= s.replace('','');
    return valore; 
   }
// LOGIN 
function  FORMLOGIN()
{
	var Email=document.Login.Email.value
    Email = sqlinjection(document.Login.Email.value);
    document.Login.Email.value=Email;   
    Email=document.Login.Email.value;	
	if (Email=="")
		{
		alert("Inserisci email!");
		document.Login.Email.focus();
		return false;
		}
	if (Email.indexOf("@") == -1)
	   {
	   alert("Email non valida!");
	   document.Login.Email.focus();            
	   return false;
	   }
	if (Email.indexOf(".") == -1)
	   {
	   alert("Email non valida!");
	   document.Login.Email.focus();            
	   return false;
	   }    
	var password=document.Login.password.value
    password = sqlinjection(document.Login.password.value);
    document.Login.password.value=password;   
    password=document.Login.password.value;	
	if (password=="") 
		{
		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;
	
	
	var Email=document.Register.Email.value
    Email = sqlinjection(document.Register.Email.value);
    document.Register.Email.value=Email;   
    Email=document.Register.Email.value;	
	if (Email=="")
		{
		alert("Inserisci email!");
		document.Register.Email.focus();
		return false;
		}
	if (Email.indexOf("@") == -1)
	   {
	   alert("Email non valida!");
	   document.Register.Email.focus();            
	   return false;
	   }
	if (Email.indexOf(".") == -1)
	   {
	   alert("Email non valida!");
	   document.Register.Email.focus();            
	   return false;
	   } 
	   
	   
    var valorecampo = Email;
	
	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()
{
    var CF=document.Register.CF.value
    CF = sqlinjection(document.Register.CF.value);
    document.Register.CF.value=CF;   
    CF=document.Register.CF.value;
	if (CF=="") 
		{
		alert("Inserisci Codice Fiscale!");
		document.Register.CF.focus();
		return false;
		}
		
		
	var Indirizzo=document.Register.Indirizzo.value
    Indirizzo = sqlinjection(document.Register.Indirizzo.value);
    document.Register.Indirizzo.value=Indirizzo;   
    Indirizzo=document.Register.Indirizzo.value;	
	if (Indirizzo=="") 
		{
		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;
        }
        
    var Citta=document.Register.Citta.value
    Citta = sqlinjection(document.Register.Citta.value);
    document.Register.Citta.value=Citta;   
    Citta=document.Register.Citta.value;	    
	if (Citta=="") 
		{
		alert("Inserisci cittą !");
		document.Register.Citta.focus();
		return false;
		}
		
	var Provincia=document.Register.Provincia.value
    Provincia = sqlinjection(document.Register.Provincia.value);
    document.Register.Provincia.value=Provincia;   
    Provincia=document.Register.Provincia.value;	 	
	if (Provincia=="") 
		{
		alert("Inserisci provincia !");
		document.Register.Provincia.focus();
		return false;
		}
	
	var Email=document.Register.Email.value
    Email = sqlinjection(document.Register.Email.value);
    document.Register.Email.value=Email;   
    Email=document.Register.Email.value;	
	if (Email=="")
		{
		alert("Inserisci email!");
		document.Register.Email.focus();
		return false;
		}
	if (Email.indexOf("@") == -1)
	   {
	   alert("Email non valida!");
	   document.Register.Email.focus();            
	   return false;
	   }
	if (Email.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;
	PasswordUno = sqlinjection(document.Register.PasswordUno.value);
    document.Register.PasswordUno.value=PasswordUno;   
    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;
	PasswordDue = sqlinjection(document.Register.PasswordDue.value);
    document.Register.PasswordDue.value=PasswordDue;   
    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;
	FrmSecurityWord = sqlinjection(document.Register.FrmSecurityWord.value);
    document.Register.FrmSecurityWord.value=FrmSecurityWord;   
    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=4
		document.Register.submit()
}			  						
//REGISTRAZIONE AZIENDA
function  FORMREGISTERAZIENDA()
{

    var CF=document.Register.CF.value
    CF = sqlinjection(document.Register.CF.value);
    document.Register.CF.value=CF;   
    CF=document.Register.CF.value;
	if (CF=="") 
		{
		alert("Inserisci Codice Fiscale!");
		document.Register.CF.focus();
		return false;
		}
		
	var Piva=document.Register.Piva.value
    Piva = sqlinjection(document.Register.Piva.value);
    document.Register.Piva.value=Piva;   
    Piva=document.Register.Piva.value;
	if (Piva=="") 
		{
		alert("Inserisci Partita iva!");
		document.Register.Piva.focus();
		return false;
		}	
	
	var Indirizzo=document.Register.Indirizzo.value
    Indirizzo = sqlinjection(document.Register.Indirizzo.value);
    document.Register.Indirizzo.value=Indirizzo;   
    Indirizzo=document.Register.Indirizzo.value;	
	if (Indirizzo=="") 	
		{
		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;
        }
	var Citta=document.Register.Citta.value
    Citta = sqlinjection(document.Register.Citta.value);
    document.Register.Citta.value=Citta;   
    Citta=document.Register.Citta.value;	    
	if (Citta=="") 
		{
		alert("Inserisci cittą !");
		document.Register.Citta.focus();
		return false;
		}		
	var Provincia=document.Register.Provincia.value
    Provincia = sqlinjection(document.Register.Provincia.value);
    document.Register.Provincia.value=Provincia;   
    Provincia=document.Register.Provincia.value;	 	
	if (Provincia=="") 
		{
		alert("Inserisci provincia !");
		document.Register.Provincia.focus();
		return false;
		}
		
	var Email=document.Register.Email.value
    Email = sqlinjection(document.Register.Email.value);
    document.Register.Email.value=Email;   
    Email=document.Register.Email.value;	
	if (Email=="")
		{
		alert("Inserisci email!");
		document.Register.Email.focus();
		return false;
		}
	if (Email.indexOf("@") == -1)
	   {
	   alert("Email non valida!");
	   document.Register.Email.focus();            
	   return false;
	   }
	if (Email.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;
	PasswordUno = sqlinjection(document.Register.PasswordUno.value);
    document.Register.PasswordUno.value=PasswordUno;   
    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;
	PasswordDue = sqlinjection(document.Register.PasswordDue.value);
    document.Register.PasswordDue.value=PasswordDue;   
    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;
	FrmSecurityWord = sqlinjection(document.Register.FrmSecurityWord.value);
    document.Register.FrmSecurityWord.value=FrmSecurityWord;   
    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=5	
		document.Register.submit()
}
function  FORMREGISTER()
{
	
	//Controllo nome 
    var nome=document.Register.Nome.value
    nome = sqlinjection(nome);
    document.Register.Nome.value=nome;   
    nome=document.Register.Nome.value;
    if (nome=="") 
	    {
	    alert("Inserisci nome!");
	    document.Register.Nome.focus();
	    return false;
		}
   //Controllo cognome 
    var Cognome=document.Register.Cognome.value
    Cognome = sqlinjection(Cognome);
    document.Register.Cognome.value=Cognome;
    Cognome=document.Register.Cognome.value;
    if (Cognome=="") 
	    {
	    alert("Inserisci cognome!");
	    document.Register.Cognome.focus();
	    return false;
	    }
	var RagSoc=	document.Register.RagSoc.value
	RagSoc = sqlinjection(RagSoc);
    document.Register.RagSoc.value=RagSoc;
    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;
	   }
}	
		  

