if(typeof nf == 'undefined') {
nf = function() {
var m, ret, i;
if(arguments.length == 1) {
if(arguments[0].nodeType) {
return arguments[0];
}
if(m = arguments[0].match(/^#([\w$]+)$/)) {
return document.getElementById(m[1]);
}
}
if(arguments.length >= 1) {
if(m = arguments[0].match(/^<(\w*)\s*\/?(>?)$/)) {
ret = m[2]
? document.createElement(m[1])
: document.createTextNode(arguments[2]);
if(arguments.length > 1 && arguments[1] !== null) {
nf(arguments[1]).appendChild(ret);
}
if(arguments.length > 2 && m[2]) {
for(i in arguments[2]) {
try {
ret[i] = arguments[2][i];
} catch(e) {
}
}
}
return ret;
}
}
};
}
nf.json_encode = function(value, whitelist) {
var charsub = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"': '\\"',
'\\': '\\\\'
};
var a, i, k, l, v;
var r = /["\\\x00-\x1F\x7F-\uFFEF]/g;
switch(typeof value) {
case 'string':
return r.test(value) ?
'"' + value.replace(r, function(a) {
if(a in charsub) {
return charsub[a];
}
var c = a.charCodeAt().toString(16);
while(c.length < 4) {
c = '0' + c;
}
return '\\u' + c;
}) + '"' :
'"' + value + '"';
case 'number':
return isFinite(value) ? String(value) : 'null';
case 'boolean':
case 'null':
return String(value);
case 'object':
if(!value) {
return 'null';
}
if(typeof value.toJSON === 'function') {
return value.toJSON();
}
a = [];
if(typeof value.length === 'number' && !(value.propertyIsEnumerable('length'))) {
l = value.length;
for(i = 0; i < l; i++) {
a.push(nf.json_encode(value[i], whitelist) || 'null');
}
return '[' + a.join(',') + ']';
}
if(whitelist) {
l = whitelist.length;
for(i = 0; i < l; i++) {
k = whitelist[i];
if(typeof k === 'string') {
v = nf.json_encode(value[k], whitelist);
if(v) {
a.push(nf.json_encode(k) + ':' + v);
}
}
}
} else {
for(k in value) {
if(typeof k === 'string') {
v = nf.json_encode(value[k], whitelist);
if(v) {
a.push(nf.json_encode(k) + ':' + v);
}
}
}
}
return '{' + a.join(',') + '}';
}
};
nf.className = function(node, classname) {
if(!node) {
return false;
}
if(node.nodeType != 1) {
return false;
}
var classes = node.className ? node.className.replace(/(^\s+|\s+$)/, '').split(/\s+/) : new Array();
var found = -1;
for(var i = 0; i < classes.length; i++) {
if(classes[i] == classname) {
found = i;
}
}
var action;
if(action = arguments[2]) {
if(found >= 0 && action < 0) {
classes[found] = null;
}
if(found == -1 && action > 0) {
classes[classes.length] = classname;
}
} else {
return found >= 0;
}
for(i = 0; i < classes.length; i++) {
if(!classes[i]) {
classes.splice(i, 1);
}
}
node.className = classes.join(' ');
};
nf.api = {
endpoint: null,
password: null,
version: 8,
headers: [],
get: function(path, callback) {
return new this.Call("GET", path, null, callback);
},
post: function(path, data, callback) {
return new this.Call("POST", path, data, callback);
},
put: function(path, data, callback) {
return new this.Call("PUT", path, data, callback);
},
del: function(path, callback) {
return new this.Call("DELETE", path, null, callback);
},
Call: function(method, path, data, callback) {
if(nf.api.endpoint === null) {
return false;
}
var e;
try {
this.xh = new XMLHttpRequest()
}
catch(e) {
try {
this.xh = new ActiveXObject('Msxml2.XMLHTTP')
}
catch(e) {
try {
this.xh = new ActiveXObject('Microsoft.XMLHTTP')
}
catch(e) {
this.xh = false;
}
}
}
if(!this.xh) {
return false;
}
this.xh.owner = this;
this.method = method;
this.path = path;
this.data = data;
this.callback = callback;
this.xh.onreadystatechange = this.stateChange;
this.xh.open(
"POST",
nf.api.endpoint +
( nf.api.password
? "?pw=" + encodeURIComponent(nf.api.password)
: ''
),
true
);
this.xh.setRequestHeader('Content-Type', 'application/x-netfira-webconnect-packed');
this.body = method + " /" + nf.api.version + "/" + path + " HTTP/1.1\r\n";
if(!nf.api.headers['Content-Type']) {
nf.api.headers['Content-Type'] = 'application/json'
}
for(e in nf.api.headers) {
if(nf.api.headers.hasOwnProperty(e)) // <----------- This stops methods being added to post data
{
this.body += e + ': ' + nf.api.headers[e] + "\r\n";
}
}
if(data !== null) {
if(typeof data == 'string') {
if('sendAsBinary' in this.xh) {
this.body += "\r\n" + data;
}
else {
this.body += "Content-Encoding: base64\r\n\r\n" + nf.base64.encode(data);
}
}
else if(typeof data == 'object') {
this.body += "\r\n" + nf.json_encode(data);
}
}
this.xh.sendAsBinary
? this.xh.sendAsBinary(this.body)
: this.xh.send(this.body);
},
findEndpoint: function() {
var scripts = document.getElementsByTagName('script');
var a = scripts[scripts.length - 1].src.split('?', 2);
this.endpoint = a[0].replace(/\/\d+\/web\/nf\.js/, '');
// this.endpoint=a; // if(a.length<2) return; // var p=a.split('&'); // var d={}; // for(var i=0;i<p.length;i++){ // a=p.split('=',2); // d[decodeURIComponent(a)]=decodeURIComponent(a); // } // if('pw' in d) this.password=d.pw; // if('v' in d) this.version=parseFloat(d.v);
}
}
nf.api.Call.prototype = {
stateChange: function() {
if(this.readyState != 4) {
return;
}
this.owner.success = this.status == 200 || this.status == 201;
var r, t = this.responseText || '';
if(this.owner.success && t.match(/^[{[][\s\S]*[}\]]/)) {
eval('r=' + t + ';');
this.owner.success &= !r.errorCode;
} else {
r = t;
}
if(!this.owner.success && ('onerror' in this.owner)) {
this.owner.onerror(r);
}
else {
this.owner.callback(r);
}
},
cancel: function() {
this.callback = function() {
};
return null;
},
set: function(name, value) {
this[name] = value;
return this;
}
}; nf.currency = function(n, dec, symbol) {
symbol = symbol || '$';
if(typeof n == 'string') {
n = parseFloat(n.replace(/[^-\d.]/g, '').replace(/^$/, '0'));
}
var neg = false;
if(neg = n < 0) {
n *= -1;
}
n = Math.round(n * 100) / 100;
if(!dec) {
dec = n == Math.floor(n) ? -1 : 1;
}
var ret = Math.floor(n).toString();
while(ret.match(/\d{4}/)) {
ret = ret.replace(/^(.*\d)(\d{3})(,|$)/, '$1,$2$3');
}
if(dec > 0) {
ret += '.' + n.toFixed(2).toString().replace(/\d+\./, '');
}
return symbol + (neg ? '-' : '') + ret;
};
nf.ucfirst = function(str) {
if(typeof str !== 'string') {
str = str.toString();
}
if(str == '') {
return '';
}
var ret = str.substr(0, 1).toUpperCase();
if(str.length > 1) {
ret += str.substr(1).toLowerCase();
}
return ret;
};
nf.base64 = {
pool: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function(input) {
var output = "", c = [], e, i = 0, j;
while(i < input.length) {
for(j = 0; j < 3; j++) {
c[j] = input.charCodeAt(i++);
}
e = [c[0] >> 2, ((c[0] & 3) << 4) | (c[1] >> 4), ((c[1] & 0xF) << 2) | (c[2] >> 6), c[2] & 0x3F];
if(isNaN(c[1])) {
e[2] = e[3] = 64;
}
else if(isNaN(c[2])) {
e[3] = 64;
}
for(j = 0; j < 4; j++) {
output += this.pool.charAt(e[j]);
}
}
return output;
},
decode: function(input) {
var output = "", c, e = [], i = 0, j;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while(i < input.length) {
for(j = 0; j < 4; j++) {
e[j] = this.pool.indexOf(input.charAt(i++));
}
c = [(e[0] << 2) | (e[1] >> 4), ((e[1] & 0xF) << 4) | (e[2] >> 2), ((e[2] & 3) << 6) | e[3]];
for(j = 0; j < 3; j++) {
if(!j || e[j + 1] != 64) {
output += String.fromCharCode(c[j]);
}
}
}
return output;
},
validate: function(input) {
return !!input.toString().match(/^(?:[/+a-z0-9]{4})*(?:[/+a-z0-9]{2}[=/+a-z0-9]{2})?$/i);
}
};
nf.md5 = function(string, raw) {
var s = arguments.callee.support,
x = s.toWordArray(string),
l = x.length, f = raw ? s.wordToString : s.wordToHex,
k, A, B, C, D, a, b, c, d,
S11 = 7, S12 = 12, S13 = 17, S14 = 22,
S21 = 5, S22 = 9 , S23 = 14, S24 = 20,
S31 = 4, S32 = 11, S33 = 16, S34 = 23,
S41 = 6, S42 = 10, S43 = 15, S44 = 21;
a = 0x67452301;
b = 0xEFCDAB89;
c = 0x98BADCFE;
d = 0x10325476;
for(k = 0; k < l; k += 16) {
A = a;
B = b;
C = c;
D = d;
a = s.f(a, b, c, d, x[k + 0], S11, 0xD76AA478);
d = s.f(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
c = s.f(c, d, a, b, x[k + 2], S13, 0x242070DB);
b = s.f(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
a = s.f(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
d = s.f(d, a, b, c, x[k + 5], S12, 0x4787C62A);
c = s.f(c, d, a, b, x[k + 6], S13, 0xA8304613);
b = s.f(b, c, d, a, x[k + 7], S14, 0xFD469501);
a = s.f(a, b, c, d, x[k + 8], S11, 0x698098D8);
d = s.f(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
c = s.f(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
b = s.f(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
a = s.f(a, b, c, d, x[k + 12], S11, 0x6B901122);
d = s.f(d, a, b, c, x[k + 13], S12, 0xFD987193);
c = s.f(c, d, a, b, x[k + 14], S13, 0xA679438E);
b = s.f(b, c, d, a, x[k + 15], S14, 0x49B40821);
a = s.g(a, b, c, d, x[k + 1], S21, 0xF61E2562);
d = s.g(d, a, b, c, x[k + 6], S22, 0xC040B340);
c = s.g(c, d, a, b, x[k + 11], S23, 0x265E5A51);
b = s.g(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
a = s.g(a, b, c, d, x[k + 5], S21, 0xD62F105D);
d = s.g(d, a, b, c, x[k + 10], S22, 0x2441453);
c = s.g(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
b = s.g(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
a = s.g(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
d = s.g(d, a, b, c, x[k + 14], S22, 0xC33707D6);
c = s.g(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
b = s.g(b, c, d, a, x[k + 8], S24, 0x455A14ED);
a = s.g(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
d = s.g(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
c = s.g(c, d, a, b, x[k + 7], S23, 0x676F02D9);
b = s.g(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
a = s.h(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
d = s.h(d, a, b, c, x[k + 8], S32, 0x8771F681);
c = s.h(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
b = s.h(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
a = s.h(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
d = s.h(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
c = s.h(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
b = s.h(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
a = s.h(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
d = s.h(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
c = s.h(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
b = s.h(b, c, d, a, x[k + 6], S34, 0x4881D05);
a = s.h(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
d = s.h(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
c = s.h(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
b = s.h(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
a = s.i(a, b, c, d, x[k + 0], S41, 0xF4292244);
d = s.i(d, a, b, c, x[k + 7], S42, 0x432AFF97);
c = s.i(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
b = s.i(b, c, d, a, x[k + 5], S44, 0xFC93A039);
a = s.i(a, b, c, d, x[k + 12], S41, 0x655B59C3);
d = s.i(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
c = s.i(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
b = s.i(b, c, d, a, x[k + 1], S44, 0x85845DD1);
a = s.i(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
d = s.i(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
c = s.i(c, d, a, b, x[k + 6], S43, 0xA3014314);
b = s.i(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
a = s.i(a, b, c, d, x[k + 4], S41, 0xF7537E82);
d = s.i(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
c = s.i(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
b = s.i(b, c, d, a, x[k + 9], S44, 0xEB86D391);
a = s.add(a, A);
b = s.add(b, B);
c = s.add(c, C);
d = s.add(d, D);
}
return f(a) + f(b) + f(c) + f(d);
}
nf.md5.support = {
rotate: function(v, o) {
return (v << o) | (v >>> (32 - o));
},
add: function(lX, lY) {
var lX4, lY4, lX8, lY8, r;
lX8 = (lX & 0x80000000);
lY8 = (lY & 0x80000000);
lX4 = (lX & 0x40000000);
lY4 = (lY & 0x40000000);
r = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
if(lX4 & lY4) {
return (r ^ 0x80000000 ^ lX8 ^ lY8);
}
if(lX4 | lY4) {
if(r & 0x40000000) {
return (r ^ 0xC0000000 ^ lX8 ^ lY8);
} else {
return (r ^ 0x40000000 ^ lX8 ^ lY8);
}
} else {
return (r ^ lX8 ^ lY8);
}
},
F: function(x, y, z) {
return (x & y) | ((~x) & z);
},
G: function(x, y, z) {
return (x & z) | (y & (~z));
},
H: function(x, y, z) {
return (x ^ y ^ z);
},
I: function(x, y, z) {
return (y ^ (x | (~z)));
},
f: function(a, b, c, d, x, s, ac) {
return this.z(a, b, c, d, x, s, ac, this.F);
},
g: function(a, b, c, d, x, s, ac) {
return this.z(a, b, c, d, x, s, ac, this.G);
},
h: function(a, b, c, d, x, s, ac) {
return this.z(a, b, c, d, x, s, ac, this.H);
},
i: function(a, b, c, d, x, s, ac) {
return this.z(a, b, c, d, x, s, ac, this.I);
},
z: function(a, b, c, d, x, s, ac, f) {
return this.add(this.rotate(this.add(a, this.add(this.add(f(b, c, d), x), ac)), s), b);
},
toWordArray: function(string) {
var c,
l = string.length,
n1 = l + 8,
n2 = (n1 - (n1 % 64)) / 64,
n = (n2 + 1) * 16,
a = Array(n - 1),
bp = 0,
bc = 0;
while(bc < l) {
c = (bc - (bc % 4)) / 4;
bp = (bc % 4) * 8;
a[c] = (a[c] | (string.charCodeAt(bc) << bp));
bc++;
}
c = (bc - (bc % 4)) / 4;
bp = (bc % 4) * 8;
a[c] = a[c] | (0x80 << bp);
a[n - 2] = l << 3;
a[n - 1] = l >>> 29;
return a;
},
wordToHex: function(l) {
var r = "", t = "", b, c;
for(c = 0; c < 4; c++) {
b = (l >>> (c * 8)) & 255;
t = "0" + b.toString(16);
r = r + t.substr(t.length - 2, 2);
}
return r;
},
wordToString: function(l) {
var r = '', i;
for(i = 0; i < 4; i++) {
r += String.fromCharCode((l >> (i * 8)) & 0xFF);
}
return r;
}
};
nf.timeString = function() {
var d = new Date();
return ((d.getHours() + 11) % 12 + 1) + ':' +
d.getMinutes().toString().replace(/^(\d)$/, '0$1') + ':' +
d.getSeconds().toString().replace(/^(\d)$/, '0$1') +
(d.getHours() < 12 ? 'am' : 'pm');
};
Date.prototype.toJSON = function() {
return (this.getUTCFullYear() + '-' +
(this.getUTCMonth() + 1) + '-' +
this.getUTCDate() + 'T' +
this.getUTCHours() + ':' +
this.getUTCMinutes() + ':' +
this.getUTCSeconds() + 'Z')
.replace(/([^\d])(\d)([^\d])/g, '$10$2$3');
};
if(!String.prototype.trim) {
String.prototype.trim = function() {
return this.replace(/(^\s+|\s+$)/g, '');
};
}
if(!Array.prototype.forEach) {
Array.prototype.forEach = function(func, scope) {
scope = scope || this;
for(var i = 0, l = this.length; i < l; i++) {
func.call(scope, this[i], i, this);
}
};
}
if(!Array.prototype.filter) {
Array.prototype.filter = function(func, scope) {
scope = scope || this;
var ret = [];
for(var i = 0, l = this.length; i < l; i++) {
if(func.call(scope, this[i], i, this)) {
ret.push(this[i]);
}
}
return ret;
};
}
if(!Array.prototype.map) {
Array.prototype.map = function(func, scope) {
scope = scope || this;
var ret = [];
for(var i = 0, l = this.length; i < l; i++) {
ret.push(func.call(scope, this[i], i, this));
}
return ret;
};
}
if(!String.prototype.toHTML) {
String.prototype.toHTML = function() { return this .replace('&', '&') .replace('<', '<') .replace('>', '>') .replace('"', '"') };
}
if(!Array.prototype.indexOf) {
Array.prototype.indexOf = function(elt) {
var len = this.length;
var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if(from < 0) {
from += len;
}
for(; from < len; from++) {
if(from in this && this[from] === elt) {
return from;
}
}
return -1;
};
}
nf.api.findEndpoint();