(function ($) {

    $.contactItemContent = function (id, data) {
		return '<span class="username">' 
			+ data['name']
			+ '</span>&nbsp;<span class="phone">(' 
			+ data['phonenumber'] + ')</span>';
	}
	
    $.contactItemClass = function (id, data) {
		return data['alerter'] == 1 ? 'authorized' : '';
	}
	    
	$.fn.arrval = function () {
		var res = [];
		this.each(function () {
			res.push($(this).val());
		});
		return res;
	}

	$.fn.strval = function () {
		return this.arrval().join(',');
	}
	
	$.fmtMsgName = function (strName, data) {
		return $._S[strName].replace('%name%', data['name']);
	}
	
	$.errorDialog = function (message) {
		alert(message);
	}
	
	$.infoDialog = function (message, button)	{
		$.customDialog(message, '', button);
	}
	
	$.confirmDialog = function (title, message, okBtnTitle, callback) {
		if (!title)	title = $._S['boxtitle.confirm'];
		$.customDialog(title, message, $._S['button.cancel'], okBtnTitle, callback);
	}

	$.handleAjaxError = function (data) {
		if (typeof data.errorMessage != 'undefined')
		{
			var msg = '';
			for (var realm in data.errorMessage)
				msg += data.errorMessage[realm] + "\n";
			$.errorDialog(msg);
		}
		else $.errorDialog($._S['error.emptyajax']);
	}
	
})(jQuery);
