/*global SISAL, window, Dialog*/

/**
 * La variabile rappresenta il namespace utilizzato per tutto il codice
 * javascript del palinsesto.
 */
SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE = (function VALIDAZIONE() {
    

    function matchRegExp(e, reg)
    {
        var key = null,
            keychar = null
            ;
        key = window.event ? e.keyCode : e.which;
        keychar = String.fromCharCode(key);

        if (key === 8 || key === 0)
        {    
            return true;
        }    
        else
        {    
            return reg.test(keychar);
        }    
    }
        
    function username(e) {
        return matchRegExp(e, new RegExp("[a-zA-Z.\\-_0-9]"));
    }                     

    function numsOnly(e) {
        return matchRegExp(e, new RegExp("[0-9]"));
    }

    function numCivicoCharsOnly(e) {
        //return matchRegExp(e, /[\/a-zA-Z0-9.-]/);
        return matchRegExp(e, new RegExp("[\/a-zA-Z0-9.-]"));
    }

    function numDocumentoCharsOnly(e) {
        //return matchRegExp(e, /[a-zA-Z0-9]/);
        return matchRegExp(e, new RegExp("[a-zA-Z0-9]"));
    }

    function emailCharNum(e) {
        //return matchRegExp(e, /[a-zA-Z0-9@.-]/);
        return matchRegExp(e, new RegExp("[a-zA-Z0-9@.-]"));
    }

    function promoCharsOnly(e) {
        //return matchRegExp(e, /[a-zA-Z0-9-]/);
        return matchRegExp(e, new RegExp("[a-zA-Z0-9-]"));
    }

    function alphaNumCharsOnly(e) {
        //return matchRegExp(e, /[_a-zA-Z0-9.-]/);
        return matchRegExp(e, new RegExp("[_a-zA-Z0-9.-]"));        
    }
        
    function provinciaCharsOnly(e) {
    //return matchRegExp(e, /[_a-zA-Z0-9.-]/);
    //return matchRegExp(e, new RegExp("[a-zA-Z]"));   
    return matchRegExp(e, new RegExp("[\\s\/a-zA-Z.\\-.']"));   
    }

    function nameCharsOnly(e) {
        //return matchRegExp(e, /[\s\x27a-zA-Z\xE0\xE8\xE9\xF9\xF2\xEC\x27]/);
        //return matchRegExp(e, new RegExp("[\\s\x27a-zA-Z\xE0\xE8\xE9\xF9\xF2\xEC\x27]"));
        return matchRegExp(e, new RegExp("[\\s\/a-zA-Z']")); 
    }

    function indirizzoCharsOnly(e) {    
        //return matchRegExp(e, /[\s\/a-zA-Z0-9\'\xE0\xE8\xE9\xF9\xF2\xEC\x27]/);
        return matchRegExp(e, new RegExp("[\\s\/a-zA-Z0-9\\'\xE0\xE8\xE9\xF9\xF2\xEC\x27\.\-]"));
    }                                 

    function luogoNascitaCharsOnly(e) {                                         
        //return matchRegExp(e, /[\s\/a-zA-Z0-9\xE0\xE8\xE9\xF9\xF2\xEC\x27]/);
        return matchRegExp(e, new RegExp("[\\s\/a-zA-Z0-9\xE0\xE8\xE9\xF9\xF2\xEC\x27]"));      
    }                                     

    function codiceFiscaleNumCharsOnly(e) {                                         
        //return matchRegExp(e, /[a-zA-Z0-9]/);
        return matchRegExp(e, new RegExp("[a-zA-Z0-9]"));       
    }                                     
    function risposteSicurezzaCharsOnly(e) {                                         
        //return matchRegExp(e, /[a-zA-Z0-9]/);
        //return matchRegExp(e, new RegExp("[\\s\a-zA-Z0-9\\'\xE0\xE8\xE9\xF9\xF2\xEC\x27\.\-]"));
         return matchRegExp(e, new RegExp("[\\s\/0-9a-zA-Z.\\-.']"));
    }  
        
    function luogoDiRilascioCharsOnly(e) {                                          
     return matchRegExp(e, new RegExp("[\\s\/a-zA-Z.\\-.']"));
    }  
        
    function usernameLogin(e) {                                         
        return matchRegExp(e, new RegExp("[0-9a-zA-Z.\\-_]"));
    
    }                     



    return {
        username : username,
        numsOnly : numsOnly,
        numCivicoCharsOnly : numCivicoCharsOnly,
        numDocumentoCharsOnly : numDocumentoCharsOnly,
        emailCharNum : emailCharNum,
        promoCharsOnly : promoCharsOnly,
        alphaNumCharsOnly : alphaNumCharsOnly,
        nameCharsOnly : nameCharsOnly,
        indirizzoCharsOnly : indirizzoCharsOnly,
        luogoNascitaCharsOnly : luogoNascitaCharsOnly,
        codiceFiscaleNumCharsOnly : codiceFiscaleNumCharsOnly,
        risposteSicurezzaCharsOnly : risposteSicurezzaCharsOnly,
                luogoDiRilascioCharsOnly: luogoDiRilascioCharsOnly,
                provinciaCharsOnly: provinciaCharsOnly,
        usernameLogin : usernameLogin
    };
}());

if (SISAL.logger.isInfoEnabled()) {
    SISAL.logger.info("SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE - namespace creato");
}

