//************************************CONTROLLO STRINGHE E NUMERI****************************************************
	
	function updatetext(text, nr)
	{
            if(nr == -1)
                    return text;
            var tmptext;
            tmptext = text.slice(0,nr);
            tmptext = tmptext + "" +  text.slice((nr+1),(text.length));
            return tmptext;
	}

	function checkHtmlElement(){
            for(i=0; i < document.frmReg.length ;i++)
            {
                var tmpstr,nr=0;
                tmpstr = document.frmReg[i].value;

                while(nr > -1)
                        if((nr = tmpstr.indexOf(">")) > -1 ||  (nr = tmpstr.indexOf("<")) > -1)
                                tmpstr = updatetext(tmpstr, nr);
                document.frmReg[i].value = tmpstr;
            }
            return true;
	}
			
	function isMailValid(email) {
            if (email != ""){
                    var re=/^[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz_0-9\.\-\_]+@[abcdefghijklmnopqrstuvwxyz_0-9\.\-\_]+\.[abcdefghijklmnopqrstuvwxyz]{2,3}$/i;
                    if(!re.test(email)){
                        return false;			
                    }
            }
            return true;
	}

	function checkPassword(pwd1, pwd2){
            if (pwd1 == pwd2) return true;
            else return false;
	}
	
	
	function checkNumericFields(){
            var phone  = document.frmReg.phone.value;	
            var fax = document.frmReg.fax.value;

            if (isNumber(phone) && isNumber(fax) ){
                return true;
            }else{
                return false;
            }
    	}
		
        function isNumber(stringa) {
            validi = "0123456789";
            for( i = 0; i < stringa.length; i++ ){
                    if( validi.indexOf( stringa.charAt(i) ) == -1 ){
                            alert("Phone/Fax - numeric fields")
                            return false;
                    }
            }
            return true;
	}
	
	function checkfield(lang){
            var nome = document.frmReg.name.value;
            var cognome = document.frmReg.surname.value;
            var email  = document.frmReg.email.value;
            var company = document.frmReg.company.value;
            var password = document.frmReg.password.value;
            var password2 = document.frmReg.password2.value;
            var userid = document.frmReg.userid.value;
            var privacy = document.frmReg.privacy[0].checked;
            
            checkHtmlElement();

            if ( (nome == '') || (cognome == '') || (password == '') || (password2 == '') || (email == '') || (userid == '') || (company == '')){
                if (lang == 'it')
                    alert("Compilare tutti i campi obbligatori");
                else
                    alert("You must compile all the fields");
                return false;
            }

            if (!checkPassword(password, password2)){
                if (lang == 'it')
                    alert("Attenzione. Le password inserite non coincidono.");
                else
                    alert("Password and retype password must be equals.");
                return false;
            }

            if (!isMailValid(email)){
                if (lang == 'it')
                    alert("Attenzione. Il formato dell' indirizzo email non è valido");
                else
                    alert("Email address format is not valid");
                return false;	
            }

            if (!checkNumericFields()){
                return false;	
            }

            if (!privacy){
                if (lang == 'it')
                    alert("Attenzione. E' necessario fornire l'autorizzazione al trattamento dei dati personali");
                else
                    alert("You have to approve my personal data's treatment");
                return false;	
            }

            return true;
	}
	
	// controlli sulla LOGIN
	function checkfield2(lang){
            var password = document.frmReg.password.value;
            var userid = document.frmReg.userid.value;
		
            checkHtmlElement();
		
            if ( password == '' || userid == ''){
                if (lang == 'it')
                    alert("Prego specificare Userid e Password");
                else
                    alert("Please specify Userid and Password");
                return false;
            }
	}
	