// String.count ; String.chunkSplit ; Object.inspectProperties

var clean_nl = function(str) { return str.replace(/\r\n/g, "\n").replace(/\r/g, "\n"); };
var eh_br = function(str) { return clean_nl(str).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br />"); };
var eh_nq = function(str) { return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"); };
var eh_c = function(str) { return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"); };
//var eh_q = function(str) { return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;"); };

jQuery(function($) {
	$("a.blank").click(function() {
		if (this.href) {
			window.open(this.href, "_blank");
			return false;
		}
		// TODO: Sinon remonter au premier a.href dans les ancetres de l'element
	});
	// En cas d'erreur
	$(document).ajaxError(function(ev, xhr, settings, ex) {
		var s = xhr.responseText.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\n/g, " "), pos = s.lastIndexOf("\/"), m = false;
		if (pos >= 0)
			m = s.substr(pos + 1).match(/^(tmp[A-Za-z0-9]*[.](txt|html)) contains the description of this error[.]\s*$/);
		if (m && m[1]) {
			alert("D\u00e9sol\u00e9, une erreur est survenue !\n\nreport=" + m[1]);
		} else {
			alert("D\u00e9sol\u00e9, une erreur est survenue !\n"
				+ "\nex=" + ex
				+ "\nquery=" + settings.type + " " + settings.url
				+ "\nstatus=" + xhr.status + " " + xhr.statusText
				+ "\nreadyState=" + xhr.readyState
				+ "\nresponseText(" + s.length + ")=" + ((s.length < 128) ? s : (
					s.substr(0, 60) + "(...)" + s.substr(s.length - 60)
				))
			);
		}
	});
	// Image de chargement
	$("#loading").ajaxStart(function() {
		$(this).show();
	}).ajaxStop(function() {
		$(this).hide();
	}).hide();
});


