var util = {
    urlencode : function (input) {        
        var SAFECHARS = "0123456789" + 
            "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + 
            "abcdefghijklmnopqrstuvwxyz" +
            "-_.!~*'()";
        var HEX = "0123456789ABCDEF";
    
    
        var output = '';
    
        if (typeof(input) == 'string') {
    
            input = $.trim(input);
            
            if (input != '') {
            
                for (var i = 0; i < input.length; i++) {
                    
                    var ch = input.charAt(i);
                    var charCode = ch.charCodeAt(0);
                    
                    
                    if (ch == " ") {
                        output += "+";
                    } else if (SAFECHARS.indexOf(ch) != -1) {
                        output += ch;
                    } else if (charCode > 255) {
                        output += "+";
                    } else {
                        output += "%" + HEX.charAt((charCode >> 4) & 0xF) + HEX.charAt(charCode & 0xF);
                    }
                }
                
            }
        
        }
           
        return output;
        
    }
};