Kcko
10/30/2013 - 12:09 PM

JS: text makes safe

JS: text makes safe

function makeSafe(thisText, allowSpace){
        var w = "!@#$%^&*()+=[]\\\';,./{}|\":<>?";
        var s = 'abcdefghijklmnopqrstuvwxyz0123456789-';
        var x = new Array('àáâãäå', 'çč', 'èéêëě','š','ř','ž','á', 'ìíîï', 'ñ', 'ðóòôõöø', 'ùúûüů', 'ýÿ',' ','.');
        var r = new Array('a', 'c', 'e','s','r','z','a', 'i', 'n', 'o', 'u', 'y','-','-');
 
        if(allowSpace){
                s = s + ' ';
        }
 
        thisText = thisText.toLowerCase();
        var newText = new Array();
 
        for (i = 0; i < thisText.length; i++){
                thisChar = thisText.charAt(i);
                if(w.indexOf(thisChar) == -1){
                        if(s.match(''+thisChar+'')){
                                newText[i] = thisChar;
                        }else{
                                for (j = 0; j < x.length; j++){
                                        if(x[j].match(thisChar)){
                                                newText[i] = r[j];
                                        }
                                }
                        }
                }
        }
 
        return newText.join('');
}