//解析url参数
	String.prototype.getQueryString = function(name) {
    	var reg = new RegExp("(^|&|\\?)" + name + "=([^&]*)(&|$)"), r;
    	if (r = this.match(reg)) return  r[2];
    	return null;
    };
    
    //获取参数值
 function getParam(par){
    	var paramstr=location.search.getQueryString(par);
    	if(paramstr==null||paramstr==undefined)
    	   paramstr='';
		return paramstr;
	}

 //创建cookie
function    SetCookie(sName, sValue) {
        var Days = 100;
        var exp = new Date();
        exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
        document.cookie = sName + "= " + escape(sValue) + ";expires= " + exp.toGMTString();
    }

//获取cookie
function    GetCookie(sName) {
        var aCookie = document.cookie.split("; ");
        for (var i = 0; i < aCookie.length; i++) {
            var aCrumb = aCookie[i].split("=");
            if (sName == aCrumb[0])
                return unescape(aCrumb[1]);
        }
        return '';
    }

function hex_sha1(e) {
  return binb2hex(core_sha1(str2binb(e), e.length * chrsz));
}
function b64_sha1(e) {
  return binb2b64(core_sha1(str2binb(e), e.length * chrsz));
}
function str_sha1(e) {
  return binb2str(core_sha1(str2binb(e), e.length * chrsz));
}
function hex_hmac_sha1(e, t) {
  return binb2hex(core_hmac_sha1(e, t));
}
function b64_hmac_sha1(e, t) {
  return binb2b64(core_hmac_sha1(e, t));
}
function str_hmac_sha1(e, t) {
  return binb2str(core_hmac_sha1(e, t));
}
function sha1_vm_test() {
  return hex_sha1('abc') == 'a9993e364706816aba3e25717850c26c9cd0d89d';
}
function core_sha1(e, t) {
  e[t >> 5] |= 128 << 24 - t % 32,
  e[(t + 64 >> 9 << 4) + 15] = t;
  var n = Array(80),
  r = 1732584193,
  i = - 271733879,
  s = - 1732584194,
  o = 271733878,
  u = - 1009589776;
  for (var a = 0; a < e.length; a += 16) {
    var f = r,
    l = i,
    c = s,
    h = o,
    p = u;
    for (var d = 0; d < 80; d++) {
      d < 16 ? n[d] = e[a + d] : n[d] = rol(n[d - 3] ^ n[d - 8] ^ n[d - 14] ^ n[d - 16], 1);
      var v = safe_add(safe_add(rol(r, 5), sha1_ft(d, i, s, o)), safe_add(safe_add(u, n[d]), sha1_kt(d)));
      u = o,
      o = s,
      s = rol(i, 30),
      i = r,
      r = v;
    }
    r = safe_add(r, f),
    i = safe_add(i, l),
    s = safe_add(s, c),
    o = safe_add(o, h),
    u = safe_add(u, p);
  }
  return Array(r, i, s, o, u);
}
function sha1_ft(e, t, n, r) {
  return e < 20 ? t & n | ~t & r : e < 40 ? t ^ n ^ r : e < 60 ? t & n | t & r | n & r : t ^ n ^ r;
}
function sha1_kt(e) {
  return e < 20 ? 1518500249 : e < 40 ? 1859775393 : e < 60 ? - 1894007588 : - 899497514;
}
function core_hmac_sha1(e, t) {
  var n = str2binb(e);
  n.length > 16 && (n = core_sha1(n, e.length * chrsz));
  var r = Array(16),
  i = Array(16);
  for (var s = 0; s < 16; s++) {
    r[s] = n[s] ^ 909522486,
    i[s] = n[s] ^ 1549556828;
  }
  var o = core_sha1(r.concat(str2binb(t)), 512 + t.length * chrsz);
  return core_sha1(i.concat(o), 672);
}
function rol(e, t) {
  return e << t | e >>> 32 - t;
}
function str2binb(e) {
  var t = Array(),
  n = (1 << chrsz) - 1;
  for (var r = 0; r < e.length * chrsz; r += chrsz) {
    t[r >> 5] |= (e.charCodeAt(r / chrsz) & n) << 32 - chrsz - r % 32;
  }
  return t;
}
function binb2str(e) {
  var t = '',
  n = (1 << chrsz) - 1;
  for (var r = 0; r < e.length * 32; r += chrsz) {
    t += String.fromCharCode(e[r >> 5] >>> 32 - chrsz - r % 32 & n);
  }
  return t;
}
function binb2hex(e) {
  var t = hexcase ? '0123456789ABCDEF' : '0123456789abcdef',
  n = '';
  for (var r = 0; r < e.length * 4; r++) {
    n += t.charAt(e[r >> 2] >> (3 - r % 4) * 8 + 4 & 15) + t.charAt(e[r >> 2] >> (3 - r % 4) * 8 & 15);
  }
  return n;
}
function binb2b64(e) {
  var t = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
  n = '';
  for (var r = 0; r < e.length * 4; r += 3) {
    var i = (e[r >> 2] >> 8 * (3 - r % 4) & 255) << 16 | (e[r + 1 >> 2] >> 8 * (3 - (r + 1) % 4) & 255) << 8 | e[r + 2 >> 2] >> 8 * (3 - (r + 2) % 4) & 255;
    for (var s = 0; s < 4; s++) {
      r * 8 + s * 6 > e.length * 32 ? n += b64pad : n += t.charAt(i >> 6 * (3 - s) & 63);
    }
  }
  return n.replace(/AAA\=(\=*?)$/, '$1');
} /*  新方法，加密算法 开始 SHA256 logical functions */
function rotateRight(n,x) {
  return ((x >>> n) | (x << (32 - n)));
}
function choice(x,y,z) {
  return ((x & y) ^ (~x & z));
}
function majority(x,y,z) {
  return ((x & y) ^ (x & z) ^ (y & z));
}
function sha256_Sigma0(x) {
  return (rotateRight(2, x) ^ rotateRight(13, x) ^ rotateRight(22, x));
}
function sha256_Sigma1(x) {
  return (rotateRight(6, x) ^ rotateRight(11, x) ^ rotateRight(25, x));
}
function sha256_sigma0(x) {
  return (rotateRight(7, x) ^ rotateRight(18, x) ^ (x >>> 3));
}
function sha256_sigma1(x) {
  return (rotateRight(17, x) ^ rotateRight(19, x) ^ (x >>> 10));
}
function sha256_expand(W, j) {
  return (W[j&0x0f] += sha256_sigma1(W[(j+14)&0x0f]) + W[(j+9)&0x0f] +
      sha256_sigma0(W[(j+1)&0x0f]));
}
var K256 = new Array(
    0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
    0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
    0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
    0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
    0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
    0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
    0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
    0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
    0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
    0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
    0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
    0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
    0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
    0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
    0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
    0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
);
var ihash, count, buffer;
var sha256_hex_digits = "0123456789abcdef";
function safe_add(x, y)
{
  var lsw = (x & 0xffff) + (y & 0xffff);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xffff);
}
function sha256_init() {
  ihash = new Array(8);
  count = new Array(2);
  buffer = new Array(64);
  count[0] = count[1] = 0;
  ihash[0] = 0x6a09e667;
  ihash[1] = 0xbb67ae85;
  ihash[2] = 0x3c6ef372;
  ihash[3] = 0xa54ff53a;
  ihash[4] = 0x510e527f;
  ihash[5] = 0x9b05688c;
  ihash[6] = 0x1f83d9ab;
  ihash[7] = 0x5be0cd19;
}
function sha256_transform() {
  var a, b, c, d, e, f, g, h, T1, T2;
  var W = new Array(16);
  a = ihash[0];
  b = ihash[1];
  c = ihash[2];
  d = ihash[3];
  e = ihash[4];
  f = ihash[5];
  g = ihash[6];
  h = ihash[7];
  for(var i=0; i<16; i++)
    W[i] = ((buffer[(i<<2)+3]) | (buffer[(i<<2)+2] << 8) | (buffer[(i<<2)+1]
    << 16) | (buffer[i<<2] << 24));

  for(var j=0; j<64; j++) {
    T1 = h + sha256_Sigma1(e) + choice(e, f, g) + K256[j];
    if(j < 16) T1 += W[j];
    else T1 += sha256_expand(W, j);
    T2 = sha256_Sigma0(a) + majority(a, b, c);
    h = g;
    g = f;
    f = e;
    e = safe_add(d, T1);
    d = c;
    c = b;
    b = a;
    a = safe_add(T1, T2);
  }

  ihash[0] += a;
  ihash[1] += b;
  ihash[2] += c;
  ihash[3] += d;
  ihash[4] += e;
  ihash[5] += f;
  ihash[6] += g;
  ihash[7] += h;
}

function sha256_update(data, inputLen) {
  var i, index, curpos = 0;
  index = ((count[0] >> 3) & 0x3f);
  var remainder = (inputLen & 0x3f);
  if ((count[0] += (inputLen << 3)) < (inputLen << 3)) count[1]++;
  count[1] += (inputLen >> 29);

  for(i=0; i+63<inputLen; i+=64) {
    for(var j=index; j<64; j++)
      buffer[j] = data.charCodeAt(curpos++);
    sha256_transform();
    index = 0;
  }
  for(var j=0; j<remainder; j++)
    buffer[j] = data.charCodeAt(curpos++);
}
function sha256_final() {
  var index = ((count[0] >> 3) & 0x3f);
  buffer[index++] = 0x80;
  if(index <= 56) {
    for(var i=index; i<56; i++)
      buffer[i] = 0;
  } else {
    for(var i=index; i<64; i++)
      buffer[i] = 0;
    sha256_transform();
    for(var i=0; i<56; i++)
      buffer[i] = 0;
  }
  buffer[56] = (count[1] >>> 24) & 0xff;
  buffer[57] = (count[1] >>> 16) & 0xff;
  buffer[58] = (count[1] >>> 8) & 0xff;
  buffer[59] = count[1] & 0xff;
  buffer[60] = (count[0] >>> 24) & 0xff;
  buffer[61] = (count[0] >>> 16) & 0xff;
  buffer[62] = (count[0] >>> 8) & 0xff;
  buffer[63] = count[0] & 0xff;
  sha256_transform();
}

function sha256_encode_bytes() {
  var j=0;
  var output = new Array(32);
  for(var i=0; i<8; i++) {
    output[j++] = ((ihash[i] >>> 24) & 0xff);
    output[j++] = ((ihash[i] >>> 16) & 0xff);
    output[j++] = ((ihash[i] >>> 8) & 0xff);
    output[j++] = (ihash[i] & 0xff);
  }
  return output;
}
function sha256_encode_hex() {
  var output = new String();
  for(var i=0; i<8; i++) {
    for(var j=28; j>=0; j-=4)
      output += sha256_hex_digits.charAt((ihash[i] >>> j) & 0x0f);
  }
  return output;
}
function sha256_digest(data) {
  sha256_init();
  sha256_update(data, data.length);
  sha256_final();
  return sha256_encode_hex();
}
function sha256_self_test()
{
  return sha256_digest("message digest") ==
      "f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650";
}
/*新sha256加密算法结束 */
function utf8t2d(e) {
  e = e.replace(/\r\n/g, '\n');
  var t = new Array,
  n = String.fromCharCode(237);
  if (n.charCodeAt(0) < 0) {
    for (var r = 0; r < e.length; r++) {
      var i = e.charCodeAt(r);
      i > 0 ? t[t.length] = i : (t[t.length] = 256 + i >> 6 | 192, t[t.length] = 256 + i & 63 | 128);
    }
  } else {
    for (var r = 0; r < e.length; r++) {
      var i = e.charCodeAt(r);
      i < 128 ? t[t.length] = i : i > 127 && i < 2048 ? (t[t.length] = i >> 6 | 192, t[t.length] = i & 63 | 128)  : (t[t.length] = i >> 12 | 224, t[t.length] = i >> 6 & 63 | 128, t[t.length] = i & 63 | 128);
    }
  }
  return t;
}
function utf8d2t(e) {
  var t = new Array,
  n = 0;
  while (n < e.length) {
    e[n] < 128 ? (t[t.length] = String.fromCharCode(e[n]), n++)  : e[n] > 191 && e[n] < 224 ? (t[t.length] = String.fromCharCode((e[n] & 31) << 6 | e[n + 1] & 63), n += 2)  : (t[t.length] = String.fromCharCode((e[n] & 15) << 12 | (e[n + 1] & 63) << 6 | e[n + 2] & 63), n += 3);
  }
  return t.join('');
}
function b64arrays() {
  var e = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  b64 = new Array,
  f64 = new Array;
  for (var t = 0; t < e.length; t++) {
    b64[t] = e.charAt(t),
    f64[e.charAt(t)] = t;
  }
}
function b64d2t(e) {
  var t = new Array,
  n = 0,
  r = e.length;
  r % 3 == 1 && (e[e.length] = 0, e[e.length] = 0),
  r % 3 == 2 && (e[e.length] = 0);
  while (n < e.length) {
    t[t.length] = b64[e[n] >> 2],
    t[t.length] = b64[(e[n] & 3) << 4 | e[n + 1] >> 4],
    t[t.length] = b64[(e[n + 1] & 15) << 2 | e[n + 2] >> 6],
    t[t.length] = b64[e[n + 2] & 63],
    n += 3;
  }
  r % 3 == 1 && (t[t.length - 1] = t[t.length - 2] = '='),
  r % 3 == 2 && (t[t.length - 1] = '=');
  var i = t.join('');
  return i;
}
function b64t2d(e) {
  var t = new Array,
  n = 0;
  e = e.replace(/\n|\r/g, ''),
  e = e.replace(/=/g, '');
  while (n < e.length) {
    t[t.length] = f64[e.charAt(n)] << 2 | f64[e.charAt(n + 1)] >> 4,
    t[t.length] = (f64[e.charAt(n + 1)] & 15) << 4 | f64[e.charAt(n + 2)] >> 2,
    t[t.length] = (f64[e.charAt(n + 2)] & 3) << 6 | f64[e.charAt(n + 3)],
    n += 4;
  }
  return e.length % 4 == 2 && (t = t.slice(0, t.length - 2)),
  e.length % 4 == 3 && (t = t.slice(0, t.length - 1)),
  t;
}
function cnonce(e) {
  var t = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
  n = '';
  for (var r = 0; r < e; r++) {
    n += t.charAt(Math.round(Math.random((new Date).getTime()) * (t.length - 1)));
  }
  return n;
}
function JSJaCJSON() {
}
function XmlDocument() {
}
function JSJaCConsoleLogger(e) {
  this.level = e || 4,
  this.start = function () {
  },
  this.log = function (e, t) {
    t = t || 0;
    if (t > this.level) {
      return;
    }
    if (typeof console == 'undefined') {
      return;
    }
    try {
      switch (t) {
        case 0:
          console.warn(e);
          break;
        case 1:
          console.error(e);
          break;
        case 2:
          console.info(e);
          break;
        case 4:
          console.debug(e);
          break;
        default:
          console.log(e);
      }
    } 
    catch (n) {
      try {
        console.log(e);
      } 
      catch (n) {
      }
    }
  },
  this.setLevel = function (e) {
    return this.level = e,
    this;
  },
  this.getLevel = function () {
    return this.level;
  };
}
/**************************/
var JSJACPACKET_USE_XMLNS = true;
function JSJaCPacket(name) {
    this.name = name;
    if (typeof(JSJACPACKET_USE_XMLNS) != 'undefined' && JSJACPACKET_USE_XMLNS) this.doc = XmlDocument.create(name, 'jabber:client');
    else this.doc = XmlDocument.create(name, '');
}
JSJaCPacket.prototype.pType = function() {
    return this.name;
};
JSJaCPacket.prototype.getDoc = function() {
    return this.doc;
};
JSJaCPacket.prototype.getNode = function() {
    if (this.getDoc() && this.getDoc().documentElement) return this.getDoc().documentElement;
    else return null;
};
JSJaCPacket.prototype.setTo = function(to) {
    if (!to || to == '') this.getNode().removeAttribute('to');
    else if (typeof(to) == 'string') this.getNode().setAttribute('to', to);
    else this.getNode().setAttribute('to', to.toString());
    return this;
};
JSJaCPacket.prototype.setFrom = function(from) {
    if (!from || from == '') this.getNode().removeAttribute('from');
    else if (typeof(from) == 'string') this.getNode().setAttribute('from', from);
    else this.getNode().setAttribute('from', from.toString());
    return this;
};
JSJaCPacket.prototype.setID = function(id) {
    if (!id || id == '') this.getNode().removeAttribute('id');
    else this.getNode().setAttribute('id', id);
    return this;
};
JSJaCPacket.prototype.setType = function(type) {
    if (!type || type == '') this.getNode().removeAttribute('type');
    else this.getNode().setAttribute('type', type);
    return this;
};
JSJaCPacket.prototype.setXMLLang = function(xmllang) {
    if (!xmllang || xmllang == '') this.getNode().removeAttribute('xml:lang');
    else this.getNode().setAttribute('xml:lang', xmllang);
    return this;
};
JSJaCPacket.prototype.getTo = function() {
    return this.getNode().getAttribute('to');
};
JSJaCPacket.prototype.getFrom = function() {
    return this.getNode().getAttribute('from');
};
JSJaCPacket.prototype.getToJID = function() {
    return new JSJaCJID(this.getTo());
};
JSJaCPacket.prototype.getFromJID = function() {
    return new JSJaCJID(this.getFrom());
};
JSJaCPacket.prototype.getID = function() {
    return this.getNode().getAttribute('id');
};
JSJaCPacket.prototype.getType = function() {
    return this.getNode().getAttribute('type');
};
JSJaCPacket.prototype.getXMLLang = function() {
    return this.getNode().getAttribute('xml:lang');
};
JSJaCPacket.prototype.getXMLNS = function() {
    return this.getNode().namespaceURI;
};

JSJaCPacket.prototype._setChildNodeByAttr = function(nodeName, nodeValue,attrname,attrvalue) {
    var aNode = this.getChildValByAttr(nodeName,attrname,attrvalue);
    var tNode = this.getDoc().createTextNode(nodeValue);
    if (aNode) try {
        aNode.replaceChild(tNode, aNode.firstChild);
    } catch(e) {} else {
        try {
            aNode = this.getDoc().createElementNS(this.getNode().namespaceURI, nodeName);
        } catch(ex) {
            aNode = this.getDoc().createElement(nodeName)
        }
        this.getNode().appendChild(aNode);
        aNode.appendChild(tNode);
        aNode.setAttribute(attrname, attrvalue);
    }
    return aNode;
};
JSJaCPacket.prototype.getChilds = function(name) {
    if (!this.getNode()) {
        return null;
    }
    name = name || '*';
    if (this.getNode().getElementsByTagNameNS) {
        return this.getNode().getElementsByTagNameNS('*', name);
    }
    return this.getNode().getElementsByTagName(name);    
}
JSJaCPacket.prototype.getChild = function(name, ns) {
    if (!this.getNode()) {
        return null;
    }
    name = name || '*';
    ns = ns || '*';
    if (this.getNode().getElementsByTagNameNS) {
        return this.getNode().getElementsByTagNameNS(ns, name).item(0);
    }
    var nodes = this.getNode().getElementsByTagName(name);
    if (ns != '*') {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes.item(i).namespaceURI == ns) {
                return nodes.item(i);
            }
        }
    } else {
        return nodes.item(0);
    }
    return null;
}
JSJaCPacket.prototype.getChildValByAttr = function(name,attrname,attrvalue) {
    
    var ret = '';    
    name = name || '*';
    if (!this.getNode()) {
        return ret;
    }
    var nodes;
    if (this.getNode().getElementsByTagNameNS) {
        nodes= this.getNode().getElementsByTagNameNS('*', name);
    }
    else
    	nodes = this.getNode().getElementsByTagName(name);
    if (nodes && nodes.item(0)) {
        for (var j = 0; j < nodes.length; j++) 
        {
        	var node=nodes.item(j);
        	if(node.getAttribute(attrname)==attrvalue)
        	{
	        	if (node && node.hasChildNodes()) {
				        for (var i = 0; i < node.childNodes.length; i++) if (node.childNodes.item(i).nodeValue) ret += node.childNodes.item(i).nodeValue;
				    }
			    }
        }
    }
    return ret;
};
JSJaCPacket.prototype.getChildVal = function(name, ns) {
    var node = this.getChild(name, ns);
    var ret = '';
    if (node && node.hasChildNodes()) {
        for (var i = 0; i < node.childNodes.length; i++) if (node.childNodes.item(i).nodeValue) ret += node.childNodes.item(i).nodeValue;
    }
    return ret;
};
JSJaCPacket.prototype.clone = function() {
    return JSJaCPacket.wrapNode(this.getNode());
};
JSJaCPacket.prototype.isError = function() {
    return (this.getType() == 'error');
};
JSJaCPacket.prototype.errorReply = function(stanza_error) {
    var rPacket = this.clone();
    rPacket.setTo(this.getFrom());
    rPacket.setFrom();
    rPacket.setType('error');
    rPacket.appendNode('error', {
        code: stanza_error.code,
        type: stanza_error.type
    },
    [[stanza_error.cond]]);
    return rPacket;
};
JSJaCPacket.prototype.xml = typeof XMLSerializer != 'undefined' ?
function() {
    var r = (new XMLSerializer()).serializeToString(this.getNode());
    if (typeof(r) == 'undefined') r = (new XMLSerializer()).serializeToString(this.doc);
    return r
}: function() {
    return this.getDoc().xml
};
JSJaCPacket.prototype._getAttribute = function(attr) {
    return this.getNode().getAttribute(attr);
};
JSJaCPacket.prototype._replaceNode = function(aNode) {
    for (var i = 0; i < aNode.attributes.length; i++) if (aNode.attributes.item(i).nodeName != 'xmlns') this.getNode().setAttribute(aNode.attributes.item(i).nodeName, aNode.attributes.item(i).nodeValue);
    for (var i = 0; i < aNode.childNodes.length; i++) if (this.getDoc().importNode) this.getNode().appendChild(this.getDoc().importNode(aNode.childNodes.item(i), true));
    else this.getNode().appendChild(aNode.childNodes.item(i).cloneNode(true));
};
JSJaCPacket.prototype._setChildNode = function(nodeName, nodeValue) {
    var aNode = this.getChild(nodeName);
    var tNode = this.getDoc().createTextNode(nodeValue);
    if (aNode) try {
        aNode.replaceChild(tNode, aNode.firstChild);
    } catch(e) {} else {
        try {
            aNode = this.getDoc().createElementNS(this.getNode().namespaceURI, nodeName);
        } catch(ex) {
            aNode = this.getDoc().createElement(nodeName)
        }
        this.getNode().appendChild(aNode);
        aNode.appendChild(tNode);
    }
    return aNode;
};
JSJaCPacket.prototype.buildNode = function(elementName) {
    return JSJaCBuilder.buildNode(this.getDoc(), elementName, arguments[1], arguments[2]);
};
JSJaCPacket.prototype.appendNode = function(element) {
    if (typeof element == 'object') {
        return this.getNode().appendChild(element)
    } else {
        return this.getNode().appendChild(this.buildNode(element, arguments[1], arguments[2], null, this.getNode().namespaceURI));
    }
};
JSJaCPacket._parseTree = function(s) {
    try {
        var r = XmlDocument.create("body", "foo");
        if (typeof(r.loadXML) != 'undefined') {
            r.loadXML(s);
            return r.documentElement;
        } else if (window.DOMParser) return (new DOMParser()).parseFromString(s, "text/xml").documentElement;
    } catch(e) {}
    return null;
};
/**************************/




function JSJaCCookie(e, t, n) {
  if (window == this) {
    return new JSJaCCookie(e, t, n);
  }
  this.name = e,
  this.value = t,
  this.secs = n,
  this.write = function () {
    if (this.secs) {
      var e = new Date;
      e.setTime(e.getTime() + this.secs * 1000);
      var t = '; expires=' + e.toGMTString();
    } else {
      var t = '';
    }
    document.cookie = this.getName() + '=' + this.getValue() + t + '; path=/';
  },
  this.erase = function () {
    var e = new JSJaCCookie(this.getName(), '', - 1);
    e.write();
  },
  this.getName = function () {
    return this.name;
  },
  this.setName = function (e) {
    return this.name = e,
    this;
  },
  this.getValue = function () {
    return this.value;
  },
  this.setValue = function (e) {
    return this.value = e,
    this;
  };
}
function JSJaCCookieException(e) {
  this.message = e,
  this.name = 'CookieException';
}
function JSJaCError(e, t, n, r) {
  r == undefined && (r = '');
  var i = XmlDocument.create('error', 'jsjac');
  return i.documentElement.setAttribute('code', e),
  i.documentElement.setAttribute('type', t),
  i.documentElement.setAttribute('content', r),
  i.documentElement.appendChild(i.createElement(n)).setAttribute('xmlns', 'urn:ietf:params:xml:ns:xmpp-stanzas'),
  i.documentElement;
}
function JSJaCConnection(e) {
  e && e.oDbg && e.oDbg.log ? this.oDbg = e.oDbg : (this.oDbg = new Object, this.oDbg.log = function () {
  }),
  e && e.httpbase && (this._httpbase = e.httpbase),
  e && e.allow_plain ? this.allow_plain = e.allow_plain : this.allow_plain = JSJAC_ALLOW_PLAIN,
  this._connected = !1,
  this._events = new Array,
  this._keys = null,
  this._ID = 0,
  this._inQ = new Array,
  this._pQueue = new Array,
  this._regIDs = new Array,
  this._req = new Array,
  this._status = 'intialized',
  this._errcnt = 0,
  this._inactivity = JSJAC_INACTIVITY,
  this._sendRawCallbacks = new Array,
  e && e.timerval && this.setPollInterval(e.timerval);
}
function JSJaCHttpBindingConnection(e) {
  this.base = JSJaCConnection,
  this.base(e),
  this._hold = JSJACHBC_MAX_HOLD,
  this._inactivity = 0,
  this._last_requests = new Object,
  this._last_rid = 0,
  this._min_polling = 0,
  this._pause = 0,
  this._wait = JSJACHBC_MAX_WAIT;
}
var JSJAC_HAVEKEYS = !0,
JSJAC_NKEYS = 16,
JSJAC_INACTIVITY = 60,
JSJAC_ERR_COUNT = 10,
JSJAC_ALLOW_PLAIN = !0,
JSJAC_CHECKQUEUEINTERVAL = 1,
JSJAC_CHECKINQUEUEINTERVAL = 1,
JSJACHBC_BOSH_VERSION = '1.6',
JSJACHBC_USE_BOSH_VER = !0,
JSJACHBC_MAX_HOLD = 1,
JSJACHBC_MAX_WAIT = 60,
JSJACHBC_MAXPAUSE = 120;
String.prototype.htmlEnc = function () {
  var e = this.replace(/&/g, '&amp;');
  return e = e.replace(/</g, '&lt;'),
  e = e.replace(/>/g, '&gt;'),
  e = e.replace(/\"/g, '&quot;'),
  e = e.replace(/\n/g, '<br />'),
  e;
},
Date.jab2date = function (e) {
  var t = new Date(Date.UTC(e.substr(0, 4), e.substr(5, 2) - 1, e.substr(8, 2), e.substr(11, 2), e.substr(14, 2), e.substr(17, 2)));
  if (e.substr(e.length - 6, 1) != 'Z') {
    var n = new Date;
    n.setTime(0),
    n.setUTCHours(e.substr(e.length - 5, 2)),
    n.setUTCMinutes(e.substr(e.length - 2, 2)),
    e.substr(e.length - 6, 1) == '+' ? t.setTime(t.getTime() - n.getTime())  : e.substr(e.length - 6, 1) == '-' && t.setTime(t.getTime() + n.getTime());
  }
  return t;
},
Date.hrTime = function (e) {
  return Date.jab2date(e).toLocaleString();
},
Date.prototype.jabberDate = function () {
  var e = function (e) {
    return e < 10 ? '0' + e : e;
  },
  t = this.getUTCFullYear() + '-';
  return t += e(this.getUTCMonth() + 1) + '-',
  t += e(this.getUTCDate()) + 'T',
  t += e(this.getUTCHours()) + ':',
  t += e(this.getUTCMinutes()) + ':',
  t += e(this.getUTCSeconds()) + 'Z',
  t;
},
Number.max = function (e, t) {
  return e > t ? e : t;
};
var hexcase = 0,
b64pad = '=',
chrsz = 8;
(typeof atob == 'undefined' || typeof btoa == 'undefined') && b64arrays(),
typeof atob == 'undefined' && (atob = function (e) {
  return utf8d2t(b64t2d(e));
}),
typeof btoa == 'undefined' && (btoa = function (e) {
  return b64d2t(utf8t2d(e));
}),
JSJaCJSON.toString = function (e) {
  var t = {
    ': '\\b',
    '\t': '\\t',
    '\n': '\\n',
    '\f': '\\f',
    '\r': '\\r',
    '"': '\\"',
    '\\': '\\\\'
  },
  n = {
    array: function (e) {
      var t = [
        '['
      ],
      r,
      i,
      s,
      o = e.length,
      u;
      for (s = 0; s < o; s += 1) {
        u = e[s],
        i = n[typeof u],
        i && (u = i(u), typeof u == 'string' && (r && (t[t.length] = ','), t[t.length] = u, r = !0));
      }
      return t[t.length] = ']',
      t.join('');
    },
    'boolean': function (e) {
      return String(e);
    },
    'null': function (e) {
      return 'null';
    },
    number: function (e) {
      return isFinite(e) ? String(e)  : 'null';
    },
    object: function (e) {
      if (e) {
        if (e instanceof Array) {
          return n.array(e);
        }
        var t = [
          '{'
        ],
        r,
        i,
        s,
        o;
        for (s in e) {
          e.hasOwnProperty(s) && (o = e[s], i = n[typeof o], i && (o = i(o), typeof o == 'string' && (r && (t[t.length] = ','), t.push(n.string(s), ':', o), r = !0)));
        }
        return t[t.length] = '}',
        t.join('');
      }
      return 'null';
    },
    string: function (e) {
      return /["\\\x00-\x1f]/.test(e) && (e = e.replace(/([\x00-\x1f\\"])/g, function (e, n) {
        var r = t[n];
        return r ? r : (r = n.charCodeAt(), '\\u00' + Math.floor(r / 16).toString(16) + (r % 16).toString(16));
      })),
      '"' + e + '"';
    }
  };
  switch (typeof e) {
    case 'object':
      return n.object(e);
    case 'array':
      return n.array(e);
  }
},
JSJaCJSON.parse = function (str) {
  try {
    return !/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(str.replace(/"(\\.|[^"\\])*"/g, '')) && eval('(' + str + ')');
  } 
  catch (e) {
    return !1;
  }
},
XmlDocument.create = function (e, t) {
  e = e || 'foo',
  t = t || '';
  try {
    var n;
    document.implementation && document.implementation.createDocument ? (n = document.implementation.createDocument(t, e, null), n.readyState == null && (n.readyState = 1, n.addEventListener('load', function () {
      n.readyState = 4,
      typeof n.onreadystatechange == 'function' && n.onreadystatechange();
    }, !1)))  : window.ActiveXObject && (n = new ActiveXObject(XmlDocument.getPrefix() + '.DomDocument'));
    if (!n.documentElement || n.documentElement.tagName != e || n.documentElement.namespaceURI && n.documentElement.namespaceURI != t) {
      try {
        t != '' ? n.appendChild(n.createElement(e)).setAttribute('xmlns', t)  : n.appendChild(n.createElement(e));
      } 
      catch (r) {
        n = document.implementation.createDocument(t, e, null),
        n.documentElement == null && n.appendChild(n.createElement(e)),
        t != '' && n.documentElement.getAttribute('xmlns') != t && n.documentElement.setAttribute('xmlns', t);
      }
    }
    return n;
  } 
  catch (i) {
    alert(i.name + ': ' + i.message);
  }
  throw new Error('Your browser does not support XmlDocument objects');
},
XmlDocument.getPrefix = function () {
  if (XmlDocument.prefix) {
    return XmlDocument.prefix;
  }
  var e = [
    'MSXML2',
    'Microsoft',
    'MSXML',
    'MSXML3'
  ],
  t;
  for (var n = 0; n < e.length; n++) {
    try {
      return t = new ActiveXObject(e[n] + '.DomDocument'),
      XmlDocument.prefix = e[n];
    } 
    catch (r) {
    }
  }
  throw new Error('Could not find an installed XML parser');
},
JSJaCCookie.read = function (e) {
  var t = e + '=',
  n = document.cookie.split(';');
  for (var r = 0; r < n.length; r++) {
    var i = n[r];
    while (i.charAt(0) == ' ') {
      i = i.substring(1, i.length);
    }
    if (i.indexOf(t) == 0) {
      return new JSJaCCookie(e, i.substring(t.length, i.length));
    }
  }
  throw new JSJaCCookieException('Cookie not found');
},
JSJaCCookie.get = function (e) {
  return JSJaCCookie.read(e).getValue();
},
JSJaCCookie.remove = function (e) {
  JSJaCCookie.read(e).erase();
},
JSJaCConnection.prototype.connect = function (e) {
  this._setStatus('connecting'),
  this.domain = e.domain || 'chat.gtja.com',
  this.authzid = e.authzid,
  this.username = e.username,
  this.resource = e.resource,
  this.pass = e.pass,
  this.register = e.register,
  this._custId = e.custId,
  this._custType = e.custType,
  this._MD5Pass = e.MD5Pass,
  this._ettoken = e.ettoken,
  this.authhost = e.authhost || this.domain,
  this.authtype = e.authtype || 'sasl',
  e.xmllang && e.xmllang != '' && (this._xmllang = e.xmllang),
  this.host = e.host || this.domain,
  this.port = e.port || 5222,
  e.secure ? this.secure = 'true' : this.secure = 'false',
  e.wait && (this._wait = e.wait),
  this.jid = this.username + '@' + this.domain,
  this.fulljid = this.jid + '/' + this.resource,
  this._rid = Math.round(100000.5 + 799999.99999 * Math.random());
  var t = this._getFreeSlot();
  this._req[t] = this._setupRequest(!0, t);
  var n = this._getInitialRequestString();
  this._req[t].r.onreadystatechange = JSJaC.bind(function () {
    this._req[t].r.status == 'success' && this._handleInitialResponse(t);
  }, this),
  this._req[t].r.error = JSJaC.bind(function (e, t, n) {
    return this._handleEvent('onerror', JSJaCError('500', 'cancel', 'service-unavailable')),
    !1;
  }, this),
  this._req[t].r.send(n);
},
JSJaCConnection.prototype.connected = function () {
  return this._connected;
},
JSJaCConnection.prototype.disconnect = function () {
  this._setStatus('disconnecting');
  if (!this.connected()) {
    return;
  }
  this._connected = !1,
  clearInterval(this._interval),
  clearInterval(this._inQto),
  this._timeout && clearTimeout(this._timeout);
  var e = this._getFreeSlot();
  this._req[e] = this._setupRequest(!1, e),
  request = this._getRequestString(!1, !0),
  this.oDbg.log('Disconnecting: ' + request, 4),
  this._req[e].r.send(request);
  try {
    JSJaCCookie.read('JSJaC_State').erase();
  } 
  catch (t) {
  }
  this.oDbg.log('Disconnected: ' + this._req[e].r.responseText, 2),
  this._handleEvent('ondisconnect',{errorcode:'501',errorlog:'disconnect:' + this._req[e].r.responseText});
},
JSJaCConnection.prototype.getPollInterval = function () {
  return this._timerval;
},
JSJaCConnection.prototype.registerHandler = function (event) {
  event = event.toLowerCase();
  var eArg = {
    handler: arguments[arguments.length - 1],
    childName: '*',
    childNS: '*',
    type: '*'
  };
  arguments.length > 2 && (eArg.childName = arguments[1]),
  arguments.length > 3 && (eArg.childNS = arguments[2]),
  arguments.length > 4 && (eArg.type = arguments[3]),
  this._events[event] ? this._events[event] = this._events[event].concat(eArg)  : this._events[event] = new Array(eArg),
  this._events[event] = this._events[event].sort(function (a, b) {
    var aRank = 0,
    bRank = 0;
    with (a) {
      type == '*' && aRank++,
      childNS == '*' && aRank++,
      childName == '*' && aRank++;
    }
    with (b) {
      type == '*' && bRank++,
      childNS == '*' && bRank++,
      childName == '*' && bRank++;
    }
    return aRank > bRank ? 1 : aRank < bRank ? - 1 : 0;
  }),
  this.oDbg.log('registered handler for event \'' + event + '\'', 2);
},
JSJaCConnection.prototype.unregisterHandler = function (e, t) {
  e = e.toLowerCase();
  if (!this._events[e]) {
    return;
  }
  var n = this._events[e],
  r = new Array;
  for (var i = 0; i < n.length; i++) {
    n[i].handler != t && r.push(n[i]);
  }
  n.length != r.length && (this._events[e] = r, this.oDbg.log('unregistered handler for event \'' + e + '\'', 2));
},
JSJaCConnection.prototype.registerIQGet = function (e, t, n) {
  this.registerHandler('iq', e, t, 'get', n);
},
JSJaCConnection.prototype.registerIQSet = function (e, t, n) {
  this.registerHandler('iq', e, t, 'set', n);
},
JSJaCConnection.prototype.resume = function () {
  try {
    this._setStatus('resuming');
    var e = unescape(JSJaCCookie.read('JSJaC_State').getValue());
    this.oDbg.log('read cookie: ' + e, 2);
    var t = JSJaCJSON.parse(e);
    for (var n in t) {
      t.hasOwnProperty(n) && (this[n] = t[n]);
    }
    if (this._keys) {
      this._keys2 = new JSJaCKeys;
      var r = this._keys2._getSuspendVars();
      for (var n = 0; n < r.length; n++) {
        this._keys2[r[n]] = this._keys[r[n]];
      }
      this._keys = this._keys2;
    }
    try {
      JSJaCCookie.read('JSJaC_State').erase();
    } 
    catch (i) {
    }
    return this._connected && (this._handleEvent('onresume'), setTimeout(JSJaC.bind(this._resume, this), this.getPollInterval()), this._interval = setInterval(JSJaC.bind(this._checkQueue, this), JSJAC_CHECKQUEUEINTERVAL), this._inQto = setInterval(JSJaC.bind(this._checkInQ, this), JSJAC_CHECKINQUEUEINTERVAL)),
    this._connected === !0;
  } 
  catch (i) {
    return i.message ? this.oDbg.log('Resume failed: ' + i.message, 1)  : this.oDbg.log('Resume failed: ' + i, 1),
    !1;
  }
},
JSJaCConnection.prototype.send = function (e, t, n) {
  if (!this.connected()) {
    return !1;
  }
  try {
    this._pQueue = this._pQueue.concat(e);
  } 
  catch (r) {
    return !1;
  }
  return !0;
},
JSJaCConnection.prototype.setPollInterval = function (e) {
  return e && !isNaN(e) && (this._timerval = e),
  this._timerval;
},
JSJaCConnection.prototype.status = function () {
  return this._status;
},
JSJaCConnection.prototype.suspend = function () {
  clearTimeout(this._timeout),
  clearInterval(this._interval),
  clearInterval(this._inQto),
  this._suspend();
  var e = '_connected,_keys,_ID,_inQ,_pQueue,_regIDs,_errcnt,_inactivity,domain,username,resource,jid,fulljid,_sid,_httpbase,_timerval,_is_polling'.split(',');
  e = e.concat(this._getSuspendVars());
  var t = new Object;
  for (var n = 0; n < e.length; n++) {
    if (!this[e[n]]) {
      continue;
    }
    if (this[e[n]]._getSuspendVars) {
      var r = this[e[n]]._getSuspendVars(),
      i = new Object;
      for (var s = 0; s < r.length; s++) {
        i[r[s]] = this[e[n]][r[s]];
      }
    } else {
      var i = this[e[n]];
    }
    t[e[n]] = i;
  }
  var o = new JSJaCCookie('JSJaC_State', escape(JSJaCJSON.toString(t)), this._inactivity);
  this.oDbg.log('writing cookie: ' + unescape(o.value) + '\n(length:' + unescape(o.value).length + ')', 2),
  o.write();
  try {
    var u = JSJaCCookie.read('JSJaC_State');
    o.value != u.value && (this.oDbg.log('Suspend failed writing cookie.\nRead: ' + unescape(JSJaCCookie.read('JSJaC_State')), 1), o.erase()),
    this._connected = !1,
    this._setStatus('suspending');
  } 
  catch (a) {
    this.oDbg.log('Failed reading cookie \'JSJaC_State\': ' + a.message);
  }
},
JSJaCConnection.prototype._abort = function () {
  clearTimeout(this._timeout),
  clearInterval(this._inQto),
  clearInterval(this._interval),
  this._connected = !1,
  this._setStatus('aborted'),
  this._handleEvent('ondisconnect',{errorcode:'501',errorlog: 'aborted'});
},
JSJaCConnection.prototype._checkInQ = function () {
  for (var e = 0; e < this._inQ.length && e < 10; e++) {
    var t = this._inQ[0];
    this._inQ = this._inQ.slice(1, this._inQ.length);
    var n = t;
    if (!n) {
      return;
    }
    if (n._subTagCount>0 && !this._handlePID(n)) {

        for (var r = 0; r < n._subNodes.length; r++) {
          var i = n._subNodes[r];
          this._handleEvent(i._tagName, i);
        }

    }
  }
},
JSJaCConnection.prototype._checkQueue = function () {
  return this._pQueue.length != 0 && this._process(),
  !0;
},
JSJaCConnection.prototype._handleEvent = function (e, t) {
  e = e.toLowerCase(),
  this.oDbg.log('incoming event \'' + e + '\'', 3);
  if (!this._events[e]) {
    return;
  }
  this.oDbg.log('handling event \'' + e + '\'', 2);
  for (var n = 0; n < this._events[e].length; n++) {
    var r = this._events[e][n];
    if (r.handler) {
      try {
        if (t) {
          if (r.handler.call(this, t)) {
            break;
          }
        } else {
          if (r.handler.call(this)) {
            break;
          }
        }
      } 
      catch (i) {
        this.oDbg.log(r.handler + '\n>>>' + i.name + ': ' + i.message, 1);
      }
    }
  }
},
JSJaCConnection.prototype._handlePID = function (e) {
  if (!e.id) {
    return !1;
  }
  for (var t in this._regIDs) {
    if (this._regIDs.hasOwnProperty(t) && this._regIDs[t] && t == e.id) {
      var n = e.id;
      try {
        return this._regIDs[t].cb.call(this, e, this._regIDs[t].arg) === !1 ? !1 : (this._unregisterPID(n), !0);
      } 
      catch (r) {
        return this.oDbg.log(r.name + ': ' + r.message),
        this._unregisterPID(n),
        !0;
      }
    }
  }
  return !1;
},
JSJaCConnection.prototype._handleResponse = function (e) {
  var t = this._parseResponse(e);
  if (!t) {
    return;
  }
  if (this._sendRawCallbacks.length) {
    var n = this._sendRawCallbacks[0];
    this._sendRawCallbacks = this._sendRawCallbacks.slice(1, this._sendRawCallbacks.length),
    n.fn.call(this, t, n.arg);
    return;
  }
  this._inQ = this._inQ.concat(t);
},
JSJaCConnection.prototype._parseStreamFeatures = function (e) {
  if (!e) {
    return this.oDbg.log('nothing to parse ... aborting', 1),
    !1;
  }
  var t;
  if (e.getElementsByTagNameNS) {
    t = e.getElementsByTagNameNS('http://etherx.jabber.org/streams', 'error').item(0);
  } else {
    var n = e.getElementsByTagName('error');
    for (var r = 0; r < n.length; r++) {
      if (n.item(r).namespaceURI == 'http://etherx.jabber.org/streams') {
        t = n.item(r);
        break;
      }
    }
  }
  if (t) {
    return this._setStatus('internal_server_error'),
    clearTimeout(this._timeout),
    clearInterval(this._interval),
    clearInterval(this._inQto),
    this._handleEvent('onerror', JSJaCError('503', 'cancel', 'session-terminate')),
    this._connected = !1,
    this.oDbg.log('Disconnected.', 1),
    this._handleEvent('ondisconnect', {errorcode:'501',errorlog:'error'}),
    !1;
  }
  this.mechs = new Object;
  var i = e.getElementsByTagName('mechanisms');
  this.has_sasl = !1;
  for (var r = 0; r < i.length; r++) {
    if (i.item(r).getAttribute('xmlns') == 'urn:ietf:params:xml:ns:xmpp-sasl') {
      this.has_sasl = !0;
      var s = i.item(r).getElementsByTagName('mechanism');
      for (var o = 0; o < s.length; o++) {
        this.mechs[s.item(o).firstChild.nodeValue] = !0;
      }
      break;
    }
  }
  return this.has_sasl ? this.oDbg.log('SASL detected', 2)  : (this.authtype = 'nonsasl', this.oDbg.log('No support for SASL detected', 2)),
  !0;
},
JSJaCConnection.prototype._process = function (e) {
  if (!this.connected()) {
    this.oDbg.log('Connection lost ...', 1),
    this._interval && clearInterval(this._interval);
    return;
  }
  this.setPollInterval(e),
  this._timeout && clearTimeout(this._timeout);
  var t = this._getFreeSlot();
  if (t < 0) {
    return;
  }
  if (typeof this._req[t] != 'undefined' && typeof this._req[t].r != 'undefined' && this._req[t].r.status == 'starting') {
    this.oDbg.log('Slot ' + t + ' is not ready');
    return;
  }
  if (!this.isPolling() && this._pQueue.length == 0 && this._req[(t + 1) % 2] && this._req[(t + 1) % 2].r.status == 'starting') {
    this.oDbg.log('all slots busy, standby ...', 2);
    return;
  }
  this.isPolling() || this.oDbg.log('Found working slot at ' + t, 2),
  this._req[t] = this._setupRequest(!0, t),
  this._req[t].r.onreadystatechange = JSJaC.bind(function () {
    if (!this.connected()) {
      return;
    }
    this._req[t].r.status == 'success' && (this._setStatus('processing'), this._handleResponse(this._req[t]), this._pQueue.length ? this._timeout = setTimeout(JSJaC.bind(this._process, this), 100)  : (this.oDbg.log('scheduling next poll in ' + this.getPollInterval() + ' msec', 4), this._timeout = setTimeout(JSJaC.bind(this._process, this), this.getPollInterval())));
  }, this);
  try {
    this._req[t].r.onerror = JSJaC.bind(function () {
      if (!this.connected()) {
        return;
      }
      return this._errcnt++,
      this._errcnt > JSJAC_ERR_COUNT ? (this._abort(), !1)  : (this._setStatus('onerror_fallback'), setTimeout(JSJaC.bind(this._resume, this), this.getPollInterval()), !1);
    }, this);
  } 
  catch (n) {
  }
  var r = this._getRequestString();
  typeof this._rid != 'undefined' && (this._req[t].rid = this._rid),
  this.oDbg.log('sending: ' + r, 4),
  this._req[t].r.send(r);
},
JSJaCConnection.prototype._registerPID = function (e, t, n) {
  return !e || !t ? !1 : (this._regIDs[e] = new Object, this._regIDs[e].cb = t, n && (this._regIDs[e].arg = n), this.oDbg.log('registered ' + e, 3), !0);
},
JSJaCConnection.prototype._sendEmpty = function () {
  var e = this._getFreeSlot();
  this._req[e] = this._setupRequest(!0, e),
  this._req[e].r.onreadystatechange = JSJaC.bind(function () {
    this._req[e].r.status == 'success' && this._getStreamID(e);
  }, this),
  typeof this._req[e].r.onerror != 'undefined' && (this._req[e].r.onerror = JSJaC.bind(function (e) {
    return !1;
  }, this));
  var t = this._getRequestString();
  this.oDbg.log('sending: ' + t, 4),
  this._req[e].r.send(t);
},
JSJaCConnection.prototype._sendRaw = function (e, t, n) {
  return t && this._sendRawCallbacks.push({
    fn: t,
    arg: n
  }),
  this._pQueue.push(e),
  this._process(),
  !0;
},
JSJaCConnection.prototype._setStatus = function (e) {
  if (!e || e == '') {
    return;
  }
  e != this._status && (this._status = e, this._handleEvent('onstatuschanged', e), this._handleEvent('status_changed', e));
},
JSJaCConnection.prototype._unregisterPID = function (e) {
  return this._regIDs[e] ? (this._regIDs[e] = null, this.oDbg.log('unregistered ' + e, 3), !0)  : !1;
},
JSJaCHttpBindingConnection.prototype = new JSJaCConnection,
JSJaCHttpBindingConnection.prototype.inherit = function (e) {
  this.domain = e.domain || 'chat.gtja.com',
  this.username = e.username,
  this.resource = e.resource,
  this._sid = e.sid,
  this._rid = e.rid,
  this._custId = e.custId,
  this._custType = e.custType,
  this._MD5Pass = e.MD5Pass,
  this._ettoken = e.ettoken,
  this._min_polling = e.polling,
  this._inactivity = e.inactivity,
  this._setHold(e.requests - 1),
  this.setPollInterval(this._timerval),
  e.wait && (this._wait = e.wait),
  this._connected = !0,
  this._handleEvent('onconnect'),
  this._interval = setInterval(JSJaC.bind(this._checkQueue, this), JSJAC_CHECKQUEUEINTERVAL),
  this._inQto = setInterval(JSJaC.bind(this._checkInQ, this), JSJAC_CHECKINQUEUEINTERVAL),
  this._timeout = setTimeout(JSJaC.bind(this._process, this), this.getPollInterval());
},
JSJaCHttpBindingConnection.prototype.setPollInterval = function (e) {
  return e && !isNaN(e) && (this.isPolling() ? this._min_polling && e < this._min_polling * 1000 ? this._timerval = this._min_polling * 1000 : this._inactivity && e > this._inactivity * 1000 ? this._timerval = this._inactivity * 1000 : this._timerval = e : this._timerval = 100),
  this._timerval;
},
JSJaCHttpBindingConnection.prototype.isPolling = function () {
  return this._hold == 0;
},
JSJaCHttpBindingConnection.prototype._getFreeSlot = function () {
  for (var e = 0; e < this._hold + 1; e++) {
    if (typeof this._req[e] == 'undefined' || typeof this._req[e].r == 'undefined' || this._req[e].r.status != 'starting') {
      return e;
    }
  }
  return - 1;
},
JSJaCHttpBindingConnection.prototype._getHold = function () {
  return this._hold;
},
JSJaCHttpBindingConnection.prototype._getRequestString = function (e, t) {
  var n = {
  };
  if (this._rid <= this._last_rid && typeof this._last_requests[this._rid] != 'undefined') {
    n = this._last_requests[this._rid].xml;
  } else {
    if (e) {
      n = e;
    } else {
      if (this._pQueue.length) {
        var r = this._pQueue[0];
        n = r,
        this._pQueue = this._pQueue.slice(1, this._pQueue.length);
      }
    }
    n.rid = this._rid,
    n.sid = this._sid,
    t && (n.type = 'terminate'),
    this._last_requests[this._rid] = new Object,
    this._last_requests[this._rid].xml = n,
    this._last_rid = this._rid;
    for (var i in this._last_requests) {
      this._last_requests.hasOwnProperty(i) && i < this._rid - this._hold && delete this._last_requests[i];
    }
  }
  return n;
},
JSJaCHttpBindingConnection.prototype._getInitialRequestString = function () {
  var e = {
    hold: this._hold,
    wait: this._wait,
    rid: this._rid,
    custId: this._custId,
    custType: this._custType,
    MD5Pass: this._MD5Pass,
    ettoken: this._ettoken
  };
  //if((e.custId==undefined||e.custId=='')&&(e.ettoken==undefined||e.ettoken=='')&&(e.custType==undefined||e.custType==''))
  {
    e.method='checkLogin';
  }
  return e;
},
JSJaCHttpBindingConnection.prototype._getStreamID = function (e) {
  this._timeout = setTimeout(JSJaC.bind(this._process, this), this.getPollInterval());
  return;
},
JSJaCHttpBindingConnection.prototype._getSuspendVars = function () {
  return 'host,port,secure,_rid,_last_rid,_wait,_min_polling,_inactivity,_hold,_last_requests,_pause'.split(',');
},
JSJaCHttpBindingConnection.prototype._handleInitialResponse = function (e) {
  var t = this._req[e].r.responseJson;
  if (!t) {
    this._handleEvent('onerror', JSJaCError('500', 'wait', 'internal-service-error'));
    return;
  }
  if(t._tagName=='body')
     t= t._attrib;
  if (t.type == 'terminate') {
    clearTimeout(this._timeout),
    this._connected = !1,
    this._handleEvent('onerror', JSJaCError(t.errorcode, 'cancel', 'auth-service-fail', t.errorlog)),
    this.oDbg.log('Disconnected.', 1),
    //this._handleEvent('ondisconnect', 'terminate:\n');
        this._handleEvent('ondisconnect', t);
    return;
  }
  if(t.myjid)
  {
    var presenceJid=t.myjid;
    if (~presenceJid.indexOf("@"))
      presenceJid = presenceJid.substr(0, presenceJid.indexOf("@"));
    if (~presenceJid.indexOf("_"))
    {
      presenceJid = presenceJid.substr(0, presenceJid.indexOf("_"));
    }

    if (~presenceJid.indexOf("\."))
    {
      this.username=presenceJid;
      this._custType = presenceJid.substr(presenceJid.indexOf("\.")+1);
      this._custId = presenceJid.substr(0, presenceJid.indexOf("\."));
      this.jid = this.username + '@' + this.domain;
    }
  }
  if(t.cookie)
  {
  	var cookieTemp=GetCookie('JSESSIONID');
  	if(t.cookie!=cookieTemp)
  	  SetCookie('JSESSIONID',t.cookie);
  }
  this._presence= t.presence;
  this._sid = t.sid,
  t.polling && (this._min_polling = t.polling),
  t.inactivity && (this._inactivity = t.inactivity),
  t.requests && this._setHold(t.requests - 1),
  t.maxpause && (this._pause = Number.max(t.maxpause, JSJACHBC_MAXPAUSE)),
      this.fulljid= t.myjid,
  this.setPollInterval(this._timerval),
  this._connected = !0,
  this._inQto = setInterval(JSJaC.bind(this._checkInQ, this), JSJAC_CHECKINQUEUEINTERVAL),
  this._interval = setInterval(JSJaC.bind(this._checkQueue, this), JSJAC_CHECKQUEUEINTERVAL),
  this._getStreamID(null),
  this._handleEvent('onconnect');
},
JSJaCHttpBindingConnection.prototype._parseResponse = function (e) {
  if (!this.connected() || !e) {
    return null;
  }
  var t = e.r;
  try {
    if (t.status != 'success' || !t.responseJson) {
      return this._errcnt++,
      this._errcnt > JSJAC_ERR_COUNT ? (this._abort(), null)  : (this._setStatus('proto_error_fallback'), setTimeout(JSJaC.bind(this._resume, this), this.getPollInterval()), null);
    }
  } 
  catch (n) {
    return this._errcnt++,
    this._errcnt > JSJAC_ERR_COUNT ? this._abort()  : (this._setStatus('proto_error_fallback'), setTimeout(JSJaC.bind(this._resume, this), this.getPollInterval())),
    null;
  }
  var r = t.responseJson;
  if (typeof e.rid != 'undefined' && this._last_requests[e.rid]) {
    if (this._last_requests[e.rid].handled) {
      return this.oDbg.log('already handled ' + e.rid, 2),
      null;
    }
    this._last_requests[e.rid].handled = !0;
  }
  //return r.type == 'terminate' ? (clearTimeout(this._timeout), clearInterval(this._interval), clearInterval(this._inQto), this._connected = !1, this._handleEvent('ondisconnect', 'session terminated:\n'), null)  : (this._errcnt = 0, t.responseJson);
  return r.type == 'terminate' ? (clearTimeout(this._timeout), clearInterval(this._interval), clearInterval(this._inQto), this._connected = !1, this._handleEvent('ondisconnect', r), null)  : (this._errcnt = 0, t.responseJson);
},
JSJaCHttpBindingConnection.prototype._reInitStream = function (e, t, n) {
  this._reinit = !0,
  t.call(this, n);
},
JSJaCHttpBindingConnection.prototype._resume = function () {
  this._pause == 0 && this._rid >= this._last_rid && (this._rid = this._last_rid - 1),
  this._process();
},
JSJaCHttpBindingConnection.prototype._setHold = function (e) {
  return !e || isNaN(e) || e < 0 ? e = 0 : e > JSJACHBC_MAX_HOLD && (e = JSJACHBC_MAX_HOLD),
  this._hold = e,
  this._hold;
},
JSJaCHttpBindingConnection.prototype._setupRequest = function (e, t) {
  var n = new Object,
  r = this;
  return n.r = {
    url: this._httpbase,
    dataType: 'jsonp',
    data: '',
    jsonp: 'callback',
    success: function (e, n) {
      r._req[t].r.finishflags = !0,
      r._req[t].r.status = 'success',
      r._req[t].r.responseJson = e,
      this.onreadystatechange();
    },
    onreadystatechange: function () {
    },
    type: 'get',
    async: e,
    onerror: function () {
      r._req[t].r.finishflags = !0;
    },
    finishflags: !1,
    status: 'starting',
    error: function (e, n, i) {
      r._req[t].r.finishflags = !0,
      r._req[t].r.status = n,
      this.onerror();
    },
    timeout: this._wait * 1000 + 10000,
    send: function (e) {
      this.data = e,
      this.data.cookie=GetCookie('JSESSIONID');
      jQuery.ajax(this);
      
    }
  },
  this._rid++,
  n.rid = this._rid,
  n;
},
JSJaCHttpBindingConnection.prototype._suspend = function () {
  if (this._pause == 0) {
    return;
  }
  var e = this._getFreeSlot();
  this._req[e] = this._setupRequest(!1, e);
  var t = {
  };
  if (this._pQueue.length) {
    var n = this._pQueue[0];
    t = n,
    this._pQueue = this._pQueue.slice(1, this._pQueue.length);
  }
  t.pause = this._pause,
  t.sid = this._sid,
  t.rid = this._rid,
  this._req[e].r.send(t);
};
var JSJaC = {
  Version: '$Rev: 456 $',
  require: function (e) {
    document.write('<script type="text/javascript" src="' + e + '"></script>');
  },
  load: function () {
    var e = [
      'xmlextras',
      'jsextras',
      'crypt',
      'JSJaCConfig',
      'JSJaCConstants',
      'JSJaCCookie',
      'JSJaCJSON',
      'JSJaCJID',
      'JSJaCBuilder',
      'JSJaCPacket',
      'JSJaCError',
      'JSJaCKeys',
      'JSJaCConnection',
      'JSJaCHttpPollingConnection',
      'JSJaCHttpBindingConnection',
      'JSJaCConsoleLogger'
    ],
    t = document.getElementsByTagName('script'),
    n = './';
    for (var r = 0; r < t.length; r++) {
      if (t.item(r).src && t.item(r).src.match(/JSJaC\.js$/)) {
        n = t.item(r).src.replace(/JSJaC.js$/, '');
        break;
      }
    }
    for (var r = 0; r < e.length; r++) {
      this.require(n + e[r] + '.js');
    }
  },
  bind: function (e, t, n) {
    return function () {
      n ? e.apply(t, n)  : e.apply(t);
    };
  }
};
typeof JSJaCConnection == 'undefined' && JSJaC.load();
var remotegtjawebet = {
  datetimeFormat: function (e) {
    return ~~e < 10 ? '0' + e : e;
  },
  getDatetime: function () {
    var e = new Date,
    t = e.getFullYear() + '-' + e.getMonth() + '-' + e.getDate();
    return t = ' ' + this.datetimeFormat(e.getHours()) + ':' + this.datetimeFormat(e.getMinutes()) + ':' + this.datetimeFormat(e.getSeconds()),
    t;
  },

  isConnectSuccess: function () {
    return remotegtjawebet.connection && remotegtjawebet.connection.connected() ? !0 : !1;
  },
  getRoomPresence: function () {
    return remotegtjawebet.presence;
  },
  handleMessage: function (e) {
    remotegtjawebet.handleFunc.handleMessage != undefined && remotegtjawebet.handleFunc.handleMessage(e);
  },
  handlePresence: function (e) {
    remotegtjawebet.handleFunc.handlePresence != undefined && remotegtjawebet.handleFunc.handlePresence(e);
  },
  handleFunc: {
  },
  isneedlogout: !1,
  connectionTimehandle: null,
  logout: function () {
    remotegtjawebet.connectionTimehandle != undefined && remotegtjawebet.connectionTimehandle != null && (clearTimeout(remotegtjawebet.connectionTimehandle), remotegtjawebet.connectionTimehandle = null),
    remotegtjawebet.connection && remotegtjawebet.isneedlogout && remotegtjawebet.connection.disconnect();
  },
  errorHandler: function (e) {
    return remotegtjawebet.connection && remotegtjawebet.connection.connected() && remotegtjawebet.connection.disconnect(),
    !1;
  },
  unloadHandler: function () {
    var e = remotegtjawebet.connection;
    typeof e != 'undefined' && e && e.connected() && e.suspend && e.suspend();
  },
  handleConnected: function () {
    remotegtjawebet.handleFunc.handleConnected != undefined && remotegtjawebet.handleFunc.handleConnected();
  },
  handleDisconnected: function (e) {
    //var t = '您离线了!';
   // e && (~e.indexOf('internal_server_error') ? ~e.indexOf('conflict') ? t = '您在其它地方登录,被迫离线了！' : t = '服务器关闭链接,您离线了！' : ~e.indexOf('aborted') ? t = '网络异常,您离线了!' : ~e.indexOf('disconnect') && (t = '您登出ET助手')),
    remotegtjawebet.presence = '0',
    remotegtjawebet.handleFunc.handleDisconnected != undefined && remotegtjawebet.handleFunc.handleDisconnected(e);
  },
  handleError: function (e) {
    var t = e || window.event,
    n = '';
    switch (t.getAttribute('code')) {
      case '401':
        n = t.getAttribute('content');
        break;
      case '402':
        n = '直播室ID不存在';
        break;
      case '503':
        n = '无法连接到IM服务器，请检查相关配置！';
        break;
      case '500':
        var n = '服务器内部错误！连接断开！重新连接';
        break;
      default:
    }
    remotegtjawebet.handleFunc.handleError != undefined && remotegtjawebet.handleFunc.handleError(t.getAttribute('code'), t.getAttribute('type'), t.firstChild.nodeName, n),
    remotegtjawebet.connection.connected() && remotegtjawebet.connection.disconnect();
  },
  getChatHisMsg:function(toJid,msgTime, handleMsg)
  {
  	var dataJson={};
  	dataJson.toJid=toJid;
  	dataJson.msgTime=msgTime;
  	
  	remotegtjawebet.sendMsg('getChatHisMsg',dataJson,handleMsg);
  },
  sendMsg:function(method,dataJson,handleFunRet)
  {
  	dataJson.cookie=GetCookie('JSESSIONID');
    if (remotegtjawebet.connection && remotegtjawebet.connection.connected())
    {
      dataJson.method=method;
      dataJson.sid= remotegtjawebet.connection._sid;
      var option = {
        type: 'get',
        dataType: 'jsonp',
        jsonp :'callback',
        url: remotegtjawebet.connectionConfig.httpdomain+'/WebIM/weblogin',
        data: dataJson,
        timeout: remotegtjawebet.connection._wait * 1000,
        success: function (data, textStatus) {
          // 成功
          if(data.ret=='success') {

            handleFunRet('success','',data);
          } else {
            handleFunRet('success','',data);

          }
        },
        error:function (xmlhttp, textStatus, errorThrown) {
          handleFunRet('error',textStatus,{});
        }
      };
      jQuery.ajax(option);
    }
    else
    {
      handleFunRet('error','当前未登录',{});
    }


  },
  disconnect:function()
  {
     remotegtjawebet.connection.connected() && remotegtjawebet.connection.disconnect();
  },
  loginXmpp: function (e, n) {
    try {
      e.httpbase = e.httpdomain + '/WebIM/weblogin';
      var r = new JSJaCHttpBindingConnection(e);
      remotegtjawebet.connectionConfig = e;
      remotegtjawebet.connection = r;
      r.registerHandler('message', remotegtjawebet.handleMessage);
      r.registerHandler('presence', remotegtjawebet.handlePresence);
      r.registerHandler('onconnect', remotegtjawebet.handleConnected);
      r.registerHandler('ondisconnect', remotegtjawebet.handleDisconnected);
      r.registerHandler('onerror', remotegtjawebet.handleError);
      n == undefined && (n = 5000),
      n < 1000 && (n = 1000);
      remotegtjawebet.connectionTimehandle = setTimeout(function () {
        remotegtjawebet.isneedlogout = !0,
        remotegtjawebet.connection.connect(remotegtjawebet.connectionConfig);
      }, n);
    } 
    catch (i) {
    } 
    finally {
      return !1;
    }
  }
};
