function hexToString(hexstr) {
var temp = '';
for (var j = 0; j < hexstr.length;) {
temp += '%' + hexstr.substring(j, j + 2);
j +=2;
}
var numChars = temp.length;
var sb = "";
var i = 0;
var c = "";
var bytes = null;
while (i < numChars) {
c = temp.charAt(i);
switch (c) {
case '+':
sb.append(' ');
i++;
break;
case '%':
if (bytes == null)
bytes = new Array((numChars - i) / 3);
var pos = 0;
while (((i + 2) < numChars) &&
(c == '%')) {
var v = parseInt(temp.substring(i + 1, i + 3), 16);
if (v >= 0)
bytes[pos++] = v;
i += 3;
if (i < numChars)
c = temp.charAt(i);
}
sb += decodeUtf8(bytes);
break;
default:
sb += c;
i++;
break;
}
}
return sb;
}
function decodeUtf8(bytes) {
var encoded = "";
for (var i = 0; i < bytes.length; i++) {
encoded += '%' + bytes[i].toString(16);
}
return decodeURIComponent(encoded);
}