var BOSH_SERVICE = '/http-bind'
var connection = null;
function escapeHtml(unsafe) {
  return unsafe
      .replace(/&/g, "&amp;")
      .replace(/</g, "&lt;")
      .replace(/>/g, "&gt;")
      .replace(/"/g, "&quot;")
      .replace(/'/g, "&#039;");
}
function escapeHtml2(unsafe) {
  return unsafe
      .replace("&amp;", "&")
      .replace("&lt;", "<")
      .replace("&gt;", ">")
      .replace("&apos;", "\"")
      .replace("&#039;", "\'");
}
function notifyUser(msg)
{
   // if (msg.getAttribute('from') == "a2@vezemdeshevle.ru/pingstream") {
    	var elems = msg.getElementsByTagName('body');
    	var body = elems[0];
		var symbol;
		var str=msg.getAttribute('from');
		var str2;
		symbol = str.lastIndexOf("/");
		str2 = str.substring(symbol+1, str.length);
		jQuery_1_8_1.jnotify(str2, Strophe.getText(body), '', {lifeTime: 60000});
	//}

	return true;
}

function onConnect(status)
{
	if (status == Strophe.Status.CONNECTED) {
		$('#notifications').html('<p class="welcome">Здравствуйте! Любые новые сообщения появятся ниже.</p>');
		connection.addHandler(notifyUser, null, 'message', null, null,  null);
		connection.send($pres().tree());
	}
}

$(document).ready(function () {
    connection = new Strophe.Connection(BOSH_SERVICE);
    connection.connect(	"@vezemdeshevle.ru",
			"d41d8cd98f00b204e9800998ecf8427e",
			onConnect);
    });
