function encodeURL(str){
    var result = "";
    var token;
    var code;
    
    for(var i=0 ; i<str.length ; i++)
    {
        token = str.charAt(i);
        code = str.charCodeAt(i);
        if (token == " ")
        {
        	result += "+";
        }
        else {
            if(	code == 0x2a || 
            	code == 0x2d || 
            	code == 0x2e || 
            	code == 0x5f || 
            	((code >= 0x30) && (code <= 0x39)) || 
            	((code >= 0x41) && (code <= 0x5a)) || 
            	((code >= 0x61) && (code <= 0x7a)))
            {
                result = result + token;
            }
            else 
            {
                if((code >= 0x0) && (code <= 0x7f))
                {
                    token = "0" + code.toString(16);
                    result += "%" + token.substr(token.length-2);
                }
                else if(code > 0x1fffff)
                {
                    result += "%" + (oxf0 + ((code & 0x1c0000) >> 18)).toString(16);
                    result += "%" + (0x80 + ((code & 0x3f000) >> 12)).toString(16);
                    result += "%" + (0x80 + ((code & 0xfc0) >> 6)).toString(16);
                    result += "%" + (0x80 + (code & 0x3f)).toString(16);
                }
                else if(code > 0x7ff)
                {
                    result += "%" + (0xe0 + ((code & 0xf000) >> 12)).toString(16);
                    result += "%" + (0x80 + ((code & 0xfc0) >> 6)).toString(16);
                    result += "%" + (0x80 + (code & 0x3f)).toString(16);
                }
                else 
                {
                    result += "%" + (0xc0 + ((code & 0x7c0) >> 6)).toString(16);
                    result += "%" + (0x80 + (code & 0x3f)).toString(16);
                }
            }
        }
    }
    return result;
}