+
+/* From: www.webtoolkit.info */
+qwebirc.util.b64Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+qwebirc.util.b64Encode = function(data) {
+ var output = [];
+ var table = qwebirc.util.b64Table;
+ for(var i=0;i<data.length;) {
+ var chr1 = data.charCodeAt(i++);
+ var chr2 = data.charCodeAt(i++);
+ var chr3 = data.charCodeAt(i++);
+
+ var enc1 = chr1 >> 2;
+ var enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
+ var enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
+ var enc4 = chr3 & 63;
+
+ if(isNaN(chr2)) {
+ enc3 = enc4 = 64;
+ } else if(isNaN(chr3)) {
+ enc4 = 64;
+ }
+
+ output.push(table.charAt(enc1) + table.charAt(enc2) + table.charAt(enc3) + table.charAt(enc4));
+ }
+ return output.join("");
+}
+
+/* From: www.webtoolkit.info */
+qwebirc.util.b64Decode = function(data) {
+ data = data.replace(/[^A-Za-z0-9\+\/\=]/g, "");
+
+ var output = [];
+ var table = qwebirc.util.b64Table;
+
+ /* grossly inefficient... so sue me */
+ while(data.length % 4 != 0)
+ data = data + "=";
+
+ for(var i=0;i<data.length;) {
+ var enc1 = table.indexOf(data.charAt(i++));
+ var enc2 = table.indexOf(data.charAt(i++));
+ var enc3 = table.indexOf(data.charAt(i++));
+ var enc4 = table.indexOf(data.charAt(i++));
+
+ var chr1 = (enc1 << 2) | (enc2 >> 4);
+ var chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
+ var chr3 = ((enc3 & 3) << 6) | enc4;
+
+ output.push(String.fromCharCode(chr1));
+ if (enc3 != 64)
+ output.push(String.fromCharCode(chr2));
+ if (enc4 != 64)
+ output.push(String.fromCharCode(chr3));
+ }
+
+ return output.join("");
+}
+
+qwebirc.util.composeAnd = function() {
+ var xargs = arguments;
+
+ return function() {
+ for(var i=0;i<xargs.length;i++)
+ if(!xargs[i].apply(this, arguments))
+ return false;
+
+ return true;
+ }
+}
+
+qwebirc.util.invertFn = function(fn) {
+ return function() {
+ return !fn.apply(this, arguments);
+ }
+}
+
+qwebirc.util.deviceHasKeyboard = function() {
+ var determine = function() {
+ if(Browser.Engine.ipod)
+ return true;
+
+ var MOBILE_UAs = ["Nintendo Wii", " PIE", "BlackBerry", "IEMobile", "Windows CE", "Nokia", "Opera Mini", "Mobile", "mobile", "Pocket", "pocket", "Android"];
+ /* safari not included because iphones/ipods send that, and we checked for iphone/ipod specifically above */
+ var DESKTOP_UAs = ["Chrome", "Firefox", "Camino", "Iceweasel", "K-Meleon", "Konqueror", "SeaMonkey", "Windows NT", "Windows 9"];
+
+ var ua = navigator.userAgent;
+
+ var contains = function(v) {
+ return ua.indexOf(v) > -1;
+ }
+
+ for(var i=0;i<MOBILE_UAs.length;i++)
+ if(contains(MOBILE_UAs[i]))
+ return false;
+
+ for(var i=0;i<DESKTOP_UAs.length;i++)
+ if(contains(DESKTOP_UAs[i]))
+ return true;
+
+ return false;
+ };
+ var v = determine();
+
+ qwebirc.util.deviceHasKeyboard = function() {
+ return v;
+ }
+
+ return v;
+}
+
+qwebirc.util.generateID_ID = 0;
+qwebirc.util.generateID = function() {
+ return "qqa-" + qwebirc.util.generateID_ID++;
+};
+
+qwebirc.util.arrayCmp = function(a, b) {
+ for(var p=0;p<a.length;p++) {
+ var ap = a[p];
+ var bp = b[p];
+ if(ap == bp)
+ continue;
+
+ if(ap < bp)
+ return -1;
+
+ return 1;
+ }
+ return 0;
+};
+
+qwebirc.util.__log = function(x) {
+ if(QWEBIRC_DEBUG) {
+ if(typeof console == "undefined") {
+ alert("log: " + x);
+ } else {
+ console.log(x);
+ }
+ }
+};
+
+qwebirc.util.logger = {
+ log: function(x) { qwebirc.util.__log("L " + x) },
+ info: function(x) { qwebirc.util.__log("I " + x) },
+ error: function(x) { qwebirc.util.__log("E " + x) },
+ warn: function(x) { qwebirc.util.__log("W " + x) }
+};
+
+qwebirc.util.log = qwebirc.util.logger.log;